akhauriyash/Code-Regression huggingface dataset:
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int64, n)
	var ans, x int64
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
		x ^= aa[i]
	}
	j := 0
	rr := make([]int, 64)
	for b := 60; b >= 0; b-- {
		if x>>uint(b)&1 != 0 {
			continue
		}
		found := false
		for i := j; i < n; i++ {
			if (aa[i]>>uint(b))&1 == 1 {
				aa[i], aa[j] = aa[j], aa[i]
				rr[j] = b
				j++
				found = true
				break
			}
		}
		if found == false {
			continue
		}
		for i := 0; i < n; i++ {
			if (aa[i]>>uint(b))&1 == 0 {
				continue
			}
			if i == j-1 {
				continue
			}
			aa[i] ^= aa[j-1]
		}
	}

	for i := 60; i >= 0; i-- {
		if x>>uint(i)&1 != 0 {
			continue
		}
		nx := ans | 1<<uint(i)
		b := nx
		for r := 0; r < j; r++ {
			if (nx>>uint(rr[r]))&1 == 1 {
				b ^= aa[r]
			}
		}
		if b&nx == 0 {
			ans = nx
		}

	}

	fmt.Fprintln(writer, ans*2+x)

	writer.Flush()
}


Measured memory_bytes: 5120
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
     nm = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(nm[0], 10);
	var m = parseInt(nm[1], 10);
//  console.log(n,m);
    
    if (n==m){console.log('Yes');}
       else{console.log('No');}

	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  string s;
  cin >> s;
  int n = s.size();

  bool fn = false;
  bool fw = false;
  bool fs = false;
  bool fe = false;  
  rep(i,n){
    if(s[i]=='N') fn = true;
    if(s[i]=='W') fw = true;
    if(s[i]=='S') fs = true;
    if(s[i]=='E') fe = true;     
  }

  if((fn^fs)||(fw^fe)) cout << "No" << "\n";
  else cout << "Yes" << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>


int main() {

    string s, t;
    cin>>s>>t;

    int n = s.length();

    int ans = 0;

    for(int i=0; i<n; i++) {
        if(s[i] != t[i]) {
            ans++;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3916
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_N 2000
#define MOD 1000000007

using namespace std;
typedef pair<int, int> ipair;

int N, M;
int S[MAX_N], T[MAX_N];
llong dp[MAX_N + 1][MAX_N + 1];

llong solve() {
    for(int i = 0; i <= N; ++i)
        dp[i][0] = 1;
    for(int j = 0; j <= M; ++j)
        dp[0][j] = 1;

    for(int i = 0; i < N; ++i)
        for(int j = 0; j < M; ++j) {
            if(S[i] == T[j]) {
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD;
            } else {
                dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j] + MOD) % MOD;
            }
        }

    return dp[N][M];
}

int main(int argc, char **argv) {
    cin >> N >> M;
    for(int i = 0; i < N; ++i)
        cin >> S[i];
    for(int i = 0; i < M; ++i)
        cin >> T[i];
    
    cout << solve() << endl;
}

Measured memory_bytes: 31488
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  ll X;
  cin >> X;
  for (ll i = 0; i < 100000; ++i) {
    if (X <= i * (i+1) / 2) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
/**
*    author:  souzai32
*    created: 01.08.2020 19:12:49
**/

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

int main() {

    int n;
    string s;
    cin >> n >> s;
    int num=0;
    int ans=n;

    for(int i=0; i<n; i++){
        if(s.at(i)=='E') num++;
    }

    for(int i=0; i<n; i++){
        if(s.at(i)=='E'){
            ans=min(ans,num-1);
            num--;
        }
        if(s.at(i)=='W'){
            ans=min(ans,num);
            num++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

const ll INF = 1ll << 60;
ll MOD = 998244353;

int main()
{

    int p, q, r;
    vector<int> a(3);
    //cin >> p >> q >> r;
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    cout << a[0] + a[1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int Mod=1e9+7;
int x[200005],y[200005];
long long dis[200005];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]);
		dis[i]=x[i]+y[i];
	}
	sort(dis+1,dis+1+n);
	long long ans=dis[n]-dis[1];
	for(int i=1;i<=n;i++){
		x[i]=-x[i];
		dis[i]=x[i]+y[i];
	}
	sort(dis+1,dis+1+n);
	cout<<max(ans,dis[n]-dis[1]);
	return 0;
} 


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

int main (){
	int n,d,i,j,k,y,dist,ans=0,x[20][20];
	cin >> n >> d;
	for(i=1;i<=n;i++){
		for(j=1;j<=d;j++) cin >> x[i][j];
	}
	for(i=1;i<n;i++){
		for(j=i+1;j<=n;j++){
			dist=0;
			for(k=1;k<=d;k++) dist+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			for(y=sqrt(dist);y<=dist;y++){
				if(y*y==dist) ans++;
				if(y*y>=dist) break;
			}
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    REP(i, n-2){
        if(a[i+1] > min(a[i], a[i+2]) && a[i+1] < max(a[i], a[i+2])) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import math
def soinsu(N):
    sqr = int(math.sqrt(N))
    lis = []
    for i in range(2,sqr+2):
        while N % i == 0:
            lis.append(i)
            N = N // i
    if not N == 1:
        lis.append(N)
    return lis
mod = 1000000007
def modpow(a,b,MOD=mod):
    res = 1
    while b > 0:
        if (b & 1) == 1:
            res = (res*a) % MOD
        a = (a*a) % MOD
        b = b >> 1
    return res
fact = []
def ncrinit(MOD=mod):
    fact.append(1)
    for i in range(1,110005):
        fact.append((fact[i-1]*i)%MOD)

def calcnCr(n,r,MOD=mod):
    up = fact[n]
    down = modpow((fact[n-r]*fact[r])%mod,mod-2,mod)
    return (up*down)%mod

def compres(lis):
    li = []
    se = set(lis)
    for i in se:
        li.append(lis.count(i))
    return li
res = 1
N,M = list(map(int,input().split()))
ncrinit()
co = compres(soinsu(M))
for i in co:
    res = (res* (calcnCr(i+N-1,i)))%mod
print(res)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000007;
const static int inf = INT_MAX;
const static llong INF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

template<typename T> T my_lcm(T a, T b){
    return a * b / my_gcd(a, b);    
}

void solve();

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}

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

    llong ans = 0;
    if (n % 2) {
        cout << ans << endl;
        return;
    }

    llong div = 10;
    while (div <= n) {
        ans += floor((long double)n/div);
        div *= 5;
    }

    cout << ans << endl;
    return;
}


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

#define FOR(i,a,b) for(ll i=a; i<b; i++)
#define IN(a) cin>>a
#define OUT(a) cout<<a<<endl

int main(){
  int a;
  IN(a);
  OUT(a+pow(a,2)+pow(a,3));
}

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

const int N = 233333;
int notp[N], pri[N], pc = 0;

int main() {
  notp[1] = 1;
  for (int i = 2; i < N; i++) {
    if (!notp[i]) {
      pri[++pc] = i;
    }
    for (int j = 1; j <= pc && i * pri[j] < N; j++) {
      notp[i * pri[j]] = 1;
      if (!(i % pri[j])) break;
    }
  }
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if ((i + j) & 1) {
        printf("%lld ", (long long) pri[(i - j + n + 3) / 2] * pri[(i + j + n * 2 + 3) / 2]);
      } else {
        long long x = 1;
        if (i > 1 || j > 1) x *= pri[(i + j - 1 + n * 2 + 3) / 2];
        if (i < n || j < n) x *= pri[(i + j + 1 + n * 2 + 3) / 2];
        if (i > 1 || j < n) x *= pri[(i - j - 1 + n + 3) / 2];
        if (i < n || j > 1) x *= pri[(i - j + 1 + n + 3) / 2];
        if (n == 2 && i == 1 && j == 1) x <<= 1;
        printf("%lld ", x + 1);
      }
    }
    puts("");
  }
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define int long long int
#define rep(a,b) for(int a=0;a<b;a++)
#define pb push_back
#define str string
#define INF
#define sf(a) scanf("%d",&a)

using namespace std;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int b,c,d=0,e=0;
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    for(int i=0;i<3;i++){
        if(a[i]==5){
           d++;
        }else if(a[i]==7){
            e++;
        }
    }
    if(d==2&&e==1){
        cout << "YES";
    }else cout << "NO";
    cout << endl;
return 0;
}


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

using namespace std;

int main()
{
  int n;
  vector<int> a;
  vector<int> b;
  vector<int> c;

  cin >> n;

  a.resize(n);
  b.resize(n);
  c.resize(n - 1);

  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    a[i]--;
  }
  for (int i = 0; i < n; i++)
  {
    cin >> b[i];
  }
  for (int i = 0; i < n - 1; i++)
  {
    cin >> c[i];
  }

  int sum = 0;
  for (int i = 0; i < n; i++)
  {
    sum += b[a[i]];
    if (i < n - 1 && a[i] + 1 == a[i + 1])
    {
      sum += c[a[i]];
    }
  }

  cout << sum << endl;
  return 0;
}

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

using namespace std;

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

    using ll = long long;

    vector<ll> a(n);

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

    const ll inf = 1LL << 60;

    vector<vector<ll>> dp(n, vector<ll>(n, inf));

    for (int i = 0; i < n; i++) {
        dp[i][i] = 0;
    }

    for (int i = 1; i < n; i++) {
        for (int j = 0; j + i < n; j++) {
            int l = j, r = j + i;

            ll s = 0;
            for (int k = l; k <= r; ++k) {
                s += a[k];
            }

            for (int k = l; k < r; k++) {
                dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r]);
            }

            dp[l][r] += s;
        }
    }

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


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N; cin >> N;
  vector<PII> xs(N);
  REP(i,N){
	int x; cin >> x;
	xs[i].FF = x-1;
	xs[i].SS = i;
  }
  SORT(xs);
  VI num(N);

  bool ok = true;
  VI ans;
  REP(i,N*N){
	bool done = false;
	for(int j=0;j<N&&!done;++j){
	  if(xs[j].FF == i){
		done = true;
		if(num[xs[j].SS] != xs[j].SS)
		  ok = false;
		else{
		  ans.PB(xs[j].SS);
		  ++num[xs[j].SS];
		}
	  }
	  else if(i < xs[j].FF && num[xs[j].SS] < xs[j].SS){
		done = true;
		ans.PB(xs[j].SS);
		num[xs[j].SS]++;
	  }
	}
	if(!done){
	  REP(j,N)
		if(num[xs[j].SS] < N){
		  ans.PB(xs[j].SS);
		  ++num[xs[j].SS];
		  break;
		}
	}
  }

  if(ok){
	cout << "Yes" << endl;
	REP(i,N*N)
	  cout << (i?" ":"") << ans[i]+1;
	cout << endl;
  }
  else
	cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 2420
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5+5;

int n , m;

ll ncr(int n){
    return n * (n - 1LL) / 2;
}

int main(){
    cin >> n >> m;
    cout << ncr(n) + ncr(m) << "\n";
}


Measured memory_bytes: 256
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]

cnt = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        a = 0
        for k in range(D):
            a += (X[i][k] - X[j][k]) ** 2
        a = a ** 0.5
        if int(a) == a:
            cnt += 1

print(cnt // 2)

Measured memory_bytes: 3188
#include<iostream>

using namespace std;
#define MAX 1000000
#define INF 1000000000

int dp1[MAX+1],dp2[MAX+2];

int main() {
    for(int i = 1;i <= MAX;i++) {
        dp1[i] = INF;
        dp2[i] = INF;
    }

    for(int n = 1;n * (n + 1) * (n + 2) / 6 <= MAX;n++) {
        int a = n * (n + 1) * (n + 2) / 6;
        for(int i = a;i <= MAX;i++) {
            dp1[i] = min(dp1[i],dp1[i - a] + 1);
        }
        if(a % 2 == 0)continue;
        for(int i = a;i <= MAX;i++) {
            dp2[i] = min(dp2[i],dp2[i - a] + 1);
        }
    }

    while(true) {
        int n;
        cin >> n;
        if(n == 0)break;
        cout << dp1[n] << " " << dp2[n] << endl;
    }
    return 0;
}



Measured memory_bytes: 10892
K, N = map(int, input().split())

if K % 2 == 0:
    ans = [K//2] + [K] * (N-1)
else:
    ans = [(K+1)//2] * N
    for i in range(N//2):
        if ans[-1] == 1:
            ans.pop()
        else:
            ans[-1] -= 1
            ans += [K] * (N - len(ans))

print(' '.join(map(str, ans)))


Measured memory_bytes: 26532
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;

int main(){
    ll N;
    cin >> N;
    long double ans;
    if(N%2 == 0){
        ans = 1/2.0;
    }
    else{
        long double k = N;
        ans = (N/2+1)/k;
    }
    std::cout << std::setprecision(7) << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[256];
	int i;
	
	i = 0;
	
	fgets(str, sizeof(str), stdin);
	
	str[strlen(str) - 1] = '\0';
	
	while (str[i] != '\0'){
		if (str[i] >= 'a' && str[i] <= 'z'){
			str[i] -= 0x20;
		}
		i++;
	}
	
	printf("%s\n", str);
	
	return (0);
}

Measured memory_bytes: 0
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var K = cin.ReadInt;

            var h = cin.ReadIntArray(N);
            var ans = h.Where(a => a >= K).Count();
            WriteLine(ans);
        }
        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 18144
#include <iostream>

using namespace std;

int main(void){
  int n;
  cin >> n;
  int ans = 0, cnt = 0, color = 10000;
  for(int i = 0; i < n; ++i){
    int c;
    cin >> c;
    if (c == color){
      ++cnt;
    }else{
      if (cnt >= 2){
        ans += cnt/2;
      }
      color = c;
      cnt = 1;
    }
  }
  if (cnt >= 2){
    ans += cnt/2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int k;
    cin >> k;

    int b = 0;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] != s[i]) b = 1;
    }
    if (!b) {
        cout << (ll)n * k / 2 << endl;
        exit(0);
    }

    auto f = [](string &s) {
        int n = s.size();
        int r = 0, l = 0;
        char c = 0;
        for (int i = 0; i <= n; i++) {
            if (i < n && s[i] == c) {
                l++;
            } else {
                r += l / 2;
                if (i == n) break;
                l = 1;
                c = s[i];
            }
        }
        return r;
    };

    string t = s + s;

    cout << f(s) + (ll)(f(t) - f(s)) * (k - 1) << endl;

    return 0;
}

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

const double EPS=1e-10;
double add(double l, double r){
    if(abs(l+r)<EPS*(abs(l)+abs(r))) return 0;
    return l+r;
}
//l-r は add(l,-r)
//l==r は add(l,-r)==0
struct Pt{
    double x, y;
    Pt(double xx=0, double yy=0){x=xx; y=yy;}
    Pt& operator=(const Pt &rhs){
        x=rhs.x; y=rhs.y; return *this;
    }
    Pt& operator+=(const Pt &rhs){
        x = add(x,rhs.x); y = add(y,rhs.y); return *this;
    }
    Pt& operator-=(const Pt &rhs){
        x = add(x,-rhs.x); y = add(y,-rhs.y); return *this;
    }
    Pt& operator*=(const double &rhs){
        x *= rhs; y *= rhs; return *this;
    }
    Pt& operator/=(const double &rhs){
        x /= rhs; y /= rhs; return *this;
    }
};
Pt operator+(const Pt &a){return a;}
Pt operator-(const Pt &a){return Pt(-a.x,-a.y);}
Pt operator+(const Pt &lhs, const Pt &rhs){
    Pt ans=lhs; ans += rhs; return ans;
}
Pt operator-(const Pt &lhs, const Pt &rhs){
    Pt ans=lhs; ans -= rhs; return ans;
}
Pt operator*(const Pt &lhs, const double &rhs){
    Pt ans=lhs; ans *= rhs; return ans;
}
Pt operator*(const double &lhs, const Pt &rhs){
    Pt ans=rhs; ans *= lhs; return ans;
}
Pt operator/(const Pt &lhs, const double &rhs){
    Pt ans=lhs; ans /= rhs; return ans;
}
bool operator==(const Pt &lhs, const Pt &rhs){
    return add(lhs.x,-rhs.x)==0 && add(lhs.y,-rhs.y)==0;
}
bool operator!=(const Pt &lhs, const Pt &rhs){return !(lhs==rhs);}
bool operator<(const Pt &lhs, const Pt &rhs){
    return add(lhs.x,-rhs.x)!=0 ? add(lhs.x,-rhs.x)<0 : add(lhs.y,-rhs.y)<0;
}
bool operator>(const Pt &lhs, const Pt &rhs){return rhs<lhs;}
bool operator<=(const Pt &lhs, const Pt &rhs){return !(lhs>rhs);}
bool operator>=(const Pt &lhs, const Pt &rhs){return !(lhs<rhs);}
istream& operator>>(istream &is, Pt &rhs){
    double x, y;
    is >> x >> y;
    rhs=Pt(x,y);
    return is;
}
ostream& operator<<(ostream &os, const Pt &rhs){
    os << rhs.x << " " << rhs.y;
    return os;
}
double norm(const Pt &a){return add(a.x*a.x,a.y*a.y);}
double abs(const Pt &a){return sqrt(norm(a));}
double dot(Pt a, Pt b){return add(a.x*b.x,a.y*b.y);}
double cross(Pt a, Pt b){return add(a.x*b.y,-a.y*b.x);}
int ccw(Pt a, Pt b, Pt c) {
    b -= a; c -= a;
    if(cross(b, c)>0) return +2;  // counter clockwise
    if(cross(b, c)<0) return -2;  // clockwise
    if(dot(b, c)<0) return +1;        // c--a--b on line
    if(norm(c)<norm(b)) return -1;    // b--c--a on line
    return 0;                         // a--b--c on line
}
int main(){
  ll n;
  cin>>n;
  vector<Pt> rec;
  Pt centroid=0;
  rep(i,n){
    Pt tmp;
    cin>>tmp;
    rec.push_back(tmp);
    centroid+=tmp;
  }
  if(n%2==1){
    cout<<"NA"<<endl;
    return 0;
  }
  centroid/=n;
  bool f=true;
  rep(i,n){
    if(ccw(rec[i%n],centroid,rec[(i+n/2)%n])!=0 && f){
      cout<<"NA"<<endl;
      f=false;
    }
  }
  cout<<fixed<<setprecision(10);
  if(f)cout<<centroid<<endl;
}



Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
int main(){
    int L, R, d;
    cin >> L >> R >> d;
    int cnt=0;
    for(int i=L; i<=R; i++){
        if(i%d==0){
            cnt++;
        }
    }
    cout  << cnt << endl;

}




Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int N;
int p[10];

void _main() {
  cin >> N;
  rep(i, 0, N) cin >> p[i];
  sort(p, p+N);

  int ans = 0;
  rep(i, 0, N) ans += p[i];
  ans -= p[N-1] / 2;
  cout << ans << "\n";
}

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

int main(){
  string n;
  cin >> n;
  long long sum = 0;
  int length = n.size();
  for(int i = 0; i < length; i++){
    sum += n[i] - '0';
  }
  if(sum % 9 == 0){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    string S;
    ll P;
    vector<pair<string, pair<ll, ll> > > p;
    rep(i, N){
        cin >> S >> P;
        p.push_back(make_pair(S, make_pair(-P, i + 1)));
    }
    sort(p.begin(), p.end());

    rep(i, N){
        cout << p[i].second.second << endl;
    }

    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    string s;
    cin >> s;
    if(s=="AKIHABARA"){
        cout << "YES" << endl;
        return 0;
    }
    string t = s;
    int n=t.size();
    rep(i,n+1){
        t.insert(t.begin()+i,'A');
        if(t=="AKIHABARA"){
            cout << "YES" << endl;
            return 0;
        }
        rep(j,n+2){
            string u = t;
            u.insert(u.begin()+j,'A');
            if(u=="AKIHABARA"){
                cout << "YES" << endl;
                return 0;
            }
            rep(k,n+3){
                string v = u;
                v.insert(v.begin()+k,'A');
                if(v=="AKIHABARA"){
                    cout << "YES" << endl;
                    return 0;
                }
                rep(l,n+4){
                    string w = v;
                    w.insert(w.begin()+l,'A');
                    if(w=="AKIHABARA"){
                        cout << "YES" << endl;
                        return 0;
                    }
                    w = v;
                }
                v = u;
            }
            u = t;
        }
        t = s;
    }
    cout << "NO" << endl;
 }

Measured memory_bytes: 256
N, M = map(int, input().split())
A = map(int, input().split())

S = [0]
w = 0
for a in A:
    w += a
    S.append(w % M)

S.sort()
ans = 0
prev = S[0]
c = 1
for i in range(1, N+1):
    if S[i] != prev:
        prev = S[i]
        ans += c * (c - 1) // 2
        c = 1
    else:
        c += 1
ans += c * (c - 1) // 2
print(ans)




Measured memory_bytes: 62576
#include <iostream>
#include <stack>
#include <vector>
#pragma region Common
using namespace std;
#define RANGE(i, a, b) for (int i = (a); i <= (b); i++)
#define RANGER(i, a, b) for (int i = (b); i >= (a); i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, a) RANGE(i, 0, a - 1)
#define REPR(i, a) RANGER(i, a - 1, 0)
#pragma endregion

using ll = long long int;
struct Edge {
  ll c;
  int v; // vertex (0-based index)
};
int main() {
  int N;
  cin >> N;
  vector<vector<Edge>> e(N, vector<Edge>());
  REP(i, N - 1) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    e[a].push_back({c, b});
    e[b].push_back({c, a});
  }

  int Q, K;
  cin >> Q >> K;
  K--;

  stack<int> stk;
  vector<ll> minC(N, -1);
  stk.push(K);
  minC[K] = 0;
  while (stk.size() > 0) {
    int i = stk.top();
    stk.pop();
    for (auto &v : e[i]) {
      if (minC[v.v] > 0)
        continue;
      minC[v.v] = minC[i] + v.c;
      stk.push(v.v);
    }
  }

  REP(j, Q) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << (minC[x] + minC[y]) << "\n";
  }
  return 0;
}

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

int main() {
  int testNum;
  cin >> testNum;
  
  int tmp = testNum;
  int sumCoeff = 0;
  while(tmp > 0) {
    sumCoeff += tmp % 10;
    tmp /= 10;
  }
  if(testNum % sumCoeff == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
ai = max(a)
aj = -1
dj = ai
for ak in a:
    if ak == ai:
        continue
    dk = abs(ai // 2 - ak)
    if dk < dj:
        aj = ak
        dj = dk
print(ai, aj)

Measured memory_bytes: 14052
import scala.io.StdIn

object Main extends App {

  final val nil = -1
  
  case class Node(var parent: Int = -1,var left: Int = -1, var right: Int = -1)

  val n = StdIn.readLine().trim.toInt
  val input  = Array.fill[Node](n)(Node())
  val depth  = Array.fill[Int](n)(0)
  val height = Array.fill[Int](n)(0)

  (0 until n).foreach{ _ =>
    val Array(current, left, right) = StdIn.readLine().trim.split(" ").map(_.toInt)
    input(current).left = left
    input(current).right = right
    if(left != nil) input(left).parent = current
    if(right != nil) input(right).parent = current
  }

  var root = nil
  (0 until n).foreach{ i =>
    //println(s"$i:" + input(i))
    if(input(i).parent == nil) root = i
  }
  
  def preorder(index: Int): Unit = {
    if(index != nil) {
      print(" " + index)
      preorder(input(index).left)
      preorder(input(index).right)
    }
  }

  def inorder(index: Int): Unit = {
    if(index != nil){
      inorder(input(index).left)
      print(" " + index)
      inorder(input(index).right)
    }
  }

  def postorder(index: Int): Unit = {
    if(index != nil) {
      postorder(input(index).left)
      postorder(input(index).right)
      print(" " + index)
    }
  }
  
  println("Preorder")
  preorder(root)
  println("")

  println("Inorder")
  inorder(root)
  println("")

  println("Postorder")
  postorder(root)
  println("")

}


Measured memory_bytes: 44308
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b,i;cin >> k >> a >> b;
  for(i=a;i<=b;i++){
    if(i%k==0){
      cout << "OK" << "\n";return 0;
    }
  }
  cout << "NG" << "\n";
}

Measured memory_bytes: 3592
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        var n = int.Parse(line[2]);
        Console.WriteLine(getAns(a, b, n));
    }
    static long getAns(long a, long b, int n)
    {
        var ans = long.MaxValue;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                if (b % j == 0)
                {
                    var w = i * (b / j);
                    ans = Min(ans, Abs(w - a));
                }
        return ans;
    }
}



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

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

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

const int MOD = 1e9 + 7;

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

    ll a, b, c;
    cin >> a >> b >> c;

    ll tmp = c - a - b;
    if(4*a*b < tmp * tmp && tmp > 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


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


using namespace std;
#define LOOP(val, times)   for(val = 0; val < (times); val++)
long long ff(long a,long b){
  if(a==0){
    return b;
  }
  
  long long maxs=b;
  long long mins=a;
  long long r=maxs%mins;
  return ff(r,mins);
  
}
long long gg(long long a,long long b,long long c){
  long long ans=b/c-(a-1)/c;
  return ans;
}
int main(){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long n=max(c,d);
  long long m=min(c,d);
  long long h=(c*d)/ff(m,n);
  long long ans=b-a+1-gg(a,b,c)-gg(a,b,d)+gg(a,b,h);
  cout<<ans<<endl;
}
  

Measured memory_bytes: 256
n=int(input())
f=[list(map(int,input().split()))for _ in range(n)]
p=[list(map(int,input().split()))for _ in range(n)]
ans=-10**10
for bit in range(1,1<<10):
  a=0
  for i in range(n):
    b=0
    for j in range(10):
      if bit&1<<j:b+=f[i][j]
    a+=p[i][b]
  ans=max(a,ans)
print(ans)

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

vector<int> to[200005];
vector<int> ans;

void dfs(int n,int p=-1){
    for(int i : to[n]){
        if(i==p) continue;
        ans[i] += ans[n];
        dfs(i,n);
    }
}

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


    for(int i=0;i<n-1;i++){
        cin >> a >> b;
        to[a-1].push_back(b-1);
        to[b-1].push_back(a-1);
    }

    ans.resize(n);
    for(int i=0;i<q;i++){
        cin >> p >> x;
        ans[p-1] += x;
    }

    dfs(0);

    for(int i=0;i<n;i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 23424
import sys, heapq, bisect, math, fractions
from collections import deque
from collections import Counter
from collections import OrderedDict

N, K = map(int, input().split())
od = OrderedDict()

for i in range(N):
    a, b = map(int, input().split())
    if a not in od:
        od[a] = b
    else:
        od[a] += b
od = OrderedDict(sorted(od.items(), key=lambda x: x[0]))

for i in od.items():
    K -= i[1]

    if K <= 0:
        print(i[0])
        exit()


Measured memory_bytes: 47012
N = int(input())
for h in range(1,3501):
  for n in range(1,3501):
    a = N*h*n
    b = 4*h*n - N*h - N*n
    if b != 0 and a % b == 0 and 0 < a//b <= 3500:
      print(h,n,a//b)
      exit()

Measured memory_bytes: 67660
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int w,a,b;
	cin>>w>>a>>b;
	if(abs(a-b)<=w)cout<<0<<endl;
	else cout<<abs((abs(a-b))-w)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}
     
int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector <int> v, v1;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        v.pb(x);
    }
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        v1.pb(x);
    }
    int ans = 0 ;
    for(int i = 0; i < n; ++i){
        if(v[i] > v1[i]){
            ans += v[i] - v1[i];
        }
    }
    cout << ans ;
    

    
    


}


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

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

    int n = N * 2;
    vector<int> L(n);

    for (int i = 0; i < n; i++){
        cin >> L.at(i);
    }
    
    sort(L.begin(), L.end());

    int count = 0;
    for (int i = 0; i < n; i = i + 2){
        count += min(L.at(i), L.at(i+1)); 
    }

    cout << count << endl;

}


Measured memory_bytes: 764
#include<iostream>
#include<complex>
using namespace std;
int main(){

    int n;
    while(cin>>n,n){

        complex<int> gem[30];
        for(int i = 0;i < n;i++){
            cin>>gem[i].real()>>gem[i].imag();
            if(gem[i].real() == 10 && gem[i].imag() == 10)gem[i].real() = gem[i].imag() = -1;
        }

        int m;
        cin>>m;

        const char way[] = "NESW";
        const int dx[] = {0,1,0,-1};
        const int dy[] = {1,0,-1,0};
        complex<int> com[50];
        complex<int> pos;
        pos.real() = pos.imag() = 10;
        for(int i = 0;i < m;i++){
            char c;
            int x;
            cin>>c>>x;
            for(int j = 0;j < 4;j++){
                if(c == way[j]){
                    com[i].real() = dx[j],com[i].imag() = dy[j];
                    while(x--){
                        pos+=com[i];
                        for(int j = 0;j < n;j++){
                            if(pos == gem[j])gem[j].real() = gem[j].imag() = -1;
                        }
                    }
                }
            }


        }

        bool flg = true;
        for(int i = 0;i < n;i++){
           // cout<<gem[i].real()<<", "<<gem[i].imag()<<endl;
            if(gem[i].real() != -1)flg = false;
        }
        if(flg)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;



    }

    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(), y = sc.nextInt();
        if(y % 2 == 0 && x * 2 <= y && x * 4 >= y){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 27028
#include <iostream>

using namespace std;

inline int Rotate(char a, char b) {
	return (a - b + ('z' - 'a' + 1)) % ('z' - 'a' + 1);
}

int main(void) {
	char str[81];
	int shift = 0;
	while(cin.getline(str, 81)) {
		shift = 0;
		for(int i = 0; str[i] != NULL; i++) {
			if((str[i] != NULL) && (str[i+1] != NULL) && (str[i+2] != NULL) &&
				(str[i] != ' ') && (str[i+1] != ' ') && (str[i+2] != ' ')) {
					if(Rotate(str[i+1], str[i]) == Rotate('h', 't')) {
						if(Rotate(str[i+2], str[i+1]) == Rotate('e', 'h')) {
							shift = 't' - str[i];
							break;
						}
						if(str[i+3] != NULL && str[i+3] != ' ') {
							if((Rotate(str[i+2], str[i+1]) == Rotate('i', 'h')) && (Rotate(str[i+3], str[i+2]) == Rotate('s', 'i'))) {
								shift = 't' - str[i];
								break;
							}
							if((Rotate(str[i+2], str[i+1]) == Rotate('a', 'h')) && (Rotate(str[i+3], str[i+2]) == Rotate('t', 'a'))) {
								shift = 't' - str[i];
								break;
							}
						}
					}
			}
		}

		for(int i = 0; str[i] != NULL; i++) {
			if(str[i] != ' ' && str[i] != '.') {
				str[i] = (str[i] - 'a' + shift + ('z' - 'a' + 1)) % ('z' - 'a' + 1) + 'a';
			}
		}

		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1120
#include<cstdio>
#include<algorithm>
using namespace std;
int n,ans,a[2005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1,sum;i<=n;i++)
	{
		for(int j=i+1,k=j;j<=n;j++)
		{
			sum=a[i]+a[j];
			while(k<n&&sum>a[k+1])k++;
			ans+=k-j;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
# = map(int, input().split())
N = int(input())
L = list(map(int, input().split()))
ans = 0
for k in range(N-2):
  for j in range(k+1, N-1):
    for l in range(j+1, N):
      li = [L[k], L[j], L[l]]
      li.sort()
      if li[0] < li[1] < li[2]:
        if li[2] < li[0] + li[1]:
          ans += 1
print(ans)

Measured memory_bytes: 9196
#include <iostream>

struct Node {
	int parent;
	int dif_to_parent;
};

int root(Node* nodes, int x)
{
	if (nodes[x].parent == x) return x;
	else return root(nodes, nodes[x].parent);
}

bool isSame(Node* nodes, int x, int y)
{
	return root(nodes, x) == root(nodes, y);
}

void unite(Node* nodes, int x, int y, int dif)
{
	int x_depth = 0;
	int y_depth = 0;
	while (nodes[x].parent != x) {
		x_depth += nodes[x].dif_to_parent;
		x = nodes[x].parent;
	}
	while (nodes[y].parent != y) {
		y_depth += nodes[y].dif_to_parent;
		y = nodes[y].parent;
	}
	if (x_depth + dif > y_depth) {
		nodes[y].parent = x;
		nodes[y].dif_to_parent = x_depth + dif - y_depth;
	} else {
		nodes[x].parent = y;
		nodes[x].dif_to_parent = y_depth - x_depth - dif;
	}
}

int difference(Node* nodes, int x, int y)
{
	int x_depth = 0;
	int y_depth = 0;
	int rx = x;
	int ry = y;
	while (nodes[rx].parent != rx) {
		x_depth += nodes[rx].dif_to_parent;
		rx = nodes[rx].parent;
	}
	while (nodes[ry].parent != ry) {
		y_depth += nodes[ry].dif_to_parent;
		ry = nodes[ry].parent;
	}
	nodes[x].parent = rx;
	nodes[x].dif_to_parent = x_depth;
	nodes[y].parent = ry;
	nodes[y].dif_to_parent = y_depth;
	return y_depth - x_depth;
}

int main()
{	
	int n, q; std::cin >> n >> q;
	
	Node* nodes = new Node[n];
	for (int i=0; i<n; i++) {
		nodes[i].parent = i;
	}
	
	for (int i=0; i<q; i++) {
		int op, x, y, z;
		std::cin >> op;
		if (op==0) {
			std::cin >> x >> y >> z;
			unite(nodes, x, y, z);
		} else {
			std::cin >> x >> y;
			if (isSame(nodes, x, y)) std::cout << difference(nodes, x, y) << std::endl;
			else std::cout << "?" << std::endl;
		}
	}
	
	delete[] nodes;
	
	return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n; cin>>n;
    vector<int> steps;
    for(int i=0;i<n;i++)
    {
        int t; cin>>t; steps.push_back(t);
    }
    vector<int> ans(n,0);
    for(int i=n-2;i>=0;i--)
    {
      //cout<<"inside\n";
        if(i==n-2)
        {
            ans[i] = abs(steps[i+1]-steps[i]);
        }
        else
        {
            ans[i] = min(ans[i+1]+abs(steps[i+1]-steps[i]), ans[i+2]+abs(steps[i+2]-steps[i]));
        }
    }
    cout<<ans[0];
    return 0;
}

Measured memory_bytes: 1144
<?php
fscanf(STDIN,"%d %d",$L,$R);
//1組目を初期値にする
$result = (($L%2019)*(($L+1)%2019))%2019;
//1組目を除いて総当り
for($i=$L;$i<=$R-1;$i++){
  if($result === 0){
    break;
  }
  for($j=$L+1;$j<=$R;$j++){
    if($result === 0){
      break;
    }
    //最小値更新
    if($result > (($i%2019)*($j%2019))%2019){
      $result = (($i%2019)*($j%2019))%2019;
    }
  }
}
echo $result;


Measured memory_bytes: 4340
#include <cstdio>
#define N 66
using namespace std;
long long pos,bitn[N],bitm[N];long long n,m,ans,tmp1,tmp2;
inline long long read()
{
	long long x=0,c=getchar();while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')x=x*10+c-48,c=getchar();return x;
}
void print(long long x)
{
	if(x>9)print(x/10);putchar(x%10+48);
}
int main()
{
	n=read();m=read();
	if(n==m)return puts("1"),0;
	for(long long i=0;i<=60;i++){
		if((1LL<<i)&n)bitn[i]=1;
		if((1LL<<i)&m)bitm[i]=1;
		if(bitm[i]>bitn[i])pos=i;
	}
	for(long long i=0;i<pos;i++)tmp1+=(1LL*bitn[i]<<i);
	for(long long i=0;i<pos;i++)if(bitm[i])tmp2=(1LL<<(i+1))-1;
	ans=(1LL<<pos)-tmp1;
	if(ans+tmp2+1LL>=(1LL<<pos))ans+=(1LL<<pos);else ans+=ans+tmp2+1LL;
	print(ans);
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
  int k;
  int a, b;
  int judge = 0;
  scanf("%d", &k);
  scanf("%d%d", &a, &b);
  for(int i = a; i <= b; i++) {
    if(i % k == 0) {
      judge = 1;
    }
  }
  if(judge == 1) {
    printf("OK");
  } else {
    printf("NG");
  }
  return 0;
}


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

int main(){
	int n;
  cin >> n;
  vector<int> a(n);
  priority_queue<int> q;
  rep(i,n) {
    cin >> a[i];
    q.push(a[i]);
  }
  int left = q.top(); q.pop();
  int right = q.top(); q.pop();
  rep(i, n){
    if(a[i] != left){	
      cout << left << endl;
    }else{
      cout << right << endl;
    }
  }
}

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define reps(i,j,n) for(int i = j ; i < n ; ++i)
#define rep(i,n) reps(i,0,n)
vector<int>vn,vm;
int n,m;
bool flg;
string tmp[]={"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
void solve(int now,int cnt){
  if( flg ) return;
  if( cnt < 0 && now == -1 ) flg = true;
  if( now < 0 || now > n - 1 ) return;
  if( vn[now] == vm[cnt] ) solve( now - 1 , cnt - 1 );
  if( ( vn[now] + 1 ) % 12 == vm[cnt] ) solve( now - 2 , cnt - 1 );
  if( ( vn[now] + 11 ) % 12 == vm[cnt] ) solve( now + 1 , cnt - 1 );
}
int FIND(string s){rep(i,12) if( s == tmp[i] ) return i;}
int main(){
  string s;
  int q;
  cin >> q;
  while(q--){
    flg = false;
    cin >> n >> m;
    vn.resize(n) , vm.resize(m);
    rep(i,n) cin >> s , vn[i] = FIND(s);
    rep(i,m) cin >> s , vm[i] = FIND(s);
    solve(n-1,m-1) , solve(n-2,m-1);
    cout << ( flg ? "Yes" : "No" ) << endl;
  }
}

Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
int n,m;
cin >> n >> m;
vector<bool>trap(n+1,true);
for(int i=0;i<m;i++){
  int z;
  cin >> z;
  trap[z]=false;
}
vector<int>dp(n+1,0);
dp[0]=1;
ll mod = 1000000007;
for(int now=0;now<=n;now++){
  for(int next=now+1;next<=min(n,now+2);next++){
    if(trap[next]){
      dp[next]+=dp[now];
      dp[next]%=mod;
    }
  }
}
cout << dp[n]<<endl;
}
 


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

using namespace std;

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

set<pii> win;
set<pii> seen;
bool wins(int a, int b) {
  if(seen.count({a, b})) return win.count({a, b});
  seen.insert({a, b});
  bool ret = false;
  for(int i = 2; i <= a; i += 2) {
    ret |= !wins(a-i, b+i/2);
  }
  for(int i = 2; i <= b; i += 2) {
    ret |= !wins(a+i/2, b-i);
  }
  if(ret) win.insert({a, b});
  return ret;
}

void solve() {
  ll a, b;
  cin >> a >> b;
  if(abs(a-b) <= 1) cout << "Brown\n";
  else cout << "Alice\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, ans = 1; cin >> N;
  string S; cin >> S;
  for(int i = 0; i < N - 1; i++){
    if(S[i] != S[i + 1]) ans += 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define Re register
#define LL long long
#define U unsigned
#define FOR(i,a,b) for(Re int i = a;i <= b;++i)
#define ROF(i,a,b) for(Re int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 200000+5;

struct Node{
	struct Edge *firstEdge;
	int d[2];bool vis;
	int num;
}node[MAXN];

struct Edge{
	Node *s,*t;
	Edge *next;
}pool[MAXN<<1],*frog = pool;

Edge *New(Node *s,Node *t){
	Edge *ret = ++frog;
	*ret = (Edge){s,t,s->firstEdge};
	return ret;
}

char str[MAXN];

inline void add(int u,int v){
	node[u].firstEdge = New(&node[u],&node[v]);
	++node[u].d[str[v]-'A'];
}

int N,M;

int main(){
	scanf("%d%d",&N,&M);
	scanf("%s",str+1);
	FOR(i,1,N) node[i].num = i;
	FOR(i,1,M){
		int u,v;scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	std::queue<Node *> q;
	FOR(i,1,N) if(!node[i].d[0] || !node[i].d[1]) q.push(&node[i]),node[i].vis = true;
	int cnt = q.size();
	while(!q.empty()){
		Node *v = q.front();q.pop();
		for(Edge *e = v->firstEdge;e;e = e->next){
			if(!--e->t->d[str[v->num]-'A'] && !e->t->vis){
				q.push(e->t);cnt++;
				e->t->vis = true;
			}
		}
	}
	puts(cnt != N ? "Yes" : "No");
	return 0;
}



Measured memory_bytes: 15232