akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var S = cin.Read;
            if(S == "Sunny")
            {
                WriteLine("Cloudy");
            }
            else if(S == "Cloudy")
            {
                WriteLine("Rainy");
            }
            else
            {
                WriteLine("Sunny");
            }
        }

        /*public long C(long n, long r)
        {
            if (r == 0 || r == n) return 1L;
            if (n < r) return 0L;
            long[,] Pascal = new long[n + 1, n + 1];
            Pascal[0, 0] = 1;
            for (long i = 1; i <= n; i++)
            {
                Pascal[i, 0] = 1;
                Pascal[i, i] = 1;
                for (long j = 1; j < n; j++)
                {
                    Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
                }
            }
            return Pascal[n, r];
        }*/

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 11220
#define _USE_MATH_DEFINES
#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,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
struct edge { int to, cost; };

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

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

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

    int n, ans = 0;
    string s;
    cin >> n >> s;
    rep(i, s.size() - 2) {
        if (s.substr(i, 3) == "ABC") {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
	int N,K;
	string S;

	cin >> N >> K;
	cin >> S;

	if(S[K-1]=='A')S[K-1]='a';
	if(S[K-1]=='B')S[K-1]='b';
	if(S[K-1]=='C')S[K-1]='c';
	cout << S;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
	long long k,a,b;
	cin>>k>>a>>b;
	if(a>=k){
		cout<<1<<endl;
		return 0;
	}
	if(a<=b){
		cout<<-1<<endl;
		return 0;
	}
	cout<<((k-a)/(a-b)+((k-a)%(a-b)>=1))*2+1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

ll extgcd(ll a, ll b, ll &x, ll &y)
{ //extended Euclidean algorithm, used for modular multiplicative inverse
    ll d = a;
    if (b != 0)
    {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    else
    {
        x = 1;
        y = 0;
    }
    return d; //return gcd(a,b)
}

ll mod_inv(ll a, ll m = MOD)
{ //return inv(a) mod m, ax+my=gcd(a,m)=1, m is prime int, ax-1=mq equiv. ax-mq=1
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m; //From (possibly) negative x to positive x
}

vector<ll> powa,powb;
void calc_power(int n, ll a, ll b, ll m = MOD)
{ //Calculate power of p_a,p_b up to n
    powa.resize(n + 1);
    powb.resize(n + 1);
    powa[0] = powb[0] = 1;
    ll invhund = mod_inv(a+b);
    REP(i, n)
    {
        powa[i + 1] = powa[i] * a % m * invhund % m;
        powb[i + 1] = powb[i] * b % m * invhund % m;
    }
}

vector<ll> expcpow;
void calc_expcpower(int n, ll expc, ll m = MOD)
{ //Calculate power of p_a,p_b up to n
    expcpow.resize(n + 1);
    expcpow[0] = 1;
    REP(i, n)
    {
        expcpow[i + 1] = expcpow[i] * expc % m ;
    }
}

vector<ll> fact, invfact;
void calc_fact(int n, ll m = MOD)
{ //Calculate factorial up to n
    fact.resize(n + 1);
    invfact.resize(n + 1);
    fact[0] = invfact[0] = 1;
    REP(i, n)
    {
        fact[i + 1] = fact[i] * (i + 1) % m;
        invfact[i + 1] = invfact[i] * mod_inv(i + 1) % m;
    }
}
ll perm(int n, int k, ll m = MOD)
{
    if (n < 0 || k < 0 || k > n)
        return 0;
    return fact[n] * invfact[n - k] % m;
}
ll comb(int n, int k, ll m = MOD)
{
    if (n < 0 || k < 0 || k > n)
        return 0;
    return (fact[n] * invfact[n - k] % m) * invfact[k] % m;
}

ll a,b,c,N,expc;

int main()
{
    cin >> N >> a >> b >> c;
    if (c != 0)
    {
        //expc = 100 * 100 % MOD * mod_inv((100 - c) * (100 - c), MOD) % MOD;
        expc = 100 * mod_inv((100 - c)) % MOD;
    }else{
        expc = 1;
    }
    //a = a * expc % MOD;
    //b = b * expc % MOD;
    //cout << dfs(0, 1, 1, 0, 0) << endl;
    calc_fact(2*N+1);
    calc_power(2*N+1,a,b);
    calc_expcpower(2 * N, expc);
    ll tot = 0;
    FOR(i, N, 2 * N)
    {
        tot = (tot + (comb(i - 1, N - 1) * i % MOD * (((powa[N] * powb[i - N] % MOD) + (powb[N] * powa[i - N] % MOD)) % MOD) % MOD)) % MOD;
    }
    tot = tot * expc % MOD;
    cout << tot << endl;
}

Measured memory_bytes: 8080
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int n, d; cin >> n >> d;

    int ans = 0;

    if(n % (2*d+1) == 0){
        ans = n / (2*d + 1);
    }
    else{
        ans = n / (2*d + 1) + 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;



int main()
{
    fastInp;

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a * c, a * d), max(b * c, b * d));
    
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    
    if(0<x && x<W && 0<y && y<H){
        if(x-r >= 0 && y-r >= 0 && x+r <= W && y+r <= H){
            printf("Yes\n");
        }
        else printf("No\n");
    }
    else printf("No\n");
}


Measured memory_bytes: 2696
#define  REP(i, s, e) for(register int i = s; i <= e ;i++)
#define DREP(i, s, e) for(register int i = s; i >= e ;i--)

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <bitset>
#include <vector>
#include <queue>
#include <cmath>
#include <map>

using namespace std;
const int maxn = 200010;

template <typename T> T read() {
	T ans(0), p(1);
	char c = getchar();
	while (!isdigit(c)) {
		if (c == '-') p = -1;
		c = getchar();
	}
	while (isdigit(c)) {
		ans = ans * 10 + c - 48;
		c = getchar();
	}
	return ans * p;
}

int m, n, k;
int b[maxn];

map<int, int>M;

int main() {
#ifdef CraZYali
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	n = read<int>();
	REP(i, 1, n) 
		M[read<int>()]++;	
	m = read<int>();
	if (m > n) {
		cout << "NO";
		return 0;
	}
	REP(i, 1, m) {
		b[i] = read<int>();
		M[b[i]]--;
	}
	REP(i, 1, m)
		if (M[b[i]] < 0) {
			cout << "NO";
			return 0;
		}
	cout << "YES";
	return 0;
}

Measured memory_bytes: 10368
#include<stdio.h>
int main(void){
    int a=0,b=0,c=0,d=0,e=0,f=0;
    double x=0,y=0;
    while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)!=EOF){
        x=(double)(c*e-b*f)/(a*e-b*d);
        y=(double)(c*d-a*f)/(b*d-a*e);
        
        if(x==-0)x=0;
        if(y==-0)y=0;
        printf("%.3lf %.3lf\n",x,y);
        
    }
    return 0;
    }

Measured memory_bytes: 636
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include <algorithm>
#include <vector>

const long MOD = 1000000007;

long long kaijo(long a, long b)
{
    if(b==0) {
        return 1;
    }
    else if(b%2==0) {
        long long tmp = kaijo(a, b/2) % MOD;
        return (tmp * tmp) % MOD; 
    }
    else {
        return (kaijo(a, b-1) * a) % MOD;
    }
}

long long st_calc( long a, long b )
{
    long long tmp = 0;

    tmp += a * kaijo(3, b) % MOD;
    if(b>0) {
        tmp += kaijo(3, b-1) * b;
    }

    return (tmp % MOD);
}

int main(int argc, char* argv[])
{
    char str[100001]={0};
    scanf("%s", str);
    long len = strlen(str);

    std::vector<long> num_a(len+1);
    std::vector<long> num_c(len+1);
    std::vector<long> num_u(len+1);

    long i;
    for(i=0; i<len; i++) {
        if(str[i]=='A')
            num_a[i] ++;
        else if(str[i]=='C')
            num_c[i] ++;
        else if(str[i]=='?')
            num_u[i] ++;
    }

    for(i=1; i<len; i++) {
        num_a[i] += num_a[i-1];
        num_c[i] += num_c[i-1];
        num_u[i] += num_u[i-1];
    }

    long long sum = 0;
    for(i=1; i<len-1; i++) {
        if(str[i]=='B' || str[i]=='?') {
            sum += (long long)st_calc(num_a[i-1], num_u[i-1]) * st_calc(num_c[len-1] - num_c[i], num_u[len-1] - num_u[i]);
            sum %= MOD;
        }
    }

    printf("%lld\n", sum);

    return 0;
}


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

int main() {
    int X;
    cin >> X;
    if (X < 600) cout << 8 << endl;
    else if (X < 800) cout << 7 << endl;
    else if (X < 1000) cout << 6 << endl;
    else if (X < 1200) cout << 5 << endl;
    else if (X < 1400) cout << 4 << endl;
    else if (X < 1600) cout << 3 << endl;
    else if (X < 1800) cout << 2 << endl;
    else if (X < 2000) cout << 1 << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  string s;
  cin >> s;
  int n = s.size(), S = 0;
  char a;
  for(int i = 0;i < n;i++) {
    S += s[i] - 48;
  }
  cout << ((S % 9 == 0) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3676
direct = ((0, -1), (0, 1), (-1, 0), (1, 0))

def comb(color, mp, pos):
  end = len(pos)
  ind = 0
  while ind < end:
    x, y = pos[ind]
    for dx, dy in direct:
      nx, ny = x + dx, y + dy
      if (nx, ny) not in pos and mp[ny][nx] == color:
        pos.append((nx, ny))
        end += 1
    ind += 1

def search(rest, now_color, goal_color, pos, mp):
  if rest == 0:
    return len(pos)
  if rest == 1:
    if now_color != goal_color:
      next_pos = pos[:]
      comb(goal_color, mp, next_pos)
      return len(next_pos)
    else:
      return 0

  ret = 0
  for next_color in range(1, 7):
    if next_color != now_color:
      next_pos = pos[:]
      comb(next_color, mp, next_pos)
      ret = max(ret, search(rest - 1, next_color, goal_color, next_pos, mp))
  return ret

def main():
  while True:
    h, w, c = map(int, input().split())
    if h == 0:
      break
    mp = [[-1] + list(map(int, input().split())) + [-1] for _ in range(h)]
    mp.insert(0, [-1] * (w + 2))
    mp.append([-1] * (w + 2))
    init_pos = [(1, 1)]
    init_color = mp[1][1]
    comb(init_color, mp, init_pos)
    print(search(5, init_color, c, init_pos, mp))
main()


Measured memory_bytes: 5628
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

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

	int N;
	cin >> N;

	cout << ((N - 1) / 111 + 1) * 111 << "\n";

	return 0;
}

Measured memory_bytes: 256
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {      
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);

            var d = a / b;
            var r = a % b;
            var f = (double)a / b;

            Console.WriteLine("{0} {1} {2:f8}",d,r,f);
        }
    }
}

Measured memory_bytes: 5660
#include<iostream>
#include<cmath>
using namespace std;
long long gcd(long long a, long long b) {
	return b == 0 ? a : gcd(b, a % b);
}
bool isprime(long long i) {
	if (i == 2)
		return 1;
	for (int j = 2; j <= sqrt(i) + 1; j++)
		if (i % j == 0)
			return 0;
	return 1;
}
int main() {
	long long m, n;
	int cnt=1;
	cin >> m >> n;
	long long a;
	a=gcd(m, n);
	if (a == 1) {
		cout << 1;
		return 0;
	}
	if (isprime(a)) {
		cout << 2;
		return 0;
	}
	for (int i = 2; i <=sqrt(a) + 0.5; i++)
	{
		if (a % i == 0 && i <= a / i) {
			if (isprime(i))
				cnt++;
			if (i < a / i && isprime(a/i))
				cnt++;
		}
		
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	var jpy, btc float64
	for i := 0; i < n; i++ {
		var value float64
		var currency string
		_, _ = fmt.Scan(&value, &currency)
		switch currency {
		case "JPY":
			jpy += value
		case "BTC":
			btc += value
		}
	}
	fmt.Println(jpy + btc*380000)
}


Measured memory_bytes: 512
N = gets.to_i
peoples = gets.split.map(&:to_i)
sum_minus, sum, sum_plus = 0, 0, 0
mid = (peoples.inject(:+) / peoples.length)
#mid = (peoples.max + peoples.min) / 2
mid_minus = mid - 1
mid_plus = mid + 1

peoples.each { |p|
  sum_plus += (p - mid_plus) ** 2
  sum_minus += (p - mid_minus) ** 2
  sum += (p - mid) ** 2
}

puts [sum_plus, sum,sum_minus].min

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    double res = 0.0;
    REP(i, N) {
        cin >> a[i];
        res += a[i];
    }
    double ans = res / N;
    int aa;
    double b = 1000000;
    reverse(a.begin(), a.end());
    REP(i, N) {
        if(abs(a[i] - ans) <= b) {
            b = abs(a[i] - ans);
            aa = i;
        }
    }
    cout << N - aa - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string s, t;
  cin >> s >> t;
  long ans = 0;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) != t.at(i))ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3916
def solv(n, x)
  ans = []
  (1..n).each do |a|
    (a + 1..n).each do |b|
      (b + 1..n).each do |c|
        ans << [a, b, c] if a + b + c == x
      end
    end
  end
  puts ans.sort.uniq.length
end

loop do
  prob = gets.split.map(&:to_i)
  break if prob == [0, 0]
  solv(*prob)
end

Measured memory_bytes: 8812
#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_V 100
#define MAX_E 1000
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cap, cost, rev;
	edge(int to_, int cap_, int cost_, int rev_)
		: to(to_), cap(cap_), cost(cost_), rev(rev_) {}
};

int V, E;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

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

int MinimumCostFlow(int s, int t, int f) {
	int res = 0;
	fill(h, h + V, 0);
	while (f > 0) {
		priority_queue<P, vector<P>, greater<P>> que;
		fill(dist, dist + V, INF);
		dist[s] = 0;
		que.push(P(0, s));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			int v = p.second;
			if (dist[v] < p.first) continue;
			for (int i = 0; i < G[v].size(); i++) {
				edge &e = G[v][i];
				if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(P(dist[e.to], e.to));
				}
			}
		}
		if (dist[t] == INF) return -1;
		for (int v = 0; v < V; v++)
			h[v] += dist[v];
		int d = f;
		for (int v = t; v != s;v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * h[t];
		for (int v = t; v != s;v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int main()
{
	int F;
	cin >> V >> E >> F;
	for (int i = 0, u, v, c, d; i < E; i++) {
		cin >> u >> v >> c >> d;
		AddEdge(u, v, c, d);
	}
	cout << MinimumCostFlow(0, V - 1, F) << endl;
	return 0;
}

Measured memory_bytes: 3140
#include<iostream>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	double a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	double sum=0;
	for(int i=0;i<n;++i)
		sum+=a[i];
	double ss=sum*1.0/(4*m);
	int tot=0;
	for(int i=0;i<n;++i)
		if(a[i]>=ss)
			++tot;
	if(tot>=m)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  if(A==1){
    A=14;
  }
  if(B==1){
    B=14;
  }
	if(A<B){
      cout<<"Bob"<<endl;
    }else if(A>B){
      cout<<"Alice"<<endl;
    }else{
      cout<<"Draw"<<endl;
    }
  return 0;
}

Measured memory_bytes: 256
(*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*)

open System;

let n = int(Console.ReadLine())
let s = Console.ReadLine()
let l = s.Length

let rec ans i str = 
    if i < l then ans (i+1) (str + string(char((int(s.[i]) - int('A') + n) % 26 + int('A'))))
    else str

Console.WriteLine(ans 0 "")

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

int main()
{
  long long int a, b, now;
  int ans = 0;

  cin >> a >> b;

  now = a;
  while (a <= now && b >= now) {
    ans++;
    now *= 2;
  }

  cout << ans << endl;
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,k;
  cin >> n;
  int a[n] = {};
  int maxA = 0;
  priority_queue<int, vector<int>, greater<int> > queue;
  for(int i=0;i<n;i++){
    cin >> a[i];
    queue.push(a[i]);
    if(maxA<a[i]) maxA=a[i];
  }
  bool isMultiple[maxA+1] = {};
  int count = 0;
  int prevX = 0;
  bool isCounted = false;

  while(!queue.empty()){
    int x = queue.top();
    queue.pop();
    if(prevX == x && isCounted){
      count--;
    }
    prevX = x;
    isCounted = false;
    if(isMultiple[x]) continue;
    count++;
    isCounted = true;
    int y = x;
    while(y<=maxA){
   	  isMultiple[y] = true;
      y += x;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 5724
import java.util.Scanner;

// 14
class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();

        long tmp;
        n -= (n / k) * k;
        while(true) {
            tmp = n;
            n = Math.abs(n - k);
            if(tmp < n) break;
        }

        System.out.println(tmp);
    }

}


Measured memory_bytes: 35444
#include<stdio.h>
#include<math.h>

int main( int argc, char *argv[] ) 
{

	double a, b, C;

	scanf( "%lf%lf%lf", &a, &b, &C );
	
	double radianC = ( C * M_PI )/180.0;
	double h = sin( radianC ) * b;
	double S = a * h * 0.5;
	
	double L = sqrt( pow( ( a-( cos( radianC ) * b ) ), 2 ) + pow( h, 2 ) );
	L = L + a + b;
		
	printf( "%lf\n%lf\n%lf\n", S, L, h );

    return 0;
}

Measured memory_bytes: 648
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
import numpy.random as random
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    # D = 365
    #お試し
    random.seed(2020)
    D = int(readline())
    C = list(map(int, readline().split()))
    S = list(list(map(int, readline().split())) for _ in range(D))

    for _ in range(D):
        print(random.randint(1,26))


if __name__ == '__main__':
    main()


Measured memory_bytes: 27420
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      r: usize,
    }
    puts!("{}\n", r*r);
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC127A
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] n = Console.ReadLine().Split(' ');
			int a = int.Parse(n[0]);
			int b = int.Parse(n[1]);
 
			if (a <= 5)
				Console.WriteLine(0);
 
			else if (a >= 13)
				Console.WriteLine(b);
 
			else
				Console.WriteLine(b / 2);
 
			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 11092
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 2000000;
int n, s;
vector < int > ans;
vector < int > g[N], b[2];
set < int > h[N];
int a[N], p[N], dep[N], l[N], r[N], color[N];
int solve(){
    set < pair < int, int > > le;
    set < pair < int, int > > re;
    for (int i = 1; i <= n; i++){
        le.insert({-l[i], i});
        re.insert({r[i], i});
    }
    int res = 0;
    int p = 0;
    int c = 1;
    while(1){
     //   cout << p << endl;
        if (c == 1){
            if (le.size() == 0) return res + abs(p);
            int x = -(*le.begin()).F;
            int in = (*le.begin()).S;
          //  cout << x << endl;
            if (x <= p) return res + abs(p);
            res += abs(p - x);
            p = x;
            le.erase(le.begin());
            re.erase({r[in], in});
            c = 0;
        } else{
            if (re.size() == 0) return res + abs(p);
            int x = (*re.begin()).F;
            int in =(*re.begin()).S;
            if (x >= p) return res + abs(p);
            res += abs(p - x);
            p = x;
            re.erase(re.begin());
            le.erase({-l[in], in});
            c = 1;
        }
    }
    cout << endl;
    return res + abs(p);
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  //  freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> l[i] >> r[i];
    }
    int ans = solve();
    for (int i = 1; i <= n; i++){
        r[i] = -r[i];
        l[i] = -l[i];
        swap(l[i], r[i]);
    }
    ans = max(ans, solve());
    cout << ans;
}


Measured memory_bytes: 161152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(a.rbegin(), a.rend());
	priority_queue<ll> pq;
	pq.push(a[0]);
	ll ans = 0;
	rrep(i, n) {
		ll now = pq.top(); pq.pop();
		ans += now;
		pq.push(a[i]);
		pq.push(a[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6892
import re
import math

def fib(n):
    a, b = 0, 1
    if n == 1:
        return a
    elif n == 2:
        return b
    else:
        for i in range(n-2):
            a, b = b, a + b
        return b

n,m = map(int, input().split())
step = ['0']*(n+1)
for i in range(m):
    a = int(input())
    step[a] = '1'
steps = ''.join(step)

a = re.findall('000*', steps)
b = len(re.findall('11', steps))
# print(steps)
count = 1
for i in a:
    count *= fib(len(i)+1) % 1000000007

if b != 0:
    print(0)
else:
    print(count % 1000000007)


Measured memory_bytes: 7404
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
using namespace std;
//
const int inf=1e9+7;//0x3f
//
char M[100][100];
bool h[100],w[100];
int main(){
	int H,W;
	cin>>H>>W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>M[i][j];
		}
	}
	for(int i=0;i<H;i++){
		bool f=true;
		for(int j=0;j<W;j++){
			if(M[i][j]=='#'){
				f=false;
				break;
			}
		}
		h[i]=f;
	}
	for(int i=0;i<W;i++){
		bool f=true;
		for(int j=0;j<H;j++){
			if(M[j][i]=='#'){
				f=false;
				break;
			}
		}
		w[i]=f;
	}
	//
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(h[i]||w[j]){
				continue;
			}else{
				cout<<M[i][j];
			}
		}
		if(!h[i]){
			cout<<endl;
		}
	}
	return 0;
}

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

int main()
{
    int num;
    std::cin >> num;
    std::vector<int> values(num);
    for (size_t i {}; i < num; ++i)
        std::cin >> values[i];
    int count {};
    for (int i {}; i < num; ++i)
        if (values[i] != i + 1)
            ++count;
    if (count <= 2)
        std::cout << "YES";
    else
        std::cout << "NO";
}

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

int main(){
	string s;
  	int c = 0;
  	cin >> s;
  	if(s[0]=='1') c++;
   	if(s[1]=='1') c++;
    if(s[2]=='1') c++;
  	cout << c << endl;
}

Measured memory_bytes: 256
// AOJ 1244
#include<iostream>
#include<string>
#include<map>
#include<sstream>
using namespace std;

typedef long long int integer;

int c;
string str;

/* 
 * Molecule -> [Atom | Atom Number | ( Molecule ) Number]*
 * Atom -> Capital | Capital Small
 * Number -> Digit | Digit Digit
 * Capital -> [A-Z]
 * Small -> [a-z]
 * Digit -> [0-9]
 */

integer Molecule();
integer Atom();
integer Number();

integer Z() {
  try {
    integer m = Molecule();
    return m;
  } catch (int e) {
    return -1;
  }
}

integer Molecule() {
  integer sum = 0;
  while (str[c] == '(' or ('A' <= str[c] and str[c] <= 'Z')) {
    if (str[c] == '(') {
      c++; // read (
      integer molecule = Molecule();
      c++; // read )
      integer number = Number();
      sum += molecule * number;
    } else {
      integer atom = Atom();
      if (isdigit(str[c])) {
        integer number = Number();
        atom *= number;
      }
      sum += atom;
    }
  }
  return sum;
}

map<string,integer> table;

integer Atom() {
  string name;
  name.push_back(str[c]);
  c++; // read[A-Z]
  if ('a' <= str[c] and str[c] <= 'z') {
    name.push_back(str[c]);
    c++; // read [a-z]
  }
  if (table.find(name) == table.end()) {
    throw -1;
  } else {
    return table[name];
  }
}

integer Number() {
  integer val = 0;
  while (isdigit(str[c])) {
    val = val * 10 + (str[c] - '0');
    c++; // read [0-9]
  }
  return val;
}

int main() {
  string line;
  while (cin >> line and line != "END_OF_FIRST_PART") {
    int mass;
    cin >> mass;
    table[line] = mass;
  }

  while (cin >> line and line != "0") {
    c = 0;
    str = line;
    integer ans = Z();
    if (ans == -1) {
      cout << "UNKNOWN" << endl;
    } else {
      cout << ans << endl;
    }
  }
}

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

int main(){
  int x,y,z, ans=0;
  cin >>x>>y>>z;
  while(x>=y+z){
    x-=z;
    if(x >=y+z){
      x-=y;
      ans++;
    }
  }
  cout << ans;
  return 0;
}


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

int Partition(int*,int,int);

main(){
  int i,n,*A,check;

  scanf("%d",&n);

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

  check=Partition(A,0,n-1);
  
  for(i=0;i<check;i++){
    printf("%d",A[i]);
    if(i<=check)printf(" ");
  }

  printf("[%d] ",A[check]);

  for(i=check+1;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }

  printf("\n");
  return 0;
}


int Partition(int *A,int p,int r){
  int x,i,j,temp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  return i+1;
}    

Measured memory_bytes: 996
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string s,ans="";
    cin>>n>>s;
    for (int i=0;i<n;i++) {
        if (i!=n-1&&s.at(i)!=s.at(i+1)) {
            ans+=s.at(i);
        }
    }
    ans+=s.at(n-1);
    cout<<ans.size()<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

int n, *ns;

bool isMa(int num, int cur, int i){
	if(i == n) return false;
	if(cur + ns[i] == num) return true;
	else return isMa(num, cur, i+1) || isMa(num, cur+ns[i], i+1);
}

int main() {
	scanf("%d", &n);
	ns = new int[n];
	for(int i = 0; i < n; i++){
		scanf("%d", &ns[i]);
	}
	
	int q;
	scanf("%d", &q);
	for(int i = 0; i < q; i++){
		int qNum;
		scanf("%d", &qNum);
		printf("%s\n", isMa(qNum, 0, 0) ? "yes" : "no");
	}
	
    return 0;
}

Measured memory_bytes: 1168
def test():
    a = []
    count = 0

    for i in range(5):
        a.append(int(input()))
    k = int(input())

    b = max(a)
    b -= min(a)

    if b <= k:
        print("Yay!")
    else:
        print(":(")


if __name__ == "__main__":
    test()


Measured memory_bytes: 3060
// atcoder/abc048/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

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

  lli a, b, x;
  while (cin >> a >> b >> x) {
    if (a == 0) a = 0;
    else a = (a - 1) / x + 1;
    b = b / x + 1;

    cout << b - a << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int N, L, ret = 0,min = 0,tmp = 0,pnt = 1;
  scanf("%d %d\n",&N,&L);
  for(int i=1; i <= N; i++){
  	tmp= L+i-1;
    ret += tmp;
    if(tmp < 0){
    	tmp *= -1;
    }
    if(tmp < min || i == 1){
    	min = tmp;
      	pnt = i;
    }
  }
  	printf("%d\n",ret -L-pnt+1);
 	return 0; 
}

Measured memory_bytes: 128
"""
・あるTについて、とりうる全てのSで支払う最小コストの和は、どのようにTをとっても同じ
　→Tを00~0と考えて、最後に2**N倍（Tのとりうる個数倍）してあげるとよい
・そうすると、各桁を独立して調べていける。
　Cは明らかにソートしてよい。Dが大きいときはCの小さいものをあてがう。
　これにより、ある桁の左にある個数と右にある個数に着目して、それらがとりうる組み合わせの数は何通りあるか考えることで桁ごとの最小コストが分かり、
　それを全てのけたについて足し合わせたものに、2**Nかけるとこたえになる


"""

import sys
sys.setrecursionlimit(10**6)


N = int(input())
C = list(map(int, input().split()))
C.sort()
MOD = 10**9 + 7


ans = 0
# どうも公式ドキュメントによると、組み込み関数のpowの第三引数に値渡すとMODとってくれるらしいので、完全に無駄
# 速くないのでシフト演算とかで置き換えたほうがいいっぽい（どのみち使う必要ないのでやらないけど）
def pow_mod(x, n, mod):
    if n == 0:
        return 1 % mod
    elif n % 2 == 0:
        y = pow_mod(x, n//2, mod)
        return y * y % MOD
    else:
        return x * pow_mod(x, n-1, mod) % mod

for i in range(N):
    # 詳細は開設動画の通りだが、i桁目の右にr個の数字、左にlこの数字がある
    l = i
    r = N - i - 1
    # i桁目の寄与が C[i] * 2**l * (2**r + r * 2**(r-1))で、最後に2**Nをかける（Tのとり方が2**Nこあるので）
    # -> C[i] * 2**l * (2**(N+r) + r * 2**(r+N-1))
    ans += ((C[i] * pow(2, l, MOD)) % MOD * (pow(2, N+r, MOD) + r * pow(2, N+r-1, MOD))) % MOD
    ans %= MOD

print(ans)

Measured memory_bytes: 27116
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

vi rnk, par;

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

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rnk[x] < rnk[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rnk[x] == rnk[y])rnk[x]++;
	}
}

bool same(int x, int y) {
	return (find(x) == find(y));
}
/*
int main() {
	int n, m, a, b, q;
	cin >> n >> m;
	par.resize(n);
	rnk.resize(n);
	rep(i, n) {
		par[i] = i;
		rnk[i] = 0;
	}

	rep(i, m) {
		cin >> a >> b;
		unite(a, b);
	}
	cin >> q;
	rep(i, q) {
		cin >> a >> b;
		cout << (same(a, b) ? "yes" : "no") << endl;
	}

}
*/
int main() {
	int n, m,tmp1,tmp2,ans=0;
	cin >> n >> m;
	vi p(n+1, 0);
	par.resize(n+1);
	rnk.resize(n+1);
	for (int i = 1; i < n+1; i++) {
		cin >> p[i];
		par[i] = i;
		rnk[i] = 0;
	}
	for (int i = 0; i < m; i++) {
		cin >> tmp1 >> tmp2;
		unite(tmp1, tmp2);
	}
	for (int i = 1; i < n+1; i++) {
		if (same(p[i], i )) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;

const int nmax=8;
bool graph[nmax][nmax];

int dfs(int v, int N,bool visited[nmax]){
    bool all_visited=true;

    for(int i=0; i<N; i++){
        if(visited[i]==false)
        all_visited=false;
    }

    if(all_visited){
        return 1;
    }
    int ret=0;

    for(int i=0; i<N; i++){
        if(graph[v][i]==false) continue;
        if(visited[i]) continue;

        visited[i]=true;
        ret+=dfs(i,N,visited);
        visited[i]=false;
    }

    return ret;
}

int main(){
    int N,M; cin >> N >> M;
    for(int i=0; i<M; i++){
        int A,B;
        cin >> A >> B;
        graph[A-1][B-1]=graph[B-1][A-1]=true;
    }

    bool visited[nmax];
    for(int i=0; i<N; i++){
        visited[i]=false;
    }

    visited[0]=true;
    cout << dfs(0,N,visited) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int ll;

int main() 
{ 
    FIO
    string s;
    cin >> s;

    if(s[2]==s[3] && s[4]==s[5])
    {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
    return 0; 
} 


Measured memory_bytes: 256
<?php
$dArray = array();
while (!feof(STDIN)) {
  $param = trim(fgets(STDIN));
  if (empty($param)) {
    break;
  }
  array_push($dArray, $param);
}

$maxX = 600;

foreach ($dArray as $d) {
  $count = $maxX / $d;
  $area = 0;
  for($i = 1; $i < $count; $i++) {
    $area += pow($d * $i, 2) * $d;
  }
  echo $area . "\n";
}

Measured memory_bytes: 15260
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = 0;
		for(int i = 1; i <= n; i++) {
			long y = n/i;
			ans+=y*(y+1)*i/2;
		}
		System.out.println(ans);
    }
}

Measured memory_bytes: 35536
import math
n = int(input())
a = list(map(int,input().split()))
g = 1
mod = 10**9 + 7
ans = 0
for i in range(n):
    u = (g*a[i])//math.gcd(g,a[i])
    ans *= u//g
    ans %= mod
    ans += u//a[i]
    ans %= mod
    g = u
print(ans)

Measured memory_bytes: 74860
# A B C
# 1 1 1
# 2 0 1
# 2 1 0
# 1 2 1
# それぞれ1以上の場合は問題ない
# 2人以上が1以上の場合はok
# では2人以上が0の場合は？
# 1 1 0 
# 0 1 1 C
# 1 0 1 A


# 合計が0の場合
# A B C
# 0 0 0

# 合計が1の場合
# A B C
# 1 0 0
# 0 1 0 AB => B
# 0 1 0 AC => No
# ==> sによる

# 合計が2の場合
# A B C
# 2 0 0
# 1 1 0 AB => B
# 0 1 1 AC => C
# 初回で0の組み合わせが選択されなければYes

# 合計が3以上の場合も同様に、初回で2つ以上が0でなければYesになる

from typing import Tuple, List, Optional

def play(N: int, A: int, B: int, C: int, s_arr: List[str]) -> Tuple[bool, Optional[List[str]]]:
    strategies = []
    v_dict = {'A': A, 'B': B, 'C': C}

    if A + B + C == 0:
        return (False, None)
    
    elif A + B + C == 1:
        prime = 'A' if A else 'B' if B else 'C'

        for s in s_arr:
            if prime in s:
                prime = s.replace(prime, '')
                strategies.append(prime)
            else:
                return (False, None)

    else:
        # 1 1 0 AB => B
        # 0 2 0 AC => No
        # 次のターンの文字列を見る
        # 1 1 0 AB => C
        # 0 1 1 AC => A
        for i in range(N):
            s = s_arr[i]
            if len(list(filter(lambda c: v_dict[c] == 0, s))) == 2:
                return (False, None)
            else:
                n, m = v_dict[s[0]], v_dict[s[1]]
                if n < m:
                    v_dict[s[0]] += 1
                    v_dict[s[1]] -= 1
                    strategies.append(s[0])
                elif n > m:
                    v_dict[s[0]] -= 1
                    v_dict[s[1]] += 1
                    strategies.append(s[1])                
                elif i < N - 1 and n == m and s[0] in s_arr[i+1]:
                    v_dict[s[0]] += 1
                    v_dict[s[1]] -= 1
                    strategies.append(s[0])
                elif i < N - 1 and n == m and s[1] in s_arr[i+1]:
                    v_dict[s[0]] -= 1
                    v_dict[s[1]] += 1
                    strategies.append(s[1])
                else:
                    v_dict[s[0]] -= 1
                    v_dict[s[1]] += 1
                    strategies.append(s[1])


    return (True, strategies)


if __name__ == '__main__':
    N, A, B, C = map(int, input().split())
    s = [input() for _ in range(N)]

    result, strategy = play(N, A, B, C, s)
    if result:
        print('Yes')
        print('\n'.join(strategy))
    else:
        print('No')



Measured memory_bytes: 24796