akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
long long gcd(long long a, long long b)
{
    return b ? gcd(b, a % b) : a;
}
map<long long, long long> prime_factor(long long n)
{
    map<long long, long long> res;
    for (long long i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1)
        res[n] = 1;
    return res;
}
long long mod_pow(long long x, long long n, long long mod)
{
    if (n == 0)
        return 1;
    long long res = mod_pow(x * x % mod, n / 2, mod);
    if (n & 1)
        res = res * x % mod;
    return res;
}
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rp(i, 0, n) cin >> a[i];
    ll mod = 1000000007;
    map<ll, ll> mp2[n];
    map<ll, ll> mp;
    rp(i, 0, n)
    {
        mp2[i] = prime_factor(a[i]);
        for (auto j = mp2[i].begin(); j != mp2[i].end(); ++j)
        {
            mp[j->first] = max(mp[j->first], j->second);
        }
    }
    ll mp4[1000000], mp5[1000000];
    map<ll, ll> mp6;
    ll co = 0;
    for (auto j = mp.begin(); j != mp.end(); ++j)
    {
        mp6[j->first] = co;
        mp4[co] = j->first;
        mp5[co] = j->second;
        co++;
    }
    ll ans = 0;
    rp(i, 0, n)
    {
        ll tt = 1;
        ll mp7[co];
        rp(j, 0, co) mp7[j] = mp5[j];
        for (auto j = mp2[i].begin(); j != mp2[i].end(); ++j)
        {
            mp7[mp6[j->first]] -= j->second;
        }
        rp(j, 0, co)
        {
            tt *= mod_pow(mp4[j], mp7[j], mod);
            tt %= mod;
        }
        ans += tt;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6016
N = gets.to_i
as = gets.split.map(&:to_i).sort
if as[0] != (as[-1]+1)/2
    puts 'Impossible'
    exit
end

hash = Hash.new(0)
as.each do |a|
    hash[a] += 1
end

(as[0]..as[-1]).each do |i|
    if i*2 == as[-1]
        if hash[i] != 1
            puts 'Impossible'
            exit
        end
    elsif i*2-1 == as[-1]
        if hash[i] != 2
            puts 'Impossible'
            exit
        end
    else
        if hash[i] < 2
            puts 'Impossible'
            exit
        end
    end
end
puts 'Possible'

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

int main() {
  string A;
  cin>>A;
  if(A.at(0)=='7'||A.at(1)=='7'||A.at(2)=='7'){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  }

Measured memory_bytes: 3624
using namespace std;
#include<bits/stdc++.h>
// #include<iostream>
// #include<string>
// #include<vector>
// #include<set>
// #include<map>
// #include<algorithm>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define IN4(P1,P2,P3,P4) cin>>(P1)>>(P2)>>(P3)>>(P4)
#define INS(I,N,V) REP((I),(N))cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N))cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N))cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUT4(P1,P2,P3,P4) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<" "<<(P4)<<endl
#define OUTS(I,N,V) REP((I),(N))cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}

cpp_int N,M,i,A,B,sum,ans;
vector<pair<cpp_int,cpp_int>>C;
inline void solve(void){
  IN2(N,M);
  REP(i,N){
    IN2(A,B);
    C.pb(mp(A,B));
  }
  sort(ALL(C));
  for(auto e:C){
    if(e.second+sum<=M){
      ans+=e.first*e.second;
      sum+=e.second;
    }else if(e.second+sum>M&&M-sum<=e.second){
      ans+=(M-sum)*e.first;
      sum+=M-sum;
    }
    if(sum==M)break;
  }
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

int main () {
    int H, W;
    cin >> H >> W;
    string s = "";

    for (int i = 0; i < H; i++){
        string S;
        cin >> S;
        
        s += S;
    }
    for (int i = 0; i < H * W; i++){
        char M = s .at(i);
        int l = 0;

        if (M == '#'){
            cout << "#";
        }
        
        if (i > 0 && i % W != 0 && M == '.' && s .at(i - 1) == '#'){
            l += 1;
        }
        if ( i < H * W - 1 && i % W != W -1 && M == '.' && s .at(i + 1) == '#'){
            l += 1;
        }
        if (i > W - 1 && M == '.' && s .at(i - W) == '#'){
            l += 1;
        }
        if (i > W && i % W != 0 && M == '.' && s .at(i - W - 1) == '#'){
            l += 1;
        }
        if (i > W - 1 && i % W != W - 1 && M == '.' && s .at(i - W + 1) == '#'){
            l += 1;
        }
        if (i < H * W - W  && M == '.' && s .at(i + W) == '#'){
            l += 1;
        }
        if (i < H * W - W && i % W != 0 && M == '.' && s .at(i + W  - 1) == '#'){
            l += 1;
        }
        if (i < H * W - W - 1 && i % W != W -1 && M == '.' && s .at(i + W + 1) == '#'){
            l += 1;
        }
        if (M == '.'){
            cout << l;
        }
        if (i % W == W - 1){
            cout << endl;
        }

    }
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  string s;
  cin >> s;
  int n = s.size();
  if (n % 2) {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < n; i += 2) {
    if (s.substr(i, 2) != "hi") {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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



int main(){
    int th, ts, ah, as;
    cin >> th >> ts >> ah >> as;
    while(th > 0 && ah > 0){
        ah = ah - ts;
        th = th - as;
    }
    if(ah <= 0){
        cout << "Yes" << '\n';
        return 0;
    }
    if(th <= 0){
        cout << "No" << '\n';
        return 0;
    }
    ah = ah - ts;
    if(ah <= 0){
        cout << "Yes" << '\n';
        return 0;
    }
    th = th - as;
    if(th <= 0){
        cout << "No" << '\n';
        return 0;
    }
}

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

long long int h[200005];
int main(){
  int n,k;
  long long int ans=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  sort(h,h+n);
  for(int i=0;i<n-k;i++)
  ans+=h[i];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int[] data = new int[3];
        while (scan.hasNext()) {
            int n=scan.nextInt();
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 3; j++) {
                    data[j] = scan.nextInt();
                }
                for (int j = 0; j < 2; j++) {
                    for (int k = j + 1; k < 3; k++) {
                        if (data[j] < data[k]) {
                            int tmp;
                            tmp = data[j];
                            data[j] = data[k];
                            data[k] = tmp;
                        }
                    }
                }
                if (data[0] * data[0] == data[1] * data[1] + data[2] * data[2])
                    System.out.println("YES");
                else
                    System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 23376
import java.util.*;

public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      char a = sc.next().charAt(0),b=sc.next().charAt(0);
      if(a==b){
        System.out.println("=");
      }else if(a>b){
        System.out.println(">");
      }else{
        System.out.println("<");
      }
    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<iomanip>
#include<queue>
#include<string>

typedef long long ll;
const int inf = 0x3f3f3f3f,maxn = 200000 + 5;

using namespace std;

int main(){

	char s[maxn],t[maxn];

	while(cin >> s >> t)
	{

		int book[30];
		memset(book,-1,sizeof(book));

		int len = strlen(s);
		bool flag = false;

		for(int i = 0;i < len;i++)
		{

			if(book[s[i] - 'a'] == -1)
			{

				book[s[i] - 'a'] = t[i] - 'a';

			}

			else if(book[s[i] - 'a'] != t[i] - 'a')
			{
				puts("No");
				flag = true;
				break;
			}

		}


		if(!flag)
		{
			memset(book,-1,sizeof(book));
			for(int i = 0;i < len;i++)
			{
				if(book[t[i] - 'a'] == -1)
				{
					book[t[i] - 'a'] = s[i] - 'a';
				}

				else if(book[t[i] - 'a'] != s[i] - 'a')
				{
					puts("No");
					flag = true;
					break;
				}
			}
		}

		if(!flag) puts("Yes");

	}

	return 0;
}

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

using namespace std;

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

  string s;
  cin >> s;

  char current_color = s[0];
  int sum = 1;
  int count = 0;

  int i = 0;
  while (i < n) {
    const char color = s[i];
    if (color != current_color) {
      current_color = color;
      sum++;
    }

    i++;
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ENDL '\n'
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR_EACH(i, v) for (auto&& i : v)

string A;
vector<vector<int>> nextCharPos;
list<int> changePoint;

void calcNextCharPos(string& s)
{
	int len = s.length();
	nextCharPos.resize(len + 1);
	FOR(i, len + 1) {
		nextCharPos[i].resize(26);
	}

	FOR(i, 26) {
		nextCharPos[len][i] = len;
	}

	for (int i = len - 1; i >= 0; i--) {
		FOR(j, 26) {
			nextCharPos[i][j] = nextCharPos[i + 1][j];
		}
		nextCharPos[i][s[i] - 'a'] = i;
	}
}

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

	cin >> A;
	calcNextCharPos(A);
	int len = A.length();
	changePoint.push_back(len);

	bool flags[26] = { false };
	int counter = 0;
	for (int i = len - 1; i >= 0; i--) {
		if (!flags[A[i] - 'a']) {
			flags[A[i] - 'a'] = true;
			counter++;
			if (counter == 26) {
				FOR(j, 26) {
					flags[j] = false;
				}
				counter = 0;
				changePoint.push_front(i);
			}
		}
	}

	string ans = "";
	int index = 0;
	for (list<int>::iterator it = changePoint.begin(); it != changePoint.end(); it++) {
		FOR(i, 26) {
			if (*it <= nextCharPos[index][i]) {
				ans += (char)(i + 'a');
				index = nextCharPos[index][i] + 1;
				break;
			}
		}
	}

	cout << ans << ENDL;

	return 0;
}

Measured memory_bytes: 30304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

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

  ll ans;
  if(k % 2 == 0){
    ans = a - b;
  }
  else{
    ans = b - a;
  }

  if(abs(ans) > 1e18){
    cout << "Unfair" << endl;
  }
  else{
    cout << ans << endl;
  }
  return 0;
}



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

const int N = 1e5 + 7;
int n, candy[N];

int main(){
	cin>>n;
	for (register int i = 1;i <= n;i ++)cin>>candy[i];
	sort(candy + 1, candy + n + 1, greater<int>());
	for (register int i = 1, j;i <= n;i ++)
		if (i + 1 <= candy[i + 1])continue;
		else {
			for (j = 1;candy[i + j] == i;j ++)continue;
			if (((candy[i] - i)&1) || !(j&1))cout<<"First";
			else cout<<"Second";
			return 0;
		}
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
  int a[4],b[4],r[5]={0},i;
  for(i=0;i<4;i++){
    scanf("%d %d",&a[i],&b[i]);
    r[a[i]]++;r[b[i]]++;
  }
  if(r[1]<3&&r[2]<3&&r[3]<3&&r[4]<3) printf("YES");
  else printf("NO");
  return 0;
}

Measured memory_bytes: 128
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 c = sc.nextInt();
        int[] b = new int[m];
        int ans = 0;
        for (int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < m; j++) {
                sum += b[j] * sc.nextInt();
            }
            if (sum + c > 0) ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21972
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    let a = BigInt(input[0][0], 10);
    let b = BigInt(input[0][1], 10);
    let c = BigInt(input[0][2], 10);
    let d = BigInt(input[0][3], 10);
    let ans = a * c;
    if (ans < a * d) ans = a * d;
    if (ans < b * c) ans = b * c;
    if (ans < b * d) ans = b * d;
    console.log(ans.toString());
 
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29624
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 200005;
const int INF = 0x3f3f3f3f;
typedef long long lld;
int n;
int a[N], l[N], r[N];
lld ans;

struct stack{
	int t;
	int dat[N];
	void clear() {
		t = 0;
	}
	void push(int x) {
		dat[++t] = x;
	}
	void pop() {
		--t;
	}
	int top() {
		return dat[t];
	}
	bool empty() {
		return (t == 0);
	}
}st;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)  scanf("%d", &a[i]);
	a[0] = a[n + 1] = -INF;
	st.push(0);
	for (int i = 1; i <= n; ++i) {
		while (a[i] < a[st.top()])  st.pop();
		l[i] = st.top();
		st.push(i);
	} 
	st.clear();
	st.push(n + 1);
	for (int i = n; i >= 1; --i) {
		while (a[i] <= a[st.top()])  st.pop();
		r[i] = st.top();
		st.push(i);
	}
	for (int i = 1; i <= n; ++i)  ans += 1ll * (i - l[i]) * (r[i] - i) * a[i];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

  if (a == b) {
	cout << "H" << endl;
  }
  else {
	cout << "D" << endl;
  }
}

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

int main(void){
    char s[27] = {};
    int i, j;
    
    scanf("%s", s);
    for( i = 0; i < strlen(s); ++i){
        for( j = 0; j < strlen(s); ++j){
            if( i != j && s[i] == s[j]){
                printf("no\n");
                return 0;
            }
        }
    }
    
    printf("yes\n");
    return 0;
    
}

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

int main(){
  string path;
  cin >> path;

  int x_pos= 0;
  int x_neg= 0;
  int y_pos= 0;
  int y_neg= 0;
  for(int i=0; i<path.size(); i++){
    if(path.at(i)=='E'){ x_pos++; }
    if(path.at(i)=='W'){ x_neg++; }
    if(path.at(i)=='N'){ y_pos++; }
    if(path.at(i)=='S'){ y_neg++; }
  }

  string ans= ((x_pos*x_neg > 0 || (x_pos==0 && x_neg==0)) && (y_pos*y_neg > 0 || (y_pos==0 && y_neg==0))) ? "Yes"
                                                                                                           : "No";
  cout << ans << endl;
}

Measured memory_bytes: 256
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)2e5 + 5;

int arr[MAXN];

int n, ans;

void solve() {
    scanf("%d", &n);

    for (int i = 1, x; i <= n; ++i) {
        scanf("%d", &x);
        arr[x] = i;
    }

    for (int i = 1, x = 0; i <= n; ++i) {
        if (arr[i] > arr[i - 1]) {
            ++x;
        }
        else {
            x = 1;
        }

        ans = max(ans, x);
    }

    printf("%d\n", n - ans);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

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

int main(){
  int n,count,ans;
  cin >> n;
  ans = 0;
  for(int i=1;i<=n;i+=2){
    count = 0;
    for(int j=1;j<=i;j+=2){
      if (i%j == 0) count += 1;
    if (count == 8){
      ans += 1;
      }
    }
  }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
x=int(input())
l=make_divisors(x)
if x==0:
  answer=[0,0]
for i in range(math.ceil(2*pow(x,0.2))):
  for j in l:
    if pow(i,5)-pow(i-j,5)==x:
      answer=[i,i-j]
      break
print(answer[0],answer[1])

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

ll A, B, C, X, Y;

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

	cin >> A >> B >> C >> X >> Y;
	ll ans = 1e15;
	for (ll i = 0; i <= max(X, Y); i++) {
		ll cur = i*2*C;
		ll rema = max(0LL, X-i);
		ll remb = max(0LL, Y-i);
		cur += rema*A + remb*B;
		ans = min(ans, cur);
	}

	cout << ans << "\n";

}

Measured memory_bytes: 384
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto H = RD;
	auto W = RD;
	auto a = new string[](H);
	foreach (y; 0..H)
	{
		a[y] = "#" ~ RD!string ~ "#";
	}

	foreach (i; 0..W+2)
		write("#");
	writeln();
	foreach (y; 0..H)
	{
		writeln(a[y]);
	}
	foreach (i; 0..W+2)
		write("#");
	writeln();
	stdout.flush();
	debug readln();
}

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

int main(){
    int a, b;
    
    cin >> a >> b;
    
    if (a >= 13){
        cout << b << endl;
    }else if(a >= 6 && a <= 12){
        cout << b / 2 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define endl "\n"
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)                   
using namespace std;                            
                                                
void yes() {cout << "YES" << endl;}                                               
void no() {cout << "NO" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const long long INF = 8e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7;

void solve() {
    int n; cin >> n;
    long long k; cin >> k;
    vector<int> p(n + 1);
    vector<long long> c(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    long long res = -INF;
    for (int it = 1; it <= n; it++) {
        long long ans = -INF;
        vector<int> used(n + 1, false);
        vector<int> g;
        int j = it;
        while (true) {
            j = p[j];
            if (used[j]) break;
            else {
                used[j] = true;
                g.pb(j);
            }
        }
        vector<long long> pref(sz(g));
        pref[0] = c[g[0]];
        for (int i = 1; i < sz(g); i++) {
            pref[i] = pref[i - 1] + c[g[i]];
        }
        if (pref[sz(g) - 1] < 0) {
            for (int i = 0; i < min(k, 1ll * sz(g)); i++) {
                ans = max(ans, pref[i]);
            }
        } else {
            for (int i = 0; i < min(k, 1ll * sz(g)); i++) {
                ans = max(ans, pref[i]);
            }
            long long ti = k / sz(g);
            long long ri = k % sz(g);
            vector<long long> mx(sz(g));
            mx[0] = pref[0];
            for (int i = 1; i < sz(g); i++) {
                mx[i] = max(mx[i - 1], pref[i]);
            }
            // cout << it << endl;
            // for (int i = 0; i < sz(g); i++) cout << pref[i] << " ";
            // cout << endl;
            // for (int i = 0; i < sz(g); i++) cout << mx[i] << " ";
            // cout << endl;
            ans = max(ans, ti * pref[sz(g) - 1] + (ri > 0) * 1ll * mx[ri - 1]);
            if (ti > 0) ans = max(ans, (ti - 1) * pref[sz(g) - 1] + mx[sz(g) - 1]);
        }
        res = max(res, ans);
    }
    cout << res << endl;
}

int main() {
    jonathan; 
    livingston;
    bool tests = 0;
    int t = 1;
    if (tests) cin >> t;
    for (int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3856
const main = (input) => {
	const args = input.trim().split("\n");
	const N = args[0]
	const As = args[1].trim().split(" ")
	let flag = ''
	if (As.includes('0')) { flag = 'zero' }
	let answer = As[0]

	const limit = 10 ** 18
	if (flag !== 'zero') {
		let i = 1;
		while (i < As.length) {
			if (answer <= limit) {
				answer = BigInt(answer) * BigInt(As[i])
				i = (i + 1) | 0
				if (answer > limit) {
					flag = 'over'
					break
				}
			}
		}
	}
	switch (flag) {
		case 'zero' :
			console.log(0)
			break
		case 'over':
			console.log(-1)
			break
		default:
			console.log(answer.toString())
	}
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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


int main() {
  int n,i;
  cin>>n;
  long long int a[n],x[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    x[i]=a[i]-i-1;
  
  }
  
  sort(x,x+n);
  long long int b;
  
  if(n%2==1)
    b=x[(n-1)/2];
  else b=x[n/2];
  
  long long int ans=0;
 
  for(i=0;i<n;i++){
    ans+=abs(x[i]-b);
   
  }
  cout<<ans;
  
  
}

Measured memory_bytes: 3328
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int U[800], L[800];
vector<P> G[800];

int maxPath(int x, int p) {
  int m = 0;
  for (P p2 : G[x]) {
    int t = p2._1;
    if (t == p || G[t].size() == 1) continue;
    m = max(m, maxPath(t, x) + p2._2);
  }
  return m;
}
int dfs(int x, int p) {
  int s = 0;
  for (P p2 : G[x]) {
    int t = p2._1;
    if (t == p || G[t].size() == 1) continue;
    s += dfs(t, x) + p2._2;
  }
  return s;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> N) {
    if (N == 0) break;
    rep(i, N) G[i].clear();
    rep(i, N-1) cin >> U[i], U[i]--;
    rep(i, N-1) cin >> L[i];
    rep(i, N-1) {
      G[U[i]].pb(P(i+1, L[i]));
      G[i+1].pb(P(U[i], L[i]));
    }
    int m = INF;
    rep(i, N) {
      int s = 2*dfs(i, -1) - maxPath(i, -1);
      m = min(m, s);
    }
    rep(i, N-1) m += L[i];
    cout << m << "\n";
  }
  return 0;
}

Measured memory_bytes: 3292
#include <stdio.h>

int main(void) {
	char s[5];
	scanf("%s", s);

	int same = 0, diff = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			if (s[i] == s[j]) same++;
			else diff++;
		}
	}

	if (same == 8 && diff == 8) puts("Yes");
	else puts("No");
}


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
ll n, m;
vector<int>v[MAXN];
int main(){
	FAST
	cin>>n>>m;
	if(n==1){cout<<"No\n";return 0;}
	FOR(i,1,m){
		ll a,b;cin>>a>>b;
		v[a].eb(b),v[b].eb(a);
	}
	FOR(i,1,n)if(siz(v[i])&1){cout<<"No\n";return 0;}
	FOR(i,1,n)if(siz(v[i])>=6){cout<<"Yes\n";return 0;}
	ll four=0; FOR(i,1,n)if(siz(v[i])>=4)++four;
	if(four>=3){
		cout<<"Yes\n";
		return 0;
	}
	if(four==2){
		vector<ll>vis(n+1,0);
		ll ans=0,r=-1,o=-1;
		function<void(ll)>dfs=[&](ll x){
			if(x==o)++ans;
			if(vis[x])return;
			vis[x]=1;
			for(auto i:v[x]){
				dfs(i);
			}
		};
		FOR(i,1,n)if(siz(v[i])==4){r=i;break;}
		FOR(i,1,n)if(i^r)if(siz(v[i])==4){o=i;break;}
		vis[o]=1, dfs(r);
		assert(ans%2==0);
		if(ans==2){
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
}


Measured memory_bytes: 12416
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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

int h1, m1, h2, m2, k;
main() {
  file("threesum");
  ios;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  h1 = h1 * 60 + m1;
  h2 = h2 * 60 + m2;
  cout << h2 - h1 - k;
  return 0;
}
/**

*/


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  rep(i,n){
    int s;
    cin >> s;
    cout << "Case " << to_string(1+i)<<":"<<endl;
    rep(j,10){
      s *= s;
      string str = to_string(s);
      while(str.size() < 8){
        str = "0" + str;
      }
      string next = "";
      for(int i = str.size()/2-2;i < str.size()/2+2;++i){
        next+=str[i];
      }
      s = ston(next,1);
      cout << s << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define OJ \
        freopen("input.txt","r",stdin); \
        freopen("output.txt","w",stdout);
using namespace std;

int main()
{
 // OJ;
int l,r,n,ans=0;
cin>>l>>r>>n;
for(int i=l;i<=r;i++)
{
  if(i%n==0)
  {
ans++;
  }
}
cout<<ans;
}

Measured memory_bytes: 3620
dp=["","+"]
s=input()
su=0
for i in range(2**(len(s)-1)):
    val=""
    b=bin(i)[2:].zfill(len(s)-1)
    for j in range(len(s)-1):
        val+=s[j]+dp[int(b[j])]
    val+=s[len(s)-1]
    su+=eval(val)
print(su)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
        int n,i;
        int a[100];
	
	    scanf("%d",&n);
        for(i = 0;i < n;i++){
        scanf("%d",&a[i]);
        }
        for(i = n-1;0 < i;i--){
        	printf("%d ",a[i]);
        }
        printf("%d\n",a[i]);
        return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

struct DATA
{
	int num, id;
	string s;
};

vector<DATA> v;

int partitionSort(int p,int r)
{
	int x = v.at(r).num;// v[r];
	int i = p - 1;

	for (int j = p; j != r; ++j)
	{
		if (v.at(j).num<=x) //v[j] <= x
		{
			++i;
			swap(v.at(i), v.at(j));
		}
	}

	swap(v.at(i + 1), v.at(r));

	return i + 1;
}


void quicksort(int p, int r)
{
	if (p < r)
	{
		int q=partitionSort(p,r);
		quicksort(p, q - 1);
		quicksort(q + 1, r);
	}
}

void check()
{
	for (int i = 1; i != v.size(); ++i)
	{
		if (v.at(i - 1).num == v.at(i).num)
		{
			if (v.at(i - 1).id>v.at(i).id)
			{
				cout << "Not stable" << endl;
				return;
			}
		}
	}
	cout << "Stable" << endl;
}



int main()
{
	int n,t;
	string s;
	DATA data;
	ios::sync_with_stdio(false);

	cin >> n;

	for (int i = 0; i != n; ++i)
	{
		cin >> s>>t;
		data.s = s;
		data.num = t;
		data.id = i;
		v.push_back(data);
	}

	quicksort(0, n - 1);
	check();

	for (int i = 0; i != v.size(); ++i)
	{
		cout << v.at(i).s<<" " << v.at(i).num<<endl;
	}
	//cout << endl;

	return 0;

}


Measured memory_bytes: 9012
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main() {
	int n;
    cin >> n;
	vector<vector<int>> v(10, vector<int>(10));
	for(int i=1; i<=n; i++) {
		string s = to_string(i);
		v[s[0] - '0'][s.back() - '0']++;
	}
	/*rep(i, 10) {
		rep(j, 10) cout << v[i][j] << " ";
		cout << endl;
	}*/
    long ans = 0;
	rep(i, 10) rep(j, 10) ans += v[i][j] * v[j][i];
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define mid ((l+r)>>1)
const int N=200005,inf=0x3f3f3f3f;
int n,fw[2],re[N],sg[N*8],wl[N*8],wr[N*8],nc=2,qx[N*4];
inline int imn(int x,int y){return x<y?x:y;}
inline void isw(int &x,int &y){int t=x;x=y,y=t;}
void chg(int wz,int x,int y,int l=1,int r=n)
{
	if(l==r) {sg[wz]=y;return;}
	if(x<=mid) ((wl[wz]==0)&&(wl[wz]=++nc)),chg(wl[wz],x,y,l,mid);
	else ((wr[wz]==0)&&(wr[wz]=++nc)),chg(wr[wz],x,y,mid+1,r);
	sg[wz]=imn(sg[wl[wz]],sg[wr[wz]]);
}
int qry(int wz,int x,int y,int l=1,int r=n)
{
	if(x<=l&&r<=y) return sg[wz];
	int rs=inf;
	if(x<=mid&&wl[wz]) rs=imn(rs,qry(wl[wz],x,y,l,mid));
	if(y>mid&&wr[wz]) rs=imn(rs,qry(wr[wz],x,y,mid+1,r));
	return rs;
}
void pls(int x,int wz=1,int l=1,int r=n+1)
{
	if(l==r) {qx[wz]=l;return;}
	if(x<=mid) pls(x,wz*2,l,mid);
	else pls(x,wz*2+1,mid+1,r);
	qx[wz]=imn(qx[wz*2],qx[wz*2+1]);
}
int qnx(int x,int wz=1,int l=1,int r=n+1)
{
	if(x<=l) return qx[wz];
	int rs=qnx(x,wz*2+1,mid+1,r);
	if(x<=mid) rs=imn(rs,qnx(x,wz*2,l,mid)); 
	return rs;
}
int swp(int x,int y,int w1=1,int w2=2,int l=1,int r=n)
{
	if(x<=l&&mid<=y) isw(wl[w1],wl[w2]);
	else if(x<=mid) swp(x,y,wl[w1],wl[w2],l,mid);
	if(x<=mid+1&&r<=y) isw(wr[w1],wr[w2]);
	else if(y>mid) swp(x,y,wr[w1],wr[w2],mid+1,r);
	sg[w1]=imn(sg[wl[w1]],sg[wr[w1]]),sg[w2]=imn(sg[wl[w2]],sg[wr[w2]]);
}
int main()
{
//	freopen("seq.in","r",stdin),freopen("seq.out","w",stdout);
	memset(sg,0x3f,sizeof(sg)),memset(qx,0x3f,sizeof(qx));
	fw[0]=2,fw[1]=1;scanf("%d",&n),pls(n+1);
	for(int i=1,x;i<=n;++i) scanf("%d",&x),re[x]=i,chg(fw[i&1],i,x);
	for(int i=1,n1,n2;i*2<=n;++i)
	{
		n1=qry(1,1,n),printf("%d ",n1),n1=re[n1],chg(1,n1,inf),pls(n1);
		n2=qry(2,n1+1,qnx(n1+1)-1),printf("%d ",n2),n2=re[n2],chg(2,n2,inf);pls(n2);
		swp(n1,n2);
	}	
	return 0;
}

Measured memory_bytes: 19968
MAX=200000
def get_prime(x):
  is_prime = [True] * 200000
  for i in range(2,MAX):
    if is_prime[i] and i >= x:
      return i
    elif is_prime[i]:
      for j in range(2 * i, MAX, i):
        is_prime[j] = False

print(get_prime(int(input())))


Measured memory_bytes: 10452
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c,d,e,t;
	scanf("%d %d",&a,&b);
	c=a+b;
	d=a-b;
	e=(a)*(b);
	t=c>(d>e?d:e)?c:(d>e?d:e);
	printf("%d\n",t);
	return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val dList = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    dList.sort()

    val centerLeft = dList[n / 2 -1]
    val centerRight = dList[n / 2]
    println(centerRight - centerLeft)
}


Measured memory_bytes: 53676
fun main(args: Array<String>) {
    val (N, L) = readInputLine().split(" ").map { it.toInt() }
    
    val strings = mutableListOf<String>()
    
    for (i in 1..N) {
        strings.add(readInputLine())
    }

    println(strings.sorted().joinToString(""))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37696
import itertools

N = int(input())

mem = list(set() for i in range(5))

for _ in range(N):
    S = input()
    first_name = "MARCH".find(S[0])
    if first_name != -1:
        mem[first_name].add(S)

ans = 0
for t in list(itertools.combinations(range(5), 3)):
    ans += len(mem[t[0]]) * len(mem[t[1]]) * len(mem[t[2]])
    
print(ans)

Measured memory_bytes: 14316
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;


int main() {
	int Q; cin >> Q;
	for (int iter = 0; iter < Q; iter++) {
		ll A, B; cin >> A >> B;
		ll lo = 0, hi = 3e9;
		while (hi - lo > 1) {
			ll mid = lo + (hi - lo) / 2;
			ll m = 0;
			for (ll i = max(1LL, mid/2 - 100000LL); i <= min(mid, mid/2 + 100000LL); i++) {
				ll a = i + (i >= A);
				ll b = mid + 1 - i + (mid + 1 - i >= B);
				m = max(m, a*b);
			}
			if (m < A*B) lo = mid;
			else hi = mid;
		}
		cout << lo << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i = 0;i < n;i++){
			d[i] = sc.nextInt();
		}

		if(d[0] != 0){
			System.out.println(0);
			return;
		}
		Arrays.sort(d);
		
		if(n != 1 && d[1] == 0){
			System.out.println(0);
			return;

		}
		
		int[] num = new int[d[n-1]+1];
		for(int i = 0;i < n;i++){
			num[d[i]]++;
		}
		
//		for(int i = 0;i < 3;i++){
//			System.out.println(num[i]);
//		}
		
		long ans = 1;
		int len = d[n-1];
		long tmp = 1;
		for(int i = 1;i <= len;i++){

			long x = tmp %998244353;
			for(int j = 0;j < num[i]-1;j++){
				tmp *= (x % 998244353);
				tmp %= 998244353;
//				System.out.println(tmp + " " +x);

			}
//			System.out.println(ans + " ans");
//			tmp = (long)Math.pow(tmp, num[i]);
			
			ans *= tmp%998244353;
			ans %= 998244353;
			tmp = num[i];
		}
		
		
		System.out.println(ans%998244353);
		



	}



	static int upperbond(int k, ArrayList<Integer> data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int min = -1;
		int max = data.size();

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data.get(mid) > k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return data.get(max);
	}

	static int lowerbond(int k, ArrayList<Integer> data){		//kより小さい最小の値をdataの中から探し、返す二分探索
		int min = -1;
		int max = data.size();

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data.get(mid) >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return data.get(min);
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   end- otherpair.end;
	}








}






Measured memory_bytes: 50824
#include<bits/stdc++.h>
using namespace std;
int n, m, sum, p, x, a[123];

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) 
	{
		scanf("%d", a + i);
		sum += a[i];
	}
	cin >> m;
	while(m--)
	{
		scanf("%d%d", &p, &x);
		printf("%d\n", sum - a[p] + x);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;
  ll ans = 0;
  rep(i, N) {
    ans += i + 1;
  }
  ANS;
  return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

struct FFT{
	const int mod, g;
	FFT(int a, int b):mod(a), g(b){}
	long long mul(long long a, long long b){
		return (a * b) % mod;
	}
	long long ex(long long a, long long e){
		long long ans = 1, tmp = a;
		while(e > 0){
			if(e % 2 == 1){
				ans = mul(ans, tmp);
			}
			tmp = mul(tmp, tmp);
			e /= 2;
		}
		return ans;
	}
	long long inv(long long a){
		return ex(a, mod - 2);
	}
	void fft(vector<long long> &a, long long h){
		int N = a.size();
		for(int m = N; m >= 2; m /= 2){
			int mh = m / 2;
			long long w = 1;
			for(int i = 0; i < mh; ++i){
				for(int j = i; j < N; j += m){
					int k = j + mh;
					long long x = a[j] - a[k];
					a[j] += a[k];
					if(a[j] > mod) a[j] -= mod;
					a[k] = mul(w, x);
					if(a[k] < 0) a[k] += mod;
				}
				w = mul(w, h);
			}
			h = mul(h, h);
		}
		int i = 0;
		for(int j = 1; j < N - 1; ++j){
			for(int k = N / 2; k > (i ^= k); k /= 2);
			if(j > i) swap(a[i], a[j]);
		}
	}
	vector<long long> convolution(vector<long long> a, vector<long long> b){
		int n = a.size() + b.size();
		int N = 1;
		while(N < n) N *= 2;
		a.resize(N);
		b.resize(N);
		long long h = ex(g, (mod - 1) / N);
		fft(a, h);
		fft(b, h);
		for(int i = 0; i < N; ++i) a[i] = mul(a[i], b[i]);
		h = inv(h);
		fft(a, h);
		long long iN = inv(N);
		for(int i = 0; i < N; ++i) a[i] = mul(a[i], iN);
		return a;
	}
};

const long long mod = 924844033;

long long fact[200200];
long long ifact[200200];
long long is[200200];

inline long long mul(long long a, long long b){
	return (a * b) % mod;
}

void init(){
	int MA = 200200;
	fact[0] = 1;
	for(int i = 1; i < MA; ++i){
		fact[i] = mul(fact[i - 1], i);
	}
	is[1] = 1;
	for(int i = 2; i < MA; ++i){
		int k = mod / i;
		int r = mod % i;
		long long tmp = is[r] * (-k);
		tmp %= mod;
		if(tmp < 0) tmp += mod;
		is[i] = tmp;
	}
	ifact[0] = 1;
	for(int i = 1; i < MA; ++i){
		ifact[i] = mul(ifact[i - 1], is[i]);
	}
}

long long C(int n, int k){
	long long ans = fact[n];
	ans = mul(ans, ifact[k]);
	ans = mul(ans, ifact[n - k]);
	return ans;
}

vector<int> G[200200];
int N;

void input(){
	scanf("%d", &N);
	for(int i = 0; i < N - 1; ++i){
		int u, v;
		scanf("%d%d", &u, &v);
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
}

int par[200200];
int sz[200200];

int cnt[200200];

void dfs(int v, int p){
	sz[v] = 1;
	par[v] = p;
	for(int i = 0; i < G[v].size(); ++i){
		int u = G[v][i];
		if(u == p) continue;
		dfs(u, v);
		sz[v] += sz[u];
	}
}

long long ans[200200];

void solve(){
	dfs(0, -1);
	for(int v = 1; v < N; ++v){
		cnt[sz[v]]++;
		cnt[N - sz[v]]++;
	}
	vector<long long> a, b;
	for(int i = 1; i < N; ++i){
		a.push_back(mul(cnt[i], fact[i]));
	}
	for(int i = N - 2; i >= 0; --i){
		b.push_back(ifact[i]);
	}
	FFT fft(mod, 44009197);
	vector<long long> c = fft.convolution(a, b);
	for(int i = 1; i <= N; ++i){
		long long tmp = c[N - 3 + i];
		ans[i] = mul(N, C(N, i)) - mul(tmp, ifact[i]);
		ans[i] %= mod;
		ans[i] += mod;
		ans[i] %= mod;
	}
}

int main(){
	input();
	init();
	solve();
	for(int i = 1; i <= N; ++i){
		printf("%lld\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 44504
// A Dynamic Programming based 
// C# program to find minimum 
// number operations to 
// convert str1 to str2 
using System;
using System.Collections.Generic;
using System.Linq;
class GFG
{
    static int k = 0;
    static Dictionary<string, bool> ans = new Dictionary<string, bool>();
    public static void Main()
    {
        var input = Console.ReadLine().Split(' ');
        var x = long.Parse(input[0]);
        var y = long.Parse(input[1]);
        Game(x, y);
    }

    static void Game(long x, long y)
    {

        if (Math.Abs(x - y) <= 1)
            Console.Write("Brown");
        else
            Console.Write("Alice");

    }





}



Measured memory_bytes: 13152
#include<stdio.h>
#define N 44

int f(int);

int F[N];
int main()
{
  int n;
  scanf("%d",&n);
  printf("%d\n",f(n));
  return 0;
}

int f(int n)
{
  if(n==0||n==1)
    return F[n]=1;
  if(F[n]!=0)
    return F[n];
  else
    return F[n]=f(n-2)+f(n-1);
}

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

signed main(){
    int N,M; cin>>N>>M;
    vector<int> A(N);
    int sum=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    int ans=0;
    double end=sum/4.0/M;
    for(int i=0;i<N;i++){
        if(A[i]>=end)ans++;
    }
    //cout<<end<<endl;
    cout<<(ans>=M ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] suki = new int[m+1];
    for(int i = 0;i<n;i++){
      int k = sc.nextInt();
      for(int j = 0;j<k;j++){
        suki[sc.nextInt()]++;
      }
    }
    int all=0;
    for(int i = 1;i<=m;i++){
      if(suki[i]==n)all++;
    }
    System.out.println(all);
  }
}


Measured memory_bytes: 38808
#include <stdio.h>

int main()
{
	int i, x, y, z, N, count[10001] = {}, tmp;
	scanf("%d", &N);
	for (x = 1; x <= 100; x++) {
		for (y = 1; y <= 100; y++) {
			for (z = 1; z <= 100; z++) {
				tmp = x * x + y * y + z * z + x * y + y * z + z * x;
				if (tmp <= N) count[tmp]++;
			}
		}
	}
	for (i = 1; i <= N; i++) printf("%d\n", count[i]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

string divide[4] = {"dream","dreamer","erase","eraser"};

int main(){
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    rep(i,4) reverse(divide[i].begin(),divide[i].end());
    bool flag = 1;
    for(int i = 0;i<s.size();){
        bool flag2 = 0;
        rep(j,4){
            string d = divide[j];
            if(s.substr(i,d.size()) == d){
                flag2 = 1;
                i += d.size();
            }
        }
        if(!flag2){
            flag = 0;
            break;
        }
    }
    if(flag) cout << "YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 512