akhauriyash/Code-Regression huggingface dataset:
use std::io::*;

fn main() {
    let stdin = std::io::stdin();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut s = String::new();
    reader.read_line(&mut s).unwrap();
    let mut iter = s.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut k: usize = iter.next().unwrap().parse().unwrap();

    let mut arr = vec![];
    for _ in 0..n {
        let mut s = String::new();
        reader.read_line(&mut s).unwrap();
        let mut iter = s.split_whitespace();
        let a: usize = iter.next().unwrap().parse().unwrap();
        let b: usize = iter.next().unwrap().parse().unwrap();
        arr.push((a, b));
    }
    arr.sort();

    for (a, b) in arr {
        if k <= b {
            println!("{}", a);
            break;
        }
        k -= b;
    }
}


Measured memory_bytes: 6396
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {

	long long n;
	cin >> n;

	long long a = 'z' - 'a' + 1;
	string ret;
	while (n > 0) {
		char b = char(n % a);
		n /= a;
		if (--b < 0) {
			b = char(a) - 1;
			n -= 1;
		}
		ret += 'a' + b;
	}
	reverse(ret.begin(), ret.end());
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 3612
N = int(input())

data = [(0,0) for _ in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    data[i] = (a, b)

data.sort(key=lambda x:x[0])
data.sort(key=lambda x:x[1])

# print(data)

x = 0
flag = True
for i in range(N):
    a, b = data[i]
    x += a
    if x > b:
        flag = False

print('Yes' if flag else 'No')

Measured memory_bytes: 31888
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

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

    int A[n][m], b[m], c[n] = { 0 };
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            c[i] += A[i][j] * b[j];
        }
    }

    for (int i = 0; i < n; i++) {
        cout << c[i] << endl;
    }
}



Measured memory_bytes: 3132
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

#define LOCAL  1
#define UPLOAD 2

#define ll long long
const long long INF = 1LL << 60;

template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

const long long mod=1e9+7;
 
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
 
  ll N = input();
  ll M = input();
  map<ll, bool> a;

  for(ll i=0;i<M;i++){
    a[input()] = true;
  }

  vector<ll> dp;
  dp.resize(N+1, 0);
  dp[0] = 1;

  for(ll i=1;i<N+1;i++){
    if(a[i]){
      dp[i] = 0;
    }
    else{
      if(i > 1){
        dp[i] = (dp[i-1]%mod+dp[i-2]%mod)%mod;
      }
      else{
        dp[i] = dp[i-1]%mod;
      }
    }
  }
  
  
  output(dp[N] % mod);

  return 0;
}

Measured memory_bytes: 7296
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#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 <regex>

#define rep(i,n) for(int i = 0; i < n; i++)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"

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

constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

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

  int n;
  cin >> n;

  vector<int> h(n);
  rep(i,n) cin >> h[i];

  vector<int> dp(n, inf);
  dp[0] = 0;
  for (int i=1; i<n; i++) {
    int step1 = dp[i-1]+abs(h[i]-h[i-1]);
    if (i < 2) { dp[i] = step1; continue; }
    int step2 = dp[i-2]+abs(h[i]-h[i-2]);
    dp[i] = min(step1, step2);
  }

  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();
    string s;
    cin >> s;
    if (s.size() % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    int n = s.size();
    for (int i = 0; i < n; i += 2) {
        if (s.substr(i, 2) != "hi") {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.LongStream;

public class Main {
    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        try (Scanner in = new Scanner(System.in)) {
            int n = in.nextInt();
            long a[] = new long[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            long sum = LongStream.of(a).sum();
            long x = (long) (n + 1) * n / 2L;
            if (sum % x != 0) {
                System.out.println("NO");
                return;
            }
            long k = sum / x;
            for (int i = 0; i < n; ++i) {
                long d = a[i] - a[(i + 1) % n];
                if ((d + k) % n != 0 || (d + k) < 0) {
                    System.out.println("NO");
                    return;
                }
            }
            System.out.println("YES");
        }
    }

    void tr(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }
}


Measured memory_bytes: 37772
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 998244353;

void solve() {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for(ll i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    ll sum = 0;
    for(ll i = 0; i < k; i++) sum += a[i];
    cout << sum;
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

/*小数点以下の長さを指定
cout << fixed << setprecision(15) << y << endl;
*/

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}


int main() {
	string s;
	cin >> s;
	string ans;
	if (s == "ABC")ans = "ARC";
	else ans = "ABC";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
H,W=map(int, input().split())
A=[]
for i in range(H):
    a=list(map(int, input().split()))
    A.append(a)


ans=[]
count=0
for h in range(H):
    for w in range(W):
        if h%2==1:
            w=W-1-w
        if h==0 and w==0:
            px,py=0,0
            pre=0
            if A[h][w]%2==0:
                continue
            else:
                A[h][w]-=1
                pre=1
        else:
            if pre>0:
                A[h][w]+=pre
                pre=0
                ans.append([px+1,py+1,h+1,w+1])
                count+=1
            if A[h][w]%2==1:
                A[h][w]-=1
                pre=1
                px,py=h,w

#print(ans)
print(count)
for a in ans:
    print(*a)

Measured memory_bytes: 30244
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	vl A(N);
	REP(i,N) cin >> A[i];
	ll ma = A[0];
	ll ans = 0;
	FOR(i,1,N) {
		if (ma > A[i]) {
			ans += (ma - A[i]);
		} else {
			ma = max(ma, A[i]);
		}
	}
	cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 4780
N = int(input())
AB = 0
A = 0
B = 0
BA = 0
for i in range(N):
    s = list(input())
    for i in range(len(s)-1):
        if s[i] == 'A' and s[i+1] == 'B':
            AB += 1
    if s[-1] == 'A' and s[0] == 'B':
        BA += 1
    elif s[-1] == 'A':
        A += 1
    elif s[0] == 'B':
        B += 1
if BA == 0:
    AB += min(A,B)
elif A+B > 0:
    AB += BA + min(A,B)
else:
    AB += BA-1
print(AB)


Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main () {

  ll N;

  set<int> s;



  cin >> N;
  ll temp;
  REP(i, 0, N) {
    cin >> temp;
    s.insert(temp);
  }

  if (s.size() == (size_t)N) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 9600
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    H,N = map(int,input().split())
    # AB = [list(map(int,input().split())) for _ in range(N)]
    A = []
    B = []
    for i in range(N):
        temp = list(map(int,input().split()))
        A.append(temp[0])
        B.append(temp[1])

    # A = np.array(A)
    # B = np.array(B)

    maxA = max(A)
    INF = 10 ** 4 + 1

    dp = [[INF for j in range(H+maxA+1)] for i in range(N)]
    dp[0][0] = 0
    for j in range(1,H+maxA+1):
        time = (j+A[0]-1)//A[0]
        dp[0][j] = B[0] * time

    for i in range(N-1):
        for j in range(H+maxA+1):
            dp[i+1][j] = min(dp[i][j],dp[i+1][j-A[i+1]]+B[i+1])

    res = min(dp[N-1][H:])
    print(res)





main()


Measured memory_bytes: 133512
#include<cstdio>
#include<algorithm>

using namespace std;

const int MAX_N = 300010;

int n;
int a[MAX_N];
int dp[MAX_N];
int sum[2][MAX_N];
int s[2];

int quadratic_dp ()
{

	dp[0] = +(1 << 30);
	for (int i = 1; i * 2 <= (n + 1); i ++)
	{
		dp[i] = -(1 << 30); /// infinty
		for (int j = 0; j < i; j ++)
        	dp[i] = max (dp[i], min (dp[j], sum[1][i * 2 - 1] - sum[1][j * 2] - (sum[0][i * 2 - 1] - sum[0][j * 2])));
	}

	return dp[(n + 1) / 2];
}

bool check (int x)
{
    int sum = 0;
    for (int i = 1; i <= n; i += 2)
    {
        if (sum >= x)
            sum = max (sum - a[i - 1] + a[i], a[i]);
        else
            sum = sum - a[i - 1] + a[i];
    }
    return sum >= x;
}

int nlogn ()
{
    int l, r, mid;

    l = -1;
    r = s[1] + 1;
    while (r - l > 1)
    {
        mid = (l + r) >> 1;

        if (check (mid))
            l = mid;
        else
            r = mid;
    }

    return l;
}

int main ()
{
	scanf ("%d", &n);
	for (int i = 1; i <= n; i ++)
		scanf ("%d", &a[i]);

	for (int i = 1; i <= n; i ++)
		s[i & 1] += a[i];

	if (!(n & 1))
	{
		printf ("%d %d\n", max (s[0], s[1]), min (s[0], s[1]));
		return 0;
	}

	sum[0][0] = sum[1][0] = 0;
	for (int i = 1; i <= n; i ++)
	{
		sum[0][i] = sum[0][i - 1];
		sum[1][i] = sum[1][i - 1];
		sum[i & 1][i] += a[i];
	}

	int ans;

	///ans = quadratic ();
	ans = nlogn ();

	printf ("%d %d\n", s[0] + ans, s[1] - ans);
	return 0;
}


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

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            ReadString();
            var D = ReadIntArray();
            int sum = D.Sum();
            int ans = D.Sum(d => d * (sum - d)) / 2;
            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static string YesNo(bool condition) => condition ? "Yes" : "No";
        static string YESNO(bool condition) => condition ? "YES" : "NO";

        #endregion
    }
}

Measured memory_bytes: 11348
from collections import deque
n,k=map(int,input().split())
a=list(map(int,input().split()))

asum=sum(a)


def divisor(n):
    divisors=[]
    for i in range(1,int(n**0.5+1)):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
div=divisor(asum)
#print(div)
b=[0]*n

ans=0
for d in div:
    count=0
    #print(d)
    #print(a)
    for i in range(n):
        b[i]=a[i]%d
    b.sort()
    #print(b)
    que=deque(b)
    #print(que)
    while que:
        s=que.popleft()
        if s==0:
            continue
        if len(que)==0:
            count=0
            break
        g=que.pop()
        #print(s,g)
        if s==d-g:
            count+=s
        if s<d-g:
            que.append(s+g)
            count+=s
        if s>d-g:
            que.appendleft(s-d+g)
            count+=(d-g)
    #print(d,count)
    if count<=k:
        ans=d
print(ans)


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

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
using namespace std;


int main(){
	string s; cin >> s;
	stack<ll> ngo;
	vector<bool> ngongo(s.size(), 0);
	ll ans = 0;
	for (int i = 0; i < s.size(); ++i){
		if (s[i] == '1') ngo.push(i);
		else if (!ngo.empty()){
			ngongo[ngo.top()] = 1;
			ngongo[i] = 1;
			ngo.pop();
		}
	}
	while (!ngo.empty()) ngo.pop();
	for (int i = 0; i < s.size(); ++i){
		if (s[i] == '0' && !ngongo[i]) ngo.push(i);
		else if (!ngo.empty() && !ngongo[i]){
			ngongo[ngo.top()] = 1;
			ngongo[i] = 1;
			ngo.pop();
		}
	}for (bool a : ngongo) if (a) ans++;
	cout << ans << endl;
}

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

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<std::string> s(N);
	std::vector<int> t(N);
	for (int i{}; i < N; i++)
		std::cin >> s[i] >> t[i];

	std::string X;
	std::cin >> X;
	int key{};
	while (s[key] != X)
		key++;
	int ans{};
	for (int i{key + 1}; i < N; i++)
		ans += t[i];
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    string S;
    cin>>S;
    int L=sz(S);
    vector<vector<ll>> dp(4,vector<ll>(L+3));
    dp.at(0).at(0)=1;
    rep(i,L){
        if(S.at(i)=='A' || S.at(i)=='?'){
            dp.at(0).at(i+1)+=dp.at(0).at(i);
            dp.at(1).at(i+1)+=dp.at(0).at(i);
            dp.at(1).at(i+1)+=dp.at(1).at(i);
            dp.at(2).at(i+1)+=dp.at(2).at(i);
            dp.at(3).at(i+1)+=dp.at(3).at(i);
            dp.at(0).at(i+1)%=MOD;
            dp.at(1).at(i+1)%=MOD;
            dp.at(2).at(i+1)%=MOD;
            dp.at(3).at(i+1)%=MOD;
        }
        if(S.at(i)=='B' || S.at(i)=='?'){
            dp.at(0).at(i+1)+=dp.at(0).at(i);
            dp.at(1).at(i+1)+=dp.at(1).at(i);
            dp.at(2).at(i+1)+=dp.at(1).at(i);
            dp.at(2).at(i+1)+=dp.at(2).at(i);
            dp.at(3).at(i+1)+=dp.at(3).at(i);
            dp.at(0).at(i+1)%=MOD;
            dp.at(1).at(i+1)%=MOD;
            dp.at(2).at(i+1)%=MOD;
            dp.at(3).at(i+1)%=MOD;
        }
        if(S.at(i)=='C' || S.at(i)=='?'){
            dp.at(0).at(i+1)+=dp.at(0).at(i);
            dp.at(1).at(i+1)+=dp.at(1).at(i);
            dp.at(2).at(i+1)+=dp.at(2).at(i);
            dp.at(3).at(i+1)+=dp.at(2).at(i);
            dp.at(3).at(i+1)+=dp.at(3).at(i);
            dp.at(0).at(i+1)%=MOD;
            dp.at(1).at(i+1)%=MOD;
            dp.at(2).at(i+1)%=MOD;
            dp.at(3).at(i+1)%=MOD;
        }
    }
    cout<<dp.at(3).at(L)<<endl;
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);
	
	int n,count = 0;
	
	do
	    {
		n = In.nextInt();
	    }while(1 >= n && n >= 10000);
	
	int []a = new int[n];

	for(int i = 0; i < n; i++)
	    {
		do
		    {
			a[i] = In.nextInt();
		}while(a[i] <= 2 && a[i] >= Math.pow(10,8));

		if((isprime(a[i])) == 1)
		   count++;
	    }
		System.out.println(count);
    }
    
    public static int isprime(int x)
    {
	if(x == 2)
	    return 1;

	if(x < 2 || x % 2 == 0)
	    return 0;
    
	int j = 3;
	while(j <= Math.sqrt(x))
	    {
		if(x % j == 0)
		    return 0;

		j += 2;
	    }
	return 1;
    }
}

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

#define RATE 380000.0
int main(void){
    int N;
    double sum=0;
    cin>>N;
    double x[N];
    string u[N];

    for(int i=0;i<N;i++){
        cin>>x[i]>>u[i];
        if(u[i]=="JPY")
            sum+=x[i];
        else if(u[i]=="BTC")
            sum+=x[i]*RATE;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	H, W, S := nextInt(), nextInt(), []string{}
	for i := 0; i < H; i++ {
		S = append(S, nextLine())
	}

	fmt.Printf("%s\n", ABC096C(H, W, S))
}

// ABC096C ...
func ABC096C(H, W int, S []string) string {
	dx := []int{-1, 0, 1, 0}
	dy := []int{0, -1, 0, 1}

	var guard string
	for i := 0; i < W; i++ {
		guard += "."
	}
	S = append([]string{guard}, S...)
	S = append(S, guard)

	for i := 0; i < len(S); i++ {
		S[i] = "." + S[i] + "."
	}

	for i := 1; i < H+1; i++ {
		for j := 1; j < W+1; j++ {
			if S[i][j] == '.' {
				continue
			}

			isAllWhite := true
			for d := 0; d < len(dx); d++ {
				if S[i+dx[d]][j+dy[d]] == '#' {
					isAllWhite = false
					break
				}
			}

			if isAllWhite {
				return "No"
			}

		}
	}

	return "Yes"
}


Measured memory_bytes: 1800
N = int(input()) # 数字を変数に格納
List_A = list(map(int,input().split())) # 複数の数字をリストに格納
List_B = list(map(int,input().split())) # 複数の数字をリストに格納

import copy

List_a = copy.copy(List_A)
List_b = copy.copy(List_B)
count = 0

for i in range(N+1):
    if i >= 1:
        if List_a[i] > List_b[i-1]:
            count += List_b[i-1]
            List_a[i] -= List_b[i-1]
            List_b[i-1] = 0
        else:
            count += List_a[i]
            List_b[i-1] -= List_a[i]
            List_a[i] = 0
        
    if i < N:
        if List_a[i] > List_b[i]:
            count += List_b[i]
            List_a[i] -= List_b[i]
            List_b[i] = 0
        else:
            count += List_a[i]
            List_b[i] -= List_a[i]
            List_a[i] = 0

print(count)

Measured memory_bytes: 19004
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
long double r,pi;
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>r;r*=2;
	pi=3.1415926535897932384626433832795;
	cout<<fixed<<setprecision(90)<<r*pi<<endl;
	return 0;
}


Measured memory_bytes: 3784
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
typedef long long ll;

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

ll dp[64][64 * 64];

int main(){
  const int n = getInt();
  const int a = getInt();
  const int MAX = n * 50;

  dp[0][0] = 1;
  REP(i,n) {
    const int x = getInt();
    for(int j = n; j >= 0; j--) {
      REP(k,MAX+1) if(dp[j][k]) {
        dp[j + 1][k + x] += dp[j][k];
      }
    }
  }

  ll ans = 0;
  REP(i,n) ans += dp[i + 1][(i + 1) * a];

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll s,ans=0;
  cin >>s;
  vector <ll> a;
  while(1){
    if(s==0) break;
    a.push_back(s%10);
    s/=10;
  }
  reverse(a.begin(),a.end());
  ll as=a.size();
  ll l[10];
  l[0]=1;
  for(ll i=1;i<10;i++) l[i]=2*l[i-1];
  for(ll i=0;i<as;i++){
    ll p=as-(i+1)-1,q=1;
    if(p<0) {
      ans+=a[i]*l[i];
      continue;
    }
     while(1){
       if(p<0) {
         ans+=q*a[i]*l[i];
         break;
       }
       ans+=q*a[i]*l[i]*l[p];
       p--;q*=10;
     }
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		String[] wkArray = new String[3];

		try {
			StringBuffer buff = new StringBuffer();
			scanner = new Scanner(System.in);
			for (int i = 0; i < 3; i++) {
				wkArray[i] = scanner.next();
			}

			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					if (i == j) {
						buff.append((wkArray[i].toCharArray())[j]);
					}
				}
			}

			System.out.println(buff.toString());

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int startNum = 0;
		int endNum = 0;

		try {
			scanner = new Scanner(System.in);
			startNum = scanner.nextInt();
			endNum = scanner.nextInt();

			int count = 0;
			for (int i = startNum; i <= endNum; i++) {
				char[] num = Integer.toString(i).toCharArray();
				if (num[0] == num[4] && num[1] == num[3]) {
					count++;
				}
			}

			System.out.println(count);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 31204
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    ll n;
    cin >> n;

    cout << n + n * n + n * n * n << endl;
}

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

int main(int argc, char** argv)
{
	int A, B, N, M;
	bool flag=true;
	std::vector<int> room, ans, num;
	std::vector<std::vector<int>>way;
	std::cin >> N >> M;
	ans.resize(N, -1);
	way.resize(N);
	for (int i = 0; i < M; i++)
	{
		std::cin >> A >> B;
		way[A - 1].push_back(B);
		way[B - 1].push_back(A);
	}
	for (int i = 0; i < N; i++)
	{
		std::sort(way[i].begin(), way[i].end());
		way[i].erase(std::unique(way[i].begin(), way[i].end()), way[i].end());
	}
	num.push_back(1);
	ans[0] = 0;
	while (1)
	{
		for (int x : num)
		{
			for (int y : way[x - 1])
			{
				if (ans[y - 1] < 0)
				{
					room.push_back(y);
					ans[y - 1] = x;
				}
			}
		}
		num.clear();
		for (int x : room)
		{
			num.push_back(x);
		}
		if (!num.empty())
		{
			room.clear();
			num.erase(std::unique(num.begin(), num.end()), num.end());
		}
		else
		{
			break;
		}
	}
	for (int x : ans)
	{
		if (x < 0)
		{
			flag = false;
			break;
		}
	}
	if (flag)
	{
		std::cout << "Yes" << std::endl;
		for (int x : ans)
		{
			if (x > 0)
			{
				std::cout << x << std::endl;
			}
		}
	}
	else
	{
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 10660
S = input()
first_half = int(S[0:2])
second_half = int(S[2:4])
if 0 < first_half and first_half <= 12 and 0 < second_half and second_half <= 12:
    print("AMBIGUOUS")
elif 0 < first_half and first_half <= 12:
    print("MMYY")
elif 0 < second_half and second_half <= 12:
    print("YYMM")
else:
    print("NA")

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int k,s;
  cin >> k >> s;
  ll res = 0;/*
  ll sum = 0;
  REP(i,k+1){
    for(int j = i+1;j <= k;j++){
      if(s-i-j >= 0 && s-i-j <= k && s-i-j != i && s-i-j != j)sum++;
    }
  }
  res += sum*6;
  sum = 0;
  REP(i,k+1){
    if(s-i*2 != i && s-i*2 >= 0 && s-i*2 <= k)sum++;
  }
  res += sum*3;
  if((s % 3) == 0 && k*3 >= s)res++;
  cout << res << endl;*/
  REP(i,k+1){
    REP(j,k+1){
      if(s-i-j <= k && s-i-j >= 0)res++;
    }
  }cout << res << endl;




  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define rep(i,a,b) for (rg int i=(a);i<=(b);i++)
#define per(i,a,b) for (rg int i=(b);i>=(a);i--)
#define pb push_back
#define lowbit(x) (x&(-x))
#define replow(i,a,b) for(rg int i = (a);i<=(b);i+=lowbit(i))
#define perlow(i,a,b) for(rg int i = (b);i>=(a);i-=lowbit(i))
#define mk make_pair
#define VI vector<int>
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define fi first
#define se second
#define il inline
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define inf 0x3f3f3f3f
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
char buf[1<<15],*p1 = buf,*p2 = buf;
inline ll read(){
    #define num ch-'0'
    char ch;bool flag=0;ll res;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=res*10ll+num);
    (flag)&&(res=-res);
    #undef num
    return res;
}
inline void write(ll x){
	if (x < 0) x = ~x + 1ll, putchar('-');
	if (x > 9) write(x / 10ll);
	putchar(x % 10ll + '0');
}
#define mid ((l + r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
#undef mid
#undef ls
#undef rs
const ll maxn = 1e9;
void solve()
{
	ll S = read();
	ll t = S / 1e9;
	ll tmp = S % (ll)(1e9);
	if(S % maxn == 0) printf("0 0 %lld %lld %lld %lld\n",maxn,0,1,t);
	else 
	printf("0 0 %lld %lld %lld %lld\n",maxn,(maxn -tmp),1,t+1);
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
//	int T = read();
//	while(T--)
	solve();
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string s;
    cin >> s;
    vector<char> str;
    REP(i,s.size()){
        if(s[i]=='B'){
            if(str.size()!=0)str.pop_back();
        }else{
            str.push_back(s[i]);
        }
    }
    REP(i,str.size())cout << str[i];
    cout << endl;
}


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

void solveA(){
  int a,b,c;
  cin >> a >> b >> c;

  if (a==b && b == c){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
void solveB(){
  int n;
  string s;
  int r=0,b=0;
  cin >> n >> s;

  for(int i = 0; i< n ; i++){
    if(s[i]=='R'){
      r++;
    }
    else{
      b++;
    }
  }

  if (r>b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}
void solveC(){
}

int main(){
  solveB();
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int w, n, i, a, b, c;
    int order[30];
    char ch;
    
    for (i = 0; i <= 30; i++) order[i] = i;
    
    scanf("%d", &w);
    scanf("%d", &n);
    
    for (i = 0; i < n; i++){
        scanf("%d%c%d", &a, &ch, &b);
        c = order[a];
        order[a] = order[b];
        order[b] = c;
    }
    for (i = 1; i <= w; i++) printf("%d\n", order[i]);
    
    return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL n,a[202020]={};
	cin>>n;
	FORQ(i,1,n){
		cin>>a[i];
	}
	FORQ(i,1,n)a[i]+=a[i-1];
	LL ans=1LL*mod*mod;
	FOR(i,2,n-1){
		int d[5]={};
		d[0]=0,d[2]=i,d[4]=n;
		FOR(j,0,2){
			int l=d[2*j],r=d[2*(j+1)],m=(l+r)/2;
			LL th=(a[r]-a[l])/2;
			while(l!=m){
				if(a[m]-a[d[2*j]]>=th)r=m;
				else l=m;
				m=(l+r)/2;
			}

			d[j*2+1]=m;
			if(fabs(a[d[2*j+2]]-a[m]-a[m]+a[d[2*j]])>fabs(a[d[2*j+2]]-a[m+1]-a[m+1]+a[d[2*j]]))d[j*2+1]=m+1;
		}
		LL mn=1LL*mod*mod,mx=0;
		FOR(j,1,5){
			mn=min(mn,a[d[j]]-a[d[j-1]]);
			mx=max(mx,a[d[j]]-a[d[j-1]]);
		}
		ans=min(ans,mx-mn);
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n,1):
    dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]))
print(dp[n-1])

Measured memory_bytes: 52208
#include<cstdio>
#include<queue>
#include<deque>
#include<algorithm>
using namespace std;
#define IL inline

const int N = 100000 + 3;

struct Edge {
	int u,v,w;
	Edge(int u=0,int v=0,int w=0):u(u),v(v),w(w){}
};

int n;
int d[N];
bool vis[N];
vector<Edge> G[N]; 
deque<int> q;

IL void make_graph() {
	for(int i=1;i<n;i++) {
		G[i].push_back(Edge(i,(i+1)%n,1));
		G[i].push_back(Edge(i,i*10%n,0));
	}
}

IL int ZeroOneBfs() {
	q.push_back(1); d[1] = 1;
	while(!q.empty()) {
		int u = q.front(); q.pop_front();
		if(!u) { return d[0];}
		if(vis[u]) continue;
		vis[u] = true;
		for(int i=0;i<G[u].size();i++) {
			int v=G[u][i].v,w=G[u][i].w;
			d[v] = d[u] + w;
			if(w) q.push_back(v);
			else q.push_front(v);
		}
	}
}

int main() {
	scanf("%d",&n);
	make_graph();
	printf("%d\n",ZeroOneBfs());
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
using namespace std;
int main(void){
   string s,p;
   cin>>s>>p;
     
   string ans="No";
   for(int i=0;i<(int)s.length();i++){
       bool flag=true;
       for(int j=0; j<(int)p.length();j++){
           if(s[(i+j)%(int)s.length()]!=p[j]){
               flag=false;
               break;
           }
       }
       if(flag){
           ans="Yes";
           break;
       }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3216
# coding: utf-8
# Your code here!

Sa = list(input())
Sb = list(input())
Sc = list(input())
a = 1
b = 0
c = 0

current_turn = 'a'
while a <= len(Sa) and b <= len(Sb) and c <= len(Sc):
    if current_turn == 'a':
        if a >= len(Sa):
            print('A')
            break
        else:
            current_turn = Sa[a]
            a += 1
    elif current_turn == 'b':
        if b >= len(Sb):
            print('B')
            break
        else:
            current_turn = Sb[b]
            b += 1
    else:
        if c >= len(Sc):
            print('C')
            break
        else:
            current_turn = Sc[c]
            c += 1

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

int main(){
  long int h,w;
  cin>>h>>w;
  string a[h];
  for(int i=0;i<h;i++){
    cin>>a[i];
  }
  for(int i=0;i<2*h;i++){
    cout<<a[i/2]<<endl;
  }
  
  return 0;

}


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

int main() {
    string S;
    string T;
    cin >> S >> T;

    int s = -1;
    for (int i = S.length() - T.length(); i >= 0; i--) {
        bool is_ok = true;
        for (int j = 0; j < T.length(); j++) {
            if (S[i+j] == '?') continue;
            else if (S[i+j] != T[j]) {
                is_ok = false;
                break;
            }
        }
        if (!is_ok) {
            continue;
        }
        else {
            s = i;
            break;
        }
    }

    if (s != -1) {
        for (int i = 0; i < S.length(); i++) {
            if (i == s) {
                cout << T;
                i += T.length() - 1;
            }
            else if (S[i] == '?'){
                cout << 'a';
            }
            else {
                cout << S[i];
            }
        }
        cout << endl;
    }
    else {
        cout << "UNRESTORABLE" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>

using namespace std;

#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int, int>
#define mp make_pair
#define PI 3.1415926535897
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned

vector<vector<int>> g;
vector<vector<int>> d;
int ch[100100];
int removed[100100];
int par[100100];
void dfs(int v, int depth, int p) {
	d[depth].push_back(v);
	par[v] = p;
	FOR(i, 0, g[v].size()) {
		int to = g[v][i];
		if (to != p) {
			ch[v]++;
			dfs(to, depth + 1, v);
		}
	}
}

int used[100100];

int main()
{
#ifdef Fcdkbear
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	double beg = clock();
#endif

	int n;
	scanf("%d", &n);
	g.resize(n);
	FOR(i, 0, n - 1) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	if (n == 2) {
		cout << "Second" << endl;
		return 0;
	}
	d.resize(n);
	int root = -1;
	FOR(i, 0, n) {
		if (g[i].size() > 1) {
			root = i;
		}
	}
	dfs(root, 0, -1);
	for (int i = n - 1; i >= 0; --i) {
		FOR(j, 0, d[i].size()) {
			int v = d[i][j];
			if (used[v]) {
				continue;
			}
			if (v == root) {
				printf("First\n");
				return 0;
			}
			int children = ch[par[v]] - removed[par[v]];
			if (children > 1) {
				printf("First\n");
				return 0;
			}
			used[par[v]] = 1;
			if (par[v] != root) {
				removed[par[par[v]]]++;
			}
		}
	}
	printf("Second\n");

#ifdef Fcdkbear
	double end = clock();
	fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 10240
import java.lang.Math;
import java.util.Scanner;
class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        if (X == 2 | X == 3 | X == 5) {
        		System.out.println(X);
        } else {
        		int i = 2;
        		while (true) {
        			if (X%i == 0) {
        				i = 2;
        				X++;
        			} else {
        				i++;
        			}
        			if (i == Math.ceil(Math.sqrt(X))) {
        				break;
        			}
        		}
        		System.out.println(X);
        }
    }
} 

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int tower[1000];
int main(void)
{
	int i;
	for (i = 1; i < 1000; ++i) {
		tower[i] = tower[i - 1] + i;
	}
	int a, b;
	scanf("%d %d", &a, &b);
	for (i = 1; i < 999; ++i) {
		if (tower[i] - a == tower[i + 1] - b)
			break;
	}
	printf("%d", tower[i] - a);
}

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

typedef long long ll;
#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    ll K;

    cin >> N >> K;
    double ans = 0;
    REP(i, N){
        int n = (int)ceil(log2((double)K) - log2((double(i+1))));
        if( n < 0 ){
            n = 0;
        }
        //DEBUG("%i", n);
        ans += pow(0.5, n);
    }
    cout << ans/N << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
  
  
  
int n,cost;
int A[1001],B[1001];
int L[501],R[502];
  
  
void merge(int left,int mid,int right){
  int i,j,n1=mid-left,n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  L[n1]=INT_MAX;
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  R[n2]=INT_MAX;
  int l=0,r=0;
  for(i=left;i<right;i++){
    if(L[l]<=R[r]){
      A[i]=L[l];
      l++;
    }
    else{
      A[i]=R[r];
      r++;
    }
  }
}
  
  
void m_sort(int left,int right){
  int mid;
  if( left+1 >= right) return;
  mid=(left+right)/2;
  m_sort(left,mid);
  m_sort(mid,right);
  merge(left,mid,right);
}
  
  
void swap(int a,int b,int *C){
  int swap;
  swap=C[a];
  C[a]=C[b];
  C[b]=swap;
}
  
  
  
  
  
  
    
   
    
  
int main(){
  scanf("%d",&n);
  int i,j;
  int cnt,sum,min,start,x;
  int C[1001]={};
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    B[i]=A[i];
  }
  m_sort(0,n);
  for(i=0;i<n;i++){
    if(A[i]==B[i]) C[i]=1;
  }
  cost=0;
  for(i=0;i<n;i++){
    if(C[i]!=1){
      C[i]=1;
      cnt=0;
      sum=0;
      min=B[i];
      x=i;
      while(1){
        for(j=0;j<n;j++){
          if(B[x]==A[j]){
            C[j]=1;
            cnt++;
            sum+=B[j];
            if(min > B[j]) min=B[j];
            x=j;
            break;
          }
        }
        if(x==i) break;
      }
      sum-=min;
      if( (cnt -1)*min > (cnt -1)*A[0]+2*(min +A[0])) cost+=sum+(cnt-1)*A[0]+2*(min +A[0]);
      else cost+=sum+(cnt-1)*min;
    }
  }
  printf("%d\n",cost);
  return 0;
}
 
  

Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;
  cin >> n;
  long long a[5]={0};
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    if(s[0]=='M')a[0]++;
    if(s[0]=='A')a[1]++;
    if(s[0]=='R')a[2]++;
    if(s[0]=='C')a[3]++;
    if(s[0]=='H')a[4]++;
  }
  sort(a,a+4);
  long long ans=0;
  for(int i=0;i<5;i++)for(int j=i+1;j<5;j++)for(int k=j+1;k<5;k++)ans+=a[i]*a[j]*a[k];
  cout << ans << endl;
}

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

#define inf 1000000007
#define ll long long int


ll knapsack(int n, int W, int* wt, int* val) {
	int maxVal = n * 1000;
	ll dp[n + 1][maxVal + 1];

	for (int v = 0; v <= maxVal; v++) {
		dp[1][v] = inf;
	}
	dp[1][0] = 0;
	dp[1][val[0]] = wt[0];

	for (int i = 2; i <= n; ++i)
	{
		for (int v = 0; v <= maxVal; v++) {
			dp[i][v] = dp[i - 1][v];
			if (val[i - 1] > v) {
				continue;
			}
			dp[i][v] = min(dp[i - 1][v], wt[i - 1] + dp[i - 1][v - val[i - 1]]);
		}
	}

	int ans = 0;
	for (int v = 0; v <= maxVal; v++) {
		if (dp[n][v] <= W) {
			ans = v;
		}
	}
	return ans;

}

int main() {
	int n, W;
	cin >> n >> W;
	int* wt = new int[n];
	int* val = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> wt[i] >> val[i];
	}

	cout << knapsack(n, W, wt, val) << endl;

	return 0;
}

Measured memory_bytes: 81316