akhauriyash/Code-Regression huggingface dataset:
#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 K;
  cin >> K;
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[K - 1]<< endl;
}

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

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

    set<int> p;
    for (int i = 1; i <= n; i++) {
        int p_;
        cin >> p_;
        p.insert(p_);
    }

    int ans, dif = 0;
    while (1)
    {
        auto f = p.find(x - dif);
        if (f == p.end()) {
            ans = x - dif;
            break;
        }

        f = p.find(x + dif);
        if (f == p.end()) {
            ans = x + dif;
            break;
        }
        dif++;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3640
class Graph(): #non-directed
    def __init__(self,n,edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0] - 1].append(e[1] - 1)
            self.graph[e[1] - 1].append(e[0] - 1)
            self.deg[e[0] - 1] += 1
            self.deg[e[1] - 1] += 1

from itertools import permutations

N, M = map(int, input().split())
E = [tuple(map(int, input().split())) for _ in range(M)]

G = Graph(N, E)
res = 0

for p in permutations(range(N)):
    if p[0] != 0:
        continue
    for i in range(N - 1):
        if not p[i + 1] in G.graph[p[i]]:
            break
    else:
        res += 1

print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    if((s[0] == s[s.size() - 1]) ^ (s.size() % 2)) {
        cout << "First" << endl;
    }
    else {
        cout << "Second" << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};



int main(){
  int n;
  cin>>n;
  int a,b;
  a=n/10;
  b=n-a*10;
  if(a==9||b==9){
    cout<<"Yes";
  }else{
    cout<<"No";
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H,W;
    H = sc.nextInt();
    W = sc.nextInt();
    int a[][] = new int[H][W];
    for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
        a[i][j] = sc.nextInt();
      }
    }
    
    int count = 0;
    int s1,s2,s3,s4;
    List<String> list = new ArrayList<String>();
    for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
        if(i == H-1 && j == W-1) break;
        if(a[i][j] % 2 == 1){
          count++;
          if(j <= W-2){
            a[i][j]--;
            a[i][j+1]++;
            s1 = i+1;
            s2 = j+1;
            s3 = i+1;
            s4 = j+2;
            list.add(s1 + " " + s2 + " " + s3 + " " + s4);
          }else{
            a[i][j]--;
            a[i+1][j]++;
            s1 = i+1;
            s2 = j+1;
            s3 = i+2;
            s4 = j+1;
            list.add(s1 + " " + s2 + " " + s3 + " " + s4);
          }
        }
      }
    }
    System.out.println(count);
    list.forEach(System.out::println);
  }
}

Measured memory_bytes: 106640
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
#define fr(a, b, c) for(int a = b; a >= c; a--)
#define all(a) a.begin(), a.end()
#define vll vector<ll>
#define vi vector<int>
using namespace std;


//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}

const ll MOD = 998244353;
const ll N = 2e5 + 7;
const ll inf = 1e9 + 5;





ll n, k, dp[N];
vll v;
//base case: i == n
//states: index, curVal
//transitions: index + 1 .... + k

ll solve(ll idx){
    if (idx == n - 1) return 0;
    ll ans = inf;
    if (dp[idx] != -1) return dp[idx];
    f(i,1,k + 1){
        if (idx + i < n)
            ans = min(ans, solve(idx + i) + abs(v[idx + i] - v[idx]));
    }
    return dp[idx] = ans;

}

int main() {
    MohamedMotaz
    memset(dp, -1, sizeof(dp));
    cin >> n >> k;
    v.resize(n);
    f(i,0,n) cin >> v[i];
    cout << solve(0);
}






Measured memory_bytes: 7296
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
#define LL long long

int n;
const int N = 1e3+7;
int cnt[N];

int main() {
    memset( cnt, 0, sizeof(cnt) );
    scanf( "%d", &n );
    for( int i = 2; i <= n; ++i ) {
        int x = i;
        for( int j = 2; j <= x; ++j ) {
            while( x%j == 0 ) {
                cnt[j] += 1;
                x /= j;
            }
        }
        cnt[x] += 1;
    }
    LL ans = 1;
    for( int i = 2; i <= n; ++i ) {
        ans = ( 1LL * ans * ( cnt[i]+1 ) ) % 1000000007;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 1000

void out(int A[],int B) {
  int a;
  for(a=0;a<B;a++){
    if(a>0) printf(" ");
    printf("%d",A[a]);
  }
  printf("\n");
}
void sort(int A[],int B){
  int a,b,c;
  for(a=1;a<B;a++){
    b = A[a];
    c = a-1;
    while(c>=0&& A[c]>b){
      A[c+1]=A[c];
      c--;
    }
    A[c+1]=b;
    out(A,B);
  }
}



    
int main(){
  int A,a,b;
  int B[N];

  scanf("%d",&A);
  if(A==0||A>100)return 0;
  for(a=0;a<A;a++) scanf("%d",&B[a]);

  out(B,A);
  sort(B,A);

  return 0;
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
const int64_t MAXT = 200010;

int main()
{
  int64_t N, C, s, t, c, ans = 0;
  cin >> N >> C;
  vector<vector<int64_t>> T(31, vector<int64_t>(MAXT, 0));
  for (int i = 0; i < N; i++)
  {
    cin >> s >> t >> c;
    T[c][s * 2 - 1]++;
    T[c][t * 2]--;
  }
  for (int i = 1; i <= 30; i++)
  {
    for (int j = 1; j <= MAXT; j++)
    {
      T[i][j] += T[i][j - 1];
    }
  }
  for (int i = 0; i <= MAXT; i++)
  {
    int64_t tmp = 0;
    for (int j = 1; j <= 30; j++)
    {
      if (T[j][i] >= 1)
        tmp++;
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 50304
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

string divide[4] = {"dream","dreamer", "erase", "eraser"};

int main(){
    string s;
    cin >> s;

    reverse(s.begin(),s.end());
    rep(i, 4) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for(ll i = 0; i < s.size();){
        bool can2 = false;
        for(int j = 0; j < 4; j++) {
            string d = divide[j];
            if(s.substr(i, d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    } 

    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
}
  

Measured memory_bytes: 512
using System;

    class Program
    {
        static void Main(string[] args)
        {
            String str1, str2, str3;
            int a, b;
            int sum = 0;
            char op;

            while (true)
            {

                string[] str = Console.ReadLine().Split(' ');
                str1 = str[0];
                str2 = str[1];
                str3 = str[2];

                a = int.Parse(str1);
                b = int.Parse(str3);
                op = char.Parse(str2);

                if (op == '+')
                {
                    sum = a + b;
                } else if (op == '-')
                {
                    sum = a - b;
                } else if (op == '*')
                {
                    sum = a * b;
                }else if (op == '/')
                {
                    sum = a / b;
                }else
                {
                    break;
                }
             Console.WriteLine(sum);
            }
        }
    }



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

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

int f[100000 + 5];

int main() {
  ios::sync_with_stdio(0);
  int n;
  long long ans = 0;
  cin >> n;
  for (int i = 0; i <= n; i++) {
    cin >> f[i];
  }
  for (int i = 1; i <= n; i++) {
    int b;
    cin >> b;
    int t = min(f[i - 1], b);
    b -= t;
    ans += t;
    t = min(f[i], b);
    f[i] -= t;
    ans += t;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int N, l;
	int sum = 0;
	int max_l = 0;

	cin >> N;

	for (int ni = 0; ni < N; ni++) {
		cin >> l;
		sum += l;
		if (l > max_l) max_l = l;
	}

	if (sum - max_l > max_l) printf("Yes");
	else printf("No");

	//printf("%6f", ans);

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)
ll n,d,e[13]={},c;

int f(ll c){
  ll ans=24,cnt=1;
  fr(i,23){
    if((c>>i)&1){
      ans=min(ans,cnt);
      cnt=1;
    }
    else cnt++;
  }
  return min(ans,cnt);
}

int rec(int i,ll c){
  //cout<<i<<" "<<(bitset<23>(c))<<endl;
  if(i==12){
    if(e[12]) return f(c+(1<<11));
    else return f(c);
  }
  if(e[i]==1) return max(rec(i+1,c+(1<<(i-1))),rec(i+1,c+(1<<(23-i))));
  if(e[i]==2) return rec(i+1,c+(1<<(i-1))+(1<<(23-i)));
  return rec(i+1,c);
}

int main(){
  cin>>n;
  fr(i,n){
    cin>>d;
    if(d==0){cout<<0<<endl;return 0;}
    if(++e[d]>2){cout<<0<<endl;return 0;}
    if(d==12&&e[d]>1){cout<<0<<endl;return 0;}
  }
  cout<<rec(1,0)<<endl;
}

Measured memory_bytes: 256
import math

a,b = input().split()

a = int(a)

n1 = int(b[0])
n2 = int(b[2])
n3 = int(b[3])

resposta = ((a * n1 * 100) + (a * n2 * 10) + (a *n3))//100

print(resposta)


Measured memory_bytes: 62092
#include<bits/stdc++.h>
using namespace std;
int main(){
     int n, m, sum;
    scanf("%d %d %d", &n, &m, &sum);
    for (int i = 0; i < m;i++){
        printf("%d ", sum);
    }
    if(sum==2||sum==1){
        for (int i = 0; i < n - m;i++){
            printf("%d ", 3);
        }
    }
    else{
        for (int i = 0; i < n - m;i++){
            printf("%d ", sum - 1);
        }
    }
}

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

int main() {
    int N;
    cin >> N;
    for (int i=1; i<10; i++) {
        for (int j=i; j<10; j++) {
            if (i*j==N) {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 2 * 1000 * 100 + 17;

int n, a[MAXN], b[MAXN], ans;
map<int, int> mp;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	iota(b + 1, b + n + 1, 1);
	sort(b + 1, b + n + 1, [](int i, int j) { return a[i] < a[j]; });
	for (int i = 1; i <= n; i++)
		mp[a[b[i]]] = i;
	for (int i = 1; i <= n; i++)
		if (i % 2)
			ans += (mp[a[i]] % 2 == 0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>
 
int main() {
    int H, W, i, j;
    while (scanf("%d%d", &H, &W) == 2 && (H || W)) {
        for (j = 0; j < W; j++) {
            printf("#");
        }
        printf("\n");
        for (i = 1; i < H-1; i++) {
            printf("#");
            for (j = 1; j < W - 1; j++) {
                printf(".");
            }
            printf("#\n");
        }
        for (j = 0; j < W; j++) {
            printf("#");
        }
        printf("\n\n");
    }
    return 0;
}

Measured memory_bytes: 588
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#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(){
    string s,t;
    cin >> s >>t;
    if(s.size()==t.size()-1){
        rep(i,s.size()){
            if(s[i]!=t[i]){
                cout << "No";
                return 0;
            }
        }
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3624
n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|i| i.to_i}
for i in 1..n-1
	puts a.join(" ")
	v=a[i]
	j=i-1
	while j>=0 && a[j] > v
		a[j+1] = a[j]
		j+=-1
		a[j+1]=v
	end
end
puts a.join(" ")

Measured memory_bytes: 8712
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define MOD 998244353

int main()
{
  long long n;cin>>n;
  long long i;
  vector<long long> rev(n/2,1);
  vector<long long> num(n/2,0);
  long long left=MOD-2;
  for(i=1;i<n/2;i++)
  {
    num.at(i)=i;
  }
  while(left!=0)
  {    
    if(left%2==1)
    {
      for(i=1;i<n/2;i++)
      {
        rev.at(i)=(rev.at(i)*num.at(i))%MOD;
      }
    }
    left/=2;
    for(i=1;i<n/2;i++)
    {
      num.at(i)=(num.at(i)*num.at(i))%MOD;
    }
  }
  long long ans=1;
  long long n3=3;
  left=n;
  while(left!=0)
  {
    if(left%2==1)
    {
      ans=(n3*ans)%MOD;
    }
    left/=2;
    n3=(n3*n3)%MOD;
  }
  long long mina = 1;
  long long minsum = 1;
  for(i=1;i<n/2;i++)
  {
    mina =(mina*((n-i+1)*(rev.at(i)*2)%MOD)%MOD)%MOD;
    minsum=(mina+minsum)%MOD;
  }
  ans=(ans+(MOD-minsum)*2)%MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 78464
N, M = map(int, input().split())        # N = 配列サイズ
A = list(map(int, input().split()))
imos = [0]*(2*M+1)
imos2 = [0]*(2*M+1)
res = 0
for i in range(N-1):
    a, b =A[i]-1, A[i+1]-1
    if a>b: b += M
    res += b-a
    if a+2>=b+1:
        continue
    imos[a+2] += 1
    imos[b+1] -= 1
    imos2[b+1] -= (b-a-1)
P = [0]
l = 0
for k, s in zip(imos, imos2):
    l += k
    P.append(P[-1] + l + s)
Q = P[1:-1]
R = [x+y for x, y in zip(Q[:M],Q[M:])]
print(res - max(R))




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

int H, W;
vector<string> S;
vector<vector<bool>> visited;
vector<int> dy = { 1, -1, 0, 0 };
vector<int> dx = { 0, 0, -1, 1 };
long long black, white;

void dfs(int y, int x) {
  visited.at(y).at(x) = true;
  if (S.at(y).at(x) == '#') black++;
  else white++;
  for (int d = 0; d < 4; d++) {
    int ny = y + dy.at(d);
    int nx = x + dx.at(d);
    if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
    if (visited.at(ny).at(nx)) continue;
    if (S.at(ny).at(nx) == S.at(y).at(x)) continue;
    dfs(ny, nx);
  }
}

int main() {
  cin >> H >> W;
  S.resize(H);
  for (int i = 0; i < H; i++) cin >> S.at(i);
  visited = vector<vector<bool>>(H, vector<bool>(W));
  long long ans = 0;
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (S.at(y).at(x) == '.') continue;
      if (visited.at(y).at(x)) continue;
      black = 0; white = 0;
      dfs(y, x);
      ans += black * white;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 15488
#include<bits/stdc++.h>
using namespace std;
int tmp, ans;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string S;
    cin >> S;
    for (int i = 1; i < N; ++i) {
        for (int j = 0; i+j < N && tmp < i; ++j) {
            if (S[j] == S[i+j]) tmp++;
            else {
                if (tmp != 0) {
                    ans = max(ans, tmp);
                    tmp = 0;
                }
            }
        }
        ans = max(ans, tmp);
        tmp = 0;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int h, w, n; cin >> h >> w >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++ i) cin >> a[i];
    vector <int> v;
    for (int i = 0; i < n; ++ i) while (a[i] --) v.push_back(i + 1);
    vector <vector <int> > grid(h, vector <int> (w));
    int x = 0, y = 0;
    for (int i = 0; i < v.size(); ++ i) {
        grid[x][y] = v[i];
        if (x & 1) -- y; else ++ y;
        if (y < 0) ++ x, ++ y;
        if (y >= w) ++ x, -- y;
    }
    for (int i = 0; i < h; ++ i) {
        for (int j = 0; j < w; ++ j) {
            cout << grid[i][j];
            cout << (j + 1 == w ? '\n' : ' ');
        }
    }
    return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    int a[100002], b[100002];
    int d[100002] {0};
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        d[a[i] - 1]++;
        d[b[i] - 1]++;
    }
    for(int i = 0; i < n; i++){
        if(d[i] % 2 == 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1408
#pragma GCC target("avx2")
#pragma GCC optimize("O3")

# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;



int main () {
   SpeedForce;
	cin >> n >> m;
	cout << max(0, n - 2 * m);
   return Accepted;
}

// B...a

Measured memory_bytes: 18688
using namespace std; 
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll,ll>  
#define MOD 1000000007
#define mit map::iterator
#define pii pair<ll,ll>
#define rep(i,a,b)	for(ll i=a;i< b;i++)
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
typedef  long long   int  ll;
//stringstream convert; 
  //  convert << number; 
  //  string s = convert.str();
 ll fact[500005],invfact[500005]; 
 ll power(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
 ll inv(ll x)
{
	return power(x,MOD-2);
}
ll divide(ll x, ll y)
{
	return (x*inv(y))%MOD;
}
ll C(ll n, ll k)
{
	if(k > n) return 0;
	return divide(fact[n], (fact[n - k]*fact[k])%MOD);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
bool isPrime(int n) {
 
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
} 
void init(){
	ll p=MOD;
	fact[0]=1;
	ll i;
	for(i=1;i<500005;i++){
		fact[i]=(i*fact[i-1])%p;
	}
	i--;
	invfact[i]=power(fact[i],p-2);
	for(i--;i>=0;i--){
		invfact[i]=(invfact[i+1]*(i+1))%p;
	}
}
ll s;
ll fun(ll a)
{
	if(a==0)
	return 0;
	return a+fun(a-1);
}
priority_queue < pair<ll,ll> , vector<pair<ll,ll> >,greater<pair<ll,ll> > > gq;

#define MAXN   10000001 
ll spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (ll i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
    for (ll i=3; i*i<MAXN; i++) 
    {
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
set<ll> getFactorization(ll x) 
{ 
    set<ll> ret; 
    while (x != 1) 
    { 
        ret.insert(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}
ll sm(ll n)
{
	ll i;
	ll k=0;
	while(n>0)
	{
		k=k+n%10;
		n=n/10;
	}
	return k;
}
void ghost()
{   
  	ll i=0,j=0,k=0,l=0,n,r=0,q=0,t,y=100000000000,m;
cin>>n>>k;
ll a[n];
for(i=0;i<n;i++)
cin>>a[i];
ll dp[n];
for(i=0;i<n;i++)
dp[i]=10000000000;
dp[1]=abs(a[1]-a[0]);
dp[0]=0;
for(i=2;i<n;i++)
{
	for(j=1;j<=min(i,k);j++)
	{
		dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
}
}
cout<<dp[n-1];
  	}
signed main()
{int test=1;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fast
//cin>>test;
while(test--)
ghost();
return 0;
}

  

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

const int dx[4] = { 0, 0, -1, 1 };
const int dy[4] = { -1, 1, 0, 0 };
const char mov[] = "UDLR";
const char tank[] = "^v<>";

int h, w, d, x, y;
string map[22], command;

int main()
{
	int t, n;
	cin >> t;
	map[0] = "######################";

	for(int i = 1; ; ++i)
	{
		cin >> h; cin >> w;
		for(int j = 1; j <= h; ++j) {
			cin >> map[j];
			map[j] = "#" + map[j] + "#";
		}
		map[h+1] = map[0];
		cin >> n; cin >> command;

		for(int j = 1; j <= h; ++j)
			for(int k = 1; k <= w; ++k)
				for(int l = 0; l < 4; ++l)
					if(map[j][k] == tank[l])
						y = j, x = k, d = l, map[y][x] = '.';

        for(int j = 0; j < n; ++j)
        {
			for(int k = 0; k < 4; ++k)
				if(command[j] == mov[k]) {
					d = k;
					if(map[y+dy[d]][x+dx[d]] == '.')
						x += dx[d], y += dy[d];
				}

			if(command[j] == 'S')
				for(int xx = x, yy = y; map[yy][xx] != '#'; xx += dx[d], yy += dy[d])
					if(map[yy][xx] == '*') { map[yy][xx] = '.'; break; }
		}

		map[y][x] = tank[d];

		for(int j = 1; j <= h; ++j)
			cout << map[j].substr(1, w) << endl;

		if(i == t) break;
		cout << endl;
	}
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N;
  cin >> N;
  ll h[N];
  for (int i = 0; i < N; i++) cin >> h[i];

  int l = 0, r = 1;
  int ans = 0;
  while (r < N) {
    int tmp = l;
    while (h[l] >= h[r]) {
      l++;
      r++;
    }
    ans = max(ans, r - tmp - 1);
    l = r;
    r++;
  }

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


Measured memory_bytes: 1024
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;


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

  int t;
  int sum;

  for (t=1;;t++) {
    sum += t;
    if (sum >= X) break;
  }

  cout << t << endl;
}


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

int main()
{
long long H,W;long long ans=0;scanf("%lld %lld",&H,&W);
if(H==1||W==1)ans=1;
else if(H%2==0)ans=H*W/2;
else ans=(H-1)*W/2+W/2+W%2;
printf("%lld",ans);
}

Measured memory_bytes: 256
grade = []
while True:
    [m, f, r] = map(int, input().split())
    if (m==-1)and(f==-1)and(r==-1):
        break
    else:
        score = m + f
        if (m==-1)or(f==-1):
            grade.append("F")
        elif score>=80:
            grade.append("A")
        elif 65<=score<80:
            grade.append("B")
        elif 50<=score<65:
            grade.append("C")
        elif 30<=score<50:
            if r>=50:
                grade.append("C")
            else:
                grade.append("D")
        else:
            grade.append("F")

for i in grade:
    print(i)

Measured memory_bytes: 7684
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N; cin >> N;
    res = (N+110)/111*111;
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    //solve<ll>(0);
    cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace  std;
int main ()
{
	int a,b,c,ans=0;
	cin>>a>>b>>c;
	for(int i=a;i<=b;i++)
	{
		if(i%c==0)ans++;
	} 
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 3572
# -*- coding: utf-8 -*-
a,b,k = map(int, input().split())

while k>0:
    if a%2==1:
        a -= 1
    b += a//2
    a = a//2
    k -= 1

    if k==0:
        break

    if b%2==1:
        b-= 1
    a += b//2
    b = b//2
    k -= 1

print(a,b)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define nl endl
#define dbg(a) cout << #a << "=" << a << endl
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define md 1000000007

using namespace std;

ll qpow(ll n, ll k, ll mod)
{
    ll ans = 1;
    assert(k >= 0);
    n %= mod;
    while (k > 0)
    {
        if (k & 1)
            ans = (ans * n) % mod;
        n = (n * n) % mod;
        k >>= 1;
    }
    return ans % mod;
}

int solve()
{
    ll n, x, m;
    cin>>n>>x>>m;
    ll ct=0;
    ll prv=x;
    map<ll, ll> mp;
    vector<long long> v;
    for(ll i=1;i<=n;i++)
    {
        if(mp[x]!=0)
        {
            // dbg(i);
            ll tot=v.back();
            if(mp[x]!=1) tot-=v[mp[x]-2];
            ll ln=i-mp[x];
            tot*=(n-i)/ln;
            i+=((n-i)/ln)*ln;
            ct+=tot;
            mp.clear();
        }
        ct+=x;
         mp[x]=i;
         ll pb=0;
       if(v.size()) pb+=v.back();
        v.push_back(x+pb);
        x=(x*x)%m;
       
        
    }
    cout<<ct<<endl;

    return 0;
}

int main()
{
    fast;
    solve();
    return 0;
}

Measured memory_bytes: 7240
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();
		int x = sc.nextInt();
		if(a <= x && x <= a + b) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 23764
n,k = map(int,input().split())
s = input()
taboo = '1' * k
for i in range(n-k+1):
  if s[i:i+k] == taboo:
    print(-1)
    break
else:
  s = s[::-1]
  #print(s)
  ans = []
  now = 0
  while True:
    for i in range(k):
      if now + k - i <= n:
        if s[now+k-i] == '0':
          now += k-i
          ans.append(k-i)
          #print(ans)
          break
    if now == n:
      ans.reverse()
      print(' '.join(list(map(str,ans))))
      break

Measured memory_bytes: 10648
#include<iostream>
#include <string.h>
using namespace std;

int main(){
    int k,ans=0;
    string str;
    cin >> k;
    for (int i = 1; i <= k;i++){
      str = to_string(i);
      if (str.size() % 2 == 1)
        ans++;
    }
      cout << ans <<endl;
    return 0;
}

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

long n, a[100010];

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> n;
  for(int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  int idx = 0;
  vector<pair<int, int>> ans;

  while(a[idx] < 0) idx++;
  if(idx == 0) {
    for(int i = 1; i < n-1; ++i) {
      ans.emplace_back(a[0], a[i]);
      a[0] -= a[i];
    }
    ans.emplace_back(a[n-1], a[0]);
    a[n-1] -= a[0];
  } else if(idx == n) {
    for(int i = 0; i < n-1; ++i) {
      ans.emplace_back(a[n-1], a[i]);
      a[n-1] -= a[i];
    }
  } else {
    for(int i = idx; i < n-1; ++i) {
      ans.emplace_back(a[0], a[i]);
      a[0] -= a[i];
    }
    for(int i = 0; i < idx; ++i) {
      ans.emplace_back(a[n-1], a[i]);
      a[n-1] -= a[i];
    }
  }
  cout << a[n-1] << endl;
  for(auto p : ans) cout << p.first << " " << p.second << endl;
  return 0;
}

Measured memory_bytes: 3572
N = int(input())
L  = list(map(int, input().split()))

ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if L[i] != L[j] and L[i] != L[k] and L[j] != L[k]:
                sum_L = L[i] + L[j] + L[k]
                max_L = max(L[i], L[j], L[k])
                if sum_L - max_L > max_L:
                    ans += 1
print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
#define fi first
#define se second
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<P> p(n);
    vector<ll> y(n), idx(n);
    int size;

    for (int i = 0; i < n; ++i) {
        cin >> p[i].fi >> p[i].se;
        y[i] = p[i].se;
    }
    sort(p.begin(), p.end());
    sort(y.begin(), y.end());
    ll min_area = (y[n - 1] - y[0]) * (p[n - 1].fi - p[0].fi);
    for (int by = 0; by < n; by++) {
        for (int ty = by + 1;ty < n; ty++) {
            size = 0;
            for (int i =0;i<n;i++)
                if (y[by] <= p[i].second && p[i].second <= y[ty])
                    idx[size++] = i;

            int lb = 0;
            while (lb + k - 1 < size) {
                min_area = min(min_area, (y[ty] - y[by]) * (p[idx[lb + k - 1]].fi- p[idx[lb]].fi));
                lb++;
            }
        }
    }
    cout << min_area << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
        long long int n;
        cin >> n;
       if(n==0) {
                cout << 0<<endl;
                return 0;
        }
        vector <int> v;
        while(1) {
                if(n==0) break;
                if(n%2!=0) {
                        v.push_back(1);
                        n--;
                }
                else{
                  v.push_back(0);
                }
                n/=-2;
        }
        reverse(v.begin(),v.end());
        for(int i=0;i<v.size();i++){
         cout << v[i];
       }
       cout <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[30];
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int sum;
	sum=0;
	for(int i=2;i<=n-1;i++)
	{
		if(a[i]<max(a[i-1],a[i+1])&&a[i]>min(a[i-1],a[i+1]))
		{
			sum++;
		}
	} 
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
--import Data.Array
import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete

ctime s = let (h,m) = divMod s 100 in h * 60 + m

solve n (p,q) cs = runST $ do
    arr <- newArray (ctime p,ctime q - 1) n :: ST s (STUArray s Int Int)
    forM_ cs $ \c -> do
        forM_ c $ \(f,t) -> do
            forM_ [ctime f..ctime t - 1] $ \i -> readArray arr i >>= writeArray arr i . subtract 1
    es <- map (>0) <$> getElems arr
    return $ maximum $ scanl (\r b -> if b then r+1 else 0) 0 es


main = do
    [n,p,q] <- getInts
    unless (n==0 && p==0 && q==0) $ do
        cs <- map (map (apply2 (,)) . splitRec 2) <$> replicateM n (getInt >> getInts)
        print $ solve n (p,q) cs
        main


Measured memory_bytes: 5164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		char[] s = sc.next().toCharArray();
		for(int i = 0; i < s.length; i++) {
			if(i%2 ==0) sb.append(s[i]);
		}
		System.out.println(new String(sb));
		sc.close();

	}

}

Measured memory_bytes: 25872
// AOJ 3024 RMQ 2
// 2019.4.2 bal4u

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

#define INF 0x7fffffff

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) ob[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}


//// セグメント木
int seg[2][1 << 19]; int sz;

void segInit(int n) {
	sz = 1; while (sz < n) sz <<= 1;
	memset(seg, INF, sizeof(seg));
}

// k番目（0-index）の値を v に変更
void update(int id, int k, int v)
{
	int a, b;

	k += sz - 1;
//	if (seg[id][k] == v) return;
	seg[id][k] = v;
	while (k > 0) {
		k = (k - 1) >> 1;
		a = seg[id][(k << 1) + 1];
		b = seg[id][(k << 1) + 2];
		seg[id][k] = (a <= b)? a: b;
	}
}

// 空間 [a, b) 内の最小値
int getMin(int id, int a, int b, int k, int l, int r)
{
	int left, right;

	if (r <= a || b <= l) return INF;
	if (a <= l && r <= b) return seg[id][k];
	left = getMin(id, a, b, (k << 1) + 1, l, (l + r) >> 1);
	right = getMin(id, a, b, (k << 1) + 2, (l + r) >> 1, r);
	return left <= right ? left : right;
}


//// 本問題
typedef struct { int y, p, n; } T;  // 位置と更新前後の値
T memo[2][200005]; int len[2];

int main()
{
	int i, k, N, Q, x, y, z;
	int syn;

	N = in();
	segInit(N);            // セグメント木の初期化
	for (i = 0; i < N; i++) update(0, i, in());
	for (i = 0; i < N; i++) update(1, i, in());

	Q = in(), syn = 0;
	while (Q--) {
		x = in(), y = in()-1, z = in();      // 0-index
		if (x == 1 || x == 2) {
			x--;   // 0と1にする. 0->A, 1->B
			if (syn) {
				// 位置と更新前後の値を記録
				k = len[x]++;
				memo[x][k].y = y, memo[x][k].n = z;
				memo[x][k].p = seg[x][y+(sz-1)];     // 元の値は y+(sz-1) の位置にある
			}
			update(x, y, z);
		}
		else if (x == 3 || x == 4) out(getMin(x-3, y, z, 0, 0, sz));
		else {
			x -= 5;   // 0と1にする. 0->A, 1->B
			if (syn) {
				// 元に戻して、相手のしてきた変更を施し、相手と同じにする
				for (i = len[x] - 1; i >= 0; i--)   // 戻す作業
					update(x, memo[x][i].y, memo[x][i].p);
				for (i = 0; i < len[!x]; i++)       // 相手に同期
					update(x, memo[!x][i].y, memo[!x][i].n);
				len[0] = len[1] = 0;
			}
			else {
				memcpy(seg[x], seg[!x], sizeof(int)*sz*2);
				syn = 1;
			}
		}
	}
	return 0;
}



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

int main() {
   int N;
   cin >> N;
   vector<int> light(N);
   for(int i = 0; i < N; i++){
     cin >>light.at(i);
   }
   int NEXT = 1;
   int count = 0;
   int check = 0;
   for(int i = 0; i < N ; i++){
      count++;
      if(light.at(NEXT - 1) == 2){
         check = 1;
         break;
      }else{
         NEXT = light.at(NEXT - 1);
      }
   }
   if(check == 0){
     cout << -1;
   }else{
     cout << count;
   }
}


Measured memory_bytes: 3792
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N, Q;
    cin >> N;

    //Indexの示す数が何個あるかバケット
    ll A[200000];

    //初期化
    REP(i, 200000)
    {
        A[i] = 0;
    }

    ll index, sum = 0;
    REP(i, N)
    {
        //数列Aの中の数がどれだけあるかカウント
        cin >> index;
        A[index]++;

        //いまいまの合計値をメモ
        sum += index;
    }

    cin >> Q;

    ll B, C;
    REP(i, Q)
    {
        cin >> B >> C;

        //合計値の変化
        ll diff = (C - B) * A[B];
        sum += diff;

        //数Cの個数は数列内に存在する数B分増える
        A[C] += A[B];

        //Bの個数はその分減る
        A[B] = 0;

        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 5176
#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 <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

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 gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s;
int main() {
  cin >> s;
  i64 n = s.size();
  i64 m = 1 << min(n + 1, i64(10));
  for (i64 u = 0; u < m; ++u) {
    string t;
    for (i64 i = 0; i <= n; ++i) {
      if (u & (1 << i)) t.push_back('A');
      if (i < n) t.push_back(s[i]);
    }
    // cout << t << endl;
    if (t == "AKIHABARA") {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n=int(input())
g=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
from collections import deque
que=deque()
que.append(0)
unvisited=[1]*n
unvisited[0]=0
lf=[0]*n
while que:
    v=que.pop()
    for u in g[v]:
        if unvisited[u]:
            lf[u]=lf[v]+1
            que.appendleft(u)
            unvisited[u]=0
que=deque()
que.append(n-1)
unvisited=[1]*n
unvisited[n-1]=0
ls=[0]*n
while que:
    v=que.pop()
    for u in g[v]:
        if unvisited[u]:
            ls[u]=ls[v]+1
            que.appendleft(u)
            unvisited[u]=0
f=0
for i in range(n):
    if lf[i]<=ls[i]:
        f+=1
if f>n-f:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 60592
N = list(input())
op = ['+','-']

for i in range(2):
    for j in range(2):
        for k in range(2):
                ans = 0
                if (op[i] == '+'):
                    ans = int(N[0]) + int(N[1])
                else:
                    ans = int(N[0]) - int(N[1])
                if (op[j] == '+'):
                    ans += int(N[2])
                else:
                    ans -= int(N[2])
                if (op[k] == '+'):
                    ans += int(N[3])
                else:
                    ans -= int(N[3])
                if (ans == 7):
                    print(N[0]+op[i]+N[1]+op[j]+N[2]+op[k]+N[3]+"=7")
                    quit()


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

using namespace std;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    vector<int> vec;
    for(int i = 0;i < N;i++){
        int b;cin >> b;
        vec.push_back(b);
        //cout<<b<<" "<<bitset<5>(b)<<endl;
    }
    vector<vector<int>> usi;
    usi.push_back(vector<int>(40));
    for(int i = 0;i < N;i++){
        vector<int> v = usi.back();
        bitset<40> bits(vec.at(i));
        for(int j = 0;j < 40;j++){
            v.at(j) += bits[j];
            //cout<<v.at(j)<<" ";
        }
        //cout<<endl;
        usi.push_back(v);
    }
    ll ans = 0;
    auto check = [&](int a, int b){
        for(int i = 0;i < 40;i++){
            if(abs(usi.at(a).at(i) - usi.at(b).at(i)) >= 2){
                return false;
            }
        }
        return true;
    };
    for(int i = 0;i < N+1;i++){
        int ok = i;
        int ng = N + 1;
        while(ng - ok > 1){
            int mid = (ok + ng) / 2;
            if(check(i, mid)){
                ok = mid;
            }else{
                ng = mid;
            }
        }
     //   cout<<ok<<" "<<i<<endl;
        ans += ok - i;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	multiset<int> s;
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		int x;
		cin >> x;
		s.insert(x);
	}
	for (int i = 1; i <= m; ++i) {
		int x = *--s.end() / 2;
		s.erase(--s.end());
		s.insert(x);

	}
	long long answer = 0;
	for (auto x : s) {
		answer += x;
	}
	cout << answer;
}

Measured memory_bytes: 4992