akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

bool check(string s)
{
  int c[26];

  for(int i = 0; i < 26; i++){
    c[i] = 0;
  }

  for(int i = 0; i < s.size(); i++){
    c[s[i]-'a']++;
  }

  for(int i = 0; i < 26; i++){
    if(c[i] >= 2) return false;
  }

  return true;
}

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

  if(s == "zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
    return 0;
  }

  if(s.size() == 26){
    int cnt = 0;
    for(int i = s.size()-1; i > 0; i--){
      if(s[i-1] > s[i]) cnt++;
      else break;
    }
    while(next_permutation(s.begin(), s.end())){
      if(check(s)) break;
    }
    s = s.substr(0, s.size()-cnt-1);
  }else{
    int c[26];
    for(int i = 0; i < 26; i++){
      c[i] = 0;
    }
    for(int i = 0; i < s.size(); i++){
      c[s[i]-'a']++;
    }
    for(int i = 0; i < 26; i++){
      if(!c[i]){
        s += ('a' + i);
        break;
      }
    }
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

const ll inf = 10000000000000000;
ll n, d, x, y, ans;

int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> d;
    for (ll i = 1; i <= n; ++i) {
        cin >> x >> y;
        if (x * x + y * y <= d * d)
            ++ans;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
using namespace std;
typedef long long ll;
ll a;

int main()
{   int n,flag=0;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>a;
        if(a&1){
            flag=1;
        }
    }
   if(flag==1){
    cout<<"first"<<endl;
   }else
   cout<<"second"<<endl;
    
    return 0;
}


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

S = [0]

Sum = 0


for i in range(N):
  K = K - A[i]
  if K >= 0:
    Sum += 1
  else:
    K = K + A[i]
    break
else:
  i = N
S.append(Sum)

for j in range(M):
  K = K - B[j]
  if K >= 0:
    Sum += 1
  else:
    if i == 0:
      break
    for k in range(i):
      K = K + A[i-k-1]
      
      Sum = Sum - 1
      if K >= 0:
        i = i-k-1
        break
    else:
      i = 0
      continue
    if K >= 0:
      Sum += 1
    
  S.append(Sum)
 
print(max(S))

Measured memory_bytes: 41828
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        HashMap<Character, Integer> cmap = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (cmap.containsKey(c)) {
                cmap.replace(c, cmap.get(c) + 1);
            } else {
                cmap.put(c, 1);
            }
        }
        String answer = "Yes";
        for (Character c : cmap.keySet()) {
            if (cmap.get(c) != 2) {
                answer = "No";
                break;
            }
        }
        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 35816
X = int(input())
a = []
b = 0
flag = True
num = 120
if(X <= 120):
  num = X
for i in range(1,num+1):
  if(X%i== 0):
    a.append(i)
while(flag):
  for i in range(len(a)): 
    if(pow(b+a[i],5)-pow(b,5) == X):
      print("%d %d"%(b+a[i],b))
      flag = False
      break
  b -= 1
  if(b < -119):
    b = 119

Measured memory_bytes: 9152
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,m;
	cin>>n>>m;
	ll x,y;
	if(n>0)
	 x=(n*(n-1))/2;
	else 
	x=0;
	if(m>0)
	 y=(m*(m-1))/2;
	else 
	y=0;
	cout<<x+y;
	return 0;
}


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

int main() {
  int n,y,a=-1,b=-1,c=-1;
  cin >> n >> y;
  for(int i=0; i<=n; i++) {
    for(int j=0; j<=n-i; j++) {
      if(10000*i+5000*j+(n-i-j)*1000==y) {
        a=i,b=j,c=n-i-j;
      }
    }
  }
  cout << a << " "<< b << " " << c << endl;  
}

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

using Lint=long long;

Lint calc(Lint N,Lint p)
{
   // N!が素因数pをいくつ含むか
   Lint res=0;
   while(N/p>0){ res+=N/p; N/=p; }
   return res;
}

Lint func(Lint N)
{
   if(N<=1) return 0;
   if(N%2==1) return 0;
   else{ return min(calc(N,2),calc(N/2,5)); }
}

int main()
{
   Lint N; cin>>N;
   cout<<func(N)<<endl;
   return 0;
}


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

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

const int MOD = 1e9 + 7;
const int INFi = 2e9 + 1;
const lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};
const char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(i, vec) for(auto &(i) : (vec))


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




int main(void){
  int n; cin >> n;
  Vint L(2 * n); vREP(ele, L) cin >> ele;
  std::sort(L.begin(), L.end());
  int res = 0;
  FORstep(i, 0, 2 * n, 2) res += L.at(i);
  cout << res << BR;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))+[0]
ans = 0
for i in range(N):
  if B[i]>=A[i]:
    B[i] -= A[i]
    ans += A[i]
    A[i] = 0
  elif B[i]>0 and B[i]<A[i]:
    A[i] -= B[i]
    ans += B[i]
    continue
  if B[i]>=A[i+1]:
    ans += A[i+1]
    A[i+1] = 0
  elif B[i]>0 and B[i]<A[i+1]:
    A[i+1] -= B[i]
    ans += B[i]
print(ans)
  

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

int A[20];
int B[20];

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long LL;

const int maxn=2e5+5;

int n,m,dr[maxn];
char s[maxn],inD[maxn];

char Read()
{
	char ch=getchar();
	while (ch<'A' || ch>'Z') ch=getchar();
	return ch;
}

int check(int x)
{
	fo(i,1,m) if (s[x]==inD[i])
	{
		x+=dr[i];
		if (x<1 || x>n) break;
	}
	return x;
}

int main()
{
	scanf("%d %d",&n,&m);
	scanf("%s",s+1);
	fo(i,1,m)
	{
		char ch1=Read(),ch2=Read();
		inD[i]=ch1;
		dr[i]=(ch2=='L') ?-1 :1 ;
	}
	
	int l=1, r=n;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (check(mid)==0) l=mid+1; else r=mid-1;
	}
	int ans1=l-1;
	
	l=1, r=n;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (check(mid)==n+1) r=mid-1; else l=mid+1;
	}
	int ans2=r+1;
	
	printf("%d\n",max(0,ans2-1-ans1));
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){
 ll d ; cin>> d ;
 ll c[26] ; rep(i,26) cin>>c[i] ;
 ll s[d][26] ;
 vector<ll> t(d) ;
 vector<ll> ans(d) ;
 rep(i,d){
     rep(j,26){
        cin>> s[i][j] ;
        if(t[i]<s[i][j]){
            t[i]= s[i][j] ;
            ans[i]= j+1;
        }
     }
 }



 rep(i,d){
     cout<< ans[i] <<endl ;
 }
 return 0 ; 
}



Measured memory_bytes: 3720
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int main(){
  ll N,A[210000],data,sum=0;
  cin>>N;
  for(int i=1;i<=N;i++){
    cin>>data;
    data-=i;
    A[i-1]=data;
  }
  sort(A,A+N);

  ll center;
  center=A[N/2];
  for(int i=0;i<N;i++){
    sum+=abs(center-A[i]);
  }
  cout<<sum<<endl;
  
  
  
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

ll a[200000];
int main() {
	int n;
	scanf("%d", &n);
	fup(i,0,n-1,1)scanf("%lld", a + i);
	if (a[0] > 0)return !printf("-1");
	fup(i, 0, n - 2, 1)
		if (a[i + 1] - a[i] > 1)return !printf("-1");
	ll ans = 0;
	fup(i, 0, n - 2, 1)
	{
		if (a[i + 1] - a[i] == 1)ans++;
		else ans += a[i + 1];
	}
	printf("%lld", ans);
}

Measured memory_bytes: 1792
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,g[100][100];

int main()
{
    n=read();ll ans=0;
    rep(i,1,n)
    {
        double x;scanf("%lf",&x);
        ll num=round(x*1e9);
        //cout << y << endl;
        int c2=0,c5=0;
        while (num%2==0) {c2++;num/=2;}
        while (num%5==0) {c5++;num/=5;}
        //cout << c2 << " " << c5 << endl;
        rep(x,max(18-c2,0),50) rep(y,max(18-c5,0),50) ans+=g[x][y];
        g[c2][c5]++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3856
#include <iostream>

using namespace std;

const int bf = 4280;

int main()
{
    int inp;

    while (cin >> inp, inp != -1) {
        int now = 0;

        while (inp >= 0) {
            if (inp > 30) {
                now += 160 * (inp - 30);
                inp = 30;
            }
            else if (inp > 20) {
                now += 140 * (inp - 20);
                inp = 20;
            }
            else if (inp > 10) {
                now += 125 * (inp - 10);
                inp = 10;
            }
            else {
                now += 1150;
                inp = -1;
            }
        }
        cout << bf - now << endl;
    }

    return 0;
}

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

if N == 2:
    print(max(A))
    exit(0)

A.sort(reverse=True)

ans = A[0]
cur = 1
for ix in range(len(A[2:])):
    ans += A[cur]
    if ix & 1:
        cur += 1

print(ans)


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

char S[51];
char T[51];
char restoredS[51];
char tmp[51];
char found =0;

int main(){
        restoredS[0]='\0';
        scanf("%s",S);
        scanf("%s",T);

        if(strlen(S) < strlen(T)){ puts("UNRESTORABLE"); return 0;}
        for(int i = strlen(S)-strlen(T); i >= 0 ; i--){
                char possible = 1;
                for(int j = 0; j < strlen(T); j++){
                        if(S[i+j] != '?' && S[i+j] != T[j]){
                                possible = 0;
                                break;
                        }
                }
                if(possible){
                        for(int a = 0; a < strlen(S); a++){
                                restoredS[a] = (S[a]=='?')?'a':S[a];
                        }
                        for(int j = 0; j < strlen(T); j++){
                                restoredS[i+j] = T[j];
                        }
                        break;
                }
        }
        if(strlen(restoredS)==0) puts("UNRESTORABLE");
        else printf("%s\n",restoredS);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int n,q,a,b;
string s;
int main(){
  cin>>s;
  if(s.size()&1)return cout<<"No",0;
  for(a=0;a<s.size()-1;a+=2){
    if(s[a]!='h'||s[a+1]!='i')return cout<<"No",0;
  }
  cout<<"Yes";
}

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

int main(){
  int N; cin >> N;
  int S[15][15];
  int ans=0;
  for(int i=0;i<15;i++){
    for(int j=0;j<15;j++){
      S[i][j]=-1;
    }
  }
  for(int i=0;i<N;i++){
    int A; cin >> A;
    for(int j=0;j<A;j++){
      int x,y; cin >> x >> y;
      S[i][x-1]=y;
    }
  }
  for(int i=0;i<(1<<N);i++){
    vector<int> d(N);
    for(int j=0;j<N;j++){
      if(i>>j&1){
        d[j]=1;
      }
    }
    bool ok=true;
    for(int j=0;j<N;j++){
      if(d[j]){
        for(int k=0;k<N;k++){
          if(S[j][k]==-1) continue;
          if(S[j][k]!=d[k]) ok=false;
        }
      }
    }
    if(ok) ans=max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
}
      

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string a,b;
    cin>>a>>b;
    if(a=="H"){
        if(b=="H"){
            cout<<"H"<<endl;
        }else{
            cout<<"D"<<endl;
        }
    }else{
        if(b=="H"){
            cout<<"D"<<endl;
        }else{
            cout<<"H"<<endl;
        }
    }
    return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
	string s; int p;
	cin >> s >> p;
	for(auto &i : s)i -= '0';
	int n = s.size();
	vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(110, vector<ll>(2))); //i桁目まで見て0がjこでフラグがk;
	dp[0][0][0] = 1;

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 105; j++) {
			for(int k = 0; k < 2; k++) {

				for(int d = 0; d <= (k ? 9 : s[i]); d++) {
					dp[i + 1][j + (d != 0)][k || d < s[i]] += dp[i][j][k];
				}
			}
		}
	}
	cout << dp[n][p][0] + dp[n][p][1] << endl;
}

Measured memory_bytes: 896
#include<stdio.h>

int main(void){
  int a,md,hz,sum = 0;
  scanf("%d",&a);
  hz = a;
  while(a){
    md = a % 10;
    sum = sum + md;
    a = a / 10;
  }
  md = hz % sum;
  if(md == 0){
    puts("Yes");
  }else puts("No");
  return 0;
}

Measured memory_bytes: 128
class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.range = [(-1,n)] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
            self.range[self.num + i] = (i,i)
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
            self.range[i] = (self.range[2 * i][0],self.range[2 * i + 1][1])

    def update(self, k, x):
        k += self.num
        self.tree[k] += x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

import sys

N = int(input())

p = [tuple(map(int,input().split())) for i in range(N)]
p.sort()

y_val = set([p[i][1] for i in range(N)])
y_val = list(y_val)
y_val.sort()
comp = {i:e for e,i in enumerate(y_val)}
n = len(y_val)

seg_low = SegmentTree([-10**18 for i in range(n)],max,-10**18)
seg_high = SegmentTree([-10**18 for i in range(n)],max,-10**18)

xmin = [-10**18 for i in range(n)]

ans = -10**18
for x,y in p:
    idx = comp[y]
    tmp1 = x+y+seg_low.query(0,idx)
    tmp2 = x-y+seg_high.query(idx,n)
    ans = max(ans,tmp1,tmp2)
    if xmin[idx]!=-10**18:
        if xmin[idx]>x:
            seg_low.update(idx,xmin[idx]-x)
            seg_high.update(idx,xmin[idx]-x)
            xmin[idx] = x
    else:
        seg_low.update(idx,-y-x+10**18)
        seg_high.update(idx,y-x+10**18)
        xmin[idx] = x

print(ans)

Measured memory_bytes: 179004
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;

int main(void)
{
    string a;
    int i;

    cin >> a;
    for(i = 0; i < (signed)a.size(); i += 2)
        if(a[i] == 'L')
        {
            cout << "No" << endl;

            return 0;
        }
    for(i = 1; i < (signed)a.size(); i += 2)
        if(a[i] == 'R')
        {
            cout << "No" << endl;

            return 0;
        }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.next());
		int k = Integer.parseInt(in.next());
		int s = Integer.parseInt(in.next());
		int p = Integer.parseInt(in.next());
		int r = Integer.parseInt(in.next());
		char[] game = in.next().toCharArray();
		int ans = 0;
		for(int i = 0; i < n; i++) {
			if(i < k) {
				if(game[i] == 's') ans += s;
				else if(game[i] == 'p') ans += p;
				else ans += r;
			}else {
				if(game[i - k] == game[i]) game[i] = '.';
				else {
					if(game[i] == 's') ans += s;
					else if(game[i] == 'p') ans += p;
					else ans += r;
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 28116
#include<bits/stdc++.h>
using namespace std;
 
#define MOD 998244353
template<typename ty1,typename ty2>
inline int add(ty1 x, ty2 y) {
	if(y>=MOD)y%=MOD;
	if(x>=MOD)x%=MOD;
    x += y; return x < MOD ? x : x - MOD;
}
template<typename ty1,typename ty2>
inline void addto(ty1 &x, ty2 y) {
		  if(y>=MOD)y%=MOD;
		  if(x>=MOD)x%=MOD;
	      x += y; if (x >= MOD) x -= MOD;
}
template<typename ty1,typename ty2>
inline int sub(ty1 x, ty2 y) {
		if(y>=MOD)y%=MOD;
		 if(x>=MOD)x%=MOD;
        x -= y; return x < 0 ? x + MOD : x;
}
template<typename ty1,typename ty2>
inline void subto(ty1 &x, ty2 y) {
	if(y>=MOD)y%=MOD;
	if(x>=MOD)x%=MOD;
    x -= y; if (x < 0) x += MOD;
}
template<typename ty1,typename ty2>
inline int mul(ty1 x, ty2 y) {
        if(y>=MOD)y%=MOD;
		if(x>=MOD)x%=MOD;
        return 1ll * x * y % MOD;
}
template<typename ty1,typename ty2>
void multo(ty1 &x, ty2 y) {
        if(y>=MOD)y%=MOD;
		if(x>=MOD)x%=MOD;
        x=1ll * x * y % MOD;
}
  
long long int gcd(long long int a, long long int b){
	if (a > b){
		swap(a, b);
	}
	while (a){
		swap(a, b);
		a %= b;
	}
	return b;
}
long long int lcm(long long int a, long long int b){
	return a / gcd(a, b)*b;
}
long long int ppow(long long int i, long long int j){
		long long int res = 1LL;
		while (j){
			if ((j & 1LL)){
				res *= i;
				if (res >= MOD){
					res %= MOD;
				}
			}
			j >>= 1;
			i *= i;
			if (i >= MOD){
				i %= MOD;
			}
		}
		return res;
	}
class Combination{
	
public:
	vector<long long int> k;
	vector<long long int> r;
	void resize(int N){
		k.resize(N + 2);
		r.resize(N + 2);
		k[0] = 1;
		for (int i = 1; i < N+2; i++){
			k[i] = k[i - 1];
			k[i] *= i;
			if (k[i] >= MOD)k[i] %= MOD;
		}
		long long int al = k[k.size() - 1];
		long long int iv = ppow(k[k.size() - 1],MOD-2);
		r[k.size() - 1] = iv;
		for (int i = (int)(r.size()) - 2; i >= 0; i--){
			r[i] = r[i + 1] * (i + 1);
			if (r[i] >= MOD){
				r[i] %= MOD;
			}
		}
	}
	long long int C(int a, int b){
		if (a < b)return 0;
		long long int up = k[a];
		long long int dw = r[b] * r[a - b];
		dw %= MOD;
		up *= dw;
		up %= MOD;
		return up;
	}
	long long int H(int a, int b){
		return C(a + b - 1, b);
	}
	long long int catalan_number(int n){
		return (C(2 * n, n) + MOD - C(2 * n, n - 1)) % MOD;
	}
};
Combination C;

int main(){
	long long int a,v,b,w,t;
	cin>>a>>v>>b>>w>>t;
	long long int dif=abs(a-b);
	long long int g=abs(v-w);
	if(v>w){
		if(g*t>=dif){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
	return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;


int main() {
	string s;
	int k;
	cin >> s >> k;
	int num;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != '1') {
			num = i;
			break;
		}
	}
	if (k - 1 < num)cout << 1 << endl;
	else cout << s[num] << endl;


	return 0;
}



Measured memory_bytes: 256
yes, no = "YES", "NO"
N = int(input())
A = list(map(int, input().split()))
even, odd = 0, 0

for e in A:
	if e % 2 == 0:
		even += 1
	else:
		odd += 1

if odd % 2 == 0:
	print(yes)
else:
	print(no)		


Measured memory_bytes: 14108
import sys

n,k = map(int, input().split())

a = list(map(int, input().split()))

dp = [sys.maxsize]*n
dp[0] = 0
for i in range(n):
    for j in range(i+1, i+k+1):
        if j < n:
            dp[j] = min(dp[j], dp[i]+abs(a[i]-a[j]))

print(dp[n-1])

Measured memory_bytes: 52448
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for (i = 0; i < n; i++)
#define P pair<int, int>

ll INF = 1000000000000000000;

int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n + 1);
  for (int i = 0; i < n + 1; i++)
  {
    cin >> a[i];
  }

  if (n == 0)
  {
    if (a[0] == 1)
    {
      cout << 1 << endl;
      return 0;
    }
    else
    {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<ll> d(n + 1);
  d[n] = a[n];
  for (int i = n - 1; i >= 0; i--)
  {
    d[i] = (d[i + 1] + 1) / 2 + a[i];
  }
  if (d[0] > 1)
  {
    cout << -1 << endl;
    return 0;
  }

  vector<ll> cum(n + 1);
  cum[n] = a[n];
  for (int i = n - 1; i >= 0; i--)
  {
    cum[i] = cum[i + 1] + a[i];
  }

  vector<ll> b(n + 1);
  b[0] = 1;
  for (int i = 1; i < n + 1; i++)
  {
    b[i] = 2 * (b[i - 1] - a[i - 1]);
    if (b[i] >= INF)
    {
      b[i] = INF;
    }
  }

  vector<ll> res(n + 1);
  for (int i = 0; i < n + 1; i++)
  {
    res[i] = min(cum[i], b[i]);
  }

  ll ans = 0;
  for (int i = 0; i < n + 1; i++)
  {
    ans += res[i];
  }

  cout << ans << endl;
}


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

int main() {
	int a, b;

	cin >> a >> b;

	if(a < b) {
		cout << "a < b" << endl;
	}else if(a > b) {
		cout << "a > b" << endl;
	}else {
		cout << "a == b" << endl;
	}

	return 0;
}


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

using ll = long long;

int main (void){
  char s[26] = {'\0'};
  int n[26] = {0};
  for (int i = 0; i < 26; i++){
    s[i] = '\0';
    n[i] = 0;
  }

  cin >> s;
  //cout << s << endl;

  for (int i = 0; i < 26 && s[i] != '\0'; i++){
    s[i] -= 97;
    n[s[i]]++;
    //cout << n[s[i]] << endl;
    if(n[s[i]] >= 2){
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    k=INT()
    ans=0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for h in range(1,k+1):
                ans+=math.gcd(math.gcd(i,j),h)
                #print(ans,i,j,h)
    print(ans)
if __name__ == '__main__':
    do()

Measured memory_bytes: 9552
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a,x,y;
    string s;
    cin >> s;
    a = s.size();
    for(int i=0;i<a;i++){
        if(s[i]=='A'){
            x = i;
            break;
            }
    }
    for(int i = 0; i < a;i++){
        if(s[a-i-1]=='Z'){
            y=a-i-1;
            break;
        }
    }
    cout << y-x+1 << endl;
}

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

#define R register
#define ll long long
#define sum(a, b, mod) (((a) + (b)) % mod)

const int MaxN = 21;
const int MaxM = (1 << 21) + 10;

char s[MaxM];
int n, k, lim, f[MaxN][MaxM];

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 0; i <= n; i++)
    {
        lim = (1 << i), scanf("%s", s);
        for (int j = 0; j < lim; j++)
            if(s[j] == '1')
                f[i][j | lim] = 1;
    }
    for(int i = n; i; i--)
    {
        for(int j = i; j <= n; j++)
        {
            lim = (1 << j);
            for(int k = 0; k < lim; k++)
            {
                int tmp = f[i][k | lim], p = - 1, q = -1;
                if(!tmp) continue;
                for(int t = i - 1; ~t; t--)
                    if(k & (1 << t)) {p = t; break;}
                for(int t = i - 1; ~t; t--)
                    if((k & (1 << t)) == 0) {q = t; break;}
                f[0][(k + lim) >> i] += tmp;
                if (~p) f[p][(1 << (j - i + p + 1)) | (((1 << p) - 1) & k) | ((((k >> i) << 1) | 1) << p)] += tmp;
                if (~q) f[q][(1 << (j - i + q + 1)) | (((1 << q) - 1) & k) | ((((k >> i) << 1)) << q)] += tmp;
            }
        }
    }
    for(int i = n; ~i; i--)
    {
        lim = (1 << i);
        for(int j = 0; j < lim; j++)
        {
            if(f[0][j | (1 << i)] >= k)
            {
                for(int l = i - 1; ~l; l--)
                    putchar('0' + (!!(j & (1 << l))));
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 172416
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;

int n, m;
vector<pii> V;

int main() {
    scanf("%d %d", &n, &m);
    for(int i = 0, a, b; i < m; ++i) {
        scanf("%d %d", &a, &b);
        V.emplace_back(a, b);
    }
    sort(V.begin(), V.end(), [&](const pii &a, const pii &b) { return a.y < b.y; });
    int ret = 0, cnt = 0;
    for(pii w : V) if(ret <= w.x) ret = w.y, cnt++;
    printf("%d\n", cnt);
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int len;
    cin >> len;
    string s, t;
    cin >> s >> t;
    int slen = s.size(), tlen = t.size();
    for (; len > 0; len--) {
        int si = slen - len;
        int ti = 0;
        if (s.substr(si, len) == t.substr(ti, len)) {
            break;
        }
    }

    cout << s.size() * 2 - len << '\n';
}

Measured memory_bytes: 3644
n=int(input())
a=list(map(int,input().split()))
k=sum(a)
b=list(map(int,input().split()))

for i in range(n):
  r=b[i]-a[i]
  a[i]=max(a[i]-b[i],0)
  if r>0:
    a[i+1]=max(a[i+1]-r,0)
print(k-sum(a))

             

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

int main(){
  int n;
  long long a[200010];
  long long b[200010];
  cin >> n;
  for (int i=0; i<n; i++) b[i]=0;
  for (int i=0; i<n; i++){
  cin >> a[i];
  b[a[i]-1]++;
  }
  long long int s;
  for (int i=0; i<n; i++){
  s += b[i]*(b[i]-1)/2;
  }
  for (int i=0; i<n; i++){
  cout << s-b[a[i]-1]+1 << endl;
  }
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int>
#define pqueue priority_queue
#define rep(a,n) for(int i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int n,vin &a){
    rep(0,n){
        cin>>a.at(i);
    }
}

int RepSq(int x,int n){
    if(n==0) return 1;
    if(n%2==0){
        int t=RepSq(x,n/2);
        return t*t%INF;
    }
    return x*RepSq(x,n-1);
}

//逆元を用いたnCrの方法 nが大きくてもよい(~10^9)　ただしrが小さくないといけない(~10^5)
const int MAX_K=200001;
const int N=1000000007;
const int MOD=INF;
long long COM[MAX_K]; //nCkを格納しておく(nが固定値の場合)
long long inv[MAX_K],finv[MAX_K],fac[MAX_K]; //facはn*...n-k+1
void bigCOMinit(){
    //逆元計算
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    //fac[0]=N % MOD,fac[1]=(N % MOD)*((N-1) % MOD) % MOD;
    for (int i = 2; i < MAX_K; i++){
        //fac[i] = fac[i - 1] * (N - i) % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;

    }

    // COM[0]=1;
    // for(int i=1;i<MAX_K;i++){
    //     COM[i]=fac[i-1] * finv[i] % MOD;
    // }
}


signed main(){
    typedef pair<int,int> P;
    int n,a,b;
    cin>>n>>a>>b;
    bigCOMinit();
    //MAX=n;
    long long tcom[MAX_K];
    fac[0]=n % MOD,fac[1]=(n % MOD)*((n-1) % MOD) % MOD;
    for (int i = 2; i < MAX_K; i++){
        fac[i] = fac[i - 1] * (n - i) % MOD;
    }

    tcom[0]=1;
    for(int i=1;i<MAX_K;i++){
        tcom[i]=fac[i-1] * finv[i] % MOD;
    }
    //cout<<finv[1]<<endl;

    int sum=RepSq(2,n)-1-tcom[a]-tcom[b];
    while(sum<0){
        sum+=MOD;
    }
    sum%=MOD;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 7936
import java.util.*;
import java.util.stream.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        // programming
        String s = getInputString(sc);
        StringBuilder temp = new StringBuilder(s);
        boolean isFound = false;
        String[] words = {"dream","dreamer","erase","eraser"};
        int i = 0;

        l1: while (true) {
            i++;
            if (i % 100 == 0) {
                System.gc();
            }
            for (String w : words) {
                if (temp.toString().endsWith(w)) {
                    temp.delete(temp.length() - w.length(), temp.length());
                    if (temp.length() == 0) {
		                isFound = true;
		                break l1;
		            }
		            continue l1;
                }
            }
            break;
        }
        if (isFound) {
            output("YES");
        } else {
            output("NO");
        }
	}

	public static String getInputString(Scanner sc) {
		return sc.next();
	}

	public static int getInputInteger(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	public static void output(String... params) {
		boolean isInit = true;
		String str = "";
		for (String s : params) {
			if (!isInit) {
				str += " ";
			}
			str += s;
			isInit = false;
		}
		System.out.println(str);
	}

    public static int[] toIntegerList(String[] ss) {
        return Stream.of(ss).mapToInt(Integer::parseInt).toArray();
    }

    public static String[] toList(String s) {
        String[] ret = s.split("");
        return ret;
    }

    public static int sum(int[] vals) {
        int sum = 0;
        for (int val : vals) {
            sum += val;
        }
        return sum;
    }

    public static int[] sort(int[] vals, boolean isAsc) {
        Arrays.sort(vals);
		if (isAsc) {
			return vals;
		}
        int[] ret = new int[vals.length];
        for (int i = 0; i < vals.length; i++) {
            ret[vals.length - i - 1] = vals[i];
        }
		return ret;
	}
}

Measured memory_bytes: 93792
import java.util.Scanner;

/**
 *
 * @author lenovo
 */
public class Main {

    public static void main(String[] args) {
        int num = 0;
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        for (int x = a; x <= b; x++) {

            if (c % x == 0) {
                num++;
         
            }
        }

        System.out.println(num);
    }

}

Measured memory_bytes: 26336
#include<bits/stdc++.h>
using namespace std;
void ts()
{
    cout<<"***我只想过个水题抽奖****"<<endl;
    cout<<"***I JUST WANT PASS A WATER-PROBLEM FOR LUCK DRAW***"<<endl;
}
#define ll long long
int x,y,z,m;
ll a[1005],b[1005],c[1005];
vector<ll>v;
void solve1()
{
    for(int i=1;i<=min(200,x);i++)
        for(int j=1;j<=min(200,y);j++)
            for(int k=1;k<=min(200,z);k++)
        v.push_back(a[i]+b[j]+c[k]);
    for(int i=201;i<=x;i++)
        for(int j=1;j<=min(50,y);j++)
            for(int k=1;k<=min(50,z);k++)
            v.push_back(a[i]+b[j]+c[k]);
    for(int i=1;i<=min(50,x);i++)
        for(int j=201;j<=y;j++)
            for(int k=1;k<=min(50,z);k++)
            v.push_back(a[i]+b[j]+c[k]);
    for(int i=1;i<=min(50,x);i++)
        for(int j=1;j<=min(50,y);j++)
            for(int k=201;k<=z;k++)
            v.push_back(a[i]+b[j]+c[k]);
}
bool judge(ll p)
{
    int tot=0;
    for(int i=1;i<=x;i++)
        for(int j=1;j<=y;j++)
        {
            if(a[i]+b[j]+c[1]<p) break;
            for(int k=1;k<=z;k++)
            {
                if(a[i]+b[j]+c[k]<p) break;
                tot++;
                if(tot>=m) return true;
            }
        }
    return false;
}
void solve2()
{
    ll l=0,r=3e10,ans;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m)) ans=m,l=m+1;
        else r=m-1;
    }
    for(int i=1;i<=x;i++)
        for(int j=1;j<=y;j++)
        {
            if(a[i]+b[j]+c[1]<ans) break;
            for(int k=1;k<=z;k++)
            {
                if(a[i]+b[j]+c[k]<ans) break;
                v.push_back(a[i]+b[j]+c[k]);
            }
        }
}
void solve3()
{
    for(int i=1;i<=x;i++)
        for(int j=1;j<=y;j++)
            for(int k=1;k<=z;k++)
            if(i*j*k<=m) v.push_back(a[i]+b[j]+c[k]);
            else break;
}
struct node
{
    ll v;
    int i,j,k;
    node(ll v=0,int i=0,int j=0,int k=0):v(v),i(i),j(j),k(k){}
    bool operator<(const node&o)const
    {
        return v<o.v;
    }
};
priority_queue<node>q;
map<ll,bool>vis;
void solve4()
{
    q.push(node(a[1]+b[1]+c[1],1,1,1));
    for(int t=1;t<=m;t++)
    {
        node now=q.top();q.pop();
        v.push_back(now.v);
        int i=now.i,j=now.j,k=now.k;
        ll s=(ll)(i+1)*1000000+j*1000+k;
        if(!vis[s]&&i+1<=x)
            q.push(node(a[i+1]+b[j]+c[k],i+1,j,k)),vis[s]=true;
        s=(ll)i*1000000+(j+1)*1000+k;
        if(!vis[s]&&j+1<=y)
            q.push(node(a[i]+b[j+1]+c[k],i,j+1,k)),vis[s]=true;
        s=(ll)i*1000000+j*1000+k+1;
        if(!vis[s]&&k+1<=z)
            q.push(node(a[i]+b[j]+c[k+1],i,j,k+1)),vis[s]=true;
    }
}
int main()
{
    scanf("%d%d%d%d",&x,&y,&z,&m);
    for(int i=1;i<=x;i++)
        scanf("%lld",&a[i]);
    for(int i=1;i<=y;i++)
        scanf("%lld",&b[i]);
    for(int i=1;i<=z;i++)
        scanf("%lld",&c[i]);
    sort(a+1,a+1+x);
    sort(b+1,b+1+y);
    sort(c+1,c+1+z);
    reverse(a+1,a+1+x);
    reverse(b+1,b+1+y);
    reverse(c+1,c+1+z);
    //solve1();
    //solve2();
    //solve3();
    solve4();
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int i=0;i<m;i++)
        printf("%lld\n",v[i]);
}


Measured memory_bytes: 896
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;

	string S;
	cin >> S;

	S[K - 1] = S[K - 1] - 'A' + 'a';

	cout << S << "\n";

	return 0;
}

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

main()
{
	long long a,b,c;
	scanf("%lld %lld %lld",&a,&b,&c);
	if(a%2==0||b%2==0||c%2==0)
	{
		printf("0\n");
		return 0;
	}
	else
	{
		long long x=a*b,y=a*c,z=b*c;
		long long ans=min(x,y);
		ans=min(ans,z);
		printf("%lld\n",ans);
		return 0;
	}
}


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

using namespace std;

const int N = 1e5+100;

long long int dp[N], h[N];

int main () {
    memset(dp,63,sizeof(dp));
    long long int n, k;
    cin >> n >> k;
    for(int i = 1 ; i <= n ; i++ ) cin >> h[i];
    dp[1]=0;
    for(int i = 2 ; i <= n ; i++ ) {
        long long int t = k;
        for(int j = i - 1 ; j >= 1 && t > 0 ; j--, t--) {
            dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
        }
    }
    cout << dp[n] << '\n';
}


Measured memory_bytes: 1792
#define REP(i,n) for (int i=0;i<(n);i++)
#include <iostream>
#include <cmath>
using namespace std;

int main(){
        int n=0;
        while(cin>>n&&n>0){
                double a[n+1];
                REP(i,n+1){
                        switch(i){
                        case 0:
                                a[i] = 1;
                                break;
                        case 1:
                                a[i] = a[i-1];
                                break;
                        case 2:
                                a[i] = a[i-1] + a[i-2];
                                break;
                        default:
                                a[i] = a[i-1] + a[i-2] + a[i-3];
                                break;
                        }
                }
                cout << ceil(a[n] / 10 / 365) << endl;
        }
}

Measured memory_bytes: 1236
// Confessions of a Dangerous Mind

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 2e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 3e-16;

/*
	Keep moving forward. Take the Leap of Faith
*/

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
	
    long long n, m; cin >> n >> m;
    
    long long fr = 1, cnt = 0;
    while(fr < m){
    	fr += (n - 1);
    	cnt++;
    } 
    
    cout << cnt;
    
	return 0;
}

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

int main() {
	int q, query, i;
	cin >> q;
	bitset<64> a;
	for (int j = 0; j < q; ++j) {
		cin >> query;
		if (0 == query) {
			cin >> i;
			cout << a[i] << endl;
		}
		else if (1 == query) {
			cin >> i;
			a[i] = true;
		}
		else if (2 == query) {
			cin >> i;
			a[i] = false;
		}
		else if (3 == query) {
			cin >> i;
			a[i] = ~a[i];
		}
		else if (4 == query) cout << a.all() << endl;
		else if (5 == query) cout << a.any() << endl;
		else if (6 == query) cout << a.none() << endl;
		else if (7 == query) cout << a.count() << endl;
		else cout << a.to_ulong() << endl;
	}
}


Measured memory_bytes: 3096
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		HashMap<Integer,Integer> D = new HashMap<>();
		for (int i = 0; i < N; i++) {
			int d = in.nextInt();
			if(D.containsKey(d)){
				D.put(d, D.get(d)+1);
			}else{
				D.put(d, 1);
			}
		}
		int M = in.nextInt();
		for (int i = 0; i < M; i++) {
			int t = in.nextInt();
			if(!D.containsKey(t)){
				System.out.println("NO");
				return;
			}else{
				int count = D.get(t);
				if(count == 1){
					D.remove(t);
				}else{
					D.put(t, count - 1);
				}
			}
		}
		System.out.println("YES");
	}

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

Measured memory_bytes: 134336
#include<iostream>
#include<string>
using namespace std;
int main(){
long n,r,p,o,i;
string s;
cin>>n;
for(i=0;i<n;i++){
o=p=r=0;
while(cin>>s){
if(s=="HIT"){
r*=2;r++;if(r>=8){p++;r-=8;}
}else if(s=="HOMERUN"){
if(r==0)p++;
else if(r==1||r==2||r==4)p+=2;
else if(r==3||r==5||r==6)p+=3;
else if(r==7)p+=4;
r=0;
}else if(s=="OUT"){
o++;
if(o>=3)break;
}
}
cout<<p<<endl;
}
return 0;
}

Measured memory_bytes: 1208
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		input.nextLine();
		
		String[] user = input.nextLine().split(" ");
		String combined = "";
		
		for (int i = 0; i < user[0].length(); i++) {
			combined += user[0].charAt(i);
			combined += user[1].charAt(i);
		}
		
		System.out.println(combined);
	}
}


Measured memory_bytes: 21716
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);

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

    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if(s == "Cloudy") {
        cout << "Rainy" << endl;
    }
    else {
        cout << "Sunny" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  // ここでストリームに obj を書き込みます。
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}


int main(){
  map<int,int> mp;
  int n,m; cin >>n >>m;
  rep(i,n){
    int a; cin >>a;
    mp[a]++;
  }

  map<int,int> red,pr;
  for(pair<int,int> x: mp){
    pr[x.first%m]+=x.second/2;
    red[x.first%m]+=x.second;
  }
  int cnt=0;
  if(m%2==0){
    cnt+=red[m/2]/2;
    red[m/2]=0;
  }
  cnt+=red[0]/2;
  red[0]=0;
  rep(i,m/2){
    int a=min(red[i+1],red[m-i-1]);
    cnt+=a;
    red[i+1]-=a;
    red[m-i-1]-=a;
  }
  rep(i,m){
    cnt+=min(pr[i],red[i]/2);
  }
  print(cnt);
}



Measured memory_bytes: 14336
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    ll a,b; cin >>a>>b;
    if ((a * b) %  2 == 0 ) {
        cout << "Even" << endl;
    }  else {
        cout << "Odd" << endl;
    }

    return 0;
}




Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::cmp::{min, max};
use std::mem::swap;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin_lock = stdin.lock();
    let s = stdin_lock
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

static DX: &'static [i32] = &[0, 0, 1, -1];
static DY: &'static [i32] = &[1, -1, 0, 0];

fn main() {
    let n: i32 = read();
    let m: i32 = read();
    let x: usize = read();

    let a: Vec<usize> = (0..m).map(|_| read()).collect();

    let left_cnt = a.iter().filter(|i| **i < x).count();
    let right_cnt = a.iter().filter(|i| x < **i).count();

    println!("{}", min(left_cnt, right_cnt));
}

fn pow_mod(mut n: u64, mut exp: u64, m: u64) -> u64 {
    let mut t = 1;

    n %= m;

    while exp > 1 {
        if exp & 1 == 1 {
            t *= n;
            t %= m;
        }

        n *= n;
        n %= m;
        exp >>= 1;
    }

    (n * t) % m
}

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

int main() {
	// your code goes here
	int a, b, c, k;
	cin >> a >> b >> c;
	cin >> k;
	while(a >= b && k != 0){
		b *= 2;
		k--;
	}
	while(k != 0){
		c *= 2;
		k--;
	}
	
	if(c > b && b > a){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3636