akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long          	ll;
typedef long long unsigned 	llu;
typedef double             	dl;
typedef pair<int,int>      	pii;
typedef pair<ll,ll>     	pll;
typedef vector<int>        	vi;
typedef vector<ll>        	vl;
typedef map<int,int> 		mii;
typedef map<ll,ll>         	mll;
typedef map<string,int>    	msi;
typedef map<char,int>      	mci;
typedef pair<int ,pii>      piii;
typedef vector<pii>         vpii;
typedef vector<piii>        vpiii;

#define pi                  acos(-1.0)
#define S                   second
#define F                   first
#define pb                  push_back
#define mkp                 make_pair
#define mem(a,b)            memset(a,b,sizeof a)
#define all(v)              v.begin(),v.end()
#define vsort(v)            sort(v.begin(),v.end())
#define IO                  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define gcd(a,b)            __gcd(a,b)
#define FOR(i,a,b)			for(int i=a;i<=b;i++)
#define RFOR(i,a,b)			for(int i=a;i>=b;i--)

#define I(a)                scanf("%d",&a)
#define I2(a,b)             scanf("%d%d",&a,&b)
#define L(a)                scanf("%lld",&a)
#define L2(a,b)             scanf("%lld%lld",&a,&b)
#define D(a)                scanf("%lf",&a)

#define SP                  cout<<" ";
#define PI(a)               printf("%d",a)
#define PL(a)               printf("%lld",a)
#define PD(a)               printf("%lf",a)
#define CHK                 cout<<"MK"<<endl

template <class T> inline T BMOD(T p,T e,T m){T ret=1;while(e){if(e&1) ret=(ret*p)%m;p=(p*p)%m;e>>=1;}return (T)ret;}
template <class T> inline T MODINV(T a,T m){return BMOD(a,m-2,m);}
template <class T> inline T isPrime(T a){for(T i=2;i<=sqrt(double(a));i++){if(a%i==0){return 0;}}return 1;}
template <class T> inline T lcm(T a, T b){return (a/gcd(a,b))*b;}
template <class T> inline T power(T a, T b){return (b==0)?1:a*power(a,b-1);}
template <class T> inline string toString(T t) { stringstream ss; ss<<t; return ss.str();}
template <class T> inline long long toLong(T t) {stringstream ss;ss<<t;long long ret;ss>>ret;return ret;}
template <class T> inline int toInt(T t) {stringstream ss;ss<<t;int ret;ss>>ret;return ret;}
template <class T> inline bool leapYear(T t){if(!(t%(T)400) || (!(t%(T)4) && t%(T)100)) return true; return false;}

//~ cout << fixed << setprecision(20) << Ans << endl;
//~ priority_queue<piii,vpiii, greater<piii> >pq; //for dijkstra
/*                 _                      */
/*____________|\/||_||\||_________________*/

string buffer;
int INT(){
	getline(cin,buffer);
	return toInt(buffer);
}
int LONG(){
	getline(cin,buffer);
	return toLong(buffer);
}

const int MX = 300010;
const ll  MD = 1e9+7;


int main()
{
	IO;
	//~ freopen("/home/krishna/PRG/practice/input.in","r",stdin);
	//~ cout<<"Ready to go!"<<endl;
	ll n,k,a[MX];
	cin>>n;
	k = n;
	for(int i=0;i<n*3;i++) cin>>a[i];
	n*=3;
	sort(a,a+n);
	ll Ans = 0;
	for(int i=n-2;k;k--,i-=2){
		Ans+=a[i];
	}
	cout<<Ans<<endl;
	return 0;
}



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

int main() {
    int n,b;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
    }

    for(int j = 0;j < n;j ++){
        for(int i = 0;i < n-1 ; i ++){
            if(a.at(i) < a.at(i+1)){
                b = a.at(i);
                a.at(i) = a.at(i+1);
                a.at(i+1) = b;
            }
        }
    }

    int A = 0, B = 0;
    for(int i = 0; i < n; i += 2){
        A += a.at(i);
    }
    for(int i = 1; i < n; i += 2){
        B += a.at(i);
    }

    cout << A-B << endl;

}
    

Measured memory_bytes: 256
let a = Array.init 4001 (fun x -> 0);;
let () =
  let rec loop b = function
      2001 -> ()
    | i ->
       let t = (i+3)*(i+2)*(i+1)/6 and
           v = if i > 1000 then b + ((i-999)*(i-1000)*2) else b in
       a.(i) <- t-v;
       a.(4000-i) <- a.(i);
       loop v (i+1)
  in loop 0 0;;

let rec read () =
  try let n = read_int () in
      Printf.printf "%d\n" a.(n);read ()
  with End_of_file -> ()
;;

let () = read ();;

Measured memory_bytes: 2340
#include<bits/stdc++.h>
using namespace std;
int n,f,s[14][8],t,h,ans;
int main()
{
    scanf("%d%d",&n,&f);
    for(int i=1;i<=11;i++)
    for(int j=1;j<=7;j++)
    {
        t++;
        s[i][j]=t;
    }
    for(int i=1;i<=11;i++)
        for(int j=1;j<=7-3+1;j++)
        {
            t=0;
            for(int k=0;k<3;k++)
            for(int l=0;l<3;l++)
                t+=s[(i+k-1)%11+1][j+l];
            if(t%11==f)
			    h++;
        }
    ans+=max(0,(n/11-1))*h;
    if(n/11>0)
	    n-=(n/11-1)*11;
    for(int i=1;i<=n-3+1;i++)
        for(int j=1;j<=7-3+1;j++)
        {
            t=0;
            for(int k=0;k<3;k++)
                for(int l=0;l<3;l++)
                    t+=s[(i+k-1)%11+1][j+l];
            if(t%11==f)ans++;
    }
    printf("%d\n",ans);
    return 0;
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

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

    int maior = -1;

    for ( int i = 1; i < n; i++ ) {
        string r = s.substr(0, i), t = s.substr(i, n - i);
        // cout << r << " <- r t -> " << t << endl;
        set<char> letras;

        for ( auto l : r ) {
            letras.insert(l);
        }
        int cont = 0;
        for ( auto l : t ) {
            if ( letras.find(l) != letras.end() ) {
                cont++;
                letras.erase(l);
            }
        }
        maior = max(cont, maior);
    }

    cout << maior << endl;

    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <queue>

#define N_MAX 100001

int desc(const void *a, const void *b){
  if(*(long *)a > *(long *)b){
    return -1;
  }else if(*(long *)a == *(long *)b){
    return 0;
  }else{
    return 1;
  }
}

int main(void){
  int i, j;

  int n, m;
  scanf("%d%d", &n, &m);

  std::priority_queue<long> q;

  long a;
  for(i=0; i<n; i++){
    scanf("%ld", &a);
    q.push(a);
  }

  for(i=0; i<m; i++){
    a=q.top();
    q.pop();
    a/=2;
    q.push(a);
  }

  long ans=0;
  for(i=0; i<n; i++){
    a=q.top();
    q.pop();
    ans+=a;
  }

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

  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define ll int
ll mod=1e9+7;
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    ll dp[n+1][(1<<n)]={},x[n];
    for(ll i=0;i<(1<<n);i++) dp[0][i]=0;
    dp[0][0]=1;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<(1<<n);j++) dp[i+1][j]=0;
        for(ll j=0;j<n;j++){
            cin>>x[j];
            if(x[j]){
                ll p=((1<<n)-1)-(1<<j);
                for(ll k=p;k>0;k=(k-1)&p){
                    dp[i+1][k+(1<<j)]+=dp[i][k];
                    dp[i+1][k+(1<<j)]%=mod;
                }
                dp[i+1][(1<<j)]+=dp[i][0];
                dp[i+1][(1<<j)]%=mod;
            }
        }
        for(ll j=0;j<(1<<n);j++) dp[i+1][j]+=dp[i][j];
    }
    cout<<dp[n][(1<<n)-1];
}


Measured memory_bytes: 183888
H, W, K = map(int, input().split())
C = []
sum = 0
count = 0
ans = 0
for i in range(H):
    c = input()
    # for j in range(len):
    C.append(c)
    sum += c.count("#")

for h in range(2 ** H):
    for w in range(2 ** W):
        for h2 in range(H):
            if (h >> h2) & 1:
                continue
            for w2 in range(W):
                if (w >> w2) & 1:
                    continue
                if C[h2][w2] == "#":
                    count += 1
        if count == K:
            ans += 1
        count = 0

print(ans)


Measured memory_bytes: 9088
function main(a){
	a = stn(a.split(" "));
	var ss=[];
	ss.push(a[0]*a[1]);
	ss.push(a[2]*a[3]);
	ss.sort(function(a,b){return a-b;});
	console.log(ss[1]);
}
function stn(a){
		return a.map(function(x){return parseInt(x,10);});
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)

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

constexpr int MAXN = 5+1e6;

int p[MAXN],a[MAXN];

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int n; cin >> n;
  multiset<int> s;
  foi (i,0,n) {
    cin >> a[i];
    p[a[i]]++;
  }

  int ans = 0;
  foi (i,0,n) {
    p[a[i]]--;

    bool ok = true;
    int x = a[i];
    for (int i = 1; i*i <= x; ++i) {
      if ((x % i) == 0) {
        int d1 = i, d2 = x/i;
        if (p[d1] || p[d2]) {
          ok = false;
          break;
        }
      }
    }

    if (ok) {
      ans++;
    }

    p[a[i]]++;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 8176
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
 
LL N, A, B, h[112345];
LL low, high, mid;
 
bool check(LL T)
{
	LL res = 0;
	rep(i, N)
	{
		if (h[i] > B*T)
		{
			res += (h[i] - B*T) / (A - B);
			if ((h[i] - B*T) % (A - B) != 0) { ++res; }
		}
	}
	return (res <= T);
}
 
int main()
{
	in >> N >> A >> B;
	rep(i, N) { in >> h[i]; }
 
	low = 0; high = 11234567890LL;
	while (high - low > 1)
	{
		mid = (high + low) / 2;
		if (check(mid)) { high = mid; }
		else { low = mid; }
	}
 
	out << high << std::endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		boolean[] isPrime = Sieve.isPrimeArray(10000);
		int[] max = new int[10001];
		int x = 0;
		for(int i=5;i<=10000;i++) {
			if (isPrime[i] && isPrime[i-2]) {
				x = i;
			}
			max[i] = x;
		}
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			System.out.println((max[n]-2) + " " + max[n]);
		}
	}

}
class Sieve {
	public static boolean[] isPrimeArray(int max) {
		boolean[] isPrime = new boolean[max+1];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for(int i=2;i*i<=max;i++) {
			if (isPrime[i]) {
				int j = i * 2;
				while(j<=max) {
					isPrime[j] = false;
					j += i;
				}
			}
		}
		return isPrime;
	}
}

Measured memory_bytes: 33600
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
 
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <numeric>
#include <time.h>
#include <stack>
#include <bitset>
// #include <any>

#define prev asasddlsa
#define rank aljds

#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i++)
 
using namespace std;
 
typedef long long ll;
typedef double dbl;
 
template<typename T>
void print(const vector<T>& s){
    for (auto x : s)
        cout << x << " ";
    cout << endl;
}
 
template<class T>   
void print(const T* s, int n){
    for (int i = 0; i < n; i++)
        cout << s[i] << ' ';
    cout << endl;
}

template<class T>
void print(vector<vector<T>> s){
    for (int i = 0; i < s.size(); i++)
        print(s[i]);
}

const int maxn = 2e5 + 7;
vector<int> s[maxn];
vector<int> lst[2];
int color[maxn], p[maxn];

void dfs(int v, int h = 0){
    color[v] = 1;
    lst[h].push_back(v);
    for (int u : s[v]){
        if (!color[u])
            dfs(u, h ^ 1);
    }
}

int solve(){
    int n;
    cin >> n;
    for (int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        s[a - 1].push_back(b - 1);
        s[b - 1].push_back(a - 1);   
    }
    dfs(0);
    vector<int> cnt = {n / 3, (n - 1) / 3, (n - 2) / 3 };
    if (lst[0].size() > lst[1].size())
        swap(lst[0], lst[1]);
    if (lst[0].size() <= cnt[0]){
        for (int v : lst[0])
            p[v] = (cnt[0]--) * 3;
        for (int v : lst[1]){
            for (int k = 0; k < 3; k++){
                if ((k > 0 && cnt[k] >= 0) || (k == 0 && cnt[k])){
                    p[v] = (cnt[k]--) * 3 + k;
                    break;
                }
            }
        }
    } else {
        for (int v : lst[0])
            p[v] = cnt[2] >= 0 ? (cnt[2]--) * 3 + 2 : (cnt[0]--) * 3;
        for (int v : lst[1])
            p[v] = cnt[1] >= 0 ? (cnt[1]--) * 3 + 1 : (cnt[0]--) * 3;
    }
    print(p, n);
    return 0;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed; 
    int t = 1;
    // cin >> t;
    while (t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 19828
/*
 * FileName:     List
 * CreatedDate:  2020-06-08 23:11:50 +0900
 * LastModified: 2020-06-09 13:18:33 +0900
 */

#include <stdio.h>
#include <stdlib.h>
typedef struct node{
    struct node *prev,*next;
    int x;
}node;
void print(node *t){
    t=t->next;
    while(t){
        printf("%d\n",t->x);
        t=t->next;
    }
//    printf("\n");
}
node *last_node(node *t){
    while(t->next){
        t=t->next;
    }
    return t;
}
node *insert(node *bottom, node *cursor,int x){
    node *in_node = malloc(sizeof(node));
    in_node->x=x;
    if(!cursor){
        node *last = last_node(bottom);
//        printf("last:%d\n",last->x);
        last->next=in_node;
        in_node->prev=last;
        return in_node;
    }
    if(bottom==cursor){
        bottom->next=in_node;
        in_node->prev=bottom;
        return in_node;
    }
    cursor->prev->next=in_node;
    in_node->prev=cursor->prev;
    cursor->prev=in_node;
    in_node->next=cursor;
    return in_node;
}
node *move(node *bottom,node *cursor,int d){
    if(!cursor&&d>0){
        return NULL;
    }
    if(!cursor&&d<0){
        node *last = last_node(bottom);
        return move(bottom,last,d+1);
    }
    if(d>0){
        for(int i=0;i<d;i++){
            node *s=cursor->next;
            if(!s){
                return NULL;
            }
            cursor=s;
        }
    }
    else if(d<0){
        for(int i=0;i<-d;i++){
            node *s=cursor->prev;
            if(s==bottom){
                return cursor;
            }
            cursor=s;
        }
    }
    return cursor;
}
node *erase(node *bottom,node *cursor){
    if(!cursor){
        return NULL;
    }
    if(cursor==bottom){
        return cursor;
    }
    node *next_cursor;
    cursor->prev->next=cursor->next;
    if(cursor->next){
        cursor->next->prev=cursor->prev;
        next_cursor=cursor->next;
    }
    else{
        next_cursor=NULL;
    }
    cursor->next=NULL;
    cursor->prev=NULL;
    free(cursor);
    cursor=NULL;
    return next_cursor;
}
void free_all(node *t){
    while(t){
        node *tmp = t;
        t=t->next;
        tmp->prev=NULL;
        tmp->next=NULL;
        free(tmp);
        tmp=NULL;
    }
}
void current(node *cursor){
    if(cursor){
        printf("cursor:%d\n",cursor->x);
    }
    else{
        printf("END\n");
    }
}
int main(void){
    int q;scanf("%d",&q);
    node *t = malloc(sizeof(node));
    t->x=0;
    node *bottom=t,*cursor=t;
    int pin=0;
    for(int i=0;i<q;i++){
        int command;scanf("%d",&command);
        if(command==2){
            cursor = erase(bottom,cursor);
//            print(t);
//            current(cursor);
        }
        else{
            int x;scanf("%d",&x);
            if(command==0){
                cursor = insert(bottom,cursor,x);
//                print(t);
//                current(cursor);
            }
            else{
                cursor = move(bottom,cursor,x);
//                print(t);
//                current(cursor);
            }
        }
    }
    print(t);
    free_all(t);
    return 0;
}



Measured memory_bytes: 17280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		int happiness = 0;

		happiness += n / 500 * 1000;
		n = n % 500;

		happiness += n / 5 * 5;

		System.out.println(happiness);

	}

}


Measured memory_bytes: 35744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll x,y;
  cin >> x >> y;
  if(x<y) swap(x,y);
  if(x-y>1) cout <<"Alice" << endl;
  else cout << "Brown" << endl;
  return 0;
    

}


Measured memory_bytes: 256
K, S = [int(x) for x in input().split()]
count = 0
for x in range(K+1):
    # y + z = S - x
    if 0 <= S - x <= K: 
        count += S - x + 1 
        # yに選べるのは0から(y+z)までのy+z-0+1通りすなわちS-x+1
    elif K < S - x <= 2 * K:
        count += 2 * K - S + x + 1 
        # K - ((S - x) - K) + 1
        # excess = (S-x)-K
    else: 
        # S-x > 2Kだと、y+z > 2Kとなり、
        # こうなる組みは存在しない
        continue
print(count)


Measured memory_bytes: 2940
my $min = 0;

MAIN : {
	my $s1 = <STDIN>;
	chomp $s1;
	my ($n, $k) = split(" ", $s1);
	
	
	
	for ($i = 0; $i <= $m; $i++) {
		my $sum = 0;
		foreach my $a (@list) {
			my $ba = $a + 1 - 1;
			my $bm = $i + 1 - 1;
			
			$sum += $ba ^ $bm;
			print STDOUT $ba ^ $bm, " = $a, $i\n";
		}
		push @sumlist, $sum;
	}

	my $max = 0;
	my $b = 0;
	if ($n % 2 eq 1) {
		$max = ($n - 1) / 2 + 1;
	}
	else {
		$max = $n / 2;
	}

	if ($k <= $max) {
		print STDOUT "YES\n";
	}
	else {
		print STDOUT "NO\n";
	}
}

exit 0;
__END__


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int x;
	int y;
	int big;
	int small;
	int tmp;
	scanf("%d%d",&x,&y);
	if(x>y){
		big = x;
		small = y;
	}else{
		big = y;
		small = x;
	}
	while(small != 0){
		tmp = small;
		small = big % small;
		big = tmp;
	}
	cout << big <<endl;
	return 0;
}

Measured memory_bytes: 3172
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    Dist = [10 ** 20] * pow(2, N)
    Dist[0] = 0
    for _ in range(M):
        a, b = map(int, input().split())
        C = [int(c) for c in input().split()]
        binaryC = 0
        for c in C: binaryC += pow(2, c-1)
        for j, d in enumerate(Dist):
            if d < 10 ** 20: Dist[j | binaryC] = min(Dist[j | binaryC], Dist[j] + a)
    print(Dist[-1] if Dist[-1] < 10 ** 20 else -1)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3188
def com(n,r,mod):
    k=min(r,n-r)
    C=1
    for i in range(1,k+1):
        C=(C*(n+1-i)*pow(i,mod-2,mod))%mod
    return C

x, y = map(int,input().split())
mod = 10 ** 9 + 7

m = 2 * x - y
n = 2 * y - x
if m >= 0 and n >= 0 and m % 3 == 0 and n % 3 == 0:
    print(com((n + m) // 3, n // 3, mod))
else:print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <vector>
//const int maxn = 1e5+5;
#define ll long long
#define MAX INT_MAX
#define FOR(i,a,b) for( int i = a;i <= b;++i)

using namespace std;
int n,m,nub,nublater,ans,hhh;
struct node
{
    int ago,later;
}v[110];
//bool cmp(node a,node b)
//{
//
//}
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>v[i].ago;
        ans+=v[i].ago;
    }
    //cout<<ans<<"  ssssssssssssssss"<<endl;
    cin>>m;
    for(int i=1;i<=m;++i)
    {
        cin>>nub>>nublater;
        cout<<ans-(v[nub].ago-nublater)<<endl;

    }




}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;

int main() {
  
  ll n, k;
  cin >> n >> k;
  ll ans = n;
  ll tmp = n % k;
  ll x = tmp - k;
  if(x < 0) x = -x;
  x = min(x,tmp);
  ans = min(x,ans);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  vector<ll> v(6);
  rep(i,6){
    cin>>v[i];
  }
  double max_n=-1;
  ll sugar_water=0,sugar=0;
  rep(i,31){
    rep(j,31){
      rep(k,101){
        rep(l,101){
          if((i+j)==0){
            //pass
          }else{
            if(1.0*(v[2]*k+v[3]*l)/(i*v[0]+j*v[1])>v[4]||100*i*v[0]+100*j*v[1]+v[2]*k+v[3]*l>v[5])continue;
            if((100.0*(v[2]*k+v[3]*l)/(100*i*v[0]+100*j*v[1]+v[2]*k+v[3]*l))>max_n){
              max_n=100.0*(v[2]*k+v[3]*l)/(100*i*v[0]+100*j*v[1]+v[2]*k+v[3]*l);
              sugar=v[2]*k+v[3]*l;
              sugar_water=100*i*v[0]+100*j*v[1]+v[2]*k+v[3]*l;
            }
          }
        }
      }
    }
  }
  cout<<sugar_water<<" "<<sugar<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  ll X; scanf("%lld", &X);
  ll ans = X / 11;
  ans *= 2;
  int m = X % 11;
  if (m > 0) { ++ans; }
  if (m > 6) { ++ans; }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 1 << 21;

struct Node {
	int node, weight, parent;
};

Node forests[100010];
int height[100010];

int findSet(int x) {
	vector<int>tree;
	int sum, i;
	while (forests[x].parent != forests[x].node) {
		tree.push_back(x);
		x = forests[x].parent;
	}
	for (vector<int>::iterator it = tree.begin(); it != tree.end(); it++) {
		sum = 0;
		i = *it;
		while (forests[i].parent != i) {
			sum += forests[i].weight;
			i = forests[i].parent;
		}
		forests[*it].parent = x;
		forests[*it].weight = sum;
	}
	return x;
}

void unite(int x, int y, int z)
{
	int X, Y;
	X = findSet(x);
	Y = findSet(y);
	if (height[X] > height[Y]) {
		forests[Y].parent = X;
		forests[Y].weight = -forests[y].weight + forests[x].weight + z;
	}
	else if (height[X] < height[Y]) {
		forests[X].parent = Y;
		forests[X].weight = -forests[x].weight + forests[y].weight - z;
	}
	else {
		forests[Y].parent = X;
		forests[Y].weight = -forests[y].weight + forests[x].weight + z;
		height[X]++;
	}
}

int main(void)
{
	int n, q, com, x, y, z, X, Y;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		forests[i].node = i;
		forests[i].weight = 0;
		forests[i].parent = i;
	}
	for (int i = 0; i < q; i++) {
		cin >> com;
		if (com) {
			cin >> x >> y;
			X = findSet(x);
			Y = findSet(y);
			if (X == Y)
				cout << forests[y].weight - forests[x].weight << endl;
			else
				cout << "?" << endl;
		}
		else {
			cin >> x >> y >> z;
			X = findSet(x);
			Y = findSet(y);
			if (X == Y)
				continue;
			else
				unite(x, y, z);
		}
	}
	return 0;
}


Measured memory_bytes: 4724
#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 < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()


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

    int N;
    cin >> N;
    string S1, S2;
    cin >> S1;
    cin >> S2;

    if (N == 1) {
        cout << 3 << endl;
        return 0;
    }

    vector<bool> vertical;
    vertical.push_back(S1.at(0) != S1.at(1));
    for (int i = 1; i < N - 1; i++) {
        if (S1.at(i-1) != S1.at(i) && S1.at(i) != S1.at(i+1)) vertical.push_back(true);
        if (S1.at(i) == S1.at(i+1)) vertical.push_back(false);
    }
    if (S1.at(N-2) != S1.at(N-1)) vertical.push_back(true);

    const ll mod = 1e9 + 7;
    ll ans = 3;
    if (!vertical[0]) ans *= 2;
    for (int i = 0; i < vertical.size() - 1; i++) {
        if (vertical[i]) ans = ans * 2 % mod;
        if (!vertical[i] && !vertical[i+1]) ans = ans * 3 % mod;
    }
    cout << ans << endl;
}

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

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

int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  if (a - k >= 0) {
    cout << (a - k) << ' ' << b;
    return 0;
  } else {
    if (b - (k - a) >= 0) {
      cout << 0 << ' ' << (b - (k - a));
    } else {
      cout << 0 << ' ' << 0;
    }
    return 0;
  }
}

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

int main(){
	int N;
	cin >> N;
	if(65 <= N && N <= 90) cout << 1 << endl;
	else if(97 <= N && N <= 122) cout << 2 << endl;
	else cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3108
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >>n;
    int a[n];
    for(int i = 0; i<n; i++){
        cin >>a[i];
    }
    
    for(int j = n-1; j>-1; j--){
        if(j != n-1){
            cout<<" ";
        }cout<<a[j];
    }cout<<endl;
}



Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
	int n; cin >> n;
	vector<int> A(n), T(n);
	vector<int>H(n);
	vector<bool>Hflag(n);

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

	H[0] = A[0]; Hflag[0] = true;
	for (int i = 1; i < n; i++) {
		if (A[i] != A[i - 1]) {
			H[i] = A[i]; Hflag[i] = true;
		}
		else {
			if (A[i] == 1) Hflag[i] = true;
			H[i] = A[i];
		}
	}

	if (Hflag[n - 1] && H[n - 1] != T[n - 1]) {
		cout << 0 << endl;
		return 0;
	}
	H[n - 1] = T[n - 1]; Hflag[n - 1] = true;
	for (int i = n - 2; i >= 0; i--) {
		if (T[i] != T[i + 1]) {
			if (Hflag[i] && H[i] != T[i]) {
				cout << 0 << endl;
				return 0;
			}
			else if (!Hflag[i]&&H[i] < T[i]) {
				cout << 0 << endl;
				return 0;
			}
			H[i] = T[i]; Hflag[i] = true;
		}
		else {
			if (T[i] == 1)if (Hflag[i] && H[i] != T[i]) {
				cout << 0 << endl;
				return 0;
			}
			H[i] = min(H[i], T[i]);
		}
	}

	long long cnt = 1;
	for (int i = 0; i < n; i++) {
		if (!Hflag[i]) {
			cnt *= H[i];
			cnt %= int(1e9 + 7);
		}
	}

	cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 1408
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
  
for i in G[0]:
  for j in G[i]:
    if j == N-1:
      print('POSSIBLE')
      exit()
      
print('IMPOSSIBLE')
  

Measured memory_bytes: 38296
#include<string>
#include<cstdio>
#include<cctype>
#include<iostream>
#include <algorithm>
#include<cmath>
#include<queue>
using namespace std;

int main(){
    int a[8]={0},b[8]={0};
    cin >>a[1]>>a[2]>>a[3]>>a[4];
    a[5]=a[1]+a[2]+a[3]+a[4];
    cin >>b[1]>>b[2]>>b[3]>>b[4];
    b[5]=b[1]+b[2]+b[3]+b[4];
    if(a[5]>b[5])cout <<a[5]<<endl;
    else cout <<b[5]<<endl;
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define MX 1000000
#define pf printf
#define sf scanf
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define db double
#define fl float
#define ii pair <int,int>
#define ff first
#define ss second
#define pb push_back
#define ps push
#define pp pop()
#define tp top()
#define ft front()
#define cl clear()
#define max3(a,b,c) max(a, max(b,c))
#define min3(a,b,c) min(a, min(b,c))
#define SA(name,size) sort(name, name+size)
#define SV(name) sort(name.begin(), name.end())
#define RV(name) reverse(name.begin(), name.end());
#define loop(a,n) for(int i=a; i<n; i++)
#define nloop(j,a,n) for(int j=a; j<n; j++)
#define Case int T; scanf("%d", &T); for(int cas = 1; cas <= T; ++cas)
#define CaseF(n) for(int cas=1; cas<=n; cas++)
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pr(x) cout << x << endl
#define pr2(x,y) cout << x << " " << y << endl
#define prln pf("\n")
using namespace std;

/**------------------------------Graph Moves-----------------------------------*/
/* anti-clockwise, starting from 0 degree */
///int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; // 4 direction
///int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1}; //8 direction
///int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1}; //Knight Direction
///int dx[]={2,1,-1,-2,-1,1}; int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction
/*----------------------------------------------------------------------------*/

int bigmod(int n, int pow, int mod){
    if(pow==0) return 1;
    int x=bigmod(n, pow/2, mod);
    x=((x%mod)*(x%mod))%mod;
    if(pow%2==1) x=((x%mod)*(n%mod))%mod;
    return x;
}

inline int getint(){
    int x;
    scanf("%d",&x);
    return x;
}
#define II getint()

inline long long getlonglong(){
    long long x;
    scanf("%lld",&x);
    return x;
}
#define LL getlonglong()

inline float getfloat(){
    float x;
    scanf("%f",&x);
    return x;
}
#define FF getfloat()

inline double getdouble(){
    double x;
    scanf("%lf",&x);
    return x;
}
#define DB getdouble()

inline string getstring(){
    string s;
    cin>>s;
    return s;
}
#define SS getstring()

/**------------------------------------------------------------------------------------------*/

struct point{
    double x,y;
};

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

    point p1, p2;
    sf("%lf %lf %lf %lf",&p1.x,&p1.y,&p2.x,&p2.y);
    double A = p1.y-p2.y;
    double B = p2.x-p1.x;
    double C = A*p1.x+B*p1.y;
    int q;
    sf("%d",&q);
    while(q--){
        point p;
        sf("%lf %lf",&p.x,&p.y);
        double D = -B*p.x+A*p.y;
        double Det = A*A - (-B*B);
        double x = ( (A*C)-(B*D) ) /Det;
        double y = ( (A*D)-(-B*C) ) /Det;
        pf("%.10lf %.10lf\n",x,y);
    }

    return 0;
}


Measured memory_bytes: 3240
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin >> n;
    ll ans = 0;
    while(n >= 500)
    {
        ans += 1000;
        n -= 500;
    }
    while( n >= 5)
    {
        ans += 5;
        n -= 5;
    }
    cout<< ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int>p(n),q(n);
    REP(i,n)cin >> p[i];
    REP(i,n)cin >> q[i];
    vector<int>r(n);
    REP(i,n){
        r[i]=i+1;
    }
    bool equal_p=false,equal_q = false;
    int count=1,a,b;

    while(!(equal_p && equal_q)){
        bool equal_p_temp = true,equal_q_temp = true;
        REP(i,n){
            if(r[i]!=p[i])equal_p_temp = false;
            if(r[i]!=q[i])equal_q_temp = false;
        }
        if(equal_p_temp){
            equal_p = true;
            a = count;
            //cout << "a=" << count << endl;
        }
        if(equal_q_temp){
            equal_q = true;
            b = count;
            //cout << "b=" << count << endl;
        }
        count++;
       
        next_permutation(ALL(r));
    } 
        
    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
// 1_2_C

#include <iostream>
#include <algorithm>
using namespace std;

int main(){
  int i, a[3];
  for(i = 0; i < 3; i++){
    cin >> a[i];
  }
  sort(a, a+3);
  cout << a[0] << " " << a[1] << " " << a[2] << endl;
  return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;
int main() {
	int N,K,sum = 0;
	cin >> N >> K;
	vector<int> L(N);
	for (int i = 0; i < N;i++) {
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	for (int i = N-1; i > N-K-1;i--) {
		sum += L[i];
	}
	cout << sum << endl;
	return 0;
}



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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")


signed main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k-1] = s[k-1] - 'A' + 'a';
    cout << s << nl;
}


Measured memory_bytes: 256
import math

a,b,H,M=map(int,input().split())

theta_a = math.pi/6 * (H+M/60)
theta_b = math.pi*2*M/60

ans = math.sqrt((b*math.cos(theta_b) - a*math.cos(theta_a))**2 + (b*math.sin(theta_b) - a*math.sin(theta_a))**2)

print(ans)

Measured memory_bytes: 9424
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        char[] c = sc.next().toCharArray();
        int count_r = 0;
        int count_g = 0;
        int count_b = 0;
        for(int i = 0; i < n; i++){
        	if(c[i] == 'R'){
            	count_r++;
            }else if(c[i] == 'G'){
            	count_g++;
            }else{
            	count_b++;
            }
        }
        long ans = (long)count_r * count_g * count_b;
        for(int i = 0; i < n; i++){
        	for(int j = i + 1; j < n; j++){
                int x = j * 2 - i;
            	if(c[i] != c[j] && x < n && c[i] != c[x] && c[j] != c[x]){
                	ans--;
                }
            }
        }
        System.out.println(ans);
	}
}

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

int main() {
    long long a, b, c, d, ans;
    cin >> a >> b >> c >> d;
    ans = max(a*c, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans << endl;
    return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  vector<vector<int>> x(N),y(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    for(int j=0;j<A.at(i);j++){
      int a,b;
      cin>>a>>b;
      x.at(i).push_back(a-1);
      y.at(i).push_back(b);
    }
  }

  int ans=0;

  for(int i=0;i<(1<<N);i++){
    vector<int> honest(N);
    bool flag=true;
    for(int j=0;j<N;j++){
      honest.at(j)=(i>>j)%2;
    }
    for(int j=0;j<N;j++){
      if(honest.at(j)==0){
        continue;
      }
      for(int k=0;k<x.at(j).size();k++){
        if(y.at(j).at(k)!=honest.at(x.at(j).at(k))){
          flag=false;
          break;
        }
      }
      if(!flag){
        break;
      }
    }
    if(flag){
      int aa=0;
      for(int j=0;j<N;j++){
        aa+=honest.at(j);
      }
      ans=max(ans,aa);
    }
  }
  cout<<ans<<endl;
}


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

using namespace std;

#define i64 int64_t
#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1;} return 0;}

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

    i64 n;
    cin >> n;
    vector<i64> A(n), B(n);
    rep(i, n) cin >> A[i];
    rep(i, n) cin >> B[i];

    i64 ans = 0;
    for (int digit = 28; digit >= 0; --digit) {
        i64 cnt = 0;
        for (int i = 0; i < n; ++i) {
            A[i] %= (1LL << digit + 1);
            B[i] %= (1LL << digit + 1); 
        }
        sort(all(B));

        for (int i = 0; i < n; ++i) {
            cnt += lower_bound(all(B), 2LL * (1LL << digit) - A[i]) - lower_bound(all(B), (1LL << digit) - A[i]);
            cnt += lower_bound(all(B), 4LL * (1LL << digit) - A[i]) - lower_bound(all(B), 3LL * (1LL << digit) - A[i]);
        }

        if (cnt % 2) ans += (1LL << digit);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3456
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


template<typename T>
class compress_fn_t {
public:
  void add(T x) {
    if (! map_.count(x))
      map_[x] = 0;
  };

public:
  void clear() {
    map_.clear();
  };

public:
  std::pair<std::map<T, int>, std::vector<T>> get() {
    int size = map_.size(), i = 0;

    std::pair<std::map<T, int>, std::vector<T>> pair;

    pair.second.resize(size);

    for (auto& kv : map_) {
      kv.second = i;

      pair.second[i] = kv.first;

      i ++;
    }

    pair.first = map_;

    return std::move(pair);
  };

private:
  std::map<T, int> map_;
};


template<class T>
class binary_index_tree_t {
public:
  binary_index_tree_t(int size) : size_(size) {
    a_ = new T[size_ + 1];

    memset(a_, 0, sizeof(T) * (size_ + 1));
  };

  ~binary_index_tree_t() {
    delete[] a_;
  };

public:
  void add(int i, int x) {	// a_i += x, 1-index
    assert(i > 0);
    assert(i <= size_);

    for ( ; i <= size_; i += i & -i)
      a_[i] += x;
  };

  T query(int i) {		// a_1 + ... + a_i, 1-index
    assert(i > 0);
    assert(i <= size_);

    T s = 0;

    for ( ; i; i -= i & -i)
      s += a_[i];

    return s;
  };

private:
  T* a_;

  int size_;
};


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, a[222222];

  long long K, acc[222222], x = 0, C = 0;

  std::cin >> N >> K;

  acc[0] = 0;

  compress_fn_t<long long> fn;

  for (int i = 0; i < N; i ++) {
    std::cin >> a[i];
    
    fn.add(acc[i + 1] = a[i] + acc[i] - K);
  }

  auto pair = fn.get();

  binary_index_tree_t<int> bit(pair.first.size());

  for (int i = 0; i < N; i ++) {
    int x = pair.first[acc[i + 1]];

    C += bit.query(x + 1);

    bit.add(x + 1, 1);

    if (acc[i + 1] >= 0)
      C ++;
  }

  std::cout << C << std::endl;

  return 0;
}


Measured memory_bytes: 30080
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
int n,p[111111],x,y,m,ans;
vector<int> g[111111],v;
bool used[111111];
map<int,int> mp;
void dfs(int i)
{
	used[i]=1;
	v.push_back(i);
	for (int j=0;j<g[i].size();j++)
	{
		int to=g[i][j];
		if (used[to]) continue;
		dfs(to);
	} 
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&p[i]);
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);  
	}
	for (int i=1;i<=n;i++)
	{
		if (!used[i])
		{
			v.clear();
			dfs(i);
			mp.clear();
			for (int j=0;j<v.size();j++)
			{
				mp[p[v[j]]]=1;
			}
			for (int j=0;j<v.size();j++)
			{
				if (mp[v[j]]) ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 13560
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int SZ = 200000;
class UF {
public:
	int P[SZ + 1], saidai;
	UF() : P(), saidai() {
		saidai = -1;
		rep1(i, SZ) P[i] = -1;
	}
	int find(int A) {
		if (P[A] < 0) return A;
		return P[A] = find(P[A]);
	}
	bool unite(int A, int B) {
		int a = find(A);
		int b = find(B);
		if (a == b) return false;
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		if (P[a] < saidai) saidai = P[a];
		P[b] = a;
		return true;
	}
} uf;

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

	int N = getint(), M = getint();

	rep(i, M) {
		uf.unite(getint(), getint());
	}

	printf("%d\n", -uf.saidai);


	Would you please return 0;
}

Measured memory_bytes: 2504
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n;
   ll d;
   cin >> n >> d;

   vector<ll> x(n), y(n);
   rep(i, 0, n) cin >> x[i] >> y[i];
   int ans = 0;
   rep(i, 0, n) {
      if (x[i] * x[i] + y[i] * y[i] <= d * d) ans++;
   }
   cout << ans << endl;
   return 0;
}

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

int Hekomi(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {

	double A, B, C;
	A = (x2 - x1)*(y4 - y1) - (y2 - y1)*(x4 - x1);
	B = (x3 - x2)*(y4 - y2) - (y3 - y2)*(x4 - x2);
	C = (x1 - x3)*(y4 - y3) - (y1 - y3)*(x4 - x3);
	if ((A > 0 && B > 0 && C > 0) || (A < 0 && B < 0 && C < 0))
		return 0;
	else
		return 1;
}

int main() {

	double x1, x2, x3, x4, y1, y2, y3, y4;
	char a;
	vector<int> TF;

	while (cin >> x1 >> a  >> y1 >> a >> x2 >> a >> y2 >> a >> x3 >> a >> y3 >> a >> x4 >> a >> y4) {
		TF.push_back(1);
		if (Hekomi(x1, y1, x2, y2, x3, y3, x4, y4) == 0) {
			TF.pop_back(); 
			TF.push_back(0);
		}
		if (Hekomi(x1, y1, x2, y2, x4, y4, x3, y3) == 0){
			TF.pop_back(); 
			TF.push_back(0);
		}
		if (Hekomi(x1, y1, x4, y4, x3, y3, x2, y2) == 0){
			TF.pop_back(); 
			TF.push_back(0);
		}
		if (Hekomi(x4, y4, x2, y2, x3, y3, x1, y1) == 0){
			TF.pop_back(); 
			TF.push_back(0);
		}
		
	}
	for (int i = 0; i < TF.size(); i++) {
		if (TF[i])cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	long long int map[100][21] = {0} ;
	
	int* intarray = new int[n];

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

	map[0][intarray[0]] = 1;
	for(int i=0;i<n-2;i++){
		for(int j=0;j<21;j++){
			if(map[i][j] != 0){
				if(j+intarray[i+1] <= 20){
					map[i+1][j+intarray[i+1]] += map[i][j];
				}
				if(j-intarray[i+1] >= 0){
					map[i+1][j-intarray[i+1]] += map[i][j];
				}
			}
		}
	}
	
	cout << map[n-2][intarray[n-1]] << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	
	int rema,remb,remc;
	cin>>rema>>remb>>remc;
//	cout<<"rema= "<<rema<<" remb= "<<remb<<" remc= "<<remc<<endl;
	for(int i=1;i<n;i++)
	{
		int a,b,c;
	cin>>a>>b>>c;
	int a1=rema,b1=remb,c1=remc;
	rema=a+max(b1,c1);
	remb=b+max(a1,c1);
	remc=c+max(b1,a1);
	//cout<<"rema= "<<rema<<" remb= "<<remb<<" remc= "<<remc<<endl;
	}
	cout<<max(rema,max(remb,remc));

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
using namespace std;
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define fill(x, y)     memset(x, y, sizeof(y))
#define all(x)         (x).begin(), (x).end()
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  double a[n+1];
  for (int i = 1; i <= n; i++) {
      cin >> a[i];
  }
  double dp[n+1][n+1];
  for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
          dp[i][j] = 0;
      }
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= i; j++) {
          if (j > 0) dp[i][j] += dp[i-1][j-1]*a[i];
          dp[i][j] += dp[i-1][j] * (1-a[i]);
      }
  }
  double ans = 0;
  for (int j = 0; j <= n; j++) {
      if (j > (n / 2)) ans += dp[n][j];
  }
  cout.precision(10);
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 74076
#include <vector>
#include <functional>
using namespace std;

template <typename T, typename Op = plus<T>>
class segtree {
private:
    size_t N;
    vector<T> data;
    T idelem;
    const Op &op;

public:
    segtree(size_t n, T idelem, const Op &op = Op())
    : idelem(idelem), op(op) {
        for(N = 1; N < n; N <<= 1);
        data = vector<T>(2 * N, idelem);
    }

    segtree(const vector<T> &init, T idelem, const Op &op = Op())
    : idelem(idelem), op(op) {
        for(N = 1; N < init.size(); N <<= 1);
        data = vector<T>(2 * N, idelem);
        for(int i = 0; i < init.size(); ++i) data[i + N] = init[i];
        for(int i = N - 1; i >= 0; --i) data[i] = op(data[2 * i], data[2 * i + 1]);
    }

    void update(size_t pos, T val) {
        data[pos + N] = val;
        for(pos = (pos + N) / 2; pos > 0; pos >>= 1) {
            data[pos] = op(data[2 * pos], data[2 * pos + 1]);
        }
    }

    T query(size_t left, size_t right) {
        left += N;
        right += N;

        T vl = idelem, vr = idelem;
        while(left < right) {
            if(left & 1) vl = op(vl, data[left++]);
            if(right & 1) vr = op(data[right - 1], vr);
            left >>= 1;
            right >>= 1;
        }
        return op(vl, vr);
    }

    T operator[](size_t k) {
        return data[k + N];
    }
};


#include <iostream>
using namespace std;

int main() {
    int n, q; cin >> n >> q;
    //segtree<int> st(n, 0);
    auto vec = vector<int>(n, 0);
    segtree<int> st(vec, 0);

    while(q--) {
        int c, x, y; cin >> c >> x >> y;
        if(c == 0) {
            st.update(x, st[x] + y);
        } else {
            cout << st.query(x, y + 1) << endl;
        }
    }
}


Measured memory_bytes: 4136