akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std ;
	#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	#define lli long long int
	#define ulli unsigned long long int
	#define ff first
	#define ss second
	#define mp make_pair
	#define pb push_back
	#define pf pop_front()
	#define lb lower_bound
	#define ub upper_bound
	#define bs binary_search
	#define rep(i,a,b) for(lli i=a;i<b;i++)
	#define repe(i,a,b) for(lli i=a;i<=b;i++)
	#define all(v) v.begin(), v.end()
	#define mod 1000000007
	#define inf 100000000000000000
	#define lld long double
	#define pll pair<long long int,long long int>
	#define pii pair<int,int>
	#define vll vector<lli>
	#define vii vector<int>
	#define endl '\n'
	#define pie  acosl(-1.0);
	#define setp(k, x) fixed << setprecision(k) << (x)
	#define deb(x) cerr << #x << ": " << x << " " << endl;
	#define debug(x) cout << "m here-" <<#x<<" ..."<<"\n";
	#define printa(a,n) for(lli i=0;i<n;i++) cout<<a[i]<<" "; cout<<"\n";
  #define printv(a) for(lli i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<"\n";
	bool sortcol( const vector<lli>& v1, const vector<lli>& v2 ) //sort on basis of column //use- sort(vect.begin(), vect.end(),sortcol);
      { return v1[1] < v2[1]; }//[] o based indexing in column
	bool sortpair(const pair<lli, lli> &a, const pair<lli, lli> &b)
			{return a.second < b.second;}
	struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

//////////////////////////////////////////////////////////////////////////////////////////////
void solve();
//////////////////////////////////////////////////////////////////////////////////////////////


int main ()
{
	// fastio
// 	lli  t;
 //	cin>>t;
 	//while(t--)
 	{
	solve();

 	}
}
///////////////////////////////////////////
void solve()
{
	lli n,i,d,a,b,c,j,k,w;

  cin>>n>>w;
  lli wt[n],val[n];
  for(i=0;i<n;i++)
  {
    cin>>wt[i]>>val[i];
  }
  lli dp[n+1][w+1];
  for(i=0;i<n+1;i++)
  {
    dp[i][0]=0;
  }

  for(i=0;i<w+1;i++)
  {
    dp[0][i]=0;
  }
  for(i=1;i<=n;i++)
  {
    for(j=1;j<=w;j++)
    {

      if(wt[i-1]<=j)
      {
        dp[i][j]= max(val[i-1]+(dp[i-1][j-wt[i-1]]),(dp[i-1][j]));

      }
      else
        dp[i][j]=dp[i-1][j];
    }
  }

  // for(i=0;i<n;i++)
  //   for(j=0;j<w;j++)
  //     cout<<dp[i][j]<<" ";
  cout<<dp[n][w]<<"\n";



}


Measured memory_bytes: 79104
import itertools
import bisect
n = int(input())
s = input()
listR = []
listG = []
listB = []
counter = 0
for i in range(len(s)):
    if s[i] == "R":
        listR.append(i)
    elif s[i] == "G":
        listG.append(i)
    elif s[i] == "B":
        listB.append(i)

listB = sorted(listB)
def binary_search_loop(data, target):
    imin = 0
    imax = len(data)-1
    while imin <= imax:
        imid = imin + (imax - imin) // 2
        if target == data[imid]:
            return True
        elif target < data[imid]:
            imax = imid -1
        else:
            imin = imid + 1
    return False
for bits in itertools.product(listR, listG):
    diff = max(bits) - min(bits)
    remover = 0
    if sum(bits) % 2 == 0:
        mid = int(sum(bits) / 2)
    else:
        mid = 1000000
    if binary_search_loop(listB, max(bits) + diff):
        remover += 1
    if binary_search_loop(listB, min(bits) - diff):
        remover += 1
    if binary_search_loop(listB, mid):
        remover += 1
    counter += (len(listB) - remover)
print(counter)

Measured memory_bytes: 73824
#include <bits/stdc++.h>
#define reps(i,j,k) for(int i=j;i<k;++i)
#define rep(i,j) reps(i,0,j)
#define fr first
#define sc second
#define fs fr
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef long long ll;

vi graph[30];
char memo[1<<24];
vi C;
int n;

int solve(int bit, char cnt){
	if(memo[bit]) return memo[bit];
	int res = cnt;
	rep(i,n){
		reps(j,i+1, n){
			if (bit & (1<<i) | bit & (1<<j) | (C[i] != C[j])) continue;
			int bbb = bit | (1 << i) | (1 << j);
			bool f = false;
			rep(k,graph[i].size()){
				int t = graph[i][k];
				if(!(bit & (1<<t))) {f = true; break;}
			}
			rep(k,graph[j].size()){
				int t = graph[j][k];
				if(!(bit & (1<<t))) {f = true; break;}
			}
			if(f) continue;
			res = max(res, solve(bbb, cnt + 2));
		}
	}
	return memo[bit] = res;
}

int main(){

	while(cin >> n,n){
		rep(i,30){
			graph[i].clear();
		}
		vi X(n),Y(n),R(n);
		C.resize(n);
		fill(memo, memo + (1<<24), 0);
		rep(i,n){
			int x,y,r,c;
			cin >> x >> y >> r >> c;	
			X[i] = x;
			Y[i] = y;
			R[i] = r;
			C[i] = c;
			rep(j,i){
				if((X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]) < (R[i]+R[j])*(R[i]+R[j])){
					graph[i].pb(j);
				}
			}
		}

		cout << solve(0,0) << endl;

	}
	return 0;
}

Measured memory_bytes: 19352
#include <bits/stdc++.h>
    using namespace std;
    
    vector<vector<long>> adj;
    long n, m;
    long ans = 0;
    
    void dfs(long bit , long next){
        bit = bit | (1 << next);
        if(__builtin_popcountl(bit) >= n){
            ans += 1;
            return;
        }
        for(int i = 0 ; i < adj[next].size() ; i++){
            if( !((bit >> adj[next][i]) & 1) )
                dfs(bit , adj[next][i]);    
        }
        
        return;
    }

    int main(){
      
      long a , b;
      cin >> n >> m;
      //vector<vector<long>> adj;
      for(int i = 0 ; i < n ; i++ ){
          vector<long> a;
          adj.push_back(a);
      }
      for(int i = 0 ; i < m ; i++ ){
          cin >> a >> b;
          adj[a - 1].push_back(b -1);
          adj[b - 1].push_back(a -1);
      }
      dfs(0 , 0);
      
      cout << ans << endl;
      
      return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    ll n; cin>>n;
    ll a[n];
    ll m1 = 0, m2 = 0;
    for(ll i=0; i<n; i++){
        ll tmp; cin>>tmp;
        a[i] = tmp;
        if(m1 < tmp){
            m2 = m1;
            m1 = tmp;
        }
        else if(m2 < tmp)
            m2 = tmp;
    }
    for(ll i=0; i<n; i++){
        if(a[i] == m1)
            OUT(m2);
        else
            OUT(m1);
    }
}

Measured memory_bytes: 3200
def main():
    from collections import defaultdict
    import sys
    
    s = input()
    t = input()
    ds = defaultdict(int)
    di = {}

    for i in range(len(s)):
        di[i] = defaultdict(int)
    
    for a in s:
        ds[a] = 1
        
    flag = 0
    for b in t:
        if ds[b] == 0:
            flag = 1
    if flag == 1:
        print(-1)
        sys.exit()

    s2 = s[::-1]
    for i in range(2*len(s)):
        for j in di[len(s) - (i-1)%len(s)-1]:
            di[len(s) - i%len(s)-1][j] = di[len(s) - (i-1)%len(s)-1][j] + 1
        di[len(s) - i%len(s) - 1][s2[(i-1)%len(s)]] = 1
    tmp = t[0]

    for k in range(len(s)):
        if tmp == s[k]:
            answer = k+1
            break
    for k in range(len(t)-1):
        l = k+1
        answer += di[(answer-1)%len(s)][t[l]]
        tmp = t[l]
    print(answer)
      

if __name__ == '__main__':
    main()

Measured memory_bytes: 441984
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    int B[N-1];
    for(int i = 0; i < N-1; i++){
        cin >> B[i];
    }
    int A[N];
    A[N-1] = B[N-2];
    for(int i = N-2; i >= 1; i--){
        A[i] = min(B[i],B[i-1]);
    }
    A[0] = B[0];
    int ans = 0;
    for(int i = 0; i < N; i++){
        ans += A[i];
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 100005

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

int A[SIZE],B[SIZE];
int mx[SIZE];
ll sum[SIZE];
int cnt[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		B[i]=A[i];
	}
	for(int i=0;i<n;i++)
	{
		mx[i]=0;
		if(i>0) mx[i]=max(mx[i-1],A[i-1]);
	}
	sort(B,B+n);
	int now=0;
	for(int i=0;i<n;i++)
	{
		if(mx[i]>=A[i]) puts("0");
		else
		{
			ll sum=0;
			while(now<n&&B[now]<=A[i])
			{
				sum+=B[now]-mx[i];
				now++;
			}
			sum+=(ll) (n-now)*(ll) (A[i]-mx[i]);
			printf("%lld\n",sum);
		}
	}
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;

int main() {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for (ll i = 0; i < n; i++) {
        ll p;
        cin >> p;
        p--;
        a[i] = p;
    }
    ll now = 0;
    vector<ll> route;
    map<ll, ll> visited;
    route.push_back(now);
    visited[now]++;
    ll distone;
    ll loop;
    while (true) {
        ll next = a[now];
        now = next;
        route.push_back(now);
        visited[now]++;
        if (visited[now]==2){
            auto itr = find(route.begin(), route.end(), now);
            auto itr2 = find(itr+1, route.end(), now);
            distone = distance(route.begin(), itr); 
            loop = distance(itr, itr2);
            break;
        }
    }
    ll t = (long long)route.size();

    if (k < t)
        cout << route[k] + 1 << endl;
    else
        cout << route[distone + (k - distone) % loop] + 1 << endl;
}


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


using namespace std;


int main() {
    float n = 0, m = 0;
    cin >> n >> m;
    float x = 0;
    float sum = 0;
    vector<float> items(n);
    for(int i = 0; i < n; i++){
        cin >> items[i];
        sum += items[i];
    }
    float k = 1/(4*m);
    k = k * sum;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(items[i] >= k){
            cnt++;
        }
        if(cnt >= m){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;


    return 0;
}

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

int readInt(){
  int ret = 0;
  char c;
  while((c=getchar()) && '0' <= c && c <= '9'){
    ret = ret * 10 + (c-'0');
  }
  return ret;
}

main(){
  int n,s;
  while(true){
    n = readInt();
    s = readInt();
    if (n==0)break;
    int r[101]={0};
    for(int i=0;i<n;i++){
      int tmp;tmp=readInt();r[tmp]++;
    }
    int ans = 0;
    for(int i=0;i<101;i++){
      if (i+i > s && r[i])ans += (r[i]*(r[i]-1))/2;
      for(int j=i+1;j<101;j++){
	if (i+j > s)ans += r[i]*r[j];
      }
    }
    printf("%d\n",ans);
  }
}

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

int main()
{
    string S;
    cin >> S;
    int N = S.size();
    
    int res = 0;
    
    // 0101... にする場合
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0 && S[i] == '1') {
            cnt++;
        }
        if (i % 2 == 1 && S[i] == '0') {
            cnt++;
        }
    }
    res = cnt;

    // 1010... にする場合
    cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0 && S[i] == '0')
        {
            cnt++;
        }
        if (i % 2 == 1 && S[i] == '1')
        {
            cnt++;
        }
    }
    res = min(res, cnt);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    int c1=0,c2=0;
    cin>>a>>b>>c>>d;
    while(c>0)
    {
        c=c-b;
        c1++;
    }
    while(a>0)
    {
        a=a-d;
        c2++;
    }
    if(c2>=c1)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

int main()
{
  int a, b, c, d, p;
  int res1, res2;

  cin >> a >> b >> c >> d >> p;
  if (c < p){
    res1 = b + ((p - c) * d);
  }
  else {
    res1 = b;
  }
  res2 = a * p;
  cout << min(res1, res2) << endl;
  return (0);
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main() {
    int n, a[100];
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++){
        if(i == n){
            cout << a[0];
            continue;
        }
        cout << a[n-i] << ' ';
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N, M; std::cin >> N >> M;
  int L = 1, R = N;
  for(int i = 0; i < M; ++i) {
    int Li, Ri; std::cin >> Li >> Ri;
    L = std::max(L, Li);
    R = std::min(R, Ri);
  }
  fin(std::max(0, R-L+1));
  return 0;
}


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

using namespace std;

int main() {
	int n, team[101] = { 0 }, a, b, c, d, rank;
	cin >> n;

	for (int i = 0; i < n * (n - 1) / 2; i++) {
		cin >> a >> b >> c >> d;
		c == d ? team[a]++, team[b]++ : (c > d ? team[a] += 3 : team[b] += 3);
	}

	for (int i = 1; i <= n; i++) {
		rank = 1;
		for (int j = 1; j <= n; j++) {
			team[i] < team[j] ? rank++ : NULL;
		}
		cout << rank << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
# t=int(input())
# for _ in range(t):
    # n,m=map(int,stdin.readline().split())
A=[2,4,5,7,9]
B=[0,1,6,8]
n=input()
a=int(n[-1])
if(a in A):
    print("hon")
elif(a in B):
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9488
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  string s, t;
  cin >> s >> t;
  cout << t + s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    int n = get<int>(), x = get<int>();
    vector<int> l(n);
    for (int i = 0; i < n; i++)
        l[i] = get<int>();

    int d = 0;
    int count = 1;
    for (int i = 0; i < n; i++) {
        d = d + l[i];
        if (d <= x)
            count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
long long a[5];
int main(){
	long long n;
	long long ans=0;
	scanf("%lld%lld%lld%lld",&a[1],&a[2],&a[3],&a[4]);
	scanf("%lld",&n);
	for (int i=1;i<4;i++){
		int cnt=1;
		for (int j=i+1;j<=4;j++){
			cnt*=2;
			if (a[i]*cnt<a[j]) a[j]=a[i]*cnt;
		}
	}
	ans+=(n/2)*a[4];
	ans+=(n%2)*a[3];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG




int main() {
  ll N;
  cin >> N;
  //vector<ll> a(N);
  //vector<vector<int>> data(3, vector<int>(4));

ll ans = 1000 - (N % 1000);
if(ans == 1000){
  ans = 0;
}

  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  string t,T;
  cin >> n;
  ll a=0,b=n;
  cout << a << endl;
  cin >> t;
  while(t!="Vacant"){
    ll m=(a+b)/2;
    cout << m << endl;
    cin >> T;
    if(((T!=t)&&(a-m)%2==0)||((T==t)&&(a-m)%2!=0)){
      b=a;
    }
    a=m;
    t=T;
  }
}


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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    while(n--){
        int x,y;
        cin >> x >> y;
        ans += y-x+1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[]args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//????¨????
		int sum = 0;
		//n????????????
		int n = sc.nextInt();
		//???????????????
		int m = sc.nextInt();
		//A??????????????£?¨? ??? m
		int [][] A = new int [n][m];
		//B??????????????£?¨?
		int [] B = new int[m];
		//A???????´?
		for(int i = 0; i< n; i++){
			for(int j =0; j<m;j++){
				A [i][j] = sc.nextInt();
				//System.out.println(A[i][j]);
			}
		}
		//B???????´?
		for(int i = 0; i < m; i++){
			B[i] = sc.nextInt();
		}
		//??¨???
		for(int i = 0; i< n; i++){
			//??????????????????
			sum =0;
			for(int j =0; j<m;j++){
				sum +=A[i][j] * B[j];
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 40784
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setbitc(x) __builtin_popcount(x)
#define init(x,a) memset(x,a,sizeof(x))
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
ll n,m,k,ar[N],br[N];
string s,s1;
//Variables End

ll sub(ll a, ll b){return (a-b+MOD)%MOD;}
ll add(ll a, ll b){return (a+b)%MOD;}
ll mul(ll a, ll b){return (a*b)%MOD;}

int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
		//cin>>n;
		cin>>s>>m;
		n=s.length();

		vector<vi> dp(m,vi(2,0));
		dp[0][0]=1;
		rep(pos,0,n){
			vector<vi> new_dp(m,vi(2,0));
			ll val=s[pos]-'0';
			rep(mod,0,m){
				
				rep(i,0,val){
					new_dp[(mod+i)%m][1]=add(new_dp[(mod+i)%m][1],dp[mod][0]);
				}
				rep(i,0,10){
					new_dp[(mod+i)%m][1]=add(new_dp[(mod+i)%m][1],dp[mod][1]);
				}

				new_dp[(mod+val)%m][0]=add(new_dp[(mod+val)%m][0],dp[mod][0]);
			}

			dp=new_dp;
		}        


		cout<<sub(add(dp[0][1],dp[0][0]),1)<<endl;
    }
    return 0;
        
}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  int N, K;
  in(N, K);
  vector<int> s(N);

  rep(i, 0, N) {
    int pi;
    in(pi);
    s[i] = (i == 0 ? 0 : s[i - 1]) + pi;
  }
  int mx = 0;
  rep(i, K - 1, N) {
    mx = max(mx, s[i] - s[i - K]);
  }
  printf("%.12f\n", (mx + K) / 2.0);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  int r,s,p;
  string t;
  cin >> n  >> k;
  cin >> r >> s >> p;
  cin >> t;
  int i;
  long ans = 0;
  for(i=0;i<k;i++){
    if(t[i]=='r')ans+=p;
    else if(t[i]=='s')ans+=r;
    else ans += s;
  }
  for(i=k;i<n;i++){
    if(t[i]!=t[i-k]){
      if(t[i]=='r')ans+=p;
      else if(t[i]=='s')ans+=r;
      else ans += s;
    }else{
      t[i] = 'u';
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	int h, w, n;
	char[][] b;
	
	int[] dx = {0, 0, 1, -1};
	int[] dy = {1, -1, 0, 0};
	boolean delete() {
		boolean[][] check = new boolean[h][w];
		boolean flag = false;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (b[i][j] != '.') {
					char c = b[i][j];
					int count;
					for (int k = 0; k < 4; k++) {
						count = 1;
						while (0 <= i+count*dx[k] && i+count*dx[k] < h && 0 <= j+count*dy[k] && j+count*dy[k] < w && c == b[i+count*dx[k]][j+count*dy[k]])
							count++;
						if (count >= n) {
							flag = true;
							for (int l = 0; l < count; l++) {
								check[i+l*dx[k]][j+l*dy[k]] = true;
							}
						}
					}
				}
			}
		}
		
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				if (check[i][j])
					b[i][j] = '.';
		
		return flag;
	}
	
	void fall() {
		for (int i = 0; i < h-1; i++) {
			for (int j = 0; j < w; j++) {
				if (b[i][j] != '.' && b[i+1][j] == '.') {
					char[] temp = new char[i+1];
					for (int k = 0; k < i+1; k++) 
						temp[k] = b[k][j];
					int count = 1;
					while (i+count+1 < h && b[i+count+1][j] == '.') count++;
					for (int k = 0; k < count; k++) {
						b[k][j] = '.';
					}
					for (int k = 0; k < i+1; k++) {
						b[count+k][j] = temp[k];
					}
				}
			}
		}
	}
	
	boolean isDeleted(char[][] map) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				b[i][j] = map[i][j];
			}
		}
		
		fall();
		while (delete()) {
			fall();
		}
		
		boolean flag = true;
		
		I:for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (b[i][j] != '.') {
					flag = false;
					break I;
				}
			}
		}
		
		return flag;
	}
	
	void run() {
		h = sc.nextInt(); w = sc.nextInt(); n = sc.nextInt();
		char[][] map = new char[h][w];
		b = new char[h][w];
		sc.nextLine();
		for (int i = 0; i < h; i++) {
			String s = sc.nextLine();
			for (int j = 0; j < w; j++) {
				map[i][j] = s.charAt(j);
			}
		}
		
		boolean flag = false;
		I:for (int i = 0; i < h; i++) {
			for (int j = 0; j < w-1; j++) {
				if (map[i][j] != map[i][j+1]) {
					char temp = map[i][j];
					map[i][j] = map[i][j+1];
					map[i][j+1] = temp;
					if (isDeleted(map)) {
						flag = true;
						break I;
					}
					temp = map[i][j];
					map[i][j] = map[i][j+1];
					map[i][j+1] = temp;
				}
			}
		}
		if (flag) out.println("YES");
		else out.println("NO");
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 24584
#include <stdio.h>
int main(){

  int n, b, f, r, v, i, j;
  int a[5][4][11];

  for(b = 1; b <= 4; b++){
    for(f = 1; f <= 3; f++){
      for(r = 1; r <= 10; r++){
	a[b][f][r] = 0;
      }
    }
  }

  scanf("%d", &n);
  for(i = 1; i <= n; i++){
    scanf("%d %d %d %d", &b, &f, &r, &v);
    a[b][f][r] = v + a[b][f][r];
  }

  for(b = 1; b <= 4; b++){
    for(f = 1; f <= 3; f++){
      for(r = 1; r <= 10; r++){
	printf(" %d", a[b][f][r]);
      }
      printf("\n");
    } 
     for(j = 0; j < 20 && b != 4; j++){
      printf("#");
      }
    if(b != 4){
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 600
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define e1 first
#define e2 second
#define int int_fast32_t
#define uint uint_fast64_t
#define ll int_fast64_t
#define ull uint_fast64_t
#define int16 int_fast16_t
#define uint16 uint_fast16_t
#define int32 int_fast32_t
#define uint32 uint_fast32_t
#define int64 int_fast64_t
#define uint64 uint_fast64_t
#define ld long double
#define float long double
#define size(x) (int)x.size()
#define satori int testCases; cin>>testCases; while(testCases--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(r) begin(r),end(r)
#define rall(r) rbegin(r),rend(r)
#define time chrono::high_resolution_clock().now().time_since_epoch().count()
#define elapsed(__begin,__end) (__end-__begin)/CLOCKS_PER_SEC
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
float pi=3.14159265358979323846;

int32_t main()
{
	fastio;
	int n;
	cin>>n;
	if(n<=599)
		cout<<8;
	else
	if(n<=799)
		cout<<7;
	else
	if(n<=999)
		cout<<6;
	else
	if(n<=1199)
		cout<<5;
	else
	if(n<=1399)
		cout<<4;
	else
	if(n<=1599)
		cout<<3;
	else
	if(n<=1799)
		cout<<2;
	else
		cout<<1;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#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 forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}


int main()
{
	fast

	int n;
	cin>>n;

	cout<<fixed<<setprecision(10);
	vector<double> v(n);

	forn(i,0,n)
	{
		cin>>v[i];
	}

	sort(all(v));

	double sum = 0;

	sum += v[0];

	forn(i,1,n)
	{
		sum += v[i];
		sum = sum/double(2);
	}

	cout<<sum;

	return 0;
}

Measured memory_bytes: 256
n = int(raw_input())
a = map(int,raw_input().split(" "))

ans = []
aa = sorted(a)

if aa[0] < 0 and aa[n-1] > 0:
  bt = aa[0]
  up = aa[n-1]
  if abs(bt) > abs(up):
    r = a.index(bt)
    for x in range(n):
      if x != r:
        a[x] += bt
        ans.append([r+1,x+1])
  else:
    r = a.index(up)
    for x in range(n):
      if x != r:
        a[x] += up
        ans.append([r+1,x+1])

aa = sorted(a)

if aa[0] == aa[n-1]:
  print 0
  exit()

if aa[0] >= 0: # all plus!
  for x in range(n-1):
    a[x+1] += a[x]
    ans.append([x+1,x+2])
elif aa[n-1] <= 0: # all minus!
  for x in range(n-2,-1,-1):
    a[x] += a[x+1]
    ans.append([x+2,x+1])

print len(ans)
for q in ans:
  print "%d %d" % (q[0],q[1])



Measured memory_bytes: 2696
#include <iostream>

#define rep(i, first, to) for(ll i = first; i < to; ++i)
#define REP(i, first, to) for(ll i = first; i <= to; ++i)

using namespace std;
typedef long long ll;

int n;
int a[101];
void show(int *p) {
	rep(i, 0, n - 1) {
		cout << p[i] << " ";
	}
	cout << p[n - 1] << endl;
}

void solve() {
	cin >> n;
	rep(i, 0, n) {
		cin >> a[i];
	}
	show(a);
	int v;
	rep(i, 1, n) {
		v = a[i];
		int j = i - 1;
		for (; j >= 0 && a[j] > v; --j) {
			a[j + 1] = a[j];
		}
		a[j + 1] = v;
		show(a);
	}
}

int main() {
	solve();
	return 0;
}

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

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    
    vector<int> B(n + 1, 0), W(n + 1, 0);
    for(int i = 0; i < n; i++){
        B[i + 1] += B[i] + (s[i] == '#');
        W[i + 1] += W[i] + (s[i] == '.');
    }

    int mini = 1e9;
    for(int i = 1; i < n + 1; i++){
        mini = min(mini, B[i - 1] + W[n] - W[i - 1]);
    }

    cout << min(mini, B[n]) << endl;

    return 0;
}

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

using namespace std;

static void FirstChangeDirection(int startIndex, const string &input, int &time, int &index, char &direction)
{
    auto firstDirection = input[startIndex];
    int t = 0;
    auto position = startIndex;
    auto delta = (input[position] == 'R') ? 1 : -1;

    while (true)
    {
        position += delta;
        t++;
        auto newDirection = input[position];
        if (newDirection != firstDirection)
        {
            time = t;
            index = position;
            direction = newDirection;
            return;
        }
    }
}

int main()
{
    string input;
    cin >> input;
    auto size = input.size();
    auto childCounts = vector<int>(size, 0);
    int time = -1;
    int index = -1;
    char direction = ' ';
    for (int i = 0; i < size; i++)
    {
        if (i > 0 && input[i] == input[i - 1])
        {
            if (time % 2 == 0 && direction == 'L' && index > 0)
            {
                childCounts[index - 1]++;
                time++;
                continue;
            }
            if (time % 2 == 0 && direction == 'R' && index < size - 1)
            {
                childCounts[index + 1]++;
                time++;
                continue;
            }
            if (time % 2 == 1 && direction == 'L' && index < size - 1)
            {
                childCounts[index + 0]++;
                time++;
                continue;
            }
            if (time % 2 == 1 && direction == 'R' && index > 0)
            {
                childCounts[index - 0]++;
                time++;
                continue;
            }
        }
        FirstChangeDirection(i, input, time, index, direction);
        int finalIndex = -1;
        if (time % 2 == 0)
        {
            finalIndex = index;
        }
        else
        {
            if (direction == 'L')
            {
                finalIndex = index - 1;
            }
            else
            {
                finalIndex = index + 1;
            }
        }
        childCounts[finalIndex]++;
    }
    for (auto count : childCounts)
    {
        cout << count << " ";
    }
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {   if (y & 1)
        res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main()
{
	IOS;
  	ll n;
  cin>>n;
  ll x=(n/500)*1000;
  ll y=((n-(n/500)*500)/5)*5;
  cout<<x+y<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define swap(X , Y) {int Z ; Z = Y ; Y = X , X = Z}

int main(void)
{
	int a , b , c , i , end;
	
	scanf("%d %d %d" , &a , &b , &c);
	for( i = a ; i <= b ; i++)
	{
		if(c % i == 0)
		{
			end++;
		}
	}
	printf("%d\n" , end);
	
	return 0;
} 


Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int n; cin >> n;
    cout << (n+1)/2;
}


Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,w,p,q;
    ans=0;
    string s,s1,s2;
    vector<int> v;
   cin>>n;
   rep(i,1,n+1){
       rep(j,1,n+1){
           rep(k,1,n+1){
               m=i;
               p=j;
               q=k;
               int t=p;
               while(p){
                   t=m%p;
                   m=p;
                   p=t;
               }
               
               while(m){
                   t=q%m;
                   q=m;
                   m=t;
               }
               ans+=q;
           }
       }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3624
s=[ord(c) for c in input()]
t=[ord(c) for c in input()]
n=len(s)
st=[(s[i],t[i]) for i in range(n)]
st=sorted(st,key=lambda x:x[0])
s=[c for c,_ in st]
t=[c for _,c in st]

for i in range(n-1):
    if (s[i]==s[i+1]) ^ (t[i]==t[i+1]):
        print('No')
        exit(0)

st=sorted(st,key=lambda x:x[1])
s=[c for c,_ in st]
t=[c for _,c in st]

for i in range(n-1):
    if (s[i]==s[i+1]) ^ (t[i]==t[i+1]):
        print('No')
        exit(0)


print('Yes')

Measured memory_bytes: 130040
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n,A,B;
    cin >> n >> A >> B;
    string s;
    cin >> s;
    int cnt = 0;
    int bcnt = 0;
    rep(i,n){
        if(s[i] == 'a' && cnt < A+B){
            cout << "Yes" << endl;
            cnt++;
            continue;
        }
        if(s[i] == 'b' && cnt < A+B && bcnt < B){
            cout << "Yes" <<  endl;
            cnt++;
            bcnt++;
            continue;
        }
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define se second
#define Mod 1000000007


 
int main(){
    ll i,j;
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    ll dp[n+1][k+1];
    for(i=0;i<=n;i++){
        for(j=0;j<=k;j++){
            dp[i][j]=0;
        }
        dp[i][0]=1;
    }
    
 
    for(i=1;i<=n;i++){
        for(j=1;j<=k;j++){
            if(j-a[i]-1>=0) {
                dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-a[i]-1]+Mod;
            } else{
                dp[i][j]=dp[i][j-1]+dp[i-1][j];
            }
            dp[i][j]%=Mod;
        }
    }
    cout<<dp[n][k]<<endl;
 
   
    return 0;
}



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

int main(){
  int A;
  int B;
  int T;
  cin >> A >> B >> T;
  
  int ans =0;
  int time = 0;
  time =(T+0.5)/A;
  
  ans = time * B;
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
N = int(input().rstrip())
l = [0 for i in range(N)]

vl = [int(i) for i in input().rstrip().split()]
for i in range(len(vl)):
    j = vl[i] - 1
    l[j] = l[j] + 1

for i in range(N):
    print(l[i])


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

int main() {
  int A, B;
  cin >> A >> B;
  
  if (A <= 5) {
    cout << 0 << endl;
  }
  else if (5 < A && A < 13) {
    cout << B / 2 << endl;
  }
  else {
    cout << B << endl;
  }
}

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

using namespace std;

int input () { int x; cin >> x; return x; }

int main () {
  int N, count;
  vector<int> L;

  cin >> N;

  for (int i = 0; i < N; i++) L.push_back(input());

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

  for (auto ib = L.end() - 1; ib >= L.begin(); ib--) {
    for (auto ia = ib - 1; ia >= L.begin(); ia--) {
      auto ic_upper_limit = lower_bound(ib, L.end(), *ia + *ib);
      count += distance(ib, ic_upper_limit) - 1;
    }
  }

  cout << count << "\n";
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int MAXN = 100010;
const int INF = 1000000000;
const int MOD = 1000000007;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

int n;
char s[1111];

bool check()
{
	if (s[1] != 'A') return false;
	int cnt = 0;
	for (int i = 3; i <= n-1; ++ i)
		if (s[i] == 'C') cnt ++;
	if (cnt != 1) return false;
	bool flag = true;
	for (int i = 2; i <= n; ++ i)
		if (!('a' <= s[i] && s[i] <= 'z'))
			if (s[i] != 'C') flag = false;
	return flag;
}

int main()
{
	
	scanf("%s", s+1);
	n = strlen(s+1);
	puts(check() ? "AC" : "WA");
	
	return 0;
}


Measured memory_bytes: 256
N = int(input())
hs = list(map(int, input().split()))
costs = [0] * N
costs[0] = 0
costs[1] = abs(hs[1]-hs[0])
for i in range(2, N):
  costs[i] = min(costs[i-1]+abs(hs[i]-hs[i-1]),
                 costs[i-2]+abs(hs[i]-hs[i-2]))
print(costs[N-1])

Measured memory_bytes: 13928
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
#define rep_re(i,s,n)for(int i = n;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_M = 100001;

ll a[100001] = {};

//unite x and y : p[uf(x)] = uf(y)
//same x and y : uf(x) == uf(y)
static const ll MAX_N = 100001;
ll p[MAX_N] = {};
ll uf(ll i) {
	if (p[i] == i) return i;
	return p[i] = uf(p[i]);
}
void init_uf() { rep(i, 1, MAX_N)p[i] = i; }

int main() {
	ll n, m; cin >> n >> m;
	repe(i, 1, n) {
		cin >> a[i];
	}
	init_uf();
	rep(i, 0, m) {
		ll x, y; cin >> x >> y;
		if (uf(x) != uf(y))p[uf(x)] = uf(y);
	}
	ll ans = 0;
	repe(i, 1, n)if (uf(i) == uf(a[i]))ans++;
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
const int N=50,zqm=1e9+7;
int n;
struct mat {
	int d[N][N];
	int* operator[](const int k) {return d[k];}
	const int* operator[](const int k) const {return d[k];}
	mat(bool isunit=0) {
		memset(d,0,sizeof(d));
		if(isunit) for(int i=0;i<n;++i) d[i][i]=1;
	}
	mat operator*(const mat &rhs) const {
		mat ret;
		for(int k=0;k<n;++k) {
			for(int i=0;i<n;++i) if(d[i][k]) {
				for(int j=0;j<n;++j) (ret[i][j]+=(d[i][k]*1ll*rhs[k][j])%zqm)%=zqm;
			}
		}
		return ret;
	}
}a,b;

int main() {
	//freopen("1.in","r",stdin);
	//freopen("1.ans","w",stdout);
	
	ll k; scanf("%d%lld",&n,&k);
	for(int i=0;i<n;++i) {
		for(int j=0;j<n;++j) scanf("%d",&a[i][j]);
	}
	b=mat(1);
	for(;k;k/=2,a=a*a) if(k&1) b=b*a;
	int ans=0;
	for(int i=0;i<n;++i) {
		for(int j=0;j<n;++j) (ans+=b[i][j])%=zqm;
	}
	printf("%d\n",ans);
	
	return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N,x;
    string S;
    cin >> N>>x;

    vector<ll> a(N);
    REP(i,N){
        cin >> a.at(i);
    }

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

    ll ans = 0;

    REP(i,N){
        x -= a.at(i);
        ans++;
        if(i==N-1){
            if(!(x==0)){
                ans--;
                break;
            }
        }
        if(x==0){
            break;
        }
        else if(x<0){
            ans--;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#define lol(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,a[110],cnt[110];
int main(){
  cin>>n;
  lol(i,n)cnt[i]=0;
  int maxi=0;
  lol(i,n){
    cin>>a[i];
    cnt[a[i]]++;
    maxi=max(maxi,a[i]);
  }
  bool ok=true;
  for(int i=0;i<(maxi+1)/2;i++)if(cnt[i]>0)ok=false;
  if(maxi%2==0&&cnt[(maxi+1)/2]!=1)ok=false;
  if(maxi%2==1&&cnt[(maxi+1)/2]!=2)ok=false;
  for(int i=(maxi+1)/2+1;i<=maxi;i++)if(cnt[i]<2)ok=false;
  cout<<(ok?"Possible":"Impossible")<<endl;;
  return 0;
}


Measured memory_bytes: 256
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
d = [k - (a[1] - a[0])]
a[0] += k
for i in range(1, n - 1):
    d.append(k - (a[i + 1] - a[i]))
d.append(k + (a[n - 1] - a[0]))
print(min(d))


Measured memory_bytes: 26444
n, m = map(int, input().split())
L = {}
for _ in range(n):
    a, b = map(int, input().split())
    if a not in L:
        L[a] = b
    else:
        L[a] += b
ans = 0
L = sorted(L.items())
for i in L:
    if i[1] >= m:
        ans += i[0] * m
        break
    else:
        m -= i[1]
        ans += i[0] * i[1]
print(ans)


Measured memory_bytes: 22996
n = int(input())
a = list(map(int, input().split()))
flag = 1
count = 0
i = 0
while flag:
    flag = 0
    for j in reversed(range(i+1,n)):
        if a[j] < a[j-1]:
            c = a[j]
            a[j] = a[j-1]
            a[j-1] = c
            flag = 1
            count += 1
    i += 1

b = [str(i) for i in a]
print(" ".join(b))
print(count)


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

using namespace std;


void solve() {
    int x,y,z;
    cin >> x >> y >> z;
    int res = min(x+y+1, z) + y;
    cout << res;
}

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


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
using namespace std;
int main() {
  int a,b,c,d,e;
  int f = 0;
  int g = 0;
  int h = 0;
  int i = 0;
  int j = 0;
  int sum = 0;
  int maxv = 0;
  cin >> a >> b >> c >> d >> e;
  if((a%10) != 0){
    f = ((a/10) + 1)*10 - a;
  }
  if((b%10) != 0){
    g = ((b/10) + 1)*10 - b;
  }
  if((c%10) != 0){
    h = ((c/10) + 1)*10 - c;
  }
  if((d%10) != 0){
    i = ((d/10) + 1)*10 - d;
  }
  if((e%10) != 0){
    j = ((e/10) + 1)*10 - e;
  }
  sum = a + b + c + d + e + f + g + h + i + j;
  maxv = max({f,g,h,i,j});
  cout << sum - maxv << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,m,ans=0;
	cin >> n;
	string s[1000];
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	cin >> m;
	for(int i=n;i<n+m;i++){
		cin >> s[i];
	}
	for(int i=0;i<n;i++){
		long long a=0;
		for(int j=i;j<n+m;j++){
			if(j<n){
				if(s[i]==s[j]){
					a++;
				}
			}else if(j>=n){
				if(s[i]==s[j]){
					a--;
				}
			}
		}
		if(a>ans){
			ans=a;
		}
	}
	cout << ans << endl;
  	return 0;
}


Measured memory_bytes: 256
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>

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

    ll x, y;
    cin >> x >> y;

    if (y > x) {
        swap(x, y);
    }

    if (y == 0 && x <= 1) {
        cout << "Brown\n";
        return 0;
    }

    if (x - y <= 1) {
        cout << "Brown\n";
    } else {
        cout << "Alice\n";
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define BLACK 0
#define WHITE 1
#define INF 100000000
#define NIL -1

void prim(void);

int A[N][N],n;

int main()
{
  int i,j;
  int cnt = 0;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d",&A[i][j]);
    }
  }

  prim();

  return 0;
}

void prim(){

  int u,v,i,mincost,sum=0;
  int d[N],pi[N],color[N];

  for(u = 0; u < n; u++){
    d[u] = INF;
    pi[u] = NIL;
    color[u] = WHITE;
  }

  d[0] = 0;

  while(1){
    mincost = INF;
    for(i = 0; i < n; i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == INF) break;

    color[u] = BLACK;
  
    for(v = 0; v < n; v++){
      if(color[v] != BLACK && A[u][v] < d[v] && A[u][v] != -1){
	pi[v] = u;
	d[v] = A[u][v];
      }
    }
  
  }
  for(u = 0; u < n; u++){
  sum += d[u];
  }
  printf("%d\n",sum);
}

Measured memory_bytes: 636
#include <iostream>

using namespace std;

int main( void ){
  int i,j;
  
  for(i = 1;i <= 9;i++){
    for(j = 1;j <= 9;j++){
      cout << i << "x" << j << "=" << i*j << endl;
    }
  }
  return 0;
}

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

int main() {
    int n, w[110];
    int sum = 0;

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

    int mini = sum;
    int s1 = 0, s2;
    for (int i = 0; i < n; i++) {
        s1 += w[i];
        s2 = sum - s1;
        mini = min(mini, abs(s1 - s2));
    }
    
    cout << mini << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(void){
    int i,flag;
    char s[4];
    flag = 0;

    scanf("%s",s);

    for(i=0; i<3; i++){
        if(s[i]==s[i+1]){
            flag = 1;
            break;
        }
    }

    if(flag == 1){
        printf("Bad\n");
    }else{
        printf("Good\n");
    }

    return 0;
}

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	vector<int> A;
	
	A.push_back(a);
	A.push_back(b);
	A.push_back(c);

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

	cout << A[0] + A[1] << endl;
}




Measured memory_bytes: 3596
import collections
n=int(input())
l=list(map(int, input().split()))
q=int(input())
s=sum(l)
d=collections.Counter(l)
for i in range(q):
    a,b=map(int, input().split())
    s=s-(a*d[a])
    s=s+(b*d[a])
    d[b]=d[b]+d[a]
    d[a]=0
    print(s)

Measured memory_bytes: 23968