akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int a,b,c,d;cin >> a >> b >> c >> d;
    cout << max(a*b,c*d) << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define N 50 + 5

int main() {
	int n,A[N];
	long double cur;
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		scanf("%d", A + i);
	}
	sort(A+1,A+n+1);
	cur=A[1];
	for(int i=2; i<=n; i++){
		cur=(cur+A[i])/2;
	}

	printf("%.9Lf\n", cur);
}

Measured memory_bytes: 256
import numpy as np

s = np.array(list(input()), np.unicode)
sl = len(s)
t = np.array(list(input()), np.unicode)
tl = len(t)
equal = (s[:, None] == t[None, :])

dp = [np.zeros(tl + 1, np.int32)]
for i in range(sl):
    tmp = dp[-1].copy()
    np.maximum(tmp[1:], tmp[:-1] + equal[i], out=tmp[1:])
    np.maximum.accumulate(tmp, out=tmp)
    dp.append(tmp)

answer = ''
while sl > 0 and tl > 0:
    if s[sl - 1] == t[tl - 1]:
        sl -= 1
        tl -= 1
        answer += s[sl]
        continue

    if dp[sl - 1][tl] > dp[sl][tl - 1]:
        sl -= 1
    else:
        tl -= 1

print(answer[::-1])

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

using namespace std;

string str;

int main() {
cin >> str;
for (int i = 1; i < str.size(); i++) {
    if(str[i-1] =='A' && str[i]=='C') 
{printf("Yes\n"); return 0;}
}
printf("No\n");
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int par[20], rankh[20];
void init(int n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		rankh[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rankh[x] < rankh[y])par[x] = y;
	else {
		par[y] = x;
		if (rankh[x] == rankh[y])rankh[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int main() {
	init(13);
	unite(1, 3); unite(3, 5); unite(5, 7); unite(7, 8); unite(8, 10); unite(10, 12);
	unite(4, 6); unite(6, 9); unite(9, 11);
	int x, y;
	cin >> x >> y;
	if (same(x, y))cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using ll = long long;

int main()
{
	ll a, b, k;
	cin >> a >> b >> k;
	ll tempa = a;
	ll tempb = b;
	if (tempa < k)
	{
		tempa = 0;
		k = k - a;
		
	}
	else if (tempa >= k)
	{
		tempa = tempa - k;
		k = 0;
		
	}
	if (tempb < k)
	{
		tempb = 0;
		k = 0;
		
	}
	else if (tempb >= k)
	{
		tempb = tempb - k;
		k = k-b;
		
	}
	cout << tempa << " " << tempb << endl;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = list(input())
lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l, r])

pair = [0] * len(S)
for i in range(len(S)-1):
    if S[i] is 'A' and S[i+1] is 'C':
        pair[i+1] = pair[i] + 1
    else:
        pair[i+1] = pair[i]

for i in range(Q):
    ans = 0
    l = lr[i][0]-1
    r = lr[i][1]-1
    print(pair[r]-pair[l])


Measured memory_bytes: 23544
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define s(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)
#define NIL -1
#define MAXN 11

void solve()
{
    int n, w;
    cin >> n >> w;
    ll wi[n], vi[n];
    ll dp[n + 1][w + 1];
    for (int i = 0; i < n; i++)
    {
        cin >> wi[i] >> vi[i];
    }
    s(dp, 0);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            if (wi[i - 1] <= j)
                dp[i][j] = max(vi[i - 1] + dp[i - 1][j - wi[i - 1]], dp[i - 1][j]);
            else
                dp[i][j] = dp[i - 1][j];
        }
    }
    cout << dp[n][w] << "\n";
}
int main()
{
#ifdef WIN32
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

#ifndef WIN32
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#endif
    int t;
    t = 1;
    /// cin >> t;
    for (int I = 1; I <= t; I++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 82452
#include <iostream>
#include <string>
#include<iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include<queue>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include <map>
#include<string.h>
#include<sstream>
#include<stack>
#include<unordered_map>
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <cstdio>
#include <cstdlib>
#define ll long long
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 7;
const double ep = 0.0000000001;
const double pi = 3.14159265359;


ll com(const pair<ll, ll> &a,
	const pair < ll, ll > &b) {
	if (a.first == b.first) {
		if (a.second < b.second) {
			return 1;
		}
		else {
			return 0;
		}
	}
	else if (a.first > b.first) {
		return 1;
	}
	else {
		return 0;
	}
}


void fun(int ind, int i) {//get all combination with length 6
vector<vector<int>>v;
int k=0, arr[100];
vector <int>v1;
	if (ind == 6) {
		v.push_back(v1);
		return;
	}
	if (i >= k)
		return;
	v1[ind] = arr[i];
	fun(ind + 1, i + 1);
	fun(ind, i + 1);
}

int main()
{
	int n, k, arr[100005];
	cin >> n>>k;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int ans = inf;
		for (int i = 0; i < n; ++i) {
			int start = 0, end = n - 1,mid;
			while (start <= end) {
				mid = (start + end) / 2;
				if (mid - i + 1 >= k) {
					if (arr[mid] - arr[i] < ans) {
						ans = arr[mid] - arr[i];
					}
					end = mid - 1;
				}
				else {
					start = mid + 1;
				}
			}
		}
		cout << ans;
	return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main(){
  string s;
  cin >> s;
  string arr[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  ll ans;
  rep(i,7){
    if(s == arr[i]){
      ans = 7-i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc076/tasks/abc076_c

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int p, s, k, l;
string S, Sd, T;

int main()
{
  cin >> Sd >> T;

  s = p = 0;
  k = T.length();
  l = Sd.length();
  reverse(ALL(T));
  reverse(ALL(Sd));
  REP(i, l)
  {
    if (Sd[i] == T[p] || Sd[i] == '?')
    {
      if (p == 0)
        s = i;
      p++;
      if (p == k)
        break;
    }
    else if (p != 0)
    {
      i -= p;
      p = 0;
    }
  }

  S = "";
  if (p == k)
  {
    REP(i, l)
    {
      S += s <= i && i < s + k ? T[i - s] : Sd[i] == '?' ? 'a' : Sd[i];
    }
    reverse(ALL(S));
  }
  else
    S = "UNRESTORABLE";

  cout << S << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int array[100];

	int i, j, n, tmp;
	int number;
	int count = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &array[i]);
	}

	for (i = 1; i < n - 1; i++) {
		if (array[i] <array[i-1]&&array[i]>array[i+1]|| array[i] >array[i - 1] && array[i]<array[i + 1])count++;
	}
	printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
dp=[[0]*(n+1) for _ in range(n+1)]
for l in range(1,n+1):
    for i in range(n-l+1):
        j=i+l-1
        if (n-l)%2==0:
            dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j])
        else:
            dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j])
print(dp[0][n-1])

Measured memory_bytes: 113116
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int h = sc.nextInt();
        int w = sc.nextInt();

        Integer[] c = new Integer[]{sc.nextInt() - 1, sc.nextInt() - 1, 0};

        int dh = sc.nextInt() - 1;
        int dw = sc.nextInt() - 1;

        char[][] field = new char[h][w];

        for (int i = 0; i < h; i++) {
            field[i] = sc.next().toCharArray();
        }

        boolean[][] visited = new boolean[h][w];
        Deque<Integer[]> q = new ArrayDeque<>();
        q.add(c);
        int ans = -1;
        while (!q.isEmpty()) {
            Integer[] cur = q.poll();
            if (visited[cur[0]][cur[1]]) {
                continue;
            }
            visited[cur[0]][cur[1]] = true;
            if (cur[0] == dh && cur[1] == dw) {
                ans = cur[2];
                break;
            }
            for (int i = -2; i <= 2; i++) {
                for (int j = -2; j <= 2; j++) {
                    int x = cur[0] + i;
                    int y = cur[1] + j;
                    int cost = cur[2];
                    if (x >= 0 && y >= 0 && x < h && y < w && field[x][y] == '.' && !visited[x][y]) {
                        if (Math.abs(i + j) == 1 && (i == 0 || j == 0)) {
                            q.addFirst(new Integer[]{x, y, cost});
                        } else {
                            q.addLast(new Integer[]{x, y, cost + 1});
                        }
                    }
                }
            }
        }
        System.out.println(ans);


        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 77356
int main(void) {
    int n, m, en, i, l;
    int H[100], W[100];
    en = 0;
    for ( n = 0 ; en == 0 ; n++ ) {
        scanf("%d %d", &H[n], &W[n]);
        if ( H[n] == 0 && W[n] == 0 )   en = 1;
    }
    for ( m = 0; m < n - 1 ; m++ ) {
        for ( i = 0; i < H[m]; i++ ) {   
            for ( l = 0; l < W[m]; l++ ) {
                printf("#");
            }
            printf("\n");
        }
    printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

ll res[100100];
int used[100100];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k; cin >> n >> k;
	int cnt=0;
	ll sum=0;
	vector<pair<ll,int> > v;
	for(int i=0;i<n;i++){
		ll t,d; cin >> t >> d;
		t--;
		v.push_back(make_pair(d,t));
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	priority_queue<pair<ll,int> ,vector<pair<ll,int>>,greater<pair<ll,int> > > q;
	for(int i=0;i<k;i++){
		if(!used[v[i].second])cnt++;
		else q.push(v[i]);
		used[v[i].second]=1;
		sum+=v[i].first;

	}
	res[cnt]=sum;
	while(q.size()){
		for(int i=k;i<n;i++){
			if(used[v[i].second]==0){
				sum-=q.top().first;
				q.pop();
				used[v[i].second]=1;
				sum+=v[i].first;
				cnt++;
				res[cnt]=sum;
			}
			if(q.size()==0||cnt==k)break;
		}
		break;
	}
	ll ans=0;
	for(ll i=0;i<=k;i++){
		if(res[i])ans=max(ans,res[i]+i*i);
	}
	cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
  }
  int temp=a[0];
  int count=0;
  for(int i=0;i<n;i++) {
    if(a[i]<=temp) {
      count++;
      temp=min(temp,a[i]);
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >>  a[i];
  }

  for (int i = 0; i < N; i++) {
    if (a[i] % 2 == 0) {
      if (a[i] % 3 != 0 && a[i] % 5 != 0) {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }



    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();


        var x = sc.intarr;
        int A = x[0];
        int B = x[1];
        int C = x[2];

        if ((A < C && C < B) || (B < C && C < A))
        {
            wr.wri("Yes");
        }
        else wr.wri("No");










    }
}
    




class Scan
{
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
    public char[] chararr => str.ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
int main()
{
    char s[3];
    gets(s);
    int i,cnt=0,ans=0;
    for(i=0;i<3;i++)
    {
        if(s[i]=='R')
        {
            cnt++;
        }
        else
        {
            cnt=0;
        }
        if(cnt>ans)
        {
            ans=cnt;
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1644
#include <stdio.h>
int main()
{
	int a, i = 1;
	
	while(true)
	{
		scanf("%d", &a);
		if(a == 0)
		{
			break;
		}
		printf("Case %d: %d\n", i++, a);
	}
	
	return 0;
 } 


Measured memory_bytes: 2708
//scanf("%d",);
#include<bits/stdc++.h>
using namespace std;

int main(){
    int idx, n, a, max, max2=0;
    scanf("%d",&n);
    for (int i = 0; i < n; ++i){
    	scanf("%d",&a);
    	if (i == 0){
    		max = a;
    		idx = i;
    	}else{
    		if(max2<a){
    			if (max<a){
    				max2 = max;
    				max = a;
    				idx = i;
    			}else{
    				max2 = a;
    			}
    		}
    	}
    }
    for (int i = 0; i < n; ++i){
    	(i==idx)?printf("%d\n", max2):printf("%d\n", max);;
    }
    return 0;
}

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

int main(){
    int n,ans=0;cin>>n;vector<int> a(n+1,0),b(n),c(n);
    for(int i=0;i<n;i++) cin>>a.at(i);
    for(int i=0;i<n;i++) cin>>b.at(i);
    for(int i=0;i<n-1;i++) cin>>c.at(i);
    for(int i=0;i<n;i++){
        ans+=b.at(a.at(i)-1);
        if(a.at(i+1)-a.at(i)==1) ans+=c.at(a.at(i)-1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int A , B , C ;
    long long K;
    
    cin >> A >> B >> C >> K;
    if(K%2 == 0){
        cout << A-B << endl;
    }else if(K%2 !=0){
        cout << B-A << endl;
    }else if(A-B > 1000000000000000000 ||B-A >1000000000000000000){
        cout << "Unfair" << endl;
    }
        
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val S = readLine()!!
    var a = 0;var b = 0

    S.forEachIndexed { index, c ->
        if (index % 2 != Character.getNumericValue(c)) a++
        if ((index + 1) % 2 != Character.getNumericValue(c)) b++
    }
    println(Math.min(a, b))
}

Measured memory_bytes: 34356
import math


def hoge(s, e, value):
    s += l
    e += l
    d, l_running, r_running = rank, 1, 1

    while l_running or r_running:
        l_end_node, r_end_node = s >> d, e >> d
        l_end_leaf = l_end_node << d, (l_end_node + 1 << d) - 1
        r_end_leaf = r_end_node << d, (r_end_node + 1 << d) - 1

        if l_end_node == r_end_node:
            if l_end_leaf[0] == s and r_end_leaf[1] == e:
                # match
                lazy[l_end_node] += value
                break
        else:
            if l_running:
                if l_end_leaf[0] == s:
                    # match
                    lazy[l_end_node] += value
                    l_running = 0
                # ??????????????????????????????????????????????¶?????????????????????´???
                elif l_end_node >> 1 << 1 == l_end_node and l_end_node+1 < r_end_node:
                    # match
                    lazy[l_end_node+1] += value

            if r_running:
                if r_end_leaf[1] == e:
                    # match
                    lazy[r_end_node] += value
                    r_running = 0
                elif r_end_node >> 1 << 1 == r_end_node-1 and l_end_node+1 < r_end_node:
                    # match
                    lazy[r_end_node-1] += value

        if d > 0:
            # propagation
            if l_running:
                lazy_left, lazy[l_end_node] = lazy[l_end_node], 0
                lazy[l_end_node << 1] += lazy_left
                lazy[(l_end_node << 1)+1] += lazy_left
            if r_running:
                lazy_right, lazy[r_end_node] = lazy[r_end_node], 0
                lazy[r_end_node << 1] += lazy_right
                lazy[(r_end_node << 1)+1] += lazy_right

        d -= 1

def get_value(i):
    i += l
    v = 0
    for j in range(rank, -1, -1):
        v += lazy[i>>j]
    return v + tree[i]

n, q = map(int,input().split())
l = 1 << math.ceil(math.log2(n))
tree = [0]*(2*l)
lazy = [0]*(2*l)
rank = int(math.log2(len(tree)))
ans = []
ap = ans.append

for _ in [None]*q:
    query = list(map(int, input().split()))
    if query[0] == 0:
        hoge(query[1]-1, query[2]-1, query[3])
    else:
        ap(get_value(query[1]-1))

print("\n".join((str(n) for n in ans)))

Measured memory_bytes: 22680
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=54;
int n,m,q;
int a[N],b[N],c[N],d[N];
int A[15];
int ans;
inline int calc() {
	int ret=0;
	for (int i=1;i<=q;++i)
		ret+=(A[b[i]]-A[a[i]]==c[i])*d[i];
	return ret;
}
inline void smax(int &x,int y) {
	x=x>y?x:y;
}
inline void dfs(int step,int l,int r) {
	if (step==n+1) {
		smax(ans,calc());
		return ;
	}
//	if (r-l+1<n-step+1) return;
	for (int i=l;i<=r;++i) {
		A[step]=i;
		dfs(step+1,i,r);
		A[step]=0;
	}
}
int main() {
//	freopen("in2.txt","r",stdin);
	scanf("%d%d%d",&n,&m,&q);
	for (int i=1;i<=q;++i) scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
	dfs(1,1,m);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll a, b;
    cin >> a >> b;
    ll temp = a * b;
    if (temp & 1) {
        cout << "Odd" << endl;
    } else {
        cout << "Even" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string s;s = "CODEFESTIVAL2016";
  string t;cin>>t;
  int a = 0;
  for(int i = 0; t.size() > i; i++){
    if(s[i]!=t[i])a++;
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int mod = 1e9+7;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
int tab[1000100];

inline ll bw(ll x) { return max(-x, x); }
int main()
{
	ll suma = 0;
	int n;
	boost;
	cin >> n;
	FOR(i, 1, n) cin >> tab[i], suma += tab[i];
	
	ll res = INF, score = 0;
	FOR(i, 1, n-1)
	{
		score += tab[i];
		res = min(res, bw(score - (suma - score)));
	}
	
	cout << res;
}


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

using namespace std;

typedef long long/*--------------------*/ll;
typedef long double/*------------------*/ld;
typedef unsigned long long/*-----------*/ull;
typedef pair<ll, ll >/*----------------*/pll;
typedef vector<pll >/*-----------------*/vpll;

#define rep(i,a)/*---------------------*/for(i = 0 ; i < a ; i++)
#define repr(i,a)/*--------------------*/for(i = a ; i >= 0 ; i--)
#define REP(i,a,b)/*-------------------*/for(i = a ; i <= b ; i++)
#define REPR(i,a,b)/*------------------*/for(i = a ; i >= b ; i--)
#define PRINT_CASE/*-------------------*/cout << "Case "<< i << ": ";
#define opt/*--------------------------*/ios_base::sync_with_stdio(false)

#define scan(N)/*----------------------*/scanf("%lld",&N)
#define print(N)/*---------------------*/printf("%lld",N)
#define scan2(N1,N2)/*-----------------*/scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2)/*----------------*/printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3)/*--------------*/scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3)/*-------------*/printf("%lld %lld %lld",N1,N2,N3)

#define lb/*---------------------------*/lower_bound
#define ub/*---------------------------*/upper_bound
#define mem(a,b)/*---------------------*/memset(a,b,sizeof(a))
#define gcd(a, b)/*--------------------*/__gcd(a, b)
#define lcm(a, b)/*--------------------*/((a)*((b)/gcd(a,b)))
#define all(a)/*-----------------------*/a.begin(),a.end()

#define endl/*-------------------------*/'\n'
#define inf/*--------------------------*/(ll)2e15
#define MOD/*--------------------------*/(ll)1000000007
#define MAXN/*-------------------------*/500005


int main()
{
	opt;
	ll n,i;
	cin >> n;
	vector<ll> a(n),b(n),c(n);
	rep(i,n)
	{
		cin >> a[i];
	}
	rep(i,n)
	{
		cin >> b[i];
	}
	rep(i,n)
	{
		cin >> c[i];
	}
	ll ans = 0;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());  	
	sort(c.begin(), c.end());
	rep(i,n)
	{
		ll x = lower_bound(a.begin(), a.end(),b[i]) - a.begin();
		ll y = n - (upper_bound(c.begin(), c.end(),b[i]) - c.begin());
		//cout << x << " " << y << endl;
		ans += x*y;
	}
	cout << ans << endl;
}





Measured memory_bytes: 2560
{-# LANGUAGE ScopedTypeVariables, LambdaCase #-}

import qualified Data.List as List
import qualified Data.Set as Set

main :: IO ()
main = do
    [a, b] <- map read . words <$> getContents
    let winner = case (a, b) of 
                    (c, d) | c == d -> "Draw"
                    (1, _)          -> "Alice"
                    (_, 1)           -> "Bob"
                    _               -> if a > b then "Alice" else "Bob"
    putStrLn winner

Measured memory_bytes: 508
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

string s;

int main(){
	getline(cin,s);
	for(auto x:s){
		if(x == ',') putchar(' ');
		else putchar(x);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		//
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		String[] inputStr = null;
		int[] inputInt = null;
		try {
			inputStr = (input.readLine()).split(" ");
			inputInt = new int[inputStr.length];
			for (int i = 0; i < inputInt.length; i++) {
				inputInt[i] = Integer.parseInt(inputStr[i]);
			}
			System.out.println(countDivisors(inputInt));
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}

	public static int countDivisors(int[] divisors) {
		int countDivisors = 0;
		for (int i = divisors[0]; i <= divisors[1]; i++) {
			if (divisors[2] % i == 0) {
				countDivisors++;
			}
		}
		return countDivisors;
	}

}



Measured memory_bytes: 24352
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

void solve()
{
	int S, W;
	cin >> S >> W;
	cout << (S <= W ? "unsafe" : "safe") << endl;
}

int main()
{
	solve();

	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<stdio.h>
using namespace std;
int h,m,s,sum;
void pr(int x){
  if(x<10)cout<<"0";
  cout<<x;
}
void print(int x){
  pr(x/3600);
  cout<<':';
  pr(x/60%60);
  cout<<':';
  pr(x%60);
  cout<<endl;
}
int main(){
  while(cin>>h>>m>>s){
    if(h==-1&&m==-1&&s==-1)break;
    sum=h*60*60+m*60+s;
    sum=120*60-sum;
    print(sum);print(sum*3);
  }
}


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

int main(){
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  //

  double pi = 3.14159265359;

  double long_  = (60*H+M)*0.5*pi/180;
  double short_ = pi*M/30;

  double kakudo = abs(long_ - short_);
  kakudo = min(kakudo, 2*pi - kakudo);
  

  cout << fixed << setprecision(10) << sqrt( A*A+B*B-2*A*B*cos(kakudo) ) << endl;
  

  return 0;
}


Measured memory_bytes: 4228
var readline = require('readline')
var reader = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

var lines = [];
reader.on('line', function(line) {
  lines.push(line);
});

reader.on('close', function() {
  var N = Number(lines[0]);

  var D = {}, ans=0;
  for(var i=1; i<=N; ++i) {
    var d = Number(lines[i]);
    if(d in D) continue;
    D[d]=null;
    ans+=1;
  }

  console.log(ans);

});

Measured memory_bytes: 7500
main = do
  line <- getLine
  let 
    x = read $ head $ words line :: Int
    power a b = power_ 1 a b 
    power_ p a b 
      | b > 0     = power_ (p*a) a (b-1)
      | otherwise = p
    func i j x 
      | x == 1          = 1
      | power i j <= x  = max (func (i+1) j x) (func i (j+1) x)
      | otherwise       = choice (power (i-1) j) (power i (j-1))
    choice a b
      | a <= x && b <= x  = max a b
      | otherwise         = min a b
    in
      putStrLn $ show $ func 2 2 x
  


Measured memory_bytes: 508
def md_burger(n, x):
  if x == 1:
    if n == 0:
      return 1
    else:
      return 0
  elif 1 < x < a[n-1]+2:
    return md_burger(n-1, x-1)
  elif x == a[n-1]+2:
    return p[n-1]+1
  elif a[n-1]+2 < x < 2*a[n-1]+3:
    return p[n-1]+1+md_burger(n-1, x-2-a[n-1])
  else:
    return 2*p[n-1]+1

if __name__=="__main__":
  n, x = input().split()
  a = [1]
  p = [1]
  for i in range(0, int(n)):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)
  print(md_burger(int(n), int(x)))

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    int n; cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    ll tmp = 0;
    for(int t : a) tmp ^= t;
    
    for(int t : a)
        cout << (tmp ^ t) << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3960
#include<iostream>
#include<string>
using namespace std;
string str{};
char str1[] = {'J','O','I'};
char str2[] = {'I','O','I'};
bool find1(int i){
  for(int j = 0 ; j < 3 ; j++)
    if(str[i+j] != str1[j])
      return false;
  return true;
}
bool find2(int i){
  for(int j = 0 ; j < 3 ; j++)
    if(str[i+j] != str2[j])
      return false;
  return true;
}
int main(){
  while(getline(cin,str)){
    int cnt1{};
    int cnt2{};
    int len = str.length();
    for(int i = 0 ; i < len ; i++){
      if(find1(i))
        cnt1++;
      if(find2(i))
        cnt2++;
    }
    cout << cnt1 << endl;
    cout << cnt2 << endl;
  }
}



Measured memory_bytes: 3128
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)
#define AAA (1000000007)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


int main() {
	int i, j, k;
	ll N, M;
	ll X;
	string S;
	cin >> N >> S;

	vector<int> A;
	rep(i, 0, N) {
		A.push_back(S[i] - '0');
	}

	bool isAppe[10] = { false };
	bool isConnect[10][10] = { {false} };
	int sum[30001] = { 0 };


	isAppe[A[N - 1]] = true;
	for (i = N - 2; i > 0; --i) {

		sum[i] = sum[i + 1];
		rep(j, 0, 10) {
			if (isAppe[j]) {
				int p = A[i];
				if (!isConnect[p][j]) {
					sum[i] += 1;
				}
				isConnect[p][j] = true;

			}
		}
		isAppe[A[i]] = true;
	}
	bool isCount[10] = { false };
	int countSum = 0;
	ull ans = 0;
	for (i = 0; i < N - 2 && countSum < 10;++i) {
		if (!isCount[A[i]]) {
			isCount[A[i]] = true;
			ans += sum[i + 1];
			countSum++;

		}
	
	
	}

	cout << ans;
	return 0;
}



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

int main(){
    int a=0,b=0;
    string s = "";

    cin >> a >> b;

    if(a>b)
        s = "a > b";
    else if(a<b)
        s = "a < b";
    else
        s = "a == b";

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3168
import java.util.*;

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

        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();

        if((r*100+g*10+b)%4==0){
            System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;


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

	int n;
	cin >> n;
	//cout << (n * 800) << (200 * (n % 15));
	cout << (n * 800) - (200 * (n / 15)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n,h,w,i,a,b,count;
  scanf("%d %d %d",&n, &h, &w );
  for(i=0;i<n;i++){
    scanf("%d %d ",&a, &b);
    if(a>=h && b>=w ){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

string s, t;

void solve() {
  for (int i=0;i<s.size();i++) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

int main() {
  cin >> s >> t;
  solve();
}


Measured memory_bytes: 3628
N, A, B, C, D = map(int, input().split())
S = input()
Sac = S[A-1:C]
Sbd = S[B-1:D]
if "##" in Sac or "##" in Sbd:
    print("No")
elif C < D:
    print("Yes")
elif "..." in Sbd:
    print("Yes")
else:
    s1 = S[A-1:B-1] + "#" + S[B:C]
    s2 = S[A-1:D-1] + "#" + S[D:C]
    if "##" not in s1 or "##" not in s2:
        print("Yes")
    else:
        print("No")

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

int main(){
	int e;
	while( cin >> e , e ){
		int m = e;
		for(int z=0 ; z*z*z <= e ; ++z ){
			for(int y=0 ; z*z*z+y*y <= e ; ++y ){
				int x = e - ( z*z*z + y*y );
				m = min( x+y+z , m );
			}
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 868
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    string s;
    cin >> n >> s;
    int m = n / 2;
    string t = s.substr(0, m);
    cout << (s == t + t ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
D,X,=map(int,input().split())
An=[int(input()) for _ in range(N)]
c = 0
for n in range(N):
    i = 0
    while True:
        d = i*An[n] + 1
        if d > D:
            break
        c += 1
        i += 1
print(c+X)

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

//幅優先探索
//迷路の最短距離を求める
//まず、盤面のサイズと、迷路のスタート地点とゴール地点の座標が与えられる。
//次に、それぞれのマスが通行可能な空きマス(.)か通行不可能な壁マス(#)かという情報を持った盤面が与えられる。
//スタート地点とゴール地点は必ず空きマスであり、スタート地点からゴール地点へは、空きマスを辿って必ずたどり着ける。

// queue (FIFO) を使うのがスマート(atcoder調べ)
// pop() := キューの先頭要素を削除
// front() 先頭要素の参照
// push() := キューの末尾にデータを追加
// 出し入れするデータは座標

// 入力例
// 7 8
// 2 2
// 4 5
// ########
// #......#
// #.######
// #..#...#
// #..##..#
// ##.....#
// ########

// 出力例
// 11

int di[4] = {0, -1, 0, 1};
int dj[4] = {1, 0, -1, 0};

int main(){

    //入力
    int r, c, si, sj, gi, gj;
    cin >> r >> c;
    si = 1;
    sj = 1;
    gi = r;
    gj = c;

    int w = 0;
    // canGo[i][j] := (i, j) が壁ならばfalse, 通路ならばtrue
    vector<vector<bool> > canGo(r + 2, vector<bool> (c + 2, false));
    for(int i = 1; i <= r; i++){
        for(int j = 1; j <= c; j++){
            char input; cin >> input;
            if(input == '.'){
            canGo[i][j] = true;
            w++;
            }
        }
    }

    //まず最初にsの情報をキューに追加して、盤面を埋める
    queue<pair<int, pair<int, int> > > wait;
    wait.push(make_pair(0, make_pair(si, sj)));
    canGo[si][sj] = false;

    //以下、幅優先
    int ans = -1;   //ansを-1で初期化

    while(!wait.empty()){    //キュー画空になるまで
        //キューの先頭要素を取り出す
        int nowcost = wait.front().first;
        int nowi = wait.front().second.first;
        int nowj = wait.front().second.second;

        wait.pop();

        //ゴールにたどり着いたらそのコストが答え
        if(nowi == gi && nowj == gj){
            ans = nowcost;
            break;
        }

        //四方向を探索
        for(int k = 0; k < 4; k++){
            int nexti = nowi + di[k];
            int nextj = nowj + dj[k];

            //その方向に進めるなら
            if(canGo[nexti][nextj]){
                //そのマスにキューを追加し
                //再度検索することの内容に壁で埋める
                wait.push(make_pair(nowcost + 1, make_pair(nexti, nextj)));
                canGo[nexti][nextj] = false;
            }
        }
    }

    //出力
    if(ans == -1) cout << -1 << endl;
    else cout << w - ans - 1 << endl;
    return 0;

}


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

dp = [10**9]*N
dp[0] = 0

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

print(dp[N-1])

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
// #define forn(i,n) for(ll i=0; i<(n); i++)
#define forn for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back


template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}
void min_self(int &a, int b){
	a = min(a, b);
}

const int INF = 1e9 + 5;

void solve(){
	int n, k;
	cin >> n >> k;
	vi a(n);
	for(auto &it: a){
		cin >> it;
	}
	vi dp(n, INF);
	// min cost of stone n
	dp[0] = 0;
	forn{
		for(int j=i+1; j<n&&j<=i+k; j++){
			min_self(dp[j], dp[i]+abs(a[i]-a[j]));
		}
	}
	cout << dp[n-1] << en;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
const Int MAX = 10000;
Int fac[MAX], finv[MAX], inv[MAX];
int COMinit = ([](){
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}(), 0);
Int COM(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
Int dp[22][1010];
int main() {
    int N, K; cin >> N >> K;
    vector<int> A(K); for (auto &a : A) cin >> a;
    dp[0][0] = 1;
    for (int i = 0; i < K; i++) {
        for (int n = 0; n <= N; n++) {
            for (int m = 0; n + m <= N; m++) {
                dp[i + 1][n + m] += dp[i][n] * COM(N - n, m) % MOD * COM(N - m, A[i] - m);
                dp[i + 1][n + m] %= MOD;
            }
        }
    }
    cout << dp[K][N] << '\n';
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,x,m,l[10],r[10],s[10];
int pp[6],ans[6],mx;
void dfs(int p){
  if(p==n){
    for(int i=0;i<m;i++){
      int sm=0;
      for(int j=l[i];j<=r[i];j++)sm+=pp[j];
      if(sm!=s[i])return;
    }
    int sss=0;
    for(int i=0;i<n;i++)sss+=pp[i];
    if(mx<sss){mx=sss;for(int i=0;i<n;i++)ans[i]=pp[i];}
    return;
  }
  for(int i=0;i<=x;i++)
    pp[p]=i,dfs(p+1);
}
 
int main(){
  cin>>n>>x>>m;
  for(int i=0;i<m;i++){
    cin>>l[i]>>r[i]>>s[i];
    l[i]--,r[i]--;
  }
  mx=-1;
  dfs(0);
  if(mx==-1)cout<<-1;
  else for(int i=0;i<n;i++){
      if(i)cout<<" ";
      cout<<ans[i];
    }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i<n; i++)
#define per(i,a,n) for (int i = n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define all(now) (now).begin(),(now).end()
#define fi first
#define se second
#define SZ(now) ((int)(now).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod = 1000000007;
inline int read(int &n){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}return n = x*f;}
ll powmod(ll a,ll b,ll mod) {ll res = 1; a%=mod; assert(b>=0); for(;b; b>>=1){if(b&1)res = res*a%mod; a = a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N = 2e5+7;
int T,n,m;
ll a[N],sum[N];
int main()
{
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    scanf("%d", &n);
    rep(i,1,n+1){
        scanf("%lld", &a[i]);
        sum[i] = sum[i - 1] + a[i];
    }

    ll p[5] = {0, 0, 0, 0, 0}, minAns = 0x7fffffff;
    int l = 1, r = 3;
    rep(i,2,n-1){
        while (l < i && abs(sum[l] - sum[0] - (sum[i] - sum[l])) >= abs(sum[l + 1] - sum[0] - (sum[i] - sum[l + 1])))
            l++;
        while (r < n && abs(sum[r] - sum[i] - (sum[n] - sum[r])) >= abs(sum[r + 1] - sum[i] - (sum[n] - sum[r + 1])))
            r++;

        ll cnt = 0,cnt2=0x7fffffff;
        p[1] = sum[l] - sum[0];
        p[2] = sum[i] - sum[l];
        p[3] = sum[r] - sum[i];
        p[4] = sum[n] - sum[r];
        // minAns = min(minAns, cnt - cnt2);
        minAns = min(   minAns,max(p[1], max(p[2], max(p[3], p[4]))) - min(p[1], min(p[2], min(p[3], p[4])))  );
    }
    printf("%lld\n", minAns);
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long
#define m 1e18
using namespace std;

int main()
{
    ll n, k, r, s, p, i, sum = 0;
    string t, c;

    cin >> n >> k >> r >> s >> p >> t;

    c = t;

    for(i = 0; i < n; i++){
        if(t[i] == 'r') t[i] = 'p';
        else if(t[i] == 's') t[i] = 'r';
        else t[i] = 's';
    }

    for(i = k; i < n; i++){
        if(t[i] == t[i - k]) t[i] = 'z';
    }

    for(i = 0; i < n; i++){
        if(t[i] != 'z'){
            if(t[i] == 'r') sum += r;
            else if(t[i] == 's') sum += s;
            else sum += p;
        }
    }

    //cout << t << endl;
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  int n, x, p, ans = 10000;
  cin >> x >> n;
  vector<int> v(110);
  for (int i = 0; i < 110; i++) {
    v[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> p;
    v[p] = 1;
  }
  ans = -1;
  for (int i = 0; i < 110; i++) {
    if (v[i] == 0 && (abs(ans - x) > abs(i - x) ||
                      (abs(ans - x) == abs(i - x) && ans > i))) {
      ans = i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
s = input()
t = input()
ans = len(t)
#startが開始位置を決める
#jはtの長さ分sを探索するための変数
for start in range(len(s)-len(t)+1):
    l = 0
    for j in range(len(t)):
        if s[j+start] != t[j]:
            l += 1
    ans = min(ans,l)
print(ans)

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

int main()
{
    int n;
    std::cin>>n;
    std::vector<int> a(n);//出席番号順
    std::vector<int> ans(n);//登校順序
    for(int i=0;i<n;i++){
        std::cin>>a[i];
        a[i]--;
    }
    for(int i=0;i<n;i++){
        ans[a[i]] = i+1;
    }
    for(int i=0;i<n;i++)std::cout<<ans[i]<<" ";
}

Measured memory_bytes: 1536
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
idx=1
#print(idx,a[idx-1])
for i in range(1,n+1):
    idx=a[idx-1]
    #print(idx,a[idx-1])
    if idx==2:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 7084
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
	public static void main(String[] args) throws IOException {
		String input;
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			input = String.valueOf(br.readLine());
		}

		Map<String, Integer> count = new HashMap<String, Integer>();

		for(int i = 0; i < input.length(); i++) {
			String chr = input.substring(i, i+1);
			if (count.containsKey(chr)) {
				count.put(chr, count.get(chr) + 1);
			} else {
				count.put(chr, 1);
			}
		}

		for(Entry<String, Integer> entry: count.entrySet()) {
			Integer value = entry.getValue();
			if(value % 2 ==1) {
				System.out.println("No");
				return ;
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 21332
s = input()
n = len(s)

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

if len(dic) == 1:
    if n == 1:
        print('YES')
    else:
        print('NO')
elif len(dic) == 2:
    if n == 2:
        print('YES')
    else:
        print('NO')
else:
    maxi = max(dic.values())
    mini = min(dic.values())
    if maxi - mini <= 1:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 39280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int w,a,b;
	cin >> w >> a >> b;
	if(b<=a+w&&a<=b+w) cout << 0 << endl;
	else cout << min(abs(b-(a+w)),abs(a-(b+w))) << endl;
}

Measured memory_bytes: 256