akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

ll gcd(ll x, ll y)
{
    if((x % y) == 0)
    {
        return y;
    }

    return gcd(y, x % y);
}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll a[n];

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

    left_gcd[0] = a[0];
    for(int i=1;i<n;++i)
    {
        left_gcd[i] = gcd(left_gcd[i-1], a[i]);
    }

    right_gcd[n-1] = a[n-1];
    for(int i=1;i<n;++i)
    {
        right_gcd[n-1-i] = gcd(right_gcd[n-1-i+1], a[n-1-i]);
    }

    ll ret = 0;

    for(int i=0;i<n;++i)
    {
        if (i == 0) {
            ret = max(ret, right_gcd[1]);
        } else if (i == (n-1)) {
            ret = max(ret, left_gcd[n-2]);
        } else {
            ret = max(ret, gcd(left_gcd[i-1], right_gcd[i+1]));
        }
    }

    cout << ret << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	string str = "CODEFESTIVAL2016";
	int ans = 0;
	REP(i,16){
		if(s[i] != str[i])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
  const int m=2019;
  string s;
  cin>>s;
  int size=s.size();
  reverse(s.begin(),s.end());
  int x=1,y=0;
  vector<int> count(m);
  ll ans=0;
  for(int i=0;i<size;i++){
    count[y]++;
    y+=(s[i]-'0') * x;
    y%=m;
    ans+=count[y];
    x=x*10%m;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  N %= 10;
  if (N == 3) {
    cout << "bon" << endl;
  }
  else if (N == 0 || N == 1 || N == 6 || N == 8) {
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3608
#include<stdio.h>
#include<string.h>
int main(void){
    char str[1201],ch[26]="abcdefghijklmnopqrstuvwxyz";
    int i,s[26]={0,};
    while(fgets(str,sizeof(str),stdin)){
    for(i=0;i<strlen(str);i++){
        if(str[i]=='a' || str[i]=='A'){
            s[0]++;
        }else if(str[i]=='b' || str[i]=='B'){
            s[1]++;
        }else if(str[i]=='c' || str[i]=='C'){
            s[2]++;
        }else if(str[i]=='d' || str[i]=='D'){
            s[3]++;
        }else if(str[i]=='e' || str[i]=='E'){
            s[4]++;
        }else if(str[i]=='f' || str[i]=='F'){
            s[5]++;
        }else if(str[i]=='g' || str[i]=='G'){
            s[6]++;
        }else if(str[i]=='h' || str[i]=='H'){
            s[7]++;
        }else if(str[i]=='i' || str[i]=='I'){
            s[8]++;
        }else if(str[i]=='j' || str[i]=='J'){
            s[9]++;
        }else if(str[i]=='k' || str[i]=='K'){
            s[10]++;
        }else if(str[i]=='l' || str[i]=='L'){
            s[11]++;
        }else if(str[i]=='m' || str[i]=='M'){
            s[12]++;
        }else if(str[i]=='n' || str[i]=='N'){
            s[13]++;
        }else if(str[i]=='o' || str[i]=='O'){
            s[14]++;
        }else if(str[i]=='p' || str[i]=='P'){
            s[15]++;
        }else if(str[i]=='q' || str[i]=='Q'){
            s[16]++;
        }else if(str[i]=='r' || str[i]=='R'){
            s[17]++;
        }else if(str[i]=='s' || str[i]=='S'){
            s[18]++;
        }else if(str[i]=='t' || str[i]=='T'){
            s[19]++;
        }else if(str[i]=='u' || str[i]=='U'){
            s[20]++;
        }else if(str[i]=='v' || str[i]=='V'){
            s[21]++;
        }else if(str[i]=='w' || str[i]=='W'){
            s[22]++;
        }else if(str[i]=='x' || str[i]=='X'){
            s[23]++;
        }else if(str[i]=='y' || str[i]=='Y'){
            s[24]++;
        }else if(str[i]=='z' || str[i]=='Z'){
            s[25]++;
        }
    }
    }
    for(i=0;i<26;i++){
        printf("%c : %d\n",ch[i],s[i]);
    }
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int A, B;
    cin >> A >> B;
    if (A <= 2 * B) cout << 0 << endl;
    else cout << A - 2 * B << endl;
    return 0;
}


Measured memory_bytes: 256
NY = input().split()
N_Y = [int(s)for s in NY]

counter_Y = 0
counter = 0
listx = []
for i in range(N_Y[0]+1):
    for j in range(N_Y[0]+1):
        k = N_Y[0] - i - j
        counter_Y = 10000 * i + 5000 * j + 1000 * k
        if counter_Y == N_Y[1] and k >= 0:
            listx = [i,j,k]
            counter += 1

if counter == 0:
    print("-1 -1 -1")
else:
    print("{} {} {}".format(listx[0],listx[1],listx[2]))


Measured memory_bytes: 3064
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanInt() int {
	scanner.Scan()
	a, err := strconv.Atoi(scanner.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := scanInt()
	k := scanInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}

	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		if i == 0 {
			ret[i] = float64(a[i]+1) * 0.5
		} else if i >= k {
			ret[i] = ret[i-1] - float64(a[i-k]+1)*0.5 + float64(a[i]+1)*0.5
		} else {
			ret[i] = ret[i-1] + float64(a[i]+1)*0.5
		}
	}

	max := float64(0.0)
	for _, v := range ret {
		if max < v {
			max = v
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 4736
import java.util.*;
 
class Main{
    public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Dice[] xai = new Dice[n];
		for(int i=0; i<n; i++){
			int[] a = new int[6];
			for(int j=0; j<6; j++){
				a[j] = scan.nextInt();
			}
			xai[i] = new Dice(a);
		}

		String ans = "Yes";
		for(int i=0; i<n-1; i++){
			for(int j=1; j<n; j++){
				if(i==j)continue;
				if(xai[i].checkTwoDices(xai[i], xai[j]).equals("Yes")){
					ans = "No";
				}
			}
		}
		System.out.println(ans);
    }
}

class Dice{
	int[] dice;
	public Dice(int[] a){
		dice = new int[6];
		for(int i=0; i<6; i++){
			dice[i] = a[i];
		}
	}
	public void roll(char c){
		int tmp = 0;
		switch(c){
			case 'N':
				tmp = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = tmp;
				break;
			case 'W':
				tmp = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = tmp;
				break;
			case 'S':
				tmp = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = tmp;
				break;
			case 'E':
				tmp = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = tmp;
				break;
		}
	}
	public void rotation(){ //???????????????????¨???????????????????
		int tmp = dice[1];
		dice[1] = dice[2];
		dice[2] = dice[4];
		dice[4] = dice[3];
		dice[3] = tmp;
	}

	public String checkTwoDices(Dice xai1, Dice xai2){
		if(compareDices(xai1, xai2, 'N', 'W'))return "Yes";
		if(compareDices(xai1, xai2, 'N', 'E'))return "Yes";
		if(compareDices(xai1, xai2, 'S', 'W'))return "Yes";
		if(compareDices(xai1, xai2, 'S', 'E'))return "Yes";
		return "No";
	}

	public boolean checkSurface(Dice xai1, Dice xai2){
		if(xai1.dice[0]==xai2.dice[0] && xai1.dice[1]==xai2.dice[1] && xai1.dice[2]==xai2.dice[2] && xai1.dice[3]==xai2.dice[3] && xai1.dice[4]==xai2.dice[4] && xai1.dice[5]==xai2.dice[5]){
			return true;
		}
		return false;
	}

	public boolean compareDices(Dice xai1, Dice xai2, char c1, char c2){
		for(int i=0; i<6; i++){
			for(int j=0; j<6; j++){
				xai2.roll(c1);
				if(checkSurface(xai1, xai2))return true;
				xai2.roll(c2);
				if(checkSurface(xai1, xai2))return true;;
			}
			xai2.rotation();
			if(checkSurface(xai1, xai2))return true;
		}
		return false;
	}

	public int showTop(){
		return dice[0];
	}
}

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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N; cin >> N;
	cout << N+N*N+N*N*N << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
int dp[8005][205];
int n,m,len,L,Inv;
int fac[8005],ifac[8005];
int f[40005],g[40005],R[40005];

int ksm(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=1ll*res*x%mod;
		x=1ll*x*x%mod,y/=2;
	}
	return res;
}

int C(int x,int y){
	if(x<y) return 0;
	int res=1ll*fac[x]*ifac[y]%mod*ifac[x-y]%mod;
	return res;
}

void NTT(int *x,int on){
	for(int i=0;i<len;i++) if(i<R[i]) swap(x[i],x[R[i]]);
	for(int i=2;i<=len;i*=2){
		int wn=ksm(3,(mod-1)/i);
		if(on==-1) wn=ksm(wn,mod-2);
		for(int j=0;j<len;j+=i){
			int w=1;
			for(int k=0;k<i/2;k++){
				int u=x[j+k],v=1ll*w*x[j+k+i/2]%mod;
				x[j+k]=(u+v)%mod;
				x[j+k+i/2]=(u-v+mod)%mod;
				w=1ll*w*wn%mod;
			}
		}
	}
}

int main(){
	scanf("%d %d",&n,&m);
	dp[0][0]=1;
	fac[0]=1;for(int i=1;i<=n+2;i++) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n+2]=ksm(fac[n+2],mod-2);
	len=1,L=0;
	while(len<=2*n) len*=2,L++;
	for(int i=0;i<len;i++) R[i]=(R[i>>1]>>1)|((i&1)<<(L-1));
	Inv=ksm(len,mod-2);
	for(int i=n+1;i>=0;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
	for(int j=1;j<=m;j++){
		for(int i=0;i<=n;i++) dp[i][j]=1ll*dp[i][j-1]*(1+i+C(i,2))%mod;
		memset(f,0,sizeof(f));for(int i=0;i<=n;i++) f[i]=1ll*dp[i][j-1]*ifac[i]%mod;
		memset(g,0,sizeof(g));for(int i=1;i<=n;i++) g[i]=ifac[i+2];
		NTT(f,1),NTT(g,1);
		for(int i=0;i<len;i++) f[i]=1ll*f[i]*g[i]%mod;
		NTT(f,-1);
		for(int i=0;i<len;i++) f[i]=1ll*f[i]*Inv%mod;
		for(int i=0;i<=n;i++) (dp[i][j]+=1ll*fac[i+2]*f[i]%mod)%=mod;
	}
	int ans=0;
	for(int i=0;i<=n;i++) (ans+=1ll*C(n,i)*dp[i][m]%mod)%=mod;
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 7040
import collections

n = int(input())
v = list(map(int, input().split()))
even_odd_length = n / 2
replace_total = 0

list_odd = v[0::2]
list_even = v[1::2]

dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))
dict_c_even_bk = dict_c_even.copy()

replace_total_tmp = 0
replace_total_tmp2 = 0

max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even

max_c_odd_keys = [k for k, v in dict_c_odd.items() if v == max_count_c_odd]
max_c_even_keys = [k for k, v in dict_c_even.items() if v == max_count_c_even]

if len(set(v)) == 1:
    print(int(even_odd_length))
else:    
    if max_c_odd_keys[0] in dict_c_even:
        del dict_c_even[max_c_odd_keys[0]]
    max_count_c_even = max(dict_c_even.values())
    replace_total_tmp = (n - max_count_c_odd - max_count_c_even)
    
    dict_c_even = dict_c_even_bk
    max_count_c_even = max_count_c_even_bk
    
    if max_c_even_keys[0] in dict_c_odd:
        del dict_c_odd[max_c_even_keys[0]]
    max_count_c_odd = max(dict_c_odd.values())
    replace_total_tmp2 = (n - max_count_c_odd - max_count_c_even)
    
    if replace_total_tmp >= replace_total_tmp2:
         replace_total = replace_total_tmp2
    else:
         replace_total = replace_total_tmp

    print(replace_total)

Measured memory_bytes: 31960
#include <bits/stdc++.h>
#define adj_list vector<vi>
#define endl "\n"
#define INF_INT 2e9
#define INF_LL 2e18
#define matmax 25
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define pl pair<ll, ll>
#define pll pair<ll, pair<ll, ll> >
#define vi vector<int>
#define vl vector<ll>
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long int ll;

ll pow1(ll a, ll b, ll m = mod)
{
	if (b == 0)
		return 1ll;
	else if (b == 1)
		return a;
	else
	{
		ll x = pow1(a, b/2, m);
		x *= x;
		x %= m;
		if (b%2)
		{
			x *= a;
			x %= m;
		}
		return x;
	}
}

template <class avgType>
avgType avg(avgType a, avgType b) {
	return (a + b)/2;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());

int randInt() {
	return rng() % INT_MAX;
}

ll randLL() {
	return rng64() % LLONG_MAX;
}

vector< int > hashmods = {1000000007, 1000000009, 1000000021, 1000000033, 1000000087, 1000000093};

bool isPalindrome(string s, int a, int b) {
	while (a < b) {
		if (s[a] != s[b])
			return false;
		a++; b--;
	}
	return true;
}

string s;

int main() {
	fastio;
	cin>>s;

	bool ans = isPalindrome(s, 0, s.length()-1) & isPalindrome(s, 0, s.length()/2 - 1) & isPalindrome(s, s.length()/2 + 1, s.length() - 1);
	cout<<(ans ? "Yes\n" : "No\n");

	return 0;
}

Measured memory_bytes: 256
package main

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

/*
0 5
5

1 11
1100

2 85
850000
*/

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 1024)
    line := readLine(reader)
    arr := strings.Split(line, " ")
    D, _ := strconv.Atoi(arr[0])
    N, _ := strconv.Atoi(arr[1])

    num := math.Pow(100.0, float64(D))
    var retval int

    if N == 100 {
        retval = int(num) * 101
    } else {
        retval = int(num) * N
    }

    fmt.Println(retval)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

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

    if (n / 100 == 1) {
        n += 800;
    } else {
        n -= 800;
    }
    if (n % 100 / 10 == 1) {
        n += 80;
    } else {
        n -= 80;
    }
    if (n % 10 / 1 == 1) {
        n += 8;
    } else {
        n -= 8;
    }

    cout << n << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n;
  int p[20];
  int ans=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
  }

  for(int i=2;i<n;i++){
    if(p[i-2]<p[i-1] && p[i-1]<p[i]){      
      ans++;
   }
    else if(p[i-2]>p[i-1] && p[i-1]>p[i]){
      ans++;
   }
   else{}
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
from operator import xor

A, B = map(int, input().split())


def f(n):
    if n % 2 == 0:
        if n % 4 == 0:
            return n
        else:
            return xor(n, 1)
    else:
        return xor(n, f(n - 1))


print(xor(f(A - 1), f(B)))

# 0,   1,   2,   3,   4,   5,   6,   7
# 000, 001, 010, 011, 100, 101, 110, 111
# 000, 001, 011, 000, 100, 001, 000, 111
# f(A, B) = f(0, A - 1) ^ f(0, B)
# f(0, X) = X ^ (X - 1)


Measured memory_bytes: 38256
import scala.io.StdIn

object Main extends App {
   val a = StdIn.readLine().toInt
   val b = StdIn.readLine().toInt
   val c = StdIn.readLine().toInt
   val x = StdIn.readLine().toInt
   
   val r = (0 to a).foldLeft(0){ (acca, ai) =>
      (0 to b).foldLeft(acca) { (accb, bi) =>
         val rc = x - (ai*500 + bi*100)
         if(0 <= rc && rc / 50 <= c && rc % 50 == 0) accb + 1 else accb + 0
      }
   }
   
   println(r)
}


Measured memory_bytes: 25404
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (n, m) = get!(usize, usize);
    let xy = get!(usize, usize; m);

    let mut red = vec![false; n];
    red[0] = true;
    let mut bs = vec![1; n];
    for &(x, y) in &xy {
        let x = x - 1;
        let y = y - 1;

        if red[x] {
            red[y] = true;
            if bs[x] == 1 {
                red[x] = false;
            }
        }
        bs[x] -= 1;
        bs[y] += 1;
    }

    println!("{}", red.iter().filter(|&&b| b).count());
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define Rep(i,n) for(int i=0; i<(n); i+=2)
#define rep2(i,x,n) for(int i=x; i<=(n); i++)
#define MOD 1000000007
#define EPS 10e-8
const int INF = 1e9;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

bool compare_by_b(pair<int, ll> a, pair<int, ll> b)
{
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
    int n,a;
    cin >> n;
    vector<pair<int, int>> pairs(n);
    rep(i,n){
        cin >> a;
        pairs[i] = make_pair(a,i);
    }
   sort(pairs.begin(), pairs.end());
   rep(i,n){
       cout << pairs[i].second+1<< endl;
   }
}

Measured memory_bytes: 1664
s = int(input())

count=1
judge=0
an=s

if an<3 or an==4:
    judge = 1
    cout=1
while judge==0:   
    if an%2==0:
        next_a=an/2
    else:
        next_a=3*an+1
    count+=1
    an=next_a
    if(an<3)or(an==4):
        judge = 1

print(count+3)

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N,M;
    cin >> N >> M;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    vector<pair<ll,ll>> BC(M);
    REP(i,M) cin >> BC[i].se >> BC[i].fi;
    sort(ALL(A));
    sort(ALL(BC),greater<pair<ll,ll>>());
    int a = 0, b = 0; //a個目の動作をb回やった
    REP(i,N) {
        A[i] = max(A[i], BC[a].fi);
        b++;
        if (b == BC[a].se) {
            a++;
            b = 0;
        }
        if (a == M) break;
    }
    ll ans = 0;
    REP(i,N) ans += A[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
import itertools

S=input()
sum1=0


for i in itertools.product(["+","-"],repeat=3):
    ans=""
    for j in range(3):
        if i[j]=="+":
            ans+=S[j]+i[j]
        elif i[j]=="-":
            ans+=S[j]+"-"
    ans+=S[-1]
    sum1=eval(ans)
    if sum1==7:
        print(ans+"="+str(7))
        exit()
    
        

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

int main() {
  int A,B;
  cin >> A >> B;
  int ans = 0;
  if ((A != 1) && (B != 1)) {
    cout << 1 << endl;
  }
  else if ((A != 2) && (B != 2)) {
    cout << 2 << endl;
  }
  else {
    cout << 3 << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define int int long long // 2e9 & 9e18
using namespace std; const int inf = numeric_limits<int>::max();
struct __io{__io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}} __io; // fast I/O
#ifdef LOCAL // setting up print debugging (yes lol)
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.x<<", "<<p.y<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
#endif

int n, m, init_s;
const int S = 2501;
vector<vector<pair<int, int>>> g;

signed main() {
    cin >> n >> m >> init_s;
    init_s = min(init_s, S-1);
    g.assign(n*S, {});
    // state: (vertex v, s coins) -> s*n + v
    for (int i = 0; i < m; ++i) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        for (int s = a; s < S; ++s) {
            g[u + s*n].push_back({v + (s - a)*n, b});
            g[v + s*n].push_back({u + (s - a)*n, b});
        }
    }
    for (int i = 0; i < n; ++i) {
        int c, d;
        cin >> c >> d;
        for (int s = 0; s + c < S; ++s) {
            g[i + s*n].push_back({i + (s + c)*n, d});
        }
    }

    // dijkstra
    vector<int> d(n * S, inf);
    d[init_s*n] = 0;
    set<pair<int, int>> boundary;
    boundary.insert({0, init_s*n});
    while (!boundary.empty()) {
        auto [_, v] = *boundary.begin();
        boundary.erase(boundary.begin());
        if (d[v] == inf) continue;
        // print("checking", v, "its neighbours:", g[v]);
        for (auto [u, cost] : g[v]) {
            if (d[u] > d[v] + cost) {
                d[u] = d[v] + cost;
                boundary.insert({d[u], u});
            }
        }
    }

    for (int i = 1; i < n; ++i) {
        int best = inf;
        for (int s = 0; s < S; ++s) {
            best = min(best, d[i + s*n]);
        }
        cout << best << '\n';
    }
    cout << endl;
}


Measured memory_bytes: 26372
import sys
readline=sys.stdin.readline

X,N=map(int,readline().split())
P=set(list(map(int,readline().split())))

x = X
while x in P:
  x -= 1
minX = x

x = X
while x in P:
  x += 1
maxX=x

if abs(minX - X) <= abs(maxX - X):
  print(minX)
else:
  print(maxX)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    ll x,y; cin >>x>>y;

    ll ans;
    if ((x>=0) == (y>=0)) {
        if (y >= x) {
            ans = y - x;
        } else {
            ans = x - y + (y==0?1:2);
        }
    } else {
        if (y >= x) {
            if (y >= abs(x)) {
                ans = y - (-x) + 1;
            } else {
                ans = -x -y + (y==0?0:1);
            }
        } else {
            if (x >= abs(y)) {
                ans = y - (-x) + 1;
            } else {
                ans = -y - x + 1;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define co(x) cout << (x) << "\n"
#define ll long long
#define pb push_back
#define Never
#define To

using namespace std;

int main(){

	cin.tie(0);
	ios::sync_with_stdio(false);

	ll N, M;

	cin >> N >> M;

	if(N != 1) N -= 2;
	if(M != 1) M -= 2;

	cout << N *  M << endl;

	Never To return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
#define int unsigned long long
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;


signed main(){
  ll q,h,s,d;
  ll n;
  cin>>q>>h>>s>>d>>n;

  ll Q=q*4;
  ll H=h*2;

  int ans=0;
  if(min(Q,min(H,s))*2>d){
    ans+=n/2*d;
    cerr<<"ans="<<ans<<endl;
    n-=((n/2)*2);
    cerr<<"n="<<n<<endl;
    ans+=min(Q,min(H,s))*n;
  }else{
    ans+=min(Q,min(H,s))*n;
  }
  cout<<ans<<endl;



}


Measured memory_bytes: 256
from functools import reduce
from itertools import combinations
from math import gcd


def func(A):
    is_A = [0] * (10**6+1)
    for a in A:
        is_A[a] += 1
    if any(x > 1 for x in is_A[2:]):
        return False
    n = 0
    for i in range(2, 10**6+1, 2):
        if is_A[i]:
            n += 1
    if n > 1:
        return False
    for i in range(3, 10**6+1, 2):
        n = 0
        for j in range(i, 10**6+1, i):
            if is_A[j]:
                n += 1
        if n > 1:
            return False
    return True


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    if func(A):
        # if not all(gcd(i, j)==1 for i, j in combinations(A, 2)):
        #     raise NameError
        print('pairwise coprime')
    elif reduce(gcd, A) == 1:
        print('setwise coprime')
    else:
        print('not coprime')
    

if __name__ == '__main__':
    solve()

Measured memory_bytes: 199028
import sys
def myin():
    for s in sys.stdin:
        for t in s.split():
            yield t
##
_in=myin()
N,M,C=[int(next(_in)) for i in range(3)]
B=[int(next(_in)) for i in range(M)]
A=[[int(next(_in)) for i in range(M)] for j in range(N)]
ans=0
for i in range(N):
    s=C
    for j in range(M):
        s+=A[i][j]*B[j]
    if s > 0:
        ans+=1
print(ans)
##


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n, x, s;
int main()
{
	while(cin >> n >> x && (n!=0))
	{
		s=0;
		for(int i=n; i*3>=x+3; i--)
		{
			if(((x-i)>=3)&&((x-i)%2==0))
			{
				s+=min(((x-i)/2)-1, i-1-((x-i)/2));
			}
			else if((x-i)>=3)
			{
				s+=min((x-i)/2, i-1-((x-i)/2));
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  rep(i, M) cin >> X[i];

  sort(X.begin(), X.end());

  vector<int> move(M);
  rep(i, M-1) {
    move[i] = X[i+1] - X[i];
  }
  sort(move.begin(), move.end());

  int ans = 0;
  rep(i, M-(N-1)) {
    ans += move[i];
  }

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


Measured memory_bytes: 1024
//abc161_a.cpp
//Sat Apr  4 20:35:15 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int x,y,z;
	cin >> x >> y >> z;

		cout << z << " " << x << " " << y << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i<N; i++)
#define RVROOP(i, N) for(int i=N; i>=0; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  char ans; cin>>ans;
  ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 764
#C_Step
N = int(input())
A = list(map(int,input().split()))
Step = 0 
for i in range(1,N,1) :
    if (A[i-1] - A[i] ) > 0 :
       Step +=  A[i-1] - A[i]
       A[i] +=  A[i-1] - A[i]
# 出力
print(Step)

Measured memory_bytes: 32352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a, b;
    
    cin >> a;
    cin >> b;
    
    for (int i=0; i<=1200; i++){
        if (floor(i*0.08)==a && floor(i*0.1)==b){
          cout << i << endl;
          break;
         }
        else if (i==1200){
          cout << -1 << endl;
        }
    }
   
    }

Measured memory_bytes: 256
import sys


fin = sys.stdin.readline
n = int(fin())
a_list = sorted(int(elem) for elem in fin().split())

num_elems = a_list[-1]
num_choices = -1
max_diff = float('-inf')
for a in a_list[:-1]:
    diff = min(num_elems - a, a)
    if diff > max_diff:
        num_choices = a
        max_diff = diff

print(num_elems, num_choices)


Measured memory_bytes: 58864
#include<stdio.h>

int isPrime(int x) {
    int i;
    if (x < 2) return 0;
    else if (x == 2) return 1;
    if (x % 2 == 0) return 0;
    for (i = 3; i * i <= x; i++) {
        if (x % i == 0) return 0;
    }
    return 1;
}

int main() {
    int n, x, i;
    int cnt = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &x);
        if (isPrime(x)) cnt++;
    }
    printf("%d\n", cnt);
    
    return 0;
}


Measured memory_bytes: 2124
#include <stdio.h>
#include <string.h>
#include <algorithm>

using ll = long long;

int main()
{
	int N;
	scanf("%d", &N);

	static ll A[100001];
	for (int i = 0; i < N + 1; i++) {
		scanf("%lld", &A[i]);
	}
	if (N == 0) {
		if (A[0] == 1) {
			puts("1");
		}
		else {
			puts("-1");
		}
		return 0;
	}

	static ll hist_max[100001];
	ll cmax = A[N];
	ll cmin = A[N];
	for (int i = N - 1; i >= 0; i--) {
		bool ng = false;
		cmax = cmax;
		cmin = (cmin + 1) / 2;
		cmax += A[i];
		cmin += A[i];
		if (i < 60) {
			ll newmax = (1LL << i);
			if (newmax < cmin) {
				ng = true;
			}
			if (cmax > newmax) {
				cmax = newmax;
			}
		}
		if (ng) {
			puts("-1");
			return 0;
		}
		hist_max[i] = cmax;
		//printf("%d..%d\n", cmin, cmax);
	}

	ll ans = A[N] + 1;
	ll cur = 1;
	for (int i = 1; i < N; i++) {
		ll tmp = std::min(cur * 2, hist_max[i]);
		cur = tmp - A[i];
		ans += tmp;
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 3296
import sys
 
x,y = map(int,input().split())
 
for n in range(x+1):
    kame = x - n
 
    tsuru_leg = n*2
    kame_leg = kame*4
 
    if y == tsuru_leg + kame_leg:
        print('Yes')
        sys.exit()
 
print('No')

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

const int N = 507;
 
int n, m, q, dp[N][N];

int main() {
	scanf("%d%d%d", &n, &m, &q);
	while (m--) {
		int l, r; scanf("%d%d", &l, &r);
		dp[l][r]++;
	}
	for (int l = 1; l <= n; l++)
		for (int i = 1; i + l <= n; i++) {
			int j = i + l;
			dp[i][j] += dp[i + 1][j] + dp[i][j - 1] - dp[i + 1][j - 1];
		}
	while (q--) {
		int l, r; scanf("%d%d", &l, &r);
		printf("%d\n", dp[l][r]);
	}
	return 0;
}

Measured memory_bytes: 1920
import sys
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
root=[-1]*n
def r(x):
    if root[x]<0:
        return x
    else:
        root[x]=r(root[x])
        return root[x]
def unite(x,y):
    x=r(x)
    y=r(y)
    if x==y:
        return
    root[x]+=root[y]
    root[y]=x
def size(x):
    x=r(x)
    return -root[x]
for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    unite(x,y)
ans=0
for i in range(n):
    ans=max(ans,size(i))
print(ans)





Measured memory_bytes: 35880
n, q = map(int, input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2]=='AC' else 0)
for i in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

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

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

    long long a, b, c;
    cin >> a >> b >> c;

    if(4*a*b < (c-a-b)*(c-a-b)) {
        if(c-a-b <= 0)
            cout << "No\n";
        else
        {
            cout << "Yes\n";
        }
        
    }
        
    else
        cout << "No\n";

    
    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int gcd( int m, int n )
{
	int a=max(m,n),b=min(m,n);
	if(m==0) return n;if(n==0) return m;
	if(a%b==0) return b;
	return gcd(b,a-b*(a/b));
}
int a[100100];
int main()
{
	lint out=1,mo=998244353;
	int n;
	cin>>n;
	rep(i,n){
		cin>>a[i];//out*=gcd(a,i);out%=mo;
	}
	sort(a,a+n);
	rep(i,n){
		out*=gcd(i,a[i]);out%=mo;
	}
	cout<<out<<endl;
}


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

using namespace std;

const int HUGEI = 2147483647;  // (1 << 31) - 1
const long long HUGEL = 9223372036854775807;  // (1 << 63) - 1
const string ABC = "abcdefghijklmnopqrstuvwxyz";

int n, m;
vector <int> pn, xm, ym;

struct DisjointSet {
    vector <int> p;
    DisjointSet() {}
    DisjointSet(int size) {
        p.resize(size, 0);
        for (int i = 0; i < size; i++) p[i] = i;
    }

    void unite(int x, int y) {
        p[find(y)] = find(x);
    }

    int find(int x) {
        if (x != p[x]) p[x] = find(p[x]);
        return p[x];
    }
};

void read() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        pn.push_back(p - 1);
    }
    for (int j = 0; j < m; j++) {
        int x, y;
        cin >> x >> y;
        xm.push_back(x - 1);
        ym.push_back(y - 1);
    }
}

DisjointSet construct() {
    DisjointSet ds = DisjointSet(n);
    for (int j = 0; j < m; j++) {
        ds.unite(xm[j], ym[j]);
    }
    return ds;
}

int cnt(DisjointSet ds) {
    vector < vector <int> > nodes;
    vector <int> empty;
    for (int i = 0; i < n; i++) {
        nodes.push_back(empty);
    }

    for (int i = 0; i < n; i++) {
        int j = ds.find(i);
        nodes[j].push_back(i);
    }

    int res = 0;
    for (int j = 0; j < n; j++) {
        set <int> iset, pset, cm;
        for (auto itr = nodes[j].begin(); itr != nodes[j].end(); itr++) {
            iset.insert(*itr);
            pset.insert(pn[*itr]);
        }
        set_intersection(iset.begin(), iset.end(), pset.begin(), pset.end(),
                         inserter(cm, cm.begin()));
        res += cm.size();
    }
    return res;
}

int main(void) {
    read();
    DisjointSet ds = construct();
    cout << cnt(ds) << endl;
    return 0;
}


Measured memory_bytes: 19308
#include <bits/stdc++.h>
using namespace std;
using ll     = long long;
using prefix = __attribute__((constructor))void;
const ll MOD = 1000000007;
const ll INF = LONG_MAX;

#define elif           else if
#define def            inline auto
#define func           inline constexpr ll
#define up(i,a,n)      for(ll i=(a),i##_1=(n);i<=i##_1;++i)
#define down(i,a,n)    for(ll i=(a),i##_1=(n);i>=i##_1;--i)
#define rep(i,n)       up(i,0,n-1)
#define append(a)      push_back(a)

func    gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
func    lcm(ll a,ll b) {return a*b/gcd(a,b);}
def     dig(ll a)      {return to_string(a).length();}
prefix  init()         {cin.tie(0),ios::sync_with_stdio(0),cout<<fixed<<setprecision(10);}

ll x[200000],a[200000],N,X,S=INF;

bool is_sum_overflow(long a,long b){
	if (a<INF/2){
		if (b<INF/2)
			return false;
		else
			return (b-INF/2+a>INF/2);
	}
	else {
		if (b<INF/2)
			return true;
		else
			return (a-INF/2+b>INF/2);
	}
}

def C(ll n){
    if(n==0)return 5LL;
    return 3+2*n;
}

def solve(ll n){
    ll i=N-1,k=0,s=0;
    while(i-n>=0){
        if(is_sum_overflow(s,(a[i]-a[i-n])*C(k)))return INF;
        s+=(a[i]-a[i-n])*C(k);
        k++;
        i-=n;
    }
    s+=a[i]*C(k);
    return s+(n+N)*X;
}

signed main(){
    cin>>N>>X;
    rep(i,N){
        cin>>x[i];
        a[i]=x[i]+(i?a[i-1]:0);
    }
    up(i,1,N){
        S=min(solve(i),S);
    }
    cout<<S<<endl;
}


Measured memory_bytes: 3456
import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    if w==1 or h==1:
        print(1)
        return
    ans = 0
    ans += math.ceil(w/2)*math.ceil(h/2)
    ans += (w//2)*(h//2)
    print(ans)
    return

if __name__=='__main__':
    h,w = IL()
    solve()

Measured memory_bytes: 26904
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int n;
int[] a;
int[][][] memo;
bool[][] done;
int[] dfs(int turn, int index, int z, int w)
{
  if (index == n) {
    return [z, w];
  }
  if (done[turn][index])
  {
    return memo[turn][index];
  }
  int ans = turn == 0 ? int.min : int.max;
  int[] ret;
  for (int i = index; i < n; ++i)
  {
    if (turn == 0) {
      auto sub = dfs(1, i + 1, a[i], w);
      if (ans < abs(sub.front - sub.back)) {
        ans = abs(sub.front - sub.back);
        ret = sub;
      }
    } else {
      auto sub = dfs(0, i + 1, z, a[i]);
      if (ans > abs(sub.front - sub.back)) {
        ans = abs(sub.front - sub.back);
        ret = sub;
      }
    }
  }
  done[turn][index] = true;
  memo[turn][index] = ret;
  return ret;
}

void main()
{
  auto nzw = readln.chomp.split.map!(to!int);
  n = nzw[0];
  int z = nzw[1];
  int w = nzw[2];
  a = readln.chomp.split.map!(to!int).array;
  memo = new int[][][](2, n);
  done = new bool[][](2, n);
  auto ret = dfs(0, 0, z, w);
  writeln = abs(ret.front - ret.back);
}


Measured memory_bytes: 892
n,m,k=map(int,input().split())
ab=[list(map(int,input().split()))for i in range(m)]
cd=[list(map(int,input().split()))for i in range(k)]
#UnionFind木
class UnionFind():
    #作りたい要素数nで初期化
    #使用するインスタンス変数の初期化
    def __init__(self,n):
        #ルートノード
        #n[x]<0ならそのノードが根かつその値の絶対値が木の要素数
        #ルートノードでその木の要素数を記録する
        self.root=[-1]*n
        #木をくっつける時にアンバランスにならないように調整する
        self.rnk=[0]*n
    #ノードxのルートノードを見つける
    def Find_Root(self,x):
        if self.root[x]<0:
            return x
        else:
            #ここで代入しておくことで、のちの繰り返しを避ける
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]
    #木の併合、入力は併合したい各ノード
    def Unite(self,x,y):
        #入力ノードのルートノードを見つける
        x=self.Find_Root(x)
        y=self.Find_Root(y)
        #すでに同じ木に属していた場合
        if x==y:
            return
        #違う木に属していた場合rを見てくっける方法を決める
        #木の高さを見て低いほうを高い木に結合する
        elif self.rnk[x]>self.rnk[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y
            #rnkが同じ（深さに差がない場合)はrnkを1増やす
            if self.rnk[x]==self.rnk[y]:
                self.rnk[y]+=1
    #xとyが同じグループに属するか判断
    def Root_Same(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)
    #ノードxが属する木のサイズを返す
    def Count(self,x):
        return -self.root[self.Find_Root(x)]
#UnionFindクラスを作成
u=UnionFind(n)
#友達関係のa,bの木を接合する
for a,b in ab:
    #配列のインデックスだからa-1,b-1とする
    u.Unite(a-1,b-1)
#同じグループに属する人-自分自身の値をansに格納する
ans=[u.Count(i)-1 for i in range(n)]
#(友達候補)=(同じグループに属する人の数)-(友達人数)-(ブロック人数)-(自分自身)
#まず友達人数を引く
for a,b in ab:
    #if文は省略しても可
    if u.Root_Same(a-1,b-1):
        ans[a-1]-=1
        ans[b-1]-=1
#最後にブロック人数を引く
for c,d in cd:
    #同じグループに属するならば引く
    if u.Root_Same(c-1,d-1):
        ans[c-1]-=1
        ans[d-1]-=1
print(*ans)


Measured memory_bytes: 124552
/**
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 2019-11-24 17:29:32
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

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

  string s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  s1 += s1;
  //debug(s1);

  int n; cin >> n;
  string s; cin >> s;

  for (int i = 0; i < (int) s.size(); ++i) {
    int cur = s[i] - 'A';
    s[i] = s1[cur + n];
  }

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー
#include <stack>
#include <bitset>

#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define mer(i,m,n) for(int i=(m);i>(n);--i)

#define MOD 1000000007
//#define MOD 998244353
//#define MAX 

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<vector<int>> ww;
//vector<char> vc;
vector<string> vs;




int main() {
	
	int D;
	ll S = 0;
	cin >> D;
	v.resize(D + 1,0);
	w.resize(27, 0);
	vector<int> x(27, 0);
	vector<int> y(27, 0);
	vector<int> c(27);
	vv.resize(D + 1, vector<int>(27, 0));

	rep(i, 1, 27)cin >> c[i];
	rep(i, 1, D+1) {
		rep(j, 1, 27)cin >> vv[i][j];
	}

	y[0] -= 99999;
	rep(i, 1, D + 1) {
		rep(j, 1, 27) y[j] = vv[i][j] + c[j] * (i - x[j]) - c[j] * (D - i);
		int max_num = max_element(y.begin(), y.end()) - y.begin();
		x[max_num] = i;
		rep(j, 1, 27) {
			if (j == max_num)S += vv[i][j];
			else S -= c[j] * (i - x[j]);
		}
		cout << max_num << '\n';
	}
	//cout << S << '\n';
	return 0;
}

Measured memory_bytes: 3668