akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define P pair<double, int>

int main(){
  int n;
  double sm = 0;
  cin >> n;
  P a[100] = {};
  for(int i=0;i<n;i++){
    cin >> a[i].first;
    a[i].second = i;
    sm += a[i].first;
  }
  sm /= n;
  for(int i=0;i<n;i++) a[i].first = abs(a[i].first - sm);
  sort(a, a+n);
  cout << a[0].second << endl;
}

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

# AとBの違うビットが偶数個なら不可能
if bin(A ^ B).count('1') % 2 == 0:
  print('NO')
  exit()

print('YES')
visited = set([A])
now = A
targets = [[B, set([2**i for i in range(N)])]]
print(now)
while True:
  if now == B:
    break
  target, bits = targets[-1]
  # nowとtargetで異なるビットを見つけ、
  # 異なるビットを変えない空間上で適当に1ビット変えた所をtargetに積む
  xor = now ^ target
  flag = False
  for i in bits:
    if xor & i:
      for j in bits:
        if j != i and now ^ j not in visited:
          targets.append([now ^ j ^ i, {j}])
          targets.append([now ^ j, bits - {i}])
          flag = True
          break
      if flag:
        break
  else:
    # 最大限遠回りしているはずなので、動く
    now = target
    visited.add(now)
    targets.pop()
    print(now)

Measured memory_bytes: 12768
n=int(input())
a_list=list(map(int,input().split(" ")))
b_list=list(map(int,input().split(" ")))
c_list=list(map(int,input().split(" ")))

manzoku=0

for i in range(n):
  ai = a_list[i]
  if i==0:
    manzoku += b_list[ai-1]
  elif ai == a_list[i-1]+1:
    manzoku += b_list[ai-1] + c_list[ai-2]
  else:
    manzoku += b_list[ai-1]
print(manzoku)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int n,k,A[5001];
ll ok,ng,dp[5010][5010];
int solve(int x){
    rep(i,n) fill(dp[i],dp[i]+k+1,0);
    dp[0][0]=1;
    rep(I,n)rep(j,k+1){
        if(I==x) continue;
        int i=I-(I>x);
        dp[i+1][j]=dp[i][j]|dp[i+1][j];
        if(j+A[I]>k) continue;
        if(dp[i][j]) dp[i+1][j+A[I]]=1;
    }
    int z=1;
    for(int i=max(0,k-A[x]);i<k;i++) if(dp[n-1][i]) z=0;
    return z;
}
ll search(){
    ok=-1,ng=n;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        if(solve(mid)) ok=mid;
        else ng=mid;
    }
    return ok;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    rep(i,n) cin>>A[i];
    sort(A,A+n);
    cout<<search()+1<<"\n";
}

Measured memory_bytes: 195968
#include <iostream>
#include <cstdlib>

int main()
{
	int x, y;
	std::cin >> x >> y;
	int ans=abs(abs(x)-abs(y));
	if(abs(x)<abs(y))
	{
		if(x<0)
			ans++;
		if(y<0)
			ans++;
	}
	else if(abs(x)>abs(y))
	{
		if(x>0)
			ans++;
		if(y>0)
			ans++;
	}
	else if(x!=y)
		ans++;
	std::cout << ans << '\n';
}

Measured memory_bytes: 764
n = int(input())
s = list(input())
dup = [''.join(s)]
ans = 'Yes'
for i in range(n-1):
    next = list(input())
    if s[-1]!=next[0] or ''.join(next) in dup:
        ans = 'No'
    else:dup.append(''.join(next))
    s = next
print(ans)

Measured memory_bytes: 38384
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var P = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var answer = 0;

            for (var i = 0; i < P.Length - 1; i++)
            {
                if (P[i] == i + 1 && P[i + 1] == i + 2)
                {
                    answer++;
                    (P[i], P[i + 1]) = (P[i + 1], P[i]);
                }
            }

            for (var i = 0; i < P.Length - 1; i++)
            {
                if (P[i] == i + 1 || P[i + 1] == i + 2)
                {
                    answer++;
                    (P[i], P[i + 1]) = (P[i + 1], P[i]);
                }
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 36200
fn main() {
    let ab: Vec<i32> = read_vec();
    let a: i32 = ab[0];
    let b: i32 = ab[1];

    let mut r = "x";
    if a + b == 15 {
        r = "+"
    } else if a * b == 15 {
        r = "*"
    }

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> elem;

vector<string> masu;
int h, w;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int main() {
  scanf("%d%d", &h, &w);
  queue<elem> que;
  for (auto i = 0; i < h; i++) {
    string line;
    cin >> line;
    masu.emplace_back(line);
    for (auto j = 0; j < w; j++) {
      if (line[j] == '#') {
        que.push(elem(0, pii(i, j)));
      }
    }
  }
  int mcnt = 0;
  while (!que.empty()) {
    elem e = que.front();
    que.pop();
    auto x = e.second.second;
    auto y = e.second.first;
    auto cnt = e.first;
    mcnt = max(mcnt, cnt);
    for (auto i = 0; i < 4; i++) {
      auto nx = x + dx[i], ny = y + dy[i];
      if (nx >= 0 && nx < w && ny >= 0 && ny < h) {
        if (masu[ny][nx] == '.') {
          masu[ny][nx] = '#';
          que.push(elem(cnt + 1, pii(ny, nx)));
        }
      }
    }
  }
  printf("%d\n", mcnt);
}


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

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

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

  Sieve s(1000005);
  auto fs = s.factor(n);

  int ans = 0;
  for (auto p : fs) {
    int x = p.second;
    int b = 1;
    while (b <= x) {
      x -= b;
      b++;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7804
import numpy as np

N = int(input())

counter = 0

lead = np.zeros((9, 9))

for i in range(1, N + 1):
    if (i % 10 != 0):
        moji = str(i)
        lead[int(moji[0]) - 1][int(moji[-1]) - 1] += 1

for i in range(1, N + 1):
    if (i % 10 != 0):
        moji = str(i)
        tmp = moji[-1]
        counter += lead[int(moji[-1]) - 1][int(moji[0]) - 1]

print(int(counter))


Measured memory_bytes: 14388
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	int temp = 0;


	for (int i = 1; i <= 1000000; i++) {
		if (a*i%b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	vector<int> vec;
	int a;
	for(int i=0; i<3; ++i){
		cin >> a;
		vec.emplace_back(a);
	}
	sort(vec.begin(),vec.end());
	// vec.erase(unique(vec.begin(), vec.end()), vec.end());
	if(vec[0]+vec[1]==vec[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

int main() {
  char b;
  cin >> b;
  if (b == 'A') cout << 'T' << endl;
  if (b == 'C') cout << 'G' << endl;
  if (b == 'G') cout << 'C' << endl;
  if (b == 'T') cout << 'A' << endl;
}

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;

int main(){
  int n; cin >> n;
  vector <int> A(n);
  rep(i,n) {
    cin >> A[i];
  }
  bool flg=true;
  int c=0;
  while(flg) {
    flg=false;
    rep(i,A.size()) {
      if (A[i] < A[i-1]) {
        int tmp = A[i];
        A[i] = A[i-1];
        A[i-1] = tmp;
        flg = true;
        c++;
      }
    }
  }
  rep(i,A.size()) {
      cout << A[i] ;
      if (i != A.size()-1) {cout << " ";}
  }
  cout << endl;
  cout << c << endl;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rip(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main()
{ ios_base::sync_with_stdio(0);
cin.tie(0);
 set<string> g;
 int n;
 string s;
 cin >> n;
 while(n--)
 {cin >> s;
  g.insert(s);}
  cout << g.size();
   return 0;
 }

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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int n,m;
vector<vector<int>> edges;
vector<bool> vst;
vector<int> l;

void dfs(vector<vector<int>>& edges, vector<bool>& used, int i) {
    for (int j : edges[i]) if (!used[j]) {
        used[j] = true;
        dfs(edges,used,j);
    }
    l.push_back(i);
}

int main() {
    cin >> n >> m;
    edges.resize(n);
    vector<bool> used(n,false);
    for (int i = 0;i < m+n-1;++i) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        edges[a].push_back(b);
        used[b] = true;
    }
    int par = 0;
    for (int i = 0;i < n;++i) if (!used[i]) par = i;

    vst = vector<bool>(n,false);
    vst[par] = true;
    dfs(edges,vst,par);

    reverse(l.begin(),l.end());
    vector<int> d(n);
    for (int i = 0;i < n;++i) d[l[i]] = i;

    vector<int> pars(n,-1);

    for (int i : l) {
        for (int j : edges[i]) {
            if (pars[j] == -1 || d[pars[j]] < d[i]) {
                pars[j] = i;
            }
        }
    }
    //p_ary(pars,0,n,i);
    for (int i : pars) cout << i+1 << "\n";
    return 0;
}

Measured memory_bytes: 13816
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
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;
}
std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i*i <= n; ++i)
	{
		if (n%i == 0)
		{
			ret.push_back(i);
			if (i != 1 && i*i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}


template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}
int main()
{
	priority_queue<int> q;
	string s = {};
	string s1 = {};
	ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	//ll x[300005] = {};
	ll y[300005] = {};
	ll z[302][302] = {};
	cin >> a;
	cin >> b;
	for (int i = 0; i < b; i++)
	{
		cin >> c;
		a -= c;
	}
	if (a<=0)
	{
		cout << "Yes" << endl;

	}
	else
	{
		cout << "No" << endl;

	}
	//cout << ans << endl;



	//return 0;

	/*cout << c << endl;
	cout << b << endl;*/
	//cout << fixed << setprecision(10) <<tmp << endl;
	//cout<<factorial<10><<endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//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;
//}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<long long,long long> st;
int main(){
	long long a,k[200000];
	long long ans;
	cin>>a;
	for(int i=0;i<a;i++)
		cin>>k[i],st[k[i]]++;
	for(int i=0;i<=a;i++)
		if(st[i]>1)
			ans+=st[i]*(st[i]-1)/2;
	for(int i=0;i<a;i++){
		if(st[k[i]]<2)
			cout<<ans<<endl;
		else
			cout<<ans+(st[k[i]]-1)*(st[k[i]]-2)/2-st[k[i]]*(st[k[i]]-1)/2<<endl;
	}
	return 0;
} 

Measured memory_bytes: 18176
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define MAX_N 100000000
#define INF 1000000007

int main(){
  int h,w,kk;
  cin >> h >> w >> kk;
  int bar[(1 << (w-1))][w];

  for(int i=0;i<(1 << (w-1));i++){
    for(int j=0;j<w-1;j++){
      if((1 << j)&i) bar[i][j] = 1;
      else bar[i][j] = 0;
    }
  }

  for(int i=0;i<(1 << (w-1));i++){
    bar[i][w-1] = 1;
    for(int j=1;j<w-1;j++){
      if(bar[i][j-1]+bar[i][j] == 2){
        bar[i][w-1] = 0;
        break;
      }
    }
  }




  long long a[h+1][w];
  for(int i=0;i<h+1;i++){
    for(int j=0;j<w;j++){
      a[i][j] = 0;
    }
  }
  a[0][0] = 1;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<(1 << (w-1));k++){
        if(bar[k][w-1] == 1){
          if(j == 0){
            if(bar[k][0] == 0) a[i+1][j] += a[i][j]%INF;
            else a[i+1][j+1] += a[i][j]%INF;
          }
          else if(j == w-1){
            if(bar[k][w-2] == 0) a[i+1][j] += a[i][j]%INF;
            else a[i+1][j-1] += a[i][j]%INF;
          }
          else{
            if((bar[k][j-1] == 0) && (bar[k][j] == 0)) a[i+1][j] += a[i][j]%INF;
            else if(bar[k][j] == 1) a[i+1][j+1] += a[i][j]%INF;
            else a[i+1][j-1] += a[i][j]%INF;
          }
        }
      }
      //cout << a[i+1][j] << endl;
    }
  }
  if(w > 1) cout << a[h][kk-1]%INF << endl;
  else cout << a[0][kk-1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=510;
typedef long long ll;
int dp[N],mod,jc[N],n,L[N],R[N],ans,id[N];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>mod;
	jc[0]=1;
	for(int i=1;i<=2*n;++i)jc[i]=(ll)jc[i-1]*i%mod;
	for(int i=0;i<2*n;++i){
		for(L[i]=0;i*i+L[i]*L[i]<n*n;++L[i]);
		for(R[i]=2*n-1;i*i+R[i]*R[i]>2*n*2*n;--R[i]);
		id[i]=i;
	}
	for(int i=n;i<2*n;++i)L[i]=R[i]+1;
	for(int i=0;i<2*n;++i)
		for(int j=i+1;j<2*n;++j)
			if(L[i]>L[j]||(L[i]==L[j]&&R[i]>R[j])){swap(L[i],L[j]);swap(R[i],R[j]);swap(id[i],id[j]);}
	for(int i=n;i<=2*n;++i){
		memset(dp,0,sizeof dp);dp[0]=1;
		int cnt=0,lim1=0;
		for(int j=0;j<2*n;++j)if(id[j]>=n){
			++cnt;lim1=min(lim1+1,i);
			for(int k=lim1;k>=cnt;--k)
				dp[k]=dp[k-1]?(ll)dp[k-1]*(L[j]-k+1)%mod:0;
			dp[cnt-1]=0;
		}else{
			lim1=min(lim1+1,i);
			for(int k=lim1;k>cnt;--k)dp[k]=((ll)dp[k]*(R[j]-(i+j-k)+1)+(ll)dp[k-1]*(L[j]-k+1))%mod;
			dp[cnt]=(ll)dp[cnt]*(R[j]-(i+j-cnt)+1)%mod;
		}
		if((i-n)&1)ans=(ans-dp[i]+mod)%mod;
		else ans=(ans+dp[i])%mod;
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int height,width,i,j;
    while (1) {
        scanf("%d %d",&height,&width);
        if (height==0&&width==0) break;
        for (i=0; i<height; i++) {
            for (j=0; j<width; j++) printf("#");
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include <vector> 
#include <list> 
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

const LL mod = 1e9 + 7;

map<int, int> prime_factor(int n) {

	map<int, int> res;
	for (int i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			++res[i];

			n /= i;
		}
	}
	if (n != 1) { res[n] = 1; }
	return res;
}


int main() {
	
	int N;
	cin >> N;
	LL ans = 1LL;

	map<int, int> soinsuunum;


	FOR(i,1, N+1) {
		//cerr << i << endl;
		map<int, int> prime = prime_factor(i);
		for (auto p : prime) {
			//cerr << p.first << " " << p.second << endl;
			soinsuunum[p.first] += p.second;
		}

	}

	for (auto p : soinsuunum) {
		ans*= (p.second+1);
		ans %= mod;
	}

	cout << ans<< endl;

}

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

string s;
long long int k;
string c;
int num=0;

int main(){

    cin>>s;
    cin>>k;

    

    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            num++;
        }
        else if(s[i]!='1'){
            c=s[i];
            break;
        }
    }




    if(num>=k){
        cout<<1<<endl;
    }
    else{
        cout<<c<<endl;
    }



}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int light[1000005];
vector<vector<int>> miti(1000005);

int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n+1);
  vector<ll> b(n);
  rep(i,n+1) {
    cin >> a[i];
  }
  rep(i,n) {
    cin >> b[i];
  }

  ll result = 0;
  rep(i,n) {
    if (a[i] >= b[i]) {
      a[i] -= b[i];
      result += b[i];
    } else {
      ll diff = b[i] - a[i];
      result += a[i];
      a[i] = 0;
      ll beat = a[i+1] < diff ? a[i+1] : diff;
      a[i+1] -= beat;
      result += beat;
    }
  }
  cout << result << endl;
}



Measured memory_bytes: 25216
#include <iostream>
using namespace std;
#include <string>
#include <algorithm>
#define ll long long
int main()
{
    ll k,s;
    ll x,y=0,z;
    cin>>k>>s;
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<=k;j++)
        {
            x=s-i-j;
            if(x>=0&&x<=k)
            {
                y++;
            }
        }
    }
    cout<<y;


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200200;
ll a[N];
ll dp[N];
int n;
int ans;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	ll lst = 0;
	for (int i = 0; i < n; i++) {
		ll x;
		scanf("%lld", &x);
		a[i] = x - lst;
		lst = x;
	}
	a[n++] = -lst;
	
	ans = 0;
	ll mx = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 0) continue;
		if (a[i] > 0) {
			mx += a[i];
			for (int p = ans; p <= ans + 2; p++) {
				dp[p + 1] = max(dp[p + 1], dp[p] + a[i]);
			}
			dp[ans + 2] = mx;
		} else {
			for (int p = ans + 2; p > ans; p--)
				dp[p] = max(dp[p] + a[i], dp[p - 1]);
			dp[ans] += a[i];
			mx += a[i];
			for (int p = ans; p <= ans + 2; p++)
				dp[p] = min(dp[p], mx);
			while(dp[ans] < 0) {
				ans++;
				dp[ans + 2] = mx;
			}
		}
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
void fileio()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
 

 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}

const int N = 100001; 



void solve(){
    int n,W;
    cin>>n>>W;
    pii * arr = new pii[n];
    forn(i,0,n-1)
        cin>>arr[i].F>>arr[i].S;

    int dp[W+1][2] = {0};

    for(int i=0;i<n;i++){
        int k = i&1;
        for(int j = 1; j<=W;j++){
            if(arr[i].F <= j){
                dp[j][k] = max(dp[j][k^1] , dp[j-arr[i].F][k^1] + arr[i].S);
            }else{
                dp[j][k] = dp[j][k^1];
            }
        }
    }

    // cout<<dp[W][0]<<" "<<dp[W][1]<<endl;

    cout<<(n%2==0 ? dp[W][1] : dp[W][0]  )<<endl;


}
 
int32_t main()
{
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

Measured memory_bytes: 1792
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;

////////////////いろいろあるよ//////////////////////////////////
int main(){
	int n,m;
  	cin >> n >> m;
  	int data[n];
  	REP(i,n)cin >> data[i];
  
  	sort(data,data+n);
  	int ans = 0;
  	REP(i,m)ans += data[i];
  
  	cout << ans << endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;

vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
const int N = 1e6 + 5;
#define MAXM 1000001
bool flag = true;
ll pchk[MAXM], arr[MAXM];
void sieve()
{
    pchk[0] = pchk[1] = 1;
    for(ll i = 2; i < MAXM; i++)
    {
        if(!pchk[i])
        {
            ll cnt = 0;
            for(ll j = i; j <  MAXM; j += i)
            {
                pchk[j] = 1;
                cnt += arr[j];
            }
            flag &= (cnt <= 1);
        }
    }
//  for(ll i = 2; i < MAXM; i++) if(!pchk[i]) prime.push_back(i);   
}

int main()
{
	sync;
    ll n, gcd = -1;
    cin >> n ;
    for(ll i = 1; i <= n; i++)
    {
        ll x;
        cin >> x;
        arr[x]++;
        if(gcd == -1)
            gcd = x;
        else
            gcd = __gcd(gcd, x);
    }
    sieve();
    if(flag)
        return cout << "pairwise coprime", 0;
    if(gcd == 1)
        return cout << "setwise coprime", 0;
    cout << "not coprime", 0;
}

Measured memory_bytes: 19264
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n = read::<i64>();
    let ans = if n == 22 {
        "Christmas Eve Eve Eve".to_string()
    } else if n == 23 {
        "Christmas Eve Eve".to_string()
    } else if n == 24 {
        "Christmas Eve".to_string()
    } else {
        "Christmas".to_string()
    };
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
string S, T;

int main(void){
	//IO("test.in", "test.out");
	cin >> S >> T;
	char m = S[0], n = T[0];
	for(int i = 1; i < S.length(); i++)
		if(S[i] < m) m = S[i];
	for(int i = 1; i < T.length(); i++)
		if(T[i] > n) n = T[i];
	if(m < n || (S.length() < T.length() && S == T.substr(0, S.length()))) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

int T, n, m;
ll d;
vector<string> v;


int check(const int a, const int b, const ll can) {
    set<int> s;
    s.insert(a);
    RREPS(i, 51) if ((can >> i) & 1) {
        REP(j, 51) if(s.count(j)) s.insert(j % i);
    }
    return s.count(b);
}

int check(const vi &a, const vi &b, ll can) {
    REP(i, n) {
        if(!check(a[i], b[i], can)) return 0;
    }
    return 1;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin >> n;
    vi a(n), b(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    ll ans = 0;
    RREP(i, 51) {
        if(!check(a, b, ans | ((1ll << i) - 1))) {
            ans |= 1ll << i;
        }
    }
    if (ans >= (1ll << 50)) ans = -1;
    cout <<  ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include<string.h>
#include<limits.h>
#include<time.h>

void sosu(int n){
	int i,j,num[n];
	
	for(i=2;i<=n;i++)num[i]=i;
	for(i=2;i<=sqrt(n);i++){
		for(j=2;j*i<=n;j++)num[j*i]=0;
	}
}

int main(){
	int number[10000]={0};
	int ac[10000]={0};
	int select[10000]={0};
	int i=0,j=0,k,count,key,count_last;
	
	while(1){
		scanf("%d,%d",&number[i],&ac[i]);
		if(number[i]==0 && ac[i]==0)break;
		i++;
	}
	for(j=0;scanf("%d",&select[j])!=EOF;j++);
	
	count=i;
	count_last=j;
	for(i=0;i<count;i++){
		for(j=i;j<count;j++){
			if(ac[i]<ac[j]){
				key=number[i];
				number[i]=number[j];
				number[j]=key;
				key=ac[i];
				ac[i]=ac[j];
				ac[j]=key;
			}
		}
	}
	
	for(i=0;i<count_last;i++){
		for(j=0,k=1;j<=count;j++){
			if(select[i]==number[j]){
				printf("%d\n",k);
				break;
			}
			if(ac[j]!=ac[j+1])k++;
		}
	}
	
return 0;

}

Measured memory_bytes: 724
#include <iostream>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define pb push_back
ll a[200005];
int main(int argc, char** argv) {
	ll k,n;
	scanf("%lld%lld",&k,&n);
	ll minn=0;
	rep(i,1,n)scanf("%d",&a[i]);
	rep(i,1,n-1)
	{
		minn=max(minn,a[i+1]-a[i]);
	}
	minn=max(minn,k+a[1]-a[n]);
	cout<<k-minn;
	return 0;
}

Measured memory_bytes: 1792
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

struct node {
    llong index;
    vector<bool> confilm;
};

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

    llong N, M;
    cin >> N >> M;

    vvecllong edge(N + 1, vecllong(0));

    FOR(i, M) {
        llong from, to;
        cin >> from >> to;
        edge[from].push_back(to);
        edge[to].push_back(from);
    }

    stack<node> st;
    node start;
    start.index = 1;
    start.confilm = vector<bool>(N + 1, false);
    st.push(start);

    llong ans = 0;

    while(!st.empty()) {
        node now = st.top();
        st.pop();

        if(now.confilm[now.index]) continue;
        now.confilm[now.index] = true;

        FOR(i, edge[now.index].size()) {
            if(!now.confilm[edge[now.index][i]]) {
                node next;
                next.index = edge[now.index][i];
                next.confilm = vector<bool>(N + 1, false);
                copy(now.confilm.begin(), now.confilm.end(), next.confilm.begin());
                st.push(next);
            }
        }

        llong isAll = 1;
        FORS(i, 1, N + 1) {
            if(!now.confilm[i]) {
                isAll = 0;
                break;
            }
        }

        ans += isAll;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use proconio::marker::{Isize1, Usize1, Bytes, Chars};
#[proconio::fastout]
fn main() {
    proconio::input!{
        a: i64,
        b: i64,
        _c: i64,
        k: i64,
    }
    if k <= a { println!("{}", k); }
    else if k <= a + b { println!("{}", a); }
    else { println!("{}", 2 * a + b - k); }
}


Measured memory_bytes: 2160
p = int(input())
T,A = map(int, input().split())
r = list(map(int, input().split()))

ans = -1
tmp = float('inf')
for i in range(p):
    t = T - r[i] * 0.006
    if abs(t - A) < tmp:
        tmp = abs(t - A)
        ans = i + 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(void) {
  int N;
  int a[300010];
  cin >> N;
  for (int i = 0; i < 3*N; i++) cin >> a[i];
  sort(a, a+3*N);
  reverse(a, a+3*N);
  long int sum = 0;
  for (int i = 1; i < 2*N; i += 2) {
    sum += a[i];
    //cout << a[i] << endl;
  }
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void){
  int i,j,k;
  int N;
  int a[200];
  int t;
  int minj;
  int count=0;
  scanf("%d",&N);
  for(i=0;i<N;i++)  scanf("%d",&a[i]);


  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(a[j]<a[minj]){
        minj=j;
      }
    }
    if(i!=minj){
      t=a[i];
      a[i]=a[minj];
      a[minj]=t;
      count++;
    }

  }
  for(i=0;i<N-1;i++)  printf("%d ",a[i]);
  printf("%d\n",a[N-1]);

  printf("%d\n",count);


  return 0;
}

Measured memory_bytes: 600
N = int(input())
A = list(map(int,input().split()))
setA = list(set(A))
if len(setA) == 1 and setA[0] == 0:
	print("Yes")
	exit()
if N % 3 != 0:
	print("No")
	exit()
if len(setA) == 1 or len(setA) > 3:
	print("No")
	exit()
if len(setA) == 2:
	if 0 in setA:
		setA.sort()
		if A.count(0) == N // 3 and A.count(setA[1]) == (N // 3) * 2:
			print("Yes")
			exit()
	print("No")
	exit()

if setA[0] ^ setA[1] != setA[2]:
	print("No")
	exit()
for a in setA:
	if A.count(a) != N // 3:
		print("No")
		exit()
print("Yes")
exit()

Measured memory_bytes: 14212
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long double A,B;
	cin>>A>>B;
	if(A>B){
		cout<<"GREATER";
	}
	if(B>A){
		cout<<"LESS";
	}
	if(A==B){
		cout<<"EQUAL";
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC143A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] AB = Console.ReadLine().Split(' ');
            int A = int.Parse(AB[0]);
            int B = int.Parse(AB[1]);
            int ans = Math.Max(A - 2 * B, 0);
            Console.WriteLine(ans);
        }
    }
}


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

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

const double EPS = 1e-8;
using P = complex<double>;
using G = vector<P>;

signed main(){
  int n; cin >> n;
  G g(n);
  rep(i,n){
    double x, y; cin >> x >> y;
    g[i].real(x);
    g[i].imag(y);
  }

  if(n & 1){
    cout << "NA" << endl;
    return 0;
  }

  P res = (g[0] + g[n/2]) * 0.5;
  FOR(i,1,n/2){
    P tmp = (g[i] + g[n/2 + i]) * 0.5;
    if(abs(res - tmp) > EPS){
      cout << "NA" << endl;
      return 0;
    }
  }
  printf("%.10lf %.10lf\n",res.real(),res.imag());
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a>=b){
		if (c >= a) {
			cout << b << " " << a << " " << c << endl;
		}
		else if (c >= b) {
			cout << b << " " << c << " " << a << endl;
		}
		else {
			cout << c << " " << b << " " << a << endl;
		}
	}
	else {
		if (c >= b) {
			cout << a << " " << b << " " << c << endl;
		}
		else if (c >= a){
			cout << a << " " << c << " " << b << endl;
		}
		else {
			cout << c << " " << a << " " << b << endl;
		}
	}
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string c;
  cin >> c;
  vector<int> r, w;
  REP(i, n){
    if (c[i] == 'W') w.push_back(i);
    else r.push_back(i);
  }
  int r_size, w_size;
  r_size = r.size();
  w_size = w.size();
    int ans = 0;
    int index = min(r_size, w_size);
    REP(i, index){
      int now_w = w[i];
      int now_r = r[r_size-i-1];
      if (now_w < now_r) ans++;
      else break;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 4892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
		int y = stdIn.nextInt();
        stdIn.close();
        System.out.printf("%d %d %f",x/y,x%y,(double)x/y);
	}
}


Measured memory_bytes: 26432
#include <bits/stdc++.h>
using namespace std;
int main(){
  int w,h,n;
  cin>>w>>h>>n;
  int x[n],y[n],a[n];
  for(int i=0;i<n;++i){
    cin>>x[i]>>y[i]>>a[i];
  }
  int x1=0,x2=w,y1=0,y2=h;

  for(int i=0;i<n;++i){
      switch(a[i]){
        case 1:
          if(x1 < x[i]) x1 = x[i];
          break;
        case 2:
          if(x2 > x[i]) x2 = x[i];
          break;
        case 3:
          if(y1 < y[i]) y1 = y[i];
          break;
        case 4:
          if(y2 > y[i]) y2 = y[i];
          break;
      }
  }
  if(x2-x1>0 && y2-y1>0){
    cout<<(x2-x1)*(y2-y1);
  }
  else{cout<<0;}
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <memory.h>
#include <bitset>
#include <stack>
#include <assert.h>
using namespace std;
#define ll  long long
#define ld long double
#define ppi pair<int, int>
#define mp make_pair	
const int N = 2e5 + 111 , NS = 1e6 + 11;
double getmotric_serise[N];
double dp[311][311][311];
bool can(int i, int j, int k)
{
	return i >= 0 && j >= 0 && k >= 0;
}
int main()
{
	int n, arr[3] = { 0 , 0 ,0 };
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int x; cin >> x;
		arr[x - 1]++;
	}
	for (int k = 0; k <= 301; k++)
		for (int j = 0; j <= 301; j++)
			for (int i = 0; i <= 301; i++)
				if (i | j | k)
				{
					int sum = (i + j + k);

					double r = 1.0 * sum / n;
					double self = (1 - r > 1e-9) ? 1 / (r * r) : 1;

					dp[i][j][k] = self * r;

					if (can(i - 1, j, k)) dp[i][j][k] += (1.0 * i / sum) * dp[i - 1][j][k];
					if (can(i + 1, j - 1, k)) dp[i][j][k] += (1.0 * j / sum) * dp[i + 1][j - 1][k];
					if (can(i, j + 1, k - 1)) dp[i][j][k] += (1.0 * k / sum) * dp[i][j + 1][k - 1];
				}
	printf("%.15lf", dp[arr[0]][arr[1]][arr[2]]);
}

Measured memory_bytes: 229632
function main(input) {
  const args = input.split('');
  var num = 0;
  
  for(var i=0; i<4;i++){
    if(args[i]=='+') num++;
    else num--;
  }
  
  console.log(num);
}

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

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

N = int(input())
S = [input().rstrip()[::-1] for i in range(N)]
S.sort(key=len)
P = 2**61 - 1

from collections import defaultdict
D = defaultdict(lambda: [0]*26)

ans = 0
for s in S:
    l = ord(s[-1]) - ord('a')
    a = 0
    tmp = [0] * 26
    for c in s[:-1]:
        i = ord(c) - ord('a')
        if a in D:
            for j in range(26):
                tmp[j] += D[a][j]
        ans += tmp[i]
        tmp[i] = 0
        a = (a*27 + i + 1) % P
    ans += tmp[l]
    D[a][l] += 1

print(ans)

Measured memory_bytes: 187332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll D;
    cin >>D;
    if(D==25){
        cout<<"Christmas"<<endl;
    }else if(D==24){
        cout<<"Christmas Eve"<<endl;
    }else if(D==23){
        cout<<"Christmas Eve Eve"<<endl;
    }else{
        cout<<"Christmas Eve Eve Eve"<<endl;
    }
    
   


    return 0;
    

}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()

using namespace std;

void execute()
{
	int N, M;
	int a, b;
	int count;
	int current;
	int ans = 0;
	cin >> N >> M;
	vector<bool> IsThrough(N, false);
	vector<vector<bool>> root(N, vector<bool>(N, false));
	vector<vector<int>> i_root(M, vector<int>(2, 0));
	queue<int> next;
	for (int i = 0; i < M; i++)
	{
		cin >> a >> b;
		i_root[i][0] = a - 1;
		i_root[i][1] = b - 1;
		root[i_root[i][0]][i_root[i][1]] = true;
		root[i_root[i][1]][i_root[i][0]] = true;
	}

	for (int i = 0; i < M; i++)
	{
		IsThrough = vector<bool>(N, false);
		root[i_root[i][0]][i_root[i][1]] = false;
		root[i_root[i][1]][i_root[i][0]] = false;
		next.push(0);
		count = 0;
		for (; !next.empty();)
		{
			current = next.front();
			next.pop();

			for (int j = 0; j < N; j++)
			{
				if (root[current][j] && !IsThrough[j])
				{
					IsThrough[j] = true;
					next.push(j);
				}
			}
			count++;
		}
		if (count <= N)
			ans++;

		root[i_root[i][0]][i_root[i][1]] = true;
		root[i_root[i][1]][i_root[i][0]] = true;
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	string n;
	cin >> n;

	if(n[0] == n[2]){
		puts("Yes");
	}else{
		puts("No");
	}

	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MOD 1000000007
typedef unsigned long long ull;
typedef   signed long long sll;


#define N_MAX 100000
#define M_MAX 100

ull n;
ull h[N_MAX];
ull a, b;

void swap_adj(ull *a, ull *b){
	ull tmp = *b;
	*b = *a;
	*a = tmp;
	return;
}

int comp(const void *a, const void *b){
	if (*(ull*)a > *(ull*)b) {
		return -1;
	} else if (*(ull*)a < *(ull*)b) {
		return +1;
	} else {
		return 0;
	}
}

int ispossible(int x){
	int i;
	int f = 0;
	for (i = 0; i < n; i++) {
		if (h[i] <= x * b) break;
		f += (h[i] - x * b - 1) / a + 1;
	}
	if (f > x) {
		return 0;
	} else {
		return 1;
	}
}

int solve(){
	
	if ((a * 2 + b) & 3) {
		puts("NO");
	} else {
		puts("YES");
	}

	return 0;
}

int main(void){
	int i, n;
	int min, max;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		if (!i || min > x) {
			min = x;
		}
		if (!i || max < x) {
			max = x;
		}
	}

	// solve();
	printf("%d\n", max - min);

	return 0;
}


Measured memory_bytes: 128