akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        sc.close();

        StringBuffer sb = new StringBuffer();
        sb.append("Christmas");
        for (int i = 0; i < 25 - D; i++){
            sb.append(" Eve");
        }

        System.out.println(sb.toString());
    }

}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <deque>
#include <complex>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const int C_CW=1,C_CCW=-1,C_OPO=2,C_STR=-2,C_RET=0;
const int INF=1<<30;
const double EPS=(1e-8);
using namespace std;
typedef complex<long double> cld;
typedef struct{
	cld point[4];
} quad;
typedef vector<quad> vq;
int unions[100];
long double cross(cld a,cld b){
	return (conj(a)*b).imag();
}
long double dot(cld a,cld b){
	return (a*conj(b)).real();
}

long double ccw(cld o,cld a,cld b){
	a-=o;
	b-=o;
	if(cross(a,b)>EPS)	return C_CCW;
	if(cross(a,b)<-EPS)	return C_CW;
	if(dot(a,b)<-EPS)	return C_OPO;
	if(norm(a)<norm(b)) return C_STR;
	return C_RET;
	
}
bool isCollision(cld sa,cld ea,cld sb,cld eb){
	if(ccw(ea,sa,sb)*ccw(ea,sa,eb)<=0 &&ccw(eb,sb,sa)*ccw(eb,sb,ea)<=0 )
		return true;
	return false;
}
bool isInside(quad a,cld b){
	REP(i,4)
		if(ccw(a.point[i],a.point[(i+1)%4],b)==C_CCW)	return false;
	return true;
}
bool isCollision(quad a,quad b){
	REP(i,4)
		REP(j,4)
			if(isCollision(a.point[i],a.point[(i+1)%4],b.point[j],b.point[(j+1)%4])) return true;
	REP(i,4){
	if(isInside(a,b.point[i]))	return true;
	if(isInside(b,a.point[i]))	return true;
	}
	return false;
}
int find(int i){
	if(unions[i]==i)
		return i;
	return unions[i]=find(unions[i]);
}
void unit(int i,int j){
	unions[find(i)]=min(find(i),find(j));
	unions[find(j)]=min(find(i),find(j));
}
int main() {
	// your code goes here
	int N;
	while(cin >> N && N){
		REP(i,N){
			vq qs;
			int M;
			cin >> M;
			REP(j,M)
				unions[j]=j;
			REP(j,M){
				quad x;
				REP(k,4){
					int tmp,tmpb;
					cin >> tmp >> tmpb;
					x.point[k]=cld(tmp,tmpb);
				}
				qs.push_back(x);
			}
			int noHit=0;
			REP(i,M)
				FOR(j,0,M)
					if(isCollision(qs[i],qs[j])){
						unit(i,j);
					}
			REP(i,M)
				if(find(i)==i)
					noHit++;
			cout << noHit << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1256
#include <iostream>
using namespace std;
typedef long long ll;

const ll N = 1e6+9;
ll n, m, a[N], ans;

int main(){
    cin >> n >> m;
    for(int i = 1; i <= m; i++) cin >> a[i];
    ans = n;
    for(int i = 1; i <= m; i++) ans -= a[i];
    if(ans >= 0)cout << ans;
    else cout << "-1";
    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >>N;
  int ac=0;
  int wa=0;
  int tle=0;
  int re=0;
  
  vector<string> kekka(N);
  for(int i=0;i<N;i++){
    cin >>kekka.at(i);
    if(kekka.at(i)=="AC")
      ac++;
    else if(kekka.at(i)=="WA")
      wa++;
    else if(kekka.at(i)=="TLE")
      tle++;
    else if(kekka.at(i)=="RE")
      re++;
  }
  cout <<"AC x "<<ac<<endl<<"WA x "<<wa<<endl<<"TLE x "<<tle<<endl<<"RE x "<<re<<endl; 
  
  }
  
    
    

Measured memory_bytes: 6372
#include<bits/stdc++.h>
#include <queue>
#include <cstring>

#define mp make_pair
#define pb push_back
#define p push

#define FOR(a, c) for(int a = 0;a<c;a++)
#define ll long long int

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%lf",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);

#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define SIZE  ( int)(1e9 + 7)
#define MAXN (ll) (1e5+5)

using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector <vector<int>> vvi;
typedef vector<long long> vl;
typedef vector <pair<int, int>> vpi;
typedef vector <pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <vi> graph;





int main (){
    ll n,k;
    cin>> n>>k;
    if(500 * n >= k) cout<<"Yes\n";
    else cout<< "No\n";
    return 0;

}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

struct edge {ll to, cost;};

int main(){
    ll N; cin >> N;
    ll Norg = N;
    if(N%2 == 1) N--;
    vpl ans;
    FOR(i, 1, N+1){
        FOR(k, i+1, N+1){
            if(k == N+1-i) continue;
            ans.pb({i, k});
        }
    }
    if(Norg%2 == 1){
        FOR(i, 1, Norg) ans.pb({i, Norg});
    }
    cout << ans.size() << endstr;
    REP(i, ans.size()) cout << ans[i].ff << " " << ans[i].ss << endstr;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 10005;
struct Edge
{
    int to, w, cost;
    Edge() {}
    Edge(int a, int b, int c): to(a), w(b), cost(c) {}
    bool operator < (const Edge &r) const
    {
        return w > r.w || w == r.w && cost > r.cost;
    }
};
vector<Edge> G[MAXN];
bool vis[MAXN];
int dist[MAXN];
int cost[MAXN];
int pre[MAXN];
void Dijkstra(int n, int start)
{
    for (int i = 0; i <= n; i++)
        vis[i] = 0, dist[i] = cost[i] = INF;
    priority_queue<Edge> que;
    que.push(Edge(start, 0, 0));
    dist[start] = cost[start] = 0;
    pre[start] = start;
    Edge tmp;
    while (!que.empty())
    {
        tmp = que.top();
        que.pop();
        int u = tmp.to;
    //    cout << tmp.to << endl;
        if (vis[u]) continue;
        vis[u] = 1;
        for (int i = 0; i < G[u].size(); i++)
        {
            int v = G[u][i].to;
            int w = G[u][i].w;
    //        cout << v << " " << w << " " << G[u][i].cost << endl;
    //        cout << dist[v] << " " << cost[v] << endl;
     //       cout << dist[u] << " " << cost[u] << endl;
            if (!vis[v] && dist[v] > dist[u] + w)
            {
                dist[v] = dist[u] + w;
                cost[v] = G[u][i].cost;
      //          cout <<"s1  " << v << " " << dist[v] << " " << cost[v] << endl;
                pre[v] = u;
                que.push(Edge(v, dist[v], cost[v]));
            }
            else if (!vis[v] && dist[v] == dist[u]+w && cost[v] >  G[u][i].cost)
            {
                cost[v] = G[u][i].cost;
         //       cout << "s2  " <<  v << " " << dist[v] << " " << cost[v] << endl;
                pre[v] = u;
                que.push(Edge(v, dist[v], cost[v]));
            }
        }
    }
   // for (int i = 2; i <= n; i++) cout << cost[i] - cost[pre[i]] <<endl;
}
int n, m;
int main()
{
    while (~scanf("%d%d", &n, &m) && (n+m))
    {
        for (int i = 1; i <= n; i++)
            G[i].clear();
        for (int i = 1; i <= m; i++)
        {
            int u, v, d, c; scanf("%d%d%d%d", &u, &v, &d, &c);
            G[u].push_back(Edge(v, d, c));
            G[v].push_back(Edge(u, d, c));
        }
        Dijkstra(n, 1);
        int ans = 0;
        for (int i = 2; i <= n; i++) ans += cost[i];
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 5148
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int n,c=0;
	cin >> n;
	vector<vector<int>> a(n);
	REP(i,n){
		REP(j,26){
			a[i].push_back(0);
		}
	}
	Vec(b,n);
	REP(i,n){
		cin >> b[i];
		int s = b[i].size();
		REP(j,s){
			char t = b[i][j];
			int u = t - 'a';
			a[i][u]++;
		}
	}
	if(n == 1){
		REP(i,26){
			char d = i + 97;
			while(a[0][i] != 0){
				cout << d;
				a[0][i]--;
			}
		}
		goto owa;
	}
	REP(i,26){
		c = min(a[0][i],a[1][i]);
		FOR(j,2,n){
			c = min(c,a[j][i]);
			
		}
		char d = i + 97;
			while(c != 0){
				cout << d;
				c--;
			}
	}
	owa:
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
static const ll MOD = 1000000007;

ll mod_pow(ll n, ll x){
	if(n == 0) return 1;
	ll ret = mod_pow(n / 2, x * x % MOD) % MOD;
	if(n % 2) return ret * x % MOD;
	return ret;
}

ll comb(int n, int k){
	if(k < 0 || k > n) return 0;
	vector<ll> memo(n + 1);
	memo[0] = 1; memo[1] = 1;
	for(int i = 2; i <= n; i++){
		memo[i] = memo[i - 1] * (ll)i;
		memo[i] %= MOD;
	}
	return ((memo[n] * mod_pow(MOD - 2, memo[k])) % MOD) * mod_pow(MOD - 2, memo[n - k]) % MOD;
}

int main(){
	int n, k;
	cin >> n >> k;
	cout << comb(n - 1, k - 1) << endl;
	return 0;
}



Measured memory_bytes: 3096
n = gets.to_i
a = gets.split(' ').map(&:to_i)

sum = [0]
n.times do |i|
  sum[i] = sum[i - 1] + a[i]
end
total = sum[-1]

memo = []
# 後ろに最低1枚渡さないといけないの忘れてた
(n - 1).times do |i|
  memo << (total - sum[i] * 2).abs
end
print memo.sort[0]



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

int main() {
   int H,M;
   while(1) {
      cin >> H >> M;
      if(H==0&&M==0){
		  break;
      }
      for(int i=0;i<H;i++){
		 for(int j=0;j<M;j++){
			cout<<'#';
		 }
		 cout<<endl;
	  }
	  cout<<endl;
  }
}
         
            



Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if( (a==b&&a!=c) || (b==c)&&(a!=b) || (a==c&&a!=b) )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	scanInit()

	n := nextInt()

	vmax := float64(n) / 3.0
	vmax *= vmax * vmax

	fmt.Printf("%.10f", vmax)

}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include <stdio.h>

unsigned long long gcd(unsigned long long a,unsigned long long b);
unsigned long long lcm(unsigned long long a,unsigned long long b);

int main(){
    int n;
    unsigned long long t[100],tmp;
    int i;

    scanf("%d",&n);

    for(i = 0;i < n;i++){
        scanf("%llu",&t[i]);
    }

    if(n == 1){
        printf("%llu",t[0]);
        return 0;
    }

    tmp = lcm(t[0],t[1]);

    if(n == 2){
        printf("%llu",tmp);
        return 0;
    }

    for(i = 2;i < n;i++){
        tmp = lcm(tmp,t[i]);
    }

    printf("%llu",tmp);

    return 0;
}

unsigned long long gcd(unsigned long long a,unsigned long long b){
    if(a % b == 0){
        return b;
    }
    return gcd(b,a % b);
}

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

Measured memory_bytes: 128
import sys
n = int(input())
A = list(map(int, sys.stdin))

cnt = 0
def insertion_sort(L, n, g):
    global cnt
    for i in range(g, n):
        v = L[i]
        j = i - g
        while 0 <= j and v < L[j]:
            L[j+g] = L[j]
            j -= g
            cnt += 1
        L[j+g] = v


def shell_sort(L, n):
    global G
    for i in G:
        insertion_sort(L, n, i)

G = [i for i in [262913, 65921, 16577, 4193, 1073, 281, 77, 23, 8, 1] if i <= n]
shell_sort(A, n)

print(len(G))
print(' '.join(str(x) for x in G))
print(cnt)
for i in A:
    print(i)

Measured memory_bytes: 47544
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ld x,y;
  cin>>x>>y;
  
  int ans = 0;
  rep(i,100){
    if(x>y) {
    cout << ans << endl;
    return 0;
    }
    y/=2;
    ans++;
  }
  
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC105B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var n = input[0];

            while (n >= 0)
            {
                if (n % 4 == 0 || n % 7 == 0)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                n -= 4;
            }

            n = input[0];

            while (n >= 0)
            {
                if (n % 4 == 0 || n % 7 == 0)
                {
                    Console.WriteLine("Yes");
                    return;
                }
                n -= 7;
            }

            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>

using namespace std;

long f(long n, long x) {
	if (n == -1) return 0;
	return n / x + 1;
}

int main(int argc, char *argv[]) {
	long a, b, x;
	cin >> a >> b >> x;

	cout << f(b, x) - f(a - 1, x) << endl;

	return 0;
}

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

int main() {
  int N;
  string str = "APPROVED";
  
  cin >> N;

  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }

  for(int i = 0; i < N; i++){
    if(vec.at(i) % 2 == 0){
      if(vec.at(i) % 3 == 0 || vec.at(i) % 5 == 0){
        str = "APPROVED";
      }else{
        str = "DENIED";
        break;
      }
    }
  }
  cout << str << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,popcnt")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1<<17, mod = 1e9 + 7;
int n, _x;
vector<int> g[maxn];
int B = 0, A = 0;
int get(vector<int> &a, int s) {
	int l = 0, r = a.size()-1, mx = 0;
	if(l == s) l++;
	if(r == s) r--;
	while(l < r) {
		mx = max(mx, a[l] + a[r]);
		l++, r--;
		if(l == s) l++;
		if(r == s) r--;
	}
	return mx;
}
int dfs(int v, int p, int h = 0) {
	vector<int> ch;
	if(g[v].size()&1) ch.pb(h);
	for(auto i : g[v]) if(i != p) {
		int t = dfs(i, v, h+1);
		if(t == -1) return -1;
		if(t) ch.pb(t);
	}
	sort(all(ch));
	if(ch.size()%2 == 0) {
		return get(ch, -1)-2*h <= _x ? 0 : -1;
	}
	p = 0;
	for(int i = 1<<17; i>>=1;)
		if(p+i < ch.size() && get(ch, p+i)-2*h > _x) p += i;
	p += (get(ch, p)-2*h > _x);
	return p >= ch.size() ? -1 : ch[p];
}
bool can(int x) {
	_x = x;
	return dfs(1, 1) != -1;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int f, t, i = 1; i < n; i++) {
		cin >> f >> t;
		g[f].pb(t);
		g[t].pb(f);
	}
	for(int i = 1; i <= n; i++) A += g[i].size()&1; A/=2;
	for(int i = 1<<17; i>>=1;) if(!can(B+i)) B += i;
	cout << A << " " << B+1 << '\n';
	return 0;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    vector<int> a(n);
    rep(i, n) {
      cin >> a[i];
      a[i]--;
    }
    int pos = 0;
    rep(i, n) {
      if (pos == 1) {
        cout << i << '\n';
        return 0;
      }
      pos = a[pos];
    }
    cout << -1 << '\n';

    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#define N 200005
#define int long long

int n;
int val[N];
int tot[25];
int qzh[N][25];

signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&val[i]);
		for(int j=0;j<=20;j++){
			if(val[i]&(1<<j))
				qzh[i][j]=1;
		}
	}
	int ans=0;
	int x=0,sum=0;
	/*int l=0,r=0;
	for(int i=1;i<=n;i++){
		x^=val[i],sum+=val[i];
		while(x!=sum){
			x^=val[l];
			sum-=val[l];
			l++;
		}
		ans+=r-l+1;
		r=i;
	}
	ans+=r-l+1;*/
	for(int i=1,j=1;i<=n;i++)
	{
		x^=val[i];sum+=val[i];
		while(x!=sum){x^=val[j];sum-=val[j];j++;}
		ans+=i-j+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 40832
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		while(input.hasNext()){
			int N = input.nextInt();
			int K = input.nextInt();
			Point[] p = new Point[N];
			
			for(int i = 0; i < p.length; ++i){
				p[i] = new Point(input.nextInt(), input.nextInt());
			}
			
			long minRectangle = Long.MAX_VALUE;
			for(int x1 = 0; x1 < p.length; ++x1){
				for(int x2 = x1 + 1; x2 < p.length; ++x2){
					for(int y1 = 0; y1 < p.length; ++y1){
						for(int y2 = y1 + 1; y2 < p.length; ++y2){
							long MAX_X = Math.max(p[x1].x, p[x2].x);
							long MIN_X = Math.min(p[x1].x, p[x2].x);
							long MAX_Y = Math.max(p[y1].y, p[y2].y);
							long MIN_Y = Math.min(p[y1].y, p[y2].y);
							
							int countInside = 0;
							for(int i = 0; i < p.length; ++i){
								if(MIN_X <= p[i].x && p[i].x <= MAX_X && MIN_Y <= p[i].y && p[i].y <= MAX_Y){
									++countInside;
								}
								
								if(countInside > K){
									break;
								}
							}

							if(countInside == K){
								minRectangle = Math.min(minRectangle, (MAX_X - MIN_X) * (MAX_Y - MIN_Y));
							}
						}
					}
				}
			}
			
			System.out.println(minRectangle);
		}
	}
	
	private static class Point {
		int x;
		int y;
		
		Point (int x, int y){
			this.x = x;
			this.y = y;
		}
	}

}


Measured memory_bytes: 23412
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int imp = int.Parse(Console.ReadLine());
            if (imp%2==0)
            {
                Console.Write(imp);
            }
            else
            {
                Console.Write(2*imp);
            }



          
        }
    }
}


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

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

Measured memory_bytes: 640
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

const int INF = 1e14;
class SegTree {
  public:
    vector<int> t;
    vector<bool> marked;
    SegTree(int n) {
      t.assign(4 * n, INF);
      marked.assign(4 * n, INF);
    }

    void push(int v) {
      if (marked[v]) {
        if (t[v] < t[2 * v]) {
          marked[2 * v] = true;
          t[2 * v] = t[v];
        }
        if (t[v] < t[2 * v + 1]) {
          marked[2 * v + 1] = true;
          t[2 * v + 1] = t[v];
        }
        marked[v] = false;
      }
    }

    void update(int v, int tl, int tr, int l, int r, int val) {
      if (l > r) return;
      if (tl == l && tr == r) {
        if (val < t[v]) {
          marked[v] = true;
          t[v] = val;
        }
      } else {
        push(v);
        int tm = (tl + tr) / 2;
        update(2 * v, tl, tm, l, min(r, tm), val);
        update(2 * v + 1, tm  + 1, tr, max(tm + 1, l), r, val);
      }
    }

    int get(int v, int tl, int tr, int pos) {
      if (tl == tr) return t[v];
      push(v);
      int tm = (tl + tr) / 2;
      if (pos <= tm) {
        return get(2 * v, tl, tm, pos);
      } else {
        return get(2 * v + 1, tm + 1, tr, pos);
      }
    }
};

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<pair<pii, int>> v(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i].fi.fi >> v[i].fi.se >> v[i].se;
    v[i].fi.fi--, v[i].fi.se--;
  }
  sort(v.begin(), v.end());
  SegTree sg(n);
  sg.update(1, 0, n - 1, 0, 0, 0);
  for (int i = 0; i < m; i++) {
    int val = sg.get(1, 0, n - 1, v[i].fi.fi) + v[i].se;
    sg.update(1, 0, n - 1, v[i].fi.fi + 1, v[i].fi.se, val);
  }
  int ans = sg.get(1, 0, n - 1, n - 1);
  if (ans == INF) {
    cout << "-1\n";
  } else {
    cout << ans << "\n";
  }
}



Measured memory_bytes: 5632
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        BigDecimal[] array = Arrays.stream(sc.nextLine().split(" ")).map(num -> new BigDecimal(num)).sorted().toArray(num -> new BigDecimal[num]);
        BigDecimal max = new BigDecimal(0);
        for (int i = 0; i < array.length; i++) {
			BigDecimal pre = array[i];
	        BigDecimal sum = new BigDecimal(0);
	        for (int j = 0; j < array.length; j++) {
	        	if (i == j) {
	        		continue;
	        	}
				BigDecimal num = array[j];
				sum = pre.add(num).divide(new BigDecimal(2), 10, BigDecimal.ROUND_DOWN);
	        	pre = sum;
	        }
	        if (max.compareTo(sum) < 1) {
	        	max = sum;
	        }
		}
        System.out.println(max.toString());
    }
}


Measured memory_bytes: 27220
#include<iostream>
#include<bits/stdc++.h>
#include<climits>

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
}

int main(){
    go();

    // code here
    int n;cin>>n;
    cout<<((1000 - (n % 1000))% 1000);
   

}






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

using namespace std;

long long f(long long b, long long n) {
    if (b <= 1) return -1;
    if (n < b) return n;
    else return f(b, n / b) + n % b;
}
int main() {
    long long n, s;

    scanf("%lld%lld", &n, &s);
    long long res = 1e13 + 1;

    if (n == s) {
        cout << n + 1 << endl;
        return 0;
    }

    if (s > n) {
        cout << -1 << endl;
        return 0;
    }

    for (long long b = 2; b * b < n; ++b) {
        if (f(b, n) == s) {
            cout << b << endl;
            return 0;
        }
    }

    long long sqrt = 0;
    for (; sqrt * sqrt <= n; sqrt++)
        ;
    for (long long p = sqrt - 1; p > 0; --p) {
        long long r = s - p;
        long long b = (n - r) / p;
        if (b == 1) continue;
        if (f(b, n) == s) {
            cout << b << endl;
            return 0;
        }
    }

    cout << -1 << endl;


    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int B[2000001], C[200001];
void CountingSort(int A[], int n)
{
  int i, j;
  for(i = 0; i <= 10001; i++)
    {
      C[i] = 0;
    }
  for(j = 1; j <= n; j++)
    {
      C[A[j]]++;
    }
  for(i = 1; i <= 10001; i++)
    {
      C[i] = C[i] + C[i-1];
    }
  for(j = n; j >= 1; j--)
  {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
}
  int main()
{
  int A[2000001], n, i;
  scanf("%d", &n);
  for(i = 1; i <= n; i++)
    {
      scanf("%d", &A[i]);
    }
      CountingSort(A, n);
  for(i = 1; i < n; i++)
    {
      printf("%d ", B[i]);
    }
  printf("%d\n", B[n]);
  return 0;
}



Measured memory_bytes: 17516
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;
const double PI=3.14159265358979323846;

int main(){
  double A,B,X,L;
  cin>>A>>B>>X;
  
  if(X<=(A*A*B/2)){
    double S=X*2/(A*B);
    cout<<setprecision(7)<<180*atan2(B,S)/PI<<endl;
    return 0;
  }
  else{
    double S=(A*A*B-X)*2/(A*A);
    cout<<setprecision(7)<<180*atan2(S,A)/PI<<endl;
    return 0;
  } 
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    vector<int> dp(n);
    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        dp[i] = dp[i - 1] + abs(h[i - 1] - h[i]);
        if (i != 1) {
            dp[i] = min(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
        }
    }
    cout << dp.back() << '\n';
    return 0;
}

Measured memory_bytes: 3964
import sys


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


s = S()
t = S()
ans = 'No'
for i in range(len(s)):
    s = s[-1] + s[:-1]
    if s == t:
        ans = 'Yes'
        break
print(ans)


Measured memory_bytes: 3064
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll v[2],sum=0;
  cin >>v[0] >> v[1];
  for(int i=0;i<2;i++){
    if(v[i]==3){
      sum+=100000;
    }else if(v[i]==2){
      sum+=200000;
    }else if(v[i]==1){
      sum+=300000;
    }
  }
  if(v[0]==1&&v[1]==1){
    sum+=400000;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
N, M =list(map(int, input().split()))
p, S =[], []
for _ in range(M):
    x, y = input().split()
    p.append(int(x))
    S.append(y)

wa = [0] * N
w = 0
ac = set()
for i in range(M):
    if S[i] == "AC":
        if p[i] in ac:
            pass
        else:
            ac.add(p[i])
            w += wa[p[i] - 1]
    else:
        wa[p[i] - 1] += 1
print(len(ac), w)

Measured memory_bytes: 20364
def diff(s,t):
  cnt = 0
  for i in range(len(s)):
    if s[i] != t[i]:
      cnt+=1
  return cnt

if __name__ == "__main__":
  count = 1001
  s = input()
  t = input()
  if(len(s) == len(t)):
    count = min(count,diff(s,t))
  for i in range(len(s)-len(t)):
    count = min(count,diff(s[i:i+len(t)],t))
  print(count)

Measured memory_bytes: 9140
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 998244353;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    string s = inp1;
    ll k = inp1;

    int n = s.length();

    if (n == 1) {
        Cout(k / 2);
        return 0;
    }

    vector<pair<char, ll>> vec;
    for (auto c : s) {
        if (vec.empty() || vec.back().first != c) vec.emplace_back(c, 1);
        else ++vec.back().second;
    }

    if (vec.size() == 1) {
        Cout((vec.front().second * k) / 2);
        return 0;
    }

    ll ans = 0LL;

    bool same = s.front() == s.back();

    if (same) {
        ans = vec.front().second / 2 + vec.back().second / 2 +
            (vec.back().second + vec.front().second) / 2 * (k - 1);
    }

    size_t start = (same) ? 1 : 0;
    size_t end = (same) ? vec.size() - 1 : vec.size();

    for (size_t i = start; i < end; ++i) {
        ans += vec[i].second / 2 * k;
    }

    Cout(ans);

    return 0;
}


Measured memory_bytes: 256
n,x = map(int,input().split())
city = list(map(int,input().split()))

from fractions import gcd

if n==1:
    print(abs(city[0]-x))
    exit(0)

city = sorted(city)

for i in range(n):
    city[i]-=x

for j in range(n):
    if j==0:
        ans = gcd(city[j],city[j+1])
    else:
        ans = gcd(ans,city[j])

print(abs(ans))

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

int main() {
  int n, t, prev = 0, time = 0;
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    time += min(t, x - prev);
    prev = x;
  }
  cout << time + t << endl;
}


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

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;

//AtCoder Regular Contest 097-D
struct LLPair {
	ll a = 0;
	ll b = 0;
};

struct UnionFindTree {
	ll num_node = 0;
	vector<ll> parent;
	vector<ll> count;

	UnionFindTree(ll num_node) {
		this->num_node = num_node;
		parent.clear();
		parent.resize(num_node);
		count.clear();
		count.resize(num_node);
		for (ll i = 0; i < num_node; i++) {
			parent[i] = i;
			count[i] = 1;
		}
	}

	ll FindRoot(ll node) {
		vector<ll> found_node;

		while (true) {
			if (parent[node] == node) {
				for (auto index : found_node) {
					parent[index] = node;
				}
				break;
			}
			else {
				found_node.push_back(node);
				node = parent[node];
			}
		}

		return node;
	}

	bool Unite(ll node1, ll node2) {
		ll node1root = FindRoot(node1);
		ll node2root = FindRoot(node2);

		if (node1root == node2root) {
			return false;
		}

		count[node1root] += count[node2root];
		count[node2root] = 0;
		parent[node2root] = node1root;

		return true;
	}

	ll Count(ll node) {
		return count[FindRoot(node)];
	}
};

int main() {
	ll N;
	scanf("%lld", &N);
	ll M;
	scanf("%lld", &M);
	vector<ll> p(N);
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &p[i]);
	}
	vector<LLPair> sw(M);
	for (ll i = 0; i < M; i++) {
		scanf("%lld %lld", &sw[i].a, &sw[i].b);
	}

	UnionFindTree uf(N);

	for (ll i = 0; i < M; i++) {
		uf.Unite(sw[i].a - 1, sw[i].b - 1);
	}

	ll result = 0;

	for (ll i = 0; i < N; i++) {
		if (uf.FindRoot(p[i] - 1) == uf.FindRoot(i)) {
			result++;
		}		
	}

	printf("%lld\n", result);
}


//AtCoder Grand Contest 019-B
/*
//TLE
int main() {
	char A[202020];
	scanf("%s", A);
	ll len = strlen(A);

	ll result = 1;

	for (ll i = 0; i < len * 2ll - 1ll; i++) { //0:0������ 1:0�����ڂ�1�����ڂ̊� 2:1������
		if (i % 2 == 0) {
			ll index = i / 2;
			ll searchMax = min(index, len - 1 - index);

			//i/2�����ڂ𒆐S
			ll count = 0;
			for (ll j = 1; j <= searchMax; j++) {
				if (A[index - j] != A[index + j]) {
					count++;
				}
			}

			result += count;
		}
		else {
			ll index = i / 2;
			ll searchMax = min(index + 1, len - 1 - index);

			//i/2�����ڂ̉E�𒆐S
			ll count = 0;
			for (ll j = 0; j < searchMax; j++) {
				if (A[index - j] != A[index + j + 1]) {
					count++;
				}
			}

			result += count;
		}
	}

	printf("%lld\n", result);
}
*/

Measured memory_bytes: 4096
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        long n=sc.nextLong();
        long a=sc.nextLong();
        long b=sc.nextLong();
        long ans=0;
        if(a>b){
            ans=0;
        }else if(a==b){
            ans=1;
        }else{
            if(n==1){
                ans=0;
            }else{
                ans=(n-2)*(b-a)+1;
            }
        }
        out.println(ans);
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vi p(N);
    rep(i, N) cin >> p[i];

    int c = 0;

    rep(i, N) {
        if (p[i] != i+1) {
            c++;
        }
    }

    if (c == 2 || c == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
using namespace std;
 
 
 
int main()
{
	
	int n;
	cin>>n;
	int d1[200];
	int d2[200];
	for(int i=0;i<n;i++){
		cin>>d1[i]>>d2[i];
	}
	int flag=0;
	for(int i=0;i<n-2;i++){
		if(d1[i]==d2[i]){
			if(d1[i+1]==d2[i+1]){
				if(d1[i+2]==d2[i+2]){
					flag=1;
					break;
				}
			}
		}
	}
	if(flag==1){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

typedef long long int LLI;

LLI calcNumLayers(int n) {
  return ((1LL << (n + 2)) - 3);
}

LLI calcNumPatties(int n) {
  return ((1LL << (n + 1)) - 1);
}

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

  LLI s = 0LL;
  while (1) {
    if (n == 0) {
      s += 1;
      break;
    }
    LLI l = calcNumLayers(n - 1);
    LLI p = calcNumPatties(n - 1);
    if (x == 1) {
      break;
    } else if (x <= l + 1) {
      x -= 1;
    } else if (x == l + 2) {
      s += p + 1;
      break;
    } else if (x <= 2 * l + 2) {
      s += p + 1;
      x -= l + 2;
    } else if (x == 2 * l + 3) {
      s += 2 * p + 1;
      break;
    }
    --n;
  }
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
let lcs (x, y) =
  let m = String.length x in
  let n = String.length y in
  let s = Array.make (n + 1) 0 in
  let t = Array.copy s in
  for i = 1 to m do
    for j = 1 to n do
      t.(j) <-
        if x.[i-1] = y.[j-1] then s.(j-1) + 1
        else if s.(j) > t.(j-1) then s.(j)
        else t.(j-1);
    done;
    Array.iteri (fun i e -> s.(i) <- e) t;
  done;
  t.(n)

let () =
  let q = Scanf.scanf "%d " (fun q -> q) in
  for _ = 0 to q - 1 do
    Scanf.scanf "%s %s " (fun x y -> x, y)
    |> lcs
    |> Printf.printf "%d\n"
  done

Measured memory_bytes: 3440
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstdint>
using namespace std;

#define N 500000

int n, m;
int p[N];

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main()
{
	int ans = 0;
	int x, y;

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

	UnionFind uf(n);
	for( int i = 0; i < m; i++ ) {
		cin >> x >> y;
		uf.unionSet( x-1, y-1 );
	}

	for( int i = 0; i < n; i++ ) {
		if( uf.findSet(i, p[i]) == true ) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>

#define avoid cout << "hello" << endl;
#define VMAX 500000
#define MAX 200000

using namespace std;

struct Node{
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x) {
  while( x->left != NIL ) x = x->left;
  return x;
}

Node* find(Node *u, int k){
  while( u != NIL && k != u->key ){
    if( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x) {
  return treeMinimum(x->right);
}

void treeDelete(Node *z) {
  Node *y;
  Node *x;
  
  if ( z->left == NIL || z->right == NIL ) y = z;
  else y = treeSuccessor(z);
  
  if ( y->left != NIL ) {
    x = y->left;
  } else {
    x = y->right;
  }
  
  if ( x != NIL ) {
    x->parent = y->parent;
  }
  
  if ( y->parent == NIL ) {
    root = x;
  } else {
    if ( y == y->parent->left ) {
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }
  
  if ( y != z ) {
    z->key = y->key;
  }
  
  free(y);
}


void insert(int k){
  Node *x = root;
  Node *y = NIL;
  Node *z = new Node;
  
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while( x != NIL ){
    y = x;
    if( z->key < x->key) x = x->left;
    else x = x->right;
  }
  
  z->parent = y;
  if( y == NIL ){
    root = z;
  } else {
    if ( z->key < y->key ){
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(int argc, const char * argv[]) {
  int n, i, x;
  string com;
  
  cin >> n;
  for ( i = 0; i < n; i++ ){
    cin >> com;
    if ( com[0] == 'f' ) {
      cin >> x;
      Node *t = find(root, x);
      if ( t != NIL ) cout << "yes" << endl;
      else cout << "no" << endl;
    } else if ( com == "insert" ) {
      cin >> x;
      insert(x);
    } else if ( com == "print" ) {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    } else if ( com == "delete" ) {
      cin >> x;
      treeDelete(find(root, x));
    }
  }
  
  return 0;
}



Measured memory_bytes: 21956
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	if (a < b){
		cout << "a < b" << endl;
	}
	if (a > b){
		cout << "a > b" << endl;
	}
	if (a == b){
		cout << "a == b" << endl;
	}
}


Measured memory_bytes: 3076
n, k = map(int, input().split())
# lst = []
# leastnum = n

if n >= k:
    # nからずっとkを引く あまりと同じ 10 -3 - 3 - 3 == 10 - (3 * 3) == 10 % 3
    # ループに入るときの数字がn % kで ループする数数は固定のk からn % k を引いた数になるのでそれを比較
    x = n % k
    print(min(x, k - x))
else:
    # 最初から負の数になるから スタートが上のループと同じ
    # print(n)じゃだめ n:2 k:100 なら  98 2 98 2だが n:2 k:3 なら　1 2 1 2 だから
    print(min(n, k - n))

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>

using namespace std;

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

int main() {
    string S;
    cin >> S;
    int n = S.size();
    bool bad = false;
    rep(i, n - 1) {
        bad |= S[i] == S[i+1];
    }
    cout << (bad ? "Bad" : "Good") << endl;
    return 0;
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }
    }

    public class Solver
    {
        public struct AB
        {
            public int A;
            public int B;
        }

        int N;
        List<string> list = new List<string>();



        public void AddNext(string input, int count)
        {


            if (count == N)
            {
                list.Add(input + "1");
                list.Add(input + "0");
                return;
            }
            else
            {

                AddNext(input + "1", count + 1);
                AddNext(input + "0", count + 1);
            }

        }

        public void Calc()
        {

            var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

            var N = p[0];
            var M = p[1];

            var A = new List<long>();
            var B = new List<long>();

            var ikerutoko = new List<List<int>>();
            for (var i = 0; i < N; i++)
            {
                ikerutoko.Add(new List<int>());
            }

            for (var i = 0; i < M; i++)
            {
                p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                A.Add(p[0]);
                B.Add(p[1]);
                ikerutoko[p[0] - 1].Add(p[1]);
                ikerutoko[p[1] - 1].Add(p[0]);
            }

            var queue = new Queue<int>();
            queue.Enqueue(1);

            var ans = new int[N];

            while (queue.Count > 0)
            {
                var v = queue.Dequeue();

                foreach (var ike in ikerutoko[v - 1])
                {

                    queue.Enqueue(ike);
                    if (ans[ike - 1] == 0)
                    {
                        ans[ike - 1] = v;
                    }
                }

                ikerutoko[v - 1].Clear();

            }


            Console.WriteLine("Yes");
            foreach (var a in ans.Where((x, i) => i >= 1))
            {
                Console.WriteLine(a);
            }


        }


    }

}


Measured memory_bytes: 57880
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int a[401] , p[401] ,  dp[401][401] ;


int f(int i,int j)
{
    if( i == j ) return 0 ;
    if(dp[i][j] != -1) return dp[i][j] ;
    int ans = 1000000000000000 ;
    for(int k = i ; k < j ; k++ )
        ans = min( ans , p[j] - p[i-1] + f(i,k) + f(k+1,j) ) ;
    return dp[i][j] = ans ;
}

signed main()
{
   int n ;
   cin >> n ;
   p[0] = 0 ;
   for(int i=1;i<=n;i++) 
    {    
        cin >> a[i] ;
        p[i] = p[i-1] + a[i] ;
        for(int j=1;j<=n;j++)
            dp[i][j] = -1 ;
        
    }
   cout << f(1,n) << endl ;
    
    return 0;
}


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

int main() {
  int H, W; cin >> H >> W;
  int a[1010][1010];
  vector<tuple<int, int, int, int>> tup;
  for(int i = 1; i <= H; ++i) {
    for(int j = 1; j <= W; ++j) {
      cin >> a[i][j];
    }
  }
  for(int i = 1; i <= H; ++i) {
    for(int j = 1; j <= W; ++j) {
      if(a[i][j] % 2 == 0 || i + j == H + W) continue;
      if(i != H) {
        tup.push_back(make_tuple(i, j, i+1, j));
        a[i][j]--;
        a[i+1][j]++;
      } else {
        tup.push_back(make_tuple(i, j, i, j + 1));
        a[i][j]--;
        a[i][j+1]++;
      }
    }
  }
  cout << tup.size()<< endl;
  for(int i = 0; i < tup.size(); ++i) {
    cout << get<0>(tup[i]) << " " << get<1>(tup[i]) << " "<< get<2>(tup[i]) << " " << get<3>(tup[i]) << endl;
  }
  return 0;
}



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

int main()
{
	int a, b , c,d , e , f;
	cin>>a>>b>>c>>d>>e>>f;
	vector<int > water , sugar;
	for(int i = 0; i <= f; i += 100*a)
	{
		for(int j = 0; j + i <= f ; j+= b*100)
		{
			if(i+j <= f) water.push_back(i+j);
		}
	}
	int lm = f/100;
	lm *=e;
	for(int i = 0;i <= lm; i += c)
	{
		for(int j = 0; j + i <= lm ; j+=d)
		{
			if(i+j <= lm) sugar.push_back(i+j);
		}
	}
	int mxS  = 0, mxW = a*100;
	for(int i = 0; i < water.size(); i++)
	{
		for(int j = 0; j < sugar.size()  ; j++)
		{
			if(water[i]+sugar[j] > f) continue;
			if(water[i]*e < 100*sugar[j]) continue;
			//cout<<water[i]<<" "<<sugar[j]<<endl;
			int tmp = water[i];
			if(tmp*mxS <= mxW*sugar[j]) 
			{
				mxW = tmp;
				mxS = sugar[j];
			}
		}
	}
	cout<<mxW+mxS<<" "<<mxS<<endl;
	
}


Measured memory_bytes: 1400