akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#ifdef Hwang_Baek_I
#define debug(args...) { string _102_ = #args; error(_102_.begin(), _102_.end(), args); }
void error(string::iterator it, string::iterator IT);
template<typename T, typename... Args>
void error(string::iterator it, string::iterator IT, T a, Args... args);
#else
#define debug(args...) 102
#endif

const int N = 110000;

int a[N];

int main() {
#ifdef Hwang_Baek_I
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k; cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	cout << (n - 1 + k - 2) / (k - 1) << endl;
	return 0;
}









#ifdef Hwang_Baek_I
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
template<int N>
string to_string(bitset<N> v) { string res = ""; for (int i = 0; i < N; i++) res += ('0' + v[i]); return res; }
string to_string(char x) { string ret = ""; ret.push_back(x); return ret; }
template<typename T>
string to_string(T x) { string ret = ""; for (auto it : x) ret += to_string(it) + ", "; ret.pop_back(); ret.pop_back(); return ret; }
template<typename T, typename U>
string to_string(pair<T, U> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template<typename T, typename U, typename V>
string to_string(tuple<T, U, V> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; }
template <typename T, typename U, typename V, typename W>
string to_string(tuple<T, U, V, W> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";}
void error(string::iterator it, string::iterator IT) { cerr << endl; }
template<typename T, typename... Args>
void error(string::iterator it, string::iterator IT, T a, Args... args) {
	cerr << "<";
	int cnt = 0;
	while (it != IT) {
		if (*it == '(' || *it == '[' || *it == '<') cnt++;
		if (*it == ')' || *it == ']' || *it == '>') cnt--;
		if (cnt == 0 && *it == ',') break;
		if (*it != ' ') cerr << *it;
		it++;
	}
	cerr << " = " << to_string(a) << "> ";
	error(++it, IT, args...);
}
#endif


Measured memory_bytes: 640
N,x = map(int,input().split())
a_list = list(map(int,input().split()))
a_list_sort = sorted(a_list)
#print(a_list)
#print(a_list_sort)
count = 0

if sum(a_list) < x :
	count = N-1
elif sum(a_list) == x :
	count = N
else:
	for i in range(N):
		if sum(a_list_sort[:i+1]) <= x:
			continue	
		else:
			count = i
			break
print(count)

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

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if (n - k <= 0)
        cout << x * n << endl;
    else
        cout << x * k + y * (n - k) << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

template<int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};
const int mod = 1e9 + 7;
using modint = ModInt< mod >;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b(n+1, 0), zero(n+1, 0);
    rep(i, n) b[i+1] = b[i] ^ a[i];
    vector<vector<int>> cmp_b(1<<20, vector<int>(1,1));

    rep1(i, n+1){
        zero[i] += zero[i-1];
        if(b[i] == 0) zero[i]++;
        else cmp_b[b[i]].push_back(i);
    }

    modint ans = 0;
    vector<vector<modint>> dp(1<<20, vector<modint>(2, 0));
    rep(i, 1<<20){
        if(cmp_b[i].size() == 1) continue;
        dp[i][0] = 1; dp[i][1] = 0;
        rep1(j, cmp_b[i].size()){
            int z = zero[cmp_b[i][j]] - zero[cmp_b[i][j-1]];
            dp[i][0] += dp[i][1] * z;
            dp[i][1] += dp[i][0];
            // cout << z << " " << dp[i][0] << " " << dp[i][1] << endl;
        }
    }

    if(b[n] == 0){
        ans = 1;
        rep(i, zero[n]-1) ans *= 2;
        rep1(i, 1<<20) ans += dp[i][1];
    }else{
        // n-1マス目で 0 -> n マス目でb[n] … dp[b[n]][0]と同じ
        ans += dp[b[n]][0];
    }
    cout << ans << endl;

}


Measured memory_bytes: 123264
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll =int long long;
map <int ,int> mpa,mpb;

int main(void){
  int N;
  cin >>N;
  string s,t;
  cin >> s >> t;
  int ans=0;
  for(int k=0; k<=N ;k++){
    if(k==N){
      cout << 2*N;
      return 0;
    }
    if(s.substr(k,N-k)==t.substr(0,N-k)){
      cout << N+k;
      return 0;
    }
  }
}

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

int MOD=1000000007;
struct edge {
    int to, cost;
};

int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

auto factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
signed main() {
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  int sum=0;
  rep(i,n)sum+=a[i];
  int k=0,ans=INF;
  rep(i,n-1){
    k+=a[i];
    ans=min(ans,abs(sum-2*k));
    }
cout<<ans<<endl;
}


Measured memory_bytes: 4828
N = int(input())
A = list(map(int, input().split()))

resZero = 0
resTwo = 0
odds = 0
for a in A:
    if a % 4 == 0:
        resZero += 1
        continue
    elif a % 4 == 2:
        resTwo += 1
        continue
    else:
        odds += 1

if resZero - odds >= -1 and resTwo == 0:
    print('Yes')
    quit()
if resZero - odds >= 0:
    print('Yes')
    quit()
print('No')

Measured memory_bytes: 14252
#n = input()
a = list(input().split())
#print(a)
#b = list(map(int, input().split()))
#c = list(map(int, input().split()))
r = int()
stack = []
for i in a:
    if i.isdigit():
        stack.append(int(i))
    elif i == "+": 
        #print(stack)      
        r = stack[-1] + stack[-2]
        stack.pop()
        stack.pop()
        stack.append(r)
    elif i == "-":
        #print(stack)
        r = stack[-2] - stack[-1]
        stack.pop()
        stack.pop()
        stack.append(r)
    elif i == "*":
        #print(stack)
        r = stack[-1] * stack[-2]
        stack.pop()
        stack.pop()
        stack.append(r)
print(stack[0])


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;


int a,b,c,d;
int main(){
  cin>>a>>b>>c>>d;
  if(abs(a-b)<=d&&abs(b-c)<=d ||abs(a-c)<=d){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


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

struct shogen {
  int people;
  int honest;
};

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

  vector<shogen> s[n];
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < a; j++) {
      int x, y;
      cin >> x >> y;
      s[i].push_back({x - 1, y});
    }
  }

  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    bool success = true;
    for (int i = 0; i < n; i++) {
      if (bit & (1 << i)) {
        for (shogen ss: s[i]) {
          if ((bit & (1 << ss.people)) && ss.honest) {
          } else if (!(bit & (1 << ss.people)) && !ss.honest){
          } else {
            success = false;
          }
        }
      }
    }
    int tmp = 0;
    if (success) {
      for (int i = 0; i < n; i++) {
        if (bit & (1 << i)) tmp++;
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

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


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

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int4(int *a1, int *a2, int *a3, int *a4) {
  scanf("%d %d %d %d", a1, a2, a3, a4);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int64_t *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%lld", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 1000
#define NUM2_MAX (NUM_MAX*NUM_MAX)
#define RANK_MAX 3000

int desc(const void *a1, const void *a2) {
    int64_t aa1 = *(int64_t*)a1;
    int64_t aa2 = *(int64_t*)a2;
    if(aa1 > aa2) return -1;
    if(aa1 == aa2) return 0;
    return 1;
}

#define CANDS_MAX 500000

int main(void) {
    int x, y, z, rank;
    get_int4(&x, &y, &z, &rank);
    static int64_t xrr[NUM_MAX+1];
    static int64_t yrr[NUM_MAX+1];
    static int64_t zrr[NUM_MAX+1];
    // 1-indexed
    fget_array(&xrr[1], x);
    fget_array(&yrr[1], y);
    fget_array(&zrr[1], z);

    qsort(&xrr[1], x, sizeof(int64_t), desc);
    qsort(&yrr[1], y, sizeof(int64_t), desc);
    qsort(&zrr[1], z, sizeof(int64_t), desc);

    static int64_t cands[CANDS_MAX];
    int cidx = 0;
    int i, j, k;

    for(i = 1; i <= x; i++) {
        for(j = 1; j <= y; j++) {
            for(k = 1; k <= z; k++) {
                if(i*j*k > rank) break;;
                cands[cidx++] = xrr[i] + yrr[j] + zrr[k];
            }
        }
    }
    qsort(cands, cidx, sizeof(int64_t), desc);

    for(i = 0; i < rank; i++) {
        printf("%lld\n", cands[i]);
    }
    return 0;
}

Measured memory_bytes: 1916
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vc vector<ll>
#define vcs vector<string>
#define vcp vector<pair<ll, ll>>
#define vct vector<tuple<ll, ll, ll>>
using namespace std;
//vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

ll k;
vc cost;
Graph g;

void dfs(int prev, int vert, ll dep)
{
	cost[vert] = dep;
	for (auto e : g[vert])
	{
		if (cost[e.to] < 0) dfs(vert, e.to, cost[vert]+e.cost);
	}
}

int main()
{
	ll a, b;
	cin >> a >> b;
	a--; b--;
	cout << a*b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

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

    string res = "second";

    REP(i, N) {
      lint a; cin >> a;
      if(a%2 != 0) {
        res = "first";
      }
    }
    PRINT(res);
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back

using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }

signed main() {
    int n, ans = 0; cin >> n; vector<ll> a(n);
    for(ll &i : a) cin >> i;
    for(int i = 0; i < n; i++)
        for(int j = i + 1; j < n; j++)
            for(int k = j + 1; k < n; k++)
                if(a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) {
                    if(min({a[i] + a[j], a[j] + a[k], a[k] + a[i]}) > max({a[i], a[j], a[k]}))
                        ans++;
                }
    cout << ans << endl;
    fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
    return 0;
    /* 取模直接除，爆零两行泪
     * 不开ll见祖宗
     */
}

Measured memory_bytes: 3800
from math import ceil
N, M = map(int, input().split())
A = list(map(int, input().split()))


# 2で割ったものに置き換え
A = [a // 2 for a in A]


# 各要素について、2で割り切れる回数が等しいかチェック
count_div_2 = None
for a in A:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1

    if count_div_2 is None:
        count_div_2 = cnt
    elif cnt != count_div_2:
        print(0)
        exit()


# 最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


# 最小公倍数
def lcm(a, b):
    return a // gcd(a, b) * b


while len(A) > 1:
    a, b = A.pop(), A.pop()
    my_lcm = lcm(a, b)

    # Mを超えたlcmは意味がない
    if my_lcm > M:
        print(0)
        exit()

    A.append(my_lcm)


print(ceil(M // A[0] / 2))


Measured memory_bytes: 14892
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int h,w,x;
    cin>>h>>w>>x;
    string s[h],temp[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    int ans=0;
    for(int i=0;i<(1<<h);i++){
        for(int j=0;j<(1<<w);j++){
            for(int k=0;k<h;k++){
                temp[k]=s[k];
            }
            for(int k=0;k<h;k++){
                if(i&(1<<k)){
                    for(int col=0;col<w;col++){
                        temp[k][col]='*';
                    }
                }
            }
            for(int k=0;k<w;k++){
                if(j&(1<<k)){
                    for(int row=0;row<h;row++){
                        temp[row][k]='*';
                    }
                }
            }
            int cnt=0;
            for(int row=0;row<h;row++){
                for(int col=0;col<w;col++){
                    if(temp[row][col]=='#')cnt++;
                }
            }
            if(cnt==x){
               ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
///Alhamdulillah



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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> b(a.size());
  copy(a.begin(), a.end(), b.begin());

  sort(b.begin(), b.end(), greater<int>());
  int max = b[0];
  int sec = b[1];

  for (int i = 0; i < n; i++) {
    int val = a[i] == max ? sec : max;
    cout << val << endl;
  }

  return 0;
}

Measured memory_bytes: 3200
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K = MI()
    A = LI()
    can_win = [False]*(K+1) #can_win[i]:山にi個ある時に勝てるか

    for i in range(1,K+1):
        for a in A:
            if a<=i:
                if not can_win[i-a]: #a個取ったら相手が勝てなくなるなら勝てるということ
                    can_win[i] = True
                    break
    print(("Second","First")[can_win[-1]])

if __name__ == '__main__':
    main()

Measured memory_bytes: 65900
n,k=map(int,input().split())
s=input()
ans=0
if s[0]=="R" and s[n-1]=="R":
    for i in range(n-1):
        if s[i]=="R":
            if s[i+1]=="R":
                ans+=1
        else:
            if s[i-1]=="L":
                ans+=1
elif s[0]=="R" and s[n-1]=="L":
    for i in range(n):
        if s[i]=="R":
            if s[i+1]=="R":
                ans+=1
        else:
            if s[i-1]=="L":
                ans+=1
elif s[0]=="L" and s[n-1]=="R":
    for i in range(1,n-1):
        if s[i]=="R":
            if s[i+1]=="R":
                ans+=1
        else:
            if s[i-1]=="L":
                ans+=1
else:
    for i in range(1,n):
        if s[i]=="R":
            if s[i+1]=="R":
                ans+=1
        else:
            if s[i-1]=="L":
                ans+=1
print(min(n-1,ans+2*k))

Measured memory_bytes: 3316
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count = 0;
		int[] a = new int[210];

		for(int i = 0; i < N; i++) a[i] = sc.nextInt();

		while(true){
			boolean exit_odd = false;
			for(int i = 0; i < N; i++){
				if(a[i] % 2 != 0) exit_odd = true;
			}

			if(exit_odd) break;

			for(int i = 0; i < N; i++){
				a[i] /= 2;
			}
			count++;
		}

		System.out.println(count);
	}
}


Measured memory_bytes: 25044
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,h[100005],dp[100005]={};
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>h[i];
  }

  for(int i=1; i<n; i++){
    if(i==1){
      dp[i]=abs(h[i]-h[i-1])+dp[i-1];
    }else{
      if(abs(h[i]-h[i-1])+dp[i-1] > abs(h[i]-h[i-2])+dp[i-2]){
	dp[i]=abs(h[i]-h[i-2])+dp[i-2];
      }else{
	dp[i]=abs(h[i]-h[i-1])+dp[i-1];
      }
    }
  }
  cout<<dp[n-1]<<'\n';
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 1000000000000000
#define mod 1000000007
#define ld long double
#define pll pair<ll,ll>
using namespace std;

int main()
{ 
   

fast;   
ll n;
cin>>n;

ll a[n];
map<ll,ll> mapp;
ll sum=0;
for(ll i=0;i<n;i++)
    cin>>a[i],mapp[a[i]]++,sum+=a[i];

ll q;
cin>>q;

while(q--)
{
    ll b1,c1;
    cin>>b1>>c1;

    if(mapp.find(b1)!=mapp.end() and mapp[b1]>0)
    {
        sum=sum-mapp[b1]*b1+mapp[b1]*c1;
       
        mapp[c1]+=mapp[b1];
         mapp[b1]=0;
    }
    cout<<sum<<'\n';
}

}


Measured memory_bytes: 9080
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
int i;
#define rep2(i, a, b) for(i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
using namespace std;
// _________コーディングはここから！！___________
template <const int sz = 5 * 10000000, typename T = long long> struct IO {
    char reader[sz], writer[sz];
    char *now, *now2 = writer;
    IO() {
        reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
        now = reader;
    }
    inline T read() {
        while(*now && *now <= 32) now++;
        if(*now == '-') {
            now++;
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return -res;
        } else {
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return res;
        }
    }
    inline string read_str() {
        string res;
        while(*now and *now != '\n' and *now != ' ') res += *now++;
        now++;
        return res;
    }
    inline void write(T x, char margin = ' ') {
        if(x == 0) {
            putchar('0');
            putchar(margin);
            return;
        }
        if(x < 0) {
            putchar('-');
            x = -x;
        }
        while(x) {
            *now2 = '0' + x % 10;
            now2++;
            x /= 10;
        }
        do {
            now2--;
            putchar(*now2);
        } while(now2 != writer);
        putchar(margin);
    }
    inline void write_str(string s, char margin = ' ') {
        for(auto c : s) putchar(c);
        putchar(margin);
    }
};
IO io;
inline int read() { return io.read(); }
inline void write(int x) { io.write(x); }
inline void write(int x, char c) { io.write(x, c); }
constexpr int N = 500003;
int c[N];
struct T {
    int l, r, idx;
    constexpr bool operator<(const T &rhs) const noexcept { return r < rhs.r; }
} q[N];
int ans[N], last[N], dat[N];

inline void dec(int k) {
    for(++k; k < N; k += k & -k) --dat[k];
}
inline int sum(int k) {
    int res = 0;
    for(++k; k > 0; k -= k & -k) res += dat[k];
    return res;
}
int n, Q, now = 1;

// 頑張れ！！
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
// 頑張れ！！

vector<int> l[N], idx[N];
int L, R;
main() {
    n = read(), Q = read();
    rep2(i, 1, n) c[i] = read();
    rep(i, Q) {
        L = read(), R = read();
        l[R].emplace_back(L), idx[R].emplace_back(i);
    }
    rep2(i, 1, n) {
        if(last[c[i]]) dec(last[c[i]]);
        last[c[i]] = i;
        for(size_t j = 0; j < l[i].size(); ++j) { ans[idx[i][j]] = sum(i) - sum(l[i][j] - 1) + i + 1 - l[i][j]; }
    }
    // rep(i, Q) {
    //     for(; now < q[i].r; ++now) {
    //         if(last[c[now]]) dec(last[c[now]]);
    //         last[c[now]] = now;
    //     }
    //     ans[q[i].idx] = sum(q[i].r - 1) - sum(q[i].l - 1) + q[i].r - q[i].l;
    // }
    rep(i, Q) write(ans[i], '\n');
}


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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;

    vector<int> vec(n,0);
    for(int i=0;i<k;++i)
    {
        int n1;
        cin>>n1;
        for(int j=0;j<n1;++j)
        {
            int temp;
            cin>>temp;
            vec[temp-1]=1;
        }
    }
    int count=0;
    for(int i=0;i<n;++i)
    {
        if(vec[i]==0)
            count++;
    }
    cout<<count<<"\n";

}  

Measured memory_bytes: 3552
from itertools import product

N, M, X = map(int, input().split(' '))
books = [tuple(map(int, input().split(' '))) for _ in range(N)]

cost = 10 ** 9
found = False
for bits in product((True, False), repeat=N):
    points = [0] * M
    c = 0
    for index, bit in enumerate(bits):
        if not bit:
            continue

        book = books[index]
        c += book[0]
        for i in range(len(points)):
            points[i] += book[i + 1]

    if all([point >= X for point in points]):
        found = True
        cost = min(cost, c)

if not found:
    cost = -1

print(cost)


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

#define N 1001
#define Mod 1000000007

int ans[N][N];

int main() {
	int n, m;

	cin >> n >> m;

	char a[n][m];

	for (int i = 0;i < n;i++) {
		for (int j = 0;j < m;j++) {
			cin >> a[i][j];
		}
	}

	ans[0][0] = 1;

	for (int i = 0;i < n;i++) {
		for (int j = 0;j < m;j++) {
			if (a[i][j] == '#') continue;

			if (i - 1 >= 0) {
				ans[i][j] += ans[i - 1][j];
				ans[i][j] %= Mod;			
			}

			if (j - 1 >= 0) {
				ans[i][j] += ans[i][j - 1];
				ans[i][j] %= Mod;
			}	
		}
	}

	cout << ans[n - 1][m - 1];
}


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

public class Program
{
    public static List<long> dp = new List<long>();
    public static long input;
    public static void Main(string[] args)
    {
        input = long.Parse(Console.ReadLine());

        for (int i = 1; i <= Math.Sqrt(input); i++)
        {
            if (input%i == 0)
            {
                dp.Add(i + (input / i));
            }
        }
        Console.WriteLine(dp.Min() - 2);
    }
}

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

// using namespace std;
// typedef long long ll;

// #define rep(i, n) for (int i = 0; i < (n); i++)
// #define rep2(i, a, b) for (int i = (a); i < (b); ++i)
// #define all(a) (a).begin(), (a).end()
// #define all2(a, b) (a).begin(), (a).begin() + (b)
// #define debug(vari) cerr << #vari << " = " << (vari) << endl;

// int main()
// {
//     int N;
//     cin >> N;

//     vector<int> vec(N);
//     rep(i, N) cin >> vec[i];

//     bool flag = true;
//     rep(i, N)
//     {
//         if (vec[i] % 2 == 0)
//         {
//             if (vec[i] % 3 != 0 || vec[i] % 5 != 0)
//             {
//                 flag = false;
//             }
//         }
//     }

//     cout << (flag ? "APPROVED" : "DENIED") << endl;

//     return 0;
// }

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

int main()
{
    int w, h, n;
    cin >> w >> h >> n;

    vector<int> x(n), y(n), a(n);
    rep(i, n) cin >> x[i] >> y[i] >> a[i];

    int x_min = 0, y_min = 0, x_max = w, y_max = h;

    rep(i, n)
    {
        if (a[i] == 1)
        {
            x_min = max(x_min, x[i]);
        }
        else if (a[i] == 2)
        {
            x_max = min(x_max, x[i]);
        }
        else if (a[i] == 3)
        {
            y_min = max(y_min, y[i]);
        }
        else
        {
            y_max = min(y_max, y[i]);
        }
    }

    int ans;
    if (x_min >= x_max || y_min >= y_max)
    {
        ans = 0;
    }
    else
    {
        ans = (x_max - x_min) * (y_max - y_min);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>

#define MOD (long long)(1e9 + 7)

using namespace std;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    long long n, k, sum = 0;

    cin >> n >> k;

    for(int i=k; i<=n+1; i++){
        sum += (i * (n - i + 1)) + 1;
        //cout << sum << endl;
    }
    
    cout << sum % MOD;

    return 0;

}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, m, ans = 0;
    cin >> n >> m;
    vector<int> c(m + 1);
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        for(int j = 0; j < a; j++){
            int x;
            cin >> x;
            c[x]++;
        }
    }
    for(auto&& i : c){
        if(i == n) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean hasPattern = false;
		for (int i = 0; i <= N && hasPattern == false; i += 4) {
			for (int j = 0; j <= N && hasPattern == false; j += 7) {
				int sum = i + j;
				if (sum == N)
					hasPattern = true;
			}
		}
		System.out.println(hasPattern ? "Yes" : "No");
		sc.close();
	}
}

Measured memory_bytes: 23508
import java.util.Scanner;

public class Main{

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

        // input
        int num = scan.nextInt();
        int min = scan.nextInt();
        int count = 1;
        for(int i = 1; i < num; i++){
            int temp = scan.nextInt();
            if(temp >= min){
                count++;
                min = temp;
            }
        }

        // answer
        System.out.println(count);

    }
}

Measured memory_bytes: 23636
#include<stdio.h>
int main(void)
    {
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if (a < b && b < c){
	   printf("Yes\n");
	}
	else{
		printf("No\n");
	}	
 	return 0;
}
	

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

using namespace std;

const int maxn = 2e3 + 5;

int a[maxn];

int main() {
	int n;
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 0 ; i < n ; i++) {
		cin >> a[i];
	}
	sort(a , a + n);
	long long ans = 0;
	for(int i = 0 ; i < n -2; i++) {
		for(int j = i + 1 ; j < n - 1; j++) {
			int t = a[i] + a[j];
			int left = j + 1, right = n - 1;
			while(left < right) {
				int mid = (left + right + 1) / 2;
				if(a[mid] < t)left = mid;
				else right = mid - 1;
			}
			if(left > j && a[left] < t) 
			ans += left - j;
		}
	}
	cout << ans << "\n";
	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 all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

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


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

    int n, a;
    cin >> n >> a;
  
    cout << n * n -a << endl;

    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;

const int  mod = 1000000007;

struct mint{
    ll x;
    mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
    mint& operator+=(const mint a){//operatorは構造体同士の比較に用いられる
        if((x +=a.x)>=mod) x-=mod;
        return *this;//thisとは現在のオブジェクトのこと
    }
    mint& operator-=(const mint a){
        if((x +=mod-a.x)>=mod) x-=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=mod;
        return *this;
    }
    mint operator+(const mint a){
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a){
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a){
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const{
        if(!t) return 1;
        mint a=pow(t>>1);
        a*=a;
        if(t&1) a*=*this;
        return a;
    }
    mint inv() const{
        return pow(mod-2);//逆元
    }

    mint&operator/=(const mint a) {
        return (*this)*=a.inv();
    }
    mint&operator/(const mint a) const{
        mint res(*this);
        return res/=a;
    }
};

pair<ll, ll> f(int l){
    /*0, 1の順に返している*/
    if(l<1) return pair<ll, ll>(0, 0);
    if(l==1) return pair<ll, ll>(1, 1);
    return pair<ll, ll>(f(l-1).first+f(l-1).second, f(l-1).first);
}

int main(void){
    int h, w, k;
    cin>>h>>w>>k;
    --k;
    vector<vector<mint> > dp(h+1, vector<mint>(w));
    if(w==1) {
        cout<<1<<endl;
        return 0;
    }
    dp[1][0]=f(w-2).first+f(w-2).second;
    dp[1][1]=max((ll)1, f(w-3).first+f(w-3).second);
    for(int i=2;i<=h;i++){
        rep(j, w){
            if(j==0) {
                pair<ll, ll> fw=f(w-2);
                pair<ll, ll> fw_1=f(w-3);
                mint a=dp[i-1][j]*max((ll)1, fw.first+fw.second);
                mint b=dp[i-1][j+1]*max((ll)1, fw_1.first+fw_1.second);
                dp[i][j]=a+b;
            }
            else if(j==w-1) {
                pair<ll, ll> fw=f(w-2);
                pair<ll, ll> fw_1=f(w-3);
                mint a=dp[i-1][j]*max((ll)1, fw.first+fw.second);
                mint b=dp[i-1][j-1]*max((ll)1, fw_1.first+fw_1.second);
                dp[i][j]=a+b;
            }
            else {
                pair<ll, ll> fk=f(j-1);
                pair<ll, ll> fw=f(w-j-2);
                pair<ll, ll> fk_1=f(j-2);
                pair<ll, ll> fw_1=f(w-j-3);
                mint a=dp[i-1][j]*max((ll)1, fk.first+fk.second)*max((ll)1, fw.first+fw.second);
                mint b=dp[i-1][j-1]*max((ll)1, fk_1.first+fk_1.second)*max((ll)1, fw.first+fw.second);
                mint c=dp[i-1][j+1]*max((ll)1, fk.first+fk.second)*max((ll)1, fw_1.first+fw_1.second);
                dp[i][j]=a+b+c;
            }
            //cout<<dp[i][j].x<<", ";
        }
        //cout<<endl;
    }
    cout<<dp[h][k].x<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))

a.sort()
alice=0
bob=0

for i in range(n//2):
    alice+=a[-1-i*2]

for i in range(n//2):
    bob+=a[-2-2*i]

if n%2!=0:
    alice+=a[0]


print(alice-bob)

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

using namespace std;

int main(){
    int n,m, x,y,suma = 0;
    vector<pair<int,int>> b;
    vector<int> a;
    cin >> n;   
    for(int i = 0; i < n; i++){
        cin >> x;
        a.push_back(x);
        suma += x;
    }
    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        b.push_back(make_pair(x,y));
    }

    for(int i = 0; i < m;i++){
        y = a[b[i].first - 1] - b[i].second;
        cout << suma - y << endl;
    }
        
        
    return 0;
}

Measured memory_bytes: 3580
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Text.Printf (printf)

rate :: Int -> Int
rate n
    | n < 400   = 1
    | n < 800   = 2
    | n < 1200  = 3
    | n < 1600  = 4
    | n < 2000  = 5
    | n < 2400  = 6
    | n < 2800  = 7
    | n < 3200  = 8
    | otherwise = 9

main :: IO ()
main = do
    getLine
    as <- fmap read . words <$> getLine :: IO [Int]

    let (bs, cs) = partition ((== 9) . head) . group . sort $ fmap rate as
    let colors = length cs
    let js = if null bs then 0 else length (head bs)

    if colors == 0
        then printf "%d %d\n" (1 :: Int) (colors + js)
        else printf "%d %d\n" colors     (colors + js)

Measured memory_bytes: 1020
import sys
import math
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    a,b,n = IL()
    x = min(b-1,n)
    print(math.floor(a*x/b)-a*math.floor(x/b))
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 9124
from collections import deque

N,u,v = map(int,input().split())

root = [[] for i in range(N)]
for _ in range(N-1):
    a, b = (int(x) for x in input().split())
    root[b-1].append(a-1)
    root[a-1].append(b-1) 

def search(p):
    stack=deque([p])
    check = [-1]*N
    check[p] = 0

    while len(stack)>0:
        v = stack.popleft()
        for i in root[v]:
            if check[i] == -1:
                check[i]=check[v]+1
                stack.append(i)
    return check

taka = search(u-1)
aoki = search(v-1)
ans = 0
for i in range(N):
    if taka[i] < aoki[i]:
        ans = max(ans, aoki[i]-1)
print(ans)

Measured memory_bytes: 91640
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
ll n, k;
int main(){
	scanf("%lld %lld", &n, &k);
	n -= (n/k)*k;
	printf("%lld\n", min(llabs(n-k), n));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
int n,a;

//inputします
void input() {
	cin >> n >> a;
}

//ライブラリ置き場


//main
int main() {
    input();
	int ans = 0;
	while (n > 0) {
		n -= a;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
function Main( ) {
  var input = require( 'fs' ).readFileSync( '/dev/stdin' ).toString();
  var data = input.split( " " ).map( Number );
  var a = data[0];
  var b = data[1];
  var C = data[2]*(Math.PI/180);
   
  var h = Math.sin( C )*b;
  var ta = Math.cos( C )*b;
  var c = Math.sqrt( Math.pow( (a-ta), 2 )+Math.pow( h, 2 ) );
   
  var S = (a*h)/2;
  var L = a+b+c;
  console.log( S+'\n'+L+'\n'+h );
};
 
Main();

Measured memory_bytes: 15552
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

int main(){
  int N;
  double x, y;
  cin >> N;
  vector<pair<double, double>> points;
  for (int i=0; i<N; i++){
    cin >> x >> y;
    points.emplace_back(pair<double, double>({x, y}));
  }
  vector<int> v(N);
  iota(v.begin(), v.end(), 0);
  double ans = 0;
  int count = 0;
  do {
    double tmp = 0;
    for (int i=0; i<N-1; i++){
      tmp += sqrt(pow(points[v[i]].first - points[v[i + 1]].first, 2) + 
                  pow(points[v[i]].second - points[v[i + 1]].second, 2));
    }
	ans += tmp;
    cerr << tmp << endl;
    count++;
  } while (next_permutation(v.begin(), v.end()));
  cout << fixed << setprecision(10) << ans / (double)count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>  
using namespace std;
int dp[3003][3003];
int main()
{
    string s,t;
    cin>>s>>t;
    for(int i=0;i<=s.size();i++)
    {
        for(int j=0;j<=t.size();j++)
        {
            if(i==0||j==0)dp[i][j]=0;
            else if(s[i-1]==t[j-1])dp[i][j]=1+dp[i-1][j-1];
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i=s.size(),j=t.size();
    string x;
    while(i>0 && j>0)
    {
        if(dp[i][j]==dp[i-1][j])i--;
        else if(dp[i][j]==dp[i][j-1])j--;
        else 
        {
            x+=s[i-1];
            i--;j--;
        }
    }
    i=x.size();
    while(i--)cout<<x[i];
}


Measured memory_bytes: 35456
N,X=(int(i) for i in input().split())
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
b=[]
for i in range(N):
    c=x[i+1]-x[i]
    b.append(c)

def zako(m,n):
    s=max(m,n)
    t=min(m,n)
    while s%t!=0:
        ss =s%t
        s=t
        t=ss
    else:
        return t
dodo=b[0]
for j in range(N-1):
    bobo = zako(b[j+1],dodo)
    dodo = bobo
print(dodo)

Measured memory_bytes: 14252
n = gets.to_s.to_i
 
ans = 0
1.upto(n) do |i|
  1.upto(n) do |j|
    t = i.gcd(j)
    1.upto(n) do |k|
      ans += t.gcd(k)
    end
  end
end
 
puts ans

Measured memory_bytes: 14392
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i

c = 0
(A+1).times do |i|
  (B+1).times do |j|
    (C+1).times do |k|
      c += 1 if (500*i + 100*j + 50*k) == X
    end 
  end
end
puts c

Measured memory_bytes: 14188
import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int s;
        if(A==B){s = A * 2;}
        else {
            if (Math.max(A, B) == A) {
                s = 2 * A - 1;
            } else {
                s = 2 * B - 1;
            }
        }
        System.out.println(s);

    }
}


Measured memory_bytes: 21204
#include <stdio.h>

int main(){
    int i, j;
    char c[2][4];
    char cr[2][4];

    scanf("%s", c[0]);
    scanf("%s", c[1]);

    for(j = 0; j < 2; j++){
        for(i = 0; i < 3; i++){
            cr[1-j][2-i] = c[j][i];
        }
    }

    for(j = 0; j < 2; j++){
        for(i = 0; i < 3; i++){
            if(c[j][i] != cr[j][i]){
                printf("NO\n");
                return 0;
            }
        }
    }

    printf("YES\n");

    return 0;
}

Measured memory_bytes: 128
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

void solve_main()
{
	QWORD A, B, C;

	cin >> A >> B >> C;

	if (C > (A - B)) {
		cout << C - (A - B) << endl;
	} else {
		cout << 0 << endl;
	}
}

int main()
{
#ifdef FOR_IDE
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
#endif

	solve_main();
	return 0;
}


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

using namespace std ; 

const int N = 1e6 +  7 ; 

long long n , ans ; 
long long a , b, c ; 
string s;

int main(){
    ios_base::sync_with_stdio(0) ; 
    cin.tie(0) ; 
   // freopen("in.in" , "r" , stdin) ; 
    cin>>n ; 
    cin>>s ; 
    for(auto u : s ){
        if(u=='R')a++ ; 
        else if(u=='G')b++ ; 
        else c++ ; 
    }
    ans = 1ll * a * b * c ; 
    for(int i = 1 ;i <n ;i++){
        for(int j = 0 ;  ; j++){
            if(j + 2*i>=n)break;
            bool is = (s[j] != s[i+j] && s[i+j] !=s[2*i+j] && s[j] !=s[j+2*i]) ; 
            ans-=is ; 
        }
    }
    cout<<max(0ll , ans ) ;
    return 0 ; 
}

Measured memory_bytes: 3636
<?php

fscanf(STDIN, "%d", $n);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$B = array_map('intval', explode(' ', trim(fgets(STDIN))));
$C = array_map('intval', explode(' ', trim(fgets(STDIN))));

sort($A);
sort($B);
sort($C);

$sum = 0;
for ($i = 0; $i < $n; ++$i) {
    $target = $B[$i];

    // A
    $l = 0;
    $r = $n;
    while ($r - $l >= 1) {
        $mid = floor(($l + $r) / 2);

        if ($A[$mid] >= $target) {
            $r = $mid;
        } else {
            $l = $mid + 1;
        }
    }
    $al = $l;

    // C
    $l = 0;
    $r = $n;
    while ($r - $l >= 1) {
        $mid = floor(($l + $r) / 2);

        if ($C[$mid] > $target) {
            $r = $mid;
        } else {
            $l = $mid + 1;
        }
    }
    $cl = (int) ($n - $l);

    $sum = (int) ($sum + (int) ($al * $cl));
}

echo $sum;


Measured memory_bytes: 25148
import java.io.*;
import java.util.*;

class Main {

	static int moves(int die, int limit)
	{
		int cnt = 0;
		if(die>=limit) return 0;
		
		while(die < limit)
		{
			cnt++;
			die = 2*die;
		}
		return cnt;
	}
	public static void main(String[] args) {
		
		FastScanner s = new FastScanner();
		int n = s.nextInt();
		int k = s.nextInt();
		
		double ans = 0;
		
		for(int i  = 1 ; i <= n ; i++)
		{
			ans = ans + (1.0/(1.0*n)) * (1.0/(1.0*Math.pow(2.0, 1.0*moves(i, k))) ) ;
		}
		System.out.println(ans);
		
	}

static   class FastScanner {
		
	    private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner() {
			this(System.in);
		}

		public FastScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		
		}	

	}

}


Measured memory_bytes: 21076