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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct BIT{
    int N;
    vector<int>dat;
    void init(int n){
        N=n;
        dat.resize(N+1);
    }
    BIT(){}
    BIT(int n){init(n);}

    void add(int k,int x){
        for(k++;k<=N;k+=k&-k)dat[k]+=x;
    }
    int sum(int k){
        int ret=0;
        for(k++;k;k-=k&-k)ret+=dat[k];
        return ret;
    }
};

int N,M;
vint lis[111111];

signed main(){
    scanf("%lld%lld",&N,&M);
    rep(i,N){
        int l,r;
        scanf("%lld%lld",&l,&r);
        r++;
        lis[r-l].pb(l);
    }

    BIT bit;bit.init(M+114);
    int latte=N;
    for(int d=1;d<=M;d++){
        for(auto l:lis[d]){
            int r=l+d;
            bit.add(r,-1);bit.add(l,1);
        }
        latte-=lis[d].size();
        int ans=latte;
        for(int x=d;x<=M;x+=d)ans+=bit.sum(x);
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MOD2 100000000
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define all(v) v.begin(),v.end()
ll mod=MOD;
using namespace std;
long long int fast_exp(long long int base,long long int ex) {
    long long int res=1;
    while(ex>0) {
       if(ex%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       ex/=2;
    }
    return res%mod;
}
long long int gcd(long long int a, long long int b)
{
    if(b==0)return a;
     return gcd(b,a%b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   double a,b;
   cin>>a>>b;
   a=a/b;
   printf("%.9f\n",a);
   return 0;

}


Measured memory_bytes: 256
let [|a;b|] = stdin.ReadLine().Split() |> Array.map int

let [|x;y|] = (if (a > b) then [|a;b|] else [|b;a|])

let rec gcd k l =
 match l with
 |0 -> k
 |_ -> gcd l (k % l)

let f x = int64 x

((f a) * (f b)) / (f (gcd x y))
|>stdout.WriteLine

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int K, S, X, Y;
    cin >> K >> S;

    int ans = 0;

    for(X = 0; X <= K; X++ )
    {
        for(Y = 0; Y <= K; Y++)
        {
            if((0 <= (S-X-Y)) && ((S-X-Y) <= K))
            {
                ans++;
            } 
        }
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

N=int(input())
A=input()
B=input()
C=input()

S=set()
ans=0

for i in range(N):
    S.add(A[i])
    S.add(B[i])
    S.add(C[i])
    ans+=len(S)-1
    S.clear()
print(ans)


Measured memory_bytes: 12516
#include <stdio.h>

int main(void){
    int n, m;
    int i;

    scanf("%d", &n);
    for(i = 1; i <= n; i++){
        m = i;
        if(i % 3 == 0){
            printf(" %d", i);
        }else{
            do{
                if(m % 10 == 3){
                    printf(" %d", i);
                    break;
                }else{
                    m /= 10;
                }
            }while(m > 0);
       }
    }
    puts("");
    return 0;
}

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

int n;
int max_;
int a[100005];
int po[100005];

int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a[t] += 1;
  }
  po[0] = a[0] + a[1];
  po[100004] = a[100003] + a[100004];
  for (int i = 1; i < 100004; i++) {
    po[i] = a[i - 1] + a[i] + a[i + 1];
  }
  for (int i = 0; i < 100004; i++) {
    if (max_ < po[i]) max_ = po[i];
  }
  cout << max_ << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
using ll = long long;

//rev 0.3 map版 辞書要素数=2のケース追加。
int main() {
    int n;cin >> n;
    bool f = false;
    vector<int> l(n);for (auto &c:l) cin >> c;
    bool early_exit=false;
    map<int,int> m;
    for(auto c:l) {
        ++m[c];
        if (m.size()>3) {early_exit = true;break;}
    }
    if (!early_exit) {
        if (m.size()==1 and l.front()==0) f = true;
        else if (m.size()==2 and n%3==0) {
            for (auto pp:m) {
                if (pp.first==0) f = true;
            }
            if (f) {
                f = false;
                vector<int> two;
                for (auto pp:m) two.push_back(pp.second);
                sort(two.begin(),two.end());
                if (m[0]==two[0] and two[1]/two[0]==2 and two[1]%two[0]==0) f=true;
            }
        }
        else if (m.size()==3 and n%3==0) {
            int pre=-1;
            for (auto pp:m) {
                if (pre==-1) pre=pp.first;
                else pre^=pp.first;
            }
            if (pre==0) {
                f=true;
                pre = -1;
                for (auto pp:m) {
                    if (pre==-1) pre=pp.second;
                    else {
                        if (pre != pp.second) {
                            f=false;
                            break;
                        }
                    }
                }
            }
        }
    }
    cout << (f ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <ios>
using namespace std;
long n, A[21] = {}, DP[21][2000] = {};

void createDP(){
	for (int i = 1; i <= n; ++i){
		DP[i][0] = DP[i][A[i]] = 1;
		for (int j = 1; j < 2000; ++j){
			if (DP[i - 1][j] == 1) DP[i][j] = 1;
			if (A[i] < j && DP[i - 1][j - A[i]] == 1) DP[i][j] = 1;
		}
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long m, i, k;
	cin >> n;
	for (i = 1; i <= n; ++i) cin >> A[i];
	createDP();
	cin >> m;
	while(m--){
		cin >> k;
		cout << ((DP[n][k] == 1) ? "yes\n" : "no\n");
	}
	return 0;
}

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

/*
left to rightにforループでWの人を数えて各場所での人の数を保存
right to leftにEの人を同じく数える。
各時点についてそれぞれの配列から向きを変える人数を計算し、maxを保存しておく。O(N)
*/

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

    string S;
    cin >> S;

    vector<int> left_to_right(N, 0);
    vector<int> right_to_left(N, 0);

    int n_w = 0;
    for (int i = 0; i < N; i++)
    {
        left_to_right[i] = n_w;
        if (S[i] == 'W')
            n_w++;
    }

    int n_e = 0;
    for (int i = N - 1; i >= 0; i--) {
        right_to_left[i] = n_e;
        if (S[i] == 'E')
            n_e++;
    }

    int minv = 1e9;
    for (int i = 0; i < N; i++)
    {
        minv = min(minv, left_to_right[i] + right_to_left[i]);
    }
    cout << minv << endl;
}

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

int main()
{
    int N;
    int p = 0, w = 0, g = 0, y = 0;
    string S;
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        cin >> S;
        if (S == "P")
        {
            p++;
        }
        else if (S == "W")
        {
            w++;
        }
        else if (S == "G")
        {
            g++;
        }
        else if (S == "Y")
        {
            y++;
        }
    }

    cout << ((p * w * g * y) ? "Four" : "Three") << endl;
}


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

int main()
{
    string str;

    getline(cin, str);

    for(int i = 0; i < str.length(); i++)
    {
        char c = str[i];
        if(islower(c))
            cout << (char)toupper(c);
        else if(isupper(c))
            cout << (char)tolower(c);
        else
            cout << c;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3060
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, M; cin >> N >> M;
    cout << (N == M ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#define _USE_MATH_DEFINES
#include <math.h>

#define B 1000000007;

using namespace std;

int main() {

	int N,A;
	int arr[1000] = {0};
	unsigned long long int ans = 1;

	cin >> N;

	for (int i = N; i > 1; i--) {
		A = i;
		for (int j = 2; j <= A; j++) {
			if (A % j == 0) {
				while (A % j == 0) {
					A /= j;
					arr[j]++;
				}
			}
		}
	}

	for (int i = 2; i <= N; i++) {
		if (arr[i] > 0)
			ans *=  arr[i] + 1;
		if (ans > 1000000000)
			ans %= B;
	}
	ans %= B;

	cout << ans  << endl;

	return 0;
}

Measured memory_bytes: 256
import math

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a
 
def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)
 

def f(b,n):
	if n < b:
		return n
	return f(b, n//b) + n%b
 
N,X = map(int,input().split())
X-=1

P = [0,1]

for i in range(1,N):
    P.append(P[i]*2+1)

left = 0
right = 1
for i in range(N):
    right = right*2 + 3

mid = int((right-left)/2)
ans = 0

while(left <= right):
    if(X<mid):
        right = mid-1
        left += 1
        N-=1
    elif (X>mid):
        left = mid+1
        right -= 1
        ans = ans + P[N] + 1
        N-=1
    else:
        ans = ans + P[N] + 1
        break

    mid = left+int((right-left)/2)
    
print(ans)

Measured memory_bytes: 3064
class UnionFind:
    def __init__(self, N):
        # Union find with component size
        # Negative means is a root where value is component size
        # Otherwise is index to parent
        self.p = [-1 for i in range(N)]

    def find(self, i):
        # Find root with path compression
        if self.p[i] >= 0:
            self.p[i] = self.find(self.p[i])
            return self.p[i]
        else:
            return i

    def union(self, i, j):
        # Union by size
        root1 = self.find(j)
        root2 = self.find(i)
        if root1 == root2:
            return
        size1 = -self.p[root1]
        size2 = -self.p[root2]
        if size1 < size2:
            self.p[root1] = root2
            self.p[root2] = -(size1 + size2)
        else:
            self.p[root2] = root1
            self.p[root1] = -(size1 + size2)

    def getComponentSize(self, i):
        return -self.p[self.find(i)]


from collections import defaultdict

N, M, K = list(map(int, input().split()))
friend = defaultdict(set)
for i in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    friend[a].add(b)
    friend[b].add(a)
block = defaultdict(set)
for i in range(K):
    c, d = list(map(int, input().split()))
    c -= 1
    d -= 1
    block[c].add(d)
    block[d].add(c)

uf = UnionFind(N)
for a, friends in friend.items():
    for b in friends:
        uf.union(a, b)

out = []
for a in range(N):
    count = uf.getComponentSize(a) - 1 - len(friend[a])
    for b in block[a]:
        if uf.find(a) == uf.find(b):
            count -= 1
    out.append(str(count))
print(" ".join(out))



Measured memory_bytes: 94824
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    int N,K;
    cin >> N >> K;

    int ans =((N-1)%(K-1)) ? (N-1)/(K-1)+1: (N-1)/(K-1);
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
//#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
#include<set>
//#include<map>
//#include<list>

using namespace std;

class UnionFind {
public:
	vector<int>data;
	UnionFind(int size) :data(size, -1) {};
	bool unionset(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x]) {
				swap(x, y);
			}
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}
	bool findset(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int x, int y) {
	int tmp, r;
	if (x < y) {
		tmp = x;
		x = y;
		y = tmp;
	}
	r = x % y;
	while (r != 0) {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}

int main(void) {
	int N;
	cin >> N;
	if (N < 1200) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ARC" << endl;
	}
}

Measured memory_bytes: 256
/**
	Language: C++
	Author  : ebby21
**/

#include <bits/stdc++.h>

using namespace std;

#define FastIO() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define Debug(v) cerr << '\n' << #v << ":\t" << v << '\n'
#define Loop(i, L, U) for (ll i = (L); i <= (U); ++i)
#define RLoop(i, U, L) for (ll i = (U); i >= (L); --i)
#define All(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;

typedef priority_queue<int, vector<int>, greater<int>> minpq;

int main() {
//	FastIO();
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;

	minpq p, q;
	vi r(c);

	int k;
	Loop (i, 1, a) {
		cin >> k;
		if (p.size() != x) {
			p.push(k);
		} else if (p.top() < k) {
			p.pop();
			p.push(k);
		}
	}
	Loop (i, 1, b) {
		cin >> k;
		if (q.size() != y) {
			q.push(k);
		} else if (q.top() < k) {
			q.pop();
			q.push(k);
		}
	}

	for (int &i : r) cin >> i;

	sort(All(r), greater<int>());

	int d1, d2;
	for (int i: r) {
		d1 = 0, d2 = 0;
		if (!p.empty()) d1 = i - p.top();
		if (!q.empty()) d2 = i - q.top();

		if (d1 <= 0 && d2 <= 0) break;

		if (d1 > d2) {
			p.pop();
			p.push(i);
		} else {
			q.pop();
			q.push(i);
		}
	}

	ll sum = 0;

	while (!p.empty()) {
		sum += p.top();
		p.pop();
	}

	while (!q.empty()) {
		sum += q.top();
		q.pop();
	}

	cout << sum << '\n';

	return 0;
}


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

int main(){
    ll k;
    cin>>k;
    int x=7%k;
    set<int>s;
    int i=1;
    while(s.count(x)==0){
        if(x==0){
            cout<<i<<endl;
            return 0;
        }
        s.insert(x);
        x=(x*10+7)%k;
        ++i;
    }
    cout<<"-1"<<endl;

}

Measured memory_bytes: 50396
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		for (int i = 0; i < 3; ++i) {
			int h = sc.nextInt();
			int m = sc.nextInt();
			int s = sc.nextInt();
			int v1 = sec(h, m, s);
			h = sc.nextInt();
			m = sc.nextInt();
			s = sc.nextInt();
			int v2 = sec(h, m, s);
			int d = v2 - v1;
			System.out.print(d / 3600 + " ");
			d %= 3600;
			System.out.print(d / 60 + " ");
			d %= 60;
			System.out.println(d);
		}
	}

	static int sec(int h, int m, int s) {
		return h * 3600 + m * 60 + s;
	}

}

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var nums = new HashSet<int>();
        for(var i = 0; i < input.Length; i++)
        {
            nums.Add(Convert.ToInt32(input[i]));
        }
        Console.WriteLine(nums.Count);
    }
}

Measured memory_bytes: 13396
import java.io.*;
import java.util.*;

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve(){

        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();

        if(a % 2 == b % 2) System.out.println((a + b) / 2 - Math.min(a, b));
        else if(a - 1 > n - b) System.out.println(((a + n - b + 1) + n) / 2 - (a + n - b + 1) + n - b + 1);
        else System.out.println(((b - (a - 1 + 1)) + 1) / 2 - 1 + (a - 1 + 1));

    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    long pow_mod(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <= 0){
                return false;
            }
        }
        return true;
    }
    private int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c){ return 33 <= c && c <= 126;}
    public boolean hasNext(){ while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b <= '9'){
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble(){ return Double.parseDouble(next());}
}


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

int main()
{
	ll k,n;
	cin >> k >> n;
	vector<ll> A(n);
	for(ll i = 0;i<n;i++)cin >> A[i];
	for(ll i = 0;i<n;i++)
	{
		A.push_back(A[i]+k);
	}
	ll ans = INT_MAX;
	for(ll i = 0;i<n;i++)
	{
		ans = min(ans,A[i+n-1]-A[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define fi first
#define se second
#define mp make_pair
#define SZ(x) ((int)(x.size()))
#define FOI(i,a,n) for(int (i)=int(a);(i)<=int(n);++(i))
#define FOD(i,a,n) for(int (i)=int(a);(i)>=int(n);--(i))
#define IN(x,y) ((y).find((x))!=(y).end())
#define ALL(t) t.begin(),t.end()
#define MSET(tabl,i) memset(tabl, i, sizeof(tabl))
#define PSET(x,y) fixed<<setprecision(y)<<lf(x)
#define DBG(c) cout<<#c<<" = "<<c<<endl;
#define RTIME ((double)clock()/(double)CLOCKS_PER_SEC)

template<typename T,typename S>inline bool REMIN(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool REMAX(T&a,const S&b){return a<b?a=b,1:0;}

typedef long long ll;
typedef long double lf;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;

int bit(ll x, int pos){ return (x >> pos) & 1; }
ll power(ll base, ll exp, ll c = 1e9 + 7) { if(!exp) return 1; ll r = power(base, exp >> 1, c); r=(r*r)%c; if(exp&1) r=(r*base)%c; return r; }

ll T,N,M,K;  
int a,b,c;
string s1,s2;

const lf PI = 2*acos(0);
const ll INF = 1e9 + 4;
const ll MOD = 1000000007;
const int NMAX = 3e5+5;
	
int mineigh[NMAX];
int sumc[NMAX];
vpi eds[NMAX];

int sumcalc(int cur, int par = -1) {
	sumc[cur] = 1;
	for(auto pa : eds[cur]) if(pa.fi != par) {
		sumc[cur] += sumcalc(pa.fi, cur);
	}
	return sumc[cur];
}

vi candies;

void find_cent(int cur, int par = -1) {
	int ma = 0;
	for(auto pa : eds[cur]) if(pa.fi != par) {
		REMAX(ma, sumc[pa.fi]);
		find_cent(pa.fi, cur);
	}
	if(ma <= N / 2 and (N - sumc[cur]) <= N / 2) {
		candies.pb(cur);
	}
}

ll calc(int cur, int par = -1) {
	ll ret = 0;
	for(auto pa : eds[cur]) if(pa.fi != par) {
		ret += 2ll * pa.se * sumc[pa.fi];
		ret += calc(pa.fi, cur);
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	cin >> N;
	MSET(mineigh, 63);
	FOI(i, 1, N - 1) {
		cin >> a >> b >> c;
		eds[a].pb(b, c);
		eds[b].pb(a, c);
		REMIN(mineigh[a], c);
		REMIN(mineigh[b], c);
	}
	
	sumcalc(1);
	find_cent(1);

	ll ans = 0;
	for(int x : candies) {
		sumcalc(x);
		int sub;
		sub = INF;
		int flag = 0;
		for(auto v : eds[x]) if(N % 2 == 0 and sumc[v.fi] == N / 2) {
			flag = 1;
			REMIN(sub, v.se);
		}
		if(!flag) {
			sub = mineigh[x];
		}
		REMAX(ans, calc(x) - sub);
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 18048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,s=0,M,c=0;
    cin>>n>>M;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        s+=arr[i];
    }
     double ss=(double)s/(4*M);
    for(int i=0;i<n;i++){
            if(arr[i]>=ss)
            c++;
    }
    if(c>=M) cout << "Yes" << endl;
    else cout << "No" <<endl;
      return 0;
}


Measured memory_bytes: 256
N = int(input())
F=[]
for i in range(N):
    F.append(list(map(int,input().split())))

P=[]
for i in range(N):
    P.append(list(map(int, input().split())))

B=[bin(i)[2:] for i in range(1024)]
for i in range(len(B)):
    while(len(B[i])<10):
        B[i]="0"+B[i]
c=0
ans=-10**9
for b in B[1:]:
    res=0
    for index,f in enumerate(F):
        #print('f',f)
        for i,j in zip(f,b):
            if(str(i)==j and i==1):
                c+=1
        #print(b,"のときのc:",c)
        #print("p",P[index][c])
        res+=P[index][c]
        c=0
    ans=max(ans,res)
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
int power(int a,int x){
	if(x==0) return(1);
	int p=power(a,x/2);
	p=(p*p)%M;
	if(x%2==0) return(p);
	return((p*a)%M);
}

int32_t main(){
    IOS;
    int n,k;
    cin>>n>>k;
    int ans=0;
    int dp[k+1]={0};
    for(int i=k;i>=1	;i--){
    	int x=k/i;
    	int res=power(x,n);
    	for(int j=i+i;j<=k;j+=i){
    		res=(res-dp[j]+M)%M;
    	}
    	dp[i]=res;
    	ans=(ans+(res*i)%M)%M;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4424
# coding: utf-8
from scipy.sparse.csgraph import floyd_warshall

N,M,L=map(int, input().split())
RG=[[0 for i in range(N)] for j in range(N)]

for i in range(M):
    f,t,c = map(int, input().split())
    if c <= L:
        RG[f-1][t-1] = c
        RG[t-1][f-1] = c

Rd = floyd_warshall(RG, directed=False)

FG=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i+1, N):
        if Rd[i][j] <= L:
            FG[i][j] = 1
            FG[j][i] = 1

Fd = floyd_warshall(FG, directed=False)

Q=int(input())
for i in range(Q):
    s, t = map(int, input().split())
    v = Fd[s-1][t-1]
    if s == t:
        print (str(0))
    if v == float('inf'):
        print (str(-1))
    else:
        print (str(int(v-1)))



Measured memory_bytes: 18904
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    lint n, k;
    cin >> n >> k;

    lint c = n / k;
    n -= c * k;
    cout << min(n, abs(n - k)) << endl;
    return 0;
}

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

int main(){
    int A,B,x1=0,x2=0,x3=0;
    cin >> A >> B;
    if(A>B){
        cout << A+(A-1) << endl;
    }else if(A<B){
        cout << B+(B-1) << endl;
    }else{
        cout << A+B << endl;
    }
}

Measured memory_bytes: 256
/***********************************************************
 *This code By @1353055672(Ligen)                          *
 *[Warning]You're not excepted to understand this code!    *
 *CSP-S 2019 RP++                                          *
 ***********************************************************/
#pragma GCC optimize(3)
#define ADD_STACK int size = 512 << 20;\
	char *pp = (char*)malloc(size) + size;  \
	__asm__("movl %0, %%esp\n" :: "r"(pp))
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<fstream>
#include<queue>
#include<map>
#include<unordered_map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mn 200020
#define Max(x,y) (((x)>(y))?(x):(y))
#define Min(x,y) (((x)<(y))?(x):(y))
#define Abs(x) (((x)<(0))?(-(x)):(x))
#define infll (ll)(1e18)
#define infint (1<<30)
#define mod (int)(1e9+7)
#define FOR(a,b,c) for (register int a=b;a<=c;++a)
#define FORD(a,b,c) for (register int a=b;a>=c;--a)
using namespace std;
// char buf[1<<20],*p1=buf,*p2=buf;
// #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline ll read(){
	ll x=0,f=1;char c;
	for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
	for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());
	return x*f;
}
template<typename T>
inline void write(T a){
	if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
	while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
}
inline void write_(){return;}
template<typename T,typename... Args>
inline void write_(T a,Args... b){write(a);putchar(' ');write_(b...);}
inline void writeln(){putchar('\n');return;}
template<typename T,typename... Args>
inline void writeln(T a,Args... b){write(a);putchar(' ');writeln(b...);}
//need c++11

//inline void write(ll a){
//    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
//    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
//}
//inline void write_(ll a){write(a);putchar(' ');}
//inline void writeln(ll a){write(a);putchar('\n');}
inline ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
inline ll lcm(ll a,ll b){return 1ll*a/gcd(a,b)*b;}
inline ll Pow(ll n,ll a){ll b=1;while(a){if(a&1)b=1ll*b*n%mod;n=1ll*n*n%mod;a>>=1;}return b;}
//---------------------Head Files--------------------------//
int n,m,w,v,ans,f[100020];
signed main(){
#ifdef LOCAL_LIGEN
	// freopen("0.in","r",stdin);
	// freopen("0.out","w",stdout);
	double be=clock();
#endif
	n=read(),m=read();
	f[0]=0;
	FOR(i,1,100000)f[i]=infint;
	FOR(i,1,n){
		w=read(),v=read();
		FORD(j,100000,v)if(f[j-v]+w<=m)f[j]=Min(f[j],f[j-v]+w);
	}
	FORD(i,100000,0)if(f[i]<=m)return writeln(i),0;
#ifdef LOCAL_LIGEN
	double en=clock();
	printf("Time: %.0lfms\n",en-be);
	fclose(stdin);fclose(stdout);
#endif
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
int cnt[2][105];
int h, w;
bool flag[110][110];

int main() {
	int k;
	cin >> k;
	deque<ll>q;
	for (int i = 1;i < 10;++i) {
		q.push_back(i);
	}
	ll ans = 0;
	for (int i = 0;i < k-1;++i) {
		ll x = q[0];
		q.pop_front();
		ll y = x % 10;
		if (y != 0)q.push_back(10 * x + (y - 1));
		q.push_back(10 * x + y);
		if (y != 9)q.push_back(10 * x + 1 + y);
	}
	cout << q.front() << endl;
	return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int N, K, ans = 0;
  cin >> N >> K;
  ans = pow(N / K, 3);
  if (K % 2 == 0) ans += pow((N / (K / 2)) - (N / K), 3);
  print(ans);
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt() //挿入回数
	K := nextInt() //出力する値の位置
	values := make([]int, N)
	counts := make(map[int]int, N)
	for i := 0; i < N; i++ {
		values[i] = nextInt()
		counts[values[i]] += nextInt()
	}
	sort.Ints(values)
	var current int
	prev_value := 0
	for _, v := range values {
		if prev_value == v {
			continue
		}
		current += counts[v]
		if K <= current {
			fmt.Println(v)
			break
		}
		prev_value = v
	}
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		log.Fatal(err)
	}
	return i
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int x;
    int y;
}grid;

int main(void){
    int H,W,D;
    scanf("%d%d%d",&H,&W,&D);

    //A[0]~A[N-1]に格納する
    grid* G;
    NEW(G,H*W);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int v;
            scanf("%d",&v);
            G[v-1].x=i;
            G[v-1].y=j;
        }
    }

    int Q;
    scanf("%d",&Q);

    int* L;
    NEW(L,Q);
    int* R;
    NEW(R,Q);
    for(int i=0;i<Q;i++){
        scanf("%d%d",&L[i],&R[i]);
        L[i]--;
        R[i]--;
    }

    //累積和
    long* sum;
    NEW(sum,H*W);
    for(int i=0;i<H*W;i++){
        if(i/D==0) sum[i]=0;
        else sum[i]=sum[i-D]+abs(G[i].x-G[i-D].x)+abs(G[i].y-G[i-D].y);
    }

    for(int i=0;i<Q;i++){
        long ans=sum[R[i]]-sum[L[i]];
        printf("%ld\n",ans);
    }

    return 0;
}

//総和をwhileループでQ個求めると、O(H*W*Q)でTLEになってしまう。

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
const int N =  1230;
int n,m,k,ans;
int a[N],b[N];
int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++)
    {
        b[i] = a[i] + b[i - 1];
    //    cout << b[i] << endl;
    }
    for (int i = 1; i <= n; i++)
        if (b[i] <= k)
            ans++;
    cout << ans + 1 << endl;
    return (0);
}




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

using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

Graph G;

vector<int> res;

//ツリー探索pはvの親。vをcに塗る
void dfs(int v, int p, int c){
    res[v] = c;
    for(auto e : G[v]){
        if(e.first == p) continue;//子から親へ逆流を防ぐ
        if(e.second & 1) dfs(e.first,v,1-c);
        else dfs(e.first,v,c);
    }
}

int main(){
    int N;cin >> N;
    G.resize(N);
    for(int i = 0; i < N-1 ; i++){
        int u,v,w;cin >> u >> v >> w;
        u--;v--;
        G[u].push_back(Edge(v,w));
        G[v].push_back(Edge(u,w));
    }
    res.assign(N,0);
    dfs(0,-1,1);

    for(auto v : res)cout << v << endl;

    return 0;
}

Measured memory_bytes: 8960
#include <stdio.h>
#define ll long long int

ll M(ll a, ll b, ll c){
    return a > b ? a > c ? a : c : b > c ? b: c;
}

ll m(ll a, ll b, ll c){
    return a < b ? a < c ? a : c : b < c ? b : c;
}
int main(){
    ll i, j, h ,w, ans = 0;
    ll s, t, u, v;
    scanf("%lld%lld", &h, &w);
    
    if(h % 3 == 0 || w % 3 == 0){
        printf("0\n");
        return 0;
    }
    
    //縦横最小
    ans = w < h ? w: h;
    
    //縦横１個ずつ
    for(i = 1; i <= h / 2; i++){
        s = w * i;
        //1
        t = (h - i) * (s / (h - i));
        u = (h - i) * (w - (s / (h - i)));
        v = M(s, t, u) - m(s, t, u);
        if(v == 0){
            printf("0\n");
            return 0;
        }
        if(ans > v) ans = v;
        
        //2
        t = (h - i) * (w / 2);
        u = (h - i) * (w - (w / 2));
        v = M(s, t, u) - m(s, t, u);
        if(v == 0){
            printf("0\n");
            return 0;
        }
        if(ans > v) ans = v;
    }
    
    for(i = 1; i <= w / 2; i++){
        s = h * i;
        //1
        t = (w - i) * (s / (w - i));
        u = (w - i) * (h - (s / (w - i)));
        v = M(s, t, u) - m(s, t, u);
        if(v == 0){
            printf("0\n");
            return 0;
        }
        if(ans > v) ans = v;
        
        //2
        t = (w - i) * (h / 2);
        u = (w - i) * (h - (h /2));
        v = M(s, t, u) - m(s, t, u);
        if(v == 0){
            printf("0\n");
            return 0;
        }
        if(ans > v) ans = v;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint 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)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, arr[200000];
map<lint, lint> expected;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N;
	lint ans = 0;
	REP(i, N) {
		cin >> arr[i];
	}
	sort(arr, arr + N, greater <lint>());
	REP(i, N) {
		lint curr = 2;
		while (curr <= arr[i]) curr *= 2;
		if (expected.find(arr[i]) != expected.end()) {
			if (expected[arr[i]] > 0) {
				ans++;
				expected[arr[i]]--;
				expected[curr - arr[i]]--;
			}
		}
		expected[curr - arr[i]]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 17632
#include<stdio.h>

int main ()
{
  int a,b;
  
  scanf("%d%d\n",&a,&b);
  
  if (a > b) {
   printf("a > b\n");
  }

  else if (a < b) {
   printf("a < b\n");
  }
  else {
   printf("a == b\n");
  }
  return 0;

}

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

int main(){
   int a,b;
   cin >> a >> b;
   if(b < 10){
       a *= 10;
       a += b;
   }
   else if(b < 100){
       a *= 100;
       a += b;
   }
   else{
       a *= 1000;
       a += b;
   } 
   for(int i=1;i<100000000;i++){
       if(i*i == a){
           cout << "Yes" << endl;
           
           return 0;
       }
   }
   cout << "No" << endl;
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int a,b;
    cin >> a >> b;
    int cnt = 0;
    int c = 1;
    while(c<b){
        c += (a-1);
        cnt++;
    } 
    
    cout << cnt << endl;
    return 0;

}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

double a[N], d[3001][3001];
int n;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	d[1][0] = a[1];
	d[1][1] = 1 - a[1];
	for (int i = 2; i <= n; i++){
		for (int j = 0; j <= i; j++){
			if (j == 0){
				d[i][j] = d[i - 1][j] * a[i];
			}
			else if (j == i){
				d[i][j] = d[i - 1][j - 1] * (1 - a[i]);
			}
			else{
				d[i][j] = (d[i - 1][j - 1] * (1 - a[i])) + (d[i - 1][j] * a[i]);
			}
		}
	}
	double ans = 0;
	for (int i = 0; i <= n / 2; i++){
		ans += d[n][i];
	}
	printf("%.10lf", ans);
	return 0;
}















Measured memory_bytes: 70272
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var N = int.Parse(inputs[0]);
        var X = long.Parse(inputs[1]);
        inputs = Console.ReadLine().Split(' ');
        var x = new long[N];
        for (int i = 0; i < N; i++)
        {
            x[i] = long.Parse(inputs[i]);
        }

        x = x.OrderBy(xd => xd).ToArray();
        var d = new long[N];
        var gcd = Gcd(Math.Abs(x.First() - X), Math.Abs(x.Last() - X));
        for (int i = 1; i < N; i++)
        {
            d[i] = Math.Abs(x[i] - x[i - 1]);
            gcd = Gcd(d[i], gcd);
        }
        Console.WriteLine(gcd);
    }

    /**
     * 最小公倍数
     * <see cref="https://qiita.com/gushwell/items/f08d0e71fa0480dbb396"/>
     */
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    /**
     * ユークリッド互除法(最大公約数)
     * <see cref="https://qiita.com/gushwell/items/e9614b4ac2bea3fc6486"/>
     */
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
}



Measured memory_bytes: 24544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W, tmp;
  cin >> H >> W;
  string col1, col2, col3, ini;
  for (int i = -1; i < W+1; i++){
    ini += '.';
  }
  cin >> col2;
  col1 = ini;
  col2 = '.' + col2 + '.';
  for (int h = 2; h <= H; h++){
    cin >> col3;
    col3 = '.' + col3 + '.';
    for (int w = 1; w <= W; w++){
      tmp=0;
      if (col2.at(w)=='#'){cout << "#";continue;}
      if (col1.at(w-1) == '#'){tmp++;}
      if (col1.at(w) == '#'){tmp++;}
      if (col1.at(w+1) == '#'){tmp++;}
      if (col2.at(w-1) == '#'){tmp++;}
      if (col2.at(w+1) == '#'){tmp++;}
      if (col3.at(w-1) == '#'){tmp++;}
      if (col3.at(w) == '#'){tmp++;}
      if (col3.at(w+1) == '#'){tmp++;}
      cout << tmp;
    }
    cout << endl;
    col1 = col2; col2 = col3;
  }
  
  col3 = ini;
  for (int w = 1; w <= W; w++){
    tmp=0;
    if (col2.at(w)=='#'){cout << "#";continue;}
    if (col1.at(w-1) == '#'){tmp++;}
    if (col1.at(w) == '#'){tmp++;}
    if (col1.at(w+1) == '#'){tmp++;}
    if (col2.at(w-1) == '#'){tmp++;}
    if (col2.at(w+1) == '#'){tmp++;}
    if (col3.at(w-1) == '#'){tmp++;}
    if (col3.at(w) == '#'){tmp++;}
    if (col3.at(w+1) == '#'){tmp++;}
    cout << tmp;
  }
  cout << endl;
  }

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

long long int gcd(long long int k,int i,int j,int l)
{
    long long int a, b, c;

                a = i;
                b = j;
                while (1)
                {

                    if (a == 0)
                    {
                        c = l;
                        while (1)
                        {

                            if (b == 0)
                            {
                                return  c;
                                
                            }
                            else if (c == 0)
                            {
                                return b;
                               
                            }
                            (b >= c) ? b %= c : c %= b;
                        }
                    }
                    else if (b == 0)
                    {
                        c = l;
                        while (1)
                        {

                            if (a == 0)
                            {
                                return c;
                               
                            }
                            else if (c == 0)
                            {
                                return a;
                               
                            }
                            (a >= c) ? a %= c : c %= a;
                        }
                    }
                    (a >= b) ? a %= b : b %= a;
                }
 }

int main()
{

    long long int k, result = 0;
    cin >> k;

    for (int i = 1; i < (k+1);i++)
    {
        for (int j = 1; j < (k+1); j++)
        {
            for (int l = 1; l < (k+1); l++)
            {
                result += gcd(k,i,j,l);
            }
        }
    }

        cout << result;
}


Measured memory_bytes: 3592
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	cout << N - M + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

while True:
    a.sort()
    if max(a) == 1 or a[n-2] == 0:
        break
    for i in a:
        if i != 0:
            t = a.index(i)
            break

    for i in range(n):
        if i == t:
            continue
        a[i] = a[i] % a[t]

print(max(a))


Measured memory_bytes: 15020
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
//#define M 1000000007
//typedef pair<ll,ll> p; 
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    
   int n;
   cin>>n;
   ll sum=0;
   for(ll i=1;i<=n;i++)
   {
       for(ll j=1;j<=n;j++)
       {
           for(ll k=1;k<=n;k++)
           {
               ll p=__gcd(k,j);
               sum=sum + __gcd(p,i);
           }
       }
   }
   cout<<sum<<endl;
  
}

Measured memory_bytes: 3612
A = int(input()) #500
B = int(input()) #100
C = int(input()) #50
x = int(input())
sum = 0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if 500 * a + 100* b + 50*c == x:
        sum += 1
print(sum)

Measured memory_bytes: 3060
<>=~$";@h=(0,sort{$b-$a}glob<>);for(1..$'){$v=$h[$i=1]>>1;$h[$i>>1]=$h[$i]while$v<$h[$i+=$h[$i*=2]<$h[$i+1]];$h[$i>>1]=$v}$\+=$_ for@h;print

Measured memory_bytes: 30204
#include <bits/stdc++.h>
#define MAX_N 100000
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, m, b[MAX_N+5];
int main() {
	read(n);
	for (int i = 1, x; i <= n; i++) read(x), b[x]++;
	for (int i = 1; i <= MAX_N; i++) m += max(0, b[i]-1);
	return printf("%d\n", n-(m+1)/2*2), 0;
}


Measured memory_bytes: 640