akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

const long long INF = 1LL << 60;  // どういう意味だろうか

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

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

int main() {
	string S;

	cin >> S;
	int year = 0;
	int month = 0;
	int day = 0;

	string temp;

	sscanf(S.c_str(), "%d/%d/%d", &year, &month, &day);

	if(year< 2019){
		cout << "Heisei" << endl;
 	}
	else if(year == 2019){
		if(month < 4){
			cout << "Heisei" << endl;
		}
		else if(month == 4){
			if(day <= 30){
				cout << "Heisei" << endl;
			}
			else{
				cout << "TBD" << endl;
			}
		}
		else{
			cout << "TBD" << endl;
		}
	}
	else{
		cout << "TBD" << endl;
	}
}


Measured memory_bytes: 256
// +build ignore
package main

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

func solve(sc *scanner, wr *bufio.Writer) int {
	N := sc.i()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = sc.i()
	}

	c := make([]int, 1000000+1)
	for i := 0; i < N; i++ {
		c[A[i]]++
	}

	onlyone := make([]int, 0)
	unique := make([]int, 0)
	for k, v := range c {
		if v == 1 {
			onlyone = append(onlyone, k)
		}
		if v >= 1 {
			unique = append(unique, k)
		}
	}

	c = make([]int, 1000000+1)

	for _, elem := range unique {
		for j := elem * 2; j < len(c); j += elem {
			c[j] = 1
		}
	}

	sum := 0
	for _, k := range onlyone {
		if c[k] == 0 {
			sum++
		}
	}

	fmt.Println(sum)
	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


Measured memory_bytes: 30624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 300500;

ll arr[MAXN];
int n;

int main()
{
	cin >> n;
	for (int i = 0; i < 3 * n; i++)
		cin >> arr[i];

	sort(arr, arr + 3 * n);

	ll res = 0;
	for (int i = 0; i < n; i++)
		res += arr[3 * n - 2 * i - 2];

	cout << res << '\n';

	return 0;
}



Measured memory_bytes: 2688
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
	class Program
	{
		static void Main(string[] args)
		{


			//テンプレート
			//// 整数の入力
			//int a = int.Parse(Console.ReadLine());

			//// スペース区切りの整数の入力
			//string[] input = Console.ReadLine().Split(' ');
			//int b = int.Parse(input[0]);
			//int c = int.Parse(input[1]);

			//// 文字列の入力
			//string s = Console.ReadLine();

			////出力
			//Console.WriteLine(a + b + c + " " + s);

			//A

			//string[] input = Console.ReadLine().Split(' ');
			//int s = int.Parse(input[0]);
			//int w = int.Parse(input[1]);

			//if (s <= w)
			//{
			//	Console.WriteLine("unsafe");
			//}
			//else
			//{
			//	Console.WriteLine("safe");
			//}

			//Console.ReadLine();

			//B
			string[] input = Console.ReadLine().Split(' ');
			var a = Double.Parse(input[0]);
			var b = Double.Parse(input[1]);
			var c = Double.Parse(input[2]);
			var d = Double.Parse(input[3]);

			double p1 = Math.Ceiling(c / b);
			double p2 = Math.Ceiling(a / d);

			if (p1 <= p2)
				Console.WriteLine("Yes");
			else
				Console.WriteLine("No");

			Console.ReadLine();

		}
	}
}

Measured memory_bytes: 27268
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    long long n,t,m;
    cin>>n>>t;
    if (n<10)
    {
        m= 100 *(10-n);
        t=t+m;
        cout<<t<<endl;

    }
    else cout<<t<<endl;
    return 0;
}


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

int main() {
    int n, a;
    cin >> n;
    a = n % 10;
    if (a == 0 || a == 1 || a == 6 || a == 8) {
        cout << "pon" << endl; 
    } else if (a == 3) {
        cout << "bon" << endl;
    } else {
        cout << "hon" << endl;
    }

}


Measured memory_bytes: 3604
#include <stdio.h>

int main(){
    int h,w;
    int i,j;
    while(1){
        scanf("%d %d", &h,&w);
        
        if (h == 0 && w == 0){
            break;
        }        
        
        for (i=0;i<h;i++){
            for (j=0;j<w;j++){
                if((i+j)%2==0) {
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}
        
    
    

Measured memory_bytes: 572
#include <iostream>
#include<vector>
#include<string>
#include<bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
#include<bits/stdc++.h>
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

using namespace std;

/*ll ma=998244353;
ll power(ll v,ll ti){
if(ti==1)
    return v;
ll x=power(v,ti/2);
x=(x*x)%ma;
if(ti%2==1)
    x=(x*v)%ma;
return x;

}
struct t{
int a,b;
};
vector<vector<t > >g;
vector<int> v;


ll n;


void dfs(int i,int sum){
v[i]=1;


for(int j=0;j<go[i].size();j++){
    int x=go[i][j].a;
    int y=go[i][j].b;
    if(v[x]==0){
        dfs(x,min(y,sum));

    }

}

}*/



 int main(){
int n;
cin>>n;
int x=0,y=0,z=0;
int ans=0;
for(int i=0;i<n;i++){
    string a;
    cin>>a;
    int s=a.size();
    if(a[0]=='B' && a[s-1]!='A')
        x++;

    if(a[0]!='B' && a[s-1]=='A')
        y++;
        if(a[0]=='B' && a[s-1]=='A')
        z++;
        for(int j=0;j<s-1;j++){
            if(a[j]=='A' && a[j+1]=='B')
                ans++;
        }
}
if(x>y)
{

    int temp=x;
    x=y;
    y=temp;
}
if(z>0){
    ans+=(z-1);
    if(x>0){
        ans++;
        x--;
    }
    if(y>0){
        ans++;
        y--;
    }
}
ans+=min(x,y);

cout<<ans<<endl;

 }


Measured memory_bytes: 256
while(True):
    N, M = map(int, input().split())
    if(N == 0 and M == 0):
        break

    DP = []
    for i in range(N):
        DP.append([int(_) for _ in input().split()])

    DP.sort(key=lambda x:x[1])
    DP.reverse()

    for i in range(N):
        decr = min(M, DP[i][0])
        M -= decr
        DP[i][0] -= decr
        if M == 0:
            break

    ans = 0
    for dp in DP:
        ans += dp[0]*dp[1]

    print(ans)



Measured memory_bytes: 7052
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>

const long long INF = 1LL<<60;
const int inf = 1 << 30;
const int mod = 1e9+7;


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 main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n){
    cin >> a[i];
  }

  unordered_map<int, int> mp;
  long long ans = 0;
  rep(j, 0, n){
    ans += mp[j - a[j]];
    mp[j+a[j]]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 19344
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

int main() {
  vector<char> vec;

  while (1) {
    char ch;
    scanf("%c", &ch);

    if (ch == '\n') {
      break;
    }

    vec.push_back(ch);
  }

  for (auto &&ch : vec) {
    if (islower(ch)) {
      printf("%c", toupper(ch));
    } else if (isupper(ch)) {
      printf("%c", tolower(ch));
    } else {
      printf("%c", ch);
    }
  }

  cout << endl;
}



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

int main() {
	int N;
	std::cin >> N;
	std::vector<std::string> S(N);
	for (int i = 0; i < N; i++) {
		std::cin >> S.at(i);
	}
	int AC = 0, WA = 0, TLE = 0, RE = 0;
	
	for (int i = 0; i < N; i++) {
		if (S.at(i) == "AC") {
			AC++;
		}
		if (S.at(i) == "WA") {
			WA++;
		}
		if (S.at(i) == "TLE") {
			TLE++;
		}
		if (S.at(i) == "RE") {
			RE++;
		}
	}

	std::cout << "AC x " << AC << std::endl;
	std::cout << "WA x " << WA << std::endl;
	std::cout << "TLE x " << TLE << std::endl;
	std::cout << "RE x " << RE << std::endl;
}

Measured memory_bytes: 6424
n=int(input())
p=list(map(int,input().split()))

count=0
for i in range(1,n-1):
    if max(p[i-1],p[i],p[i+1])!=p[i] and min(p[i-1],p[i],p[i+1])!=p[i]:
        count+=1

print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
char sh[5];
int i,sum,ans;
int main()
{
    ans=sum=0;
    scanf("%s",sh);
    for(i=0;i<3;i++)
    {
        if(sh[i]=='R')
        {
            sum++;
            if(sum>ans)ans=sum;
        }
        else
            sum=0;
    }
    printf("%d",ans);
    return 0;
}


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

const int INF = 1e9;

int main() {
  int n;
  cin>>n;
  int f[n][10];
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>f[i][j];
    }
  }
  int p[n][10];
  for(int i=0;i<n;i++){
    for(int j=0;j<11;j++){
      cin>>p[i][j];
    }
  }
  int ans = -1e9;
  for(int i=1;i<(1<<10);i++){
    int cnt[n];
    for(int j=0;j<n;j++){
      cnt[j]=0;
    }
    for(int j=0;j<n;j++){
      for(int k=0;k<10;k++){
        if(f[j][k]==1&&((i>>k)&1==1)){
          ++cnt[j];
        }
      }
    }
    int tmp=0;
    for(int j=0;j<n;j++){
      tmp+=p[j][cnt[j]];
    }
    ans=max(ans, tmp);
  }
  cout<<ans<<endl;

}

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

class Cube {
public:
	int f[6];
	Cube() {}
	void roll_z() { roll(1, 2, 4, 3); }
	void roll_y() { roll(0, 2, 5, 3); }
	void roll_x() { roll(0, 1, 5, 4); }
	void roll(int i, int j, int k, int l) {
		int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
	}
};

bool eq(Cube c1, Cube c2) {
	for (int i = 0; i < 6; i++)
		if (c1.f[i] != c2.f[i])return false;
	return true;
}

bool equal(Cube c1, Cube c2) {
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 4; j++) {
			if (eq(c1, c2))return true;
			c1.roll_z();
		}
		if (i % 2 == 0)c1.roll_y();
		else c1.roll_x();
	}
	return false;
}

int main()
{
	Cube c1, c2;
	
	for (int i = 0; i < 6; i++)cin >> c1.f[i];
	for (int i = 0; i < 6; i++)cin >> c2.f[i];

	if (equal(c1, c2))cout << "Yes" << endl;
	else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3112
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

ll dp[N][2];
vector<int> G[N];

void dfs(int u,int pa) {
    dp[u][0]=dp[u][1]=1;
    for(auto it:G[u]) {
        if(it==pa) continue;
        dfs(it,u);
        dp[u][0]=(dp[u][0]*(dp[it][1]+dp[it][0])%mod)%mod;
        dp[u][1]=(dp[u][1]*dp[it][0])%mod;
    }
}

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

    int n,x,y;
    cin>>n;
    ifr(i,1,n) {
        cin>>x>>y;
        G[x-1].pb(y-1);
        G[y-1].pb(x-1);
    }
    dfs(0,0);
    cout<<(dp[0][1]+dp[0][0])%mod<<endl;
    return 0;
}

Measured memory_bytes: 10880
using System;
using System.Linq;

// https://atcoder.jp/contests/abc122/tasks/abc122_b
namespace BATCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ACGT = new[] { 'A', 'C', 'G', 'T' };

            // 入力の取得
            var inputs = Console.ReadLine().ToCharArray();

            int maxLength = 0, currentLength = 0;
            foreach (var c in inputs)
            {
                if (ACGT.Contains(c))
                {
                    currentLength++;
                    if (maxLength < currentLength) maxLength = currentLength;
                }
                else
                {
                    currentLength = 0;
                }
            }

            // 解答の出力
            Console.WriteLine(maxLength);
        }
    }
}


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

int main()
{
	int n;
	cin >> n;
	vector<char> v;
	for (int i = 0; i < n; ++i)
	{
		char x;
		cin >> x;
		v.push_back(x);
	}
	if(n%2!=0){
			cout << "No" << endl;
			exit(0);
		}
	int l = n*0.5;
	for (int i = 0; i < l; ++i)
	{
		if(v[i] != v[i+l]){
			cout << "No" << endl;
			exit(0);
		}
	}
	cout << "Yes" << endl;

	return 0;
}

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

main()
{
long long int ar[100000],br[100000],n,a,b,c,k,i,d1,d2,d3,ck=0,m,j;
//char cr[1000];
//float aaf,bbf,ccf,rf,kf;
//scanf("%lld",&n);
cin>>n;



for(i=0;i<n;i++){
        cin>>a;
        br[a-1]=i+1;






}
for(i=0;i<n;i++){
        cout<<br[i]<<" ";

}

    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define MP make_pair
#define PB push_back

using namespace std;
typedef pair<int,int> Pair;
typedef long double ld;
typedef long long ll;

const int mod = 998244353, MAX = 1e5, N = 50005;
//template{{{
const long double Pi = 3.14159265358979323846l;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; };
inline void inc(int &x, int y) { x += y; x -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		x = mul(x, x), y >>= 1;
	} return ans;
}

/*char buf[1<<23],obuf[1<<23],*p1=buf,*p2=buf, *O = obuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
void print(int x) {
    if(x > 9) print(x / 10);
    *O++=x%10+'0';
} */

template <class T> inline T	input() {
	T x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}

template <class T> inline bool chkmin(T &x, T y) { x = x < y ? x : y; return x == y; }
template <class T> inline bool chkmax(T &x, T y) { x = x > y ? x : y; return x == y; }
template <class T> inline T gcd(T x, T y) { return !y ? x : gcd(y, x % y); }
template <class T> inline T sqrm(T x) { return (ll) x * x % mod; }
template <class T> inline T sqr(T x) { return x * x; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read; //}}}

ld A, B, H, M;

int main() {
#ifdef local
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	freopen("log", "w", stderr);
#endif

	cin >> A >> B >> H >> M;
	ld hetaA = (H * 60 + M) * Pi / 360;
	ld hetaB = M * Pi / 30;

	ld xA = A * cos(hetaA), yA = A * sin(hetaA);
	ld xB = B * cos(hetaB), yB = B * sin(hetaB);
	printf("%.18Lf\n", sqrt(sqr(xA - xB) + sqr(yA - yB)));
	return 0;
}


Measured memory_bytes: 4156
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int[] l = new int[n];
		Arrays.setAll(l, i -> Integer.parseInt(sc.next()));
		int count = 0;
		for(int i=0; i<n-2; i++){
			jloop: for(int j=1; j<n-1; j++){
				if(i >= j){
					continue jloop;
				}
				kloop: for(int k=2; k<n; k++){
					if(i >= k || j >= k){
						continue kloop;
					}
					if(l[i] != l[j] && l[j] != l[k] && l[k] != l[i] && l[i]+l[j] > l[k] && l[j]+l[k] > l[i] && l[k]+l[i] > l[j]){
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 35640
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
const n = Number(list[0]);
const A = list[1].trim().split(' ');
const q = Number(list[2]);
const mi = list[3].trim().split(' ');

class KeyMap {
  constructor() {
    this.map = {};
  }
  get(...args) {
    let map = this.map;
    args.forEach(arg => {
      map[arg] = map[arg] || {};
      map = map[arg];
    });
    return map;
  }
}

const dp = new Map();
const keyMap = new KeyMap();
const memo = (i, m) => {
  if (dp.has(keyMap.get(i, m))) {
    return dp.get(keyMap.get(i, m));
  }
  if (i === n) {
    return m === 0;
  }

  const nI = i + 1;
  const nM = m - A[i];
  dp.set(keyMap.get(nI, m), memo(nI, m));
  dp.set(keyMap.get(nI, nM), memo(nI, nM));
  return dp.get(keyMap.get(nI, m)) || dp.get(keyMap.get(nI, nM));
}
for (let i = 0; i < q; i++) {
  console.log(memo(0, Number(mi[i])) ? 'yes' : 'no');
}



Measured memory_bytes: 31672
n = int(input())
A = list(map(int, input().split()))
L = [0]*8
tourist = int()
for a in A:
    n = a//400
    if n > 7:
        tourist += 1
    else:
        L[n] = 1

cnt = int()
for l in L:
    if l == 1:
        cnt += 1

if cnt==0:
    print(1,tourist)
else:
    print(cnt, cnt+tourist)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
#define PI 3.14159265358979323846264338327950L
typedef unsigned long long uint64;
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  rep(i,n){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      ans ++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

class Node{
public:
	int num;
	int c;
	int fee;

	Node(){ num = 0; c = 0; fee = 0;}
	Node(int num, int c, int fee) : num(num), c(c), fee(fee){}

};

bool operator< (const Node &n1, const Node &n2){
	return n1.fee < n2.fee;
}

bool operator>(const Node &n1, const Node &n2){
	return n1.fee > n2.fee;
}

int main(void){

	int c, n, m, s, d;
	while (cin >> c >> n >> m >> s >> d, c, n, m, s, d){
		vector<vector <int> > path(n + 1);
		vector<vector <int> > cost(n + 1);
		bool checked[101][11] = { false };

		for (int i = 0; i < m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			path[a].push_back(b);
			cost[a].push_back(f);
			path[b].push_back(a);
			cost[b].push_back(f);
		}

		priority_queue<Node, vector<Node>, greater<vector<Node>::value_type> > que;

		que.push(Node(s, c, 0));

		while (!que.empty()){
			Node buff = que.top();
			que.pop();
			if (checked[buff.num][buff.c]) continue;
			checked[buff.num][buff.c] = true;
			if (buff.num == d){
				cout << buff.fee << endl;
				break;
			}

			int nnum = buff.num;
			for (int i = 0; i < path[nnum].size(); i++){
				que.push(Node(path[nnum][i], buff.c, buff.fee + cost[nnum][i]));
				if (buff.c > 0) que.push(Node(path[nnum][i], buff.c - 1, buff.fee + cost[nnum][i] / 2));
			}
		}
	}
	return 0;
}

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

using namespace std;

using lint = long long;

class UnionFind{
public:
  UnionFind(int N);
  int root(int x);
  bool connect(int x, int y);
  int size(int x);
private:
  vector<int> parent;
};

UnionFind::UnionFind(int N)
{
  parent = vector<int>(N, -1);
}

int UnionFind::root(int x)
{
  if(parent[x] < 0) return x;
  return parent[x] = root(parent[x]);
}

int UnionFind::size(int x)
{
  return -parent[root(x)];
}

bool UnionFind::connect(int x, int y)
{
  x = root(x);
  y = root(y);
  if( x == y){
    return false;
  }
  if(size(x) < size(y))
    swap(x, y);

  parent[x] += parent[y];
  parent[y] = x;

  return true;
}

void printZeroPad(int a, int n)
{
  cout << setfill('0') << right << setw(n) << a;
  cout << setfill(' ');
}

struct tri{
  int a;
  int b;
  int c;

  bool operator<(const tri &another) const
  {
    if(a != another.a)
      return a < another.a;

    if(b != another.b)
      return b < another.b;

    return c < another.c;
  };
};

int main(void)
{
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    set<int> roots;
    for(int i = 0; i < M; i++){
        int x, y, z;
        cin >> x >> y >> z;
        uf.connect(x-1, y-1);
        
    }
    int cnt = 0;
    for(int i = 0; i < N; i++){
        roots.insert(uf.root(i));
    }
    cout << roots.size() << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(a, max(b, c))
#define MIN(x, y, z) min(a, min(b, c))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;

  ll before = 0;
  rep(i, 1000000000) {
    ll num = i * i;
    if (num > N) {
      COUT(before);
      return 0;
    }
    before = num;
  }
  return 0;
}

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

int main() {
  int r,g,b;
  cin>>r>>g>>b;
  int x = r*100+10*g+b;
  if (x%4==0) puts("YES");
  else puts("NO");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

int t[1005];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n;
	for(i=1;i<n;i++){
		cin>>t[i];
	}
	t[0]=1e6,t[n]=1e6;
	a=0;
	for(i=0;i<n;i++){
		a+=min(t[i],t[i+1]);
	}
	cout<<a<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  ll cur = 0;
  ll j = 0;
  rep(i, n) {
    while (j < n && cur + a[j] == (cur ^ a[j])) {
      cur += a[j];
      j++;
    }
    // cout << i << ":" << j << endl;
    ll n = j - i;
    ans += n;
    if (i == j)
      j++;
    else
      cur -= a[i];
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

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.first <<","<<P.second <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
    
    long long n, k;
    scanf("%lld %lld", &n, &k);
    
    long long step = n / k;
    
    long long firstLower = n - k * step;
    long long ans = abs(k - firstLower);
    
    firstLower += k;
    ans = min(ans, abs(k - firstLower));
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
// AOJ 2334 Roads on Towns
// 2018.2.24 bal4u

#include <stdio.h>
#include <math.h>

#define EPS			1e-10
#define INF			1e20
typedef struct { double x, y; } PP;

PP p[2][1002];

PP vectorSub(PP *p1, PP *p2) { PP r; r.x = p1->x - p2->x, r.y = p1->y - p2->y; return r; }
double cross(PP *a, PP *b) { return a->x * b->y - a->y * b->x; }
double dot(PP *a, PP *b) { return a->x * b->x + a->y * b->y; }
double norm(PP *a) { return a->x * a->x + a->y * a->y; }

int ccw(PP *p0, PP *p1, PP *p2)
{
	PP a = vectorSub(p1, p0), b = vectorSub(p2, p0);
	double t = cross(&a, &b);
	if (t >  EPS) return 1;
	if (t < -EPS) return -1;
	if (dot(&a, &b) < -EPS) return 2;
	if (norm(&a) < norm(&b)) return -2;
	return 0;
}

int intersect(PP *p1, PP *p2, PP *p3, PP *p4)
{
	return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
		   ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0;
}

double dist(PP *p1, PP *p2) { return hypot(p1->x - p2->x, p1->y - p2->y); }

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		return -n;
	}
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

double calc(PP *s, PP *g, PP *a, int n, PP *es, PP *eg)
{
	int i, j;
	double ans, x, y, z;

	if (!intersect(s, g, es, eg)) return dist(s, g);
	if (n == 0) return INF+100;

	ans = INF+100;
	for (i = 0; i < n; i++) {
		if (intersect(s, a+i, es, eg)) continue;
		x = dist(s, a+i);
		if (x >= ans) continue;
		if (!intersect(g, a+i, es, eg)) {
			y = dist(g, a+i);
			if (x + y < ans) ans = x + y;
			continue;
		}
		for (j = 0; j < n; j++) if (j != i) {
			if (intersect(a+i, a+j, es, eg)) continue;
			y = dist(a+i, a+j);
			if (x + y  >= ans) continue;
			if (!intersect(g, a+j, es, eg)) {
				z = dist(g, a+j);
				if (x + y + z < ans) ans = x + y + z;
			}
		}
	}
	return ans;
}

int main()
{
	int i, j, n[2];
	PP s[2], g[2];
	double ans, x;

	n[0] = in()-2, n[1] = in()-2;
	for (i = 0; i < 2; i++) {
		s[i].x = in(), s[i].y = in();
		g[i].x = in(), g[i].y = in();
		for (j = 0; j < n[i]; j++) p[i][j].x = in(), p[i][j].y = in();
	}

	ans = INF+100;
	for (i = 0; i < 2; i++) {
		x = dist(s+1-i, g+1-i) + calc(s+i, g+i, p[i], n[i], s+1-i, g+1-i);
		if (x < ans) ans = x;
	}

	if (ans >= INF) puts("-1");
	else printf("%.12lf\n", ans);
	return 0;
}


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

struct fenwick_tree{
	vector<long long> bit;
	int n;
	fenwick_tree(int na){
		n = na;
		bit.assign(n, 0);
	}
	long long query(int end){
		long long val = 0;
		for(; end >= 0; end = (end & (end + 1)) - 1) val += bit[end];
		return val;
	}
	void update(int idx, long long val){
		for(; idx < n; idx = idx | (idx + 1)) bit[idx] += val;
	}
};

int n;
long long d, a;
pair<long long, long long> arr[200001];

int main(){
	cin >> n >> d >> a;
	fenwick_tree bit(n + 1);
	for(int i = 1; i <= n; i++) cin >> arr[i].first >> arr[i].second;
	sort(arr, arr + n + 1);
	long long cnt = 0;
	for(int i = 1; i <= n; i++){
		arr[i].second = max(0LL, arr[i].second + bit.query(i));
		long long up = arr[i].first + 2 * d;
		auto it = upper_bound(arr, arr + n + 1, make_pair(up, LLONG_MAX));
		long long rem = arr[i].second / a;
		if(arr[i].second % a) rem++;
		bit.update(i, -rem * a);
		if(it != arr) bit.update(it - arr, rem * a);
		cnt += rem;
	}
	cout << cnt << "\n";
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(long long)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    long long n;
    cin>>n;
    vector<long long> A(n),B(n),C(n);
    for(long long i=0;i<n;i++)cin>>A[i];
    for(long long i=0;i<n;i++)cin>>B[i];
    for(long long i=0;i<n;i++)cin>>C[i];
    sort(All(A));
    sort(All(B));
    sort(All(C));
    long long res = 0;
    for(auto b:B){
        long long u = distance(A.begin(),lower_bound(All(A),b));
        long long d = n-distance(C.begin(),upper_bound(All(C),b));
        res+=u*d;
    }
    cout<<res<<endl;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
const long long MOD = 1e9 + 7;
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    ll N, K;
    cin >> N >> K;
    COMinit();

    ll ans = 0;
    rep(i, min(N, K + 1)) {
        ll res = COM(N - 1, N - i - 1) * COM(N, i);
        // cout << i << " " << COM(N - 1, N - i - 1) << " " << COM(N, i) << " " << res << endl;
        ans += res % MOD;
        ans %= MOD;
    }

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

Measured memory_bytes: 27020
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

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

 int x[100]={0}, y[100]={0};
 int x_ele,y_ele;
 for( int i=0; i<n; i++ ){
   cin >> x_ele;
   x[i] = x_ele;
 }
 for( int j=0; j<n; j++ ){
   cin >> y_ele;
   y[j] = y_ele;
 }

 double p1=0, p2=0, p3=0, p_inf=0;
 for( int k=0; k<n; k++ ){
  p1 += abs(x[k]-y[k]);
  p2 += pow(abs(x[k]-y[k]),2.0);
  p3 += pow(abs(x[k]-y[k]),3.0);
  if( p_inf < abs(x[k]-y[k]) ){
    p_inf = abs(x[k]-y[k]);
  }
 }

 cout << fixed << setprecision(6) << p1 << endl;
 cout << fixed << setprecision(6) << sqrt(p2) << endl;
 cout << fixed << setprecision(6) << pow(p3,(double)1/3) << endl;
 cout << fixed << setprecision(6) << p_inf << endl;

 return 0;
}


Measured memory_bytes: 3448
import sys

def main():
    N = int(sys.stdin.readline().rstrip())
    H = list(map(int, input().split()))


    for x in reversed(range(1, N)):
        if H[x] >= H[x-1]:
            pass

        elif  H[x] == H[x-1] - 1:
            H[x-1] -= 1

        else:
            print('No')
            sys.exit()

    print('Yes')


main()

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;

int routeCount = 0;
double routeSum = 0;

void search(vector<pair<double, double>> point, double sum, pair<double, double> last) {
    if (point.size() == 0) {
        routeCount++;
        routeSum += sum;
        return;
    }

    for (int i = 0; i < point.size(); i++) {
        double tmpSum = sum + sqrt( pow(point[i].first-last.first, 2) + pow(point[i].second-last.second, 2) );
        vector<pair<double, double>> tmp(point);
        pair<double, double> tmpLast = tmp[i];
        tmp.erase(tmp.begin() + i);
        search(tmp, tmpSum, tmpLast);
    }
}


int main() {
    int n;
    cin >> n;
    vector<pair<double, double>> point(n);
    for (int i = 0; i < n; i++) {
        cin >> point[i].first >> point[i].second;
    }

    for (int i = 0; i < n; i++) {
        vector<pair<double, double>> tmp(point);
        pair<double, double> tmpLast = tmp[i];
        tmp.erase(tmp.begin() + i);
        search(tmp, 0, tmpLast);
    }

    printf("%-20.10f\n", (routeSum / routeCount));
}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;

using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<ll, ll> pii;
typedef long double ld;

typedef pair<ld, ld> pld;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

typedef vector<ll> vi;
typedef vector<pii> vpii;
namespace IO {
    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> &a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> &a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> &a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;
#define int ll

void solve() {
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    vpii perm(n);
    int res = 0;
    map<int, int> cnt;
    rep(i, 0, n) {
        res += cnt[i - a[i]];
        ++cnt[i + a[i]];
    }
    put(res);
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;
    while (q--) solve();
}



Measured memory_bytes: 30208
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 200200;

int A[MAX];
int B[MAX];

VI X[2];
VI Y[2];

void add(int* a, VI* x, int n, int st)
{
	FOR (i, 0, n)
	{
		int v = a[i];
		int m = v % st;
		int d = v / st;

		x[d & 1].PB(m);
	}
}

LL get_less(VI& a, VI& b, int val)
{
	int ind = SZ(b) - 1;

	LL res = 0;

	FOR (i, 0, SZ(a))
	{
		while(ind >= 0 && a[i] + b[ind] >= val) ind--;

		res += ind + 1;
	}

	return res;
}

LL get_more(VI& a, VI& b, int val)
{
	LL res = get_less(a, b, val);
	res = SZ(a) * (LL)SZ(b) - res;
	return res;
}

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

	int n;
	scanf("%d", &n);
	FOR (i, 0, n)
	{
		scanf("%d", &A[i]);
	}

	FOR (i, 0, n)
	{
		scanf("%d", &B[i]);
	}

	int st = 1;

	int res = 0;

	FOR (it, 0, 30)
	{
		X[0].clear();
		X[1].clear();
		Y[0].clear();
		Y[1].clear();

		add(A, X, n, st);
		add(B, Y, n, st);

		sort(ALL(X[0]));
		sort(ALL(X[1]));
		sort(ALL(Y[0]));
		sort(ALL(Y[1]));

		LL cur = 0;

		cur += get_more(X[0], Y[0], st);
		cur += get_less(X[0], Y[1], st);
		cur += get_less(X[1], Y[0], st);
		cur += get_more(X[1], Y[1], st);

		cur %= 2;
		res += cur * st;
		st *= 2;
	}

	cout<<res<<endl;

}


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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define sortv(v) sort(v.begin(),v.end());
#define sorta(a,n) sort(a,a+n);
#define arrayin(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define arrayout(a,n) for(int i=0;i<n;i++) cout<<" ";cout<<"\n";
#define whatIs(x) cout<<#x<<" is "<<x<<endl;
#define fillA(a,value) memset(a,value,sizeof(a));
#define len(s) s.length()
#define reached cout<<"reached "<<endl;
#define INF INT_MAX //Infinity
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define MOD 1000000007
#define fi first
#define se second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vi64 vector<lli>
#define viii vector<tuple<int,int,int>>
#define prq priority_queue<int>
#define mii map<int,int>
#define msi multiset<int>
#define nl "\n"
#define sii set<int,int>
#define sz size

typedef long long int lli;
typedef unsigned long long int ulli;
typedef double ld;

using namespace std;

const int maxSize=200001;
vector<int> v[maxSize];
bool visited[maxSize];
int level[maxSize];
void bfs(int s)
{
	visited[s]=true;
	queue<int> q;
	q.push(s);
	level[s]=0;
	while(!q.empty())
	{
		int node=q.front();
		q.pop();
		for(int i=0;i<v[node].size();i++)
		{
			if(visited[v[node][i]]==false)
			{
				visited[v[node][i]]=true;
				q.push(v[node][i]);
				level[v[node][i]]=level[node]+1;
			}
		}
	}
}

int main()
{
	fio;
	/*int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
	}*/
	int n,m;
	cin>>n>>m;
	REP(i,m)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	bfs(1);
	if(level[n]==2) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 13424
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


enum Type{
	black_USU,
	white,
	black_ATSU,
};


int main(){

	int LIMIT,K;
	scanf("%d %d",&LIMIT,&K);

	ll dp[LIMIT+1][3];

	for(int height = 0; height <= LIMIT; height++){
		for(int i = 0; i < 3; i++)dp[height][i] = 0;
	}

	ll ans = 0;

	dp[0][black_USU] = 1;
	ans++;
	if(K <= LIMIT){
		dp[K-1][black_ATSU] = 1;
		ans++;
	}

	for(int height = 1; height < LIMIT; height++){
		dp[height][black_USU] = dp[height-1][white];
		ans += dp[height][black_USU];
		dp[height][white] = dp[height-1][black_USU]+dp[height-1][black_ATSU];
		if(height >= K){
			dp[height][black_ATSU] = dp[height-K][white];
			ans += dp[height][black_ATSU];
		}
	}

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 3228
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	ll n, ans;
	cin >> n;
	ans = 9e16;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i != 0) continue;
		if (ans > n / i + n / (n / i) - 2) {
			ans = n / i + n / (n / i) - 2;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX = 510000;
ll gcd(ll a, ll b){
    if (a % b == 0)
    {  return(b);}
    else{return(gcd(b, a % b));}
}
ll lcm(ll a, ll b)
{return a * b / gcd(a, b);}
int main(){
  int N;
  cin >>N;
  vector<ll>A(N);
  rep(i,N){cin >>A[i];}
  ll gc=A[0];
  rep(i,N){
  	gc=gcd(gc,A[i]);
  }
  cout<<gc;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pa pair<int,int>
#define pii pair<ll,ll>
#define st first
#define nd second
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;
const int MAX=200005;
ld expected[MAX];
ld pref[MAX];
ld ans=0;
int main()
{
  BOOST;
  cout<<fixed<<setprecision(9);
  int n,k;
  cin>>n>>k;
  ld sum=0;
  for (int i=1;i<=n;i++)
  {
    ll a;
    cin>>a;
    ll s=a*(a+1)/2;
    expected[i]=(ld)s/(ld)a;
    sum+=expected[i];
    pref[i]=sum;
  }

  for (int i=k;i<=n;i++)
  {
    ans=max(ans,pref[i]-pref[i-k]);
  }

  cout<<ans;
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main()
{
    long long n, k;
    cin >> n >> k;
    vector<int> a(n+1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    unordered_map<int,int> vis;
    int cur = 1;
    while (true)
    {
        if (k && vis.find(cur) == vis.end())
        {
            vis[cur] = 1;
            cur = a[cur];
            k--;
        }
        else
        {
            break;
        }
    }
    if (!k)
        cout << cur << endl;
    else
    {
        long long size_of_loop = 1;
        int temp = a[cur];
        while (temp != cur)
        {
            temp = a[temp];
            size_of_loop++;
        }
        k = k % size_of_loop;
        while (k--)
        {
            cur = a[cur];
        }
        cout << cur << endl;
    }

    return 0;
}

Measured memory_bytes: 11020
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 	
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }
   
 void solve() {
	  int n;
	  cin>>n;
	  vi v(n+1);
	  rep(i,1,n+1) cin>>v[i];
	  vi dp(n+1),pre(n+1);
	  dp[1]=0;
	  dp[0]=0;
	  pre[1]=v[1];
	  for(int i=3;i<=n;i+=2) {
		     pre[i]=pre[i-2]+v[i];
		  }
	  
	  rep(i,2,n+1) {
		    if(i&1)  {
				  dp[i]=max(v[i]+dp[i-2],dp[i-1]);
				}
			else {
				   dp[i]=v[i]+dp[i-2];
				   dp[i]=max(dp[i],pre[i-1]);
				}	
		  }	  
		  cout<<dp[n]<<endl;
		  
	  
         
 }

    
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	solve();


return 0;	   
}


Measured memory_bytes: 7956
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N,K,sum = 0;
    cin >> N >> K;
    for(int i = 0;i < N;i++){
        int x;
        cin >> x;
        sum += min(x,abs(K-x))*2;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256