akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] p = new int[N];
        for(int n=0;n<N;n++) p[n]=sc.nextInt()-1; //to 0-indexed
        
        int ans = 0;
        int t=0;
        //the best plan: if the i-th element is i, swap it with the next one. otherwise do nothing.
        for(int n=0;n<N-1;n++){
        	if(p[n]==n){
        	    t=p[n];
        	    p[n]=p[n+1];
        	    p[n+1]=t;
        	    ans++;
        	}
        }
        //the final elements does not have the next one...
        if(p[N-1]==N-1)ans++;
        System.out.println(ans);
    }
}

Measured memory_bytes: 50708
S = input()

date  = ['MON', 'TUE', 'WED', 'THU', 'FRI','SAT','SUN']

if S == date[5]:
    print('1')
elif S == date[4]:
    print('2')
elif S == date[3]:
    print('3')
elif S == date[2]:
    print('4')
elif S == date[1]:
    print('5')
elif S == date[0]:
    print('6')
elif S == date[6]:
    print('7')



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

int main(){
  int n,l;
  cin>>n>>l;
  int result = 0;
  for(int i=0;i<n;++i){
    result += (l+i);
  }
  int low = l;
  int high = l+n-1;
  if(low > 0){
    cout<<result-low<<endl;
  }else if( high < 0 ){
    cout<<result-high<<endl;
  } else {
    cout<<result<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int a, b;
	cin >> a >> b;
	
	cout << max(a + b, max(a - b, a * b)) << endl;
	
	return 0;
}


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

// using namespace std;
using std::sort;
using std::lower_bound;
using std::unique;
using std::vector;
using std::set;

typedef long long ll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)

int n;
ll k;
ll a[252521];
ll tmp[252521];

ll solve(int l,int r){
  if(r-l==1){
    return 0ll;
  }
  int mid = (l+r)/2;
  ll ret = solve(l,mid) + solve(mid,r);
  int hl = l, hr = mid;
  FOR(i,l,r){
    if(hl<mid && (hr==r || a[hl]<=a[hr])){
      tmp[i] = a[hl++];
    }else{
      ret += hl-l;
      tmp[i] = a[hr++];
    }
  }
  FOR(i,l,r)a[i]=tmp[i];
  return ret;
}

int main(){
  scanf("%d%lld",&n,&k);
  REP(i,n){
    scanf("%lld",a+i+1);
    a[i+1] += a[i] - k;
  }
  n++;
  ll ans = solve(0,n);
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3328
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
#define IO ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL), cerr.tie(NULL);
typedef long long ll;
typedef long double ld;
 
 
 
ll MOD=1e9 + 7;
ll OO=1e9 + 7;
const int N=1e5 + 10,M = 2750131 + 1;
int arr[N];
int vis[N];

int n,m,k,T,lvl,comp;
int a,b,c;

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


bool Solve(){
	
	for(int i=0;i<N;++i){
		bool flage = false;
		for(int j=0;j<n && arr[j]<=i;++j)
			flage |= !vis[i-arr[j]];
			
		vis[i] = flage;
	}
	
	return vis[k];
}



int main(){
	
	//freopen("algoritm.in","r",stdin);
//	freopen("algoritm.out","w",stdout);
	IO
	cin>>n>>k;
	for(int i=0;i<n;++i)
		cin>>arr[i];
	sort(arr,arr+n);
	
	cout<<(Solve() ? "First" : "Second")<<endl;
	
	return 0;
}

Measured memory_bytes: 4036
S = str(input())

FF = S[:2]
SS = S[2:]

if(int(FF)<13 and int(FF) >0):
    if(int(SS)<13 and int(SS) > 0):
        print("AMBIGUOUS")
        
    else:
        print("MMYY")
        
elif(int(SS)<13 and int(SS)>0):
    print("YYMM")
    
else:
    print("NA")
    

Measured memory_bytes: 3060
S = input()
T = input()

i = 0
j = 0
ss = list()
tt = list()
slist = list()
tlist = list()

if len(S) == len(T):
   for s in S:
      if s in slist:
         ss.append(slist.index(s))
      else:
         ss.append(i)
         slist.append(s)
         i += 1

   for t in T:
      if t in tlist:
         tt.append(tlist.index(t))
      else:
         tt.append(j)
         tlist.append(t)
         j += 1

   if ss == tt:
      print("Yes")
   else:
      print("No")
else:
   print("No")
      
      
         


Measured memory_bytes: 6832
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		for(int i=0;i<Math.max(a, b);i++) {
			System.out.print(Math.min(a, b));
		}
		System.out.println();

	}
}

Measured memory_bytes: 22740
// Crt. 2020-01-12  20:14:32
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

struct vec {
  double x, y;
  vec (const double& x0 = 0, const double& y0 = 0) : x(x0), y(y0) {}
  vec operator + (const vec& t) const {return vec(x+t.x, y+t.y);}
  vec operator - (const vec& t) const {return vec(x-t.x, y-t.y);}
  vec operator * (const double& t) const {return vec(x*t, y*t);}
  vec operator / (const double& t) const {return vec(x/t, y/t);}
  const double len2 () const {return x*x + y*y;}
  const double len () const {return sqrt(len2());}
  vec norm() const {return *this/len();}
  vec rotate_90_c () {return vec(y, -x);}
};

double dot(const vec& a, const vec& b) {return a.x*b.x + a.y*b.y;}
double crs(const vec& a, const vec& b) {return a.x*b.y - a.y*b.x;}

vec lin_lin_int(const vec& p0, const vec& v0, const vec& p1, const vec& v1) {
  double t = crs(p1-p0, v1) / crs(v0, v1);
  return p0 + v0 * t;
}

vec circle(const vec& a, const vec& b, const vec& c) {
  return lin_lin_int((a+b)/2, (b-a).rotate_90_c(), (a+c)/2, (c-a).rotate_90_c());
}

int n;
vec pot[100005];

int main() {
  scanf("%d", &n);
  for(int i=1; i<=n; i++) scanf("%lf%lf", &pot[i].x, &pot[i].y);
  random_shuffle(pot+1, pot+n+1);
  vec o;
  double r2 = 0;
  for(int i=1; i<=n; i++) {
      if((pot[i]-o).len2() > r2) {
          o = pot[i], r2 = 0;
          for(int j=1; j<i; j++) {
              if((pot[j]-o).len2() > r2) {
                  o = (pot[i]+pot[j])/2, r2 = (pot[j]-o).len2();
                  for(int k=1; k<j; k++) {
                      if((pot[k]-o).len2() > r2) {
                          o = circle(pot[i], pot[j], pot[k]), r2 = (pot[k]-o).len2();
                        }
                    }
                }
            }
        }
    }
  printf("%.10lf\n", sqrt(r2));
  return 0;
}



Measured memory_bytes: 1792
def readinput():
    h,w=list(map(int,input().split()))
    n=int(input())
    a=list(map(int,input().split()))
    return h,w,n,a

def main(h,w,n,a):
    cmat=[]
    for _ in range(h):
        cmat.append([0]*w)
    i=0
    j=0
    jstep=1
    for c in range(n):
        k=a[c]
        while k>0: 
            cmat[i][j]=c+1
            if (j==0 and jstep==-1) or (j==w-1 and jstep==1):
                i=i+1
                jstep=jstep*(-1)
            else:
                j=j+jstep
            k-=1
    return cmat

if __name__=='__main__':
    h,w,n,a=readinput()
    ans=main(h,w,n,a)
    for i in range(h):
        print(' '.join(map(str,ans[i])))

            

Measured memory_bytes: 9336
# -*- coding:utf-8 -*-

s = input()


count = 0
max = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "G" or s[i] == "T" or s[i] == "C":
        count += 1
        if (i == len(s)-1) and (max < count):
          max = count
    else:
        if max < count:
            max = count
        count = 0
print(max)

Measured memory_bytes: 3060
import java.util.HashSet;
import java.util.Scanner;

public class Main {

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

        int num = Integer.parseInt(line);
        String[] elementStr = sc.nextLine().split(" ");

        HashSet<Integer>elem = new HashSet<Integer>();
      for(int i = 0; i < num ;i++) {
    	elem.add(Integer.parseInt(elementStr[i]));
    }



        if(elem.size() == elementStr.length) {
        	System.out.println("YES");
        }else {
        	System.out.println("NO");
        }

	}

}


Measured memory_bytes: 65712
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
using namespace std;

void se(vector<vector<int>> &v, vector<int> &u, int key, int num){
    for(int i=0; i<v[key].size(); ++i){
        if(u[v[key][i]]<0){
            u[v[key][i]]=num;
            se(v, u, v[key][i], num);
        }
    }
}


int con(vector<vector<int>> &v, vector<int> &u){
    int now=0;
    for(int i=1; i<=v.size(); ++i){
        if(u[i]<0){
            u[i]=now;
            se(v, u, i, now);
            ++now;
        }
    }
    return now;
}

int main() {
	int N, K, L; cin >> N >> K >> L;
	vector<vector<int>> rd(N+1), rw(N+1);
	for(int i=0; i<K+L; ++i){
	    int p, q; cin >> p >> q;
	    if(i<K){
	        rd[p].push_back(q);
	        rd[q].push_back(p);
	    }
	    else{
	        rw[p].push_back(q);
	        rw[q].push_back(p);
	    }
	}
	vector<int> A(N+1, -1), B(N+1, -1);
	int x=con(rd, A), y=con(rw, B);
	map<pair<int, int>, int> mp;
	for(int i=1; i<=N; ++i) ++mp[make_pair(A[i], B[i])];
	for(int i=1; i<=N; ++i) cout << mp[make_pair(A[i], B[i])] << (i<N ? " " : "");
	cout << endl;
	return 0;
}


Measured memory_bytes: 27776
#include<iostream>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, s, a) for (int i = s; i < a; i++)
#define llint long long int
using namespace std;

const int N_MAX = 505;
const llint INF = 999999999999999;

int main()
{
    llint n;
    cin >> n;

    stack<int> ans;
    if (n == 0) ans.push(0);
    else {
        while (n != 0) {
            int r = n % -2;
            n /= -2;

            if (r == -1) {
                r = 1;
                n++;
            }
            ans.push(r);
        }
    }
    
    while (!ans.empty()) {
        cout << ans.top();
        ans.pop();
    }
    cout << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    string s,t; cin>>s>>t;
    int num=s.size()-t.size()+1;
    //候補の数
    if(num<=0){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    bool oks =false;
    int cnt;
    for(int i=num-1;0<=i;i--){
        cnt=0;
        for(int j=t.size()-1;0<=j;j--){
            if(s[j+i]=='?'||s[j+i]==t[j])cnt++;
        }
        if(cnt==t.size()){
            oks=true;
            for(int j=t.size()-1;0<=j;j--){
                s[j+i]=t[j];
            }
            break;
        }
    }
    if(!oks){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    rep(i,s.size()){
        if(s[i]=='?')s[i]='a';
        cout<<s[i];
    }
    cout<<endl;

}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] h = new int[n+1];
        h[1] = 0;
        for(int i = 1; i < n+1; i++){
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n+1];
        /**
         * dp的核心是类似于数学归纳法
         * 数学方面的东西想清楚是关键
         * 在第n步和之前的步数的关系向好最关键
         *
         * 这个青蛙问题，其实就是你跳到第i个坑的时候，
         * 只和前面的第i-1个坑或者第i-2个坑有关
         * 所以你调到第i个坑的时候，只要求到
         * min（第[i-1]个坑到i个坑， 第【i-2】个坑到第i）个坑哪个消耗大就行了
         */
        for(int i = 2; i < n+1; i++){
            if(i-2>=1){
                dp[i] = Math.min(dp[i-1]+Math.abs(h[i-1]-h[i]), dp[i-2]+Math.abs(h[i-2]-h[i]));
            }else { //i-2比1小的时候是没有i-2这个坑的
                dp[i] = dp[i-1]+ Math.abs(h[i-1]-h[i]);
            }
        }

        System.out.println(dp[n]);
    }
}


Measured memory_bytes: 49092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = Input.NextInt();
            var list = Input.LongList().OrderBy(x => x).ToList();

            if (N % 2 == 0 && list.Where((x, i) => i % 2 == 0 ? i + 1 == x : i == x).Count() == N) {
                Console.WriteLine(Enumerable.Repeat(2, N / 2).Aggregate(1L, (prev, now) => (prev * now) % 1000000007));
            } else if (N % 2 != 0 && list.Where((x, i) => i % 2 == 0 ? i == x : i + 1 == x).Count() == N) {
                Console.WriteLine(Enumerable.Repeat(2, N / 2).Aggregate(1L, (prev, now) => (prev * now) % 1000000007));
            } else {
                Console.WriteLine(0);
            }
        }
    }

    class Input {
        static IEnumerator<string> enumerator;

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            if (enumerator == null || !enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
                enumerator.MoveNext();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            if (enumerator == null || !enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
                enumerator.MoveNext();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 24544
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
#include <bitset>

#define ll long long
const ll MOD = 1e9 + 7;

// 隣接リストで使う辺を表す型
struct BellmanfordEdge
{
    ll to;
    ll cost;
    BellmanfordEdge(ll to, ll cost) :to(to), cost(cost) {}
};

// 戻り値が空配列なら負の閉路を含む
std::vector<ll> Bellmanford(ll s, std::vector<std::vector<BellmanfordEdge>>& connection)
{
    // 2 <= N <= 1000, -10^9 <= cost
    const ll INF = 1000000000001;
    auto n = connection.size();
    auto dist = std::vector<ll>(n, -INF);

    dist[s] = 0;

    std::vector<bool> containsCircuit(n, false);
    for (auto i=0; i<n; i++)
    {
        for (auto v=0; v<n; v++)
        {
            if (dist[v] == -INF)
                continue;

            for (auto k = 0; k < connection[v].size(); k++)
            {
                auto edge = connection[v][k];
                if (dist[edge.to] < dist[v] + edge.cost)
                {
                    dist[edge.to] = dist[v] + edge.cost;

                    // Bellmanford ではグラフの走査回数ごとに始点からN次の点までの最小距離しか考慮できない.
                    // 故に N - 1 回更新すれば各点への最小距離が求まる.
                    // それでも最小距離更新の余地があるなら負の閉路が存在する
                    if (i == n - 1)
                        containsCircuit[v] = true;
                }
            }
        }
    }

    // 閉路がゴール(n番目の頂点)までの経路にあるか
    for (auto v=0; v<n; v++)
    {
        if (!containsCircuit[v])
            continue;

        for (auto k = 0; k < connection[v].size(); k++)
        {
            if (containsCircuit[v])
                containsCircuit[connection[v][k].to] = true;
        }
    }

    return containsCircuit[n - 1] ? std::vector<ll>() : dist;
}

int main()
{
    ll N, M;
    std::cin >> N >> M;
    std::vector<std::vector<BellmanfordEdge>> connection(N, std::vector<BellmanfordEdge>());

    for (auto i=0; i<M; ++i)
    {
        ll from, to, cost;
        std::cin >> from >> to >> cost;
        from--;
        to--;
        connection[from].emplace_back(BellmanfordEdge(to, cost));
    }

    auto result = Bellmanford(0, connection);
    if (result.empty())
        std::cout << "inf" << std::endl;
    else
        std::cout << result[N-1] << std::endl;
}


Measured memory_bytes: 3680
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))

    # cnt[k] = v ... 深さkのノード数
    cnt = {}
    max_depth = 0
    for d in D:
        max_depth = max(max_depth, d)
        if d not in cnt:
            cnt[d] = 1
        else:
            cnt[d] += 1

    # 頂点1との距離が0になるノードは1つしか存在しない
    if D[0] != 0:
        print(0)
        exit(0)
    elif cnt[0] > 1:
        print(0)
        exit(0)

    ans = 1
    MOD = 998244353
    for i in range(0, max_depth):
        if (i not in cnt) or (i + 1 not in cnt):
            ans = 0
            break
        ans *= cnt[i] ** cnt[i + 1]
        ans %= MOD

    print(ans)


Measured memory_bytes: 68456
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    vector<bool>stt(n,true);
    vector<set<int>>list(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
        a[i]--;
        list[a[i]].insert(i);
    }
    int cnt=0;
    for(int i=0; i<n; i++){
        for(auto v : list[i]){
            if(a[i]==v&&stt[v]){
                stt[i] = false;
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 12940
#include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
int main(void){
    for(int h, m, s; cin >> h >> m >> s, h != -1;){
        h = 2 - h, m = -m, s = -s;
        if(s < 0) m--, s += 60;
        if(m < 0) h--, m += 60;
        printf("%02d:%02d:%02d\n", h, m, s);

        h *= 3, m *= 3, s *= 3;
        if(s > 60) m += (s / 60), s %= 60;
        if(m > 60) h += (m / 60), m %= 60;
        printf("%02d:%02d:%02d\n", h, m, s);
    }

    return 0;
}

Measured memory_bytes: 1144
#include<stdio.h>
int main(){
	int h1,h2,m1,m2,k;
	int a,b,c,d;
	
	scanf("%d %d %d %d %d", &h1,&m1,&h2,&m2,&k);
	
	a = (h1*60) +m1;
	b=(h2*60) +m2;
	c = b-a;
	d = c- k;  
	
	printf("%d\n", d);
	return 0;
}

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

int main(){
        int n;
        cin >> n;
        vector<int> a(n);
        for(auto &i : a) cin >> i;
        map<int,int> m;
        for(int i = 0; i < n; i++) {
                m[i+1-a[i]]++;
        }

        // for (auto const& pair: m) {
        //         std::cout << "{" << pair.first << ": " << pair.second << "}\n";
        // }
        long long int count = 0;
        for(int i = 0; i < n; i++) {
                m[i+1-a[i]]--;
                count += m[a[i]+i+1];
        }
        cout << count << endl;
}


Measured memory_bytes: 20764
#include<iostream>
    #include<cstdio>
    #include<math.h>
    #include<string>
    #include<algorithm>
    #include<functional>
    #include<vector>
    #include<set>
    #include<map>
    #define INF 999999
    #define EPS 1.0e-6
     
    using namespace std;
     
    typedef long long ll;
    typedef pair<int, int> P;
    typedef pair<int, P> PP;
     
    string s;
    int alp[30];
     
    int main()
    {
    	cin >> s;
    	int len = s.length();
    	int xnum = 0;
     
    	string r = "";
    	string l = "";
    	vector<int> index;
    	for (int i = 0; i < len; i++) {
    		if (s[i] != 'x') {
    			l += s[i];
    			index.push_back(i);
    		}
    		else xnum++;
    	}
     
    	for (int i = len - 1; i >= 0; i--) {
    		if (s[i] != 'x')r += s[i];
    	}
    	//cout << r << endl;
    	//cout << l << endl;
     
     
    	int is = (int)index.size();
    	int middle;
     
     
    	if (is == 0) {
    		cout << 0 << endl;
    		return 0;
    	}
    	
    	if (is == 1) {
    		int lx = 0;
    		for (int i = 0; i < len; i++) {
    			if (s[i] != 'x')break;
    			if (s[i] == 'x')lx++;
    		}
    		cout << xnum - 2 * min(lx,xnum-lx);
    		return 0;
    	}
    	
     
    	int k, t;
    	if (is % 2 == 0) {
    		middle = is / 2 - 1;
    		k = index[middle] - 1;
    		t = index[middle+1] + 1;
    		xnum -= t - k - 3;
    	}
    	else {
    		middle = is / 2;
    		k = index[middle] - 1;
    		t = index[middle] + 1;
    		//xnum -= t - k - 2;
    	}
     
    	//cout << k << " " << t << endl;
     
    	ll ans = 0;
    	if (r == l) {
    		while (k >= 0 && t <= len - 1) {
    			if (s[k] != s[t]) {
    				if (s[k] == 'x') {
    					ans++;
    					k--;
    					xnum--;
    				}
    				else {
    					ans++;
    					t++;
    					xnum--;
    				}
    			}
    			else {
    				if (s[k] == 'x')xnum -= 2;
    				k--; t++;
    				
    			}
    		}
    		//cout << xnum << endl;
    		cout << ans+xnum << endl;
    	}
    	else cout << -1 << endl;
    	return 0;
    }

Measured memory_bytes: 1148
import sys
from collections import defaultdict

import numpy as np


def prepare(n, MOD):
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


n = int(sys.stdin.buffer.readline())
mp = map(int, sys.stdin.buffer.read().split())
ab = list(zip(mp, mp))
atob = defaultdict(list)
max_a, max_b = 0, 0
for a, b in ab:
    atob[a].append(b)
    max_a = max(max_a, a)
    max_b = max(max_b, b)

MOD = 10 ** 9 + 7

dp = np.zeros(max_b * 2 + 1, dtype=np.int64)
ans = 0
for i in range(-max_a, max_a + 1):
    if i < 0 and -i in atob:
        for j in atob[-i]:
            dp[-j + max_b] += 1
    dp = np.add.accumulate(dp) % MOD
    if i > 0 and i in atob:
        for j in atob[i]:
            ans = (ans + dp[j + max_b]) % MOD

facts, invs = prepare(2 * (max_a + max_b), MOD)
ans = int(ans)
for a, b in ab:
    ans = (ans - facts[2 * (a + b)] * invs[2 * a] * invs[2 * b]) % MOD

print(ans * invs[2] % MOD)


Measured memory_bytes: 58500
from statistics import mean, median,variance,stdev
import sys
import math
import fractions
def j(a):
    if a: print("AC")
    else :print("WA")


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#x = ip()                              #入力整数1つ
x,y = (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

max = 1
ls = int(math.sqrt(y))+1
s = []
if y==1 or x>=y:print(1)
elif x==1:print(y)
else:
    n = y
    for i in range(2,ls):
        if n==1:break
        l=0
        while n%i == 0:
             n = n//i
             l+=1
        s.append([i,l])
    for i in range(len(s)):
        s[i][1]//=x
    num = 1
    for i in range(len(s)):
        if s[i][1]: num*=(pow(s[i][0],s[i][1]))
    print(num)


Measured memory_bytes: 118056
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
ll N, W;
llvec v, w;
ll dp[101][100100];
ll visited[101][100100];

ll dpf(ll n, ll value){
  if(visited[n][value]==1){
    return dp[n][value];
  }else{
    visited[n][value]=1;
    if(n==0){
      if(value==v[n])dp[n][value]=w[n];
      else if(value==0)dp[n][value]=0;
      else dp[n][value]=1e12;
    }else{
      if(value-v[n]>=0)dp[n][value]=min(dpf(n-1, value), dpf(n-1, value-v[n]) + w[n]);
      else{dp[n][value] = dpf(n-1, value);
      }
    }
    return dp[n][value];
  }
  
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> N >> W;
  v = llvec(N);
  w = llvec(N);
  
  rep(i, N){
    cin >> w[i] >> v[i];
  }

  ll ans = 0;
  rep(i, 100100){
    if(dpf(N-1, i)<=W){
      ans = i;
    }
    //cout << dpf(N-1, i) << " " << i << endl;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 157952
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    string s;
    cin >> s;

    int64_t n = s.size();
    vector<int64_t> ans(n);

    int64_t last_r = 0;
    for (auto i : irange(0L, n)) {
        auto c = s[i];

        if (c == 'R') {
            last_r = i;
        } else {
            if ((i - last_r) % 2 == 0) {
                ++ans[last_r];
            } else {
                ++ans[last_r + 1];
            }
        }
    }

    int64_t last_l = n - 1;
    for (auto i : irange(n - 1, -1L, -1L)) {
        auto c = s[i];

        if (c == 'L') {
            last_l = i;
        } else {
            if ((last_l - i) % 2 == 0) {
                ++ans[last_l];
            } else {
                ++ans[last_l - 1];
            }
        }
    }

    const auto* delim = "";
    for (auto a : ans) {
        cout << delim << a;
        delim = " ";
    }
    cout << "\n";
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()



ll factorial(ll x, ll n){
  
  if (n==0){
    return 1;
  }
  
  else if (n==1){
    return x%MOD;
  }
  else if (n%2==0){
    return (factorial(x,n/2)*factorial(x,n/2))%MOD;
  }
  
  else {
    return (((factorial(x,(n-1)/2)*factorial(x,(n-1)/2))%MOD)*x)%MOD;
  }

}
  



int main(){
  

  ll n;
  cin>>n;
  vector<ll> data(n);
  rep(i,n){
    ll tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  ll sum=0;
  rep(i,n){
    sum+=data.at(i);
  }
  
  vector<ll> answer(n);
  
  ll tmp=0;
  for (int i=1;i<=n-2;i+=2){
    tmp+=2*data.at(i);
  }
  answer.at(0)=sum-tmp;
  
  for (int i=1;i<n;i++){
    answer.at(i)=2*data.at(i-1)-answer.at(i-1);
  }
  
  rep(i,n-1){
    cout<<answer.at(i)<<" ";
  }
  cout<<answer.at(n-1)<<endl;
  
    
  


}












Measured memory_bytes: 2944
# -*- coding:utf-8 -*-
import sys


class Node(object):
    __slots__ = ["value", "left", "right"]

    def __init__(self, value, left=None, right=None):
        self.value = value
        self.left = left
        self.right = right


class BinTree(object):
    def __init__(self):
        self._tree = None

    def insert(self, value):
        parent = None
        current = self._tree

        while current is not None:
            parent = current
            if value < current.value:
                current = current.left
            else:
                current = current.right

        if parent is None:
            self._tree = Node(value)
        elif value < parent.value:
            parent.left = Node(value)
        else:
            parent.right = Node(value)

    def preoder_walk(self):
        def preoder(node):
            result = []
            if node is None:
                pass
            else:
                result.append(node.value)
                result.extend(preoder(node.left))
                result.extend(preoder(node.right))
            return result

        return preoder(self._tree)

    def inorder_walk(self):
        def inorder(node):
            result = []
            if node is None:
                pass
            else:
                result.extend(inorder(node.left))
                result.append(node.value)
                result.extend(inorder(node.right))
            return result

        return inorder(self._tree)


def print_tree(tree):
    print(" " + " ".join([str(val) for val in tree.inorder_walk()]))
    print(" " + " ".join([str(val) for val in tree.preoder_walk()]))


def insert_main(commands):
    tree = BinTree()
    for com in commands:
        if com[0] == "insert":
            tree.insert(int(com[1]))
        elif com[0] == "print":
            print_tree(tree)
        else:
            raise ValueError


if __name__ == "__main__":
    n = int(input())
    commands = [com.split() for com in sys.stdin.readlines()]
    insert_main(commands)

Measured memory_bytes: 230040
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 2000000000
#define MAXN 55

int GLL(LL& x) {
  return scanf("%lld", &x);
}

int GI(int& x) {
  return scanf("%d", &x);
}

int n, p, a[MAXN];
int c1, c0;
LL pascal[MAXN][MAXN];
void build_pascal() {
  for (int n = 2; n < MAXN; n++) {
    FOR1(k, n) {
      pascal[n][k] = pascal[n-1][k-1] + pascal[n-1][k];
    }
  }
}


int main() {

  memset(pascal, 0, sizeof pascal);
  FORN(i, MAXN) {
    FORN(j, i + 1) pascal[i][j] = 1;
  }
  build_pascal();

  GI(n);
  GI(p);
  c1 = 0;
  c0 = 0;

  FORN(i, n) {
    int tmp;
    GI(tmp);
    c1 += tmp&1;
    c0 += (tmp&1) == 0;
  }

//  if (c1 == 0 && c0 > 0 && p == 0) {
//    printf("here\n");
//    printf("%lld\n", powmod(2, c0));
//    return 0;
//  }

//  printf("c1: %d, c0: %d\n", c1, c0);

  LL ans = 0;
  if (p == 1) {
    for (int tot = 0; tot < n+1; tot++) {
      for (int i0 = 0; i0 < min(c0+1, tot) + 1; i0++) {
        int i1 = tot - i0;
        if (i1 + i0 == 0) continue;
        if (i1 > c1) continue;
        if ((i1&1) == 0) continue;

        ans += pascal[c0][i0] * pascal[c1][i1];
//        printf("0: %d, 1: %d, ans %lld\n", i0, i1, ans);
      }
    }
  }
  else {
    
    for (int tot = 0; tot < n+1; tot++) {
      for (int i0 = 0; i0 < min(c0+1, tot) + 1; i0++) {
        int i1 = tot - i0;
//        printf("       %d (%d)\n", i1, c1);
        if (i1 > c1) continue;
        if (i1&1) continue;

//        printf("   %d c %d, %d c %d\n", c0, i0, c1, i1);
        ans += pascal[c0][i0] * pascal[c1][i1];
//        printf("0: %3d, 1: %3d, ans %lld\n", i0, i1, ans);
      }
    }
  }

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

  
  return 0;
}


Measured memory_bytes: 256
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

# extended gcd and modinv
# x = y*(x/y) + x%y
#   ->  g = ax+by = a(y*(x/y) + x%y) + by
#         = (a*(x/y) + b)*y + a*(x%y)
#
# while  g=ax+by, b==0  ->  g=x, a=1

def exgcd(x,y):
    if y == 0:
        return (x,1,0)
    else:
        g,b,a = exgcd(y, x%y)
        return (g, a, b-(x//y)*a)

# return y s.t. x*y mod p == 1
def modinv(x,p):
    return pow(x,p-2,p)


def modinv2(x,p):
    g,a,b = exgcd(x,p)  # ax+bp = g, g=1 if mutually prime
    return a%p


R = 1000003
facts = [1] * R
for i in range(2,R):
    facts[i] = (facts[i-1]*i)%R

qq = inn()
for q in range(qq):
    x,d,n = inm()
    if d==0:
        print(pow(x,n,R))
        continue
    xd = modinv(d,R)
    y = (x * xd) % R
    if y+n-1 >= R:
        print(0)
    else:
        z = pow(d,n,R) * facts[y+n-1] * modinv(facts[y-1],R)
        print(z%R)


Measured memory_bytes: 75484
input = int(input())

input_list = list(range(1, input + 1))

count_list = []

for e in input_list:
    count = 0
    e_tmp = e
    while True:
        if e_tmp % 2 == 0:
            e_tmp = e_tmp/2
            count += 1
        else:
            break
    count_list.append([e, count])

max_value = 0
max_key = 0

for i in range(input):    
    curr_value = int(count_list[i][1])
    if curr_value >= max_value:
        max_value = curr_value
        max_key = count_list[i][0]
    
print(max_key)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<vector>
#include<math.h>
#include<algorithm>
#include<string>
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> >
#define vb vector<bool> 
#define vvb vector<vector<bool> >
#define INF 1145141919810
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b:i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
using namespace std;

int main(){
	string a,b,c; cin>>a>>b;
	if(a.size()>b.size()){
		cout<<"GREATER"<<endl;
		exit(0);
	}
	else if(b.size()>a.size()){
		cout<<"LESS"<<endl;
		exit(0);
	}
	else{
		rep(i,a.size()){
			if(a[i]>b[i]){
				cout<<"GREATER"<<endl;
				exit(0);
			}else if(b[i]>a[i]){
				cout<<"LESS"<<endl;
				exit(0);
			}
		}
	}cout<<"EQUAL"<<endl;
	return 0;
}

Measured memory_bytes: 256
n,x = map(int, input().split())
l = list(map(int, input().split()))
a = [0]
for i in range(n):
    a.append(l[i] + a[i])
for i in range(n+1):
    if(a[i] > x):
        ans = i
        break
    ans = n+1
print(ans)

Measured memory_bytes: 3060
import java.util.*;
public class Main{
	public static void main(String[] args){
		long ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		long[] a = new long[m];
		for(int i=0; i<m; i++){
			a[i] = sc.nextLong();
		}
		
		quick_sort(a, 0, m-1);
		
		long[] difs = new long[m-1];
		for(int i=1; i<m; i++){
			difs[i-1] = a[i] - a[i-1];
		}
		
		quick_sort(difs, 0, m-2);
		for(int i=0; i<m-n; i++){
			ans += difs[i];
		}
		
		System.out.println(ans);
	}
	
	static void quick_sort(long[] d, int left, int right) {
		if(left>=right){
				return;
		}
		long p = d[(left+right)/2];
		int l = left, r = right;
		long tmp;
		while(l<=r){
			while(d[l] < p){ l++; }
			while(d[r] > p){ r--; }
			if (l<=r) {
				tmp = d[l]; d[l] = d[r]; d[r] = tmp;
				l++;
				r--;
			}
		}
		quick_sort(d, left, r);
		quick_sort(d, l, right);
	}
}

Measured memory_bytes: 58336
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeginnerContest053
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();                                                   

            Console.WriteLine(int.Parse(input) < 1200 ? "ABC" : "ARC");

        }
    }
}


Measured memory_bytes: 2648
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint A, B; cin >> A >> B;
    range(i, 1, 100000) {
        if (i * 8 / 100 == A and i / 10 == B) {
            cout << i << "\n";
            return 0;
        }
    }
    cout << -1 << "\n";
}

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;
using P = pair<int, int>;

int main() {
    ll N;
    cin >> N;
    string ans = "";

    while(N-1 >= 26){
        ll a = (N-1) % 26;
        N = (N-1) / 26;
        string str(1, 'a' + a);
        ans = str + ans;
    }
    string s(1, 'a' + (N - 1));
    ans = s + ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
s=input()
u=len(s)
a=s[0]
b=s[1]
if(u==2 or a==b):
	print("1 2" if a==b else "-1 -1")
	exit(0)
for i in range(2,u):
	c = s[i]
	if a==c:
		print("{} {}".format(i-1,i+1))
		exit(0)
	if b==c:
		print("{} {}".format(i,i+1))
		exit(0)
	a=b
	b=c
print("-1 -1")

Measured memory_bytes: 3188
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define times(n) for(int i=0;i<n;i++)
int main(){
    int n,m,j;
    scanf("%d%d",&n,&m);
    vector<vector<int> > s(n+1);
    int p[m],y[m];
    times(m)scanf("%d%d",&p[i],&y[i]),s[p[i]].push_back(y[i]);
    times(n)sort(s[i+1].begin(),s[i+1].end());
    times(m)j=lower_bound(s[p[i]].begin(),s[p[i]].end(),y[i])-s[p[i]].begin()+1,printf("%06d%06d\n",p[i],j);
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void insertion(ll a[], ll n){
    for (ll i = 0; i < n;i++){
        ll v = a[i];
        ll j = i - 1;
        while(j>=0&&a[j]>v){
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for (ll i = 0;i<n-1;i++){
            cout << a[i] << " ";
        }
        cout << a[n - 1] << endl;
    }
}
int main() {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) cin >> a[i];
    insertion(a, n);
}



Measured memory_bytes: 3092
#include<iostream> 
using namespace std; 
  
// A function to check if n is palindrome 
int isPalindrome(int n) 
{ 
    // Find reverse of n 
    int rev = 0; 
    for (int i = n; i > 0; i /= 10) 
        rev = rev*10 + i%10; 
  
    // If n and rev are same, then n is palindrome 
    return (n==rev); 
} 
  
// prints palindrome between min and max 
void countPal(int min, int max) 
{ int count=0;
    for (int i = min; i <= max; i++) 
        if (isPalindrome(i)) 
          count++; 
          cout<<count;
} 
  
// Driver program to test above function 
int main() 
{ int a,b;
cin>>a>>b;
    countPal(a, b); 
    return 0; 
} 

Measured memory_bytes: 3604
#include <stdio.h>


int main(int argc, char **argv)
{
  int n,i,a,b,x,xx,suma,sumb,dig;
  x = 100000;
  suma = 0;
  sumb = 0;
  scanf("%d",&n);
  for(i = 0 ; i < n / 2 ; i++){
    a = i + 1;
    b = n - a;
    while(a > 0){
      dig = a % 10;
      suma = suma + dig;
      a = a / 10;
    }
    dig = 0;
    while(b > 0){
      dig = b % 10;
      sumb = sumb + dig;
      b = b / 10;
    }
    dig = 0;
    xx = suma + sumb;
    if(x > xx){
      x = xx;
    }
    suma = 0;
    sumb = 0;
  }
  printf("%d\n",x);

  return 0;
}


Measured memory_bytes: 128
using System;

class Program {
    static void Main (string[] args) {
        var inp = Console.ReadLine().Split(' ');
        long hp = long.Parse(inp[0]);
        double count = 1;
        double count2 = 0;

        while(true) {
            if(hp <= 1) {
                count2++;
                break;
            } else {
                hp /= 2;
            }

            count2 += Math.Pow(2,count);
            count++;
        }

        Console.WriteLine(count2);
    }
}

Measured memory_bytes: 13140
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

map<ll, ll> opp_tbl;

vector<PI> inv(const vector<PI> &v) {
  vector<PI> opp(v.size());
  REP(i, 0, v.size()) {
    opp[i] = PI(v[i].first, 3 - v[i].second);
  }
  return opp;
}

VI primes;
void primes_init(void) {
  int s = 3001;
  VI tbl(s, 1);
  tbl[0] = tbl[1] = 0;
  REP(i, 2, s) {
    REP(j, 2, (s + i - 1) / i) {
      tbl[i * j] = 0;
    }
  }
  REP(i, 2, s) {
    if (tbl[i]) {
      primes.push_back(i);
    }
  }
}

/*
 * n |-> (r, (...)^3/r)
 * n / r = (...)^3
 * if n is not factored into a product of p <= 10^5, or the opposite is not in range, return (-1, ?).
 */
pair<ll, ll> opposite(ll v) {
  int oldv = v;
  ll f_ll = 1, opp_ll = 1;
  int e = 0;
  int ind = 0;
  while ((v >= 2 || e >= 1) && ind < primes.size()) {
    int p = primes[ind];
    if (v % p == 0) {
      v /= p;
      e++;
    } else {
      if (e % 3 != 0) {
	REP(j, 0, e % 3) {
	  f_ll *= p;
	}
	REP(j, 0, 3 - e % 3) {
	  opp_ll *= p;
	  if (opp_ll > 10000000000) {
	    return pair<ll, ll>(-1, -1);
	  }
	}
      }
      e = 0;
      ind++;
    }
  }
  // Is v square?
  ll sq = sqrt(v);
  if (v >= 2 && v == sq * sq) {
    f_ll *= sq * sq;
    opp_ll *= sq;
    if (opp_ll > 10000000000) {
      return pair<ll, ll>(-1, -1);
    }
    v = 1;
  }

  // if v <= 100000 (<= 3000^2) then v is prime and v^2 is in range
  if (v <= 100000) {
    f_ll *= v;
    REP(j, 0, 2) {
      opp_ll *= v;
      if (opp_ll > 10000000000) {
	return pair<ll, ll>(-1, -1);
      }
    }
    v = 1;
  }
  if (v >= 2) {
    return pair<ll, ll>(-1, -1);
  }
  opp_tbl[f_ll] = opp_ll;
  opp_tbl[opp_ll] = f_ll;
  //cerr << "old f opp:" << oldv << " " << f_ll << " " << opp_ll << endl;
  return pair<ll, ll>(f_ll, opp_ll);
}

int main(void){
  int n;
  cin >> n;
  VL s(n);
  REP(i, 0, n) {
    cin >> s[i];
  }
  primes_init();
  int cnt = 0;
  map<ll, int> tbl;
  REP(i, 0, n) {
    pair<ll, ll> norm = opposite(s[i]);
    if (norm.first == -1) {
      cnt++;
    } else {
      if (tbl.count(norm.first) == 0) {
	tbl[norm.first] = 1;
      } else {
	tbl[norm.first]++;
      }
    }
  }
  for (map<ll, int>::iterator it = tbl.begin(); it != tbl.end(); ++it) {
    pair<ll, int> w = *it;
    if (w.first == 1) {
      cnt++;
      continue;
    }
    ll opn = opp_tbl[w.first];
    int opc = tbl.count(opn) ? tbl[opn] : 0;
    cnt += max(w.second, opc);
    it->second = 0;
    tbl[opn] = 0;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 21632
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
// #include <show_vec.hh>


#define DEBUG  if(false)

using namespace std;

using ll = long long;
#define LINE printf("LINE : %d\n", __LINE__);
#define loop(i, n) for(i = 0; i < n; i++)
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

int main(){

  int N; cin >> N;
  ll K; cin >> K;
  vec<int> Next(N, 0), visited(N, 0);
  for(int i = 0; i < N; i++){
    cin >> Next[i];
    Next[i]--;
  }
  int curr  = 0;
  visited[0] = 1;
  int loop_first, loop_end;
  int count = 0;
  while(true){
    int next = Next[curr];
    if(visited[next] == 1){
      loop_first = next;
      loop_end = curr;
      break;
    }else{
      visited[next] = 1;
      curr = next;
      count++;
    }
  }
  int count_ = 0;
  curr = 0;
  for(int i = 0; i < count; i++){

    if(curr == loop_first){
      break;
    }else{
      count_++;
      curr = Next[curr];
    }
  }

  int step = 0;
  if(K <= count){
    step = K;
  }else{
    step = ((K-count_) % (count - count_ + 1)) + count_;
  }
  DEBUG printf("count : %d\n", count);
  DEBUG printf("count_ : %d\n", count_);
  int moved;
  curr = 0;
  DEBUG printf("step : %d\n", step);
  for(int i = 0; i < step; i++){
    curr = Next[curr];
  }
  cout << curr+1 << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    vector<ll> A(n);
    for(auto& x:A)cin >> x;
    ll sum = accumulate(A.begin(),A.end(),0);
    ll cnt = 0;
    for(i=0;i<n;i++){
        if(4*m*A[i]>=sum)cnt++;
    }

    //cout << cnt << endl;
    if(cnt>=m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
double memo[3000][3000],arr[3000],x;
int a;
double solve(int idx,int num){
    if(idx==a && num>=(a+1)/2) {
        return 1;
    }
    if(idx==a)
        return 0;
    double &cur=memo[idx][num];
    if(cur!=-1.0)
        return cur;
    cur=0;
    cur+=(arr[idx]*solve(idx+1,num+1))+((1-arr[idx])*solve(idx+1,num));
    return cur;

}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for(int i=0;i<3000;i++){
        for(int c=0;c<3000;c++)
            memo[i][c]=-1.0;
    }
    cin>>a;
    for(int i=0;i<a;i++)
        cin>>arr[i];
    cout<<fixed<<setprecision(10)<<solve(0,0);
}

Measured memory_bytes: 70784