akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
  string buf, s;
  string head, tail;
  cin >> s;
  cin >> buf;

  int Q = stoi(buf);

  bool flag = true;

  getline(cin, buf);

  for(int i = 0; i < Q; i++){
    getline(cin, buf);
    if (buf.size() == 1) {
      flag = not flag;
    } else {
      if ((buf[2] == '1') == flag) {
        head += buf[4];
      } else {
        tail += buf[4];
      }
    }
  }

  string ans;

  if (flag) {
    reverse(head.begin(), head.end());
    ans = head + s + tail;
  } else {
    reverse(tail.begin(), tail.end());
    reverse(s.begin(), s.end());
    ans = tail + s + head;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1348
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a < b) {
    REP(i, b) { cout << a; }
    cout << endl;
  } else {
    REP(i, a) { cout << b; }
    cout << endl;
  }
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    s = S()
    a = s.index('A')
    z = s.rindex('Z')
    return z-a+1

print(main())


Measured memory_bytes: 7836
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

// N以上の最小の約数Kを求める

int main() {
	int N, M;
	cin >> N >> M;

	int ans = MAX;
	for (int i = 1; i*i <= M; i++) {
		if (M % i == 0) {
			int another = M / i;
			if (i >= N) ans = min(ans, i);
			if (another >= N) ans = min(ans, another);
		}
	}

	cout << M / ans << endl;

	return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Os")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
}
int main()
{
    vok();
    ll n,k;
    IN n>>k;
    vll a(n);
    bitset<50> b[n];
    loop(i,0,n)
    {
        IN a[i];
        bitset<50> temp(a[i]);
        b[i]=temp;
    }
    bitset<50> ans(0);
    rloop(i,49,0)
    {
        int countt=0;
        loop(j,0,n)
        {
            if(b[j][i])
            {
                countt++;
            }
          	cout<<"";
        }
        ans[i]=1;
        if((countt*2)<n && ans.to_ullong()<=k)
        {
            //Do Nothing
        }
        else
        {
            ans[i]=0;
        }
    }
    ll fans=0LL;
    ll X=ans.to_ullong();
    loop(i,0,n)
    {
      	cout<<"";
        fans+=(X^a[i]);
    }
    OUT fans<<endl
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
#define MAX 10000
#define NIL -1

using namespace std;

struct Node {int p, l,  r;};
struct Node T[MAX];
int n;

void preParse(int u) {
  if (u == NIL) return;
  cout << ' ' << u;
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u) {
  if (u == NIL) return;
  inParse(T[u].l);
  cout << ' ' << u;
  inParse(T[u].r);
}

void postParse(int u) {
  if (u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  cout << ' ' << u;
}

int main() {
  int v, l, r, root;

  cin >> n;
  REP(i, n) T[i].p = NIL;

  REP(i, n) {
    cin >> v >> l >> r;
    T[v].l = l;
    T[v].r = r;
    if (l != NIL) T[l].p = v;
    if (r != NIL) T[r].p = v;
  }

  REP(i, n) {
    if (T[i].p == NIL)
      root = i;
  }

  cout << "Preorder" << endl;
  preParse(root);
  cout << endl;
  cout << "Inorder" << endl;
  inParse(root);
  cout << endl;
  cout << "Postorder" << endl;
  postParse(root);
  cout << endl;

  return 0;
}

Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long int i=1,sum=0;
	while(i<=n){
		if(i%3==0||i%5==0){
			i++;
		}
		else{
			sum+=i;
			i++;
		}
	}
	cout<<sum;

	return 0;
}

Measured memory_bytes: 3568
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  val a1 = sc.nextInt
  val a2 = sc.nextInt
  val a3 = sc.nextInt

  val res = if(a1 + a2 + a3 >= 22) "bust" else "win"

  println(res)

}

Measured memory_bytes: 25552
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n, m;
	while(cin >> n >> m) {
		vector<vector<int>> s(m);
		REP(i, m) {
			int k;
			cin >> k;
			REP(j, k) {
				int t;
				cin >> t;
				t--;
				s[i].push_back(t);
			}
		}
		vector<int> p(m);
		REP(i, m) cin >> p[i];
		int ans = 0;
		REP(mask, 1<<n) {
			bool f = true;
			REP(i, m) {
				int cnt = 0;
				REP(j, SZ(s[i])) {
					if((mask>>(s[i][j]))&1) {
						cnt++;
					}
				}
				if(cnt%2 != p[i]) {
					f = false;
				}
			}
			if(f) {
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main() {

    int N, K;
    std::cin >> N >> K;
    int max = N * (N - 1) / 2 - (N - 1);
    int ans = -1;
    if (max < K) {
        std::cout << -1 << std::endl;
        return 0;
    }
    int M = N - 1 + max - K;
    std::cout << M << std::endl;
    for (int i = 2; i <= N; ++i)std::cout << 1 << " " << i << "\n";
    for (int i = N - 1; i < M;) {
        for (int j = 2; j < N && i < M; ++j) {
            for (int k = j + 1; k <= N && i < M; ++k, ++i) {
                std::cout << j << " " << k << "\n";
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

int x;

int main() {
    int ans;
    rep(i,5){
        cin >> x;
        if (x == 0) ans = i+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
    int a[3][3];
    int n;
    int b[10];
    for(int i = 0;i < 3;i++){
        for(int j = 0;j < 3;j++){
            scanf("%d",&a[i][j]);
        }
    }
    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        scanf("%d",&b[i]);
    }

    for(int i = 0;i < 3;i++){
        for(int j = 0;j < 3;j++){
            for(int k = 0;k < n;k++){
                if(a[i][j] == b[k]){
                    a[i][j] = 0;
                    break;
                }
            }
        }
    }
        for(int i = 0;i < 3;i++){
            if((a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) || (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) || (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) || (a[2][0] == 0 && a[1][1] == 0 && a[0][2] == 0)){
                printf("Yes");
                return 0;
            }
        }
    printf("No");
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Random;

public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        String a=sc.next();
        int x = a.length();
        Random random = new Random();
        int randomValue = random.nextInt(x-2);
        String b=a.substring(randomValue, randomValue+3);
        System.out.println(b);
    }
}


Measured memory_bytes: 35672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const int n_max = 1e5+10;
vector<int> g[n_max];
set<int> used;
bool tot_ok = true;

void dfs(int cv, int pv){
  // cout << cv << " " << pv << endl;
  bool ok = false;
  for(auto &nv : g[cv]){
    if(nv == pv) continue;
    dfs(nv,cv);
    if(used.count(cv)==1){
      ok = true;
    }
  }
  if(!ok){
    if(used.count(pv)==0){
      ok = true;
      used.insert(cv);
      used.insert(pv);
    }
  }

  if(!ok){
    tot_ok = false;
  }

}


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

  int n;
  cin >> n;

  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a;--b;
    g[a].pb(b);
    g[b].pb(a);
  }
  used.insert(-1);
  dfs(0,-1);

  if(!tot_ok){
    cout << "First" << endl;
    return 0;
  }

cout << "Second" << endl;

  return 0;
    

}


Measured memory_bytes: 10496
s=list(input())+["Z"]
cnt = 0
for i in range(len(s)):
    t = 0
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        t += 1
        for j in range(i+1,len(s)):
            if s[j]  == "A" or s[j] == "C" or s[j] == "G" or s[j] == "T":
                t += 1
            else:
                if cnt < t:
                    cnt = t
                break
print(cnt)

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

#define MAX 1e8

void add_candidate(vector<double> x, vector<double> &candidate)
{
    candidate.push_back(x[0] - x[1]);
    candidate.push_back(x[1] - x[2]);
    candidate.push_back((x[0] - x[2]) / 2);
}

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

    // [minus, const, plus]
    vector<double> xmin(3, MAX);
    vector<double> xmax(3, -MAX);
    vector<double> ymin(3, MAX);
    vector<double> ymax(3, -MAX);
    double x, y;
    string D;
    for (int i = 0; i < N; i++)
    {
        cin >> x >> y;
        cin >> D;

        if (D == "L")
        {
            xmin[0] = min(xmin[0], x);
            xmax[0] = max(xmax[0], x);
        }
        else if (D == "R")
        {
            xmin[2] = min(xmin[2], x);
            xmax[2] = max(xmax[2], x);
        }
        else
        {
            xmin[1] = min(xmin[1], x);
            xmax[1] = max(xmax[1], x);
        }

        if (D == "D")
        {
            ymin[0] = min(ymin[0], y);
            ymax[0] = max(ymax[0], y);
        }
        else if (D == "U")
        {
            ymin[2] = min(ymin[2], y);
            ymax[2] = max(ymax[2], y);
        }
        else
        {
            ymin[1] = min(ymin[1], y);
            ymax[1] = max(ymax[1], y);
        }
    }

    vector<double> candidate;
    add_candidate(xmin, candidate);
    add_candidate(xmax, candidate);
    add_candidate(ymin, candidate);
    add_candidate(ymax, candidate);
    candidate.push_back(0);

    double ans = 1e18;
    for (double c : candidate)
    {
        if (c >= 0)
        {
            x = max({xmax[0] - c, xmax[1], xmax[2] + c}) - min({xmin[0] - c, xmin[1], xmin[2] + c});
            y = max({ymax[0] - c, ymax[1], ymax[2] + c}) - min({ymin[0] - c, ymin[1], ymin[2] + c});
            ans = min(ans, x * y);
        }
    }
    cout << fixed << setprecision(2) << ans << endl;
}


Measured memory_bytes: 256
N, M = gets.chomp.split.map(&:to_i)

arr = Array.new(N)
 
M.times {
  s, c = gets.chomp.split.map(&:to_i)
  if arr[s - 1] && arr[s - 1] != c
    puts "-1"
    exit
  end
  arr[s - 1] = c
}
  
if arr.count > 1 && arr[0] == 0
    puts "-1"
    exit
end
  
if !arr[0] && arr.count > 1
  arr[0] = 1
end
 
ret = arr.reduce(""){|sum, i|
  if (i) then
    sum = sum << i.to_s
  else
    sum = sum << "0"
  end
}
 
puts ret

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
#define endl '\n'

void solve() {
    int n;
    cin >> n;

    vector<ll> a(n);
    for (auto &x: a) {
        cin >> x;
    }

    ll res = 0;
    map<ll, ll> cnt;
    for (int i = 0; i < n; ++i) {
        ll cur = i - a[i];
        res += cnt[cur];
        ++cnt[i + a[i]];
    }
    cout << res << endl;

}

int main() {
    FAST_IO;

    int t;
    // cin >> t;
    t = 1;

    while (t--) {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 27460
import itertools
n,p = map(int,input().split())
a = list(map(lambda x:int(x)&1,input().split()))
cnt0 = a.count(0)
cnt1 = n - cnt0
if p==0 and cnt0==n:
    print(2**n)
elif p==1 and cnt0==n:
    print(0)
else:
    print(2**(n-1))

Measured memory_bytes: 3060
import collections

N = int(input())
s_list = []
for i in range(N):
    s_list.append(input())
dict = collections.Counter(s_list)
max_num = 0
for i in dict.values():
    max_num = max(max_num,i)
top_vote = []
for i,j in dict.items():
    if j == max_num:
        top_vote.append(i)
top_vote.sort()
for i in top_vote:
    print(i)


Measured memory_bytes: 35572
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define endl '\n'
#define N 200000 + 5
using namespace std;

int n, a[N], b[N];

int main(){
    IOS;
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> a[i];
    for(int i=n; i>=1; i--){
        int sum = 0;
        for(int j=i+i; j<=n; j+=i){
            sum += b[j];
            sum %= 2;
        }
        b[i] = sum ^ a[i];
    }
    vector<int> ans; // index
    for(int i=1; i<=n; i++)
        if(b[i])
            ans.push_back(i);
    cout << ans.size() << endl;
    for(int i=0; i<ans.size(); i++)
        cout << ans[i] << (i == ans.size()-1 ? "\n" : " ");
    return 0;
}


Measured memory_bytes: 3192
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int a,b,c,d;
  char str,str2;
  cin>>str>>str2;
  if(str>str2)
    cout<<'>'<<endl;
  else if(str<str2)
    cout<<'<'<<endl;
  else
    cout<<"="<<endl;
  return 0;
}


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

int main() {
  int H, W;
  for (int i=0; ; i++) {
    cin >> H >> W;
    if (i != 0) cout << endl;
    if (H == 0 && W == 0) break;
    for (int j=0; j<H; j++) {
      for (int k=0; k<W; k++) {
        if (j == 0 || j%2 == 0) {
          if (k == 0 || k%2 == 0) cout << "#";
          else cout << ".";
        }
        else {
          if (k == 0 || k%2 == 0) cout << ".";
          else cout << "#";
        }
        if (k == W-1) cout << endl;
      }
    }
  }
  return 0; 
}


Measured memory_bytes: 3112
# -*- coding: utf-8 -*-
h, w = map(int,input().split())
a = [list(input()) for _ in range(h)]

#print(a)
i = 0
j = 0
ans = "Possible"
while i < h - 1 or j < w - 1:
    flag1 = [False for _ in range(2)]
    flag2 = [False for _ in range(2)]
    #print(i, j+1)
    #print(a)
    #print(a[i][j+1])
    if i == 0 and j == 0:
        flag2[0] = True
    if i + 1 < h and a[i + 1][j] == '#':
        flag1[0] = True
    if j + 1 < w and a[i][j + 1] == '#':
        flag1[1] = True
    if i - 1 >= 0 and a[i - 1][j] == '#':
        flag2[0] = True
    if j - 1 >= 0 and a[i][j - 1] == '#':
        flag2[1] = True
    #print(flag1, flag2)
    if len(set(flag1)) == 2 and len(set(flag2)) == 2:
        if flag1[0]:
            i += 1
        if flag1[1]:
            j += 1
    else :
        ans = "Impossible"
        break
if a[h - 2][w - 1] == '#' and a[h - 1][w - 2] == '#':
    ans = "Impossible"
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<int>D1(N),D2(N);
  for(int i=0;i<N;i++){
    cin>>D1[i]>>D2[i];
  }
  for(int i=0;i<N-2;i++){
    if(D1[i]==D2[i]&&D1[i+1]==D2[i+1]&&D1[i+2]==D2[i+2]){cout<<"Yes"<<endl;return 0;}
  }
  cout<<"No"<<endl;
  return 0;                       
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 111111;
signed main(){
    int a,b;
    cin>>a>>b;
    if(a%b==0)cout<<-1<<endl;
    else{
        for(int i=1;i<d5;i++){
            if(a*i%b!=0){
                cout<<a*i<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
struct number_{
	int n;
	int index;
}seq[100002];
int comp1(number_ a,number_ b){
	return a.n<b.n;
}
int comp2(number_ a,number_ b){
	return a.index<b.index;
}
int n,ans=0;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>seq[i].n;
		seq[i].index=i;
	}
	sort(seq,seq+n,comp1);
	for(int i=0;i<n;i++){
		seq[i].n=i%2;
	}
	sort(seq,seq+n,comp2);
	for(int i=0;i<n;i+=2){
		ans+=seq[i].n;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(x) memset(x, 0, sizeof x)
#define mem1(x) memset(x, -1, sizeof x)
#define MX 100005
ll arr[MX], dp[MX],n;
//ll rec(ll i, ll score)
//{
//    if(i==n-1) return score;
//    else if(i>=n) return 1e9;
//    else if(dp[i]<score && dp[i]!=-1) return dp[i];
//    else if(!i || dp[i]==-1 || score<dp[i])
//    {
//        ll ret1=1e9, ret2=1e9;
//        if(i+1<=n-1) ret1= rec(i+1, score+llabs(arr[i+1]-arr[i]));
//        if(i+2<=n-1) ret2= rec(i+2, score+llabs(arr[i+2]-arr[i]));
//        return dp[i]=min(ret1,ret2);
//    }
//}
int main()
{
    ll i,j,k,l, m;
    scanf("%lld %lld",&n,&k);
    for(i=0; i<n; i++) scanf("%lld",&arr[i]);
    for(i=1; i<n; i++) dp[i]=1e9;
    for(i=0; i<n; i++)
    {
        ll len=i+k;
        for(j=i+1; j<n && j<=len; j++)dp[j]=min(dp[j], dp[i]+llabs(arr[i]-arr[j]));
    }
    printf("%lld\n",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1792
/*
 *  *s.rbegin()=*(--s.end())
 *   sort(v.rbegin(),v.rend()) = negative of v[i] , sort(v.begin(),v.end())
 *   sort(v.begin()+l_index,v.begin()+r_index+1);
 * 
 *   for(auto &it:v)cin>>it; 
 *   n + n/2 + n/3 + n/4 + n/5 + ........n/n =>n*log(n)
 *   n + n/3 + n/5 + n/7 + n/11+.............=>n*log(log(n))
 *   1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 .......=>gcd( a[i] , a[i+1] , a[i+2] )=1;
 *   2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 ......=>upto 1e6 max diff a[i], a[i+1] ~ 150
 *   Every even integer greater than 2 can be expressed as the sum of two primes.[1]  : https://en.wikipedia.org/wiki/Goldbach%27s_conjecture
 *   printf("%03d\n",k);
 *   scanf("%d/%d/%d",&d,&m,&y);   
 */

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
vector<int>dx={0,1,0,-1},dy={1,0,-1,0};
long long  gcd(long long  a,long long b)
{
     while (a&&b)a>b?a%=b:b%=a;
     return a+b;
}
const int N=1e5;
vi C(N+1);
vvii G(N+1);
vb B(N+1);
int n,u,v,w;
void dfs(int I,int clr)
{
	B[I]=true;C[I]=clr;
	for(int i=0;i<(int)G[I].size();i++)
	{
		if(!B[ G[I][i].first ])dfs(G[I][i].first,clr^G[I][i].second);
	}
}
int32_t main()
{
	IOS
	cin>>n;
	for(int i=1;i<=n-1;i++)
	{
		cin>>u>>v>>w;
		G[u].pb({v,w&1});
		G[v].pb({u,w&1});
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
	cout<<C[i]<<" ";
	cout<<endl;
	
		
	
}
		


Measured memory_bytes: 10240
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d;
	a--; b--; c--; d--;
	cin >> s;

	bool ok = true;

	for (int i = a; i + 1 <= c; i++) {
		if (s[i] == '#' && s[i + 1] == '#')ok = false;
	}
	for (int i = b; i + 1 <= d; i++) {
		if (s[i] == '#' && s[i + 1] == '#')ok = false;
	}

	if (c > d) {
		bool f = false;
		for (int i = b; i <= d; i++) {
			if ((i - 1 >= 0 && s[i - 1] == '.') && s[i] == '.' && s[i + 1] == '.')f = true;
		}
		if (!f)ok = false;
	}


	cout << (ok ? "Yes" : "No") << endl;


	return 0;
}

Measured memory_bytes: 592
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline



def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

K=int(input())
s = [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]

print(s[K-1])



Measured memory_bytes: 12400
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  ll N,Y;
  cin>>N>>Y;
  ll x=-1,y=-1,z=-1;
  for(ll a=0; a<=N; ++a){
    for(ll b=0; b<=N-a; ++b){
    ll c=N-a-b;
    ll sum =10000*a+5000*b+1000*c;
    if(sum==Y){
    x=a,y=b,z=c;}}}
    cout<<x<<" "<<y<<" "<<z<<endl;
}


  

  

  


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

int a[9];
int b[9];
int main()
{
    int n, m;
    cin >> n >> m;
    if (n < m)
    {
        for (int i = 0; i < m; i++)
            cout << n;
    }
    else
    {
        for (int i = 0; i < n; i++)
            cout << m;
        
    }
    return 0;
}

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

typedef long long ll;
ll const mod = 1e9+7;

int main(void){
    int n;
    cin >> n;
    vector<string> s(2);
    cin >> s.at(0) >> s.at(1);
    vector<ll> dp(n, 0);
    for(int i=0; i<n; i++){
        if(s[0][i] == s[1][i]){
            if(i == 0){
                dp.at(0) = 3;
            }else{
                if(s[0][i-1] == s[1][i-1]){
                    dp.at(i) = dp.at(i-1)*2%mod;
                }else{
                    dp.at(i) = dp.at(i-1);
                }
            }
        }else{
            if(i == 0){
                dp.at(0) = (dp.at(1)) = 6;
            }else{
                if(s[0][i-1] == s[1][i-1]){
                    dp.at(i) = dp.at(i-1)*2%mod;
                    dp.at(i+1) = dp.at(i);
                }else{
                    dp.at(i) = dp.at(i-1)*3%mod;
                    dp.at(i+1) = dp.at(i);
                }
            }
            i++;
        }
    }
    cout << dp.back() << endl;
    return 0;
}

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

int mod = 1000000007;
int n;
int a[200001];
int c[200001];
vector<int> pos[200001];
int dp[200001];		//dp([i])[num] = i(>=0)番目の値(直後の値)がnumのときに定義される。左からi個の状態は何通り？

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	
	//縮約(a -> c)
	int cor = 0;
	rep(i, n) {
		if (cor > 0 && c[cor - 1] == a[i]) continue;
		c[cor++] = a[i];
	}
	c[cor++] = 0;
	n = cor;
	
	//DP
	dp[c[0]] = 1;	//dp([0])[c[0]]
	for (i = 1; i < n; i++) {
		dp[c[i]] += dp[c[i - 1]];
		dp[c[i]] %= mod;
	}
	
	cout << dp[0] << endl;
	return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>

int main(void) {

    int a, b;
    char op;

    while(op != '?'){
        scanf("%d %c %d", &a, &op, &b);
        if(op == '+'){
            printf("%d\n", a+b);
        } else if(op == '-'){
            printf("%d\n", a-b);
        } else if(op == '/'){
            printf("%d\n", a/b);
        } else if(op == '*') {
            printf("%d\n", a*b);
        }
    }

    return 0;
}


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

int main(){
    int N; cin >> N;
    vector<int> d(N,0); for(int i = 0; i < N; i++) cin >> d.at(i);
    
    sort(d.begin(),d.end());
    ll ans = 0;
    if(d.size() % 2 == 0){
        int size = d.size();
        ans = d.at(size/2) - d.at(size/2-1);
    }
    cout << ans << endl;
}



Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    if(n <= k){
        cout << "0" << endl;
        return 0;
    }
    long long sum = 0;
    rep(i,n-k) sum += h[i];
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#define ll long long int
using namespace std;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i < n; i++){
        int temp = n/i;
        if(n%i == 0)
            temp--;
        ans += temp;
    }
    cout << ans << endl;
}



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

int main()
{
    string s;
    vector<int> m(26, 0);
    cin >> s;
    for (int i = 0; i < s.size(); ++i)
    {
        m[s[i] - 'a']++;
    }

    for(int i = 0; i < 26; ++i)
    {
        if(!m[i])
        {
            cout <<  char(i + 'a') << "\n";
            return 0;
        }
    }
    cout << "None" << "\n";
    return 0;
}

Measured memory_bytes: 3648
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 500001; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1] = {}; 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	for(int i=0;i<MAX;i++)
     last_visit[i] = -1;

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << '\n'; 


} 

// driver code 
int main() 
{ 
  int n,q;
  cin>>n>>q;
	int a[n];
  for(int i=0;i<n;i++)
     cin>>a[i];

	Query queries[q]; 
	for(int i=0;i<q;i++){
     cin>>queries[i].l>>queries[i].r;
     queries[i].l--,queries[i].r--;
     queries[i].idx = i; 
  } 
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD


ll A,B;
ll i, j, k,ans;



int main(){
    scanf("%lld%lld", &A,&B);
    printf("%lld",A-2*B<0?0:A-2*B);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

	vector<int> a(n), t, tm, minus;
	rep(i,n){
		cin >> a[i];
		if(a[i] == 2) t.emplace_back(i);
		else if(a[i] == -2) tm.emplace_back(i);
		else if(a[i] == -1) minus.emplace_back(i); 
		//if(a[i] < 0) minus++;
	}

	set<int> s;
	if(tm.size() % 2 == 0){
		cout << t.size() + tm.size() << endl;
		for(auto i : t){
			s.emplace(i);
		}
		for(auto i : tm){
			s.emplace(i);
		}

	}else if(tm.size() % 2 == 1 and minus.size() >= 1){
		cout << t.size() + tm.size() + 1 << endl;
		for(auto i : t){
			s.emplace(i);
		}
		for(auto i : tm){
			s.emplace(i);
		}
		s.emplace(minus[0]);
	}else{
		cout << t.size() + tm.size() - 1 << endl;
		for(auto i : t){
			s.emplace(i);
		}
		rep(i,tm.size() - 1){
			s.emplace(tm[i]);
		}
	}

	for(auto i : s){
		cout << i + 1 << endl;
	}
}



Measured memory_bytes: 3160
#include<iostream>
#include<cstdio>
#include<vector>
#define MD 86 
#define ll long long
#define mod 1000000007
using namespace std;
inline ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll f[MD+5];int ans;
vector<pair<ll,ll> >v[MD+5];
int main()
{
	f[0]=f[1]=1;
	for(int i=2;i<=MD+2;++i) f[i]=f[i-1]+f[i-2];
	v[1].push_back(make_pair(1,2));
	v[1].push_back(make_pair(1,3));
	for(int i=2;i<=MD;++i)
	{
		for(int j=0;j<v[i-1].size();++j)
		{
			ll x=v[i-1][j].first,y=v[i-1][j].second;
			for(x+=y;x<=f[i+2];x+=y) v[i].push_back(make_pair(y,x));
		}
	}
	for(int Q=read();Q--;)
	{
		ll x=read(),y=read();if(x>y) swap(x,y);
		for(ans=1;f[ans+1]<=x&&f[ans+2]<=y;++ans);
		printf("%d ",ans);
		if(ans==1) printf("%d\n",1LL*x*y%mod);
		else 
		{
			int sum=0;
			for(int j=0;j<v[ans-1].size();++j)
			{
				ll X=v[ans-1][j].first,Y=v[ans-1][j].second;
				if(Y<=x&&X+Y<=y) sum=(sum+(y-X)/Y)%mod;
				if(Y<=y&&X+Y<=x) sum=(sum+(x-X)/Y)%mod;
			}
			printf("%d\n",sum);
		}
	}
	return 0;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N,X,T;
  cin>>N>>X>>T;
  cout<<(N+X-1)/X*T<<endl;

  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	string a,b;cin>>a>>b;
	string ans;
	for(int i=0;i<n;i++){
		
			ans+=a[i];
			ans+=b[i];
		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

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

int main()
{
  // input & declare
  int n,tmp;
  cin >> n;
  std::vector<int> v;
  double sum = 0;
  int ave1 = 0;
  int ave2 = 0;
  for(int i = 0; i < n; i++)
  {
    cin >> tmp;
    v.push_back(tmp);
    sum += tmp;
  }


  ave1 = ceil(sum / n);
  ave2 = floor(sum / n);


  // ave = ceil(sum / n);
  // std::cout << ave << '\n';

  int ans1 = 0;
  int ans2 = 0;

  // process
  for(int i = 0; i < n; i++)
  {
    ans1 += pow((ave1 - v[i]),2);
    ans2 += pow((ave2 - v[i]),2);
  }

  // output
  std::cout << min(ans1,ans2) << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[])
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k - 1] += 32;
    cout << s;
    return 0;
}


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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int main() {
    string s, rs;
    cin >> s;
    rs = s;
    reverse(rs.begin(), rs.end());

    int ans = 0;
    for (int i = 0; i < ((int)s.size() + 1) / 2; i++) {
        if (s[i] != rs[i])
            ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]
INF = float('inf')
wf = [[INF]*N for i in range(N)]
for a,b,c in src:
    a,b = a-1,b-1
    wf[a][b] = wf[b][a] = c
for i in range(N):
    wf[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])

ans = 0
for a,b,c in src:
    a,b = a-1,b-1
    if c != wf[a][b]:
        ans += 1
print(ans)

Measured memory_bytes: 3444
// 解説AC
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

int main() {
  int n;
  cin >> n;
  map<int,int> mp;
  rep(i,n) {
    int x;
    cin >> x;
    mp[x]++;
  }
  bool ok=true;
  if(mp.size()>3) ok=false;
  else if(mp.size()==1) {
    if(!mp.count(0)) ok=false;
  }
  else if(mp.size()==2) {
    if(n%3!=0) ok=false;
    else if(mp.at(0)!=n/3) ok=false;
  }
  else {
    if(n%3!=0) ok=false;
    vector<int> a;
    for(auto p : mp) {
      if(p.second!=n/3) ok=false;
      a.push_back(p.first);
    }
    int q=a[0]^a[1]^a[2];
    if(q!=0) ok=false;
  }

  cout << (ok? "Yes" : "No") << endl;
}



Measured memory_bytes: 3840
#include <stdio.h>

int main(){
  int N,i,max=0,min=0;
  scanf("%d",&N);
  int a[N];
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
 	if(a[i]>max){
      max=a[i];
    }else if(a[i]>min){
      min=a[i];
    }
  }
  for(i=0;i<N;i++){
    if(a[i]==max){
      printf("%d\n",min);
    }else{
      printf("%d\n",max);
    }
  }
}

Measured memory_bytes: 2304
from functools import cmp_to_key


def f(s, t):
    m = min(len(s), len(t))
    if s[:m] > t[:m]:
        return 1
    elif s[:m] < t[:m]:
        return -1
    else:
        if len(s) > len(t):
            return -1
        else:
            return 1


def ms(s, t):
    i = 0
    for c1, c2 in zip(s, t):
        if c1 != c2:
            return i
        i += 1
    return i


def xxor(x):
    if x & 3 == 0:
        return x
    if x & 3 == 1:
        return 1
    if x & 3 == 2:
        return x + 1
    if x & 3 == 3:
        return 0


def gray(x):
    return x ^ (x // 2)


n, l = map(int, input().split())
s = [input() for _ in range(n)]
s.sort(key=cmp_to_key(f))
g = gray(l) ^ gray(l - len(s[0]))
for i in range(n - 1):
    b = ms(s[i], s[i + 1]) + 1
    g ^= gray(l - b + 1) ^ gray(l - b)
    t = len(s[i + 1]) - b
    g ^= gray(l - b) ^ gray(l - b - t)
if g == 0:
    print('Bob')
else:
    print('Alice')


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

int main(){
    int a, b, k; cin >> a >> b >> k;
    set<int> reg;
    for(int i = a; i <= min(a+k-1,b); i++) {
        reg.insert(i);
    }
    for(int i = max(b-k+1,a); i <= b; i++) {
        reg.insert(i);
    }
    auto itr = reg.begin();
    for(int i = 0; i < reg.size(); i++) {
        cout << *itr << endl;
        itr++;
    }
    return 0;
}

Measured memory_bytes: 256
import sys

INPUT = lambda: sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)


def main():
    S = INPUT()
    N = len(S)

    s = ["", ""]
    for i in range(N):
        for j in range(2):
            s[j] += str((i + j)%2)

    cnt = [0, 0]
    for i in range(N):
        for j in range(2):
            if s[j][i] != S[i]: cnt[j] += 1

    print(cnt[0] if cnt[0] < cnt[1] else cnt[1])


if __name__ == '__main__':
    main()

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

using namespace std;



#define MAXN 51
typedef long long ll;

ll powint(ll a, ll b) {
  ll ans = 1;
  while(b--) {
    ans *= a;
  }
  return ans;
}

int main() {
  ll n, p, a[MAXN], np=0;
  cin >> n >> p;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    np |= a[i]%2;
  }
  if (!np) {
    cout << (p ? 0 : powint(2, n)) << endl;
    return 0;
  }
  cout << (n==1 ? a[0]%2==p : powint(2, n-1)) << endl;
  return 0;
}


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

typedef long long int ll; 
long double pi=3.141592653589793238462643383279502884197169399375105820974944592307816406286 ;

int main()
{
        ll a,b,h,m;
        scanf("%lld %lld %lld %lld",&a,&b,&h,&m);
        long double ans=0;
        ans= a*a+b*b-2*a*b*cos((pi*h)/6+(m*pi)/360-(m*pi)/30);
        cout << setprecision(10) << fixed<<sqrt(ans);
        printf("\n");
}

Measured memory_bytes: 4120
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
#define UB upper_bound
#define LB lower_bound
const int NUM = 2e5 + 5;
double dp[3000][3000];
double p[3000];
// dp[i][no of heads] = probability 
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        cout << fixed << setprecision(10);
        int n; cin >> n;
        FOR(i,0,n)
            cin >> p[i];
        dp[0][0] = 1 - p[0]; // Got a tail on zeroth index
        dp[0][1] = p[0]; // Got the head :)
        FOR(i,1,n){
            FOR(j,0,3000){
                // tail
                dp[i][j] += (1-p[i])*dp[i-1][j];
                // head
                if(j > 0)
                dp[i][j] += p[i]*dp[i-1][j-1];
            }
        }
        double ans = 0.0;
        FOR(i,n/2+1,3000)
            ans += dp[n-1][i];
        cout << ans;
    }   
}

Measured memory_bytes: 73976
#include<bits/stdc++.h>
using namespace std;
int main()
{
   char a[100],b[100],c[100];
   int l1,l2;
   scanf("%s",&a);
   scanf("%s",&b);
   scanf("%s",&c);
   l1=strlen(a);
   l2=strlen(b);
    if(a[l1-1]==b[0]&&c[0]==b[l2-1])
       printf("YES\n");
       else printf("NO\n");

}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);
		List<Integer> list = new ArrayList<Integer>();

		while(true){
			int a = in.nextInt();
			String op = in.next();
			int b = in.nextInt();


			if(op.equals("?")){
				break;
			}else{

				switch(op){
					case "+":
						list.add(a + b);
						break;
					case "-":
						list.add(a - b);
						break;
					case "*":
						list.add(a * b);
						break;
					case "/":
						list.add(a / b);
						break;
				}
			}
		}
		list.forEach(result -> System.out.println(result));

	}

}




Measured memory_bytes: 31480
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

#define _ { \
	ios_base::sync_with_stdio(false); \
    cin.tie(NULL); \
}

int main(){
   _;
   int a,b;cin>>a>>b;
   int aa=a*50/4,bb=b*10;
   int ans=1e6;
   for(int i=min(aa,bb);i<1251;i++){
   	if(i*4/50==a&&i/10==b){cout<<i;return 0;}
   }
cout<<-1;
}

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

struct FenwickTree {
	typedef int T;
	vector<T> v;
	void init(int n) { v.assign(n, 0); }
	void add(int i, T x) {
		for(; i < (int)v.size(); i |= i + 1) v[i] += x;
	}
	T sum(int i) const {	//[0, i)
		T r = 0;
		for(-- i; i >= 0; i = (i & (i + 1)) - 1) r += v[i];
		return r;
	}
	T sum(int left, int right) const {	//[left, right)
		return sum(right) - sum(left);
	}
};

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> p(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &p[i]), -- p[i];
		int BlockSize = 250, NumBlocks = N / BlockSize + 1;
		vector<vector<long long> > memo(NumBlocks, vector<long long>(N));
		FenwickTree ft;
		for(int bi = 0; bi < NumBlocks; ++ bi) {
			vector<long long> &v = memo[bi];
			int i = bi * BlockSize;
			{
				ft.init(N);
				long long sum = 0;
				for(int j = i; j < N; ++ j) {
					sum += (j - i) - ft.sum(p[j]);
					v[j] = sum;
					ft.add(p[j], 1);
				}
			}
			{
				ft.init(N);
				long long sum = 0;
				for(int j = i - 1; j >= 0; -- j) {
					sum += ft.sum(p[j]);
					v[j] = sum;
					ft.add(p[j], 1);
				}
			}
		}
		ft.init(N);
		int Q;
		scanf("%d", &Q);
		for(int ii = 0; ii < Q; ++ ii) {
			int l; int r;
			scanf("%d%d", &l, &r), -- l, -- r;
			int bl = (l + BlockSize - 1) / BlockSize, br = (r - 1) / BlockSize;
			long long ans = 0;
			if(bl > br) {
				for(int i = r; i >= l; -- i) {
					ans += ft.sum(p[i]);
					ft.add(p[i], 1);
				}
				for(int i = l; i <= r; ++ i)
					ft.add(p[i], -1);
			} else {
				int L = bl * BlockSize, R = br * BlockSize;
				ans += memo[bl][r];
				ans += memo[br][l];
				if(bl < br)
					ans -= memo[bl][R - 1];
				for(int i = R; i <= r; ++ i)
					ft.add(p[i], 1);
				for(int i = l; i < L; ++ i)
					ans += ft.sum(p[i]);
				for(int i = R; i <= r; ++ i)
					ft.add(p[i], -1);
			}
			printf("%lld\n", ans); fflush(stdout);
		}
	}
	return 0;
}

Measured memory_bytes: 316488
W,H = map(int, input().split())
P = [0] * W
Q = [0] * H
for i in range(W):
  P[i] = int(input())
for i in range(H):
  Q[i] = int(input())
  
P.sort()
Q.sort()

# banhei
infv = int(1e9)
P.append(infv)
Q.append(infv)

cumP = [0] * (W+1)
cumQ = [0] * (H+1)
for i in range(W):
  cumP[i+1] = cumP[i] + P[i]
for i in range(H):
  cumQ[i+1] = cumQ[i] + Q[i]
  
#print(cumP)
#print(cumQ)
y,x = 0,0
cost = 0
while y <= H and x <= W:
  #print(x,y)
  # 右か下にコストが安いほうにいけばよい。イコールなら任意でよい。
  if x == W and y == H:
    break
  elif P[x] <= Q[y]:
    cost += P[x]
    x += 1
    cost += cumQ[y]
  else:
    cost += Q[y]
    y += 1
    cost += cumP[x]
    
print(cost)

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

int main () {
	long N;
	// 各数字の個数を保持しておく
	long *count = calloc(100000, sizeof(long));
	long prev_sum = 0;
	scanf("%ld", &N);
	long *A = malloc((1 + N) * sizeof(long));
	for (long i = 1; i <= N; i++)
	{
		scanf("%ld", &A[i]);
		count[A[i]] += 1;
		prev_sum += A[i];
	}
	long Q;
	scanf("%ld", &Q);
	long *sum = malloc((Q + 1) * sizeof(long));
	sum[0] = prev_sum;
	long *B = malloc((1 + Q) * sizeof(long));
	long *C = malloc((1 + Q) * sizeof(long));
	for(long i = 1; i <= Q; i++)
	{
		scanf("%ld", &B[i]);
		scanf("%ld", &C[i]);
		// Bの数
		long prev_count = count[B[i]];
		long add = (C[i] - B[i]) * prev_count;
		sum[i] = sum[i - 1] + add;
		count[B[i]] -= prev_count;
		count[C[i]] += prev_count;
	}

	for (long i = 1; i <= Q; i++)
	{
		printf("%ld\n", sum[i]);
	}

	return 0;
}


Measured memory_bytes: 5644