akhauriyash/Code-Regression huggingface dataset:
#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,k;
  cin >> n >> k;
  vector<P> p(n);
  rep(i,n){
    cin >> p[i].first >> p[i].second;
  }
  sort(p.begin(),p.end());
  ll cnt=0;
  ll ans;
  ll i=0;
  while(cnt<k){
    cnt +=p[i].second;
    ans=p[i].first;
    i++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
import string
small_letter = string.ascii_lowercase
letter_to_int = dict()
int_to_letter = dict()
counter = 0
for i in small_letter:
    letter_to_int[i] = counter
    int_to_letter[counter] = i
    counter += 1
n = int(input())
sol_vec = [[0 for i in range(26)] for j in range(2)]
tmp = input()
for j in tmp:
    sol_vec[0][letter_to_int[j]] += 1
for i in range(n-1):
    tmp = input()
    for j in tmp:
        if sol_vec[0][letter_to_int[j]] > 0:
            sol_vec[1][letter_to_int[j]] += 1
    for j in range(26):
        if sol_vec[1][j] < sol_vec[0][j]:
            sol_vec[0][j] = sol_vec[1][j]
        sol_vec[1][j] = 0
ans_string = ""
for i in range(26):
    ans_string +=  int_to_letter[i] * sol_vec[0][i]
print(ans_string)

Measured memory_bytes: 3768
N, M = map(int, input().split())
nn = 500500
P = 10 ** 9 + 7
fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % P

C = lambda a, b: fa[a] * fainv[b] % P * fainv[a-b] % P if 0 <= b <= a else 0
PP = lambda a, b: fa[a] * fainv[a-b] % P if 0 <= b <= a else 0

ans = 0
for i in range(N + 1):
    ans = (ans + C(N, i) * PP(M - i, N - i) * (-1) ** i) % P
    
print(ans * PP(M, N) % P)

Measured memory_bytes: 48472
#include<iostream>
using namespace std;
int main(){
	int n, i, p, ans=0;
	double sum;
	cin>>n;
	int num[n];
	for(int i=0;i<n;i++){
		cin>>num[i];
		sum+=num[i];
	}
	p=sum/n+0.5;
	for(int i=0;i<n;i++){
		ans+=(p-num[i])*(p-num[i]);
	} 
	cout<<ans;
} 

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut ab: Vec<(i64, i64)> = (0..n)
        .map(|_| {
            let a = input();
            let b = input();
            (a, b)
        })
        .collect();
    let mut cd: Vec<(i64, i64)> = (0..n)
        .map(|_| {
            let c = input();
            let d = input();
            (c, d)
        })
        .collect();
    ab.sort();
    cd.sort();

    let mut ans = 0;
    for (c, d) in cd {
        let mut k = -1;
        for i in 0..ab.len() {
            if (ab[i].0 < c && ab[i].1 < d) && (k < 0 || ab[k as usize].1 < ab[i].1) {
                k = i as i64;
            }
        }
        if k >= 0 {
            ans += 1;
            ab.remove(k as usize);
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
inputs = list(map(int, input().split()))
max = []

if inputs[0] > inputs[1]:
    max.append(inputs[0])
    inputs[0] = inputs[0] - 1
else:
    max.append(inputs[1])
    inputs[1] = inputs[1] - 1

if inputs[0] > inputs[1]:
    max.append(inputs[0])
    inputs[0] = inputs[0] - 1
else:
    max.append(inputs[1])
    inputs[1] = inputs[1] - 1

print(max[0]+max[1])
               

 


Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <functional>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif

// 二乗を計算する。
ll sq(ll x) { return x * x; }

// 領域内にいるか。
bool within(ll x, ll min, ll max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T& container, typename T::key_type& key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
ll modpow(ll b, ll e, ll m) {
	ll result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}


// ここから解法

int main(void) {
	ll A, B;
	cin >> A >> B;
	ll sum = A + B;
	if (sum % 2 == 0) {
		cout << (sum / 2) << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
/*     *******************Bismillahir Rahmanir Rahim************************
                          **************************
                          #    MD. ASFAKUL GHANI   #
                          #       *ProMAGFAT*      #
                          #         CSE-25         #
                          #JAHANGIRNAGAR UNIVERSITY#
                          #    Dhaka,Bangladesh    #
                          &&&&&&&&&&&&&&&&&&&&&&&&&#
*/

#include <bits/stdc++.h>
using namespace std;

#define fasterIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define Im int main()
#define ll long long
#define sc scanf
#define pf printf
#define rn0 return 0
#define rn return
#define f0(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define f2(i,n) for(ll i=n-1;i>=0;i--)
#define pi 2*acos(0.0)
#define modulo 1000003
#define dd double
#define PI 3.14159265358979
#define pi 2*acos(0.0)
#define p_b push_back
#define ps push

/*
ll for_binarySearch(ll a,ll b,ll aa[],ll x){while(a<=b){ll mid=(a+b)/2;if(aa[mid]==x) return 1;else if(aa[mid] > x) b=mid-1;else a=mid+1;}return -1;}
ll for_gcd(ll a,ll b){if(a==0) return b;else return for_gcd(b%a,a);}
ll for_prime(ll x){for (ll i=2;i*i<=x;i++){if(x%i==0) return 0;}return 1;}
void for_swap(char *x,char *y){char temp;temp=*x;*x=*y;*y=temp;}
ll for_big_mod(ll b,ll p,ll m){if(p==0) return 1;else if(p%2==0){ll k=for_big_mod(b,p/2,m);return (k*k)%m;}else return ((b%m)*(for_big_mod(b,p-1,m)))%m;}
ll for_josephus(ll n,ll k){if(n==1) return 1;return (for_josephus(n-1,k)+k-1)%n+1;}
ll for_gcdExtended(ll a,ll b,ll *x,ll *y){if(a==0){*x=0;*y=1;return b;}ll x1,y1;ll gcd=for_gcdExtended(b%a,a,&x1,&y1);*x=y1-(b/a)*x1;*y=x1;return gcd;}
*/


Im
{
    //fasterIO;

    ll n;
    cin>>n;
    ll a1[n+5];
    for (ll i=0; i<n; i++) cin>>a1[i];

    ll c=0;
    for (ll i=0; i<n; ){
        bool f=1;
        if (a1[i]==a1[i+1]&&i<n-1){
            c++; f=0;
        while (a1[i]==a1[i+1]&&i<n-1) i++;
        }
        if (a1[i]<a1[i+1]&&i<n-1){
            if (f)
            c++;
            while (a1[i]<=a1[i+1]&&i<n-1) i++;
        }
        else if (a1[i]>a1[i+1]&&i<n-1) {
            if (f)
            c++;
            while (a1[i]>=a1[i+1]&&i<n-1) i++;
        }
        else c++;
        //cout << i << " " << c << endl;
        i++;
    }

    cout << c << endl;

   // main();

    rn0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int dx = abs(c-a), dy = abs(d-b);
    if(dx == 0 || dy == 0){
        cout << 0 << "\n";
    }else {
        int g = __gcd(dx, dy);
        cout << (dx/g+dy/g-1)*g << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
N, Q = map(int,input().split()) # 複数の数字を変数に格納
List_ab = [list(map(int,input().split())) for i in range(N-1)] # [[1,2],[3,4],[5,6]]
List_px = [list(map(int,input().split())) for i in range(Q)] # [[1,2],[3,4],[5,6]]

count_list = [0]*N

List_ab.sort()

for i in range(Q):
    count_list[List_px[i][0]-1] += List_px[i][1]
        
for i in range(N-1):
    count_list[List_ab[i][1]-1] += count_list[List_ab[i][0]-1]
    
print(*count_list)

Measured memory_bytes: 113532
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
const long double PI = acos(-1);
using namespace std;
int main (){
    int a, b; 
    cin >> a >> b;
    while(a!=0&&b!=0){
        for(int i=0; i<a; i++){
             for(int j=0; j<b; j++){
                 cout << "#";
             }
            cout << endl;
        }
        cout << endl;
        cin >> a >> b;
    }
    return 0;
}


Measured memory_bytes: 3088
#define ONLINE_JUDGE
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>
#include <iterator>
#include <map>
#include <set>
#ifndef ONLINE_JUDGE
#include <prettyprint/prettyprint.hpp>
#endif

#define FOR(i, n) for(int i = 0; i < n; ++i)
#define TEST int T; std::cin >> T; while(T--)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vll = std::vector<ll>;
using vull = std::vector<ull>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

const int mod = 1e9 + 7;

void add(int &a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}

void sub(int& a, int b) {
	a += b;
	if(a < 0) a += mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	ifstream fin("in.txt");
	ofstream fout("out.txt");
	auto cinbuf = cin.rdbuf(fin.rdbuf());    // save and redirect
	auto coutbuf = cout.rdbuf(fout.rdbuf()); // save and redirect
#endif	
	int n;
	cin >> n;
	int a[n][n];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> a[i][j];
		}
	}
	vector<int> dp(1 << n);
	dp[0] = 1;
	for (int b = 0; b < (1 << n) - 1; ++b) {
		int i = __builtin_popcount(b);
		for(int j = 0; j < n; ++j) {
			if(a[i][j] && !(b & (1 << j))) {
				add(dp[b ^ (1 << j)], dp[b]);
			}
		}
	}
	cout << dp[(1 << n) - 1] << endl;
#ifndef ONLINE_JUDGE
	cin.rdbuf(cinbuf);    // restore
	cout.rdbuf(coutbuf); // restore
#endif	
}


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

using namespace std;

long long int n, m;

const long long MOD = 1000000007;


int main() {
   cin >> n >> m;
  
       if(abs(n-m) <= 1){ 
         cout << "Brown" << endl;
       }
     else{
       cout << "Alice" << endl;
     }
}
                         
       


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

                    
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if((A==B)&&(A!=C) || (B==C)&&(A!=B) || (A==C)&&(B!=C)) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    }


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;
  int ans=0;
  if(n%2==0){
    int m=n/2;
    rep(i,m){
      if(s[i]!=s[i+m])ans++;
    }
  }
  else ans++;
  if(ans==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    // std::cout << std::fixed << std::setprecision(10);
    int k, x; std::cin >> k >> x;
    for(int i=-k+1; i<k; i++)
    {
        if(x+i<-1000000) continue;
        else if(1000000<x+i) continue;
        std::cout << x + i << std::endl;
    }
    return 0;
}

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

int main()
{
  char c;
  scanf("%c",&c);
  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
  {
    cout<<"vowel"<<endl;
    return 0;
  }
  else
  {
    cout<<"consonant"<<endl;
    return 0;
  }
}

Measured memory_bytes: 256
//omajinai
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
//omajinai

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    cin >> n;
    int a = 1,b = n;

    int ans;

    for(int i = 1;i <= sqrt(n);i ++){
        int m = n;
        if(n % i == 0){
            m /= i;
            string s = to_string(m);
            ans = s.size();
        }
    }

    cout << ans << endl;

    
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = 998244353;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;
const int P = 1000;

int n;
vector<int> g[3][N];

bool read(){
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n) forn(j, 3)
		g[j][i].clear();
	forn(j, 3){
		int m;
		scanf("%d", &m);
		forn(i, m){
			int v, u;
			scanf("%d%d", &v, &u);
			--v, --u;
			if (v > u) swap(v, u);
			g[j][v].pb(u);
		}
	}
	return true;
}

int add(int a, int b){
	a += b;
	if (a >= MOD)
		a -= MOD;
	return a;
}

int mul(int a, int b){
	return a * li(b) % MOD;
}

int gr[3][N];
int cnt[3][P];
int pw[N];

int calc(int i, int v){
	if (gr[i][v] != -1)
		return gr[i][v];
	vector<int> tmp;
	for (auto u : g[i][v])
		tmp.pb(calc(i, u));
	sort(all(tmp));
	tmp.resize(unique(all(tmp)) - tmp.begin());
	forn(j, sz(tmp)) if (tmp[j] != j)
		return gr[i][v] = j;
	return gr[i][v] = sz(tmp);
}

void solve() {
	memset(gr, -1, sizeof(gr));
	memset(cnt, 0, sizeof(cnt));
	pw[0] = 1;
	pw[1] = INF64 % MOD;
	fore(i, 2, N) pw[i] = mul(pw[i - 1], pw[1]);
	forn(j, 3) forn(i, n) cnt[j][calc(j, i)] = add(cnt[j][calc(j, i)], pw[i + 1]);
	int ans = 0;
	forn(i, P) forn(j, P) if ((i ^ j) < P && cnt[0][i] && cnt[1][j] && cnt[2][i ^ j])
		ans = add(ans, mul(mul(cnt[0][i], cnt[1][j]), cnt[2][i ^ j]));
	printf("%d\n", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if(read()) {
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 14208
#include<iostream>

using namespace std;

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

	if (D == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	else if (D == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (D == 24) {
		cout << "Christmas Eve" << endl;
	}
	else if (D == 25) {
		cout << "Christmas" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<map>
#include<set>
#define int long long int
#define mod 1000000007
int function(string &str1,string &str2,int initial,int final,int memo[][4][4],int status1,int status2)
{
	if(initial>final)
	    return 1;
	if(memo[initial][status1][status2]!=-1)
	    return memo[initial][status1][status2];
	else
	{
		if(str1[initial]==str2[initial])
		{
			int i;
			int answer=0;
			for(i=1;i<4;i++)
			{
				if(i!=status1&&i!=status2)
				{
					answer+=function(str1,str2,initial+1,final,memo,i,i);
					answer=answer%mod;
				}
			}
			memo[initial][status1][status2]=answer;
			return memo[initial][status1][status2];
		}
		else
		{
			int i,j;
			int answer=0;
			for(i=1;i<4;i++)
			{
				for(j=1;j<4;j++)
				{
					if(i!=j&&i!=status1&&j!=status2)
					{
						answer+=function(str1,str2,initial+2,final,memo,i,j);
						answer=answer%mod;
					}
				}
			}
			memo[initial][status1][status2]=answer;
			return memo[initial][status1][status2];
		}
	}
}
int32_t main()
{
     int n;
     cin>>n;
     int j,arr[n];
     int count[100002]={0};
     for(j=0;j<n;j++)
     {
		 cin>>arr[j];
		 count[arr[j]]++;
	 }
	 int answer=0;
	 answer=count[0]+count[1];
	 for(j=1;j<=100000;j++)
	 {
		 answer=max(answer,count[j-1]+count[j]+count[j+1]);
	 }
	 cout<<answer<<endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
template<typename T> using Graph = vector<vector<T>>;

struct edge { int to, cap, rev; };

const int MAX_V = 100;
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, int cap) {
    G[from].emplace_back((edge){to, cap, (int)G[to].size()});
    G[to].emplace_back((edge){from, 0, (int)G[from].size() - 1});
}

void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (int i = 0; i < G[v].size(); i++) {
            edge &e = G[v][i];
            if (e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

int dfs(int v, int t, int f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[v] < level[e.to]) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        bfs(s);
        if (level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        int f;
        while ((f = dfs(s, t, inf)) > 0) {
            flow += f;
        }
    }
}

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

    int V, E;
    cin >> V >> E;
    rep(i, E) {
        int a, b, c;
        cin >> a >> b >> c;
        add_edge(a, b, c);
    }
    cout << max_flow(0, V - 1) << endl;
}

Measured memory_bytes: 3260
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let s: Vec<char> = itr.next().unwrap().chars().collect();
    let t: Vec<char> = itr.next().unwrap().chars().collect();


    let mut num = Vec::new();
    let mut i = 0;
    while i < n {
        if i + 1 < n && s[i] == s[i + 1] && t[i] == t[i + 1] {
            num.push(2);
            i += 2;
        } else {
            num.push(1);
            i += 1;
        }
    }

    let mut ans = if num[0] == 1 { 3u64 } else { 6u64 };
    for i in 1..num.len() {
        if num[i - 1] == 1 {
            ans <<= 1;
        } else if num[i] == 2 {
            ans *= 3;
        }
        ans %= 1_000_000_007;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }

const vector<string> s3 = {
    "aab",
    "c.b",
    "cdd"
};

const vector<string> s[] = {
{
    "aabc",
    "ddbc",
    "efgg",
    "efhh"
},
{
    "abbcc",
    "a.dee",
    "ffdgg",
    "hij..",
    "hij.."
},
{
    "aabcc.",
    "d.b..e",
    "dff..e",
    "g..hhi",
    "g..j.i",
    ".kkjll"
},
{
    ".aa.bbc",
    "d..e..c",
    "d..e..f",
    ".gg.hhf",
    "i..j..k",
    "i..j..k",
    "llmmnn."
}
};

int main() {
    int N;
    cin >> N;
    vector2d<char> ans = vector2d<char>(N, vector<char>(N, '.'));
    int k = 0;
    auto push_ans = [&](const vector<string> &v) -> void {
        int n = v.size();
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                ans[i + k][j + k] = v[i][j];
            }
        }
    };
    if(N <= 2) {
        cout << -1 << endl;
        return 0;
    }
    if(N == 3) {
        push_ans(s3);
    } else {
        while(N - k >= 8) {
            push_ans(s[0]);
            k += 4;
        }
        push_ans(s[N % 4]);
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 2176
n = int(input())
ns = list(map(int, input().split()))
one = ns.count(1)
two = ns.count(2)
three = n-one-two
dp = [[[0 for _ in range(n+1)] for _ in range(two+three+1)] for _ in range(three+1)]
for k in range(three+1):
    for j in range(two+three-k+1):
        for i in range(n-j-k+1):
            v = k+i+j
            if v==0:
                continue
            res = n
            if i:
                res += i * dp[k][j][i-1]
            if j:
                res += j * dp[k][j-1][i+1]
            if k:
                res += k * dp[k-1][j+1][i]
            dp[k][j][i] = res / v
print(dp[three][two][one])


Measured memory_bytes: 501896
N, K = map(int, input().split())
h = []
for i in range(N):
	h.append(int(input()))
h.sort()
minimum = 1e10
for i in range(N-K+1):
	if minimum > h[i+K-1] - h[i]:
		minimum = h[i+K-1] - h[i]
print(minimum)


Measured memory_bytes: 7384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int main(){
    int n; cin>>n;
    string x; cin>>x;
    int d; cin>>d;

    vector<bool> used(n, false);
    for(int i=0; i<n; i++){
        if(d <= 0) break;

        if(x[i] == '0'){
            x[i] = '1';
            used[i] = true;
            d--;
        }
    }

    for(int i=n-1; i>=0; i--){
        if(d <= 0) break;

        if(x[i] == '1' && !used[i]){
            x[i] = '0';
            d--;
        }
    }

    cout << x << endl;
}


Measured memory_bytes: 3220
def left_child(i):
    if 2*i >= len(L):
        return 0
    else :
        return int(2*i)

def right_child(i):
    if 2*i+1 >= len(L):
        return 0
    else :
        return int(2*i + 1)
        
N=int(input())
L=list(map(int,input().split()))
L = [-3000000000]+L
    
H = int(N/2)
for h in range(H ,0,-1):
    while True:

        l_c = left_child(h)
        r_c = right_child(h)

        L_h=L[h]
        L_l_c=L[l_c]
        L_r_c=L[r_c]

        if L[l_c] > L[r_c] and L[l_c] > L[h]:
            L[h] = L_l_c
            L[l_c] = L_h
            h = l_c

        elif L[l_c] < L[r_c] and L[r_c] > L[h]:
            L[h] = L_r_c
            L[r_c] = L_h
            h = r_c

        else:
            break
L=L[1:]
L=['']+L
print(' '.join(map(str,L)))


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

int main() {
  int n, k;
  cin >> n >> k;
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    double tmp = 1.0 / n;
    int now = i;
    while (now < k) {
      now *= 2;
      tmp /= 2;
    }
    ans += tmp;
  }
  printf("%.13f", ans);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>

using namespace std;

map<char,long long> mp;

int main ()
{
    long long n,i;
    long long res=0;
    string s;

    cin>>n;

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

    res=(long long)mp['R']*mp['C']*mp['H']+mp['A']*mp['C']*mp['H']+mp['M']*mp['C']*mp['H']+mp['A']*mp['R']*mp['H']+mp['M']*mp['R']*mp['H']+mp['M']*mp['A']*mp['H']+mp['A']*mp['R']*mp['C']+mp['M']*mp['R']*mp['C']+mp['M']*mp['A']*mp['C']+mp['M']*mp['A']*mp['R'];

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(){
  int n_takoyaki;
  scanf("%d", &n_takoyaki);
  
  int *oishisa;
  oishisa = (int *)malloc(sizeof(int)*n_takoyaki);
  
  int i;
  for(i=0; i<n_takoyaki; i++){
    scanf("%d", &oishisa[i]);
  }
  
  int sum = 0;
  int j;
  for(i=0; i<n_takoyaki; i++){
    for(j=i+1; j<n_takoyaki; j++){
      sum += oishisa[i]*oishisa[j];
    }
  }
  printf("%d", sum);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+7;
const int maxm = 2e5+7;
const ll mod = 998244353;

int n,m,ar[maxn];
char ch[maxn];
int main()
{
    int a,b,c,d;
    scanf("%d", &n);
    scanf("%d%d%d%d",&a,&b,&c,&d);
    scanf("%s", ch+1);
    bool flag=1;
    if(d>c){
        while(a!=c || b!=d){
            if(a>n || b>n)break;
            if(b!=d){
                if(d<=b+2)b=d;
                else if(ch[b+2]=='.')b+=2;
                else if(ch[b+1]=='.')b++;
                else{
                    flag=0;
                    break;
                }
            }
            else{
                if(c<=a+2)a=c;
                else if(ch[a+2]=='.')a+=2;
                else if(ch[a+1]=='.')a++;
                else{
                    flag=0;
                    break;
                }
            }
        }
    }
    else{
        while(a!=c || b!=d){
            //cout<<a<<" "<<b<<endl;
            if(a>n || b>n)break;
            if(a!=c){
                if(c<=a+2 && b!=c){
                    a=c;
                    continue;
                }
                else if(ch[a+2]=='.' && b!=a+2){
                    a+=2;
                    continue;
                }
                else if(ch[a+1]=='.' && a+1!=b){
                    a++;
                    continue;
                }
            }
            if(b==d){
                flag=0;
                break;
            }
            if(ch[b+1]=='.' && a!=b+1)b++;
            else if(ch[b+2]=='.' && a!=b+2)b+=2;
            else{
                flag=0;
                break;
            }
        }
    }
    if(a!=c || b!=d)flag=0;
    printf("%s\n", flag?"Yes":"No");
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define sz(v) (int)(v).size()
#define vec(x) vector < x >
using vi = vector < int >;
using vvi = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
using int64 = long long;
//const int64 biGinf = 9e+18;
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
const char nwl = '\n';

int main() {
// #ifndef ONLINE_JUDGE
// 	if (fopen("input.txt", "r")) {
// 		freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	}
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ur code
	char ch;
	cin >> ch;
	if (ch < 'a') cout << 'A';
	else cout << 'a';


	return 0;
}

Measured memory_bytes: 3632
from collections import deque

S = input()
dq = deque(S)

Q = int(input())
inverse = False
for _ in range(Q):
    query = list(input().split())
    if query[0] == '1':
        inverse = not inverse
    else:
        tmp = (int(query[1]) - 1) ^ inverse
        if tmp: dq.append(query[2])
        else: dq.appendleft(query[2])

if inverse: dq.reverse()
for c in dq:
    print(c, end='')
print('')

Measured memory_bytes: 7664
#include <cstdio>
#include <cstring>

int main(void)
{
    char a[101], b[101], c[101], nxt='a';
    int alen, blen, clen, ai=0, bi=0, ci=0;
    int chk=1;

    scanf("%s %s %s", a, b, c);
    alen=strlen(a);
    blen=strlen(b);
    clen=strlen(c);

    while(chk) {
        if(nxt=='a') {
            if(ai>=alen) break;
            nxt=a[ai++];
        } else if(nxt=='b') {
            if(bi>=blen) break;
            nxt=b[bi++];
        } else {
            if(ci>=clen) break;
            nxt=c[ci++];
        }
    }
    printf("%c", nxt-'a'+'A');
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  string s;
  cin>>s;
  rep(i,0,s.length()/2+(s.length()%2)){
    cout<<s[i*2];
  }
}

// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 512
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

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

  int n; cin >> n;
  print(180 * (n - 2));

  return 0;
}

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
int a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
int n;
cin>>n;
while(n--){
  a[2]*=2;
}
cout<<(a[0]+a[1]+a[2]);
system("pause");
return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(int N; cin >> N, N;) {
		vector<int> v(N);
		rep(i,N) cin >> v[i];
		
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N - 1; j++) {
				if(v[j] > v[j+1]) {
					swap(v[j], v[j+1]);
					cnt++;
				}
			}
		}
		
		cout << cnt << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}
double mini=0.00000000000001;
double memo[1000000];
double n;

double j2(ll i){
    if(abs(memo[i])>mini) return memo[i];
    if(i==0) return 1;
    return j2(i-1)/2;
}

int main(){
    ll n;cin>>n;
    ll a[5];
    ll b=10000000000000000;
    for(ll i=0;i<5;i++){
        cin>>a[i];
        b=min(b,a[i]);
    }
    ll ans;
    ans=((n-1)-(n-1)%b)/b+5;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;

const int N = 100010;
long long dp[N];

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

    int n, m;
    cin >> n >> m;

    vector<bool> NG(N, false);
    for(int i = 0; i < m; i++){
        int a;
        cin >> a;
        NG[a] = true;
    }

    dp[0] = 1;
    for(int i = 1; i <= n; i++){
        if(NG[i]) continue;
        if(i - 1 >= 0) dp[i] = (dp[i] + dp[i - 1]) % MOD;
        if(i - 2 >= 0) dp[i] = (dp[i] + dp[i - 2]) % MOD;
    }

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007

int main(){
    int N; cin >> N;
    vector<vector<int>> T(N, vector<int>(3));

    for(vector<int> &t:T)
        cin >> t[0] >> t[1] >> t[2];

    map<int, int> M;
    vector<vector<int>> o;
    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++){
            for(int k=0; k<N; k++){
                if(T[k][2]==0) continue;
                M[T[k][2]+abs(i-T[k][0])+abs(j-T[k][1])]++;
            }
            if(M.size()==1) o.push_back({i, j, M.begin()->first});
            M.clear();
        }
    }
    
    for(int i=0; i<o.size(); i++){
        bool f = true;
        for(int j=0; j<N; j++){
            if(T[j][2]==0 && max(0, o[i][2] - abs(o[i][0]-T[j][0]) - abs(o[i][1]-T[j][1]))!=0) f = false;
        }
        if(f) cout << o[i][0] << " " << o[i][1] << " " << o[i][2] << endl;
    }
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto&& i : a){
        cin >> i;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            ans = max(ans, abs(a[i] - a[j]));
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())

if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
else:
    print(c, b, a)
    


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;


int main() {
    fast

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

    if((a+b)%2==0)
        cout<<(a+b)/2;
    else
        cout<<"IMPOSSIBLE";




	return 0;
}




Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
#define V vector
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

const ll INF = 1e18;

int main () {
    ll n, k; cin >> n >> k;
    V<ll> p(n), c(n);
    rep(i, n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i, n) cin >> c[i];
    V<ll> loop(n), loop_cnt(n);
    rep(i, n) {
        ll a = p[i];
        ll cnt = c[a];
        ll count = 1;
        while (a != i) {
            a = p[a];
            cnt += c[a];
            count++;
        }
        loop[i] = cnt;
        loop_cnt[i] = count;
    }
    V<ll> ans(n);
    rep(i, n) {
        ll cnt = -INF;
        if (loop[i] < 0) {
            ll a = p[i];
            ll point = c[a];
            chmax(cnt, point);
            ll count = 1;
            while (a != i && count < k) {
                a = p[a];
                point += c[a];
                chmax(cnt, point);
                count++;
            }
            ans[i] = cnt;
        }
        else {
            cnt = loop[i] * (k/loop_cnt[i]);
            ll m = k % loop_cnt[i];
            if (m == 0) {
                m = loop_cnt[i];
                cnt -= loop[i];
            }
            ll point = -INF;
            ll a = p[i];
            ll now = c[a];
            chmax(point, now);
            rep(i, m-1) {
                a = p[a];
                now += c[a];
                chmax(point, now);
            }
            ans[i] = cnt + point;
        }
    }
    ll res = -INF;
    rep(i, n) chmax(res, ans[i]);
    cout << res << endl;


    //rep(i, n) printf("%ld %ld\n", loop[i], loop_cnt[i]);
    //rep(i, n) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
#define int long long
using namespace std;
int MOD = 1000000007;

signed main(){
    int N;
    cin >> N;
    
    string S;
    map<char,int> mp;
    for(int i=0;i<N;i++){
        cin >> S;
        mp[S[0]]++;
    }
    
    string march[] = {"M","A","R","C","H"};
    sort(march,march+5);
    string tmp;
    vector<string> v;
    set<string> st;
    
    do{
        for(int i=0;i<3;i++){
            tmp += march[i];
        }
        sort(tmp.begin(),tmp.end());
        st.insert(tmp);
        tmp = "";
    }while(next_permutation(march,march+5));
    
    for(auto it = st.begin();it != st.end();it++){
        v.push_back(*it);
    }
    unsigned long long ans = 0;
    
    for(int i=0;i<v.size();i++){
        ans += (mp[v[i][0]]*mp[v[i][1]]*mp[v[i][2]]);
    }
    
    cout << ans << endl;
    return 0;
}



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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int a[] = new int[n];
        int total = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            total += a[i];
        }

        int count = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] * 4 * m >= total) count++;
        }

        if (count >= m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,a[10001],sum=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
	 cin>>a[i];
    for(int i=1;i<=n-1;i++)
    for(int j=i+1;j<=n;j++)
    {
        if(a[i]<a[j])
		swap(a[i],a[j]);
    }
    for(int i=1;i<=k;i++) 
	sum+=a[i];
	
    cout<<sum<<endl;
    return 0;
}


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

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

    int answer = 0;
    int sum = 1;
    while (true) {
        if (sum >= b) {
            break;
        }
        
        answer++;
        sum += a - 1;
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;


int main(){
    int N;
    cin >> N;
    vector<LL> v;
    for(int i=0;i<N;i++){
        LL a;
        cin >> a;
        v.push_back(a);
    }
    LL ans=0;
    while(1){
        auto p=max_element(v.begin(),v.end());
        LL k=*p/N;
        *p%=N;
        for(int i=0;i<N;i++){
            if(i==p-v.begin()) continue;
            else v[i]+=k;
        }
        ans+=k;
        if(*max_element(v.begin(),v.end())<=N-1) break;
    }
    cout << ans << endl;
    return 0;
}

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

const int N = 100005;

int n;
int d[N];
vector<int> G[N];
bool bipartite;
bool c[2];
int cnt;

int m;
int a[N];
int b[N];
int t[N];

long long ans;

void dfs(int u) {
	++cnt;
	for (int v : G[u]) {
		if (d[v] == -1) d[v] = (d[u] ^ 1), c[d[v]] = 1, dfs(v);
		else if (d[v] == d[u]) bipartite = true;
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	memset(d, -1, sizeof d);
	while(m--) {
		int u, v; cin >> u >> v;
		G[u].push_back(v); G[v].push_back(u);
	}

	m = 0;
	for (int i = 1; i <= n; ++i) if (d[i] == -1) {
		bipartite = false; d[i] = 0; c[0] = 1; c[1] = 0; cnt = 0; dfs(i);
		++m; a[m] = bipartite; b[m] = c[0] + c[1]; t[m] = cnt;
	}

	int full0 = 0, full1 = 0, full = 0, cnt_invalid = 0; 
	for (int i = 1; i <= m; ++i) {
		full1 += (b[i] == 2 ? 1 : 0);
		if (b[i] == 2) full0 += (a[i] == 1 ? 1 : 2);
		full += t[i];
		if (b[i] == 1) cnt_invalid++;
	}

	for (int i = 1; i <= m; ++i) {
		//cerr << t[i] << ' ' << a[i] << endl;
		if (a[i] == 1) {
			ans += full1 + 1LL * cnt_invalid * t[i];
		} else {
			if (b[i] == 1) ans += full;
			else ans += full0 + 1LL * cnt_invalid * t[i];
		}
		//cerr << i << ' ' << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N,M; cin >> N >> M;
    VI redmemo(N+1), ball(N+1);
    REP(i,N+1) redmemo[i] = 0;
    FOR(i,1,N+1)
    {
        ball[i] = 1;
    }
    redmemo[1] = 1;

    REP(i,M)
    {
        int x,y; cin >> x >> y;
        if(redmemo[x] == 1)
        {
            if(ball[x] == 1)
            {
                redmemo[y] = 1;
                redmemo[x] = 0;
            }
            else
            {
                redmemo[y] = 1;
            }
        }
        ball[x]--; ball[y]++;
        dump(ball[x])
        dump(ball[y])
        dump(redmemo[x])
        dump(redmemo[y])
    }
    int ans = 0;

    FOR(i,1,N+1)
    {
        if(redmemo[i] == 1) 
        {
            dump(i)
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024