akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;

int n, k;
vector<p> v;
ll dsum = 0;
ll ksum = 0;
ll res = 0;
map<int, int> ate;

void countKsum(){
  for(auto a : ate){
    ksum += (a.second > 0);
  }
}

int main(){
  vector<p> tmp;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int d, k;
    cin >> k >> d;
    v.push_back({d, k});
  }
  sort(rall(v));

  for (int i = 0; i < k; i++) {
    ate[v[i].second]++;
    dsum += v[i].first;
    if(ate[v[i].second] >= 2) tmp.push_back(v[i]);
  }
  sort(all(tmp));
  countKsum();
  res = ksum * ksum + dsum;

  for (int i = k; i < n; i++) {
    int tmpSize = int(tmp.size());
    if(tmpSize == 0) break;
    if(ate[v[i].second] == 0){
      ate[v[i].second]++;
      dsum += v[i].first - tmp[0].first;
      ksum++;
      res = max(res, ksum * ksum + dsum);
      tmp.erase(tmp.begin() + 0);
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 4468
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

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

    int ans = 1 << 30;
    for (int s = 0; s < (1 << n); ++s) {
        vector<int> c(n), sc(n), d(n);
        for (int i = 0; i < n; ++i) {
            c[i] = s & (1 << i) ? a[i] : b[i];
        }
        sc = c;
        sort(begin(sc), end(sc));
        vector<bool> used(n);
        bool ok_outer = true;
        for (int i = 0; i < n; ++i) {
            int f = !(s & (1 << i));
            int x = s & (1 << i) ? a[i] : b[i];
            bool ok = false;
            for (int j = 0; j < n; ++j) {
                if (sc[j] == x && (iabs(i - j) & 1) == f && !used[j]) {
                    d[i] = j;
                    used[j] = true;
                    ok = true;
                    break;
                }
            }
            if (!ok) {
                ok_outer = false;
            }
        }
        if (ok_outer) {
            int scr = 0;
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < i; ++j) {
                    scr += d[j] > d[i];
                }
            }
            ans = min(ans, scr);
        }
    }

    if (ans >= (1 << 30)) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc103/tasks/abc103_d

int main() {
    int N, M; cin >> N >> M;
    vector<P> ab;
    REP(i, M) {
        int a, b; cin >> a >> b;
        ab.push_back({b, a});
    }

    sort(ab.begin(), ab.end());

    int now = 0;
    int ans = 0;
    for (P p : ab) {
        int right = p.first;
        int left = p.second;
        if (left >= now) {
            now = right;
            ans ++;
        }
    }

    cout << ans << "\n";


    return 0;
}


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

long long int getint(){
    long long int n;
    scanf("%lld",&n);
    return n;
}

int main(void){
    long long int N=getint();
    long long int A=getint();
    long long int B=getint();
    long long int C=getint();
    long long int D=getint();
    long long int a=C+D;
    long long int b=B-A;
    long long int c=-C*(N-1);
    long long int d=-D*(N-1);
    int f=0;
    for(long long int i=0;i<=N;i++){
        if(i*a+c>=b&&i*a+d<=b){
            f=1;
            i=N+1;
        }
    }
    cout<<(f?"YES":"NO")<<endl;
    return 0;
}

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

using namespace std;
const int N = 105, W = 100005;
int n, g;
int w, val;
long long d[W];
int main() {
	cin >> n >> g;
	for(int i = 1; i <= n; i ++) {
		cin >> w >> val;
		for(int j=g; j>=w; j--)
            d[j] = max(d[j], d[j - w] + val);
	}
	cout << d[g];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
#define PB push_back
#define MP make_pair
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main(){
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n;cin>>n;
  map<string,int> mp;
  for(int i=0;i<n;++i){
    string s;cin>>s;
    mp[s]++;
  }
  cout<<"AC x "<<mp["AC"]<<'\n';
  cout<<"WA x "<<mp["WA"]<<'\n';
  cout<<"TLE x "<<mp["TLE"]<<'\n';
  cout<<"RE x "<<mp["RE"]<<'\n';
  
  return 0;
}
//2020.07.05 20:02:30


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,l; cin>>n>>l;
  int taste=0;
  vector<int>vec_abs(n);
  vector<int>vec(n);
  for(int i=1;i<=n;i++){
    taste+=l+i-1;
    vec_abs[i-1]=abs(l+i-1);
    vec[i-1]=l+i-1;
  }
  sort(vec_abs.begin(),vec_abs.end());
  sort(vec.begin(),vec.end());
  if(l+n-1<0) cout<<taste-vec[n-1]<<endl;
  else cout<<taste-vec_abs[0]<<endl;
}
    
    


Measured memory_bytes: 256
#!python3.4
# -*- coding: utf-8 -*-
# abc158/abc158_c
import sys,math

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    A, B = i2nn()
    a_left = math.ceil(A / 0.08)
    a_right = int((A+1) // 0.08)
    b_left = math.ceil(B / 0.1)
    b_right = int((B+1) // 0.1)
    # print(a_left, b_left, a_right, b_right)
    left = max(a_left, b_left)
    right = min(a_right, b_right)
    if left < right:
        print(left)
    else:
        print(-1)
    return

main()


Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {
	static long ans = Integer.MAX_VALUE;
	static long s;
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		long h = sc.nextLong();
		long w = sc.nextLong();
		long s1, s2;
		s = h * w;
		for(int i = 0; i <= h; i++) {
			s1 = w * i;
			s2 = w * ((h-i)/2);
			update(s1, s2);
			s2 = (h - i) * (w / 2);
			update(s1, s2);
		}
		for(int i = 0; i <= w; i++) {
			s1 = h * i;
			s2 = h * ((w - i)/2);
			update(s1, s2);
			s2 = (h / 2) * (w - i);
			update(s1, s2);
		}
		System.out.println(ans);
	}
	static void update(long s1, long s2) {
		if(s1 == 0 || s2 == 0) {
			return;
		}
		long s3 = - s1 - s2 + s;
		long sa = Math.max(s1, Math.max(s2, s3)) - Math.min(s1, Math.min(s2, s3));
		if(ans > sa) {
			ans = sa;
		}
	}
}


Measured memory_bytes: 21972
X,K,D = map(int,input().split())
b = 0

b = abs(X)//D
if b <= K:
    K -= b
else:
    b = K
    K = 0
    
    
if X > 0:
    X -= D*b
elif X < 0:
    X += D*b
    
if K == 0:
    print(abs(X))
else:
    if X == 0:
        if K % 2 == 0:
            print(X)
        else:
            print(D)
    elif X > 0:
        if abs(X-D) < abs(X):
            X -= D
            K -= 1
        if K % 2 == 0:
            print(abs(X))
        else:
            print(min(abs(X-D),abs(X+D)))
    elif X < 0:
        if abs(X+D) < abs(X):
            X += D
            K -= 1
        if K % 2 == 0:
            print(abs(X))
        else:
            print(min(abs(X-D),abs(X+D)))



Measured memory_bytes: 9176
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, q;
	vector<int> S(100000);
	vector<int> T(50000);
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> S[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> T[i];
	}
	int ans = 0;
	
	for (int i = 0; i < q; i++) {
		auto itr = find(S.begin(), S.end(), T[i]);
		if (itr != S.end()) ans++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3408
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> G(n);
  REP(i, n) {
    int u, k;
    cin >> u >> k, u--;
    REP(j, k) {
      int v;
      cin >> v, v--;
      G[u].push_back(v);
    }
  }
  vector<bool> ed(n, false);
  vector<int> dis(n, -1);
  queue<P> que{};
  ed[0] = 1;
  que.push(P(0, 0));
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    int id = p.first;
    int d = p.second;
    dis[id] = d;
    REP(i, G[id].size()) {
      if (ed[G[id][i]] == true) continue;
      ed[G[id][i]] = true;
      que.push(P(G[id][i], d + 1));
    }
  }
  REP(i, n) { cout << i + 1 << " " << dis[i] << endl; }
}


Measured memory_bytes: 3164
# frozen_string_literal: true

S = gets.chomp.split("")
T = gets.chomp.split("")

mapping = {}
S.each_with_index {|s, i|
  t = T[i]

  if mapping[s] && mapping[s] != t
    puts "No"
    exit
  end

  mapping[s] = t
}

if mapping.length != mapping.values.uniq.length
  puts "No"
else
  puts "Yes"
end


Measured memory_bytes: 22780
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
using namespace std;
map<string,int>a;
int main()
{
    int n,choose,temp,l,r;
    string color;
    scanf("%d", &n);
    while (n--)
    {
        scanf("%d ", &choose);
        switch (choose)
        {
        case 0:
            cin >> color >> temp;
            //scanf("%s%d", color, &temp);
            a[color] = temp;
            break;
        case 1:
            cin >> color;
            if (a.find(color) != a.end())printf("%d\n", a[color]);
            else printf("0\n");
            break;
        case 2:
            cin >> color;
            a.erase(color);
        }
    }
    
}


Measured memory_bytes: 27816
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define LL long long
#define pb push_back
#define mp make_pair
#define M 1000000007
#define y1 fwfwkpoe
 
#define K 200001

int n;
int a[K];

int main() {
	scanf("%d", &n);
	
	FOE(i, 1, n) scanf("%d", &a[i]);
	
	sort(a + 1, a + n + 1);
	
	if (a[n] - a[1] >= 2) {
		puts("No"); return 0;	
	}
	
	if (a[n] == a[1]) {
		if (a[n] == n - 1) {
			puts("Yes"); return 0;	
		}
		
		int maxpairs = n / 2;
		
		if (a[n] <= maxpairs) {
			puts("Yes"); return 0;	
		}
		
		puts("No"); return 0;
	}
	
	int low = 0, high = 0;
	
	FOE(i, 1, n) {
		if (a[i] == a[1]) low++;
		if (a[i] == a[n]) high++;	
	}
	
	int maxpairs = high / 2;
	
	if (high == 1) {
		puts("No"); return 0;	
	}
	
	if (a[n] > low + maxpairs) {
		puts("No"); return 0;	
	}
	
	if (a[1] == 1 && low >= 2) {
		puts("No"); return 0;	
	}
	
	if (a[n] < low + 1) {
		puts("No"); return 0;	
	}
	
	puts("Yes"); return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
2文字以上。aaもだめか
abc
abcab
総数くらい？
aaabbc
a
ab
abc
abcabcabc...のかたちしかないっぽい
*/
int main(){
  string S; cin>>S;
  ll sz=S.size(), A,B,C;
  A=B=C=0;
  for(int i=0; i<sz; i++){
    if(S[i]=='a')
      A++;
    else if(S[i]=='b')
      B++;
    else
      C++;
  }
  if(abs(A-B)>1 || abs(B-C)>1 || abs(A-C)>1)
    cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
Pll P[int(1e5+5)];

int main(){
  cin >> N;
  for (int i = 0; i < N; i++){
    ll A, B; cin >> A >> B;
    P[i] = {A, B};
  }
  sort(P, P + N, greater<Pll>());

  cout << P[0].fi + P[0].se << endl;

  return 0;
}


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

int main() {
  int k;
  vector<int> antennas;
  int amount = 5;

  while (amount--) {
    int input;
    cin >> input;
    antennas.push_back(input);
  }

  cin >> k;

  for (int i = 0;i < 5;i++) {
    for (int j = i+1;j < 5;j++) {
      if(k < abs(antennas[i] - antennas[j])) {
        cout << ":(";
        return 0;
      }
    }
  }
  cout << "Yay!";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

const ll mod = 1e9 + 7;

const int MAX = 2010;
V<ll> memo(MAX, -1);
ll ans = 0;

ll calc(int p) {
  ll ret = 0;
  if (memo[p] != -1) return memo[p];
  if (p < 3) return memo[p] = 0;
  if (p >= 3) ret++;
  for (int i = 3; i <= p; i++) {
    ret += calc(p - i);
    ret %= mod;
  }
  return memo[p] = ret;
}

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

  ll ans = calc(n);
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(x, y) for(ll x = 0; x < (y); x++)
#define REP(x, z, y) for(ll x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; FOR(cnt, 0, getline(stream,res,sp_word))
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((ll)log10((double)(x)) + 1)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;

int main(){
  ll x;
  scanf("%lld",&x);
  printf("%lld",(x / 11 * 2) + ( x % 11 == 0 ? 0 : (x  % 11 <= 6 ? 1 : 2)));
  return 0;
}

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

int main() {
  int N;
  cin >> N ;
  int sum =0 ;
  int sum2 =0 ;
   vector<int> A(N);
    
  for (int i = 0; i < N; i++) {  
   cin >> A.at(i);}
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
  for (int i = 0; i < N; i++) {  
  
  
  
    if (i%2==0){
   
    sum += A.at(i);
  }
  else if (i%2!=0) {
   
    sum2  += A.at(i);
  
  }
  }
  cout << sum-sum2 << endl;
  
  
}


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

using namespace std;

const int e = 1e5;

int main()
{
     int t;
     cin >> t;
     map<string, int>kt;
     while(t --){
        string t;
        cin >> t;
        kt[t] ++;
     }
     cout << "AC" <<" "<<"x"<<" "<<kt["AC"]<<"\n";
     cout << "WA" <<" "<<"x"<<" "<<kt["WA"]<<"\n";
     cout << "TLE" <<" "<<"x"<<" "<<kt["TLE"]<<"\n";
     cout << "RE" <<" "<<"x"<<" "<<kt["RE"]<<"\n";
}


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

using namespace std;

int main()
{
	
    int k,m,n,a,b;
    cin>>n>>k>>a>>b;
    if(n>k)
    {
    	m=a*k+(n-k)*b;
    }
    else 
    m=a*n;
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

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

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
struct Bit {
    vector<T> bit[2];
    int N;

    Bit(int n): N(n) { for (int i = 0; i < 2; i++) bit[i].assign(n + 1, 0); }

    //[1, n]
    void init(int n) {
        for (int i = 0; i < 2; i++) bit[i].assign(n + 1, 0);
        N = n;
    }

    T sub_sum(int p, int i) {
        T s = 0;
        while (0 < i) {
            s += bit[p].at(i);
            i -= i & -i;
        }
        return s;
    }
    // 1-indexed
    T sum(int i) { return sub_sum(0, i) + sub_sum(1, i) * i; }
    // [a, b]
    T sum(int a, int b) { return sum(b) - sum(a - 1); }

    void sub_add(int p, int i, T v) {
        while (i <= N) {
            bit[p].at(i) += v;
            i += i & -i;
        }
    }
    //[a, b] 1-indexed
    void add(int a, int b, T v) {
        sub_add(0, a, -v * (a - 1));
        sub_add(1, a, v);
        sub_add(0, b + 1, v * b);
        sub_add(1, b + 1, -v);
    }
};  

int main() {
    int n;
    ll d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> m(n);
    for (int i = 0; i < n; i++) {
        int x, h;
        cin >> x >> h;
        m.at(i) = make_pair(x, h);
    }
    sort(m.begin(), m.end());
 
    auto binary_search = [&](ll x){
        int ng = n;
        int ok = -1;
 
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
 
            if (m.at(mid).first <= x) ok = mid;
            else ng = mid;
        }
        return ok;
    };
    
    Bit<ll> bit(n);
    //bit.init(n + 1);
    for (int i = 0; i < n; i++) {
        bit.add(i + 1, i + 1, m.at(i).second);
    }

    ll cnt = 0;
    for (int l = 0; l < n; l++) {
        ll h = bit.sum(l + 1, l + 1);
        if (h <= 0) continue;

        int r = binary_search(m.at(l).first + d * 2);
        ll c = (h + a - 1) / a;
        cnt += c;
        bit.add(l + 1, r + 1, c * -a);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 6528
//package cp;
import java.util.*;
import java.io.*;
public class Main {
	long gcd(long a,long b) {if(b==0)return a;else return gcd(b,a%b);}
	void swap(long a,long b) {long temp=a;a=b;b=temp;}
	StringBuilder sb=new StringBuilder();
	Integer[] ARR=new Integer[5];
	//Integer sort-TLE-Initialize object elements i.e a[0].
	void divisor(long n,int start) {
		int cnt=0;for(int i=start;i<=Math.sqrt(n);i++) {
		if(n%i==0) {if(i==n/i)cnt++;else cnt+=2;}}}
	
	public static void main(String[] args) throws IOException {	
		PrintWriter out = new PrintWriter(System.out);
		Readers.init(System.in);
		Main obj=new Main();
		int n=Readers.nextInt();
		int k=Readers.nextInt();
		long[] a=new long[n+1];
		for (int i = 1; i < a.length; i++) {
			a[i]=Readers.nextLong();
		}
		long[] dp=new long[n+1];
		dp[1]=0;
		for (int i = 2; i <=n; i++) {
			long minn=Integer.MAX_VALUE;
			for (int j = 1; j <=k ; j++) {
				if((i-j)>=1)minn=Math.min(minn, dp[i-j]+Math.abs(a[i]-a[i-j]));
			}
			dp[i]=minn;
		}
//		dp[2]=Math.abs(a[2]-a[1]);
//		for (int i = 3; i <=n; i++) {
//			long minn=Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]),dp[i-2]+Math.abs(a[i]-a[i-2]));
//			dp[i]=minn;
//		}
		System.out.println(dp[n]);
		out.flush();
	}
}
class Readers {
 
    static BufferedReader reader;
 
    static StringTokenizer tokenizer;
 
 
 
    /** call this method to initialize reader for InputStream */
 
    static void init(InputStream input) {
 
        reader = new BufferedReader(
 
                     new InputStreamReader(input) );
 
        tokenizer = new StringTokenizer("");
 
    }
 
 
 
    /** get next word */
 
    static String next() throws IOException {
 
        while ( ! tokenizer.hasMoreTokens() ) {
 
            //TODO add check for eof if necessary
 
            tokenizer = new StringTokenizer(
 
                   reader.readLine() );
 
        }
 
        return tokenizer.nextToken();
 
    }
 
 
 
    static int nextInt() throws IOException {
 
        return Integer.parseInt( next() );
 
    }
 
	
 
    static double nextDouble() throws IOException {
 
        return Double.parseDouble( next() );
 
    }
    
    
    static long nextLong() throws IOException{
    	
		return Long.parseLong(next());
	}
 
}


Measured memory_bytes: 44732
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;



int main(){
  int n, ans=1;
  cin>>n;
  int p[n];

  REP(i, n) {
    cin>>p[i];
  }
  vector<int> k(n+1, 0);

  REP(i, n){
    k[p[i]] = k[p[i]-1]+1;
    ans=max(ans, k[p[i]]);
    //cout<<p[i]<<" "<<k[p[i]]<<endl;
  }
  cout<<n-ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    answer = [0 for i in range(N+1)]

    for i in range(0, N):
        for j in range(i+1, N):
            # A-A, E-E, A-B, D-Eは近道を使えない
            if j <= X or Y <= i:
                answer[j-i] += 1
                continue
            # B-Dは近道使うだけ
            if i == X and j == Y:
                answer [1] += 1
                continue
            # A-Cは近道or直接
            if i < X and j < Y:
                answer[min(j-i, (X-i)+(Y-j)+1)] += 1
                continue
            # C-Eも同様
            if i > X and j > Y:
                answer[min(j-i, (j-Y)+(i-X)+1)] += 1
                continue
            # A-D
            if i < X and j == Y:
                answer[(X-i)+1] += 1
                continue
            # B-E
            if i == X and j > Y:
                answer[(j-Y)+1] += 1
                continue
            # B-C
            if i == X and j < Y:
                answer[min(j-i, 1+(Y-j))] += 1
                continue
            # C-D
            if i > X and j == Y:
                answer[min(j-i, 1+(i-X))] += 1
                continue
            # A-E
            if i < X and j > Y:
                answer[(X-i)+(j-Y)+1] += 1
                continue
            if i > X and j < Y:
                answer[min(j-i, (i-X)+(Y-j)+1)] += 1
                continue
            raise ValueError("error")

    for i in range(1, N):
        print(answer[i])


if __name__ == '__main__':
    main()


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

class B {
    static void Main(string[] args) {
        int N = int.Parse(Console.ReadLine());

        var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

        for (int i = 0; i < N; i++) {
            if (A[i] % 2 == 0) {
                if (A[i] % 3 != 0 && A[i] % 5 != 0) {
                    Console.WriteLine("DENIED");
                    return;
                }
            }

        }

        Console.WriteLine("APPROVED");

    }
}

Measured memory_bytes: 13268
///==================================================///
///                HELLO WORLD !!                    ///
///                  IT'S ME                         ///
///               BISHAL GAUTAM                      ///
///         [ bsal.gautam16@gmail.com ]              ///
///==================================================///
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define nl puts("")
#define SZ(x) x.size()
#define pb(x) push_back(x)
#define X first
#define Y second
#define pii pair<int,int>
#define mpr(a,b) make_pair(a,b)
#define S(a) scanf("%d",&a)
#define P(a) printf("%d",a)
#define SL(a) scanf("%lld",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define all(v) v.begin(),v.end()
#define clr(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define fr(i,a,n) for(i=a;i<=n;i++)
#define rf(i,a,n) for(i=n;i>=a;i--)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
///==========CONSTANTS=============///
///  Digit     0123456789012345678 ///
#define MX     200001
#define inf    1000000000
#define MD     1717171769LL
#define eps    1e-9
///===============================///

ll LCM(ll a,ll b){
    return a/__gcd(a,b)*b;
}

ll x;
int main()
{
   int n;
   cin>>n;
   ll L=1LL;
   for(int i=1;i<=n;i++){
    cin>>x;
    L=LCM(L,x);
   }
   cout<<L<<endl;
}


Measured memory_bytes: 256
N = int(input())
S=input()

#dp[i][j]はi文字目からスタートする文字列と，j文字目からスタートする文字列の共通部分長
dp=[[0]*(N+1) for _ in range(N+1)]

ans=0
for i in range(N-1,-1,-1):
    for j in range(N-1,i,-1):
        if S[i]==S[j]:
            dp[i][j]=max(dp[i][j],dp[i+1][j+1]+1)
            ans = max(ans,min(dp[i][j],j-i))
        else:
            dp[i+1][j+1]=0

print(ans)

Measured memory_bytes: 229768
fn main() {
    let vec_num : Vec<i64> = read_vec();

    let mut cant_move : bool = false;

    let mut squares: i64 = 1;
    for val in vec_num {
    	squares *= val;
    	if val == 1 {
    		cant_move = true;
    	}
	}

    let ans:i64 = if cant_move {1} 
    			else if squares % 2 == 0 {squares / 2} 
    			else {squares / 2 + 1};

    println!("{}", ans );
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc  =new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		double ans = (a * b) /3.305785;

//		BigDecimal x = new BigDecimal(ans);
//		BigDecimal y = x.setScale(6, BigDecimal.ROUND_DOWN);

		System.out.println(ans);

	}

}

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

using namespace std;
typedef long long ll;
const int Maxn = 1e6 + 5;
int N, Q, M, Cnt;
int A, B, C;
ll Ans;
struct Node
{
    int A, B, C;
    bool operator < (const Node &Temp) const
    {
        return C < Temp.C;
    }
}Edge[Maxn];
int H[Maxn], F[Maxn];

int Find(int X)
{
    if (X == F[X]) return X;
    return F[X] = Find(F[X]);
}

int main()
{
    memset (H, 127, sizeof H);
    scanf ("%d %d", &N, &Q);
    for (int i = 1; i < N; ++i) F[i] = i;
    for (int i = 0; i < Q; ++i)
    {
        scanf ("%d %d %d", &A, &B, &C);
        Edge[++Cnt] = Node{A, B, C};
        H[A + 1] = min(H[A + 1], C + 1);
        H[B + 1] = min(H[B + 1], C + 2);
    }
    for (int i = 1; i < (N << 1); ++i) H[i] = min(H[i], H[i - 1] + 2);
    for (int i = 1; i < (N << 1); ++i)
    {
        A = i % N, B = (i - 1) % N;
        Edge[++Cnt] = Node{A, B, H[i]};
    }
    sort (Edge + 1, Edge + Cnt + 1);
    for (int i = 1; i <= Cnt; ++i)
    {
        A = Edge[i].A, B = Edge[i].B, C = Edge[i].C;
        int FA = Find(A), FB = Find(B);
        if (FA != FB) Ans += C, F[FA] = FB;
    }
    printf ("%lld\n", Ans);
}

Measured memory_bytes: 15408
import math

a, b, C = map(int, input().split())
s = a * b * math.sin(math.radians(C)) / 2
print(s)
c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(C))
c = c2 ** 0.5
print(a + b + c)
h = s * 2 / a
print(h)



Measured memory_bytes: 5716
#!/usr/bin/env python3
import sys


def solve_(S: str, K: int, used):
    #print(S, K, used)
    mn = 'z'
    tmp = set()
    for i, c in enumerate(S):
        if c < mn and not c in used:
            tmp = set()
            for j in range(5):
                tmp.add(S[i:i + j + 1])
            mn = c
        elif c == mn:
            for j in range(5):
                tmp.add(S[i:i + j + 1])
    if len(tmp) < K:
        used.append(mn)
        return solve_(S, K - len(tmp), used)
    else:
        tmp = list(tmp)
        tmp.sort()
        return tmp[K - 1]

def solve(S, K):
    ret = solve_(S, K, [])
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    K = int(next(tokens))  # type: int
    solve(s, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(S: str):
    print(700 + 100 * int(S.count("o")))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  unsigned long long A, B, N;
  cin >> A >> B >> N;
  if(N + 1 >= B){
    cout << ((B-1)*A)/B << endl;
  }else{
    cout << ((N)*A)/B << endl;
  }
}

Measured memory_bytes: 3608
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
# D問題なんてさっさと解いて、いっぱいすやすやしようね( ˘ω˘ )ｽﾔｧ
# ( ˘ω˘ )ｽﾔｧ ( ˘ω˘ )ｽﾔｧ ( ˘ω˘ )ｽﾔｧ ( ˘ω˘ )ｽﾔｧ ( ˘ω˘ )ｽﾔｧ

a,b,x0=gsmi

#面積の問題にする
x=x0.to_f/a
ans=0
if (a*b.to_f)/2<=x
  # 空いた部分は三角形
  s2 = a*b-x
  xh = 2 * s2 / a.to_f
  atan = Math.atan2(xh,a)
  ans = atan*180/Math::PI
else
  # 水は三角形
  xh = 2 * x / b.to_f
  atan = Math.atan2(b,xh)
  ans = atan*180/Math::PI
end

puts ans

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

#define ll long long
#define ar array
 
using namespace std;

int main() {

    int a, b, c, d, e, k;
    
    cin >> a >> b >> c >> d >> e >> k;
    
    if(e - a > k){
    	cout << ":(" << endl;
	}
	else{
		cout << "Yay!" << endl;
	}

    return 0;
}

Measured memory_bytes: 256
#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 N,M;
  cin >> N >> M;
  rep(i,M){
    int A;
    cin >> A;
    N -= A;
  }
  cout << max(-1,N) << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
int n,i=1;
main(){
    std::cin>>n;
    for(;(i*i+i)/2<n;i++);
    for(;i>0;i--){
        if(n-i>=0){
            std::cout<<i<<'\n';
            n-=i;
        }
    }
}

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

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

  if (x < 1200)
    cout << "ABC" << endl;
  else
    cout << "ARC" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define ull unsigned long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define meme(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define mod 1'000'000'007
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
} 

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int n,i;
    cin>>n;
    int arr[n];
    fo(i,n){
        cin>>arr[i];
    }
    int dp[n];
    dp[0]=0;
    dp[1] = abs(arr[1]-arr[0]);
    Fo(i,2,n){
        int k = abs(arr[i]-arr[i-1])+dp[i-1];
        int y = abs(arr[i]-arr[i-2])+dp[i-2];
        dp[i] = min(k,y);
    }
    cout<<dp[n-1]<<"\n";
}


Measured memory_bytes: 4400
#include<iostream>
using namespace std;
int N,K,R,S,P;
string s;
bool exs[1<<17];
int main() {
	cin >> N >> K >> R >> S >> P >> s;
	int ans = 0;
	for(int i=0; i<N; i++) {
		if(i<K || s[i-K]!=s[i] || !exs[i-K]) {
			ans += s[i]=='r' ? P:s[i]=='s' ? R:S;
			exs[i] = true;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
# 最長共通部分　LCS ***未完成***
strA = input()
strB = input()
### 一致したら左上+1、そうでない場合は上か左のMAX
# / | 0 | A | B | C | B | A |
# 0 | 0 | 0 | 0 | 0 | 0 | 0 |
# B | 0 | 0 | 1 | 1 | 1 | 1 |
# B | 0 | 0 | 1 | 1 | 2 | 2 |
# A | 0 | 0 | 1 | 1 | 2 | 3 |
dp = [[0] * (len(strA) + 1) for _ in range(len(strB) + 1)]

for i, A in enumerate(strA, 1):
    for j, B in enumerate(strB, 1):
        if A == B:
            dp[j][i] = dp[j - 1][i - 1] + 1
        else:
            dp[j][i] = max(dp[j - 1][i], dp[j][i - 1])
ans = ""
cnt = 1
lstAns = dp[-1]
x, y = len(strA), len(strB)
while x > 0 and y > 0:
    if dp[y][x] == dp[y - 1][x]:
        y -= 1
    elif dp[y][x] == dp[y][x - 1]:
        x -= 1
    else:
        x -= 1
        y -= 1
        ans = strA[x] + ans

print(ans)

Measured memory_bytes: 113372
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
	int a,b;
	while(~scanf("%d%d",&a,&b))
	{
		if(a-b>=0)
			printf("%d\n",a-b);
		else
			printf("0\n");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);


int main() {
    cin>>N>>K;
    vec a(N);
    rep(i,N) cin>>a[i];
    reps(i, K, N){
        cout<<(a[i] > a[i - K] ? "Yes" : "No")<<endl;
    }
}


Measured memory_bytes: 4840
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
#include <stack>
#include <cstring>

#define ll long long
#define MP make_pair
#define PB push_back
#define P push
#define f first
#define se second
#define S size()
#define B begin()
#define E end()
#define PI acos(-1)
#define fscan1(n)  scanf("%d",&(n));
#define fscan2(n,m)  scanf("%d %d",&(n),&(m));
#define fscan3(n,m,k)  scanf("%d %d %d",&(n),&(m),&(k));

const int N = 1e5 + 100;
const int M = 2e5 + 100;
const ll oo = 1e18;

int n, m, k, t, q, h, a, b, c, x, y, z;
using namespace std;

ll ar[N];
ll dp[N];


int main(){
	
	cin >> n >> k;
	for(int i = 1; i < n; i++) dp[i] = oo;
	for(int i = 0; i < n; i++){
		cin >> ar[i];
		for(int j = i - k; j < i && i; j++){
			(j < 0) ? j = 0:0;
			dp[i] = min(dp[i], dp[j] + abs(ar[i] - ar[j]));
		}

	}
	

	cout << dp[n - 1] << endl;


	return 0;
 }




Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <map>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n;i>s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
typedef long long ll;
//static const ll MOD = 1e9 + 7;
static const ll MOD = 1+ 7;
static const ll INF = (ll)1 << 62;

string s[100001];
map<string, ll> m;

int main() {
	ll n; cin >> n;
	rep(i, 0, n) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
		m[s[i]]++;
	}

	ll ans = 0;
	for (map<string, ll>::iterator it = m.begin(); it != m.end(); it++) {
		if (it->second > 1) {
			ans += it->second*(it->second - 1) / 2;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 18176
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	
	vector<ll> p(a), q(b), r(c);
	for(int i = 0; i < a; ++i) {
		cin >> p[i];
	}
	
	for(int i = 0; i < b; ++i) {
		cin >> q[i];
	}
	
	for(int i = 0; i < c; ++i) {
		cin >> r[i];
	}
	
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	sort(r.begin(), r.end());
	
	priority_queue<ll, vector<ll>, greater<ll>> pq;
	
	for(int i = a - 1; i > a - x - 1; i--) {
		pq.push(p[i]);
	}
	
	for(int i = b - 1; i > b - y - 1; i--) {
		pq.push(q[i]);
	}
	
	while( r.size() && r.back() > pq.top() ) {
		pq.pop();
		pq.push(r.back());
		r.pop_back();
	}
	
	
	ll ans = 0LL;
	//while( !pq.empty() ) {
	while( pq.size() ) {
		ans += pq.top();
		pq.pop();
	}

	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char s[3],tmp;
	scanf("%s",s);
	if(s[0]>s[1])
	{
		tmp=s[0];
		s[0]=s[1];
		s[1]=tmp;
		//printf("The First If: %s\n",s);
	}
	if(s[0]>s[2])
	{
		tmp=s[0];
		s[0]=s[2];
		s[2]=tmp;
		//printf("The Second If: %s\n",s);
	}
	if(s[1]>s[2])
	{
		tmp=s[1];
		s[1]=s[2];
		s[2]=tmp;
		//printf("The Third If: %s\n",s);
	}
	//printf("%s\n",s);
	printf("%s",strcmp(s,"abc")==0||strcmp(s,"ABC")==0?"Yes":"No");
	return 0;
}
		

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){ 
    int x,a,b;
    cin >> x >> a >> b;

    if(abs(x-a) > abs(x - b)) puts("B");
    else puts("A");
}   

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

#define End exit(0)
#define LL long long
#define mp make_pair
#define SZ(x) ((int) x.size())
#define GO cerr << "GO" << endl
#define DE(x) cout << #x << " = " << x << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

void proc_status()
{
	freopen("/proc/self/status","r",stdin);
	string s; while(getline(cin, s)) if (s[2] == 'P') { cerr << s << endl; return; }
}

template<typename T> inline T read() 
{
	register T x = 0;
	register char c; register int f(1);
	while (!isdigit(c = getchar())) if (c == '-') f = -1;
	while (x = (x << 1) + (x << 3) + (c ^ 48), isdigit(c = getchar()));
	return x * f;
}

template<typename T> inline bool chkmin(T &a,T b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a,T b) { return a < b ? a = b, 1 : 0; }

const int maxN = 1e7 + 2;
const int mod = 998244353;

int qpow(int a, int b)
{
    int ans = 1;
    for (; b; b >>= 1, a = 1ll * a * a % mod)
        if (b & 1) ans = 1ll * ans * a % mod;
    return ans;
}

inline void Inc(int &x) { x < 0 ? x += mod : 0; }

int fac[maxN + 2], ifac[maxN + 2], pw2[maxN + 2];

void init(int N = 1e7)
{
    fac[0] = 1;
    for (int i = 1; i <= N; ++i) fac[i] = (LL) fac[i - 1] * i % mod;
    ifac[N] = qpow(fac[N], mod - 2);
    for (int i = N - 1; i >= 0; --i) ifac[i] = (LL) ifac[i + 1] * (i + 1) % mod;
    pw2[0] = 1;
    for (int i = 1; i <= N; ++i) pw2[i] = pw2[i - 1] * 2ll % mod;
}

int C(int n, int m)
{
    if (n < m) return 0;
    return (LL) fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

int n;

void input() { n = read<int>(); }

void solve()
{
    int ans = qpow(3, n);
    for (int i = n / 2 + 1; i <= n; ++i)
        Inc(ans -= 2ll * C(n, i) * pw2[n - i] % mod);
    printf("%d\n", ans);
}

int main() 
{ 
    input(), init(), solve();
	return 0;
}



Measured memory_bytes: 117376
#include <stdio.h>
#include <algorithm>

using namespace std;
typedef long long llong;

#define MAX 200001

int main()
{
  int N, ans = 0;
  llong A[MAX];

  scanf("%d", &N);

  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
  }

  sort(A, A + N);
  int Amax = A[N - 1];
  int chk[Amax + 1];
  for (int i = 0; i <= Amax; i++)
  {
    chk[i] = 0;
  }
  // エスとラテネスの篩
  for (int i = 0; i < N; i++)
  {

    // for (int j = i + 1; j < N; j++)
    // {
    //   if (A[j] % A[i] == 0)
    //     B[j] = false;
    // }
    if (chk[A[i]] == 0)
    {
      for (int j = 2; j * A[i] <= Amax; j++)
      {
        chk[j * A[i]]++;
      }
    }
    if (i > 0 && A[i] == A[i - 1])
      chk[A[i]]++;
  }

  for (int i = 0; i < N; i++)
  {
    if (chk[A[i]] == 0)
      ans++;
  }
  printf("%d\n", ans);

  return 0;
}

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

int main() {
	int N;  cin >> N;
	vector<long long> a(N), b(N);
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i < N; i++) cin >> b[i];

	long long cnt = 0;
	for (int i = 0; i < N; i++) {
		if (a[i] < b[i]) cnt += (b[i] - a[i]) / 2;
		if (a[i] > b[i]) cnt -= (a[i] - b[i]);
	}

	if (cnt >= 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 384
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        Set<Integer> set =
            IntStream.rangeClosed(1,N).boxed().collect(Collectors.toSet());
        for(int i=0;i<K;i++){
            int d = sc.nextInt();
            for(int j=0;j<d;j++){
                Integer a = sc.nextInt();
                if(set.contains(a))
                    set.remove(a);
            }
        }
        System.out.println(set.size());
    }

}


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

int main() {
    int h, w;
    std::cin >> h >> w;
    int cnt = 0;
    for (int i = 0; i < h; i++) {
        std::string s;
        std::cin >> s;
        for (int j = 0; j < w; j++) if (s[j] == '#') cnt++;
    }
    std::cout << (cnt == h + w - 1 ? "Possible" : "Impossible") << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define M 1000000
using namespace std;

//vector<ll> ;

void answer(){
    string s;
    cin>>s;
    ll t,f=0;
    cin>>t;
    std::deque<char> d;
    for(int i=0;i<s.size();i++) d.pb(s[i]);
    while(t--){
        ll tp; cin>>tp;
        if(tp==1){
            f+=1;continue;
        }
        ll p;char c;
        cin>>p>>c;
        if(f%2==1){
            if(p==2) d.push_front(c);
            else d.pb(c);
        }
        else{
            if(p==1) d.push_front(c);
            else d.pb(c);
        }
    }
    if(f%2==0)
    for(auto i=d.begin();i!=d.end();i++) cout<<*i;
    if(f%2==1)
    for (auto it = d.rbegin(); it != d.rend(); ++it) cout<<*it;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int q;
    //cin>>q; while(q--)
        answer();
    return 0;
}

Measured memory_bytes: 976
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    S = input()
    if S == 'AAA' or S == 'BBB':
        print('No')
    else:
        print('Yes')
    return


# B
def B():
    N, A, B = LI()
    ans = N // (A + B) * A + min(N % (A + B), A)
    print(ans)
    return


# C
def C():
    A, B = LI()
    for i in range(1, 1001):
        if i * 8 // 100 == A and i * 10 // 100 == B:
            print(i)
            return
    print(-1)
    return


# D
def D():
    s = S()
    d = deque(s)
    q = I()
    f = 1
    for i in range(q):
        query = input().split()
        if len(query) == 1:
            f *= -1
        else:
            if query[1] == '1':
                if f == 1:
                    d.appendleft(query[2])
                else:
                    d.append(query[2])
            else:
                if f == 1:
                    d.append(query[2])
                else:
                    d.appendleft(query[2])
    ans = ''.join(d)
    if f == -1:
        ans = ans[::-1]
    print(ans)
    return


# E
def E():
    return


# F
def F():
    return


# Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 76264
from collections import defaultdict

n,m = map(int, input().split())
dic = defaultdict(lambda:0)
for _ in range(n):
  ar = list(map(int, input().split()))
  for i in range(1,len(ar)):
    dic[ar[i]] += 1

ans = 0
for i,v in dic.items():
  if v == n:
    ans += 1
print(ans)

Measured memory_bytes: 3316