akhauriyash/Code-Regression huggingface dataset:
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
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();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int a,b,c;

main(){
	string s;
	cin>>a>>s>>b;
	char m=s[b-1];
	rep(i,a){
		if(s[i]!=m)s[i]='*';
	}
	dump(s);
}





Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int a[5];
	while(~scanf("%d,%d,%d,%d,%d",a,a+1,a+2,a+3,a+4)){
		sort(a,a+5);
		if(a[0]==a[3]||a[1]==a[4]){
			cout<<"four card"<<endl;
		}else if(a[0]==a[2]&&a[3]==a[4]||a[0]==a[1]&&a[2]==a[4]){
			cout<<"full house"<<endl;
		}else if((a[0]+1==a[1]||a[0]==1&&a[4]==13)&&a[1]+1==a[2]&&a[2]+1==a[3]&&a[3]+1==a[4]){
			cout<<"straight"<<endl;
		}else if(a[0]==a[2]||a[1]==a[3]||a[2]==a[4]){
			cout<<"three card"<<endl;
		}else if(a[0]==a[1]&&(a[2]==a[3]||a[3]==a[4])||a[1]==a[2]&&a[3]==a[4]){
			cout<<"two pair"<<endl;
		}else if(a[0]==a[1]||a[1]==a[2]||a[2]==a[3]||a[3]==a[4]){
			cout<<"one pair"<<endl;
		}else{
			cout<<"null"<<endl;
		}
	}
	return 0;
}

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

int A, B, C, K, ans;
cin >> A >> B >> C >> K;

ans = 0;

if (A < K){
  ans = A;
  K = K - A;
}
else{
  ans = K;
  K = 0;
}

if(K == 0){}
else if(K > B){
  K = K - B;
}
else{
  K = 0;
}

if(C = K){
  ans = ans - C;
}
else if(K > 0){
  ans = ans - K;
}

cout << ans << endl;

}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static int GCD(int a, int b)
    {
        var c = 1;
        while (c != 0)
        {
            c = a % b;
            a = b;
            b = c;
        }
        return a;
    }

    static void Main()
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split().Select(int.Parse).ToArray();

        var l = new int[N];
        l[0] = A[0];
        var r = new int[N];
        r[N - 1] = A[N - 1];
        for (int i = 1; i < N; i++)
        {
            l[i] = GCD(l[i - 1], A[i]);
        }
        for (int i = N - 2; i >= 0; i--)
        {
            r[i] = GCD(r[i+1], A[i]);
        }

        var ans = Max(l[N - 2], r[1]);
        for (int i = 1; i < N - 1; i++)
        {
            ans = Max(ans, GCD(l[i - 1], r[i + 1]));
        }
        WriteLine(ans);
    }
}


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

typedef vector<int> vi;

#define REPI(_i,len) for(int _i=0;_i<len;++_i)
#define REPI2(_i,_l,len) for(int _i=0,_l=len;_i<_l;++_i)
#define VREP(v,_itr,_end) for(auto _itr=v.begin(),_end=v.end();_itr!=_end;++_itr)
#define VCREP(v,_itr,_end) for(auto _itr=v.cbegin(),_end=v.cend();_itr!=_end;++_itr)

int abs(int x, int y) {
	return x >= 0 ? x : -x;
}

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

	vi h(N);
	VREP(h,itr,end)
		cin >> *itr;
	vi dps(N);
	REPI(i,N)
	{
		int min1 = 0; //i==0
		for (int j = 1, len = min(i, K); j <= len; ++j) {
			int dp1 = dps[i - j] + abs(h[i - j] - h[i]);
			if (j == 1 || dp1 < min1) {
				min1 = dp1;
			}
		}
		dps[i] = min1;
	}
	cout << dps[N - 1] << endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    vec.at(i) = a;
  }
  int a = vec.at(0);
  if(a == 2) {
    cout << '1' << endl;
  }
  else {
    for(int i = 0; i < N; i++) {
      a = vec.at(a - 1);
      if(a == 2) {
        cout << i + 2 << endl;
        break;
      }
      else if(i == N - 1) {
        cout << "-1" << endl;
      }
    }
  }
}

Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  double sum = 0;
  vector<pair<double, double>> Q;
  int head = 0;
  // deque<pair<double, double>> Q;
  for (int i = 0; i < n; ++i) {
    double T, V;
    scanf("%lf%lf", &T, &V);
    if (i > 0) {
      double rem = V;
      while (rem > 0) {
        if (Q[head].first > rem) {
          Q[head].first -= rem;
          sum -= rem * Q[head].second;
          break;
        } else {
          rem -= Q[head].first;
          sum -= Q[head].first * Q[head].second;
          ++head;
        }
      }
    }
    // trace(i);
    // for (auto& it : Q) {
    //   trace(it.first, it.second);
    // }
    while (head < Q.size() && Q.back().second > T) {
      double V2 = Q.back().first, T2 = Q.back().second;
      Q.pop_back();
      sum -= V2 * T2;
      T = (V2 * T2 + V * T) / (V2 + V);
      V += V2;
    }
    Q.push_back({V, T});
    sum += V * T;
    printf("%.10f\n", sum / m);
  }
  return 0;
}


Measured memory_bytes: 18536
import sys, os
import collections

def solve(input_stream):
  a,b,c = map(int,input_stream.readline().strip().split())
  ans = ""
  if a+b+c < 22:
    ans = "win"
  else:
    ans = "bust"
  return [ans]

if __name__ == "__main__":
    outputs = solve(sys.stdin)
    for line in outputs:
      print(line)

Measured memory_bytes: 3316
import sys

if sys.platform=='ios':
	sys.stdin=open('input_file.txt')

x=int(input())
k=x//11

if x==11*k:
	ans=2*k
elif 11*k<x and x<=11*k+6:
	ans=2*k+1
else:
	ans=2*(k+1)
print(ans)

Measured memory_bytes: 9100
#include <iostream>
using namespace std;
constexpr int M = 1000000007;

int main() {
    int n; cin >> n;
    int c[n]; for (int i = 0; i < n; i++) cin >> c[i];
    long long sum[200100] = {};
    long long ans = 1;
    sum[c[0]] = 1;
    for (int i = 1; i < n; i++) {
        if (c[i-1] == c[i]) continue;
        int temp = ans;
        ans = (ans + sum[c[i]]) % M;
        sum[c[i]] += temp;
    }
    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e15;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 1e5 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 1e6 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;


ll dp[101][101 * 1000];
int w[101], v[101];

void solve() {
    int n, W;
    cin >> n >> W;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j < 101 * 1000; ++j) {
            dp[i][j] = inf_ll;
        }
    }
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> w[i] >> v[i];
        sum += v[i];
    }

    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= sum; ++j) {
            dp[i][j] = dp[i - 1][j];
            if (j - v[i] >= 0) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
            }
        }
    }
    int ans = 0;
    for (int j = 0;j<=sum;++j){
        if(dp[n][j] <= W){
            ans = j;
        }
    }
    cout << ans<<"\n";


}

signed main() {
#ifdef zxc
    debug = 1;
    freopen("../input.txt", "r", stdin);
#else

#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(20);

    int t = 1;

    while (t--)
        solve();
    dout << endl << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}

Measured memory_bytes: 80000
line = gets.chomp

if line.match(/^k.*eyence$/) ||
    line.match(/^ke.*yence$/) ||
    line.match(/^key.*ence$/) ||
    line.match(/^keye.*nce$/) ||
    line.match(/^keyen.*ce$/) ||
    line.match(/^keyenc.*e$/) ||
    line.match(/^keyence.*$/) ||
    line.match(/.*keyence$/) ||
    line == 'keyence'
  puts 'YES'
else
  puts 'NO'
end


Measured memory_bytes: 1788
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class abc100c {
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        int res = 0;
        for (int i = 0, a; i < N; ++i) {
            in >> a;
            while (a % 2 == 0) {
                ++res;
                a /= 2;
            }
        }
        out << res << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	abc100c solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e2 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b;
	cin >> a >> b;
	if (a & b & 1) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

vector<P> d[100010];
ll Par[100010];
ll sa[100010];
bool arrived[100010];
vec ans;

ll dfs(ll x){
    ll count=0;
    arrived[x]=true;
    rep(i,d[x].size()){
        ll a=d[x][i].first, b=d[x][i].second;
        if(!arrived[a]){
            Par[a]=x;
            if(dfs(a)) {
                count++;
                ans.pb(b);
            }
        }
    }
    count+=sa[x];
    sa[x]=0;
    //cout<<x<<':'<<count%2<<endl;
    return count%2;
}

int main(){
    rep(i,100010) Par[i]=-1;
    ll N,M; cin>>N>>M;
    vector<P> dd;
    rep(i,N){
        ll A,B; cin>>A>>B;
        dd.pb(mp(A,B));
    }
    sort(ALL(dd));
    vec Z(N);
    vec sw(N+1,0);
    rep(i,N){
        Z[i]=dd[i].first;
        if(dd[i].second) sw[i]=1;
    }

    vector<P> kari;
    rep(i,M){
        ll l,r; cin>>l>>r;
        ll a=lower_bound(ALL(Z),l)-Z.begin();
        ll b=upper_bound(ALL(Z),r)-Z.begin();
        if(a!=b) {d[a].pb(mp(b,i+1)); d[b].pb(mp(a,i+1));}
        kari.pb(mp(a,b));
    }
    //rep(i,M) cout<<kari[i].first<<'|'<<kari[i].second<<endl;
    

    
    rep(i,N+1){
        if(i==0) sa[i]=sw[i];
        else if(sw[i]!=sw[i-1]) sa[i]=1;
    }

    bool able=true;
    rep(i,N+1){
        if(Par[i]==-1) {
            ll x=dfs(i);
            //cout<<i<<':'<<x<<endl;
            if(x!=0) able=false;
        }
    }

    sort(ALL(ans));
    if(!able) cout<<-1<<endl;
    else {
        cout<<ans.size()<<endl;
        rep(i,ans.size()) cout<<ans[i]<<' ';
        cout<<endl;
    }


}

Measured memory_bytes: 27884
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    int i,j=0,k=0;
    j=(n*(n-1))/2;
    k=(m*(m-1))/2;
    cout<<(j+k)<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
vector<vector<int>> g;
int n, m;
void dfs(int p) {
    for(int v : g[p]) {
        if(v==n-1) {cout << "POSSIBLE" << endl; exit(0);}
    }
}

int main() {
    cin >> n >> m;
    g.assign(n, vector<int>());
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int v : g[0]) dfs(v);
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 12288
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    from collections import defaultdict
    ans=defaultdict(int)
    for _ in range(int(input())):
        ans[input()]+=1
    print('AC x '+str(ans['AC']))
    print('WA x '+str(ans['WA']))
    print('TLE x '+str(ans['TLE']))
    print('RE x '+str(ans['RE']))
    


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 69852
def fac(n):  #nは2以上
    a=[]
    t=n
    if t%2==0:
        count=0
        while t%2==0:
            count+=1
            t//=2
        a.append([2,count])

    for i in range(3,n+1,2):
        if i*i>n:
            break
        if t%i==0:
            count=0
            while t%i==0:
                count+=1
                t//=i
            a.append([i,count])

    if t!=1:
        a.append([t,1])
    
    return a

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())

    d=dict()
    for i in range(1,n+1):
        li=fac(i)
        for p in li:
            if p[0] not in d:
                d[p[0]]=p[1]
            else:
                d[p[0]]+=p[1]

    cnt_75=0
    cnt_25=0
    cnt_15=0
    cnt_5=0
    cnt_3=0
    for v in d.values():
        if v>=74:
            cnt_75+=1; cnt_25+=1; cnt_15+=1; cnt_5+=1; cnt_3+=1
        elif v>=24:
            cnt_25+=1; cnt_15+=1; cnt_5+=1; cnt_3+=1
        elif v>=14:
            cnt_15+=1; cnt_5+=1; cnt_3+=1
        elif v>=4:
            cnt_5+=1; cnt_3+=1
        elif v>=2:
            cnt_3+=1

    ans=0
    ans+=cnt_75
    ans+=cnt_25*(cnt_3-1)
    ans+=cnt_15*(cnt_5-1)
    ans+=cnt_5*(cnt_5-1)//2*(cnt_3-2)
    print(ans)

if __name__=="__main__":
    main()

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;
const double PI = 3.14159265359;

int n;
int a[N];

int main() {

	FAST;

	int r;
	cin >> r;
	double ans = 2 * PI * r;
	cout << setprecision(9) << fixed << ans << '\n';
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int,int> l;
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for(int i = 0; i < N; i++) {
    l[i + A.at(i)]++; //アクセスしたときに0を追加してインクリメント
  }
  ll ans=0;
  for(int i = 0; i < N; i++) {
    ans += l[i - A.at(i)];
  }
  cout << ans << endl;
}


Measured memory_bytes: 21128
#include <bits/stdc++.h>
#define change_read() freopen("C:\\Users\\ACM2018\\Desktop\\in.txt","r",stdin)
#define change_write() freopen("C:\\Users\\ACM2018\\Desktop\\out.txt","w",stdout)
#define creat_read() freopen("C:\\Users\\ACM2018\\Desktop\\in.txt","w",stdout)
using namespace std;
const int maxm = 2e5+10;
struct p{
    int ind;
    long long x;
}mat1[maxm],mat2[maxm];
bool cmp(p a,p b){
    return a.x<b.x;
}
struct e{
    int from,to;
    long long val;
}edge[maxm<<4];
bool cmp2(e a,e b){
    return a.val<b.val;
}
int pre[maxm];
int fin(int a){
    return a==pre[a]?a:(pre[a]=fin(pre[a]));
}
long long uni(int a,int b,long long val){
    int aa = fin(a);
    int bb = fin(b);
    if(aa==bb) return 0;
    pre[aa] = bb;
    return val;
}
int main(){
//    change_read();
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++){
        pre[i] = i;
        scanf("%lld%lld",&mat1[i].x,&mat2[i].x);
        mat1[i].ind = mat2[i].ind = i;
    }

    sort(mat1+1,mat1+n+1,cmp);
    sort(mat2+1,mat2+n+1,cmp);
    if(n==2){
        cout<<min(abs(mat1[2].x-mat1[1].x),abs(mat2[2].x-mat2[1].x))<<endl;
        return 0;
    }
    int flag = 0;
    for(int i = 2;i<n;i++){
        edge[flag++] = e{mat1[i].ind,mat1[i-1].ind,abs(mat1[i].x-mat1[i-1].x)};
        edge[flag++] = e{mat1[i].ind,mat1[i+1].ind,abs(mat1[i].x-mat1[i+1].x)};
        edge[flag++] = e{mat2[i].ind,mat2[i-1].ind,abs(mat2[i].x-mat2[i-1].x)};
        edge[flag++] = e{mat2[i].ind,mat2[i+1].ind,abs(mat2[i].x-mat2[i+1].x)};
    }
    long long ans = 0;
    sort(edge,edge+flag,cmp2);
    for(int i = 0;i<flag;i++){
        ans=ans+uni(edge[i].from,edge[i].to,edge[i].val);
    }
    printf("%lld\n",ans);
    return 0;
}













Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n, dist[110][110];
vector<int> G[110];
lint cnt[110];

void dfs(int v, int pv, int d){
    chmax(cnt[d], (lint)G[v].size()-1);
    for(int nv: G[v])if(nv != pv){
        dfs(nv, v, d+1);
    }
}

int main(){
    scanf("%d", &n);
    if(n == 2){
        printf("%d %d\n", 1, 2);
        return 0;
    }
    rep(i, n){
        rep(j, n) dist[i][j] = MAX;
        dist[i][i] = 0;
    }
    rep(i, n-1){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
        dist[a][b] = dist[b][a] = 1;
    }
    rep(k, n)rep(i, n)rep(j, n) chmin(dist[i][j], dist[i][k] + dist[k][j]);

    pair<int, lint> ans = {MAX, INF};
    rep(i, n){
        int col = 1;
        rep(k, n) chmax(col, dist[i][k] + 1);

        memset(cnt, 0LL, sizeof(cnt));
        dfs(i, -1, 0);
        lint num = G[i].size();
        For(d, 1, n)if(cnt[d]) num *= cnt[d];
        chmin(ans, {col, num});
    }
    rep(i, n)For(j, i+1, n)if(dist[i][j] == 1){
        int col = 1;
        rep(k, n) chmax(col, min(dist[i][k], dist[j][k]) + 1);

        memset(cnt, 0LL, sizeof(cnt));
        dfs(i, j, 0);
        dfs(j, i, 0);
        lint num = (max(G[i].size(), G[j].size())-1) * 2;
        For(d, 1, n)if(cnt[d]) num *= cnt[d];
        chmin(ans, {col, num});
    }

    printf("%d %lld\n", ans.fi, ans.se);
}

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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int h, w; cin >> h >> w;
	int n; cin >> n;
	int a[10005];
	int b[10005];
	int c[105][105];
	rep(i, 0, n) cin >> a[i];
	int now = 0;
	rep(i, 0, n){
		rep(j, 0, a[i]){
			b[now+j] = i+1;
		}
		now += a[i];
	}
	now = 0;
	rep(i, 0, h){
		if(i%2==0){
			rep(j, 0, w){
				c[i][j] = b[now];
				now++;
			}
		}else{
			for(int j=w-1;j>=0;j--){
				c[i][j] = b[now];
				now++;
			}
		}
	}
	rep(i, 0, h){
		rep(j, 0, w){
			cout << c[i][j] << ' ';
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
    int n;
    scanf("%d", &n);

    unordered_map<int, int> c;
    for (int i = 0; i < n; ++ i) {
        int a;
        scanf("%d", &a);
        c[a] ++;
    }

    int res = 0;
    for (auto &e : c) {
        if (e.second & 1) res ++;
    }
    printf("%d\n", res);

    return 0;
}

Measured memory_bytes: 4388
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(200000)

N = int(raw_input())
tree = [[] for _ in xrange(N)]

for i in range(N-1):
    a, b, c = map(int, raw_input().split())
    a -= 1; b -= 1;
    tree[a].append((b, c))
    tree[b].append((a, c))

Q, K = map(int, raw_input().split())
K -= 1

depth = [0 for _ in xrange(N)]

def dfs(v, p = -1, d = 0):
    depth[v] = d
    for i, j in tree[v]:
        if i == p:
            continue
        dfs(i, v, d + j)

dfs(K)

for i in range(Q):
    x, y = map(int, raw_input().split())
    x -= 1; y -= 1
    print depth[x] + depth[y]

Measured memory_bytes: 144636
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

A = list(map(int, input().split()))
A.sort()
rA = list(reversed(A))

res = 10000
val = 0
for i in range(2):
    val += A[i+1] - A[i]
res = min(res, val)
for i in range(2):
    val += abs(rA[i+1] - rA[i])
res = min(res, val)
print(res)

Measured memory_bytes: 65600
#include<iostream>
using namespace std;
int N;
int a[300][300],A[300][300],tmp[300][300];
int v[300];
int T;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)cin>>a[i][j];
	for(int i=0;i<N;i++)A[i][i]=1;
	for(int i=0;i<N;i++)cin>>v[i];
	cin>>T;
	while(T)
	{
		if(T&1)
		{
			for(int i=0;i<N;i++)for(int j=0;j<N;j++)tmp[i][j]=A[i][j],A[i][j]=0;
			for(int i=0;i<N;i++)for(int j=0;j<N;j++)if(a[i][j]==1)
			{
				for(int k=0;k<N;k++)A[i][k]^=tmp[j][k];
			}
		}
		T>>=1;
		for(int i=0;i<N;i++)for(int j=0;j<N;j++)tmp[i][j]=a[i][j],a[i][j]=0;
		for(int i=0;i<N;i++)for(int j=0;j<N;j++)if(tmp[i][j]==1)
		{
			for(int k=0;k<N;k++)a[i][k]^=tmp[j][k];
		}
	}
	int id=0;
	for(int i=0;i<N;i++)
	{
		int now=-1;
		for(int j=id;j<N;j++)
		{
			if(A[j][i]==1)
			{
				now=j;
				break;
			}
		}
		if(now==-1)continue;
		if(id<now)
		{
			for(int j=0;j<N;j++)swap(A[id][j],A[now][j]);
			swap(v[id],v[now]);
		}
		for(int j=0;j<N;j++)if(j!=id&&A[j][i]==1)
		{
			for(int k=0;k<N;k++)A[j][k]^=A[id][k];
			v[j]^=v[id];
		}
		id++;
	}
	if(id==N)
	{
		for(int i=0;i<N;i++)cout<<v[i]<<(i+1==N?"\n":" ");
	}
	else
	{
		bool ok=true;
		for(int i=0;i<N;i++)if(v[i]==1)
		{
			bool now=false;
			for(int j=0;j<N;j++)if(A[i][j]==1)now=true;
			if(!now)
			{
				ok=false;
				break;
			}
		}
		cout<<(ok?"ambiguous":"none")<<endl;
	}
}



Measured memory_bytes: 4164
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int field[6][6] = {0},a,next_x = 1,next_y = 0,t = 2;
  for(int i=0; i<5; i++){
    for(int j=0; j<4; j++){
      scanf("%1d",&a);
      field[j+1][i]+=(a<<2);
      field[j+1][i+1]+=(a<<0);
    }
    if(i<4){
      for(int j=0; j<5; j++){
	scanf("%1d",&a);
	field[j][i+1]+=(a<<1);
	field[j+1][i+1]+=(a<<3);
      }
    }
  }
  for(;;){
    if(t == 1){
      if(field[next_x][next_y]&2){
	cout <<"U";
	if(field[next_x][next_y]&1){t = 8;}
	else{next_y--;}
      }
      else{next_x++;t = 2;}
    }
    else if(t == 2){
      if(field[next_x][next_y]&4){
	cout <<"R";
	if(field[next_x][next_y]&2){t = 1;}
	else{next_x++;}
      }
      else{next_y++;t = 4;}
    }
    else if(t == 4){
      if(field[next_x][next_y]&8){
	cout <<"D";
	if(field[next_x][next_y]&4){t = 2;}
	else{next_y++;}
      }
      else{next_x--;t = 8;}
    }
    else if(t == 8){
      if(field[next_x][next_y]&1){
	cout <<"L";
	if(field[next_x][next_y]&8){t = 4;}
	else{next_x--;}
      }
      else{next_y--;t = 1;}
    }
    if(!next_x && !next_y){break;}
  }
  cout <<endl;
  return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;

public class Main {

	public static void main(String args[]){
		Scanner cin = new Scanner(System.in);

		int target = cin.nextInt();
		String tmp = cin.next();
		cin.close();
		int x = 0;
		int max =0;
		for(int i=0;i<target;i++){
			if(tmp.charAt(i)=='I'){
				x++;
			}else{
				x--;
			}
			if(max<x){
				max = x;
			}
		}

		System.out.println(max);
	}
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
long long n,w,ans,dp[100005];
struct num{
	long long w,v;
}a[100005]; 
long long max(long long x,long long y) {
	if (x>y) return x;
	else return y;
}
bool cmp(num a,num b) {
	return a.w<b.w;
}

int main() {
	cin>>n>>w;
	for (int i=1;i<=n;i++) cin>>a[i].w>>a[i].v;
	sort(a+1,a+n+1,cmp);
	dp[0]=0;
	for (int i=1;i<=n;i++) 
		for (int j=w;j>=a[i].w;j--) 
			dp[j]=max(dp[j],dp[j-a[i].w]+a[i].v);
	for (int i=1;i<=w;i++) {
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}
/*
5 5
1 100000
1 100000
1 100000
1 100000
1 100000

500000
*/

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	
	int a,b,c,d;
	
	scanf("%d %d %d %d",&a,&b,&c,&d);
	
	if(a+b>c+d){
		printf("Left\n");
	}
	
	else if(a+b==c+d){
		printf("Balanced\n");
	}
	
	else{
		printf("Right\n");
	}
	
	
	return 0;
}

Measured memory_bytes: 128
object Main {

  import java.util.Scanner

  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    var str = scanner.next()
    var ref = 0
    val a = str.toInt
    str = scanner.next()
    val b = str.toInt
    str = scanner.next()
    val h = str.toInt

    ref = (a + b) * h / 2

    println(ref)

  }
}


Measured memory_bytes: 25784
// https://abc112.contest.atcoder.jp/tasks/abc112_b
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int input_N = Integer.parseInt(sc.next());
		int input_T = Integer.parseInt(sc.next());
 
        // programming
        int min_cost = Integer.MAX_VALUE;
        boolean is_found = false;
        for (int i = 0; i < input_N; i++) {
            int c = Integer.parseInt(sc.next());
            int t = Integer.parseInt(sc.next());
            if (t <= input_T && c < min_cost) {
                is_found = true;
                min_cost = c;
            }
        }

        if (is_found) {
            System.out.println(min_cost);
        } else {
            System.out.println("TLE");
        }
	}
}

Measured memory_bytes: 23508
#include <iostream>
#include <limits>
#include <set>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

using Z = long long;
constexpr Z INF = numeric_limits<Z>::max() / 3;

#ifdef DEBUG
# define dump(x) cerr << #x << " = " << (x) << endl
# define mesg(m) cerr << m << endl
# define debug if (true)
#else
# define NDEBUG
# define dump(x)
# define mesg(m)
# define debug if (false)
#endif
#define rep(i, n) for (auto i = 0; i < n; i++)
#define rrep(i, n) for (auto i = n; i >= 0; i--)
#define all(c) begin(c), end(c)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Z n, x;
  cin >> n >> x;
  Z total = x;
  Z t = n - x, w = n;
  while (true) {
    Z capacity = w / t, rest = w % t;
    dump(capacity);
    dump(rest);
    total += rest + (2 * capacity - 1) * t;
    if (rest == 0) {
      total -= t;
      break;
    }
    w = t;
    t = rest;
  }
  cout << total << endl;
}


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

int cnt0,cnt1,ans,n;
char s[300001];

int main()
{
	scanf("%d%s",&n,s+1);
	cnt0=cnt1=0;
	for (int i=1; i<=n; i++) if (s[i]=='.') cnt1++;
	ans=cnt1;
	for (int i=1; i<=n; i++)
	{
		if (s[i]=='.') cnt0++,cnt1--;
		ans=min(ans,i-cnt0+cnt1);
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int mod = 1e9 + 7, N, C, A[409], B[409], dp[409][409], s[409][409];

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int substract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}

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

scanf ("%d %d", &N, &C);
for (int i=1; i<=N; i++)
    scanf ("%d", &A[i]);
for (int i=1; i<=N; i++)
    scanf ("%d", &B[i]);
for (int i=1; i<=400; i++)
    s[0][i] = 1;
for (int i=1; i<=C; i++)
    for (int j=1; j<=400; j++)
        s[i][j] = mul (s[i - 1][j], j);
for (int i=0; i<=C; i++)
    for (int j=1; j<=400; j++)
        s[i][j] = add (s[i][j], s[i][j - 1]);
dp[0][0] = 1;
for (int i=1; i<=N; i++)
    for (int j=0; j<=C; j++)
        for (int k=0; k<=j; k++)
            dp[i][j] = add (dp[i][j], mul (dp[i - 1][j - k], substract (s[k][B[i]], s[k][A[i] - 1])));
printf ("%d\n", dp[N][C]);
return 0;
}


Measured memory_bytes: 1536
import java.util.HashMap;
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
	   Scanner sc = new Scanner(System.in);
	   HashMap <Integer, Integer>hm = new HashMap<Integer,Integer>();
	   
	   int n = sc.nextInt();
	   
	   for(int i =  0; i < n ;i++) {
		   int a = sc.nextInt();
		   if(!hm.containsKey(a)) {
			   hm.put(a, 1);
		   }
		   else {
			   hm.put(a, hm.get(a) + 1);
		   }
	   }
	   
	   int ans = 0;
		   
	   for(int num : hm.keySet()) {
		   if(num > hm.get(num)) {
			   ans += hm.get(num);
		   }
		   if(num <= hm.get(num)) {
			   ans += (hm.get(num) - num);
		   }
	   }

	   System.out.println(ans);

	}
}


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

using namespace std;

#define ll long long
#define INF 1e18L + 5

int findLCS(int m, int n, string &S, string &T, vector< vector<int> > &LCS)
{
	if(LCS[m][n]!=-1)
		return LCS[m][n];
	if(m==0 || n==0)
		LCS[m][n] = 0;
	else
	{
		LCS[m][n] = max(findLCS(m-1,n,S,T,LCS), findLCS(m,n-1,S,T,LCS));
		LCS[m][n] = max(LCS[m][n], (findLCS(m-1,n-1,S,T,LCS) + (S[m-1] == T[n-1])));
		// LCS[m][n] = max(findLCS(m-1,n,S,T,LCS), max(findLCS(m,n-1,S,T,LCS), (findLCS(m-1,n-1,S,T,LCS) + (S[m-1]==T[n-1])))
	}
	return LCS[m][n];
}

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

    string S,T;
    cin>>S>>T;

    vector< vector<int> > LCS(S.size()+1, vector<int>(T.size()+1,-1));

	int n = findLCS(S.size(),T.size(), S, T, LCS);

	vector<char> lcs(n);
	int i = S.size(), j = T.size();
	while(i>0 && j>0)
	{
		if(S[i-1]==T[j-1])
		{
			lcs[n-1] = S[i-1];
			i--;j--;n--;
		}
		else if (LCS[i-1][j]>LCS[i][j-1])
			i--;
		else j--;
	}
	for(i=0;i<lcs.size();i++)
		cout<<lcs[i];
	cout<<endl;
    return 0;
}


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

#define int long long

using namespace std;

const int MOD = 1e9 + 7;

int dp[101][100001];

signed main() {

    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= k; j++){
            dp[i - 1][j] += dp[i - 1][j - 1];
        }
        for(int j = 0; j <= k; j++){
                dp[i][j] = dp[i - 1][j];
                if(j - a[i] - 1 >= 0) dp[i][j] -= dp[i - 1][j - a[i] - 1];
                dp[i][j] %= MOD;
        }
    }
    cout << dp[n][k];
    return 0;
}


Measured memory_bytes: 82508
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

vector<int>E[300000];
int d[300000];

void dfs(int v,int p){
	for(int u:E[v]){
		if(u==p)continue;
		d[u]=d[v]+1;
		dfs(u,v);
	}
}

int dp[300000];

int rec(int v){
	if(dp[v]!=-1)return dp[v];
	if(v==0)return true;
	if(v-1>=0){
		if(!rec(v-1))return dp[v]=true;
	}
	if(v-2>=0){
		if(!rec(v-2))return dp[v]=true;
	}
	return dp[v]=false;
}
int main(){
	int n;cin>>n;
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	d[0]=0;
	dfs(0,-1);
	int id=max_element(d,d+n)-d;
	d[id]=0;
	dfs(id,-1);
	int c=*max_element(d,d+n);
	memset(dp,-1,sizeof(dp));
	if(rec(c))puts("First");
	else puts("Second");
}

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

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

void solve() {
    ll c[6];
    rep(i, 6) cin >> c[i];
    int v[] = {1, 5, 10, 50, 100, 500}    ;
    ll sum = 0;
    rep(i, 6) sum += c[i] * v[i];
    cout << (sum >= 1000 ? 1 : 0) << "\n";
}

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


Measured memory_bytes: 3216
#include <iostream>
#include <string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans;
	for (int i = a; i<=b; i++) {
		if (c%i == 0) {
			ans++;
		}
	}
	cout << ans << endl;
}



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

int main()
{
  int n, l;
  cin >> n >> l;

  int sum = 0;

  vector<int> apple(n);
  rep(i, n)
  {
    apple.at(i) = l + i;
    sum += apple.at(i);
    // cout << apple.at(i) << endl;
  }

  // cout << sum;

  int ans = 100000;

  for (int i = 0; i < n; i++)
  {
    int tmp = sum - apple.at(i);
    ans = min(abs(tmp - sum), ans);
  }

  rep(i, n)
  {
    if (ans == abs(apple.at(i)))
    {
      ans = i;
      break;
    }
  }
  cout << sum - apple.at(ans);
}


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

int main(){
  int n;
  cin>>n;
  vector<char> v(n);
  int R=0;
  for(int i=0;i<n;i++){
    cin>>v[i];
    if(v[i]=='R') R++;
  }
  int cntR=0;
  for(int i=0;i<R;i++){
    if(v[i]=='R') cntR++;
  }
  cout<<R-cntR;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n%1000==0)
    cout<<"0"<<endl;
    // else if(n%1000<=500)
    // cout<<n%1000<<endl;
    else
    cout<<1000-n%1000<<endl;
    return 0;
}

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

long long GetNumberOfPatties(long long x, long long d_l[], long long d_p[], long long n);

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

	int n;
	long long x;
	cin >> n >> x;

	long long d_l[n+1];
	d_l[0] = 1;
	for (int i = 1; i < n+1; ++i)
		d_l[i] = 2*d_l[i-1] + 3;

	long long d_p[n+1];
	d_p[0] = 1;
	for (int i = 1; i < n+1; ++i)
		d_p[i] = 2*d_p[i-1] + 1;

	cout << GetNumberOfPatties(x, d_l, d_p, n) << "\n";
	
	return 0;
}

long long GetNumberOfPatties(long long x, long long d_l[], long long d_p[], long long n)
{
	if (n == 0) return 1;

	if (x == 1) {
		return 0;
	} else if (x <= 1 + d_l[n-1]) {
		return GetNumberOfPatties(x-1, d_l, d_p, n-1);
	} else if (x == 2 + d_l[n-1]) {
		return d_p[n-1] + 1;
	} else if (x <= 2 + 2*d_l[n-1]) {
		return d_p[n-1] + 1 + GetNumberOfPatties(x-d_l[n-1]-2, d_l, d_p, n-1);
	} else if (x == 3 + 2*d_l[n-1]) {
		return 2*d_p[n-1] + 1;
	}

	cout << "err" << endl;
}


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

bool f(int p) {
    for (int i=2; i*i<=p; i++) {
        if (p % i == 0) return false;
    }
    return true;
}

int main() {
    int N;
    while (cin >> N) {
        int p1, p2;
        for (p1=N-1; ; p1--) if (f(p1)) break;
        for (p2=N+1; ; p2++) if (f(p2)) break;
        cout << p1 << " " << p2 << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<math.h>
#define N 10000
int primenum(int);
int main(){
  int a[N],b,i,num=0;
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d\n",&a[i]);
  }
  for(i=0;i<b;i++){
    if(primenum(a[i]))
      num++;
  }
  printf("%d\n",num);
  return 0;
}

int primenum(int c){
  int j;
  if(c==2)return 1;
  if(c%2==0 || c<2)return 0;
  j=3;
  while(j<=(int)sqrt(c)){
    if(c%j==0)return 0;
    j+=2;
  }
  return 1;
}

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

struct SCard
{
    char Name;
	int  Value;
};

vector<SCard> BubbleSort(vector<SCard> List);
vector<SCard> Selection(vector<SCard> List);
void Output(vector<SCard> List);
string IsStable(vector<SCard> Org, vector<SCard> After);

int main(){
    int n;
	vector<SCard> List;
	vector<SCard> TempList;
	
    cin >> n;
	
	//???????????\???
	for(int i = 0; i < n; i++){
		SCard Temp;
		cin >> Temp.Name;
		cin >> Temp.Value; 
		List.push_back(Temp);
	}
	TempList.clear();
	TempList = BubbleSort(List);
    Output(TempList);
	cout << IsStable(List, TempList) << endl;

    TempList.clear();
	TempList = Selection(List);
    Output(TempList);
	cout << IsStable(List, TempList) << endl;

}

vector<SCard>  BubbleSort(vector<SCard> List)
{
	for(int i = 0; i < List.size(); i++){
		for(int j = List.size() - 1; j > i; j--){
			if(List[j].Value < List[j-1].Value){
				SCard Temp = List[j];
				List[j] = List[j-1];
				List[j-1] = Temp;
			}
		}
	}
	return List;
}

vector<SCard> Selection(vector<SCard> List)
{
	for(int i = 0; i < List.size(); i++){
		int Min = i;
		for(int j = i; j < List.size(); j++){
			if(List[j].Value < List[Min].Value){
				Min = j;
			}
		}
		SCard Temp = List[i];
		List[i] = List[Min];
		List[Min] = Temp;
	}
	return List;
}

void Output(vector<SCard> List)
{
	for(int i = 0; i < List.size(); i++){
		if(i > 0) cout << " ";
		cout << List[i].Name << List[i].Value;
	}
	cout << endl;
}

string IsStable(vector<SCard> Org, vector<SCard> After)
{
	for(int i = 0; i < Org.size(); i++){
		for(int j = i + 1; j < Org.size(); j++){
			for(int a = 0; a < Org.size(); a++){
				for(int b = a + 1; b < Org.size(); b++){
					if(Org[i].Value == Org[j].Value && Org[i].Name == After[b].Name 
					&& Org[i].Value == After[b].Value && Org[j].Name == After[a].Name
					&& Org[j].Value == After[a].Value){
						return "Not stable";
					}
				}
			}
		}
	}
	return "Stable" ;
}

Measured memory_bytes: 1228
from bisect import bisect_right
from bisect import bisect_left

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
answer = 0
for i in range(N):
    x1 = bisect_left(A, B[i])
    x2 = bisect_right(C, B[i])
    # print(x1, x2, N)
    answer += x1 * (N - x2)

print(answer)

Measured memory_bytes: 23232
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;

 
int main() {
	
	int N;
	cin>>N;
map<int,int> H;
	fx(N){
		int a;
		cin>>a;
		H[a]++;
	}
	bool flag=true;
	for(pair<int,int> p:H){
		if(p.second!=2){
                    if(N%2==1){
                         if(!(p.first==0&&p.second==1)){
                   flag=false;
                  ce('0')
break;
                         }
                     }else{
                   flag=false;
                  ce('0')
break;
                    }
		}else if(p.first==0){
                   flag=false;
                  ce('0')
break;
               }
	}
	
	if(flag){
		ll ans=1;
		int n=N/2;
		while(n-->0){
			ans*=2;
			ans%=1000000007;
		}
		ce(ans)
	}
	
}

Measured memory_bytes: 3200
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 1e2 + 21;

int n, ans, lans, a[N];
int main() {
	scanf("%d", &n);
	ans = 1e9;
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (int i = 1; i <= 100; i++) {
		lans = 0;
		for (int j = 1; j <= n; j++) lans += (a[j] - i) * (a[j] - i);
		ans = std::min(ans, lans);
	}
	printf("%d", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
#define fr first
#define sc second
#define int ll

using namespace std;
const int MN = 3e3+7;
const int MA = 5e6+7;

int a[MN], cnt[5];
int dp[MN][MN];

signed main(){
    int n, k;
    cin >> n;
    for(int i = 0; i < n; i++)cin >> a[i];
    for(int z = 1; z <= n; z++){
        for(int l = 0; l < n-z+1; l++){
            int r = l+z-1;
            if(l == r){
                dp[l][r] = a[l];
                //cout << l << ' ' << r << " : " << dp[l][r] << endl;
                continue;
            }
            dp[l][r] = max(a[l] - dp[l+1][r], a[r] - dp[l][r-1]);
            //cout << l << ' ' << r << " : " << dp[l][r] << endl;
        }
    }
    cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 70016
import java.util.*;
public class Main{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = n-1; i >= 0; i--) {
            a[i] = sc.nextInt();
        }
        sc.close();
        for ( int i = 0; i < n; i++) {
            if(i>0) System.out.print(" ");
            System.out.print(a[i]);
        }
        System.out.println();


    }
}


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

namespace ConsoleApplication1
{
    class Edge
    {
        internal int to, cost;

        public Edge(int to, int cost)
        {
            this.to = to;
            this.cost = cost;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int V = int.Parse(input[0]);
            int E = int.Parse(input[1]);
            int r = int.Parse(input[2]);

            Dictionary<int, List<Edge>> nodeList = new Dictionary<int, List<Edge>>();
            for (int i = 0; i < V; i++) nodeList.Add(i, new List<Edge>());

            for (int i = 0; i < E; i++)
            {
                input = Console.ReadLine().Split(' ');
                int s = int.Parse(input[0]);
                int t = int.Parse(input[1]);
                int d = int.Parse(input[2]);

                nodeList[s].Add(new Edge(t, d));
            }

            BellmanFord(nodeList, r);

        }

        static void BellmanFord(Dictionary<int, List<Edge>> NL, int start)
        {
            int n = NL.Count, INFTY = int.MaxValue;

            int[] dp = Enumerable.Repeat(INFTY, n).ToArray();
            dp[start] = 0;

            bool isUpdate = true, isNegative = false;

            for (int cnt = 0; cnt < n; cnt++)
            {
                isUpdate = false;

                for (int i = 0; i < n; i++)
                {
                    int outDegree = NL[i].Count;
                    for (int j = 0; j < outDegree; j++)
                    {
                        Edge e = NL[i][j];

                        if (dp[i] != INFTY && dp[e.to] > dp[i] + e.cost)
                        {
                            dp[e.to] = dp[i] + e.cost;
                            isUpdate = true;
                        }
                    }
                }

                if (!isUpdate) break;
                if (cnt == n - 1) isNegative = true;
            }

            if (isNegative) Console.WriteLine("NEGATIVE CYCLE");
            else
            {
                StringBuilder sb = new StringBuilder();
                foreach (int d in dp)
                {
                    sb.AppendLine(d == INFTY ? "INF" : d.ToString());
                }
                Console.Write(sb);
            }
        }
    }
}

Measured memory_bytes: 10368