akhauriyash/Code-Regression huggingface dataset:
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a);a=(a*a);b=b/2;}return res;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE
vector<ll>adj[60];
ll n;
ll par[60];
ll lca[60];
void dfs(ll s,ll pa)
{
  par[s]=pa;
  for(auto it : adj[s])
  {
    if(it!=pa)
    {
      dfs(it,s);
    }
  }
}
signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         cin>>n;
         for(int i=0;i<n-1;i++)
         {
          ll a1,b1;
          cin>>a1>>b1;
          adj[a1].pb(b1);
          adj[b1].pb(a1);
         }
         dfs(1,-1);
         ll m;
         cin>>m;
         ll a11[m+1],b11[m+1];
         for(ll i=1;i<=m;i++)
        {
            cin>>a11[i]>>b11[i];
            ll a1 = a11[i];
            ll b1 = b11[i];
            vector<ll>vis(n+5,0);
            while(a1!=-1)
            {
              vis[a1]=1;
              a1=par[a1];
            }
            while(vis[b1]!=1)
            {
                  b1 = par[b1];
            }
            lca[i]=b1;
        }
        ll ans =0;
        for(ll i=0;i<(1<<m);i++)
        {
           ll mask=0;
           vector<ll>vis(n+5,0);
           for(ll j=0;j<m;j++)
           {
            if(i&(1<<j))
            {
                  ll p1 = lca[j+1];
                  ll a1 = a11[j+1];
                  ll b1 = b11[j+1];
                  while(a1!=p1)
                  {
                      if(vis[a1]==0)
                      {
                        mask++;
                      }
                      vis[a1]=1;
                      a1 = par[a1];
                  }
                  while(b1!=p1)
                  {
                    if(vis[b1]==0)
                    {
                      mask++;
                    }
                    vis[b1]=1;
                    b1=par[b1];
                  }
            }
           }
           if(__builtin_popcountll(i) & 1)
            ans -=power(2,(n-1-mask));
          else
            ans+=power(2,(n-1-mask));
        }
        cout<<ans<<endl;
         

      }
      






}



























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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int INF = TEN(9);

int dp[110][110];
bool f[110][110];

int main() {
	int H, W; cin >> H >> W;
	rep(i, H) {
		string s; cin >> s;
		rep(j, W) {
			f[i][j] = (s[j] == '#');
		}
	}

	rep(i, 110) {
		rep(j, 110) {
			dp[i][j] = INF;
		}
	}

	dp[0][0] = (f[0][0]);

	rep(i, H) {
		rep(j, W) {
			if (i > 0) {
				chmin(dp[i][j], dp[i-1][j] + (f[i][j] && !f[i-1][j]));
			}
			if (j > 0) {
				chmin(dp[i][j], dp[i][j-1] + (f[i][j] && !f[i][j-1]));
			}
		}
	}
	cout << dp[H-1][W-1] << endl;

	return 0;
}

Measured memory_bytes: 256
abc=[int(i) for i in input().split()]

abc.sort()

def func(a,b,c):
    return int((c-a)/2+(c-b)/2)

if abc[0]%2==abc[1]%2:
    if abc[0]%2!=abc[2]%2:
        print(func(abc[0]+1,abc[1]+1,abc[2])+1)
    else:
        print(func(abc[0],abc[1],abc[2]))
else:
    if abc[0]%2==abc[2]%2:
        print(func(abc[0]+1,abc[1],abc[2]+1)+1)
    else:
        print(func(abc[0],abc[1]+1,abc[2]+1)+1)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        var tmp = ReadIntArray();
        int n = tmp[0], k = tmp[1];

        long n0 = n / k;
        long ans = n0 * n0 * n0;

        if (k%2 == 0)
        {
            long n1 = (n0*k + k/2) <= n ? n0 +1 : n0;

            if (k/2 <= n)
            {
                ans += n1 * n1 * n1;
            }
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

int main(){
	int h, w;
	int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
	int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
	cin >> h >> w;
	char field[h+2][w+2] = { };
	for(int i = 0; i < h; i++){
		string s;
		cin >> s;
		for(int j = 0; j < w; j++){
			field[i+1][j+1] = s[j];
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(field[i+1][j+1] == '.'){
				char a = '0';
				for(int k = 0; k < 8; k++){
					if(field[i+1+dx[k]][j+1+dy[k]] == '#'){
						a += 1;
					}
				}
				field[i+1][j+1] = (char)a;
			}
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cout << field[i+1][j+1];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define T int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define PI 3.141592653589793238462643383


int main (){
    fast;
    int ac = 0,tle = 0,re = 0,wa = 0;
    T{
        string s;
        cin>>s;

        if(s == "WA") wa++;
        else if(s == "AC") ac++;
        else if(s == "TLE") tle++;
        else re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
    


}











Measured memory_bytes: 3632
package main

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

func main() {
	N := nextInt()

	A := make([]int, N)
	B := make([]int, N)

	for i := 0; i < N-1; i++ {
		a := nextInt() - 1
		A[i] = a
		B[a]++
	}
	for i := 0; i < N; i++ {
		fmt.Println(B[i])
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;
  ll arr[n + 5];
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];

  unordered_set<ll> dp;

  for (ll i = 1; i <= n; i++) {
    if (arr[i] == 1) {
      dp.insert(1);
    } else {
      if (dp.find(arr[i] - 1) != dp.end())
        dp.insert(arr[i]);
    }
  }

  cout << ((dp.size()) ? (n - (ll)dp.size()) : -1) << en;

  return 0;
}

Measured memory_bytes: 10056
# ABC132 D Blue and Red Balls
def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a

def comb_mod(n, k, mod):
    if k > n or k < 0:
        return 0
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod

n,k = map(int,input().split())
MOD=10**9+7

for i in range(1,k+1):
    print((comb_mod(n-k+1,i,MOD)*comb_mod(k-1,i-1,MOD))%MOD)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

int a[100003];

int main() {
	int n, x; cin >> n >> x;
	for (int i = 0; i < n; ++i) cin >> a[i];
	ll ans = 0;
	if (a[0] > x) {
		ans += a[0] - x;
		a[0] = x;
	}
	for (int i = 0; i < n - 1; ++i) {
		if (a[i] + a[i + 1] <= x) continue;
		if (a[i + 1] >= x - a[i]) {
			ans += a[i + 1] - x + a[i];
			a[i + 1] = x - a[i];
		}
		else {
			ans += a[i + 1];
			a[i + 1] = 0;
			ans += a[i] - x;
			a[i] = x;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int N;
		cin >> N;
		char x[10] = { 'p','p','h','b','h','h','p','h','p','h' };
		cout << x[N%10] << "on" << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
int min(long int a[], int num){
    long int min = 10000000000000000;
    int min_n = 0;
    for(int i = 0; i < num; i++){
        if(a[i] < min){
            min = a[i];
            min_n = i;
        }
    }
    return min_n;
}

int main(void){
    long int N;
    long int a[5];
    scanf("%ld", &N);
    for(int i = 0; i < 5; i++){
        scanf("%ld", &a[i]);    
    }
    int n = min(a, 5);
    long int ans = 5 + ((N-1) / a[n]);
    printf("%ld\n", ans);
    return 0; 
}

Measured memory_bytes: 128
//use itertools::Itertools;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        h1: usize,
        m1: usize,
        h2: usize,
        m2: usize,
        k: usize
    }

    let mut time = h2 * 60 + m2 - h1 * 60 - m1 - k;
    println!("{}", time);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2232
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n, k;
    cin >> n >> k;

    vector <int> pref(n + 1), pos_pref(n + 1), pos_post(n + 1);
    vector <int> a(n);
    for (int i = 0; i < n;++i) {
        cin >> a[i];
        pref[i + 1] = pref[i] + a[i];
        pos_pref[i + 1] = pos_pref[i] + max(0ll, a[i]);
    }                                        
    for (int i = n - 1; i >= 0; --i)
        pos_post[i] = pos_post[i + 1] + max(0ll, a[i]);
    int ans = 0;
    for (int i = 0; i + k - 1 < n; ++i) {
        ans = max(ans, pos_pref[i] + pos_post[i + k] + max(0ll, pref[i + k] - pref[i]));
    }   
    cout << ans << endl;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int dp[n];
  memset(dp,0,sizeof(dp));
  dp[0]=0;
  if(n>0)
  dp[1]=abs(arr[1]-arr[0]);
  if(n>1)
  {
  dp[2]=min(dp[0]+abs(arr[2]-arr[0]),dp[1]+abs(arr[2]-arr[1]));    
}
  for(int i=3;i<n;i++)
  {
dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1]));
// int m=min(abs(arr[i]-arr[i-2]),abs(arr[i]-arr[i-1]));
// if(m==abs(arr[i]-arr[i-2]))
// dp[i]=dp[i-2]+abs(arr[i]-arr[i-2]);
// else
// dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);

   

  }
//   for(auto i:dp)
//   cout<<i<<" ";
//   cout<<endl;
cout<<dp[n-1]<<endl;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> fib;
    fib.push_back(0);
    fib.push_back(1);
    for(int i = 2; fib[i-1] <= 1000000000; i++){
        fib.push_back(fib[i-1]+i);
    }
    int X; cin >> X;
    int ans = 0;
    while(fib[ans] < X) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>

struct TNode
{
	int Index;
	TNode* Parent;
	std::vector<TNode*> Children;
	
	TNode();
};

TNode::TNode()
{
	Index = -1;
	Parent = NULL;
	Children.clear();
}

typedef std::vector<TNode> TRootedTree;

void AddNode(TRootedTree& Tree)
{
	int Index;
	std::cin >> Index;
	Tree[Index].Index = Index;
	int ChildrenCount;
	std::cin >> ChildrenCount;
	Tree[Index].Children.resize(ChildrenCount);
	for(int i = 0; i < ChildrenCount; i++){
		int ChildIndex;
		std::cin >> ChildIndex;
		Tree[Index].Children[i] = &(Tree[ChildIndex]);
		Tree[ChildIndex].Parent = &(Tree[Index]);
	}
}

int GetDepth(const TNode& Node, int Depth = 0)
{
	if(!Node.Parent) return Depth;
	return GetDepth(*(Node.Parent), Depth + 1);
}

std::string GetType(const TNode& Node)
{
	if(!Node.Parent) return "root";
	if(Node.Children.empty()) return "leaf";
	return "internal node";
}

void OutputNode(const TNode& Node)
{
	std::cout << "node " << Node.Index << ": ";
	int ParentIndex = Node.Parent != NULL ? Node.Parent->Index : -1;
	std::cout << "parent = " << ParentIndex << ", ";
	std::cout << "depth = " << GetDepth(Node) << ", ";
	std::cout << GetType(Node) << ", ";
	std::cout << "[";
	for(unsigned int i = 0; i < Node.Children.size(); i++){
		std::cout << Node.Children[i]->Index;
		if(i < Node.Children.size() - 1) std::cout << ", ";
	}
	std::cout << "]" << std::endl;
}

int main()
{
	int Count;
	std::cin >> Count;
	TRootedTree Tree(Count);
	for(int i = 0; i < Count; i++){
		AddNode(Tree);
	}
	
	for(int i = 0; i < Count; i++){
		OutputNode(Tree[i]);
	}
	return 0;
}

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

int main(int argc, char const *argv[])
{
    int n; cin >> n;
    int a[200010];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int fst, snd, fn=0, sn=0;

    for (int i = 0; i < n; i++)
    {
        if (a[i] > fst)
        {
            fst = a[i]; fn = i;
        }else if(a[i] > snd) {
            snd = a[i]; sn = i;
        }
        
    }
    for (int i = 0; i < n; i++)
    {
        if (i != fn)
        {
            cout << fst << endl;
        }
        else {
            cout << snd << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
#define INFTY 2000000001
#define MAX 500000
int count=0;
int L[MAX/2+2],R[MAX/2+2];

void merge(int A[],int left,int mid,int right)
{
  int i,j,k,n1,n2;

  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    count++;
    if(L[i]<=R[j]){
      A[k]=L[i++];
    
    }else{
      A[k]=R[j++];
    
    }
  }
}

void mergeSort(int A[],int left,int right)
{
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){
int i,n,s[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  mergeSort(s,0,n);
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",s[i]);
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
}


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

int ctoi(char c){
    if (c>='0' && c<='9'){
        return c-'0';
    }
    return 0;
}
int main(){
    string A, B;
    cin >> A >> B;
    if (A.length()>B.length()) {
        cout << "GREATER" << endl;
        return 0;
    }
    else if(A.length() < B.length()){
        cout << "LESS" <<endl;
        return 0;
    }
    else {
        for (int i=0; i<A.length(); i++){
            if (A.at(i)!=B.at(i)){
                int a=ctoi(A.at(i));
                int b=ctoi(B.at(i));
                if (a>b) {
                    cout << "GREATER" << endl;
                    return 0;
                }
                else {
                    cout << "LESS" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "EQUAL" << endl;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M;
	cin >> N >> M;
	string A[2010], B[2010];
	rep(i,0,N) cin >> A[i];
	rep(i,0,N) cin >> B[i];
	ll ans = 0;
	rep(i,0,N){
		rep(j,0,M){
			if(A[i][j] != B[i][j]) ans++;
		}
	}
	print(ans);

	
}


Measured memory_bytes: 11616
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)

vector<int>g[100010];
bool vis[100010];
void dfs(int rt)
{
    vis[rt]=1;
    for(auto x: g[rt])
    {
        if(vis[x]==0)
        {
            dfs(x);
        }
    }
}
int main()
{
   int n,m,a,b, cnt=0;
   cin>>n>>m;
   for(int i=0; i<m; i++)
   {
       si2(a,b);
       g[a].pb(b); g[b].pb(a);
   }

   for(int i=1; i<=n; i++)
   {
       if(vis[i]==0)
       {
           dfs(i);
           cnt++;
       }
   }
   cout<<cnt-1;
}



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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    System.out.println(Character.isUpperCase(s.charAt(0))?"A":"a");
  }
}

Measured memory_bytes: 32604
#include <iostream>
using namespace std;
int A[100],n,v,j;
void print()
{
    for(j=0;j<n;j++)
    {
        cout<<(j==0?"":" ")<<A[j];
    }
    cout<<endl;
}
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    print();
    for(int i=1;i<n;i++)
    {
        v=A[i];
        j=i-1;
        while(j>=0&&A[j]>v)
        {
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        print();
    }
    return 0;
    
}


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

typedef pair<int,int> pii;
typedef vector<int> vec;
typedef unordered_map<int,int> hash;
#define long long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,v) memset(a,v,sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define INF 0x3f3f3f3f//infinity for integers
#define JJ ios_base::sync_with_stdio(0); cin.tie(0)//input fast
#define MOD 1000000007


int main()
{
	JJ;
	int n,d; cin>>n>>d;
	double x,y;
	double dist=0;
	int ans=0;
	FOR(i,0,n){
		cin>>x>>y;
		dist=sqrt((x*x)+(y*y));
		if(dist<=d){
			ans++;
		}
	}
	cout<<ans<<endl;
	


	return 0;
}


Measured memory_bytes: 3860
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll a;
    cin>>a;
    string s;
    cin>>s;
    ll b=int(s[0]-'0')*100+int(s[2]-'0')*10+int(s[3]-'0');
    cout<<a*b/100<<endl;
}

Measured memory_bytes: 3648
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int n =sc.nextInt();
       int[] a = new int[n];
       int res = 0;
        
       for(int i=0; i<n; i++) {
           a[i] = sc.nextInt();
       }
       sc.close();

       for(int i=0; i<n; i++) {
            while(a[i]%2 == 0) {
                a[i] /= 2;
                res++;
            }
       }
       System.out.println(res);
    }
}

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

using namespace std;

#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const int inf = 1e9; 

const double PI =  3.14159265;

int main(){
	IO;
	ll x;
	ll cnt = 0;
	cin>>x;
	x = x - (x%5);
	cnt += (x/500)*1000;
	x = x%500;
	cnt += x;
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 256
from collections import deque
h,w=map(int,input().split())
maze=[str(input()) for _ in range(h)]#行→列の順
dist=[[-1]*w for _ in range(h)]
ans=[]
for i in range(h):
    for j in range(w):
        if maze[i][j]==".":
            dist=[[-1]*w for _ in range(h)]
            dist[i][j]=0
            que=deque([(j,i)])
            while len(que):
                x,y=que.popleft()
                for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
                    nx,ny=x+dx,y+dy
                    if min(nx,ny)>=0 and nx<=w-1 and ny<=h-1:
                        if maze[ny][nx]=='.' and dist[ny][nx]<0:
                            dist[ny][nx]=dist[y][x]+1
                            que.append([nx,ny])
        m=0
        for k in range(h):
          for l in range(w):
            m=max(m,dist[k][l])
        ans.append(m)
print(max(ans))

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

#define debug(x) cout << #x" = " << x;

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int MAXN = 2E5 + 10, MOD = 1E9 + 7;

int n;
PII a[MAXN];
int l[MAXN], r[MAXN];

vector<int> b[MAXN];
ll f[MAXN];

int main(){
	scanf("%d", &n);
	vector<int> c;
	for (int i = 1; i <= n; ++i)
		scanf("%d%d", &a[i].st, &a[i].nd), c.push_back(a[i].nd);
	sort(a + 1, a + n + 1);
	sort(all(c));
	for (int i = 1; i <= n; ++i)
		a[i].nd = lower_bound(all(c), a[i].nd) - c.begin() + 1, eput(a[i].nd);

	r[1] = a[1].nd;
	for (int i = 2; i <= n; ++i)
		r[i] = max(r[i - 1], a[i].nd);
	l[n] = a[n].nd;
	for (int i = n - 1; i >= 1; --i)
		l[i] = min(l[i + 1], a[i].nd);

	for (int i = 1; i <= n; ++i)
		b[r[i]].push_back(l[i]), eput(l[i], r[i]);
	f[0] = 1;
	for (int i = 1; i <= n; ++i){
		f[i] = f[i - 1];
		for (auto &x: b[i])
			f[i] = (f[i] + (f[i] - (x == 1 ? 0 : f[x - 2]))) % MOD;
		eput(f[i]);
	}
	printf("%lld\n", (f[n] - f[n - 1] + 2ll * MOD) % MOD);
	return 0;
}


Measured memory_bytes: 16628
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<pair<int, int>> pii;
typedef vector<vector<int>> table;
int W,N;

/*
1: 2, 4
2: 2, 5
3: 1, 2
4: 3, 8
*/

//check[i][j] = i個以降t以下のアイテムを買ったときの最大値
//W = 容量
//N = 全部の個数
//i = 今見てる品物
//t = 残り重さ
//j = 価値

int paking(pii item, table &check, int i, int t){ 
  //cout << "i:" << i << " t:" << t <<endl;
  if(i == N|| t <= 0){
    //cout << "return 0" <<endl;
    return 0;
  }
  if(check[i][t] != 0){
    //cout << "check i:" << i << " t:" << t <<endl; 
    return check[i][t];
  }

  if(t-item[i].first >= 0){
  check[i][t] = max(paking(item, check, i+1, t-item[i].first) + item[i].second, paking(item, check, i+1, t));
  //cout << "i:" << i << " t:" << t << " " << check[i][t]<<endl; 
  }
  else{
    check[i][t] = paking(item, check, i+1, t);
    }

  return check[i][t];
}

int main() {
 cin >> N >> W;
 table check(N+1, vector<int>(W+1,0));
 pii item;
 for(int i = 0; i < N; i++){
   int a , b;
   cin >> a >> b;
   pair<int, int> p = make_pair(b,a);
   item.push_back(p);
 }
 cout << paking(item, check, 0, W) <<endl;
}


Measured memory_bytes: 6876
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int tetra[200];
int dp[1000010];
int dp2[1000010];


signed main(){
    rep(i, 0, 200) tetra[i] = (i+1)*(i+2)*(i+3)/6;
    fill(dp, dp+1000010, INF);
    fill(dp2, dp2+1000010, INF);
    dp[0] = dp2[0] = 0;
    rep(i, 0, 1000010) rep(j, 0, 200){
        if(i+tetra[j] > 1000010) break;
        chmin(dp[i+tetra[j]], dp[i]+1);
        if(tetra[j]%2 == 1) chmin(dp2[i+tetra[j]], dp2[i]+1);
    }
    int n;
    while(cin >> n, n) cout << dp[n] << ' ' << dp2[n] << endl;

    return 0;
}


Measured memory_bytes: 18612
X = int(input())
def eratosthenes(N):
  s = [i % 2 for i in range(N)]
  s[0] = s[1] = 0
  s[2] = 1

  for i in range(2, int(N**0.5)):
    if s[i] == 0: continue
    for j in range(2 * i, N, i):
      s[j] = 0
  
  return s

s = eratosthenes(10**5 + 10)
for i in range(X, 10**5+10):
  if s[i] == 1:
    print(i)
    break

Measured memory_bytes: 3864
#include <bits/stdc++.h>
 
#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTI(a,i)
#endif
 
#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 (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
 
template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}
 
template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}
 
template <class T>
using vec2 = vector<vector<T>>;
 
template <class T>
using vec3 = vector<vector<vector<T>>>;
 
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll X, K, D;
    cin >> X >> K >> D;
 
    if (X < 0) X *= -1;
 
    ll x = X / D;
 
    X -= min(x, K) * D;
    K -= min(x, K);
    K %= 2;
    if (K == 1) {
        X -= D;
    }
 
    ll result = abs(X);
    cout << result << endl;
 
 
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <queue>

using namespace std;
typedef long long LL;
const int maxn = 10000005;
const int maxm = 505;

int prm[maxn/10],tot;bool is[maxn];
int n,x[maxm],a[maxm],m,e[maxm][maxm];
int match[maxm],vis[maxm],ans,odd,even;
void predo(int n) {
	is[0]=is[1]=1;
	for (int i=2;i<=n;i++)
	{
		if (!is[i]) prm[++tot]=i;
		for (int j=1;j<=tot;j++)
		{
			int num=prm[j]*i;
			if (num>n) break;
			if (i%prm[j]) is[num]=1;
			else {is[num]=1;break;}
		}
	}
}
bool Hungray(int u) {
	for (int v=1;v<=m;v++)
	if (e[u][v]&&!vis[v]) {
		vis[v]=true;
		if (!match[v]||Hungray(match[v])) {
			match[v]=u;return true;
		}
	}
	return false;
}
int main()
{
	#ifdef Amberframe
		freopen("arc080f.in","r",stdin);
		freopen("arc080f.out","w",stdout);
	#endif
	predo(1e7);scanf("%d",&n);x[0]=-1;
	for (int i=1;i<=n;i++) scanf("%d",&x[i]);
	for (int i=1;i<=n;i++) x[i]!=x[i-1]+1?a[++m]=x[i]:0;
	for (int i=1;i<=n;i++) x[i]!=x[i+1]-1?a[++m]=x[i]+1:0;
	sort(a+1,a+m+1);is[2]=1;
	for (int i=1;i<=m;i++)
	for (int j=i+1;j<=m;j++)
		if (!is[a[j]-a[i]]) e[i][j]=e[j][i]=1;
	for (int i=1;i<=m;i++)
	if (a[i]&1) {
		++odd;memset(vis,0,sizeof vis);
		if (Hungray(i)) ++ans;
	}
	else ++even;
	odd-=ans;even-=ans;
	ans+=2*(odd/2+even/2)+(odd&1)*3;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 13952
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	m := stdin.ReadInt()
	k := stdin.ReadInt()

	answers := make([]int, n)
	friends := NewCounter()
	parents := NewCounter()
	uf := NewUnionFind(n)

	for i := 0; i < m; i++ {
		a := stdin.ReadInt() - 1
		b := stdin.ReadInt() - 1
		friends.Increment(a)
		friends.Increment(b)
		uf.Union(a, b)
	}

	for i := 0; i < n; i++ {
		parents.Increment(uf.Find(i))
	}

	for i := 0; i < n; i++ {
		answers[i] = parents.Get(uf.Find(i)) - 1 - friends.Get(i)
	}

	for i := 0; i < k; i++ {
		c := stdin.ReadInt() - 1
		d := stdin.ReadInt() - 1
		if uf.Find(c) == uf.Find(d) {
			answers[c]--
			answers[d]--
		}
	}

	s := []string{}
	for _, v := range answers {
		s = append(s, strconv.Itoa(v))
	}
	stdout.Println(strings.Join(s, " "))
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

type UnionFind struct {
	parents []int
}

func NewUnionFind(n int) *UnionFind {
	uf := UnionFind{}
	uf.parents = []int{}
	for i := 0; i < n; i++ {
		uf.parents = append(uf.parents, i)
	}
	return &uf
}

func (uf *UnionFind) Find(x int) int {
	if uf.parents[x] == x {
		return x
	}

	uf.parents[x] = uf.Find(uf.parents[x])
	return uf.parents[x]
}

func (uf *UnionFind) Union(x, y int) {
	x = uf.Find(x)
	y = uf.Find(y)
	if x != y {
		uf.parents[y] = x
	}
}

type Counter map[interface{}]int

func NewCounter() *Counter {
	return &Counter{}
}

func (c *Counter) put(key interface{}, v int) {
	d := map[interface{}]int(*c)
	d[key] = v
}

func (c *Counter) Increment(key interface{}) {
	c.put(key, c.Get(key)+1)
}

func (c *Counter) Decrement(key interface{}) {
	v := c.Get(key)
	if v > 0 {
		c.put(key, v-1)
	}
}

func (c *Counter) Get(key interface{}) int {
	d := map[interface{}]int(*c)
	if v, ok := d[key]; ok {
		return v
	} else {
		return 0
	}
}

func (c *Counter) Keys() []interface{} {
	d := map[interface{}]int(*c)
	keys := []interface{}{}
	for key := range d {
		keys = append(keys, key)
	}
	return keys
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int N = 2e5 + 10;
const int EMPTY = N-1;

int n, a[N], last[N], nxt[N], beg[N], follow[N], jump[N], njump[N];
ll k;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    forn(i,n) cin >> a[i];

    beg[n] = EMPTY;
    dforsn(i,0,n) {
        if (last[a[i]]) {
            beg[i] = beg[last[a[i]]+1];
        }
        else beg[i] = a[i];
        last[a[i]] = i;
    }

    jump[EMPTY] = beg[0];
    forn(i,n) if (!follow[a[i]]) follow[a[i]] = i+1;
    forn(i,n) jump[a[i]] = beg[follow[a[i]]];

    int c = EMPTY;
    auto e = k-1;
    a[n] = EMPTY;
    while (e > 0) {
        if (e&1) c = jump[c];
        forn(i,n+1) njump[a[i]] = jump[jump[a[i]]];
        forn(i,n+1) jump[a[i]] = njump[a[i]];
        e /= 2;
    }

    int start = c == EMPTY ? 0 : follow[c];
    vector<bool> in(N);
    vi ans; forsn(i, start, n) {
        if (in[a[i]]) {
            while (1) {
                auto x = ans.back();
                ans.pop_back();
                in[x] = 0;
                if (x == a[i]) break;
            }
        }
        else {
            ans.push_back(a[i]);
            in[a[i]] = 1;
        }
    }
    for (auto x : ans) cout << x << ' ';
    

    return 0;
}


Measured memory_bytes: 7412
#include <iostream>                                                                                                          
  #include <vector>
  #include <algorithm>
   
  int main(){
      int N;
      std::cin >> N;
      std::vector<int> L;
      for(int i=0; i<2*N; ++i){
        int l = 0;
        std::cin >> l;
        L.push_back(l);
     }
     if(L.size()!=2*N) return -1;
  
     std::sort(L.begin(),L.end());
     int sum = 0;
     while(L.size()>0){
        sum += L.at(L.size()-2);
        L.pop_back();
        L.pop_back();
     }
     std::cout << sum << std::endl;
  
     return 0;
 }

Measured memory_bytes: 256
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	static long MOD = 1000000007L;

	public static void main(String[] args) {
		final char WALL = '#';
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] MAP = new char[H][];
		for (int i = 0; i < H; i++) {
			MAP[i] = sc.next().toCharArray();
		}
		int[][] pat = new int[H][W];
		pat[0][0] = 1;
		for (int h = 1; h < H; h++) {
			pat[h][0] = (MAP[h][0] == WALL) ? 0 : pat[h-1][0];
		}
		for (int w = 1; w < W; w++) {
			pat[0][w] = (MAP[0][w] == WALL) ? 0 : pat[0][w-1];
		}
		for (int h = 1; h < H; h++) {
			for (int w = 1; w < W; w++) {
				if (MAP[h][w] == WALL) {
					pat[h][w] = 0;
				} else {
					long val = ((long)pat[h-1][w] + (long)pat[h][w-1]) % MOD;
					pat[h][w] = (int)val;
				}
			}
		}
		System.out.println(pat[H-1][W-1]);
	}
}


Measured memory_bytes: 35432
#include <iostream>
#include <algorithm>

int main()
{
  int N, K;
  std::cin >> N >> K;
  int* p = new int[N];
  for (int i=0; i<N; i++) std::cin >> p[i];
  std::sort(p, p+N);
  int res = 0;
  for (int i=0; i<K; i++) res += p[i];
  std::cout << res << std::endl;
  delete[] p;
  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <map>

int main(int argc, char* argv[])
{
  int a,b,c,d,ans;

  std::cin >> a;
  std::cin >> b;
  std::cin >> c;
  std::cin >> d;

  ans  = a > b ? b : a;
  ans += c > d ? d : c;  

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


Measured memory_bytes: 256
import java.util.*
import kotlin.comparisons.compareByDescending

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val p = Array(n) {
        readLine()!!.split(" ").map { it.toInt() }.let { Jobs(it[0], it[1]) }
    }
    p.sortBy { it.a }

    var ans = 0L
    var pointer = 0
    val queue = PriorityQueue<Int>(1, compareByDescending { it })
    repeat(m) {
        while (pointer < n && p[pointer].a <= it + 1) {
            queue.add(p[pointer].b)
            pointer++
        }
        ans += queue.poll() ?: 0
    }
    println(ans)
}

class Jobs(val a: Int, val b: Int)

Measured memory_bytes: 76420
// Author: drunken_legend
 
#include <bits/stdc++.h>
using namespace std;
#define lli long long int

int main()
{
    int n;
    cin >>n;
    std::vector<int> v(n);
    for (int i = 0; i < n; ++i)
    {
    	/* code */cin>>v[i];
    }
    std::vector<int> dp(n,INT_MAX);
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    for(int i=2;i<n;i++){
    	dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<dp[n-1];

    return 0;
}
 

Measured memory_bytes: 4044
//105
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<(x)<<endl
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf=1e18;
const int N=2e5+10;
ll factorial(ll x){//階乗の計算
    if(x==0||x==1) return 1;
    return x*factorial(x-1);
}
ll gcd(ll a ,ll b){return b ? gcd(b,a%b) : a;}//最大公約数
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}//最小公倍数
int num_digit(ll a){//桁数を求める
    int num_dig = 0;
    while(a!=0){
        a /= 10;
        ++num_dig;
    }
    return num_dig;
}
vector<ll> digit(ll a){//桁の数字を求める
    vector<ll> dig(num_digit(a));
    for(int i=num_digit(a)-1; i>=0; --i){
        dig[i] = a%10;
        a /= 10; 
    }
    return dig;
}

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

    int cnt=0;
    int ans=0;
    for(int num=1; num<=n; ++num){
        for(int i=1; i<=num; ++i){
            if(num%i==0) ++cnt;
        }
        if(num%2!=0 && cnt==8) ++ans;
        // cout(ans);
        cnt = 0;
    }
    cout(ans);

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
n = range(N)
list_Alice = [0]
list_Bob = [0]
A.sort(reverse = True)
for i in n:
  if i%2 == 0:
    list_Alice.append(A[i])
  else:
    list_Bob.append(A[i])
print(sum(list_Alice) - sum(list_Bob))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      if(4*i+7*j==n){
        cout<<"Yes"<<endl;
        return(0);
      }
    }
  }
  cout<<"No"<<endl;
  return(0);
}


Measured memory_bytes: 256
import java.util.*;
// import java.util.stream.*;

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

  int n;
  int a[];

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      n = sc.nextInt();
      a = new int[n];
      for (int i = 0; i < n; i++) a[i] = sc.nextInt();
    } finally {
      sc.close();
    }
  }

  void solve() {
    int b = total();
    int c = odd();
    System.out.println(b - c);
  }

  int total() {
    return (int)Math.pow(3, n);
  }

  int odd() {
    int ans = 1;
    for (int i = 0; i < n; i++) ans *= calc(a[i]);
    return ans;
  }

  int calc(int i) {
    if (i % 2 == 0) return 2;
    return 1;
  }
}


Measured memory_bytes: 35520
#include<iostream>
#include <string>
#include <set>
#include <cstdlib> 
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
  string S;
  cin>> S;
  int min=999;
  for (int i=0;i<S.size()-2;i++){
    string s=S.substr(i,3);
    int a=stoi(s);
    if (min>abs(a-753)){
      min=abs(a-753);
    }
  }
  cout <<min <<endl;
}  
  

Measured memory_bytes: 256