akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

ll gcd_ll(ll a, ll b)
{
	if (a == 0)
		return 0;
	if (b == 0)
		return 0;
	ll x;
	while (1)
	{
		x = a % b;
		if (x == 0)
			return b;
		else
		{
			a = b;
			b = x;
		}
	}
}

vector<vl> pow_;
vi plist;
void pow_ini() {
	pow_.clear();
	int len = plist.size();
	rep(i, len) {
		ll ptmp = plist[i];
		vl powtmp;
		powtmp.push_back(ptmp);
		rep(j, 62) {
			ll nxt = powtmp[j] * powtmp[j];
			nxt %= mod;
			powtmp.push_back(nxt);
		}
		pow_.push_back(powtmp);
	}
	return;
}

ll pow1(ll i, ll b) {
	ll ans = 1;
	rep(n, 62) {
		if ((b >> n) % 2 == 1) {
			ans *= pow_[i][n];
			ans %= mod;
		}
	}
	return ans;
}

int main() {
	int N, K;
	cin >> N >> K;
	vl gcdsum(K + 1, 0);
	vl gcdsumeq(K + 1, 0);
	rep(k, K)
		plist.push_back(k + 1);
	pow_ini();
	ll ans = 0;
	rrep(r, K) {
		int k = r + 1;
		int ktmp = K / k;
		gcdsum[k] = pow1(ktmp - 1, N);
		gcdsumeq[k] = gcdsum[k];
		int kk = k;
		while (1) {
			kk += k;
			if (kk > K)
				break;
			gcdsumeq[k] -= gcdsumeq[kk];
			gcdsumeq[k] += mod;
			gcdsumeq[k] %= mod;
		}
		ans += gcdsumeq[k] * k;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 57456
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;
vi eulerSieve(int n)    // 查找记录2-n的素数
{
    vi p;
    vector<bool> vst(n+1, false);
    for (int i = 2; i <= n; i++)
    {
        if (vst[i] == false)  // 如果未被筛过，则为素数
            p.push_back(i);
        for (int j = 0; j < p.size(); j++)
        {
            if (i * p[j] > n)      // 当要标记的合数超出范围时跳出
                break;
            vst[i * p[j]] = true;     // 将已经记录的素数的倍数进行标记
            if (i % p[j] == 0)      //关键步骤
                break;
        }
    }
    return p;
}

vi primesUntil(int n){
    vi p;
    p.push_back(2);
    for (int i =3; i<=n; ++i){
        for (int j=0; j<p.size(); ++j){
            if (i%p[j] == 0) break;
            if (p[j]* p[j]> i)
            {
                p.push_back(i);
                break;
            }
        }
    }
    return p;
}

vector<pll> defactor(lint v, const vi& p){// prime,   power
    vector<pll> ans;
    int pid = 0;
    while(v>1){
        int cnt = 0;
        while(v%p[pid] == 0) {
            cnt++;
            v= v/p[pid];
        }
        if (cnt) ans.push_back({p[pid], cnt});
        pid++;
        if (v > 1 && (pid >= p.size() || lint(p[pid])*p[pid]>v)){
            ans.push_back({v, 1});
            break;
        }
    }
    return ans;
}


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

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

    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if (n%2){
        cout<<b[n/2] - a[n/2] + 1;
    } else {
        cout<<((b[n/2] + b[n/2-1]) - (a[n/2] + a[n/2-1])) + 1;
    }


}


Measured memory_bytes: 4788
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


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

	int ans = 0;
	for (int i = a; i <= b; i++)
	{
		int a = i / 10000;
		int b = (i / 1000) % 10;
		int c = (i / 10) % 10;
		int d = i % 10;
		if (a == d && b == c) ans++;
	}
	cout << ans << endl;
}



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

int ans=0;

void check(long long x){
	int a=0, b=0, c=0;
	while(x>0){
		if(x%10==3) a=1;
		if(x%10==5) b=1;
		if(x%10==7) c=1;
		x /= 10;
	}
	ans += a*b*c;
}
		
		
void dfs(long long x, long long n){
	if(x<=n){
		check(x);
		dfs(10*x+3, n);
		dfs(10*x+5, n);
		dfs(10*x+7, n);
	}
}
int main(void){
	long long n;
	cin >> n;
	dfs(0, n);
	cout << ans << endl;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n=4;
  map<ll,ll> m;
  REP(i,n){
    ll a;
    cin>>a;
    m[a]+=1;
  }
  
  if(m[1]==1 && m[9]==1 && m[7] == 1 && m[4]== 1)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;

}

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

int main() {
    string S; cin >> S;
    int q; cin >> q;
    int Q;
    int flag = 1;
    int F;
    char c;
    vector<char> front(0), back(0);
    for (int i = 0; i < q; i++) {
        cin >> Q;
        if (Q == 1) {
            flag *= -1;
        }
        else {
            cin >> F;
            cin >> c;
            if (F * flag == 2 || F * flag == -1) {
                back.push_back(c);
            }
            else {
                front.push_back(c);
            }
        }
    }
    if (flag == 1) {
        for (int i = front.size() - 1; i >= 0; i--) {
            cout << front[i];
        }
        cout << S;
        for (int i = 0; i < back.size(); i++) {
            cout << back[i];
        }
        cout << endl;
    }
    else {
        for (int i = back.size()-1; i >= 0; i--) {
            cout << back[i];
        }
        for (int i = S.length() - 1; i >= 0; i--) {
            cout << S[i];
        }
        for (int i = 0; i < front.size(); i++) {
            cout << front[i];
        }
        cout << endl;
    }
}


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

using namespace std;


#define MAXN 100000



int get(int i) {
  printf("%d\n", i);
  fflush(stdout);
  string s;
  cin >> s;
  if (s=="Vacant") exit(0);
  if (s=="Male") return 1;
  return 2;
}

int main() {
  int n;
  scanf(" %d", &n);
  int first = get(0);
  if (!first) return 0;
  int lo = 0, hi = n;
  while (lo+3<hi) {
    int mid = (lo+hi)/2;
    if (mid%2) mid++;
    if (get(mid)!=first) hi = mid;
    else lo = mid;
  }
  for (int i = lo; i <= hi; ++i) {
    get(i);
  }
  return 0;
}


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

template<typename A, size_t N, typename T>
void static_fill(A (&arr)[N], const T &val){ fill((T*)arr, (T*)(arr+N), val); }

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

int w, h;
bool wall[31][31][31][31];
int d[31][31];

bool chmin(int &a, int b) {
    if (a <= b) return false;
    a = b;
    return true;
}

bool is_wall(int y1, int x1, int y2, int x2) {
    if (x2 < 0 || w <= x2 || y2 < 0 || h <= y2) return true;
    return wall[y1][x1][y2][x2];
}

void set_wall(int y1, int x1, int y2, int x2) {
    wall[y1][x1][y2][x2] = wall[y2][x2][y1][x1] = true;
}

int main() {
    while (cin >> w >> h) {
        if ( ! w) break;

        static_fill(wall, false);
        int v;
        for (int i=0; i<2*h-1; ++i) {
            if (i % 2 == 0) {
                for (int j=0; j<w-1; ++j) {
                    cin >> v;
                    if (v) set_wall(i/2, j, i/2, j+1);
                }
            } else {
                for (int j=0; j<w; ++j) {
                    cin >> v;
                    if (v) set_wall(i/2, j, i/2+1, j);
                }
            }
        }

        static_fill(d, INF);
        d[0][0] = 1;
        queue<pair<int,int>> q;
        q.push(make_pair(0, 0));
        while ( ! q.empty()) {
            int y = q.front().first;
            int x = q.front().second;
            q.pop();
            for (int i=0; i<4; ++i) {
                if (is_wall(y, x, y+dy[i], x+dx[i])) continue;
                if (chmin(d[y+dy[i]][x+dx[i]], d[y][x]+1)) {
                    q.push(make_pair(y+dy[i], x+dx[i]));
                }
            }
        }
        cout << (d[h-1][w-1] == INF ? 0 : d[h-1][w-1]) << endl;
    }
    return 0;
}


Measured memory_bytes: 4008
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n;

void dfs(vector<char> s, vector<char> used, ll cur) {
	if (cur < n - 1) {
		rep(i, sz(used)) {
			s[cur] = used[i];
			dfs(s, used, cur + 1);
		}
		if (sz(used) > 0) {
			char c = used[sz(used) - 1];
			c++;
			s[cur] = c;
			used.push_back(c);
		}
		else {
			s[cur] = 'a';
			used.push_back('a');
		}
		dfs(s, used, cur + 1);
	}
	else {
		rep(i, sz(used)) {
			rep(j, n - 1)cout << s[j];
			cout << used[i] << endl;
		}
		rep(i, n - 1)cout << s[i];
		if (sz(used)) {
			cout << ++used[sz(used) - 1] << endl;
		}
		else {
			cout << 'a' << endl;
		}
	}
}

int main() {
	cin >> n;
	vector<char> s(n), used;
	dfs(s, used, 0);
	return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int num[]  = new int[n-1];        
        for(int i = 0;i < n-1;i++){
            num[i]  = sc.nextInt();
        }
        int ans = num[0];
        for(int i = 0;i < n-2;i++){
            ans += min(num[i],num[i+1]);
        }
        ans += num[n-2];
        System.out.print(ans);
    }
    static int min(int a,int b){
        if(a>b)return b;
        return a;
    }
    
}


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

#define pb push_back
#define all(a) (a).begin(), (a).end()

using ll = long long;
using pii = pair<int, int>;

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int r = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == r + 1) {
            ++r;
        }
    }
    if (!r) cout << -1;
    else {
        cout << n - r;
    }
    cout << '\n';
}

Measured memory_bytes: 1024
object Main extends App {

  import scala.io.StdIn._

  val Array(n, weightMax) = readLine.trim.split(' ').map(_.toInt)
  val maxMemo = Array.tabulate(weightMax + 1){ _ ⇒ Long.MinValue}.also{arr ⇒ arr(0) = 0L}
  for (_ ← 0 until n){
    val Array(w, v) = readLine.trim.split(' ').map(_.toInt)
    for (prev ← (0 to weightMax - w).reverse) {
      if (maxMemo(prev) != Long.MinValue && maxMemo(prev + w) < maxMemo(prev) + v) {
        maxMemo(prev + w) = maxMemo(prev) + v
      }
    }
  }
  println(maxMemo.max)
  case class Goods(weights: Long, value: Long)
  implicit class Extend[T](value: T){
    def also(func: T ⇒ Unit): T = {func(value); value}
    def let[A](func: T ⇒ A): A = func(value)
  }
}

Measured memory_bytes: 37480
l = []
for i in range(3):
  a = [int(x) for x in input().split()]
  l.append(a)
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for x in range(3):
  for y in range(3):
    for i in range(n):
      if l[x][y] == b[i]:
        l[x][y] = 0
hantei = "No"
for i in range(3):
  if l[i][0] == l[i][1] and l[i][1] == l[i][2]:
    hantei = "Yes"
    break
  elif l[0][i] == l[1][i] and l[1][i] == l[2][i]:
    hantei = "Yes"
    break
if l[0][2] == l[1][1] and l[1][1] == l[2][0]:
  hantei = "Yes"
elif l[0][0] == l[1][1] and l[1][1] == l[2][2]:
  hantei ="Yes"
print(hantei)

Measured memory_bytes: 3064
n,m = map(int,input().split())
res = 0

q = []
for i in range(m):
    q.append(list(map(int,input().split())))
p = list(map(int,input().split()))


for s in range(2**n): 
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1,len(q[i])):
            w = q[i][j]
            if s >> (w-1) & 1:
                cnt += 1
        if cnt % 2 != p[i]:
            judge = False
    if judge:
        res += 1
print(res)

Measured memory_bytes: 9244
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
 
using namespace std;
typedef long long ll;
struct Info{int par, weight;};
const int MAX = 100005;
const int INF = (1<<28);

class UnionFind{
public:
  
  Info info[MAX];

  void init(int n){
    for(int i = 0; i < n; i++) info[i] = (Info){i,0};
  }
 
  Info find(int x){
    if(info[x].par == x) return info[x];
    
    Info tmp = find(info[x].par);
    info[x].weight += tmp.weight;
    info[x].par = tmp.par;
    return info[x];
  }

 
  
  void unite(int x, int y, int w){
    Info X = find(x);
    Info Y = find(y);
    //W[x]+w = W[y]
    
    info[Y.par].par = X.par;
    info[Y.par].weight += w+info[x].weight-info[y].weight;
  }
   
  bool same(int x, int y){
    return find(x).par == find(y).par;
  }

  int getValue(int x){return info[x].weight;}
};
 
int N,M;
bool used[MAX];
UnionFind uf;
 
void init(){
  memset(used,false,sizeof(used));
  uf.init(N+1);
}
 
 
void update(){
   
  int a,b,c;
  cin >> a >> b >> c;
  uf.unite(a,b,c);
}
 
void print(){
  int a,b;
  cin >> a >> b;
  if(uf.same(a,b)) cout << uf.getValue(b)-uf.getValue(a) << endl;
  else cout << "UNKNOWN" << endl;
}
 
int main(){
   
  while(cin >> N >> M && N+M){
    init();
    for(int i = 0; i < M; i++){
      char c;
      cin >> c;
      if(c == '!') update();
      else print();
    }
  }
  return 0;
}

Measured memory_bytes: 2880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1000000007;
ll inv = 500000004;

int main(){
  ll N,K;cin >> N >> K;
  vector<ll> A(N,0);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  ll ans = 0;
  for(int i=0;i<N;i++){
    ll sum1=0,sum2=0;
    for(int j=0;j<i;j++){
      if(A[i]>A[j]){
        sum1 += 1;
      }
    }
    for(int j=i+1;j<N;j++){
      if(A[i]>A[j]){
        sum2 += 1;
      }
    }
    ll K1 = K*(K-1)%MOD*inv%MOD;
    ll K2 = K*(K+1)%MOD*inv%MOD;
    ans = (ans + sum1*K1%MOD)%MOD;
    ans = (ans + sum2*K2%MOD)%MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#create date: 2020-07-11 21:00

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    l, r, d = na()
    print(r//d - (l-1) //d)

if __name__ == "__main__":
    main()

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

int main( int argc, char *argv[] )
{
int i;
int N;
int A;
int iPre;
int iCount;
int iFlag;

	// N を取得
	cin >> N;

	// A を取得しながら、数列の数をカウント
	cin >> iPre;
	iCount = 1;
	iFlag = 0;	// 0:未設定 1:単調非減少 2:単調非増加
	for( i = 1; i < N; i++ )
	{
		cin >> A;
		if( iPre > A )
		{
			if( iFlag == 0 )
			{
				// 単調非増加
				iFlag = 2;
			}
			else if( iFlag == 1 )
			{
				// 新しい数列の先頭
				iCount++;
				iFlag = 0;
			}
		}
		else if( iPre < A )
		{
			if( iFlag == 0 )
			{
				// 単調非減少
				iFlag = 1;
			}
			else if( iFlag == 2 )
			{
				// 新しい数列の先頭
				iCount++;
				iFlag = 0;
			}
		}

		iPre = A;
	}

	// 出力
	cout << iCount << endl;

	return 0;
}


Measured memory_bytes: 256
"""
https://atcoder.jp/contests/abc048/tasks/abc048_b
"""

a,b,x = map(int,input().split())

def f(n,d):
    if n == -1:
        return 0
    return n // d+1

print(f(b,x)-f(a-1,x))

"""
ans = 0

for i in range(a,b+1):
    if i % x == 0:
        ans += 1

print(ans)
"""

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n,l,a=0;
cin>>n>>l;
for(int i=1;i<=n;i++)
{
a+=i-1+l;
}
int ans=100000;
int res=0;
for(int i=1;i<=n;i++)
{
    if(ans>abs(a-(a-(i-1+l))))
    {
    ans=abs(a-(a-(i-1+l)));
    res=a-(i-1+l);
    }
}
cout<<res<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
ll euclidean_gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}


int main() {
  int n;
  cin >> n;
  vector<tuple<string,int,int>> resaurant(n);
  rep(i,n){
    string s;
    int p;
    cin >> s >> p;
    p=-p;
    resaurant[i] = make_tuple(s,p,i+1);
  }
  sort(resaurant.begin(),resaurant.end());
  rep(i,n){
    cout << get<2>(resaurant[i]) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
// AOJ 1201: Lattice Practices
// 2017.12.17 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { char a[6], b[6]; int diff; } T;
T p[10];
char *h[5], *v[5];
int diff[10];
int ans;

int check(int j)
{
	int i;
	for (i = 0; i < 5; i++) if (h[i][j] == v[j][i]) return 0;
	return 1;
}

void solve(int k, int s)
{
	int i, j, bit;

	if (k == 10) { ans++; return; }
	for (bit = 1, i = 0; i < 10; i++, bit <<= 1) {
		if (s & bit) continue;
		if (k < 5) {
			h[k] = p[i].a;
			solve(k+1, s | bit);
			if (diff[i]) {
				h[k] = p[i].b;
				solve(k+1, s | bit);
			}
		} else {
			j = k - 5;
			v[j] = p[i].a;
			if (check(j)) solve(k+1, s | bit);
			if (diff[i]) {
				v[j] = p[i].b;
				if (check(j)) solve(k+1, s | bit);
			}
		}
	}
}

int cmp(T *a, T *b)
{
	return a->diff - b->diff;
}

int main()
{
	int i, j;

	while(scanf("%s", p[0].a) && p[0].a[0] != 'E') {
		for (i = 1; i < 10; i++) scanf("%s", p[i].a);
		for (i = 0; i < 10; i++) {
			for (j = 0; j < 5; j++) p[i].b[j] = p[i].a[4-j];
			p[i].diff = (memcmp(p[i].a, p[i].b, 5) != 0);
		}
		qsort(p, 10, sizeof(T), cmp);
		for (i = 0; i < 10; i++) diff[i] = p[i].diff;

		ans = 0;
		solve(0, 0);
		printf("%d\n", ans >> 3);
	}
	return 0;
}

Measured memory_bytes: 1856
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int H[] = new int[N];
        for (int i = 0; i < N; i++) {
            H[i] = s.nextInt();
        }

        int longestStreak = 0;
        int streak = 0;
        int h = H[0];
        for (int i = 1; i < N; i++) {
            if (H[i-1] >= H[i]) {
                streak += 1;
            } else {
                if (longestStreak < streak) {
                    longestStreak = streak;
                }
                streak = 0;
            }
        }
        if (longestStreak < streak) {
            longestStreak = streak;
        }

        System.out.println(longestStreak);
    }

}

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

const int mod = 1e9 + 7;

void add(int &x,int y) {
	x += y; if (x >= mod) x -= mod;
}

int n;
int a[21][21];
int f[1 << 21];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			scanf("%d", &a[i][j]);
		}
	}
	f[0] = 1;
	for (int mask = 0; mask < (1 << n); ++mask) {
		int id = __builtin_popcount(mask);
		for (int i = 0; i < n; ++i) {
			if (mask & (1 << i)) {
				continue;
			}
			if (a[id][i] == 0) {
				continue;
			}
			add(f[mask | (1 << i)], f[mask]);
		}
	}
	printf("%d\n", f[(1 << n) - 1]);
}

Measured memory_bytes: 8448
n = int(input())
s = input()
num = [0]*n
numset = set()
for i in range(n-1, 1, -1):
    numset.add(s[i])
    num[i] = len(numset)

ans = 0
ex_1 = [False]*10
for i in range(n-2):
    c1 = s[i]
    if ex_1[int(c1)]:
        continue
    ex_1[int(c1)] = True
    ex_2 = [False]*10
    for j in range(i+1, n-1):
        c2 = s[j]
        if ex_2[int(c2)]:
            continue
        ex_2[int(c2)] = True
        ans += num[j+1]
print(ans)

Measured memory_bytes: 42092
import sys

def solve():
    input = sys.stdin.readline
    Rate = [0] * 9
    N = int(input())
    A = [int(a) for a in input().split()]
    for a in A: Rate[min(8, a // 400)] += 1
    count = 0
    for i in range(8):
        if Rate[i] > 0: count += 1
    minC, maxC = count, count + Rate[8]
    if count == 0: minC = 1
    print(minC, maxC)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <queue>
using namespace std;
int main(){
	string S; cin >> S; 
	string ans = "Yes"; 
	for(int i = 0; i < S.size(); i++){
		if(i % 2 == 0 && S.at(i) == 'L') ans = "No"; 
		if(i % 2 == 1 && S.at(i) == 'R') ans = "No"; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
import Data.List
mo=998244353
main=do
 getLine
 d<-map read.words<$>getLine
 let c=f 0 0$sort d
 print$if head d/=0||head c/=1 then 0 else foldl1(\a b->a*b`mod`mo)$zipWith power c$tail c
power a n
 |n==0=1
 |even n=power(a*a`mod`mo)(div n 2)
 |odd n=a*(power a$n-1)`mod`mo
f i c[]=[c]
f i c(d:ds)
 |i==d=f i(c+1)ds
 |i/=d=c:f(i+1)0(d:ds)

Measured memory_bytes: 29052
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<ctime>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0;
string s;
bool flag;

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


int main(void) {
  ll a, b;

  cin >> n >> a >> b;

  while (1) {
	if (a + 1 != b) {
	  a++;
	}
	else {
	  cout << "Borys" << endl;
	  return 0;
	}

	if (b - 1 != a) {
	  b--;
	}
	else {
	  cout << "Alice" << endl;
	  return 0;
	}

  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int n;
  cin>>n;
  int cnt=0;
  string A[n];
  int B[n];
  string x;
  for(int i=0;i<n;i++)
  {
    cin>>A[i]>>B[i];
  }
  cin>>x;
  int p=0;
  for(int i=0;i<n;i++)
  {
    if(A[i] == x)
    {
      p=i;
    }
  }
  for(int i=(p+1);i<n;i++)
  {
  	cnt=cnt+B[i];
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
 
#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
typedef long long ll;
using namespace std;

string a;
ll ans,cnt[26];

ll c(ll x,ll y){
	if(x<y)return 0;
	ll ans=1;
	lp(y){
		ans*=x-i;
		ans/=(i+1);
	}
	return ans;
}

int main(){
	cin>>a;
	lp(26)
		cnt[i]=0;
	lp(a.size())
		cnt[a[i]-'a']++;
	ans=c(a.size(),2);
	lp(26)
		ans-=c(cnt[i],2);
	cout<<ans+1<<endl;
	return 0;
}

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

#define ld			long double
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD         1000000007
#define sd(t) 		scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii 		cout << "hii" << endl
#define okay 		cout << "okay" << endl
#define hey 		cout << "hey" << endl

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int inf = 1e18;
const int mod = 1e9+7;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
} 

clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

const int N = 1e5+5;
int arr[N];

void solve()
{
    string s;
    cin >> s;
    if(s=="ABC"){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }
}			 	      		        

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    L=[[0,0,0]for _ in range(N)]
    for i in range(N):
        a,b=MI()
        L[i]=[a+b,a,b]
        
    L.sort(reverse=True)
    
    a=0
    b=0
    for i in range(N):
        if i%2==0:
            a+=L[i][1]
        else:
            b+=L[i][2]
            
    print(a-b)

main()


Measured memory_bytes: 94160
#include <bits/stdc++.h>
using namespace std;
int main(){
  int L, R;
  cin >> L >> R;
  L--;
  if (L / 2019 != R / 2019){
    cout << 0 << endl;
  } else {
    long long ans = 2019;
    for (long long i = L + 1; i <= R; i++){
      for (long long j = i + 1; j <= R; j++){
        ans = min(ans, i * j % 2019);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
from bisect import bisect_left

n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(l, l[small] + l[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)

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

int main() {
	int N;
	cin >> N;
	int a[N];
	bool b[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		b[i] = false;
	}
	int i = 0, cnt = 0;
	while (true) {
		if (i == 1) {
			cout << cnt << endl;
			return 0;
		} else if (b[i]) {
			cout << -1 << endl;
			return 0;
		}
		b[i] = true;
		i = a[i] - 1;
		cnt++;
	}
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)

int main()
{
   ll n,r;
   cin>>n>>r;
  if(n<10)
   cout<<r+1000-100*n;
  else
    cout<<r;
}


Measured memory_bytes: 256
n = int(input())
cards = [input().split() for i in range(n)]
for mark in ["S", "H", "C", "D"]:
    cards_mark = [cards[i][1] for i in range(n) if mark in cards[i]]
    loss = [i for i in range(1,14) if str(i) not in cards_mark]
    for j in range(len(loss)):
        print("{} {}".format(mark, loss[j]))


Measured memory_bytes: 5608
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 200001;
int main()
{
  int n,i,j,c=0;
  int a[N_MAX],b[N_MAX],ca[N_MAX],cb[N_MAX];
  cin >> n;
  fill(ca+1,ca+n+1,0);
  fill(cb+1,cb+n+1,0);
  for(i=0;i<n;i++){
    cin >> a[i];
    ca[a[i]]++;
  }
  for(i=0;i<n;i++){
    cin >> b[i];
    cb[b[i]]++;
  }
  for(i=1;i<=n;i++)
    if(ca[i]+cb[i]>n){
      cout << "No" << endl;
      return 0;
    }
  cout << "Yes" << endl;
  for(i=0;i<n;i++){
    if(a[i]!=b[i])
      continue;
    if(b[i]!=c){
      j=0;
      c=b[i];
    }
    for(;j<n;j++)
      if(a[j]!=c&&b[j]!=c){
        b[i]=b[j];
        b[j]=c;
        j++;
        break;
      }
  }
  for(i=0;i<n;i++)
    cout << b[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 6748
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  stack<int> s1;
  stack<pair<int,int>> s2;
  char ch;
  int sum=0;
  for(int i=0;cin>>ch;i++){
    if(ch=='\\') s1.push(i);
    else if (ch=='/' && s1.size() >0){
      int j=s1.top();
      s1.pop();
      sum += i-j;
      int a=i-j;
      while(s2.size()>0 && s2.top().first > j){
        a+=s2.top().second;
        s2.pop();
      }
      s2.push(make_pair(j,a));
    }
  }
  
  vector<int> ans;
  while(s2.size() >0){
    ans.push_back(s2.top().second);
    s2.pop();
  }
  reverse(ans.begin(),ans.end());
  cout<<sum<<endl;
  cout<<ans.size();
  for(int i=0;i<ans.size();i++){
    cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  
  return 0;
}     


Measured memory_bytes: 3236
N = int(input())
words = [input().strip() for _ in range(N)]

def solve(words):
  s = {words[0]}
  for p, w in zip(words, words[1:]):
    if p[-1] != w[0]:
      return "No"
    if w in s:
      return "No"
    s.add(w)
  return "Yes"

print(solve(words))

Measured memory_bytes: 3060
mod=round(1e9+7)

r,c = list(map(int, input().split()))
mat = []
for i in range(r):
    mat.append(list(input()))
dp=[]
for i in range(r):
    dp.append([0]*(c))
for i in range(r):
    if mat[i][0]=='#':
        break
    else:
        dp[i][0]=1
for i in range(c):
    if mat[0][i]=='#':
        break
    else:
        dp[0][i]=1
for i in range(1,r):
    for j in range(1,c):
        if mat[i][j]=='#':
            dp[i][j]=0
        else:
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod
print(dp[r-1][c-1])
    


Measured memory_bytes: 151004
while 1:
    m, n = input().split()
    if m == "0" and n == "0":
        break
    for i in range(int(m)):
        for j in range(int(n)):
            if i == 0 or j == 0 or i == int(m)-1 or j == int(n)-1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()

Measured memory_bytes: 9120
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
int n,a[3][105],res,ans;
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	for(int i=1;i<=2;i++)
	for(int j=1;j<=n;j++)
	cin>>a[i][j];
	for(int i=1;i<=n;i++)
	res+=a[1][i];
	res+=a[2][n];
	ans=res;
	for(int i=n;i>=2;i--){
		res-=a[1][i];
		res+=a[2][i-1];
		ans=max(ans,res);
	}
	cout<<ans;
	//system("pause");
	return 0;
}

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

int main() {
  string A,B,C;
  cin >> A;
  cin >> B;
  cin >> C;
  char turn = 'a';
  char answer;
  for(int i = 0;i < 300;i++) {
    if(turn == 'a') {
      if(A.size() == 0) {
        answer = 'A';
      }
      else {
        if(A.at(0) == 'a') {
          turn = 'a';
        }
        else if(A.at(0) == 'b') {
          turn = 'b';
        }
        else {
          turn = 'c';
        }
        A.erase(A.begin());
      }
    }
    
    if(turn == 'b') {
      if(B.size() == 0) {
        answer = 'B';
      }
      else {
        if(B.at(0) == 'a') {
          turn = 'a';
        }
        else if(B.at(0) == 'b') {
          turn = 'b';
        }
        else {
          turn = 'c';
        }
        B.erase(B.begin());
      }
    }
    
    if(turn == 'c') {
      if(C.size() == 0) {
        answer = 'C';
      }
      else {
        if(C.at(0) == 'a') {
          turn = 'a';
        }
        else if(C.at(0) == 'b') {
          turn = 'b';
        }
        else {
          turn = 'c';
        }
        C.erase(C.begin());
      }
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

string merge(string a, string b) {
	int al = a.length(), bl = b.length();
	string res = a+b;
	FOR(i, 1, min(al, bl)) {
		string as = a.substr(al-i);
		string bs = b.substr(0, i);
		if(as == bs) {
			res = a+b.substr(i);
		}
	}
	return res;
}

int diffstr(string a, string b) {
	return merge(a, b).length()-a.length();
}

int main() {
	int N;
	while(cin >> N, N) {
		vs data(N);
		REP(i, N) {
			cin >> data[i];
		}

		vs city;
		REP(i, N) {
			bool ok = true;
			REP(j, N) {
				if(i != j && data[j].find(data[i]) != string::npos) {
					ok = false;
					break;
				}
			}
			if(ok) {
				city.push_back(data[i]);
			}
		}

		N = city.size();
		vvi diff(N, vi(N));
		REP(i, N) {
			REP(j, N) {
				diff[i][j] = diffstr(city[i], city[j]);
			}
		}

		vvi dp(1<<N, vi(N, INF));
		REP(i, 1<<N) {
			if(i == 0) {
				REP(j, N) {
					dp[1<<j][j] = city[j].length();
				}
				continue;
			}

			REP(j, N) {
				if(i&(1<<j)) {
					REP(k, N) {
						if(j != k && !(i&(1<<k))) {
							dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k], dp[i][j]+diff[j][k]);
						}
					}
				}
			}
		}

		int ans = INF;
		REP(i, N) {
			ans = min(ans, dp[(1<<N)-1][i]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2588
package main

import (
	"fmt"
	"sort"
)

type Diff struct {
	S int
	E int
	V int
}

type ByValue []Diff

func (a ByValue) Len() int           { return len(a) }
func (a ByValue) Less(i, j int) bool { return a[i].V > a[j].V }
func (a ByValue) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	var N, M int
	fmt.Scan(&N)
	fmt.Scan(&M)

	nums := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&nums[i])
	}
	sort.Ints(nums)
	// fmt.Println("")
	// fmt.Println(nums)

	if N >= M {
		fmt.Println(0)
		return
	}

	diff := make([]Diff, M-1)
	for i := 0; i < M-1; i++ {
		diff[i] = Diff{i, i + 1, nums[i+1] - nums[i]}
	}
	// sort.Slice(diff, func(i, j int) bool { return diff[i].V > diff[j].V })
	sort.Sort(ByValue(diff))
	// fmt.Println(diff)

	parts := []int{0}
	for i := 0; i < N-1; i++ {
		parts = append(parts, diff[i].E)
	}
	parts = append(parts, len(nums)-1)
	sort.Ints(parts)
	// fmt.Println(parts)

	sum := 0
	var i int
	for i = 0; i < len(parts)-2; i++ {
		sum += nums[parts[i+1]-1] - nums[parts[i]]
	}
	sum += nums[len(nums)-1] - nums[parts[i]]

	fmt.Println(sum)
}

Measured memory_bytes: 7936
/* Written in FCP - alpha version */
#ifdef false
/* Original code */
$i
n:int
s:str
$p
int w=0, r=n-1, ans=0
while w<r {
    if s[w] == 'R' {
        w++
        continue
    } elif (s[r] == 'W') {
        r--
        continue
    }
    swap(s[w], s[r])
    ans++
}
<<ans
#endif
/* Transpiled code */

#include <bits/stdc++.h>

#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second

using namespace std;

using str = string;
using uint = unsigned int;
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<str>;
using vvs = vector<vector<str>>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

template<typename T>
std::ostream& operator<<(std::ostream& s, std::vector<T> t) {
    for (int i = 0; i < sz(t); i++) {
        s << t[i] << (i == sz(t) - 1 ? "" : " ");
    }
    return s;
}



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

    
        int n;
cin >> n;
str s;
cin >> s;
int w=0, r=n-1, ans=0;
while (w<r) {
    if (s[w] == 'R') {
        w++;
        continue;
    } else if (s[r] == 'W') {
        r--;
        continue;
    };
    swap(s[w], s[r]);
    ans++;
};
cout <<ans;
        goto end_tc_label;
        end_tc_label:;
    
}


Measured memory_bytes: 3768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// Nの入力
		int N = sc.nextInt();
		
		// diの入力
		int[] d = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
		
		// 回復量の総和の計算
		int sum = 0;
		for (int i = 0; i < N-1; i++) {
			for (int j = i+1; j < N; j++) {
				sum += d[i] * d[j];
			}
		}
		
		// 結果の出力
		System.out.println(sum);
		
		sc.close();
	}

}


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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for(T &x : vec)
        is >> x;
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n, l;
    cin >> n >> l;

    ll ans = 0;
    ll rem = (1 << 30);
    vi a(n);
    REP(i, n) {
        // cout << l << " ";
        ans += l;
        if(abs(rem) > abs(l))
            rem = l;
        l++;
    }

    cout << ans - rem << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  ll n;
  cin >> n;
  ll arr[n];
  for(ll i=0;i<n;i++)
    cin >> arr[i];
  sort(arr,arr+n);
  // for(ll i=0;i<n;i++)
  //   cout << arr[i] << ' ';
  // cout << endl;
  ll s=0;
  ll a=0;
  while(s<n){
    if(arr[s]==arr[s+1] && s<n){
      ll c=0;
      ll k=arr[s];
      while(arr[s]==k && s<n){
        s++;
        c++;
      }
      // cout << arr[s] << ' ' << c << endl;
      if(c%2!=0)
        a++;
    }
    else{
      a++;
      s++;
    }
    // cout << a << endl;
  }
  cout << a << endl;
  return 0;
}


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

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

#define ff first
#define ss second
#define pb push_back
#define sz size()

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
int n;
std::vector<ll> v;
void call(int i, int p, ll num, bool taken = 1){
  if(i == n){
    if(taken)v.pb(num);
    return;
  }
  if(!taken){
    for(int cur = 1; cur < 10; cur++)call(i + 1, cur, cur, 1);
    call(i + 1, p, num, 0);
  }
  else {
    call(i + 1, p, num * 10LL + p);
    if(p + 1 < 10)call(i + 1, p + 1, num * 10LL + (p + 1));
    if(p - 1 >= 0)call(i + 1, p - 1, num * 10LL + (p - 1));
  }
}

int main() {

  n = 10;
  call(0, 0, 0, 0);
  sort(v.begin(), v.end());

  int k;
  cin >> k;
  cout << v[k - 1] << endl;

  return 0;
}

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

int main(){

    long long n, a, tmp;
    cin >> n >> a;

    for (int i = 0; i < 4; i++) {
        cin >> tmp;
        if(tmp < a) a = tmp;
    }

    cout << (n + (a-1)) / a + 4 << endl;
    return 0;

}

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

int main(){

  
  
  int n,q;
  cin>>n>>q;

  vector<int> A(n,0);
  priority_queue< pair<int,int> > Q;
  
  for(int i=0;i<n;i++){
    Q.push( make_pair(0,-i) );
  }
  
  for(int i=0;i<q;i++){
    int a,v;
    cin>>a>>v;
    a--;
    A[a]+=v;
    Q.push( make_pair( A[a], -a) );

    pair<int,int> ans;
    while(1){
      ans=Q.top();
      if(ans.first==A[-ans.second]){
        break;
      }else{
        Q.pop();
      }
    }

    cout<<-ans.second+1<<' '<<ans.first<<endl;
  }
  return 0;
}

Measured memory_bytes: 23152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}
 
int main() {
    FAST_IO();
    int N, M; cin >> N >> M;
    vector<pii> X(N);
    rep(i, N) cin >> X[i].first >> X[i].second;
    sort(all(X));
    priority_queue<int, vector<int>, less<int>> PQ;
    int score = 0, idx = 0;
    for(int day = M - 1; day >= 0; --day) {
        while(idx < N && X[idx].first <= M - day) {
            PQ.push(X[idx++].second);
        }
        if(!PQ.empty()) {
            score += PQ.top();
            PQ.pop();
        }
    }
    cout << score << "\n";
}

Measured memory_bytes: 1660
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
using namespace std;
typedef long long ll;

int main(){
    int n,m; cin>>n>>m;
    vector<pair<int,int>> p(m);
    for(int i=0;i<m;i++){
        int s,c; cin>>s>>c;
        if(s==1&&c==0&&n!=1){
            cout<<-1<<endl;
            return 0;
        }
        p[i]=make_pair(s,c);
    }

    for(int i=0;i<m;i++){
        for(int j=i+1;j<m;j++){
            if(p[i].first==p[j].first){
                if(p[i].second!=p[j].second){
                    cout<<-1<<endl;
                    return 0;
                }
                p[j].second=0;
            }
        }
    }

    int ans=0;

    for(int i=0;i<m;i++){
        ans+=p[i].second*pow(10,n-p[i].first);
    }
    if(ans<pow(10,n-1)&&n!=1) ans+=pow(10,n-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
    int a, b, d, r;
    double f;
    
    scanf("%d %d", &a, &b);
    
    if(a < 1 || b > pow(10,9)) return 0;
    
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
    
    printf("%d %d %.16f", d, r, f);
    return 0;
}

Measured memory_bytes: 640