akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    int k = 0;
    rep(i, 3)
    {
        k += a[i] % 2;
    }

    int cost = 0;
    if (k == 1) {
        cost++;
        rep(i, 3)
        {
            a[i] = a[i] / 2 * 2 + 1;
        }
    } else if (k == 2) {
        cost++;
        rep(i, 3)
        {
            a[i] = (a[i] + 1) / 2 * 2;
        }
    }

    int m = max(a[0], max(a[1], a[2]));
    cost += (3 * m - a[0] - a[1] - a[2]) / 2;
    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 256
void main()
{
    long n, k;
    ipElems(n, k);
    double[] p = rdRow!double;

    double[] q = new double[n];
    foreach (i; 0 .. n)
    {
        q[i] = p[i] * (p[i] + 1) / (2.0 * p[i]);
    }

    double[] lists = new double[n-k+1];
    lists[0] = q[0..k].sum;

    double result = lists[0];
    foreach (i; 1 .. n-k+1)
    {
        lists[i] = lists[i-1] - q[i-1] + q[k+i-1];
        result = max(result, lists[i]);
    }


    writefln("%.15f", result);
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void ipElems(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 13480
n, k, c = map(int, input().split())
s = list(input())
os = 0
for ss in s:
    if ss == 'o':
        os += 1
s2 = list(reversed(s))

if c == 0 and os > k:
    exit(0)

def calc(s):
    global n, k, c
    answer = set()
    pre = None
    for idx, i in enumerate(s):
        if i == 'o' and (pre is None or idx > pre + c):
            answer.add(idx + 1)
            # 前回働いた日を記録
            pre = idx
        if len(answer) >= k:
            return answer

answer1 = sorted(list(calc(s)))
answer2 = calc(s2)
answer2 = sorted(list(set(map(lambda x: len(s2) - x + 1, answer2))))
# print(answer1)
# print(answer2)

for i in range(len(answer1)):
    if answer1[i] == answer2[i]:
        print(answer1[i])


Measured memory_bytes: 50792
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n,h,w;
  cin>>n;
  cin>>h;
  cin>>w;
  cout << (n-h+1)*(n-w+1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll MOD = (ll)(1e9 + 7);
constexpr ll MAX = 300 * 300;

ll power(const ll p, const ll n)
{
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 1) {
        return (power(p, n - 1) * p) % MOD;
    } else {
        const ll pp = power(p, n / 2);
        return (pp * pp) % MOD;
    }
}

int main()
{
    ll d;
    cin >> d;
    vector<ll> l(d);
    for (ll i = 0; i < d; i++) {
        cin >> l[i];
    }
    ll s;
    cin >> s;

    vector<vector<ll>> dp(2, vector<ll>(s + 1, 0));
    vector<vector<ll>> prev(2, vector<ll>(s + 1, 0));

    prev[0][0] = 1;
    for (ll i = 0; i < d; i++) {
        for (ll j = 0; j < 2; j++) {
            for (ll k = 0; k <= s; k++) {
                dp[j][k] += prev[j][k];
                dp[j][k] %= MOD;
                const ll sum = k + l[i];
                if (sum <= s) {
                    dp[(j + 1) % 2][sum] -= prev[j][k];
                    dp[(j + 1) % 2][sum] %= MOD;
                }
            }
        }
        prev = dp;
        fill(dp.begin(), dp.end(), vector<ll>(s + 1, 0));
    }
    ll sum = 0;
    for (ll i = 0; i <= s; i++) {
        for (ll j = 0; j < 2; j++) {
            sum += prev[j][i] * power(s - i, d);
            sum %= MOD;
            sum = (sum + MOD) % MOD;
        }
    }
    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 6304
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define ll long long

const int MOD = 1e9 + 7;

int main()
{
    int k, s;
    cin >> k >> s;

    int cnt = 0;
    REP(x, k + 1)
    {
        REP(y, k + 1)
        {
            int z = s - x - y;
            if(z <= k && z >= 0)
            {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
 
int n,maxi;
int Ea[81],dp[81][321][321];
 
int rec(int idx,int prev,int now){
  if(idx == n-1) return now;
  if(dp[idx][prev][now]) return dp[idx][prev][now];
  int res = 0;
  res = rec(idx+1,now,Ea[idx+1]);
  if(now > 0) res = max(res,rec(idx+1,now-1,prev + Ea[idx+1]));
  return dp[idx][prev][now] = res;
}
 
 
int main(){
  int N;
  cin >> N;
  while(N--){
    memset(dp,0,sizeof(dp));
    cin >> n;
    for(int i=0;i<n;i++) cin >> Ea[i];
    cout << ((n == 1)? Ea[0] : rec(1,Ea[0],Ea[1])) << endl;
  }
}

Measured memory_bytes: 33776
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
int main()
{
  int x, y;
  cin >> x >> y;
  for (int i = 0; i <= x; i++)
  {
    int kame = x - i;
    if (i * 2 + kame * 4 == y)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL (vec)(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define eb emplace_back
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
#define PQ priority_queue
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

void comb(V<VL>&n){
  rep(i,SZ(n)){
    n[i][0]=1;
    n[i][i]=1;
  }
  reps(i,SZ(n)-1)
    reps(j,i-1)
      n[i][j]=n[i-1][j-1]+n[i-1][j];
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,p;
  cin>>n>>p;
  vector<long> a(n);
  rep(i,n)cin>>a[i];

  int even=0,odd=0;
  for(auto e:a)(e&1?odd:even)++;
  if(odd==0){
    if(p==0)out((ll)pow(2,n));
    else out(0);
  }
  else{
    out((ll)pow(2,n-1));
  }
  
  
  return 0;
}

// WA
/*
  int even=0,odd=0;
  rep(i,n)(a[i]&1?odd:even)++;
  VV(ll,Even,even+1,even+1,0);
  VV(ll,Odd,odd+1,odd+1,0);
  comb(Even);
  comb(Odd);

  ll res=0;
  if(p==0){
    res+=Even[even][even];
    for(int i=0;i<odd;i+=2)res+=Odd[odd][i];
  }
  else{
    for(int i=1;i<odd;i+=2)res+=Odd[odd][i];
  }
  out(res);
  */

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

const int N_MAX = 25;

int main(){
  int p[N_MAX];

  int n;

  scanf("%d", &n);

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

  int ans = 0;

  for(int i = 1; i < n-1; i++){
    if (p[i] > p[i-1] && p[i] < p[i+1]) ans++;
    else if (p[i] < p[i-1] && p[i] > p[i+1]) ans++;
  }

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

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  rep(i,N) cin >> A[i];
  rep(i,N) cin >> B[i];
  rep(i,N-1) cin >> C[i];
  int ans = 0;
  rep(i, N){
    ans += B[A[i]-1];
    if(A[i+1] == A[i]+1){
      ans += C[A[i]-1];
    }
  }
  cout << ans << endl;
  }


Measured memory_bytes: 256
N,M=map(int,input().split())
lrc = [tuple(map(int,input().split())) for _ in range(M)]
lrc = sorted(lrc)
INF=10**20

class SegTree:
    """ segment tree with point modification and range product. """
    # # https://yukicoder.me/submissions/452850
    def __init__(self, N, data_f = min, data_unit=1<<30):
        self.N = N
        self.data_f = data_f
        self.data_unit = data_unit
        self.data = [self.data_unit] * (N + N)

    def build(self, raw_data):
        data = self.data
        f = self.data_f
        N = self.N
        data[N:] = raw_data[:]
        for i in range(N - 1, 0, -1):
            data[i] = f(data[i << 1], data[i << 1 | 1])

    def set_val(self, i, x):
        data = self.data
        f = self.data_f
        i += self.N
        data[i] = x
        while i > 1:
            data[i >> 1] = f(data[i], data[i ^ 1])
            i >>= 1

    def fold(self, L, R):
        """ compute for [L, R) """
        vL = vR = self.data_unit
        data = self.data
        f = self.data_f
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                vL = f(vL, data[L])
                L += 1
            if R & 1:
                R -= 1
                vR = f(data[R], vR)
            L >>= 1
            R >>= 1
        return f(vL, vR)

seg = SegTree(N,min,INF)
seg.set_val(0,0)

for i in range(1,M+1):
  l,r,c = lrc[i-1]
  tmp = seg.fold(l-1,r-1)
  seg.set_val(r-1,min(tmp+c, seg.fold(r-1,r)))

ans = seg.fold(N-1,N)
if ans == INF:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 30932
import java.util.Scanner;

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

    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    System.out.println(B + Math.min(C, A + B + 1));
  }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main(){
    int n;
    string a;
    cin >> n >> a;

    if(n < len(a)) {
        string b = a.substr(0, n);

        cout << b << "..." << '\n';
    }
    else {
        cout << a << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int,int>
#define PII pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
const int inf = 0x7fffffff; //beware overflow
const LL INF = 0x7fffffffffffffff; //beware overflow
#define mem(x, y) memset(x, (y), sizeof(x) );
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
LL ans = 0;
int L;
char w[30];
void dfs(LL acu, LL cur, int len) {
    if( len == L-1) {
        ans += acu+cur;
        return;
    }
    dfs(acu, cur*10+w[len+1]-'0', len+1);
    dfs(acu+cur, w[len+1]-'0', len+1);
}
int main() {
    scanf("%s", w);
    L = strlen(w);
    dfs(0, w[0]-'0', 0);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
  long long int N, M;
  cin >> N >> M;

  vector<long long int> A(M), B(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }

  vector<long long int> inconv(M);
  inconv[M - 1] = N * (N - 1) / 2;
  vector<vector<long long int> > group;
  map<long long int, long long int> belong;
  for (int i = M - 2; i >= 0; i--) {
    if (belong[A[i + 1]] == 0 && belong[B[i + 1]] == 0) {
      group.push_back(vector<long long int>(0));
      group.back().push_back(A[i + 1]);
      group.back().push_back(B[i + 1]);
      belong[A[i + 1]] = group.size();
      belong[B[i + 1]] = group.size();
      inconv[i] = inconv[i + 1] - 1;
    } else if (belong[A[i + 1]] == 0) {
      belong[A[i + 1]] = belong[B[i + 1]];
      group[belong[A[i + 1]] - 1].push_back(A[i + 1]);
      inconv[i] = inconv[i + 1] - group[belong[A[i + 1]] - 1].size() + 1;
    } else if (belong[B[i + 1]] == 0) {
      belong[B[i + 1]] = belong[A[i + 1]];
      group[belong[B[i + 1]] - 1].push_back(B[i + 1]);
      inconv[i] = inconv[i + 1] - group[belong[B[i + 1]] - 1].size() + 1;
    } else if (belong[A[i + 1]] != belong[B[i + 1]]) {
      int ori, target;
      if (group[belong[A[i + 1]] - 1].size() <= group[belong[B[i + 1]] - 1].size()) {
        ori = belong[A[i + 1]] - 1;
        target = belong[B[i + 1]] - 1;
      } else {
        target = belong[A[i + 1]] - 1;
        ori = belong[B[i + 1]] - 1;
      }
      inconv[i] = inconv[i + 1] - (long long int) group[target].size() * (long long int) group[ori].size();
      while(group[ori].size() > 0) {
        group[target].push_back(group[ori].back());
        belong[group[ori].back()] = belong[group[target][0]];
        group[ori].pop_back();
      }
    } else {
      inconv[i] = inconv[i + 1];
    }
  }

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

  return 0;
}


Measured memory_bytes: 19764
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long n;
	cin>>n;
	string s="";
	bool pl=1;
	while(n!=0){
		if(n%2){
			s='1'+s;
			n--;
		}else{
			s='0'+s;
		}
		n/=(-2);
	}
	if(s.size()==0)s='0';
	cout<<s<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (int)n; i++)

const int inf = 1'000'000'000;

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (int)n; i++)

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll c = a+b;
  ll ans = a * (n/c);
  // 青の途中で切れた場合と赤のボールにまで行った場合
  ans += min(n%c, a);
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define N 200005
using namespace std;
char str[N],mm[N];
int dp[N];
int route[N];
int a[30];
int main(void)
{
    scanf("%s",str + 1);
    int l = strlen(str+1);
    //memset(nex,-1,sizeof(nex));
    memset(route,-1,sizeof(route));
    memset(dp,0x3f,sizeof(dp));
    memset(a,-1,sizeof(a));
    int id = 0;
    dp[l+1] = 1;
    route[l+1] = l + 1;
    mm[l+1] = 0;
    for(int i = l+2;i < N;i++)
        dp[i] = 0;
    for(int i = 0; i < 26; i++)
        a[i] = l+1;
    for(int i = l; i >= 1; i--)
    {
        a[str[i]-'a'] = i;
        for(int j = 0; j < 26; j++)
        {
            if(dp[i] > dp[a[j] + 1] + 1)
            {
                mm[i] = j;
                //printf("%d\n",j);
                dp[i] = dp[a[j] + 1]+1;
                route[i] = a[j] + 1;
            }
        }
    }
    //printf("%d\n",dp[1]);
    int f = 1;
    while(f<l+1)
    {
        printf("%c",mm[f] + 'a');
        f = route[f];
    }
    return 0;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		int max = 0, prev = 0;
		for(int i = 0; i < n; i++) {
			int x = sc.nextInt(), y = sc.nextInt();
			if(x == y) {
				max = Math.max(max, prev + 1);
				prev++;
			} else {
				prev = 0;
			}
		}
		
		pw.println(max >= 3 ? "Yes" : "No");
		
		pw.flush();
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++)
				array[i] = new Integer(nextInt());
			return array;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public static int[] shuffle(int[] a) {
			int n = a.length;
			Random rand = new Random();
			for (int i = 0; i < n; i++) {
				int tmpIdx = rand.nextInt(n);
				int tmp = a[i];
				a[i] = a[tmpIdx];
				a[tmpIdx] = tmp;
			}
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 32944
// D - Prediction and Restriction
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N,K,R,S,P; string T;
	cin>>N>>K>>R>>S>>P>>T;
	vector<string> G(K); rp(i, 0, N) G[i%K] += T[i];
	int ans = 0;
	for(auto s:G)
		rp(i, 0, s.size())
			if(i>0 && s[i-1]==s [i]) s[i] = '-';
			else ans += s[i]=='r'?P:s[i]=='s'?R:S;
	cout<< ans <<endl;
}

Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#define out(a) printf("%d",a)
#define ll long long
using namespace std;
int n,last,b,ll1,ans;
struct dist
{
	int l,r;
}p[100050];
bool cmp(dist a,dist b)
{
    return a.l<b.l;
}
int read()
{
	int s=0,t=1; char ch;
	while (ch<'0'||ch>'9'){if (ch=='-') t=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*t;
}
int main()
{
	n=read();
	for (int i=1;i<=n;i++) 
		scanf("%d%d",&p[i].l,&p[i].r);
		sort(p+1,p+n+1,cmp);
		ll1=1;
	while (ll1<=n) {
		if (b==1) {
		ans+=p[ll1].r-last,b=0;
		if (p[ll1].r>=p[ll1+1].l) last=p[ll1].r,b=1;
	}
		else {
	  if (p[ll1].r<p[ll1+1].l) ans+=p[ll1].r-p[ll1].l+1;
	  else last=p[ll1].r,b=1,ans+=p[ll1].r-p[ll1].l+1;
     }
     ll1++;
	}
	out(ans);
}

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

int main(){
    string S;
    cin >> S;
    int price = 700;

    rep(i,3){
        if(S.at(i)=='o'){
        price += 100;
        }
    }
    cout << price << endl;
}



Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
static vector<int> table;

static int popcount(int x) {
    int cnt = 0;
    while (x) {
        cnt += x & 1;
        x >>= 1;
    }
    return cnt;
}

static int f(int x) {
    if (x == 0)
        return 0;
    if (x == 1)
        return 1;
    if (x == 2)
        return 1;

    auto& m = table[x];
    if (m >= 0)
        return m;

    m = 1 + f(x % popcount(x));
    return m;
}

int main() {
    int n;
    string x;
    cin >> n >> x;

    table = vector<int>(200'005, -1);

    auto pc_orig = count(x.begin(), x.end(), '1');
    auto posplus = vector<int>(200'005, -1);
    auto posminus = vector<int>(200'005, -1);
    auto remplus = 0;
    auto remminus = 0;
    {
        auto plus = 1;
        auto minus = 1;

        for (auto i = n - 1; i >= 0; --i) {
            posplus[i] = plus;
            posminus[i] = minus;

            remplus += (x[i] - '0') * plus;
            remplus %= (pc_orig + 1);
            remminus += (x[i] - '0') * minus;
            remminus %= pc_orig <= 1 ? 1 : (pc_orig - 1);

            plus = plus * 2 % (pc_orig + 1);
            minus = pc_orig <= 1 ? 0 : minus * 2 % (pc_orig - 1);
        }
    }

    for (auto i = 0; i < n; ++i) {
        auto&& pos = x[i] == '0' ? posplus : posminus;
        auto pc = pc_orig + (x[i] == '0' ? 1 : -1);
        auto cnt = 0;
        if (pc > 0) {
            auto rem = 0;
            if (x[i] == '0') {
                rem = remplus;
                rem += posplus[i];
                rem %= pc;
            } else {
                rem = remminus;
                rem += pc;
                rem -= posminus[i];
                rem %= pc;
            }

            cnt = 1 + f(rem);
            // cerr << x << " // " << rem << "\n";
        }

        cout << cnt << "\n";
    }

    return 0;
}


Measured memory_bytes: 5972
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chkmax(T& a,T b){return a<b?a=b,1:0;}
template<class T> inline bool chkmin(T& a,T b){return a>b?a=b,1:0;}
template<typename T> inline T& read(T& x){
    static char c; bool flag=0;
    while(!isdigit(c=getchar())) if(c=='-') flag=1;
    for(x=c-'0';isdigit(c=getchar());(x*=10)+=c-'0');
    if(flag) x=-x;
    return x;
}
const int maxn=200010;
int n,m,a[maxn],b[maxn];
int main(){
#ifdef xffyjq
    freopen("exec.in","r",stdin);
    freopen("exec.out","w",stdout);
#endif
    read(n);
    for(int i=1;i<=n;i++) read(a[i]);
    read(m);
    for(int i=1;i<=m;i++) read(b[i]);
    sort(a+1,a+n+1); sort(b+1,b+m+1);
    int j=1;
    for(int i=1;i<=m;i++){
        while(j<=n&&a[j]<b[i]) ++j;
        if(j>n||a[j]>b[i]) puts("NO"),exit(0);
        ++j;
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
	int S,h,m,s;
	scanf("%d",&S);
	h=S/3600;
	m=(S-h*3600)/60;
	s=S-h*3600-m*60;
	printf("%d:%d:%d\n",h,m,s);

	return 0;
}


Measured memory_bytes: 2052
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	long long x,y;
	int t=0;
	scanf("%lld%lld",&x,&y);
	while(x<=y){
		x*=2;
		t++;
	}
	printf("%d\n",t);
	return 0;
}

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

int main() {
  long long N;
  cin >> N;
  int n = sqrt(N);
  int num;
  while (n>0) {
    if (N%n == 0) {
      num = N/n;
      break;
    }
    n--;
  }
  string ans = to_string(num);
  cout << ans.size() << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define SIZE(a) int((a).size())

int main(){
  string s;cin>>s;
  int y,m,d;
  y=(s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+s[3]-'0';
  m=(s[5]-'0')*10+s[6]-'0';
  d=(s[8]-'0')*10+s[9]-'0';
  if(m>4){cout<<"TBD"<<endl;}
  else{{cout<<"Heisei"<<endl;}}
}

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

int main() {
    int n;
    cin >> n;
    vector<long double> a(n);
    rep(i,n) {
        int temp;
        cin >> temp;
        a[i] = 1.0/(long double)temp;
        // cout << a[i] << endl;
    }
    long double ans=0.0;
    rep(i,n) ans += a[i];
    cout << (long double) 1.0/ans <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int a,b,c,n,i,t;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d%d%d",&a,&b,&c);
    if(a<b){
      t=a;a=b;b=t;
    }
    if(a<c){
      t=a;a=c;c=t;
    }
    printf("%s\n", (a*a-b*b-c*c)==0?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String O = input.readLine();
        String E = input.readLine();
        System.out.println(zip(O, E));
    }

    private static String zip(String first, String second) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < second.length(); i++) {
            builder.append(first.charAt(i));
            builder.append(second.charAt(i));
        }
        if (first.length() > second.length()) {
            builder.append(first.charAt(first.length() - 1));
        }
        return builder.toString();
    }
}


Measured memory_bytes: 21460
#include<iostream>
using namespace std;
main(){
	string ap="apple",pe="peach";
	string str;
	getline(cin,str);
	int c1=0,c2=0,c=0;
	for(int i=0;i<str.size();++i){
		string s="";
		for(int j=i;j<i+5;++j){
			s+=str[j];
		}
		if(s==ap){
			for(int j=i;j<i+5;++j){
				str[j]=pe[j-i];
			}
		}
		if(s==pe){
			for(int j=i;j<i+5;++j){
				str[j]=ap[j-i];
			}
		}
	}
	cout<<str<<endl;
}

Measured memory_bytes: 1188
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
struct edge{ll to,cost;};
vector<vector<edge>> graph;
vector<vector<bool>> used;
vector<ll> A;
vector<ll> d1;
int n,m;
void dijkstra(ll s){
    d1.resize(n);
    for(int i=0;i<n;i++)d1[i]=inf;//訪れていない頂点をinfで初期化
    d1[s]=0;
    priority_queue<P,vector<P>,greater<P>> q;
    q.push(P(0,s));//始点を０で置く
    while(!q.empty()){
        P a=q.top();
        q.pop();
        if(d1[a.se]<a.fi)continue;
        for(int i=0;i<graph[a.se].size();i++){
            edge e=graph[a.se][i];
            if(d1[e.to]>d1[a.se]+e.cost){
                d1[e.to]=d1[a.se]+e.cost;//訪れていないorより低いコストの経路を発見した時、値を更新
                q.push(P(d1[e.to],e.to));//コストの低いところ優先のbfs
            }
        }
    }
    return;
}
int main(){
    cin>>n>>m;
    graph.resize(n);
    for(int i=0;i<m;i++){
           ll l,r,c;
           cin>>l>>r>>c;
           l--;r--;
           graph[l].push_back(edge{r,c});
    }
    for(int i=0;i<n-1;i++)graph[i+1].push_back(edge{i,0});
    dijkstra(0);
    if(d1[n-1]==inf)cout<<-1<<endl;
    else cout<<d1[n-1]<<endl;
    
}


Measured memory_bytes: 9336
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int main(){
    int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
    int s=0;
    s+=a;
    s+=b*5;
    s+=c*10;
    s+=d*50;
    s+=e*100;
    s+=f*500;
    if(s>=1000){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef  long long   ll;
typedef  long double ld;
#define ceil(n, m) ((n / m) + ( n % m ? 1 : 0))
#define mod(n, m) (((n % m) + m) % m)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    ll ans = 0;
    vector<int> a(n);
    for(auto &i : a)
        cin >> i;
    map<vector<int>, bool> mp;
    for(int i = 0; i < n - 2; ++i)
        for(int j = i + 1; j < n - 1; ++j)
            for(int k = j + 1; k < n; ++k)
               if(a[i] != a[j] && a[i] != a[k] && a[j] != a[k]){
                   if(a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[k] + a[j] > a[i] )
                  // cout << i << " " << j << " " << k << '\n';
                   ++ans;
               }

    cout << ans;






}

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

using namespace std;

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

	return gcd(b, a % b);
}

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

	vector<int> list(N);
	for (int i = 0; i < N; i++)
	{
		cin >> list[i];

		list[i] = abs(X - list[i]);
	}

	int ans = pow(10, 9);
	for (int i = 0; i < N - 1; i++)
	{
		if (list[i] < list[i + 1])
		{
			swap(list[i], list[i + 1]);
		}

		list[i + 1] = gcd(list[i], list[i + 1]);
	}

	cout << list[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val sortedNumbers = sc.nextLine.split(" ").map(_.toInt).sorted.reverse
    println((sortedNumbers.head.toString + sortedNumbers(1)).toInt + sortedNumbers(2))
  }

}


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

int main()
{
	string s; cin >> s;
	for (int i = 0; i < 8; ++i)
	{
		int ans = s[0]-48;
		string op = "";
		for (int j = 2; j >= 0; --j)
		{
			if (i & 1 << j)
			{
				ans -= s[3-j]-48;
				op += "-";
			}
			else
			{
				ans += s[3-j]-48;
				op += "+";
			}
		}
		if (ans == 7)
		{
			op += "=";
			for (int i = 0; i < 4; ++i)
				cout << s[i] << op[i];
			cout << 7 << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;


int main(){
  int N; cin >> N;
  vector<int> X(N), L(N);
  rep(i, N) cin >> X.at(i) >> L.at(i);
  
  vector<int> s(N), e(N);
  vector<pair<int,int>> es(N);
  rep(i, N){
    s.at(i) = X.at(i) - L.at(i);
    e.at(i) = X.at(i) + L.at(i);
    es.at(i) = make_pair(e.at(i), s.at(i));
  }
  
  sort(es.begin(), es.end());
  
  int count1 = 0; int count2 = 0;
  vector<bool> remove(N, false);
  
  while(count1 < N){
    count2 = count1 + 1;
    while(count2 < N && es.at(count2).second < es.at(count1).first){
      remove.at(count2) = true;
      count2++;
    }
    count1 = count2;
  }
  
  int res = 0;
  rep(i, N){
    if(!remove.at(i)) res++;
  }
  
  
  cout << res;
  
}

Measured memory_bytes: 2560
import java.util.*;

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

        while(true){
            int x = sc.nextInt();
            String op = sc.next();
            int y = sc.nextInt();

            if(op.equals("+")){
                System.out.println(x + y);
            }else if(op.equals("-")){
                System.out.println(x - y);
            }else if(op.equals("*")){
                System.out.println(x * y);
            }else if(op.equals("/")){
                System.out.println(x / y);
            }else if(op.equals("?")){
                break;              
            }
        }
    }
}


Measured memory_bytes: 26432
#include <stdio.h>
#include <iostream>
#include <limits.h>
#include <cstdlib>
#include <algorithm>
#include <unordered_map>
#include <vector>
using namespace std;

int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  string ans = "No";
  a = a +b;
  if(c <= a)
    ans = "Yes";

  cout << ans << endl;
}


Measured memory_bytes: 256
'''input
6
1 2
1 3
1 4
1 5
1 6
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import defaultdict
import sys, threading


def get_source(graph):
	for i in graph:
		return i


def make(first, second):
	return str(first) + ' ' + str(second)


def dfs(graph, node, visited, color, medges, mx_c):
	visited[node] = True
	c = 1
	for i in graph[node]:
		if i not in visited:
			if color[node] == c:
				c += 1
			color[i] = c
			medges[make(node, i)] = c
			medges[make(i, node)] = c
			mx_c[0] = max(mx_c[0], c)
			c += 1
			dfs(graph, i, visited, color, medges, mx_c)


# main starts
def main():
	graph = defaultdict(list)
	n = int(input().strip())
	edges = []
	for _ in range(n - 1):
		u, v = list(map(int, input().split()))
		graph[u].append(v)
		graph[v].append(u)
		edges.append([u, v])

	s = get_source(graph)
	color = dict()
	visited = dict()
	color[s] = 0
	medges = dict()
	mx_c =[0]
	dfs(graph, s, visited, color, medges, mx_c)

	print(mx_c[0])
	for i, j in edges:
		print(medges[make(i, j)])


if __name__ == '__main__':
	sys.setrecursionlimit(100005)
	threading.stack_size(1 << 27)
	thread = threading.Thread(target = main)
	thread.start()



Measured memory_bytes: 99416
n, q = map(int, input().split())
s = list(input())
b = [[]*2 for _ in range(q)]
for i in range(q):
    b[i] = list(map(int, input().split()))

c = [0 for _ in range(len(s))]
count = 0

for i in range(len(s)):
    if s[i:i+2] == ["A", "C"]:
        count += 1
        c[i:i+2] = [count-1, count]
    else:
        c[i:i+2] = [count, count]

for i in range(q):
    start = b[i][0]-1
    end = b[i][1]-1
    ans = c[end] - c[start]
    print(ans)

Measured memory_bytes: 32920
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int N, K;
  cin >> N >> K;
  priority_queue<int> B;
  rep(i, N)
  {
    int n;
    cin >> n;
    B.push(n);
  }
  int result = 0;
  rep(i, K)
  {
    result += B.top();
    B.pop();
  }
  cout << result << endl;
}

Measured memory_bytes: 256
def solve(n, aaa):
    dp = [0]
    aaa_with_idx = list(zip(aaa, range(n)))
    aaa_with_idx.sort(reverse=True)
    for k in range(1, n + 1):
        ndp = [0] * (k + 1)
        a, i = aaa_with_idx[k - 1]
        for l in range(k):
            # 左に配置
            ndp[l + 1] = max(ndp[l + 1], dp[l] + a * abs(i - l))
            # 右に配置
            r = n - (k - l)
            ndp[l] = max(ndp[l], dp[l] + a * abs(i - r))
        dp = ndp
    return max(dp)


n = int(input())
aaa = list(map(int, input().split()))
print(solve(n, aaa))


Measured memory_bytes: 9320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll match[1005][1005]={0};
ll day[1005]={0},used[1005]={0};
int main(){
  ll n;
  cin>>n;
  for(int i=1;i<=n;i++){
    for(int j=1;j<n;j++) cin>>match[i][j];
  }
  queue<P> que;
  for(int i=1;i<n;i++){
    for(int j=i+1;j<=n;j++){
      if(match[i][1]==j&&match[j][1]==i){
        que.push(P(i,j));
        day[i]++;
        day[j]++;
        used[i]++;
        used[j]++;
      }
    }
  }
  while(!que.empty()){
    P p=que.front();
    que.pop();
    int a=p.first,b=p.second;
    int ato=match[a][used[a]+1],bto=match[b][used[b]+1];
    while(match[ato][used[ato]+1]==a||match[bto][used[bto]+1]==b){
      if(match[ato][used[ato]+1]==a){
        ll dy=max(day[a],day[ato])+1;
        day[a]=dy;
        day[ato]=dy;
        used[a]++;
        used[ato]++;
        que.push(P(a,ato));
        ato=match[a][used[a]+1];
        bto=match[b][used[b]+1];
      }
      if(match[bto][used[bto]+1]==b){
        ll dy=max(day[b],day[bto])+1;
        day[b]=dy;
        day[bto]=dy;
        used[b]++;
        used[bto]++;
        que.push(P(b,bto));
        ato=match[a][used[a]+1];
        bto=match[b][used[b]+1];
      }
    }
  }
  ll ans=0;
  for(int i=1;i<=n;i++){
    if(used[i]!=n-1) {
      cout<<-1<<endl;
      return 0;
    }
  }
  for(int i=1;i<=n;i++) ans=max(ans,day[i]);
  cout<<ans<<endl;
}


Measured memory_bytes: 9856
#pragma GCC optimize(2,3,"Ofast","unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in ll read()
	{
		ll x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<=32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
#define pb push_back
const int p=998244353;
map<string,int>mp[2];string s;
in void M(int &x) {x-=p;x+=x>>31&p;}
int f(int t,string s)
{
	if(mp[t].find(s)!=mp[t].end()) return mp[t][s];
	int len=s.length(),res=0;
	if(t)
	{
		for(int i=0;i<len;i++) M(res+=1ll*f(1,s.substr(0,i))*f(0,s.substr(i,len))%p);
		return mp[t][s]=res;
	}
	for(int i=1;i<len;i++) if(!(len%i))
	{
		string t="";for(int j=0;j<i;j++) t+='1';
		for(int j=0;j<len;j+=i) for(int k=0;k<i;k++) if(s[j+k]=='0') t[k]='0';
		M(res+=f(1,t));
	}
	return mp[t][s]=res;
}
int main()
{
	mp[0][""]=mp[1][""]=mp[0]["0"]=mp[1]["0"]=1,mp[0]["1"]=mp[1]["1"]=2;
	cin>>s;write(f(1,s),'\n');
	return ot(),0;
}
//Author: disangan233

Measured memory_bytes: 14028
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
        int N,P; cin >> N >> P;
        if (N == 0 && P == 0) break;
        int k = P;
        int cnt = 0;
        vector<int> A(N);
        while (1) {
            if (k != 0) {
                k--;
                A[cnt]++;
                if (A[cnt] == P) break;
            } else {
                k = A[cnt];
                A[cnt] = 0;
            }
            cnt++;
            if (cnt == N) cnt = 0;
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
{
    cout<<"3"<<endl;
}
else if((s[0]=='R'&&s[1]=='R')||(s[1]=='R'&&s[2]=='R'))
{
    cout<<"2"<<endl;
}
else if(s[0]=='R'||s[1]=='R'||s[2]=='R')
{
    cout<<"1"<<endl;
}
else
{
    cout<<"0"<<endl;
}
return 0;
}


Measured memory_bytes: 3512
from itertools import accumulate
MOD = 10 ** 9 + 7
S = int(input())

# dp[a][b]: 長さaで、合計bである数列の数

dp = [0] * (S+4)
dp[0] = 1
acc = list(accumulate(dp))
acc[-1] = acc[-2] = acc[-3] = 0

ans = 0
for a in range(700):
    ndp = []
    for b in range(S+1):
        ndp.append(acc[b-3] % MOD)
    ndp += [0, 0, 0]
    ans += ndp[S]
    ans %= MOD
    dp = ndp
    acc = list(accumulate(dp))
    acc[-1] = acc[-2] = acc[-3] = 0

print(ans)


Measured memory_bytes: 9420
import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    String s[]=br.readLine().split(" ");
      	int a=Integer.parseInt(s[0]);
		float b=Float.parseFloat(s[1]);
      	System.out.printf("%.0f",a*b);
      System.out.println();

    }
}


Measured memory_bytes: 25780
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;


int main() {

	string p;
	cin >> p;
	cout << p[0] << p.size() - 2 << p[p.size() - 1] << endl;
	return 0;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	vector<char>v(n);
	for (int i = 0;i < n;i++){
		cin>>v[i];
	}
	for (auto i = v.begin();i != v.end();i++){
		if(*i == *(i-1)){
			v.erase(i);
			i--;
		}
	}
	
	cout<<v.size();
}

Measured memory_bytes: 384
from builtins import print


def comb(n, m) :
    ans = 1
    for i in range(n) :
        ans *= i+1
    for i in range(m) :
        ans //= i+1
    for i in range(n-m) :
        ans //= i+1
    return ans


N, A, B = map(int, input().split())
val = list(reversed(sorted((map(int, input().split())))))

ret = 0

prev = [0, 1]
for i in range(A, B+1) :
    cur = [ sum( [ val[j] for j in range(i) ]) , i]
    if i > A :
        if prev[0] * cur[1] > prev[1] * cur[0] :
            break
    cntLarge = [ 1 if v > val[A] else 0 for v in val  ].count(1)
    ret += comb( val.count(val[i-1]) ,i - cntLarge)
    prev = cur

print(format(prev[0] / prev[1], '.12f'))
print(ret)


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    cin >> n;
    vl x(n), sorted(n);
    map<ll, ll> m;

    NREP() {
        cin >> x[i];
        m[x[i]]++;
        sorted[i] = x[i];
    }
    sort(ALL(sorted));

    NREP() {
        auto it = lower_bound(ALL(sorted), x[i]);
        ll pos = distance(sorted.begin(), it) + 1;
        if (pos <= n / 2) {
            MSG(sorted[(n / 2)])
        } else {
            MSG(sorted[(n / 2) - 1])
        }
    }
}


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

int main(){
	uint64_t x;
	cin >> x;
	
	uint64_t ans = x / (5 + 6) * 2;
	uint64_t mod = x % (5 + 6);
	if(1 <= mod && mod <= 6){
		ans += 1;
	}
	else if (6 < mod){
		ans += 2;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256