akhauriyash/Code-Regression huggingface dataset:
//パーを出せるときは出す貪欲
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//#define int long long
using namespace std;

string s;

signed main() {
	int i;
	
	cin >> s;
	int diff = 0;
	int score = 0;
	
	for (i = 0; i < s.length(); i++) {
		if (diff > 0) {
			score += 1 - (s[i] == 'p');
			diff--;
		}
		else {
			score -= (s[i] == 'p');
			diff++;
		}
	}
	cout << score << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    ll d; cin >> d;
    d = d * d;
    int ans = 0;
    rep(i,n) {
        ll x, y; cin >> x >> y;
        ll dis = x*x + y*y;
        if (dis <= d) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>

#define MAX_N 100

int N;
int A[MAX_N];

void insertion_sort() {
    int min_j;
    int count=0;

    for (int i=0; i<N; i++) {
        min_j = i;
        for (int j=i; j<N; j++) {
            if (A[j] < A[min_j]) {
                min_j = j;
            }
        }
        if (A[i] != A[min_j]) {
            std::swap(A[i], A[min_j]);
            count++;
        }
    }

    for (int i=0; i<N-1; i++) std::cout << A[i] << ' ';
    std::cout << A[N-1] << std::endl;

    std::cout << count << std::endl;
}

int main() {
    std::cin >> N;
    for (int i=0; i<N; i++) std::cin >> A[i];

    insertion_sort();

    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
bool cmp(char a, char b)
{
	return a>b;
}
int main()
{
	string s, t;
	cin >> s >> t;
	sort (s.begin(), s.end());
	sort (t.begin(), t.end(), cmp);
	if (s<t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

using namespace std;
#define pi acos(-1)
#define _terminated return 0
#define endl "\n"
#define yes cout << "yes" << endl 
#define no cout << "no" << endl 
#define booster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<long> > v2l;

const int mod = 1e+5;
const int mx = 2e+5;
const ll inf = 1e18;

void upper_bubble_sort(){
     int i,j,temp,number_of_input;
     int array[100];
     cin >> number_of_input;
     for(i=0; i<number_of_input; i++)
         cin >> array[i];
         for(i=0; i<number_of_input; i++){
             for(j=0; j<(number_of_input-i-1); j++){
               if(array[j] > array[j+1]){
                 temp = array[j];
                 array[j] = array[j+1];
                 array[j+1] = temp;
                }
              }
         }
    for(i=0; i<number_of_input; i++)
      cout << array[i] << endl;
}
void bst(void){
          int low,high,mid,keynum,num,array[100];
          cin >> keynum;
          low = 1;
	         high = num;
         	do{
		        mid = (low + high) / 2;
		         if(keynum < array[mid])
			         high = mid - 1;
		         else if (keynum > array[mid])
			         low = mid + 1;
	         } 
          while (keynum != array[mid] && low <= high);
	        if(keynum == array[mid]){
            cout << "number located at " << mid +1 << endl;}
         else
           no;
        }

int solvio1(int p){
     while (p >= 10) 
     p /= 10; 
     return p; 
} 
void solve(){ 
    int N,P,i; 
    int ans = INT_MAX;
    cin >> N;
    int cnt = 0;
    for(i=0; i<N; i++){ 
       cin >> P; 
       if(P <= ans){ 
          ans = P; 
          cnt++; 
       } 
     } 
    cout << cnt << endl;
}
    
int main(){
    booster;
    solve();
    _terminated;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;


int q;
ll a, b, p, ans;
int main() {
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> a >> b;
        if (a > b)
            swap(a, b);
        if (a == b) {
            cout << (a - 1) * 2 << endl;
            continue;
        } else if (b - a == 1) {
            cout << (a - 1) * 2 << endl;
            continue;
        }

        p = a * b;

        ll l = 1, r = 1e9;
        while (l < r) {
            ll m = (r - l + 1) / 2 + l;
            if (m * m >= p) {
                r = m - 1;
            } else {
                l = m;
            }
        }
        if (l * (l + 1) >= p) {
            cout << 2 * l - 2 << endl;
        } else {
            cout << 2 * l - 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    
    char a[4];
    cin >>a[0]>>a[1]>>a[2]>>a[3];
    int sum = 0;
    for(int i=0;i<3;i++){
        if(a[i] == a[i+1]){
            sum++;
            //cout << sum;
        }
        else sum = 0;
        if(sum >= 2) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(sum >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
V = list(map(int, input().split()))
a = Counter(V[0::2]).most_common() + [(0,0)]
b = Counter(V[1::2]).most_common() + [(0,0)]
if a[0][0]!=b[0][0]:
    print(N-a[0][1]-b[0][1])
else:
    print(N-max(a[1][1]+b[0][1],a[0][1]+b[1][1]))

Measured memory_bytes: 20572
import sys
N = int(input())
li = [None] * N
for i in range(N):
  li[i] = list(map(int,input().split()))
li = sorted(li, key = lambda x:x[1])

t = 0
for l in li:
  t += l[0]
  if t > l[1]:
    print("No")
    sys.exit()
print("Yes")

Measured memory_bytes: 55252
#include <stdio.h>
#include <vector>
#include <queue>

using namespace std;

vector<int> edges[100001];
int distA[100001];
int distB[100001];

int main() {
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  for (int i = 0; i <= N; i++) {
    distA[i] = -1;
    distB[i] = -1;
  }

  queue<int> q;
  distA[1] = 0;
  q.push(1);
  while (!q.empty()) {
    int pos = q.front();
    q.pop();
    //    printf("dist A cur = %d\n", pos);
    for (int i = 0, ilim = edges[pos].size(); i < ilim; i++) {
      int next_pos = edges[pos][i];
      if (distA[next_pos] != -1) continue;
      distA[next_pos] = distA[pos] + 1;
      q.push(next_pos);
    }
  }

  distB[N] = 0;
  q.push(N);
  while (!q.empty()) {
    int pos = q.front();
    q.pop();
    for (int i = 0, ilim = edges[pos].size(); i < ilim; i++) {
      int next_pos = edges[pos][i];
      if (distB[next_pos] != -1) continue;
      distB[next_pos] = distB[pos] + 1;
      q.push(next_pos);
    }
  }

  int nearer_to_A = 0;
  for (int i = 1; i <= N; i++) {
    if (distA[i] <= distB[i]) {
      nearer_to_A++;
    }
  }
  
  if (nearer_to_A > N - nearer_to_A) {
    printf("Fennec\n");
  } else {
    printf("Snuke\n");
  }

  return 0;
}


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

const int max_n = 200005;
int a[max_n];
int main(){
    int n;
    cin >> n;
    bool fl=true;
    REP(i,n) {
        cin>>a[i];
        if(a[i]==1) fl=false;
    }
    if(fl){
        cout << -1 <<endl;
        return 0;
    }

    int ans = 0, num = 1;
    REP(i,n){
        if(a[i]==num) num++;
        else ans++;        
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
int main(){
	std::string sss;
	std::cin>>sss;
	int count;

	for (std::size_t i = 0;i < sss.size();i++){
		if(sss[i] == '1'){
			count += 1;
		}
	}
	std::cout<<count;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=998244353;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int32_t main()
{
    int n,m;
    cin>>n>>m;
    int ans=0;
    for(int i=1;i<=sqrt(m+0.5);i++)
    {
        if(m%i) continue;
        if(m/i>=n) ans=max(ans,i);
        if((m/(m/i))>=n) ans=max(ans,(m/i));
    }
    cout<<ans<<endl;
    return 0;
}


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

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
//#define int long long
template<class T, class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void println(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void){
    string s,t;cin>>s>>t;
    sort(all(s));sort(rall(t));
    if(s<t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


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

int main() {
  int N;
  string S, T;
  cin >> N >> S >> T;
  
  string ans = "";
  for (int i = 0; i < N; ++i) {
    ans += S[i];
    ans += T[i];
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  ll N;
  cin >> N;
  vl a(N);
  ll S = 0;
  rep(i, N){
    cin >> a[i];
    S += a[i];
  }

  ll c1 = S / N, c2 = S / N + 1;
  ll ans1 = 0, ans2 = 0;
  rep(i, N){
    ans1 += (a[i] - c1) * (a[i] - c1);
    ans2 += (a[i] - c2) * (a[i] - c2);
  }
  
  cout << min(ans1, ans2) << endl;  
  
  return 0;
}

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

int main(){
    int n,x,y,h,w;
    
    while(cin >> n,n){
        int tc = 0;
        while(n--){
            cin >> x >> y >> h >> w;
            
            int tc1 = 0,tc2 = 0,size = x+y+h;
            bool tf1 = false,tf2 = false;
            
            if(size <= 60) tc1 = 600;
            else if(size <= 80) tc1 = 800;
            else if(size <= 100) tc1 = 1000;
            else if(size <= 120) tc1 = 1200;
            else if(size <= 140) tc1 = 1400;
            else if(size <= 160) tc1 = 1600;
            else tf1 = true;
            
            if(w <= 2) tc2 = 600;
            else if(w <= 5) tc2 = 800;
            else if(w <= 10) tc2 = 1000;
            else if(w <= 15) tc2 = 1200;
            else if(w <= 20) tc2 = 1400;
            else if(w <= 25) tc2 = 1600;
            else tf2 = true;
            
            if(tf1||tf2) continue;
            else tc += max(tc1,tc2);
        }
        cout << tc << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main()
{
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	while (1) {
		C -= B;
		if (C <= 0) break;
		A -= D;
		if (A <= 0) break;
	}
	if (C <= 0) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1600
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
const ll maxn = 1e5+100,mod = 1e9+7,INF = 1ll<<62;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i%2==0){
			cout<<s[i];
		}
	}
}


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

using namespace std;

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

Measured memory_bytes: 3632
#include <iostream>
#include <math.h>

int main()
{
	double A, B,Amin,Bmin;
	int ans;
	std::cin >> A >> B;
	Amin = A *12.5;
	Bmin = B *10.0;
	if (Amin < Bmin) {
		if ((A + 1) * 12.5 > Bmin) {
			ans = ceil(Bmin); 
		}
		else {
			ans = -1;
		}
	}
	else {
		if ((B + 1) * 10.0 > Amin) {
			ans = ceil(Amin);
		}
		else {
			ans = -1;
		}
	}
    std::cout << ans;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	int a, b, c;
	while(scanf("%d %d", &a, &b) + 1){
		c = 1;
		for(int i = 1;i <= 8 ; i++){
			c *= 10;
			if(c > a + b){
				printf("%d\n", i);
				i += 8;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int d=sc.nextInt();
		if(d==22) {
		System.out.println("Christmas Eve Eve Eve");
		}
		if(d==23) {
			System.out.println("Christmas Eve Eve");
			}
		if(d==24) {
			System.out.println("Christmas Eve");
			}
		if(d==25) {
			System.out.println("Christmas");
			}

	}
}


Measured memory_bytes: 21332
#include <stdio.h>

int main(void)
{
	int min;
	int a[3];
	int h,i;
	int soeji;
	
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	
	for(h=0;h<3;h++)
	
	{
		min = 114514;
		
		for(i=0;i<3;i++)
		{
			if(min > a[i])
			{
				min = a[i];
				soeji = i;
			}
		}
	a[soeji] = 114514;
	
	printf("%d",min);
	if(h==0 || h==1)
	{
		printf(" ");
	}
	}
	printf("\n");
}

Measured memory_bytes: 2744
#include <cstdio>
#include <vector>
using namespace std;
vector<int>v[100005];
int n,m,a,b;
bool vis[100005];
void dfs(int x){
	if(vis[x])return;
	vis[x]=true;
	for(int i=0;i<v[x].size();++i)dfs(v[x][i]);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i){
		scanf("%d%d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int j=0;
	for(int i=1;i<=n;++i){
		if(!vis[i]){
			++j;
			dfs(i);
		}
	}
	printf("%d\n",j-1);
	return 0;
}


Measured memory_bytes: 9300
#include <iostream>
#include <string>

int main()
{
  std::string S,T="";
  std::cin>>S>>T;
  
  int A,B=0;
  std::cin>>A>>B;
  
  std::string U="";
  std::cin>>U;
  
  if(S==U)
  {
    A--;
  }
  else if(T==U)
  {
    B--;
  }
  
  std::cout<<A<<" "<<B<<std::endl;
  
  return 0;
}

Measured memory_bytes: 256
import sys

n, k = map(int, input().split())
ara = [0]
ara += list( map(int, input().split()) )

now = 1
vis = []
taken = [0]*(n+1)

while taken[now] == 0:
	vis.append(now)
	taken[now] = 1
	now = ara[now]

cycleLen = len(vis) - vis.index(now)

if k < vis.index(now):
	print(vis[k])
	sys.exit()

k -= vis.index(now)

k %= cycleLen

print(vis[k + vis.index(now) ])





Measured memory_bytes: 32320
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    char x,y,z;
    cin >> x >> y;
    if(x>y) z='>';
    else if(x<y) z='<';
    else z='=';
    cout << z << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-13
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.9lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0)
#define endl '\n'
using namespace std;
int s[10004];
int main()
{
    int n;
    cin>>n;
    int m=1000000000,t=0;
    for(int i=1;i<=n;i++){cin>>s[i];t+=s[i];if(s[i]%10!=0&&s[i]<m)m=s[i];}
    if(t%10==0)t=t-m;
    if(t%10==0)cout<<0<<endl;
    else cout<<t<<endl;







}




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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
ll X;
int main()
{
    cin >> X;
    ll A, B, A_MAX = 500;
    
    for (A = -A_MAX; A <= A_MAX; A++){
        for (B = -A_MAX; B <= A_MAX; B++){
            if (A * A * A * A * A - B * B * B * B * B ==  X){
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define big 998244353
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589
int power(int x,int y){
    int r=1,z=x;
    while(y){
        if(y & 1)r*=z;
        z*=z;y=y>>1;}
    return r;}
int powerm(int x,int y,int p){
    int r=1;
    while(y){
        if(y & 1)r=(r*x)%p;
        y=y>>1;
        x=(x*x)%p;}
    return r%p;}
int modinv(int x,int m){
    return powerm(x,m-2,m);}
int logarithm(int a,int b){
    int x=0;
    while(a>1){
        x++;
        a/=b;}
    return x;}
int32_t main(){
    fast;
    int n,m;
    cin>>n>>m;
    char mat[n][m];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>mat[i][j];
    int dp[n][m];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            if(i+j==0)
                dp[i][j]=1;
            else
                dp[i][j]=0;
            if(mat[i][j]=='#' || i+j==0)
                continue;
            dp[i][j]=0;
            if(i==0)
                dp[i][j]+=dp[i][j-1];
            else if(j==0)
                dp[i][j]+=dp[i-1][j];
            else
                dp[i][j]+=(dp[i-1][j]+dp[i][j-1]);
            dp[i][j]%=mod;

        }
    cout<<dp[n-1][m-1];
    return 0;
}

Measured memory_bytes: 12416
S = list(input())
A = list(reversed(S))
LEN=len(S)
ans=0
if LEN%2==0:
    for i in range(LEN//2):
        if S[i]!=A[i]:
            ans+=1
else:
    for i in range((LEN-1)//2):
        if S[i]!=A[i]:
            ans+=1
print(ans)

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

using namespace std;

int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  char S[100000], T[100000];
  scanf("%s%s", S, T);
  
  // 最大公約数を計算
  int g = __gcd(N, M);
  int stepS = N / g;
  int stepT = M / g;
  for (int i = 0; i < g; ++i) {
    if (S[stepS * i] != T[stepT * i]) {
      printf("-1");
      return 0;
    }
  }
  printf("%lld", 1ll * N / g * M);
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

typedef long long ll;

ll mod=1000000007ll;
ll f[2010101], rf[2010101];

ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
void init() {
	int i;
    f[0] = 1;
	for(i=1;i<2010101;i++){f[i] = (f[i - 1] * i) % mod;}
    rf[2010101 - 1] = inv(f[2010101 - 1]);
	for(i=2010101-2;i>=0;i--){
    rf[i] = (rf[i + 1] * (i + 1)) % mod;
	}
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
    if (k < 0 || n < k) return 0;

    ll a = f[n]; // = n!
    ll b = rf[n - k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * bc) % mod;
}

int main(){

	init();

	int H,W,A,B;

	scanf("%d %d %d %d",&H,&W,&A,&B);

	int i;

	ll ans=0ll;

	for(i=0;i<H-A;i++){
	ll add=C(B-1+i,B-1)*C(H-1-B+W-1-i,W-1-B);
	add%=mod;
	ans+=add;
	ans%=mod;
	}
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 31616
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner =new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        String sign=null;
        if(a<b){
            sign="<";
        }else if(a>b){
            sign=">";
        }else{
            sign="==";
        }
        System.out.println("a "+sign+" b");
    }
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    int n;
    string s;
    cin >> n >> s;
    YesorNo(s.substr(0,n/2) == s.substr(n/2));
}

Measured memory_bytes: 3708
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			a.begin(), a.end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define	MAX_QWORD		((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;

	map<char, int> mp;
	REP(i, N) {
		char a;
		cin >> a;
		mp[a]++;
	}

	if (mp.size() == 3)
		cout << "Three" << endl;
	else 
		cout << "Four" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
int main(){
 int n, m, p, acNum=0, waNum=0;
 string s;
 cin >> n >> m;
 int Wa[n] = {};
 bool N[n] = {};
 for(int i=0;i<m;i++){
  cin >> p >> s;
  if(N[p-1]==false){
    if(s=="AC"){
      acNum++;
      waNum += Wa[p-1];
      N[p-1] = true;
    }else{
      Wa[p-1]++;
    }
  } 
 }
 cout << acNum << " " << waNum << endl;
 return 0;
}


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

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < 100; i++){
	for(int j = 0; j < 100; j++){
      if(4 * i + 7 * j == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N, K, Q;
    cin >> N >> K >> Q;
    map<int, int> mp;

    for(int i = 1; i <= Q; i++) {
        int tmp = 0;
        cin >> tmp;
        if(mp.count(tmp)) {
            mp[tmp]++;
        } else {
            mp[tmp] = 1;
        }
    }

    for(int i = 1; i <= N; i++) {
        if(K - Q + mp[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 5376
import sys
from math import ceil

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    L = [INT() for _ in range(5)]

    idx = 0
    for i in range(5):
        idx = i if (L[i]-1)%10 < (L[idx]-1)%10 else idx

    for i in range(5):
        if i != idx: L[i] = ceil(L[i]/10) * 10

    print(sum(L))


if __name__ == '__main__':
    main()

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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((a+b)>(c+d))cout<<"Left"<<endl;
	else if((a+b)<(c+d))cout<<"Right"<<endl;
	else cout<<"Balanced"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,ll,ll> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> P;
int n;
ll m;
int primecount[100005];
int main(void)
{
  memset(primecount,0,sizeof(primecount));
  cin >> n >> m;
  ll ans=-1;
  ll memory=-1;
  ll savem=m;
  vector<ll> primes;
  if(m%n==0)
    {
      cout << m/n << endl;
      return 0;
    }
  else
    {
      primes.push_back(1);
      for(ll i=1;i*i<=m;i++)
	{
	  if(m%i==0)
	    {
	      primes.push_back(i);
	      if(i!=1 && i*i!=m)
		{
		  primes.push_back(m/i);
		}
	    }
	}
      sort(primes.begin(),primes.end());
      for(int i=0;i<primes.size();i++)
	{
	  if(savem/primes[i]>=n)
	    {
	      ans=max(ans,primes[i]);
	    }
	}
      cout << ans << endl;
    }
      /*for(int i=2;i<=int(sqrt(m))+2;i++)
	{
	  while((m%i)==0)
	    {
	      m/=i;
	      primecount[i]+=1;
	    }
	}
      if(m>1)
	{
	  memory=m;
	}
      for(int i=2;i<=int(sqrt(m))+2;i++)
	{
	  m=savem;
	  if(primecount[i]!=0)
	    {
	      ll tmp=1;
	      while(primecount[i]>0)
		{
		  tmp*=i;
		  primecount[i]--;
		  m/=i;
		  if(m>=n) ans=max(tmp,ans);
		}
	    }
	    }*/
  return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)

typedef pair<int, int> P;


int main() {
    ll a,b,c,k; cin >> a >> b >> c >> k;

    ll ans = 0;
    if(k <= a) {
        cout << k << endl;
        return 0;
    } else {
        k -= a;
        ans += a;
    }

    if(k <= b) {
        cout << ans << endl;
        return 0;
    } else {
        k -= b;
    }

    cout << ans - k << endl;

    return 0;
}

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

using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = 0;
    ans += min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    ans -= min(c, k);

    cout << ans;

    return 0;
}


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

int sum(int x){
  if(x < 10)
    return x;
  
  return x%10 + sum(x/10);
}

int main(){
  int n;
  cin >> n;
  
  int s = sum(n);
  
  if(n%s == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

npA = np.array(A)
max_number = max(A)
max_itr = np.where(npA == npA.max())
if len(max_itr[0]) == 1:
  for i in range(N):
    if i != max_itr[0][0]:
      print(max_number)
    else:
      print(sorted(A)[-2])
else:
  for i in range(N):
    print(max_number)

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

l = max(a)
r = 0
d = 10**9
for i in range(n):
    if (l == a[i]):
        continue
    tmp = abs(l - 2*a[i])
    if (tmp < d):
        r = a[i]
        d = tmp

print("{0} {1}".format(l, r))


Measured memory_bytes: 14432
#include <iostream>
#include <string>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int i, j, k, l;
int H, W, N, Q;
int a, b, c;

int main()
{
	cin >> a >> b >> c;

	if (a >= b&&a >= c)
	{
		cout << b + c << endl;
	}
	else if (b > c)
	{
		cout << a + c << endl;
	}
	else
	{
		cout << a + b << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    
    int a,b,c;
    int count = 0;
    
    std::cin >> a >> b >> c;
    for(int i = a; i <= b; i ++){
        if(c % i == 0) count += 1;
    }

    std::cout << count << "\n";
    
    return 0;
}



Measured memory_bytes: 3112
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define MN 100005
using namespace std;
int n,tt,a[MN],num[MN],tmp[MN],tmpx[MN];
long long tx;
void mergesort(int ll,int rr){
	if(ll==rr)return;
	int mid=(ll+rr)>>1;
	mergesort(ll,mid),mergesort(mid+1,rr);
	int tl=ll,tr=mid+1,now=0;
	while(tl<=mid&&tr<=rr){
		if(tmp[tl]<tmp[tr])tmpx[++now]=tmp[tl++];
		else {
			tx+=tl-ll;
			tmpx[++now]=tmp[tr++];
		}
	}
	while(tl<=mid)tmpx[++now]=tmp[tl++];
	while(tr<=rr)tx+=tl-ll,tmpx[++now]=tmp[tr++];
	for(int i=ll,j=1;i<=rr;i++,j++)tmp[i]=tmpx[j];
}
bool check(int mid){
	for(int i=1;i<=n;i++)
		tmp[i]=tmp[i-1]+(a[i]<=mid?1:-1);
	tx=0;mergesort(0,n);
	return tx>=(1ll*n*(n+1)/4+1);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),num[++tt]=a[i];sort(num+1,num+tt+1);tt=unique(num+1,num+n+1)-num;
	int l=1,r=tt-1,ans=tt-1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(num[mid]))ans=mid,r=mid-1;
		else l=mid+1;
	}printf("%d\n",num[ans]);
}

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

#define ll long long
#define ld long double
#define ff first
#define ss second
#define eps 1e-9
#define pi acos(-1.0)
#define all(v) v.begin(),v.end()

#define MAX 500005

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

    ll n;
    cin >> n;

    ll a[n];

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

    ll stool=0;
    for(int i=1;i<n;i++)
    {
        if(a[i-1]<=a[i]) continue;
        stool+= a[i-1]-a[i];
        a[i] = a[i-1];
    }

    cout << stool << endl;

    return 0;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef vector<vector<int>> Matrix;

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

int main(){
    string  x;
    cin >> x;
	if(x == "ABC"){
    	cout << "ARC" << endl;
    }
  	else{
      cout << "ABC" << endl;
 	 }

    

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<long long>;
using vvi=vector<vector<long long>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000009;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}

int main(){
  int n,q;cin>>n>>q;
  int ans =0;
  string s;cin>>s;
  rep(i,n-1){
    if(s[i]=='A'&&s[i+1]=='C')s[i]='a';
  }
  vi v(n);
  v[0]=0;
  for(int i=1;i<n;i++){
    v[i]=v[i-1];
    if(s[i-1]=='a')v[i]++;
  }
  rep(i,q){
    int l,r;cin>>l>>r;
    l--;r--;
    cout<<v[r]-v[l]<<endl;
  }
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#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;}()
typedef long long ll;
typedef pair<int, int> 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;}

int main(){
    int a,b;
    cin >> a >> b;
    put((a+b+1)/2);
    return 0;
}


Measured memory_bytes: 256
def innerProduct(v, u):
    return sum(x * y for (x, y) in zip(v, u))

if __name__ == "__main__":
    n, m = map(int, input().split())
    point_list = [tuple(int(s) for s in input().split()) for i in range(n)]
    operations = [
            (-1, -1, -1),
            (-1, -1,  1),
            (-1,  1, -1),
            (-1,  1,  1),
            ( 1, -1, -1),
            ( 1, -1,  1),
            ( 1,  1, -1),
            ( 1,  1,  1),
            ]

    result = max(sum(sorted([innerProduct(t, ope) for t in point_list], reverse=True)[:m]) for ope in operations)
    print(result)


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

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

  // ここにプログラムを追記
  bool flg = false;
  for ( int i = 0; i < N; i++ ) {
    char S;
    cin >> S;
    
    if ( S == 'Y' ) {
      flg = true;
      break;
    }
  }
  
  if ( flg ) cout << "Four" << endl;
  else cout << "Three" << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCALc
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, l, r, f, t;
vpi a;
int main() {
	doin();
	cin >> n >> m;
	l = 0;
	r = n;
	for (int i = 0; i < m; i++) {
		cin >> f >> t;
		l = max(l, f);
		r = min(r, t);
	}
	if(r<l) cout << 0;
	else cout << (r-l+1);
}


Measured memory_bytes: 256
#include <stdio.h>
int array1[100010]={0},array2[100010]={0};
int main()
{   array1[2]=1;
    for(int i=3;i<=100000;i+=2){
    if(i%2==0){continue;}
    int flag=0;
    for(int j=2;j*j<=i;j++){
        if(i%j==0){
            flag=1;
            continue;
            }
        }
        if(flag)continue;
        array1[i]=1;
    }
    for(int i=3;i<=100000;i+=2){
        if(array1[i]&&array1[(i+1)/2]){
            array2[i]=array2[i-2]+1;
        }else{
            array2[i]=array2[i-2];
        }
    }
    /*for(int i=1;i<100;i+=2){
        printf("i=%d %d\n",i,array2[i]);
    }*/
    int q;
    scanf("%d",&q);
    int l[q],r[q];
    for(int i=0;i<q;i++){
        scanf("%d%d",&l[i],&r[i]);
        printf("%d\n",array2[r[i]]-array2[l[i]-2]);
    }
    
    
    return 0;
}


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

int main(){
  int n,m,l;
  cin >> n >> m >> l;
  int** A = new int*[n];
  for(int i=0;i<n;i++) A[i] = new int[m];
  int** B = new int*[m];
  for(int i=0;i<m;i++) B[i] = new int[l];
  long long int** C = new long long int*[n];
  for(int i=0;i<n;i++) C[i] = new long long int[l]();

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> A[i][j];
    }
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<l;j++){
      cin >> B[i][j];
    }
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      for(int k=0;k<m;k++){
        C[i][j] += A[i][k] * B[k][j];
      }
      if(j != l-1) cout << C[i][j] << ' ';
      else cout << C[i][j] << endl;
    }
  }
}


Measured memory_bytes: 3228
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N, A, B;
  cin >> N >> A >> B;
  long foo = min(A, B);
  long bar = max(0l, A + B - N);
  cout << foo << " " << bar << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

t = [0 for i in range(N)]
t[1] = abs(h[1] - h[0])

for i in range(2, N):
  t[i] = min(t[i-2] + abs(h[i-2] - h[i]), t[i-1] + abs(h[i-1] - h[i]))

print(t[N-1])


Measured memory_bytes: 13928
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := newIo()
	defer io.Flush()
	N, K := io.NextInt(), io.NextInt()
	Xplus := []int{}
	Xminus := []int{}
	for i := 0; i < N; i++ {
		x := io.NextInt()
		if x < 0 {
			Xminus = append(Xminus, -x)
		} else if x == 0 {
			K--
		} else {
			Xplus = append(Xplus, x)
		}
	}
	if K == 0 {
		fmt.Println(0)
		return
	}
	if K == 1 {
		result := Xplus[0]
		if Xminus[0] < result {
			result = Xminus[0]
		}
		fmt.Println(result)
		return
	}
	if len(Xminus) > K {
		Xminus = Xminus[len(Xminus)-K:]
	}
	if len(Xplus) > K {
		Xplus = Xplus[0:K]
	}
	if len(Xminus) == 0 {
		fmt.Println(Xplus[K-1])
		return
	}
	if len(Xplus) == 0 {
		fmt.Println(Xminus[0])
		return
	}
	X := append(Xminus, Xplus...)
	result := X[0] + X[K-1] + int(math.Min(float64(X[0]), float64(X[K-1])))
	log("fresult", result)
	for i := 0; i < len(X)-(K-1); i++ {
		a := X[i]
		b := X[i+(K-1)]
		var r int
		if a < b {
			r = 2*a + b
		} else {
			r = 2*b + a
		}
		if r < result {
			result = r
		}
	}
	fmt.Println(result)
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
//#define random_shuffle(r...)random_shuffle(r,[](int _){return my_rand()%_;})

int main(){

 ll x,y;
  cin>>x>>y;

  ll ans = 0,i=1;

   while(x <= y){

     ans++;
     x *= 2;
   }

   cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 3636
#include <cmath>
#include <cstdio>

using namespace std;

double det(int a, int b, int c, int d) {
  return a * d - b * c;
}

int main() {
  int a, b, c, d, e, f;
  while (scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f) == 6) {
    double x = det(c, b, f, e) / det(a, b, d, e),
           y = det(a, c, d, f) / det(a, b, d, e);
    if (x <= 0.0 && x >= -0.0009) x = 0.0;
    if (y <= 0.0 && y >= -0.0009) y = 0.0;
    printf("%.3f %.3f\n", x, y);
  }
  return 0;
}

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

vector<int> sieve(int n) {
  vector<int> p(n);
  for(int i=2; i<n; i++) p[i]=i;
  for(int i=2; i*i<n; i++) {
    if(p[i]) {
      for(int j=i*i; j<n; j+=i) p[j]=0;
    }
  }
  return p;
}

int main() {
  vector<int> p=sieve(25);
  for(int i=1; i<13; i++) p[i]=0;
  int z=1;
  for(int i=1; i<25; i++) {
    if(!p[i]) z=z*i/__gcd(i,z);
  }
  int n;
  while(cin >> n && n) {
    vector<vector<int> > v[25];
    for(int i=0; i<n; i++) {
      int m,t;
      cin >> m >> t;
      vector<int> a(m);
      for(int j=0; j<m; j++) cin >> a[(j-t+m)%m];
      v[m].push_back(a);
    }
    int ans=0;
    for(int l=0; l<z; l++) {
      int d=0;
      for(int i=1; i<25; i++) {
        if(p[i]) continue;
        for(int j=0; j<v[i].size(); j++) d+=v[i][j][l%v[i][j].size()];
      }
      ans=max(ans,d);
    }
    for(int i=1; i<25; i++) {
      if(!p[i]) continue;
      int M=0;
      for(int k=0; k<i; k++) {
        int sum=0;
        for(int j=0; j<v[i].size(); j++) sum+=v[i][j][k];
        M=max(M,sum);
      }
      ans+=M;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

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

  vector<queue<int>> A(N, queue<int>());
  rep(i, N) rep(j, M) {
    int a; cin >> a;
    A[i].push(a);
  }

  set<int> used;
  int ans = N;
  rep(i, M) {
    map<int, int> count;
    rep(j, N) {
      while (!A[j].empty() && used.find(A[j].front()) != used.end())
        A[j].pop();
      ++count[A[j].front()];
    }
    int max_count = 0, max_num;
    for (const auto& e : count) {
      int num = e.first, count = e.second;
      if (chmax(max_count, count))
        max_num = num;
    }
    chmin(ans, max_count);
    used.insert(max_num);
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    int64_t x = 0;
    for(int i=0; i<N; i++) {
        x += A[i] * (1 - i%2*2);
    }
    cout << x << ' ';

    for(int i=1; i<N; i++) {
        x = -x;
        x += 2 * A[i-1];
        cout << x << ' ';
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &out, const vector<int> &b) {
    for (auto k : b) out << k << " ";
    return out;
}

istream& operator>> (istream& in, pii& b) {
    in >> b.first >> b.second;
    return in;
}

ostream& operator<< (ostream& out, const pii& b) {
    out << "{" << b.first << ", " << b.second << "}";
    return out;
}

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
#else
    #define dbg(x) 57
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
#endif

const ld PI = acos(-1);

#define time clock() / (double) CLOCKS_PER_SEC

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int x = 1;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == x) {
            x++;
            continue;
        }
        ans += (a[i] - 1) / x;
        if (x == 1) x++;
    }
    cout << ans << "\n";
}
/*

*/

Measured memory_bytes: 3996