akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate
from collections import defaultdict

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

acc = [0] + list(accumulate(a))
sm = [(e - i) % k for i, e in enumerate(acc)]

d = defaultdict(int)
ans = 0
for r in range(1, n + 1):
    if r - k >= 0:
        e = sm[r - k]
        d[e] -= 1

    e = sm[r - 1]
    d[e] += 1

    e = sm[r]
    ans += d[e]

print(ans)


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

using namespace std;

/* Q.: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_B&lang=jp */

struct node
{
    int parent;
    int sibling;
    int left, right;
    int chCnt;
    int depth;
    int height;
    string type;
} Node;

int adjustDepth(vector<node> &v, int id, const int depth)
{
    v[id].depth = depth;
    int len = v[id].chCnt;

    int lh = -1, rh = -1;
    if (v[id].left >= 0)
        lh = adjustDepth(v, v[id].left, depth + 1);
    if (v[id].right >= 0)
        rh = adjustDepth(v, v[id].right, depth + 1);

    v[id].height = max(lh, rh) + 1;

    return v[id].height;
}

int findRootId(const vector<node> &t, const int id)
{
    return t[id].parent < 0 ? id : findRootId(t, id + 1);
}

int main()
{
    int n;
    scanf("%d\n", &n);
    vector<node> t(n);
    for (int i = 0; i < n; i++)
    {
        t[i].parent = -1;
        t[i].sibling = -1;
        t[i].left = -1;
        t[i].right = -1;
        t[i].chCnt = 0;
    }

    for (int i = 0; i < n; i++)
    {
        int id, chN;
        scanf("%d", &id);
        scanf("%d %d", &(t[id].left), &(t[id].right));

        if (t[id].left < 0 && t[id].right < 0)
            t[id].type = "leaf";
        else
        {
            t[id].type = "internal node";
            t[t[id].left].parent = id;
            t[t[id].right].parent = id;
            t[t[id].left].sibling = t[id].right;
            t[t[id].right].sibling = t[id].left;

            if (t[id].left >= 0 && t[id].right >= 0)
                t[id].chCnt = 2;
            else
                t[id].chCnt = 1;
        }
    }

    adjustDepth(t, findRootId(t, 0), 0);

    for (int i = 0; i < n; i++)
    {
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
               i,
               t[i].parent,
               t[i].sibling,
               t[i].chCnt,
               t[i].depth,
               t[i].height,
               t[i].parent == -1
                   ? "root"
                   : t[i].type.c_str());
    }

    return 0;
}



Measured memory_bytes: 3340
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]

s = input()

if s == 'SUN':
  print(7)
  exit()
print((7 - days.index(s))%7)

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

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

int main(void) {
    int d;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> d;
    cout << "Christmas";
    REP(i, 25 - d) {
        cout << " Eve";
    }
    
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
import sys
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))

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

Measured memory_bytes: 56672
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>x(n);
  rep(i,0,n)cin>>x[i];
  rep(i,0,n)res+=min(x[i],k-x[i])*2;
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <string>
#include <map>
#include <list>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define LargeNum 1000000007
int a[50], b[50], c[50], d[50], score = -1;
void seisei(int N, int M, int Q, int n, int A[]){
    if (n == N){
        int ans = 0;
        rep(i, Q){
            if (A[b[i]-1] - A[a[i]-1] == c[i]) ans += d[i];
        }
        if (score < ans) score = ans;
        return;
    }
    else {
        if (n != 0) A[n] = A[n-1];
        seisei(N, M, Q, n+1, A);
        while (true){
            if (A[n] < M) {
                A[n] ++;
                seisei(N, M, Q, n+1, A);
            }
            else break;
        }
    }
}

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    int A[N];
    rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    rep(i, N) A[i] = 1;
    seisei(N, M, Q, 0, A);
    cout << score << endl;
    return 0;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]
def main():
    n,q = map(int,input().split())
    U = Unionfind(n)
    for i in range(q):
        t,u,v = map(int,input().split())
        if t == 0:
            U.union(u,v)
        else:
            print(int(U.same(u,v)))

if __name__ == "__main__":
    main()

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

typedef long long ll;

main()
{
    string s , t, temp;
    int a, b, c, x = 0;
    cin >> s >> t;
    a = s.size();
    b = t.size();
    for(int i = 0; i <= a - b; i++){
        temp = s.substr(i, b);
        c = 0;
        for(int j = 0; j < b; j++){
            if(temp[j] == t[j]){
                c++;
            }
        }
        x = max(x, c);
    }
    cout << b - x;
}





///promy_pompom
//hello world


Measured memory_bytes: 3632
"use strict";
function Main(input) {
  const args = input.split(' ').map(m => parseInt(m));
  const R = args.shift();
  const G = args.shift();
  const B = args.shift();
  const N = args.shift();
  let count = 0;

  const countR = Math.trunc(N / R);
  const modR = N % R;
  for (let i = 0; i <= countR; i++) {
    const need = modR + (R * i);
    if (need === 0) {
      // console.log(`R: ${countR - i}`);
      count++;
      continue;
    }
    const countG = Math.trunc(need / G);
    const modG = need % G;
    for (let j = 0; j <= countG; j++) {
      const need2 = modG + (G * j);
      if (need2 === 0) {
        // console.log(`R: ${i}, G: ${j}`);
        count ++;
      } else if ((need2 % B) === 0) {
        // console.log(`R: ${countR - i}, G: ${countG - j}, B: ${need2 / B}`);
        count ++;
      }
    }
  }

  console.log(count);


}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

using i32 = int;
using i64 = long long;

using namespace std;


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

    i32 q;cin >> q;

    multiset<i64,greater<>> l;
    multiset<i64> r;

    i64 tmp = 0;

    REP(_,q){
        i32 c;cin >> c;
        if(c == 1){
            i64 a,b;cin >> a >> b;

            tmp += b;
            if(l.size()){
                i64 L = *l.begin(),R = *r.begin();
                if(L > a || a > R) tmp += min(abs(L - a),abs(R - a));

                if(a < L){
                    REP(i,2) l.emplace(a);
                    r.emplace(*l.begin());
                    l.erase(l.begin());
                }else if(a <= R){
                    l.emplace(a);
                    r.emplace(a);
                }else{
                    REP(i,2) r.emplace(a);
                    l.emplace(*r.begin());
                    r.erase(r.begin());
                }
            }else{
                l.emplace(a);
                r.emplace(a);
            }

        }else{
            cout << *l.begin() << ' ' << tmp << '\n';
        }
    }

}



Measured memory_bytes: 22328
/*
????????????????????£????????§?????????????????????????????°??????????????°?????\????????????????????????????????????
??£????????????????????£???????????????????????????????????????
???????????\????????????????????????????????°??????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????´???????????§??????

???????????´??° x ???????????????????????????????????????????????????????????°?????????????????????????????????

?????????????????????????????\?????????????????????????????????????????????????????????????????????????????¨?????¨?????????????????????
*/

#include <iostream>
int main() {
	int num;
	int i = 1;

	while (1)
	{
		std::cin >> num;
		if (num == 0) {
			break;
		}
		else {
			std::cout << "Case " << i << ": " << num << std::endl;
			i++;
		}
	}

	return 0;
}

Measured memory_bytes: 3016
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        String[] charactor = "abcdefghijklmnopqrstuvwxyz".split("");
        
        ArrayList<String> s = new ArrayList<String>(Arrays.asList(sc.next().split("")));
        List<String> s_sorted = new ArrayList<String>(new HashSet<>(s));
        Collections.sort(s_sorted);
        
        int num = 0;
        for(int i=0; i<s_sorted.size(); i++){
            if(!s_sorted.get(i).equals(charactor[i])){
                System.out.println(charactor[i]);
                return;
            }
            num = i;
        }
        
        if(num == 25){
            System.out.println("None");
        }else{
            System.out.println(charactor[num+1]);
        }
    }
}

Measured memory_bytes: 32752
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll N, l, r, s = 0;
  cin >> N;
  for (ll i = 0; i < N; i++) {
    cin >> l >> r;
    s += r - l + 1;
  }
  cout << s << endl;
}


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

using namespace std;

const int N = (int)1e5 + 7;

int a[N];

main() {    
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + n + 1);
	cout << a[n] << ' ';
	int mid = (a[n] + 1) / 2;
	int dif = 1e9;
	int ans;
	for (int i = 1; i < n; i++) {
		if (abs(a[i] - mid) < dif) {
			ans = a[i];
			dif = abs(a[i] - mid);
		}
	}	
	cout << ans;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int n;
    int d,x;
    while(cin>>n){
        cin>>d>>x;
        int a;
        int sum=0;
        for(int i=0;i<n;i++){
            cin>>a;
            int j=1,k=1,cnt=1;
            j=k*a+1;
            while(j<=d){
                cnt++;
                k++;
                j=k*a+1;

            }
            sum=sum+cnt;
        }
        cout<<sum+x<<endl;
    }
    return 0;

}


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

int main()
{
	ll n, a, b;
	ignore = scanf("%lld %lld %lld", &n, &a, &b);
	
	if ((b - a) % 2 == 0) {
		printf("%lld\n", (b - a) / 2);
		return 0;
	}
	
	ll res = n;
	{
		ll aa = 1;
		ll bb = b - a + 1;
		res = min(res, a - 1 + (bb - aa) / 2 + 1);
	}
	{
		ll aa = n - (b - a);
		ll bb = n;
		res = min(res, n - b + (bb - aa) / 2 + 1);
	}
	printf("%lld\n", res);
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    string S,T;
    cin>>S>>T;
    int n=S.size();
    int m=T.size();
    vector<LL> x(n+1,0),y(m+1,0);
    REP(i,n){
        if(S[i]=='A')x[i+1]=1;
        else x[i+1]=2;
        x[i+1]+=x[i];
    }
    REP(i,m){
        if(T[i]=='A')y[i+1]=1;
        else y[i+1]=2;
        y[i+1]+=y[i];
    }
    int Q;
    cin>>Q;
    REP(q,Q){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        LL cnt=x[b]-x[a-1]-y[d]+y[c-1]+30000000;
        //cout<<x[b]-x[a-1]<<" "<<y[d]-y[c-1]<<endl;
        if(cnt%3==0)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 2512
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
int x, a, b;
int main(){
	scanf("%d%d%d", &x, &a, &b);
	if(a >= b)printf("delicious\n");
	else if(b - a <= x)printf("safe\n");
	else printf("dangerous\n");
	return 0;
}

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

int main(){
	ll N, M;
	cin >> N >> M;
	vector<ll> x(N);
	vector<ll> y(N);
	vector<ll> z(N);
	for (int i = 0; i < N; i++){
		cin >> x[i] >> y[i] >> z[i];
	}

	ll res = 0;
	for (int b = 0; b < 8; b++){
		int t = b;
		int flg[3] = {0};
		for (int i = 0; i < 3; i++){
			flg[i] = t%2;
			t /= 2;
		}

		vector<ll> v(N, 0);
		for (int i = 0; i < N; i++){
			if (flg[0] == 0) v[i] += x[i];
			else v[i] -= x[i];
			if (flg[1] == 0) v[i] += y[i];
			else v[i] -= y[i];
			if (flg[2] == 0) v[i] += z[i];
			else v[i] -= z[i];
		}

		sort(v.begin(), v.end(), greater<ll>());

		ll tmp = 0;
		for (int i = 0; i < M; i++){
			tmp += v[i];
		}
		
		res = max(res, tmp);
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
import numpy as np
N, M = map(int, input().split())
a = []
for i in range(N):
    a.append(list(map(int,input().split())))

ar = np.array(a)

b = np.zeros((N,8))
for i in range(0,N):
    b[i,0] = ar[i,0] + ar[i,1] + ar[i,2]
    b[i,1] = ar[i,0] + ar[i,1] - ar[i,2]
    b[i,2] = ar[i,0] - ar[i,1] + ar[i,2]
    b[i,3] = ar[i,0] - ar[i,1] - ar[i,2]
    b[i,4] = -ar[i,0] + ar[i,1] + ar[i,2]
    b[i,5] = -ar[i,0] + ar[i,1] - ar[i,2]
    b[i,6] = -ar[i,0] - ar[i,1] + ar[i,2]
    b[i,7] = -ar[i,0] - ar[i,1] - ar[i,2]

e0 = np.asarray([0,0,0,0,0,0,0,0])

c0 = b[:,0]
d0 = np.sort(c0)[::-1]
e0[0] = sum(d0[:M])

c1 = b[:,1]
d1 = np.sort(c1)[::-1]
e0[1] = sum(d1[:M])

c2 = b[:,2]
d2 = np.sort(c2)[::-1]
e0[2] = sum(d2[:M])

c3 = b[:,3]
d3 = np.sort(c3)[::-1]
e0[3] = sum(d3[:M])

c4 = b[:,4]
d4 = np.sort(c4)[::-1]
e0[4] = sum(d4[:M])

c5 = b[:,5]
d5 = np.sort(c5)[::-1]
e0[5] = sum(d5[:M])

c6 = b[:,6]
d6 = np.sort(c6)[::-1]
e0[6] = sum(d6[:M])

c7 = b[:,7]
d7 = np.sort(c7)[::-1]
e0[7] = sum(d7[:M])


e1 = np.sort(e0)[::-1]
print(e1[0])

Measured memory_bytes: 20996
X,Y,A,B,C = map(int,input().split())
AList = sorted(list(map(int,input().split())),reverse=True)
BList = sorted(list(map(int,input().split())),reverse=True)
CList = sorted(list(map(int,input().split())),reverse=True)
FullList = sorted(AList[:X] + BList[:Y])
counter = 0
for i in range(min(C,X+Y)):
  if CList[i] <= FullList[i]:
    break
  else:
    counter += 1
ans = sum(CList[:counter])+sum(FullList[counter:])
print(ans)


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

int main(){
    int a,b,x;
    cin>>a>>b>>x;
    double s=(double)x/a;
    double ans;
    double pi=acos(-1);
    if(s<=a*b/2.0){
        double w=2.0*s/b;
        ans=atan2(b,w)/(2*pi)*360;
    }
    else{
        double h=2.0*(a*b-s)/a;
        ans=atan2(h,a)/(2*pi)*360;
    }
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 4028
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();
		final int m = sc.nextInt();

		HashMap<Integer, ArrayList<Integer>> list = new HashMap<Integer, ArrayList<Integer>>();
		for (int i = 1; i <= n; i++) {
			int totalItem = sc.nextInt();
			ArrayList<Integer> itemList = new ArrayList<Integer>();
			for (int j = 0; j < totalItem; j++) {
				itemList.add(sc.nextInt());
			}
			list.put(i, itemList);
		}

		int count = 0;
		int total = 0;
		for (int k = 0; k <= m; k++) {
			for (final int key : list.keySet()) {
				final ArrayList<Integer> likeItem = list.get(key);
				if (likeItem.contains(k)) {
					count++;
				}
			}
			if (count == n) {
				total++;
			}
			count = 0;
		}

		java.lang.System.out.println(total);

	}

}


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

struct Cube {
  public:
  int f[6];
  void roll(int i, int j, int k, int l){
    int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t; 
  }
  void roll_x() { roll(0,2,5,3); } 
  void roll_y() { roll(0,1,5,4); }
  void roll_z() { roll(1,2,4,3); }
    
};

int getRight(Cube c, int top, int front); //Cube入れんと事故る main内で入れてる

int main() {
  Cube c;
  for ( int i = 0; i < 6; i++ ) cin >> c.f[i];
  int n;
  cin >> n;
  int top, front;
  for ( int i = 0; i < n; i++ ) {
      cin >> top >> front; 
      cout << getRight(c, top, front) << endl;
  }
  return 0;
}

int getRight(Cube c, int top, int front) { 
    for ( int j = 1; j <= 6; j++ ) { //ちゃんと下辿ればeasyわかる
      for ( int i = 1; i <= 4; i++ ) { //3だと毎回元に戻らない
          if ( top == c.f[0] && front == c.f[1] ) return c.f[2]; 
          c.roll_z(); 
      }
      //各out loopで下を1回
      if ( j % 2 == 0) c.roll_x();
      else c.roll_y();
    }
}



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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

vector<pair<char, int64_t>> run_length(string s) {
    vector<pair<char, int64_t>> ret;
    if (s.empty()) return ret;
    int64_t cnt = 0;
    char c = s[0];
    for (size_t i = 0; i < s.size(); i++) {
        if (s[i] == c) {
            cnt++;
        } else {
            ret.emplace_back(c, cnt);
            c = s[i];
            cnt = 1;
        }
        if (i + 1 == s.size()) {
            ret.emplace_back(c, cnt);
        }
    }
    return ret;
}

int main() {
    string s;
    cin >> s;
    // if (s.front() == s.back()) {
    //     print(0);
    //     return 0;
    // }
    vector<pair<char, Int>> v = run_length(s);
    print(v.size() - 1);
    return 0;
}


Measured memory_bytes: 5460
import math
n = int(input())
li = list(map(int,input().split()))

all_li = []
two_count = 0
zero_count = 0
for l in li:
    count = 0
    if l % 2 == 0:
        count += 1
    if l % 4 == 0:
        count += 1
        two_count += 1
    if count == 0:
        zero_count += 1
    all_li.append(count)
#print(all_li)
#[0, 1, 2]
if two_count == 0:
    #print(list(set(all_li)))
    if list(set(all_li)) == [1]:
        print('Yes')
    else:
        print('No')
elif zero_count == 0:
    print('Yes')
else:
    if zero_count > two_count +1:
        print('No')
    elif zero_count == two_count + 1:
        if len(all_li) - zero_count - two_count == 0:
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')

Measured memory_bytes: 63640
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define ld long double
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846
 
 const int N =3e5+5;
 const int lg=20;
 
	 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;	
	}
	 return res;	
   }
 
 
 
 
void solve() {   
	     int n,m,k;
	     cin>>n>>m>>k;
	     vi a(n+1,0),b(m+1,0);
	     rep(i,0,n) {
			   cin>>a[i+1];
			   a[i+1]+=a[i];
			 }
		rep(i,0,m) {
			   cin>>b[i+1];
			   b[i+1]+=b[i];
			 }
			
			int j=m,ans=0;
			
			rep1(i,0,n) {
				  if(a[i]>k) break;
				   while(a[i]+b[j]>k)
				      j--;
				   ans=max(ans,i+j);  
				   
				}  	
				
				cout<<ans<<endl;  
	    
    } 
 
 
int32_t main() {
	cool;
	int t=1;	
	    //~ cin>>t;
	while(t--)
	   solve();		   
	   
	   return 0;	   
}


Measured memory_bytes: 6356
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	A := sc.nextIntSlice(N)
	count := sort(A, 0, N)

	for i := 0; i < N; i++ {
		if i != 0 {
			fmt.Fprint(wtr, " ")
		}
		fmt.Fprint(wtr, A[i])
	}
	fmt.Fprintln(wtr)
	fmt.Fprintln(wtr, count)
	wtr.Flush()
}

func merge(A []int, left, mid, right int) {
	n1 := mid - left
	n2 := right - mid
	L := make([]int, n1+1)
	R := make([]int, n2+1)
	for i := 0; i < n1; i++ {
		L[i] = A[left+i]
	}
	for i := 0; i < n2; i++ {
		R[i] = A[mid+i]
	}
	L[n1] = 1 << 60
	R[n2] = 1 << 60
	i, j := 0, 0
	for k := left; k < right; k++ {
		if L[i] <= R[j] {
			A[k] = L[i]
			i++
		} else {
			A[k] = R[j]
			j++
		}
	}
}

func sort(A []int, left, right int) int {
	count := 0
	if right-left > 1 {
		mid := (left + right) / 2
		count += sort(A, left, mid)
		count += sort(A, mid, right)
		merge(A, left, mid, right)
		count += right - left
	}
	return count
}



Measured memory_bytes: 11944
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
a = [int(input()) for _ in range(5)]
b = []
last_order = 0

for i in range(5):
	b.append(-(-a[i] // 10) * 10)
	if (a[i] % 10 < a[last_order] % 10) and (a[i] % 10 != 0):
		last_order = i

print(sum(b) - b[last_order] + a[last_order])


Measured memory_bytes: 38256
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


//変数
string s;






//サブ関数
//入力
void input()
{
	cin >> s;
}


//計算
void calc()
{
	pair<int, int> res = { -2,-2 };

	//len=2
	REP(i, (int)s.size() - 1) {
		if (s[i] == s[i + 1]) {
			res.first = i;
			res.second = i + 1;
			break;
		}
	}
	//len=3
	REP(i, (int)s.size() - 2) {
		if (s[i] == s[i + 2]) {
			res.first = i;
			res.second = i + 2;
			break;
		}
	}

	cout << res.first + 1 << " " << res.second + 1 << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 760
#include "stdio.h"

int main(){
  	
  char str[4];
   int ret = scanf("%s", str);
  int count = 0;

  for(int ii=0;ii<4;ii++){
   	if(str[ii] == '1'){
   	  count++;
   	}
  }
  printf("%d",count);
    
	return 0; 
}

Measured memory_bytes: 128
#include<iostream>
#include<string.h>

using namespace std;

int main(){
	char kata[10];
	cin >> kata;
	if(kata[0] == kata[1] && kata[0] == kata[2] && kata[1] == kata[2]){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int a, b; cin >> a >> b;
    if(a > b) swap(a, b);
    int ans = 0;
    REP(i, b) ans = ans * 10 + a;
    Out(ans);

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int [] A = new int[K];
        for(int i=0;i<K;i++)A[i] = sc.nextInt();
        int min = 999999999;
        for(int i=0;i<K;i++){
            int a1,a2;
            if(i-1>=0) a1 = Math.abs(N-A[i]+A[i-1]);
            else a1 = Math.abs(A[K-1]-A[0]);
            if(i+1<K) a2 = Math.abs(A[i]+N-A[i+1]);
            else a2 = Math.abs(A[K-1]-A[0]);
            if(a1<min) min = a1;
            if(a2<min) min = a2;
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 85476
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  double n; cin >> n;

  if((int) n%2 == 0){
    cout << 0.5 << endl;
  } else {
    double ans = (n-1)/(2*n) + 1/n;
    cout << setprecision(8) << ans << endl;    
  }



  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define     debug       printf("\n<<CameHere<<\n")
#define     mem(x,y)    memset(x, y, sizeof(x))
#define     all(qz)     qz.begin(),qz.end()
#define     rall(qz)    qz.rbegin(),qz.rend()
#define     inf         LLONG_MIN
#define     INF         LLONG_MAX
#define     mod         1000000007
#define     Sqr(x)      ((x)*(x))
#define     ll          long long
#define     mk          make_pair
#define     pb          push_back
#define     pi          acos(-1.0)
#define     cos(a)      cos(a*pi/180)
#define     sin(a)      sin(a*pi/180)
#define     tan(a)      tan(a*pi/180)

ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
/*---------AL ASAD NUR RIYAD------------*/


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

    ll n;
    cin>>n;
    string ans;
    while(n>0){
        ll x=n%26;
        n=n/26;
        if(x==0){
            x=26;
            n-=1;
        }
        ans.pb('a'+x-1);
    }
    reverse(all(ans));
    cout<<ans<<endl;
    return 0;
}



















Measured memory_bytes: 3648
#include <stdio.h>

#define mod 1000000007

int N,K;
long F[2<<17];
long I[2<<17];

int main( int argc, char *argv[] )
{
    int i;
    char s[3];
    int A = 0;
    int B = 0;

    scanf( "%c%c%c", &s[0], &s[1], &s[2] );

    for( i=0; i<3; i++ ) {
        if( s[i] == 'A' ) A = 1;
        else if( s[i] == 'B' ) B = 1;
    }

    if( A && B ) puts( "Yes" );
    else puts( "No" );
}


Measured memory_bytes: 128
# a 高橋の体力
# b 高橋の攻撃力
# c 青木の体力
# d 青木の攻撃力

a,b,c,d = map(int,input().split())

while(1):
  c = c - b
  if(c <= 0):
    print('Yes')
    break
  a = a - d
  if(a <= 0):
    print('No')
    break
  

Measured memory_bytes: 9028
#include <bits/stdc++.h> 
#define lowbit(x) x&(-x)
using namespace std;
typedef long long ll;
const int N = 5e4;
const int M = 2e3;

ll f[35];

void f_table(){
	f[0] = 1;
	for(int i = 1;i <= 30;++i) f[i] = f[i-1]*3;
	return ;
}

int main(){
	f_table();
	int n;
	ll x1,y1,x2,y2;
	scanf("%d",&n);
	for(int t = 0;t < n;++t){
		scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
		x1--;y1--;x2--;y2--;
		
		ll ans = 0,flag = 0,sx,sy,ex,ey;
		for(int i = 30;i >= 0;--i){
			sx = x1/f[i],sy = y1/f[i],ex = x2/f[i],ey = y2/f[i];
			if(sx != ex && sy != ey) break;
			if(sx == ex && sx % 3 == 1 && abs(sy-ey) > 1){
				ll xl = x1/f[i]*f[i]-1;
				ll xr = xl+f[i]+1;
				ll dx = min(abs(xl-x1)+abs(xl-x2),abs(xr-x1)+abs(xr-x2));
				ll dy = abs(y1-y2);
				ans = dx+dy;
				flag = 1;
				break;
			}
			if(sy == ey && sy % 3 == 1 && abs(sx-ex) > 1){
				ll yl = y1/f[i]*f[i]-1;
				ll yr = yl+f[i]+1;
				ll dx = abs(x1-x2);
				ll dy = min(abs(yl-y1)+abs(yl-y2),abs(yr-y1)+abs(yr-y2));
				ans = dx+dy;
				flag = 1;
				break;
			}
		}
		if(flag) printf("%lld\n",ans);
		else printf("%lld\n",abs(x1-x2)+abs(y1-y2));
	}
    return 0;
}

Measured memory_bytes: 384
INF=float('inf')
n,k,c=map(int,input().split())
s=input()

L=[-1 for _ in range(n)]
cl=c+1
wl=1
for i in range(n):
  if wl>k:
    continue
  if s[i]=='x':
    cl+=1
  else:
    if cl>c:
      L[i]=wl
      wl+=1
      cl=1
    else:
      cl+=1

R=[-1 for _ in range(n)]
cr=c+1
wr=k
for j in range(n-1,-1,-1):
  if wr<1:
    continue
  if s[j]=='x':
    cr+=1
  else:
    if cr>c:
      R[j]=wr
      wr-=1
      cr=1
    else:
      cr+=1

for i in range(n):
  if L[i]==-1:
    continue
  if R[i]==-1:
    continue
  if L[i]==R[i]:
    print(i+1)
    
  

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

vector<int> getMax(const vector<int> &list, const int MAX_NUM);

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

    int N;
    cin >> N;

    vector<int> list1, list2;
    int tmp;
    for (int i = 0; i < N/2; ++i) {
        cin >> tmp;
        list1.push_back(tmp);
        cin >> tmp;
        list2.push_back(tmp);
    }

    const int MAX_NUM = 100001;
    vector<int> mm1 = getMax(list1, MAX_NUM);
    vector<int> mm2 = getMax(list2, MAX_NUM);

    int c = 0;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (mm1[i*2] != mm2[j*2]) {
                tmp = mm1[i*2+1] + mm2[j*2+1];
                if (c < tmp) { c = tmp; }
            }
        }
    }
    cout << N - c << endl;

    return 0;
}

vector<int> getMax(const vector<int> &list, const int MAX_NUM) {
    int shukei[MAX_NUM];
    for (int i = 0; i < MAX_NUM; ++i) {
        shukei[i] = 0;
    }
    for (auto i : list) {
        shukei[i]++;
    }

    int p1_cnt = 0, p2_cnt = 0, p3_cnt = 0;
    int p1 = -1, p2 = -1, p3 = -1;
    for (int i = 1; i < MAX_NUM; ++i) {
        if (shukei[i] > 0) {
            if (shukei[i] >= p1_cnt) {
                p3_cnt = p2_cnt;
                p3 = p2;
                p2_cnt = p1_cnt;
                p2 = p1;
                p1_cnt = shukei[i];
                p1 = i;
            }
            else if (shukei[i] >= p2_cnt) {
                p3_cnt = p2_cnt;
                p3 = p2;
                p2_cnt = shukei[i];
                p2 = i;
            }
            else if (shukei[i] >= p3_cnt) {
                p3_cnt = shukei[i];
                p3 = i;
            }
        }
    }
    vector<int> tmp = {p1, p1_cnt, p2, p2_cnt, p3, p3_cnt};
    return tmp;
}

Measured memory_bytes: 1276
N,K = map(int,input().split())
h = list(map(int,input().split()))
h.insert(0,0)

dp = [10**10] * (N+1)
dp[0],dp[1] = 0,0

for i in range(2,N+1):
    for j in range(min(K,i)):
        if i - j - 1 == 0:
            break
        dp[i] = min(dp[i] , dp[i-j-1] + abs(h[i] - h[i-j-1]))
print(dp[N])


Measured memory_bytes: 52448
N, K = gets.split.map(&:to_i)
R, S, P = gets.split.map(&:to_i)
T = gets.chomp.chars

ans = 0
rock_count = 0

def count(ch)
  mark = Array.new(N)
  ret = 0
  T.each.with_index do |ch2, i|
    next if mark[i]
    count = 0
    next if ch2 != ch
    j = i
    prev = nil
    while j < N
      mark[j] = true
      if T[j] == ch && prev != ch
        count += 1
        prev = T[j]
      else
        prev = nil
      end
      j += K
    end
    ret += count
  end
  ret
end

rsum = count('s') * R
ssum = count('p') * S
psum = count('r') * P
puts rsum + ssum + psum

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

class Knapsack
{
	static public void Main(string[] args)
	{
		int N, W;
		string[] vals = Console.ReadLine().Split(' ');
		N = int.Parse(vals[0]);
		W = int.Parse(vals[1]);
 
		int[] w = new int[N];
		int[] v = new int[N];
		for(int i=0; i < N; i++)
		{
			vals = Console.ReadLine().Split(' ');
			w[i] = int.Parse(vals[0]);
			v[i] = int.Parse(vals[1]);
		}

		List<int>[] values = new List<int>[4];
		for(int i=0; i < 4; i++)
		{
			values[i] = new List<int>();
		}

		for(int i=0; i < N; i++)
		{
	        	values[w[i]-w[0]].Add(v[i]);		    
		}

		foreach(var list in values)
		{
			list.Sort((a,b) => b - a);
		}

		long[,] cum = new long[4,N+1];
		for(int i=0; i < 4; i++)
		{
			for(int j=1; j < values[i].Count+1; j++)
			{
				cum[i,j] = cum[i,j-1] + values[i][j-1];
			}
		}
		
		long max = 0;
		for(int i=0; i <= values[0].Count; i++)
		{
			for(int j=0; j <= values[1].Count; j++)
			{
				for(int k=0; k <= values[2].Count; k++)
				{
					for(int l=0; l <= values[3].Count; l++)
					{
						if((long)w[0] * i + ((long)w[0]+1) * j + ((long)w[0]+2) * k + ((long)w[0]+3)*l <= W)
						{
							long sum = cum[0,i] + cum[1,j] + cum[2,k] + cum[3,l];
							if(sum > max)
								max = sum;
						}
					}
				}
			}
		}
		Console.WriteLine(max);
	}
}


Measured memory_bytes: 11220
package main

import (
  "fmt"
  "math"
)

func main() {
  const MAX = math.MaxInt32
  var N int
  fmt.Scanf("%d", &N)
  var dist [301][301]int
  var input [301][301]int

  for i := 0; i < N; i++ {
    for j := 0; j < N; j++ {
      fmt.Scanf("%d", &input[i][j])
    }
  }

  for k := 0; k < N; k++ {
    for i := 0; i < N; i++ {
      for j := 0; j < N; j++ {
        if i == j || j == k || k == i {
          continue
        }
        if input[i][j] > input[i][k] + input[k][j] {
          fmt.Println(-1)
          return
        } else if input[i][j] == input[i][k] + input[k][j] {
          dist[i][j] = MAX
        }
      }
    }
  }

  ret := 0
  for i := 0; i < N; i++ {
    for j := 0; j < N; j++ {
      if dist[i][j] == MAX {
        continue
      }
      ret += input[i][j]
    }
  }
  fmt.Println(ret / 2)
}


Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
ll gyaku(ll n){
  ll u=mod-2;
  ll ret=1;
  ll now=n;
  while(u>0){
    if(u%2==1){
      ret*=now;
      ret%=mod;
    }
    now*=now;
    now%=mod;
    u/=2;
  }
  return ret;
}
int main(){
  ll n;cin>>n;
  ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
  ll ans=0;
  ll ki=1;
  for(ll i=1;i<=n;i++){
    ki*=i;
    ki%=mod;
  }
  ll sum=0;
  for(ll i=1;i<=n;i++){
    sum+=ki*gyaku(i);
    sum%=mod;
  }
  for(ll i=1;i<=n;i++){
    //cout<<sum<<endl;
    ans+=sum*a[i-1];
    ans%=mod;
    sum+=ki*gyaku(i+1);
    sum%=mod;
    sum-=ki*gyaku(n-i+1);
    sum%=mod;
    sum=(sum+mod)%mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
void build(){

}
#define N 202002
int BIT[ N ];
inline int lb( int x ){
  return x & (-x);
}
void modify( int x ){
  for( int i = x ; i < N ; i += lb( i ) )
    BIT[ i ] ++;
}
int query( int x ){
  int ret = 0;
  for( int i = x ; i ; i -= lb( i ) )
    ret += BIT[ i ];
  return ret;
}
LL n , k , a[ N ];
void init(){
  n = getint();
  k = getint();
  vector<LL> li;
  for( int i = 1 ; i <= n ; i ++ ){
    a[ i ] = getint() - k + a[ i - 1 ];
    li.push_back( a[ i ] );
  }
  sort( li.begin() , li.end() );
  li.resize( unique( li.begin() , li.end() ) - li.begin() );
  for( int i = 0 ; i <= n ; i ++ )
    a[ i ] = lower_bound( li.begin() , li.end() , a[ i ] ) - li.begin() + 1;
}
void solve(){
  LL ans = 0;
  modify( a[ 0 ] );
  for( int i = 1 ; i <= n ; i ++ ){
    ans += query( a[ i ] );
    modify( a[ i ] );
  }
  printf( "%lld\n" , ans );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


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

using namespace std;
int main(void){
    int N, K;
    cin >> N >> K;
   
    int ans = 1;
    int sum = K;
    while (1) {
        if (sum >= N) break;
        sum += K - 1;
        ans++;
    }
    cout << ans << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int q,pos,l,r,t;
char c;
int alp[26][500010];
int lowbit(int x)
{
    return x&(-x);
}

void update(int id,int i,int x)
{
    i++;
    int len=s.size();
    while(i<=len){
        alp[id][i]+=x;
        i+=lowbit(i);
    }
}

int query(int id,int i)
{
    int res=0;
    while(i){
        res+=alp[id][i];
        i-=lowbit(i);
    }
    return res;
}

int main()
{
    int x; cin>>x;
	cin>>s;
    int len=s.size();
    for(int i=0;i<len;i++){
        update(s[i]-'a',i,1);
    }
    cin>>q;
    while(q--){
        cin>>t;
        if(t==1){
            cin>>pos>>c;
            pos--;
            update(s[pos]-'a',pos,-1);
            s[pos]=c;
            update(s[pos]-'a',pos,1);
        }
        else{
            cin>>l>>r;
            int cnt=0;
            for(int i=0;i<26;i++){
                if(query(i,r)-query(i,l-1)>0) cnt++;
            }
            printf("%d\n",cnt);
        }
    }
    return 0;
}

Measured memory_bytes: 51716
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    if (x<y) {
        if (y<z) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    } else {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2148