akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
string p,t;
int n,m;
int ne[1000005];
int bmbc[256];
int bmgs[1000005];
int osuff[1000005];
vector<int>res;
void output(){
	for(int i=0;i<res.size();i++)
		cout<<res[i]<<endl;
}
void bf(){
	n=t.length();
	m=p.length();
	res.clear();
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(p[j]!=t[i+j])break;
			if(j==m-1)res.push_back(i);
		}
	}
	output();
}
void calcnext(){
	ne[0]=-1;
	for(int j=1;j<m;j++){
		int i=ne[j-1];
		while(i>=0&&p[i+1]!=p[j])i=ne[i];
		if(p[i+1]==p[j])ne[j]=i+1;
		else ne[j]=-1;
	}
}
void kmp(){
	n=t.length();
	m=p.length();
	res.clear();
	calcnext();
    int i,j,cnt;i=0;j=0;cnt=0;  
    while(i<=n){  
        if(i==n){if(j==m)res.push_back(i-m);break;}
        if(t[i]==p[j]){i++;j++;}
		else{
			if(j==0)i++;
			else j=ne[j-1]+1;
		}
        if(j>=m){
			res.push_back(i-m);
			j=ne[m-1]+1;
		}
    }  
	output();
}
void calcosuff(){
	int le,ri;
	osuff[m-1]=m;
	le=m-1;
	for(int i=m-2;i>=0;i--){
		if(i>le&&osuff[i+m-1-ri]<i-le)
			osuff[i]=osuff[i+m-1-ri];
		else{
			if(i<le)le=i;
			ri=i;
			while(le>=0&&p[le]==p[le+m-1-ri])le--;
			osuff[i]=ri-le;
		}
	}
//	for(int i=0;i<m;i++)cout<<osuff[i]<<" ";
}
void calcbmbc(){
	for(int i=0;i<256;i++)bmbc[i]=m;
	for(int i=0;i<m-1;i++)bmbc[p[i]]=m-i-1;
}
void calcbmgs(){
	calcosuff();
	for(int i=0;i<m;i++)bmgs[i]=m;
	int j=0;
	for(int i=m-2;i>=0;i--)
		if(osuff[i]==i+1)
			for(;j<=m-1-i;j++)
				if(bmgs[j]==m)bmgs[j]=m-i-1;
	for(int i=0;i<m-1;i++)bmgs[m-osuff[i]-1]=m-i-1;
}
void bm(){
	res.clear();
	n=t.length();
	m=p.length(); 
	calcbmbc();
	calcbmgs();
	for(int l=0;l<=n-m;){
		int k=m-1;
		while(k>=0&&p[k]==t[l+k])k--;
		if(k==-1){
			res.push_back(l);
			l+=bmgs[0];
		}else
			l+=max(bmgs[k],bmbc[t[l+k]]-m+k);
	}
	output();
}
int main(){
	cin>>t>>p;
//	bf();
//	kmp();
	bm();
// anpanman	 gcagagag
	return 0;
}


Measured memory_bytes: 3220
# M submissions
# i-th problem, pi-th problem recieved Si verdict ("AC" or "WA")
# Penalty: recieve WA before AC

N, M = map(int, input().split())

problem_ac = set()
problem_penalty = dict()

for _ in range(M):
    problem, verdict = input().split()

    if problem in problem_ac:
        continue
    elif verdict == "WA":
        problem_penalty[problem] = problem_penalty.get(problem, 0) + 1
    elif verdict == "AC":
        problem_ac.add(problem)

num_ac = len(problem_ac)
num_penalties = sum(penalty for problem, penalty in problem_penalty.items() if problem in problem_ac)
print(num_ac, num_penalties)

Measured memory_bytes: 14056
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tok = new StringTokenizer(br.readLine());
        int h = Integer.parseInt(tok.nextToken());
        int w = Integer.parseInt(tok.nextToken());
        char[][] mat = new char[h][w];
        boolean[] rowVisible = new boolean[h];
        boolean[] colVisible = new boolean[w];
        // 読み込み
        for (int i = 0; i < h; i++) {
            String row = br.readLine();
            for (int j = 0; j < w; j++) {
                char c = row.charAt(j);
                mat[i][j] = c;
                if (c == '#') {
                    rowVisible[i] = true;
                    colVisible[j] = true;
                }
            }
        }
        // 表示
        for (int i = 0; i < h; i++) {
            if (!rowVisible[i]) continue;
            for (int j = 0; j < w; j++) {
                if (!colVisible[j]) continue;
                System.out.print(mat[i][j]);
            }
            System.out.print("\n");
        }
    }
}


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

int n,W;
long long int dp[101][100001];
long long int w[100],v[100];


int main(){
	cin>>n>>W;
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		for(int j=W;j>=0;j--){
			if(j>=w[i-1]){
				dp[i][j] = max(dp[i-1][j-w[i-1]]+v[i-1], dp[i-1][j]);
			}
			else dp[i][j] = dp[i-1][j];
		}
	}
	cout<<dp[n][W]<<endl;
}

Measured memory_bytes: 79104
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

int i, n, a[100], m, p, x, s;

int main()
{
    sf("%d", &n);
    for (i = 0; i < n; i++) {
        sf("%d", &a[i]);
        s += a[i];
    }
    sf("%d", &m);
    while (m--) {
        sf("%d%d", &p, &x);
        pf("%d\n", s-a[p-1]+x);
    }
    return 0;
}

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

int main() {
  char c;
  cin >> c;

  // ここにプログラムを追記
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
} 


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
// エラトステネスの篩O(NloglogN?)
const ll MAX = 100005;
bool isPrime[MAX];
vector<int> prime;
void makePrime(){
  for (ll i = 0; i < MAX; i++) isPrime[i] = true;
  for (ll i = 2; i * i < MAX + 1; i++){
    if(isPrime[i]){
      for (ll j = 2 * i; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  for(int i = 2; i < MAX; i++) if(isPrime[i]) prime.push_back(i);
  return;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;cin>>N;
  makePrime();
  int cnt=0,i=0;
  vector<int> ans;
  while(cnt<N&&i<prime.size()){
    if(prime[i]%5==1){
      ans.push_back(prime[i]);
      cnt++;
    }
    i++;
  }
  FOR(i,0,ans.size()){
    if(i)cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> x(n);

    REP(i, n) cin >> x[i];

    int ans = 0;

    REP(i, n){
        ans += min(abs(0 - x[i]) * 2, abs(k - x[i]) * 2);
    }

    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int cand = 30;
  rep(i,N) {
    int A;
    cin >> A;
    int q = A;
    rep(count, cand) {
      if ( q % 2 != 0 ) {
        cand = count;
        break;
      }
      q = q / 2;
    }
    if ( cand < 1 ) {
      break;
    }
  }
  int answer = cand;
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

int main(){
    int N, K;
    cin >> N >> K;
    ll dp[N+1][N+1][N*N+1];
    rep(i, N+1)rep(j, N+1)rep(k, N*N+1) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    rep(i, N)rep(j, N)rep(k, N*N+1){
        if(dp[i][j][k] == 0) continue;
        if(i+j+2 <= N){
            dp[i+1][j+1][k+4*j+2] += dp[i][j][k];
            dp[i+1][j+1][k+4*j+2] %= MOD;
        }
        if(i+j+1 <= N){
            dp[i+1][j][k+2*j] += (2*j+1)*dp[i][j][k];
            dp[i+1][j][k+2*j] %= MOD;
        }
        if(j > 0){
            dp[i+1][j-1][k] += j*j*dp[i][j][k];
            dp[i+1][j-1][k] %= MOD;
        }
    }
    cout << dp[N][0][K] << endl;
}

Measured memory_bytes: 51072
import java.util.Scanner;

public class Main {

	void main() {
		try(Scanner sc =new Scanner(System.in)){
			for(;;) {
				int y = sc.nextInt();
				int x = sc.nextInt();
				if(x == 0 && y == 0) break;
				System.out.println(Math.min(x, y) + " " + Math.max(x, y));
			}
		}
	}

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

	}

}



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

bool multiple_solutions=false;

vector<int> topologicalSort(int v,const vector<int> edge[]){
	vector<int> zeros;
	vector<int> in(v),res;
	for(int i=0;i<v;i++){
		for(int j=0;j<(int)edge[i].size();j++)in[edge[i][j]]++;
	}
	for(int i=0;i<v;i++)if(in[i]==0)zeros.push_back(i);
	while(!zeros.empty()){
		if(zeros.size()>=2)multiple_solutions=true;
		int u=zeros.back();
		zeros.pop_back();
		res.push_back(u);
		for(int i=0;i<(int)edge[u].size();i++){
			if(--in[edge[u][i]]==0)zeros.push_back(edge[u][i]);
		}
	}
	return res;
}


int main(){
	vector<int> edge[5000];
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		edge[a-1].push_back(b-1);
	}
	vector<int> order(topologicalSort(n,edge));
	for(int i=0;i<n;i++)cout<<order[i]+1<<endl;
	cout<<multiple_solutions<<endl;
	return 0;
}

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

long long int N, a[100000], b[100000], i, p;

int main(){
    scanf("%lld", &N);
    for(i = 0; i < N; ++i){
        scanf("%lld%lld", a + i, b + i);
    }
    /*if(N == 3 && *a == 3 && *b == 5){
        puts("114514");
        return 0;
    }*/
    for(i = N - 1; i >= 0; --i){
        p += ((a[i] + p) % b[i]) ? b[i] - (a[i] + p) % b[i]:0;
    }
    cout << p << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        long max = a[1] - a[0];
        long min = a[0];
        for(int i = 1; i < n; i++){
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        }
        System.out.println(max);
    }
}



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a,b; cin>>a>>b;
  string s,t;
  for (int i=0; i<b; i++) {
    s += char('0'+a);
  }
  for (int i=0; i<a; i++) {
    t += char('0'+b);
  }
  if (s>t) swap(s,t);
  out(s);
  

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
  int d, n;
  scanf("%d %d", &d, &n);
  int val = 1;
  for (int i = 0; i < d; i++) {
    val *= 100;
  }
  if (n == 100) n++;
  printf("%d\n", val*n);
  return 0;
}

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

int main(){
  int M,D,count=0;
  cin >> M >> D;
  for(int i=1;i<M+1;i++){
    for(int j=1;j<D+1;j++){
      if(j / 10 >= 2 && j % 10 >= 2){
        if((j/10) * (j%10) == i){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

int main(){
    int K;
    cin >> K;
    ll a, b, c;
    ll ans = 0;

    for (a = 1; a < K + 1; a++)
    {
        for (b = 1; b < K + 1; b++)
        {
            for (c = 1; c < K + 1; c++)
            {
                if (gcd(b, c) == 1)
                {
                    ans += 1;
                } else
                {
                    ans += gcd(a, gcd(b, c));
                }
                
                
            }
            
        }
        
    }
    cout << ans << endl;
      
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	for (int i = 0; i < S.size(); i+=w) {
		cout << S.at(i);
	}
	cout << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main() {
	int N,M,C;
	cin >> N >> M >> C;
	int *B = new int[M];
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}
	int count = 0;
	for (int i = 0; i < N; i++) {
		int sum = C;
		for (int j = 0; j < M; j++) {
			int a; cin >> a;
			sum += a * B[j];
		}
		if (sum > 0) { count++; }
	}

	cout << count;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
dic = dict()

for i in A:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

ans = 0
for num in dic:
    ans += num * dic[num]

for i in range(Q):
    b, c = list(map(int, input().split()))
    x = 0
    if b in dic:
        x = dic.pop(b)
        if c in dic:    
            dic[c] += x
        else:
            dic[c] = x
    ans += x * (c-b)
    print(ans)

Measured memory_bytes: 83376
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int x[5];
  for(int i=0; i<5; i++) cin >> x[i];
  int y[5];
  priority_queue<pair<int, int>> que;
  for(int i=0; i<5; i++) {
    if(x[i]%10 == 0) y[i] = 10;
    else y[i] = x[i]%10;
    que.push(make_pair(y[i], x[i]));
//    cout << "i: " << i << ", y[i]: " << y[i] << endl;
  }
  int ans = 0;
  for(int i=0; i<5; i++) {
    auto tmp = que.top(); que.pop();
    ans += tmp.second;
    if(i != 4 && ans%10 != 0) ans = (ans/10 + 1)*10;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, m;
  cin >> n >> m;
  if(2*n>=m) cout << m/2 << newl;
  else cout << (2*n+m)/4 << newl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; ++i) // マクロ
using namespace std; // stdの省略
using pii = pair<int, int>; // pairの略記
using ll = long long; // long longの略記


int main(void) {
   
   int r;
   cin >> r;
   
   
   
   cout << 2*r*M_PI << endl;
   
   return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

//const ll MOD = 1000000007ll;
const ll MOD = 2019ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

ll L,R;
ll ans = MOD;
int main() {
    cin>>L>>R;

    if(L==0){
        cout << 0 << endl;
        return 0;
    }

    int range = min(MOD*2,R-L)+1;

    //DEBUG(range);
    int ival = MOD;
    int jval = MOD;
    FOR(i,L,L+range){
        FOR(j,i+1,L+range){
            ival = i%MOD;
            jval = j%MOD;
            if(ans > ((ival*jval)%MOD))
                ans = (ival*jval)%MOD;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
main = do
  li <- getLine
  let n = read li
  let ans = compute n
  print ans

-- k は k+1 で割ると 0 余り k
-- 1からN-1まではこれをして、Nだけは残った1で割って余り0
-- つまり sum [1..N-1]

compute :: Int -> Int
compute n = n * (n-1) `div` 2


Measured memory_bytes: 508
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int A = sc.nextInt();
		int b = 0;
		if( H%A!=0 ){
			b = 1;
		}
		System.out.println(H/A+b);
	}
}

Measured memory_bytes: 25044
#include <stdio.h>

#define MAX 100

/*
    与えられるリング状の文字列を ring,
    そこから見つける文字列を make とする.
    --> ring の長さを取得しつつ，
        ring をふたつ連結した ring2 をつくる.        
        ring2 のあたまから make を探せばよい.
    --> make の長さを取得.
    --> ring2 のあたまから，make の一文字目に一致するものを探す．
        --> 一致したら，そこから ring2 を検査して
            make のすべての文字に一致するか調べる．
            --> 一致したら，検査を終えて Yes と表示．
            --> 一致しない場合，また ring2 から make の一文字目を探す．
        --> どれも一致しない場合，No と表示．
*/

int main(void)
{
    int i, j;

    char ring[MAX + 1];
    char make[MAX + 1];
    scanf("%s %s", ring, make);

    char ring2[MAX * 2 + 1];
    for (i = 0; (ring2[i] = ring[i]) != '\0'; i++){
        ;
    }
    int len_ring = i;
    for (i = 0; (ring2[len_ring + i] = ring[i]) != '\0'; i++){
        ;
    }

    for (i = 0; make[i] != '\0'; i++){
        ;
    }
    int len_make = i;

    enum {YES, NO} y_n;
    y_n = NO;
    for (i = 0; i < len_ring; i++){
        if (ring2[i] == make[0]){
            for (j = 0; j < len_make; j++){
                if (ring2[i + j] == make[j]){
                    y_n = YES;
                    continue;
                }else{
                    y_n = NO;
                    break;
                }
            }
            if (y_n == YES){
                break;
            }else{
                continue;
            }
        }
    }

    if (y_n == YES){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 944
import math

input_num = int(input())
total = 0


def gcd(a, b, c):
    return math.gcd(math.gcd(a, b), c)


for i in range(input_num):
    for j in range(input_num):
        for k in range(input_num):
            total += gcd(i + 1, j + 1, k + 1)
print(total)


Measured memory_bytes: 71092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

int main() {
  ll n;
  ll zero=0;
  cin >> n;
  map<ll,ll> count;
  for(ll i=2;i<=n;i++) {
    ll temp=i;
    for(ll j=2;j*j<=temp;j++) {
      while(temp%j==0) {
        temp/=j;
        count[j]++;
      }
    }
    if(temp!=1) {
      count[temp]++;
    }
  }
  ll n2=0,n4=0,n24=0,n14=0,n74=0;
  for(auto p:count) {
    if(p.second>1) {
      n2++;
    }
    if(p.second>3) {
      n4++;
    }
    if(p.second>13) {
      n14++;
    }
    if(p.second>23) {
      n24++;
    }
    if(p.second>73) {
      n74++;
    }
  }
  ll ans=0;
  ans+=max(n4*(n4-1)*(n2-2)/2,zero);
  ans+=max(n24*(n2-1),zero);
  ans+=max(n14*(n4-1),zero);
  ans+=n74;
  cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np

N, C = map(int, input().split())
X = [0]
V = [0]
for i in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)
X.append(C)
V.append(0)
# 0 ... N+1


m = s = 0
Left = [0] * (N+2)  # 即退店，1つ目まで，…
for i in range(1, N+2):
    s += -(X[i] - X[i-1]) + V[i]
    m = max(m, s)
    Left[i] = m

m = s = 0
Right = [0] * (N+2)
for i in range(N, -1, -1):
    s += -(X[i+1] - X[i]) + V[i]
    m = max(m, s)
    Right[i] = m

m = s = 0
LeftSub = [0] * (N+2)
for i in range(N, -1, -1):
    s += -2 * (X[i+1] - X[i]) + V[i]
    m = max(m, s)
    LeftSub[i] = m

m = s = 0
RightSub = [0] * (N+2)
for i in range(1, N+2):
    s += -2 * (X[i] - X[i-1]) + V[i]
    m = max(m, s)
    RightSub[i] = m

LeftTotal = np.array(Left[:-1]) + np.array(LeftSub[1:])
RightTotal = np.array(Right[1:]) + np.array(RightSub[:-1])
m = max(LeftTotal.max(), RightTotal.max())

print(m)


Measured memory_bytes: 37872
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)

bool is_integer(long double x)
{
    return std::floor(x) == x;
}

void Main()
{
    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }

    ll x;
    cin >> x;
    ll a, b;
    for (a = -1000; a <= 1000; ++a)
    {
        for (b = -1000; b <= 1000; ++b)
        {
            if (x == (ll)(pow(a, 5) - pow(b, 5)))
                break;
        }

        if (x == (ll)(pow(a, 5) - pow(b, 5)))
            break;
    }
    cout << a << " " << b << endl;
    return;
}

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


Measured memory_bytes: 4124
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

// ランレングス圧縮
vector<pair<char, int>> rle(const string& s) {
  char prv = '\0';
  ll cnt = 0;
  vector<pair<char, int>> res;
  rep(i, s.size()+1) {
    if (i == s.size() || s[i] != prv) {
      if (prv != '\0') {
        res.eb(prv, cnt);
      }
      prv = s[i];
      cnt = 1;
    }
    else {
      ++cnt;
    }
  }
  return res;
}

void solve() {
  string s; cin >> s;
  string ss = "";
  ll pos = 0;
  while (pos+1 < s.size()) {
    if (s[pos] == 'B' && s[pos+1] == 'C') {
      ss += 'X';
      pos += 2;
    }
    else {
      ss += s[pos++];
    }
  }
  auto v = rle(ss);
  ll sum = 0, ans = 0;
  // cout << v << endl;
  each(p, v) {
    if (p.first == 'A') {
      sum += p.second;
    }
    else if (p.first == 'X') {
      ans += p.second * sum;
    }
    else {
      sum = 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1936
s = input()
q = int(input())
q_list = [input().split() for i in range(q)]

flag = False
add_after = ""
add_before = ""
for q_num in q_list:
    if int(q_num[0]) == 1:
        if flag == False:
            flag = True
        else:
            flag = False
    
    else:
        if int(q_num[1]) == 1 and flag == False or int(q_num[1]) == 2 and flag == True:
            add_before = q_num[2] + add_before
        else:
            add_after = add_after + q_num[2]

result = add_before + s + add_after
if flag:
    print(result[::-1])
else:
    print(result)

Measured memory_bytes: 40660
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
a,b,c,d = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

def gcd(a,b):
  while b:
    a,b = b,a%b
  return a

def lcm(x, y):
    return (x * y) // gcd(x, y)


cd = lcm(c,d)

# b以下
cwari = b//c
dwari = b//d
cdwari = b//cd
ub = b-cwari-dwari+cdwari

# a以下
cwari = (a-1)//c
dwari = (a-1)//d
cdwari = (a-1)//cd
ua = (a-1)-cwari-dwari+cdwari

print(ub-ua)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	int n = 7;
	vector<ll> a(n);
	REP(i, n) {
		cin >> a[i];
	}
	ll res = 0;
	vector<ll> b = { 2,1,0,2,2,0,0 };
	ll m = min({ a[0],a[3],a[4] });
	res += a[1];
	ll temp = m*3;
	temp += ((a[0] - m) / 2 + (a[3] - m) / 2 + (a[4] - m) / 2) * 2;
	ll temp2 = 0;
	if (m > 0) {
		m--;
		temp2 += m * 3;
		temp2 += ((a[0] - m) / 2 + (a[3] - m) / 2 + (a[4] - m) / 2) * 2;
	}
	put(res + max(temp, temp2));
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
ab = []
for _ in range(M):
    ab.append(tuple(map(int, input().split())))
ab.sort()
r = 0
ans = 0
for a, b in ab:
    if a >= r:
        r = b
        ans += 1
    else:
        r = min(b, r)
print(ans)


Measured memory_bytes: 17004
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

def isok(bs, RT):
    return True if bs <= RT else False

def search(B, RT):
    left = -1
    right = M+1
    while right-left>1:
        mid = left+(right-left)//2
        if isok(B[mid], RT):
            left = mid
        else:
            right = mid
    return left

def solve():
    asum = [0]*(N+1)
    bsum = [0]*(M+1)
    for i in range(N):
        asum[i+1]=asum[i]+A[i]
    for i in range(M):
        bsum[i+1]=bsum[i]+B[i]

    ans = 0
    for i in range(N+1):
        RT = K-asum[i]
        if RT < 0:
            break
        ans = max(ans, i+search(bsum, RT))
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 48936
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long ans = 0;
        for (int i = 2; i < Math.sqrt(N); i++) {
            int count = 0;
            while (true) {
                if (N%i == 0) {
                    N /= i;
                    count++;
                } else {
                    break;
                }
            }
            int index = 1;
            while (true) {
                count -= index;
                if (0 <= count) {
                    ans++;
                } else {
                    break;
                }
                index++;
            }
        }
        System.out.println(N == 1 ? ans : ans+1);
    }
}

Measured memory_bytes: 35808
#include <iostream>

int main() {
	const int size = 4;
	int a[size], b[size];

	while (std::cin
		>> a[0] >> a[1] >> a[2] >> a[3]
		>> b[0] >> b[1] >> b[2]	>> b[3]
	) {
		int hit = 0, blow = 0;
		for (int i = 0; i < size; i++)
			if (a[i] == b[i]) {
				hit++;
			} else {
				for (int j = 0; j < size; j++)
					if (i != j && a[i] == b[j])
						blow++;
			}

		std::cout << hit << " " << blow << std::endl;
	}
}

Measured memory_bytes: 1160
import copy
class Card:
    def __init__(self, str):
        self.mark = str[0]
        self.number = int(str[1:])
        
    def __str__(self):
        return self.mark + str(self.number)
        
n = int(input())
card_list = [Card(c) for c in input().split()]

def bubble_sort(a):
    a = copy.copy(a)
    n = len(a)
    for i in range(n):
            for j in range(0, n-i-1):
                if a[j].number > a[j+1].number:
                    a[j], a[j+1] = a[j+1], a[j]
    return a
    
sorted_card_list1 = bubble_sort(card_list)
print(*sorted_card_list1)
print("Stable")

def selection_sort(a):
    a = copy.copy(a)
    n = len(a)
    for i in range(n):
        min_index = i
        for j in range(i+1,n):
            if a[j].number < a[min_index].number:
                min_index = j
        if i != min_index:
            a[i],a[min_index] = a[min_index],a[i]
    return a

    
sorted_card_list2 = selection_sort(card_list)
print(*sorted_card_list2)
if sorted_card_list1 == sorted_card_list2:
    print("Stable")
else:
    print("Not stable")


Measured memory_bytes: 6348
#include <stdio.h>
int main(void){
	int rank[3]={0,0,0},i,mt[10];
	for(i=1;i<=10;i++){//??\?????¨???
		scanf("%d",&mt[i-1]);
	}
	for(i=1;i<=10;i++){//??????????????¨???
		if(rank[0]<=mt[i-1]){//??°??????1???????????????
			rank[2]=rank[1];
			rank[1]=rank[0];
			rank[0]=mt[i-1];
		}else if(rank[1]<=mt[i-1]){//??°??????2???????????????
			rank[2]=rank[1];
			rank[1]=mt[i-1];
		}else if(rank[2]<=mt[i-1]){//??°??????3???????????????
			rank[2]=mt[i-1];
		}
	}
	for(i=0;i<=2;i++){
		printf("%d\n",rank[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n;
string s;

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

	cin>>s;
	int n=s.size();
	bool isti=true;
	for(int i=1;i<n;i++)
        if(s[i]!=s[i-1])
            isti=false;
    if(isti)
    {
        cout<<n;
        return 0;
    }
	int k=n;
	for(int i=0;i<n/2;i++)
        if(s[i]!=s[i+1])
            k=min(k,n-i-1);
    for(int i=(n+1)/2;i<n;i++)
        if(s[i]!=s[i-1])
            k=min(k,i);
    cout<<k;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int n,k;
    int d[10];
    char str[32];
    int i;
    char *p;
    int cnt = 0;
    int chk;
    int dchk;
    int ng;
    
    int num;
    int ddd;
    
    p = fgets(str, 32, stdin);
    for(i=0;i<32;i++){
        if(str[i] == ' '){
            str[i] = '\0';
            n = atoi(str);
            k = atoi(&str[i+1]);
            break;
        }
    }
    
    p = fgets(str, 32, stdin);
    for(i=0;i<32;i++){
        if(str[i] == ' '){
            str[i] = '\0';
            d[cnt++] = atoi(p);
            p = &str[i + 1];
        }
    }

    d[cnt] = atoi(p);

    for(chk=n;;chk++) {
        ng = 0;
        num = chk;
        i = 0;
        while(num!=0){
            ddd = num % 10;
            num = num / 10;
            for(dchk=0;dchk < k;dchk++) {
                if(ddd == d[dchk]) {
                    ng = 1;
                    break;
                }
            }
            if(ng) {
                break;
            }
        }
        if(!ng) {
            break;
        }
    }

    printf("%d\n", chk);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    if(a+b<=2*c)
        cout<<a*x+b*y;
    else if(x>y)
        cout<<min(2*y*c+a*(x-y),2*c*max(x,y));
    else
        cout<<min(2*x*c+b*(y-x),2*c*max(x,y));
    return 0;
}

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

int main(){
  int n;cin >> n;
  long long sum = 0;
  for(int i=1;i<=n;++i){
    if(i%3 != 0 && i%5 != 0)sum += i;
  }
  cout << sum << endl;
  return 0;
}

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

using namespace std;

int main() {
    int n, c;
    cin>>n;
    c=n%10;
    if((c==2)||(c==4)||(c==5)||(c==7)||(c==9))
    printf("hon");
    else if(((c==0)||(c==1)||(c==6)||(c==8)))
    printf("pon");
    else
    printf("bon");
    
    
    
    
    
    
    return 0;
}

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

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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  string S;
  cin>>S;
  cout<<S[0]<<S[1]<<S[2]<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N;
  cin>>N;
  int tmp=N;
  int s=0;
  while(tmp){
    s+=tmp%10;
    tmp/=10;
  }
  if(N%s==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  }


Measured memory_bytes: 256
def resolve():
    N, X, M = map(int, input().split())

    cycle = [False] * M
    A = []
    for i in range(N):
        if cycle[X]:
            break
        cycle[X] = True
        A.append(X)
        X = X ** 2 % M

    # サイクルのスタートを探索
    loop_start = 0
    for i in range(len(A)):
        if A[i] == X:
            loop_start = i
            break

    # サイクル前の和
    ans = sum(A[:loop_start])
    N -= loop_start

    # サイクルの要素
    A = A[loop_start:]

    loops = N // len(A)
    rest = N % len(A)
    
    ans += sum(A) * loops + sum(A[:rest])

    print(ans)


if __name__ == "__main__":
    resolve()

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }



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

    vll d(K);
    vll A(N);

    for(ll i = 0; i < N; i++){
        A.at(i) = 0;
    }

    for(ll i = 0; i < K; i++){
        cin >> d.at(i);
        for(ll j = 0; j < d.at(i); j++){
            ll kouho;
            cin >> kouho;
            A.at(kouho - 1) = 1;
        }
    }

    ll count = 0;

    for(ll i = 0; i < N; i++){
        if(A.at(i)==0){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] ch = sc.next().toCharArray();
        int length = ch.length;
        boolean existsSame = false;
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < length; j++) {
                // iとjが同じ場合は次のループ
                if (j == i) continue;
                if (ch[i] == ch[j]) {
                    existsSame = true;
                    break;
                }
            }
        }
        if (existsSame) {
            System.out.println("no");
        } else {
            System.out.println("yes");
        }
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
    int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

const int N = 2e5 + 1e3;
int n, a[N], b[N];

int main () {
	n = read();
	For (i, 1, n) b[i] = a[i] = read();
	sort(a + 1, a + 1 + n);

	int mid = n >> 1;
	For (i, 1, n)
		printf ("%d\n", b[i] <= a[mid] ? a[mid + 1] : a[mid]);
    return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
#include <string.h>

void replace(char *str, int a, int b, char *p);
void reverse(char *str, int a, int b);
void print(char *str, int a, int b);

int main(void)
{
  char str[1001],p[1001],order[10];;
  int a, b, q, i;
  scanf("%s", str);
  scanf("%d", &q);
  for(i=0;i<q;i++) {
    scanf("%s", order);
    if(strcmp(order, "replace") == 0) {
      scanf("%d%d%s", &a, &b, p);
      replace(str, a, b, p);
    } else if (strcmp(order, "reverse") == 0) {
      scanf("%d%d", &a, &b);
      reverse(str,a ,b);
    } else if (strcmp(order, "print") == 0) {
      scanf("%d%d", &a, &b);
      print(str, a, b);
    }
  }
  return 0;
}

void replace(char *str, int a, int b, char *p)
{
  int i;
  for(i=a;i<=b;i++) {
    str[i]=p[i-a];
  }
}

void reverse(char *str, int a, int b)
{
  char temp;
  int i;

  for(i=0;i<=(b-a)/2;i++) {
    temp=str[a+i];
    str[a+i]=str[b-i];
    str[b-i]=temp;
  }
}

void print(char *str, int a, int b)
{
  int i;
  for(i=a;i<=b;i++) {
    putchar(str[i]);
  }
  putchar('\n');
}

Measured memory_bytes: 2672
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    if A[0] != 0:
        if N == 0 and A[0] == 1:
            print('1')
            exit()
        else:
            print('-1')
            exit()

    if N == 0:
        print('1')
        exit()

    v = [0 for _ in range(N + 1)]
    v[N] = A[N]

    for i in range(N - 1, -1, -1):
        up = min(2 ** i, v[i + 1] + A[i])
        v[i] = up

    # print(v)
    for i in range(N):
        up = min(v[i + 1], (v[i] - A[i]) * 2)
        v[i + 1] = up

    # print(v)
    ans = 0
    for i in range(N + 1):
        if v[i] < A[i]:
            print('-1')
            exit()
        ans += v[i]

    # print(v)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 672924
import numpy as np

def counter(array):
    if array.size == 0:
        return 0
    if array.size == 1:
        return array[0]
    min_num = np.min(array)
    idx = np.argmin(array)
    tmp = array - min_num
    return min_num + counter(tmp[:idx]) + counter(tmp[idx+1:])


n = int(input())
h = np.array(list(map(int, input().split())))
print(counter(h))

Measured memory_bytes: 21408
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int x,t,n,i,a,minp;
  cin >> n >> t >> a;
  double h[n-1],minv = 1000000000;
  for ( i = 0; i < n; i++){
    cin >> h[i];
    if (chmin(minv,abs(a - (t - h[i] * 0.006)))){
      minp = i + 1;
    }
  }
  cout << minp << '\n';
  return 0;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))
ans = 0

for i in range(N):
    while h[i] != 0:
        for j in range(i, N):
            if h[j] != 0:
                h[j] = h[j] - 1
            elif h[j] == 0:
                break
        ans += 1

print(ans)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
 
 
signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int a,b;
  	cin >> a >> b;
  	if(a>1&&b>1) print1(a*b/2+a*b%2);
  	else print1(1);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
#include <iostream>
#include <cmath>

long long int ggd(int number1, int number2) {
	int m = number1;
	int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}

	while (m != n) {
		int temp = n;
		n = m - n;
		m = temp;
	}

	return m;
}
int lcm(int number1, int number2) {
	return number1 * number2 / ggd(number1, number2);
}

int main(void) {
	long long max = 0, sum = 0, maxa = 0, res;
	int n;
	int a[100000];
	scanf("%d", &n);
	int lcm1=1;
	for (int i = 0; i < n; i++) {
		scanf(" %d", &a[i]);
		//if (a[i] > maxa)maxa = a[i];
		//lcm1 = lcm(lcm1, a[i]);
		sum += a[i];
	}
	for (int i = 0; i < n; i++) {
		sum += (lcm1 - 1) % a[i];
	}
	/*for (int i = 0; i < maxa*2; i++) {
		sum = 0;
		for (int j = 0; j < n; j++) {
			sum += i%a[j];
		}
		if (sum > max)max = sum;
	}*/
	
	printf("%lld\n", sum-n);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<iomanip>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    ll x,p;cin>>x>>p;
    cout<<fixed<<setprecision(10)<<(x+1)/2*100/(double)p<<endl;
    return 0;
}


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

using namespace std;
#define ll long long

ll INF = 1e9 + 7;
const int N = 1e6 + 5;

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

    ll x,k,d;
    cin>>x>>k>>d;

    x = abs(x);

    if(x/d >= k)
        cout<<(x - k * d)<<endl;
    else
    {
        ll tmp = x - d*(x/d);
        ll n = k - (x/d);

        if(n%2 == 0)
            cout<< abs(tmp)<<endl;
        else
            cout<< abs(tmp - d)<<endl;
    }

}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int r;
    cin >> r;

    cout << r*r;
    return 0;
}

Measured memory_bytes: 256
program main
    implicit none
    character(100):: s
    integer(4):: ls
    integer(4):: i, j
    logical:: j1, j2, j3
    read*, s

    ls = len_trim(s)
    j1=.true.
    j2=.true.
    j3=.true.

    do i=1, (ls-1)/2
        j = ls+1-i
        if (s(i:i) /= s(j:j)) j1 = .false.
    end do

    do i=1, (ls-1)/2/2
        j = (ls-1)/2+1-i

        if(s(i:i) /= s(j:j)) j2 = .false.
    end do

    
    do i=(ls+3)/2, ((ls+3)/2+ls)/2
        j = ((ls+3)/2+ls)-i

        if(s(i:i) /= s(j:j)) j2 = .false.
    end do

    if (j1 .and. j2 .and. j3) then
        print*, 'Yes'
    else
        print*, 'No'
    end if
end program main

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {
    double a, b ,c, d;
    scanf("%lf %lf %lf", &a, &b, &c);
    double s, l, h;
    s = 0.5 * a * b * sin(M_PI * c / 180);
    d = sqrt(a * a + b * b - 2 * a * b * cos(M_PI * c / 180));
    l = 1.00000000 * (a + b + d);
    h = 2.00000000 * s / a;
    printf("%8lf\n", s);
    printf("%8lf\n", l);
    printf("%8lf\n", h);
}


Measured memory_bytes: 3424