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

void print(int a, int b, string str)
{
    for(int i=a;i<=b;i++)
    {
        cout << str[i];
    }
    cout << endl;
    return;
}

string reverse(int a, int b, string str)
{
    int left = a, right = b;
    while(left<right)
    {
        swap(str[left++],str[right--]);
    }
    return str;
}

string replace(int a, int b, string p, string str)
{
    for(int i=0;i<b-a+1;i++)
    {
        str[a+i] = p[i];
    }
    return str;
}

int main()
{
    string str, p, command;
    int q, a, b;
    
    cin >> str >> q;
    for(int i=0;i<q;i++)
    {
        cin >> command >> a >> b;
        if(command == "print") {
            print(a, b, str);
        } else if(command == "reverse") {
            str = reverse(a, b, str);
        } else if(command == "replace") {
            cin >> p;
            str = replace(a, b, p, str);
        }
    }
    
    return 0;
}



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


int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll ans = 0;
    if( (a%2==0) || (b%2==0) || (c%2==0)){
        ans = 0;
    }
    else{
        ans = min(a*b,min(b*c,c*a));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3532
s = input()
s_len = len(s)
li = [0]*(s_len+1)
for i in range(0,s_len):
    if s[i] == "<":
        if li[i] >= li[i+1]:
            li[i+1] = li[i] + 1
for i in range(s_len-1,-1,-1):
    if s[i] == ">":
        if li[i] <= li[i+1]:
            li[i] = li[i+1]+1
print(sum(li))

Measured memory_bytes: 46448
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;

int main(){
  int N; cin >> N;
  vector<int> A(N);
  rep(i,N){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  rep(i,N-1){
    if(A[i] == A[i+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024
n = 0
dat = []


def input_file():
    global n, dat
    f = open('input', mode='r')
    n = int(f.readline())
    # min = 2e10
    # max = -1
    # print(min)
    for _ in range(n):
        i = int(f.readline())
        dat.append(i)

    # print(max - min)


def input_cmd():
    global n, dat
    n = int(input())
    for _ in range(n):
        dat.append(int(input()))


input_cmd()
# input_file()

# p = -2e10
# for i in range(n):
#     for j in range(i + 1, n):
#         r = dat[j] - dat[i]
#         if r > p:
#             p = r
minV = dat[0]
maxV = -2e10
for i in range(1, n):
    r = dat[i] - minV
    maxV = r if r > maxV else maxV
    minV = dat[i] if dat[i] < minV else minV
print(maxV)



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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    unsigned long N, K;
    cin >> N >> K;
    vector<unsigned long> dp(K + 1);
    dp[0] = 1;
    for(unsigned long i{0}, a; i < N; ++i){
        cin >> a;
        for(unsigned long j{K}; j > a; --j)dp[j] += dp[j] > dp[j - a - 1] ? -dp[j - a - 1] : MOD - dp[j - a - 1];
    }
    for(unsigned long i{0}; i < N; ++i)partial_sum(dp.begin(), dp.end(), dp.begin(), [](auto i, auto j){return (i + j) % MOD;});
    cout << dp.back() << endl;
    return 0;
}

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

 int main (void) {
    int a,b,c;
    int d;
    
    d = scanf("%d %d %d",&a,&b,&c);
    
    if(a,b,c<1 || a,b,c>100){
      printf("1~100以外の整数は入力しないでください\n");
      exit(0);
      }
      
    if(b-a==c-b){
    printf("YES\n");
    return 0;
    }else{
    printf("NO\n");
    return 0;
    }
   }
    
    
     
      
      
     

Measured memory_bytes: 128
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

w,a,b = inpl()
if a<b:
    print(max(0,b-(a+w)))
else:
    print(max(0,a-(b+w)))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 string S;
  cin>>S;
  string x=S;
  reverse(all(x));
  if(x!=S) {
cout<<"No"<<endl;
  return 0;
  }
  ll N=S.size()/2;
  for(ll i=0;i<N/2;i++) {
if(S[i]!=S[N-1-i]) {
cout<<"No"<<endl;
return 0;
}
  }
  
  
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    ll x, y, Xor = 0;
    cin >> x >> y;
    for(int i = 0; i < n - 2; i++) {
        ll z;
        cin >> z;
        Xor ^= z;
    }
    if(x + y < Xor) {
        cout << -1 << endl;
        return 0;
    }
    ll And = x + y - Xor;
    if(And % 2) {
        cout << -1 << endl;
        return 0;
    }
    And >>= 1;
    if(Xor & And){
        cout << -1 << endl;
        return 0;
    }
    ll ans = And;
    for(ll b = 1ll << 40; b >= 1; b >>= 1) {
        if(Xor & b && ans + b <= x) ans += b;
    }
    if(ans == 0 || ans > x) {
        cout << -1 << endl;
        return 0;
    }
    cout << x - ans << endl;
    return 0;
}

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

int check_prime(int input){
  int check = 1;
 int m = sqrt((double)input);
  //cout << m << endl;
  int tmp = m;
  while(tmp > 1){
    if(input % tmp == 0){
      check = 0;
      break;
    }
    tmp--;    
  }
  
  return check;
}

int main(void){
  int A;
  cin >> A;
  while(check_prime(A) == 0){
    A++;
  }
  cout << A << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    cout << (1000-N%1000)%1000 << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int n; cin >> n;
  ll A = 1, B = 1;
  rep(i,n) {
    ll a, b; cin >> a >> b;
    ll x = max((A+a-1)/a,(B+b-1)/b);
    A = a * x; B = b * x;
    // cout << "\t" << a << ", " << b << endl;
  }
  cout << A + B << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int s; cin >> s;
    int L = s / 100;
    int R = s % 100;
    bool LisOK = 0;
    bool RisOK = 0;
    if(L <= 12 && L >= 1) LisOK = 1;
    if(R <= 12 && R >= 1) RisOK = 1;
    if(RisOK && LisOK) cout << "AMBIGUOUS" << endl;
    else if(RisOK && !LisOK) cout << "YYMM" << endl;
    else if(!RisOK && LisOK) cout << "MMYY" << endl;
    else cout << "NA" << endl;

}

Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    
    if n == 1:
        print('Hello World')
    else:
        a = i_input()
        b = i_input()
        print(a+b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 58860
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

double P[10], Q[10];

double f(double a) {
	double ans = 1 - a;
	rep(i, 0, 6) {
		ans += max(0.0, (P[i] + Q[i]) * a - Q[i]);
	}
	return ans;
}

void solve() {
	rep(i, 0, 6) {
		int a; cin >> a;
		P[i] = a / 100.0;
	}
	rep(i, 0, 6) {
		int a; cin >> a;
		Q[i] = a / 100.0;
	}
	double ans = min(f(0), f(1));
	rep(i, 0, 6) {
		ans = min(ans, f(Q[i] / (P[i] + Q[i])));
	}
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b;
    while(scanf("%d %d",&a,&b)==2){
        if((a==1||a==3||a==5||a==7||a==8||a==10||a==12) && (b==1||b==3||b==5||b==7||b==8||b==10||b==12)){
            printf("Yes\n");
        }
        else if((a==4||a==6||a==9||a==11) && (b==4||b==6||b==9||b==11)){
            printf("Yes\n");
        }
        else if(a==2 && b==2){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }
    return 0;
 }

Measured memory_bytes: 128
class Main{
    public static void main(String[] a){
    int x;
    int i;
    int j;
for ( i=1;i<10;i++)
   for( j = 1; j<10; j++)
   {x = i*j;
   System.out.println( i +"x"+ j +"="+ x );}
    }
}

Measured memory_bytes: 24192
H,W,A,B=map(int,input().split())
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
def kumi(h,w,a):
    a[0]=1
    #print(a)
    for i in range(1,h):
        b=a[i-1]*(w+i)%(10**9+7)
        a[i]=b*mod_inv(i,10**9+7)
        #print(a)
    return a
f=[0]*(H-A)
s=[0]*(H)
f=kumi(H-A,B-1,f)
s=kumi(H,W-B-1,s)
"""print(f)
print(s)"""
ans=0
for i in range(H-A):
    ans+=f[i]*s[-i-1]
print(ans%(10**9+7))
"""ans=0
for i in range(H-A):
    #print(cmb(i+B-1,B-1)%(10**9+7),cmb(H-i+W-B-2,W-B-1)%(10**9+7))
    ans+=cmb(i+B-1,B-1)*cmb(H-i+W-B-2,W-B-1)%(10**9+7)
print(ans%(10**9+7))"""


Measured memory_bytes: 59408
/* Author : tushar3105 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef pair<long long int,long long int> ii;					// Pair of integers
typedef vector<long long int> vi;                   				// Vector of integers
typedef vector<vector<long long int>> vvi;                 			// Vector of vi
typedef vector<pair<long long int, long long int>> vii;				// Vector of ii

#define pb push_back								// Push back to vectors
#define mp make_pair								// For pairs
#define ff first								// For pairs
#define ss second								// For pairs
#define all(c) (c).begin(),(c).end()						// Use in sorting
#define sz(a) ((long long int)(a).size())
#define lli long long int
#define ull unsigned long long int
#define ld long double
#define ref(i,x,y) for(long long int i=(x);i<=(y);++i)				// Loop to go forward
#define reb(i,x,y) for(long long int i=(x);i>=(y);--i)				// Loop to go backward
#define trf(c,it) for(auto it = (c).begin(); it != (c).end(); it++)		// Remember it is an iterator
#define trb(c,it) for(auto it = (c).end()-1; it != (c).begin()-1; it--)		// Remember it is an iterator
#define tc(t) long long int (t); cin>>(t);while((t)--)				// Test cases
//fill (dist,dist+110000,pinf);							// For setting default

const long long int mod = 1e9+7;
const long long int pinf = 9223372036854775807;
const long long int ninf = -9223372036854775807;

/*-----------------------------Code begins----------------------------------*/

int main (void)
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif

	lli x,y,a,b,c;

	lli red[110000], green[110000], cl[110000];

	cin>>x>>y>>a>>b>>c;

	ref(i,0,a-1)
		cin>>red[i];

	ref(i,0,b-1)
		cin>>green[i];

	ref(i,0,c-1)
		cin>>cl[i];

	sort(red,red+a);
	sort(green,green+b);
	sort(cl,cl+c);

	lli final[210000], top=0;

	reb(i,a-1,a-x)
		final[top++]=red[i];

	reb(i,b-1,b-y)
		final[top++]=green[i];

	sort(final, final+top);
	lli end=c-1, sum=0;

	ref(i,0,top-1)
	{
		if (end>=0)
		{
			if (final[i]<cl[end])
			{
				final[i]=cl[end];
				end--;
			}
		}

		sum=sum+final[i];
	}

	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int a[200006];
int main () {
    int N, sum=0;
    cin >> N;
    for (int i=0; i<N; i++) {
        cin >> a[i];
        sum^=a[i];
    }
    for (int i=0; i<N; i++) {
        cout << (sum^a[i]) << endl;
    }
}

Measured memory_bytes: 4400
n,k = map(int, input().split())
p = list(map(int, input().split())) 
c = list(map(int, input().split()))
r = -10**9
for i in range(n):
  ans=c[i]
  e =[ans]
  f = i
  a = 1
  while a<k:
    i = p[i]-1
    if i == f:
      break
    a+=1
    ans+=c[i]
    e.append(ans)
  if e[-1]>0 and a<k:
    w = k%len(e)
    if w!=0:
      y = k//len(e)*e[-1]+max(e[:w])
    else:
      y =( k//len(e)-1)*e[-1]+max(e)
    g=y
  else:
    g=max(e)
  r = max(r,g)
print(r)

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

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





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e4 + 10;
const int inf = 1e9;
const int N = 5000;

int n;
vector<int> g[maxn];
int x[maxn];
int dpBlack[maxn], dpWhite[maxn];

void relax(int &x, int y) {
    x = min(x, y);
}

void print(vector<int> dp) {
    for (int i=0; i<=5; i++) cout<<dp[i]<<" ";
    cout<<endl;
    
}
bool dfs(int at) {

    for (int to: g[at]) {
	if (!dfs(to)) {
	    return false;
	}
    }
	

    // assume we are black
    {
	vector<int> dp(N+10, inf); //dp[black]=minWhiteSum
	dp[0] = 0;

	for (int to: g[at]) {
	    vector<int> ndp(N+10, inf);
	    // to is black
	    for (int i=N-x[to]; i>=0; i--) {
		relax(ndp[i+x[to]], dp[i]+dpBlack[to]);
	    }
	    // to is white
	    for (int i=N-dpBlack[to]; i>=0; i--) {
		relax(ndp[i+dpBlack[to]], dp[i]+x[to]);
	    }
	    swap(ndp, dp);
	}


	dpBlack[at] = inf;
	for (int i=0; i<=x[at]; i++) {
	    relax(dpBlack[at], dp[i]);
	}
    }

    // assume we are white
    {
	vector<int> dp(N+10, inf); //dp[white]=minBlackSum
	dp[0] = 0;
	
	for (int to: g[at]) {
	    vector<int> ndp(N+10, inf);
	    // to is white
	    for (int i=N-x[to]; i>=0; i--) {
		relax(ndp[i+x[to]], dp[i]+dpWhite[to]);
	    }
	    // to is black
	    for (int i=N-dpWhite[to]; i>=0; i--) {
		relax(ndp[i+dpWhite[to]], dp[i]+x[to]);
	    }
	    swap(ndp, dp);
	}
	
	dpWhite[at] = inf;
	for (int i=0; i<=x[at]; i++) {
	    relax(dpWhite[at], dp[i]);
	}
    }

    return dpBlack[at]<inf/2 || dpWhite[at]<inf/2;
}

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

    cin>>n;
    for (int i=2; i<=n; i++) {
	int p;
	cin>>p;
	g[p].push_back(i);
    }

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

    bool ok = dfs(1);


    // for (int i=1; i<=n; i++) {
    // 	watch(i);
    // 	cout<<dpBlack[i]<<"  "<<dpWhite[i]<<endl;
    // }
    
    cout<<(ok ? "POSSIBLE\n" : "IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=15;
int a[maxn];
int main()
{
    for(int i=1;i<=3;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+3+1);
    int f=1;
    for(int i=1;i<=3;i++)
    {
        if(i<=2&&a[i]!=5) f=0;
        if(i==3&&a[i]!=7) f=0;
    }
    if(f)
        puts("YES");
    else
        puts("NO");
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		for(int i=n-1; i>=0; i--){
			System.out.print(a[i]);
			if(i!=0){
				System.out.print(" ");
			}else{
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 26072
#include <iostream>
using namespace std;
 
int main() {
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long res = 0;
  if (K <= A) {
    res = K;
  } else {
    res += A;
    K -= A;
    if (K <= B) {
      res += K * 0;
    } else {
      res += B * 0;
      K -= B;
      if (K <= C) {
        res += K * -1;
      } else {
        res += C * -1;
      }
    }
  }
  cout << res << endl;
}

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

int main(void) {
  int n;
  while (1) {
    cin >> n;
    if (n == 0) break;
    int count = 0;
    while (n != 1) {
      if (n % 2 == 0) {
        n /= 2;
      } else {
        n = n * 3 + 1;
      }
      count++;
    }
    cout << count << endl;
  }

  return 0;
}

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

int N, K;
vector<int> a;

vector<vector<int>> dp;
vector<int> pref_sum;

const int MOD = 1e9 + 7;

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

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

    dp.resize(N, vector<int>(K + 1));
    for (int i = 0; i <= a[0]; ++i) {
        dp[0][i] = 1;
    }

    pref_sum.resize(K + 2);
    for (int i = 1; i < N; ++i) {
        for (int j = 0; j <= K; ++j) {
            pref_sum[j + 1] = (pref_sum[j] + dp[i - 1][j]) % MOD;
            dp[i][j] = (pref_sum[j + 1] - pref_sum[j - min(j, a[i])]) % MOD;
            dp[i][j] = dp[i][j] < 0 ? dp[i][j] + MOD : dp[i][j];
        }
    }

    cout << dp[N - 1][K];
}


Measured memory_bytes: 39808
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const double EPS = 1e-6;

int main(void) {
	int N;
	while (cin >> N, N) {;
		vector<string> F(N);
		VI W(N), S(N);
		for (int i = 0; i < N; i++) {
			cin >> F[i] >> W[i] >> S[i];
		}

		VI p(N);
		iota(p.begin(), p.end(), 0);

		double ans = 1e+8;
		VI best_p(p.begin(), p.end());

		do {
			double g = 0, gt = 0;
			for (int i = 0; i < N; i++) {
				g += (i + 1) * W[p[i]];
				gt += W[p[i]];
			}
			g /= gt;

			if (g - EPS > ans) {
				continue;
			}

			bool flg = true;
			for (int i = N - 1; i >= 0; i--) {
				int sum = 0;
				for (int j = i + 1; j < N; j++) {
					sum += W[p[j]];
				}
				flg &= sum <= S[p[i]];
			}

			if (flg && g < ans + EPS) {
				ans = g;
				swap(best_p, p);
			}
		} while (next_permutation(p.begin(), p.end()));

		for (auto i : best_p) {
			cout << F[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1208
n,a,b=map(int,input().split())
s=input()
"""
10 2 3
abccabaabb
->
Yes
Yes
No
No
Yes
Yes
Yes
No
No
No

12 5 2
cabbabaacaba
->
No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
No
No
"""
n_pass=0
n_fpass=0
ans=[]
for _ in range(n):
    if s[_] == 'a' and n_pass < a+b:
        n_pass+=1
        ans.append('Yes')
    elif s[_] == 'b' and n_pass < a+b and n_fpass < b:
        n_pass+=1
        n_fpass+=1
        ans.append('Yes')
    else:
        ans.append('No')
for _ in range(n):
    print(ans[_])  



Measured memory_bytes: 4784
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

	    int N=gi();
	    Map<Integer, Integer> m=new HashMap<Integer, Integer>();

	    for(int i=0; i<N;i++) {
	    	int v=gi();
	    	if(m.containsKey(v)) {
	    		m.put(v, m.get(v)+1);
	    	} else {
	    		m.put(v, 1);
	    	}
	    }

	    int a=0;
	    for(Map.Entry<Integer, Integer> e : m.entrySet()) {
	    	int k=e.getKey();
	    	int v=e.getValue();
	    	if(v >= k) {
	    		a+=v-k;
	    	} else {
	    		a+=v;
	    	}
	    }
	    System.out.print(a);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 61756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;


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

  ll ans = 0;
  set<ll> s;
  s.insert(0);
  s.insert(n+1);
  s.insert(pos[n]);
  for (int i = n - 1; i > 0; --i) {
    ll p = pos[i];
    auto gtp = s.lower_bound(p);
    auto ltp = gtp;
    auto lltp = --ltp;
    auto ggtp = gtp;
    if (*ltp != 0) {
      --lltp;
    }
    if (*gtp != n + 1) {
      ++ggtp;
    }
    ans += i * ((p - *ltp) * (*ggtp - *gtp) + (*gtp - p) * (*ltp - *lltp));
    s.insert(p);
  }
  cout << ans;
  
  return 0;
}




Measured memory_bytes: 5760
#include <stdio.h>
int main()
{
	int a,b,M;
	scanf("%d %d", &a, &b);
	M = a*b;
	if (M % 2 == 0)
	{
		printf("Even\n");
	}
	else
	{
		printf("Odd\n");
	}
	return 0;
}

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

int ok[24*60+5],tmp[24*60+5];

inline int conv(int p) { return (p/100)*60 + p%100; }

int main() {
    int n,p,q,k;
    while(cin>>n>>p>>q, n|p|q) {
        q = conv(q) - conv(p); p = conv(p);
        memset(ok, 0, sizeof(ok));

        for(int i=0; i<n; ++i) {
            cin>>k;
            int pp,qq;
            for(int j=0; j<k; ++j) {
                cin>>pp>>qq;
                pp = conv(pp); qq = conv(qq);
                pp -= p, qq -= p;
                for(int l=pp; l<qq; ++l) ok[l]++;
            }
        }

        int mm = 0,ans = 0;
        for(int i=0; i<q; ++i) {
            if(ok[i] == n) {
                ans = max(mm, ans);
                mm = 0;
            }else mm++;
        }
        ans = max(mm, ans);

        cout<<ans<<endl;
    }
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;

namespace ABC073_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var num = new List<int>();
            for (var i = 0; i < n; i++)
            {
                var s = int.Parse(Console.ReadLine());
                num.Add(s);
            }
            num.Sort();
            var pre = -1;
            int ans = 0;
            int number = 0;
            foreach(var ch in num)
            {
                if(pre != ch)
                {
                    pre = ch;
                    ans += (number % 2);
                    number = 1;
                }
                else
                {
                    number++;
                }
            }
            ans += number % 2;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 18140
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int N;
  cin >> N;
  int W[N];
  rep(i, 0, N) cin >> W[i];
  int S1 = W[0];
  int S2 = 0;
  rep(i, 1, N) S2 += W[i];
  int rsl = abs(S1 - S2);
  rep(i, 1, N) {
      S1 += W[i];
      S2 -= W[i];
      rsl = min(rsl, abs(S1 - S2));
  }

  cout << rsl << endl;

}


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

int main() {
  int n, m, l;
  l = 0;
  cin >> n >> m;
  vector<vector<int> > data(n, vector<int>(m));
  vector<int> b(m);

  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> data.at(i).at(j);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      l += data.at(i).at(j) * b.at(j);
    }
    cout << l << endl;
    l = 0;
  }



}


Measured memory_bytes: 3148
#include<cstdio>
#include<algorithm>
using namespace std;
int Mod = 1000000007, n, m;
int w[5], res;
long long D[5010], T[5010], po[5010], Ipo[5010], Inv2=Mod/2+1;
void Do(){
    int j;
    long long sum=0;
    for(j=1;j<=m;j++){
        sum=(sum+D[j-1]*Ipo[j]%Mod*(j-1))%Mod;
        T[j]=(D[j]*(j+1)+sum*po[j])%Mod;
    }
    for(j=1;j<=m;j++)D[j]=T[j];
}
int main(){
    int i;
    po[0]=Ipo[0]=1;
    scanf("%d%d",&n,&m);
    for(i=1;i<=5000;i++)po[i]=po[i-1]*2%Mod, Ipo[i]=Ipo[i-1]*Inv2%Mod;
    for(i=1;i<=m;i++)D[i]=po[i];
    for(i=1;i<n;i++){
        Do();
    }
    printf("%lld\n",D[m]);
}


Measured memory_bytes: 1856
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long

ll n,x,ans;
vector<ll> l,ln;
void zzz(ll i){
  ll j=i;
  for(;i>0;i--){
    if(ln[i]+(j+1-i)==x){
      x=0;
      ans+=l[i];
      return;
    }
    if(ln[i]+(j+1-i)+1==x){
      x=0;
      ans+=l[i]+1;
      return;
    }
    if(ln[i]+(j+1-i)<x)break;
  }
  if(i>0){
    ans+=l[i]+1;
    x-=ln[i]+(j+1-i)+1;
    if(x>0)zzz(i-1);
  }
  else{
    x-=j+1;
    if(x>=3) ans+=3;
    else if(x>0) ans+=x;
  }

}

int main(){
  cin>>n>>x;
  ans=0;
  l.assign(n+1,0);
  ln.assign(n+1,0);
  l[0]++;
  ln[0]++;
  for(int j=1;j<=n;j++){
    l[j]=l[j-1]*2+1;
    ln[j]=ln[j-1]*2+3;
  }
  zzz(n-1);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;
int[] d = [-1,1];
int h,w;
int[][] hwall,wwall;

int saiki(){

    Tuple!(int,int)[] queuex,queuey;
    int x,y;
    bool[31][31] used;
    foreach(i;used)foreach(j;i) j = false;
    int ans = 2;
    int temp;
    int c;
    queuex ~= tuple(x,1);
    queuey ~= tuple(y,1);
    while(c < to!int(queuex.length)){
	x = queuex[c][0];
	y = queuey[c][0];
	ans = queuex[c][1];
	c++;
	if(x == w-1 && y == h-1){
	    return ans;
	}

	foreach(i;d){
	    if(x+i>=w || x+i < 0 ) continue;
	    if(i == -1 && wwall[y][x]) continue;
	    if(i != -1 && wwall[y][x+i]) continue;
	    if(used[y][x+i]) continue;
	    used[y][x+i] = true;
	    queuex ~= tuple(x+i,ans+1);
	    queuey ~= tuple(y,ans+1);
	}
	foreach(i;d){
	    if(y+i>=h || y+i < 0 ) continue;
	    if(i == -1 && hwall[y][x]) continue;
	    if(i != -1 && hwall[y+i][x]) continue;
	    if(used[y+i][x]) continue;
	    used[y+i][x] = true;
	    queuex ~= tuple(x,ans+1);
	    queuey ~= tuple(y+i,ans+1);
	}
    }
    return 0;
}

void main(){

    while(true){
	int[][] th,tw;
	auto s = readln().split().to!(int[]);
	if(s[0] == 0 && s[1] == 0) break;
	w = s[0];
	h = s[1];

	th ~= new int[31];
	tw ~=  0 ~ readln().split().to!(int[]);
	for(int i=0;i<h-1;i++){
	    th ~=  readln().split().to!(int[]);
	    tw ~=  0 ~ readln().split().to!(int[]);
	}
	hwall = th.dup();
	wwall = tw.dup();
	writeln(saiki());
    }

}

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

const int64_t MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  
  string S,T;
  cin>>S>>T;

  int64_t ans=0;
  int st=0;
  if(S[0]==T[0]){
    ans=3;
    st=1;
  }
  else{
    ans=6;
    st=2;
  }

  for(int i=st;i<N;++i){
    
    if(S[i]==T[i] && S[i-1]==T[i-1]){
      ans *= 2;
      ans %= MOD;
    }
    else if(S[i]!=T[i] && S[i-1]==T[i-1]){
      ans *= 2;
      ans %=MOD;
      ++i;
    }
    else if(S[i]!=T[i] && S[i-1]!=T[i-1]){
      ans *=3;
      ans %= MOD;
      ++i;
    }
    
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
dice = list(input().split(' '))
a = list('NNNNWNNNWNNNENNNENNNWNNN')
x = 0
aa,bb,cc,dd,ee,ff  = input().split(' ')
for i in a:
    if i == 'W':
        dice = [dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]]
    elif i == 'S':
        dice = [dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]]
    elif i == 'N':
        dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
    elif i == 'E':
        dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
    if dice[0] == aa and dice[1] == bb and dice[2] == cc and dice[3] == dd and dice[4] == ee and dice[5] == ff:
        x = x + 1
kome = 'Yes' if x > 0 else 'No'
print(kome)


Measured memory_bytes: 5576
//
// Created by yamunaku on 2019/10/06.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int x=0,y=0;
    rep(i,n){
        if('A'<=s[i]&&s[i]<='M'){
            x++;
        }else if('N'<=s[i]&&s[i]<='Z'){
            x--;
        }else if('a'<=s[i]&&s[i]<='m'){
            y++;
        }else{
            y--;
        }
    }
    string ans="";
    if(x>0){
        rep(i,x){
            ans.push_back('A');
        }
    }else if(x<0){
        rep(i,-x){
            ans.push_back('N');
        }
    }
    if(y>0){
        rep(i,y){
            ans.push_back('a');
        }
    }else if(y<0){
        rep(i,-y){
            ans.push_back('n');
        }
    }
    cout << ans.size() << endl;
    cout << ans << endl;
    return 0;
}



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

int main() {
	int n;
	cin >> n;
	map<string,int> poll;
	for (int i = 0; i < n; i++) {
		string x;
		cin >> x;
		if (poll.count(x))poll.at(x)++;
		else poll[x] = 1;
	}
	int ans = 0;
	vector<string> wait;
	for (pair<string,int> p:poll) {
		ans = max(ans, p.second);
	}
	for (pair<string, int>p : poll) {
		if (p.second == ans)wait.push_back(p.first);
	}
	for (int i = 0; i < wait.size(); i++) {
		cout << wait.at(i) << endl;
	}
}

Measured memory_bytes: 26868
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

template <class RandomIt>
size_t ssort(RandomIt first, RandomIt last) {
    size_t times=0;
    for (RandomIt it=first; it<last; ++it) {
        RandomIt min_=it;
        for (RandomIt it2=it+1; it2<last; ++it2)
            if (*min_ > *it2)
                min_ = it2;

        if (it != min_) {
            swap(*it, *min_);
            ++times;
        }
    }

    return times;
}

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

    vector<int> A(N);
    for (size_t i=0; i<N; ++i)
        scanf("%d", &A[i]);

    size_t t=ssort(A.begin(), A.end());

    for (size_t i=0; i<N; ++i)
        printf("%d%c", A[i], i<N-1? ' ':'\n');

    printf("%zu\n", t);
    return 0;
}

Measured memory_bytes: 2732
S = input()
while True:
  if S.endswith("dream"):
    S = S[0: len(S)-len("dream")]
  elif S.endswith("dreamer"):
    S = S[0: len(S)-len("dreamer")]
  elif S.endswith("erase"):
    S = S[0: len(S)-len("erase")]
  elif S.endswith("eraser"):
    S = S[0: len(S)-len("eraser")]
  else:
    break
if (len(S) == 0):
  print("YES")
else:
  print("NO")


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int div(int num)
{
    int counter = 0;
    while(num%2==0)
    {
        num /= 2;
        counter++;
    }
    return counter;
}
int main()
{
    int n;cin >> n;
    vector<int> a(n);rep(i,n)cin >> a[i];
    int ans = 0;
    rep(i,n)
    {
        ans += div(a[i]);
        // cout << div(a[i]) << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
 
int main(){
 
  int N,K;
    cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    bool flag=false;
    if(K>A[N-1]) cout<<"IMPOSSIBLE"<<endl;
    else{
        for(int i=0;i<N-1;i++){
            A[i+1]=gcd(A[i],A[i+1]);
            if(A[i+1]==1){
                flag=true;
                break;
            }
        }
        if(flag) cout<<"POSSIBLE"<<endl;
        else{
            if(K%A[N-1]==0) cout<<"POSSIBLE"<<endl;
            else cout<<"IMPOSSIBLE"<<endl;
        }
    }
}

Measured memory_bytes: 640
import sys
readline = sys.stdin.readline
N = int(readline())
sn = {}
maxn = 0
for _ in range(N):
    S = readline()
    if S in sn:
        sn[S] += 1
    else:
        sn[S] = 0
    maxn = max(maxn, sn[S])
ans = sorted(s for s, n in sn.items() if n == maxn)
for s in ans:
    print(s, end="")

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

#define endl "\n"
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define MOD 1000000007
#define INF 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y) 
#define mem(a,val) memset(a,val,sizeof(a))
#define f first
#define s second

void print_array(ll *a,ll n){for(ll i=0;i< n;++i){ cout<<a[i]<<" "; } cout<<"\n";}

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

	ll n,k;
	cin>>n>>k;
	ld arr[n];;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
		arr[i] = ((arr[i]+1))/(2);
	}

	ld pre[n+1]={0};
	pre[1]=arr[0];

	ld ans=0;

	for (int i = 1; i <= n; ++i)
	{
		pre[i]=arr[i-1]+pre[i-1];
	}

	ld mx  = 0;
	for (int i = k-1; i < n; ++i)
	{
		ld tmp  = pre[i+1]-pre[i+1-k];
		if(tmp>mx) mx = tmp;
	}

	cout<<fixed<<setprecision(7)<<mx;

	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a<<' '<<b<<' '<<-a-b+3*c<<endl;
    cout<<-2*a-b+4*c<<' '<<c<<' '<<2*a+b-2*c<<endl;
    cout<<a+b-c<<' '<<-b+2*c<<' '<<-a+2*c<<endl;
    return 0;
}

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

using namespace std;

int main(void) {
   string str;
  cin >> str;
  if(str[0] == '9' || str[1] == '9') {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
 return 0;
}


Measured memory_bytes: 256
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 2000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[li];
int cev;
string s;
vector<int> v;

int main(void){
	scanf("%d %d",&n,&k);
	FOR{
		scanf("%d",&a[i]);
	}
	dp[1]=0;
	dp[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;i++){
		dp[i]=inf;
		for(int j=i;j>=max(1,i-k);j--){dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));}
	}
	printf("%d\n",dp[n]);
	return 0;
}



Measured memory_bytes: 4620
#include <bits/stdc++.h>
#define CFS cin.tie(nullptr);ios::sync_with_stdio(false);
#define CST(x) cout<<fixed<<setprecision(x);
using namespace std;
constexpr int IINF = numeric_limits<int>::max();
constexpr long LINF = numeric_limits<long>::max();
constexpr int MOD = (int) 1e9 + 7;
// constexpr int MOD = 998244353;

int main(){
    int s, w;
    cin >> s >> w;
    if (w >= s) {
        cout << "unsafe" << "\n";
    }
    else {
        cout << "safe" << "\n";
    }
}

Measured memory_bytes: 3620
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        N: u32,
        A: [i64; N],
    }
    let mut res:i64 = 0;
    for (i, v) in A.iter().enumerate() {
        if i % 2 == 1 {
            res = res - v;
        } else {
            res = res + v;
        }
    }
    print!("{} ", res);
    for i in 0..N-1 {
        res = (A[i as usize] - res / 2) * 2;
        print!("{} ", res);
    }
    println!("");
}



Measured memory_bytes: 5372
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

bool check(string tmp) {
    // cout << tmp << endl;
    if(tmp.length() % 2 == 1) {
        cout << "nope" << endl;
        return false;
    } else {
        int len = tmp.length();
        string before = tmp.substr(0, len / 2);
        string after = tmp.substr(len / 2);
        // cout << before << ":" << after << endl;
        return before == after;
    }
}
int main() {
    string s;
    cin >> s;
    int l = s.length();
    //末尾の文字を消していく
    for(int i = l - 2; i >= 0; i -= 2) {
        if(check(s.substr(0, i))) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "0" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int arr[] = new int [n+1]; 
		boolean flag = false;
		for(int i=1 ; i <= n ; i++){
			arr[i] = scanner.nextInt();
		}
		int count = 0;
		int i = 1;
		
		while(flag == false){
			if(i == n+1){
				i=1;
			}
			if(arr[i] == i){
				if(i!=n){
					int temp = arr[i];
					arr[i] = arr[i+1];
					arr[i+1] = temp;
					i++;
					count ++;
				}else{
					int temp = arr[i];
					arr[i] = arr[i-1];
					arr[i-1] = temp;
					i++;
					count ++;
				}
			}else{
				i++;
			}
			
			if(i == n+1){
				for(int j=1 ; j<=n ; j++){
					if(arr[j] == j){
						break;
					}
					if(j == n) flag = true;
				}
			}
		}
		
		System.out.println();
		System.out.println(count);
		
	}
}


Measured memory_bytes: 51364
use std::collections::BTreeMap;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let mut map = BTreeMap::new();
    let mut sum = 0;
    for _ in 0..n {
        let a: i64 = sc.read();
        map.entry(a).and_modify(|c| *c += 1).or_insert(1);
        sum += a;
    }

    let q: usize = sc.read();
    for _ in 0..q {
        let from: i64 = sc.read();
        let from_count = map.get(&from).cloned().unwrap_or(0);

        let to: i64 = sc.read();
        let d = to - from;
        sum += d * from_count;
        map.entry(to)
            .and_modify(|c| *c += from_count)
            .or_insert(from_count);
        map.remove(&from);
        sc.write(sum);
        sc.write("\n");
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 3972
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

using namespace std;

int main() {
  int n;
  cin >> n ;
  if(n%2==0){
   cout << n/2 << endl;
  }else{
   cout << (n/2)+1 << endl;   
  }
  return 0 ;
}


Measured memory_bytes: 256
n=int(input())
aList=list(map(int,input().split()))
aSum=sum(aList)
ans=[0 for i in range(n)]
temp=aSum
for i in range(1,n,2):
    temp-=aList[i]*2
ans[0]=temp
for i in range(1,n):
    ans[i]=aList[i-1]*2-ans[i-1]
temp=str(ans).replace(",","")
temp=temp.replace("[","")
temp=temp.replace("]","")
print(temp)


Measured memory_bytes: 14232
c1,c2,c3=map(int,input().split())
d1=c2-c1
d2=c3-c2
ans=0
for i in range(2):
  c1,c2,c3=map(int,input().split())
  if c2-c1!=d1 or c3-c2!=d2:
    ans+=1
print("Yes" if ans==0 else "No")

Measured memory_bytes: 3060