akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;





// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};


ll foo(ll a, int b){
    ll ans = 0;
    while(a){
        if (a%b == 0) ans++;
        else break;
        a/=b;
    }
    rn ans;
}


int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans;
    ll need;
    if ((a-b)%2 == 0){
        ans = (abs(a-b))/2;
    }
    else{
        ll minab = min(a,b);
        ll maxab = max(a,b);
        ll candi1 = (maxab -1 + minab -1 + 1)/2;
        ll candi2 = (n-minab + n - maxab + 1)/2;
        ans = min(candi1,candi2);
        
    }
    cout << ans;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    	int line = Integer.parseInt(sc.next());
      	String line1 = sc.next();
      	String line2 = sc.next();
      
      String kekka = "";
      for(int i = 0; i < line; i ++){
        kekka = kekka + line1.substring(i,i+1) + line2.substring(i,i+1);
      }
      System.out.print(kekka);
    }
}

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

struct node {
    int weight;
    int to_id;

    node(int t, int w) {
        this->weight = w;
        this->to_id = t;
    }
    bool operator>(node const &rhs) const {
        if (this->weight > rhs.weight) { return true; }
        else if (this->weight < rhs.weight) { return false; }
        if (this->to_id > rhs.to_id) { return true; }
        else if (this->to_id < rhs.to_id) { return false; }
        return false;
    }
};

// Graph:
typedef std::vector<std::vector<node>> Graph;

int prim(Graph const &input) {
    std::vector<bool> used(input.size(), false);
    int used_count = 0;
    int total_weight = 0;
    std::priority_queue<node, std::vector<node>, std::greater<node>> que;

    used[0] = true; used_count++;
    for (auto const &e: input[0]) que.push(e);
    while (used_count < input.size()) {
        // std::cout << que.size() << "; " << used_count << std::endl;
        assert(!que.empty());
        node s = que.top();
        que.pop();
        if (used[s.to_id]) continue;
        // std::cout << "marked " << s.to_id << " as used." << std::endl;
        used[s.to_id] = true; used_count++;
        total_weight += s.weight;
        for (auto const &e: input[s.to_id]) que.push(e);
    }
    return total_weight;
}

int main(void)
{
    int n, m;
    while ( std::cin >> n >> m, n) {
        Graph g(n);
        for (int i = 0; i < m; i++) {
            int f, t, c;
            std::cin >> f >> t >> c;
            g[f].emplace_back(t, c);
            g[t].emplace_back(f, c);
        }

        std::cout << prim(g) << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 2984
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

int a, b;

void main() {
    scan(a, b);

    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        writeln("Possible");
    }
    else {
        writeln("Impossible");
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
let pi = 4. *. atan 1.;;
let f a b c =
  let rad c = c *. pi /. 180. in
  let h = b *. (sin (rad c)) in
  let s = a *. h /. 2. in
  let l = a +. b +. sqrt( (a -. b *. (cos (rad c))) ** 2. +. h ** 2. ) in
  Printf.printf "%f %f %f\n" s l h;;

let () = Scanf.scanf "%f %f %f\n" f;;

Measured memory_bytes: 2732
package main

import "fmt"

func main() {
	var S string
	var K int
	fmt.Scan(&S, &K)
	for i := 0; i < K; i++ {
		if S[i] != '1' {
			fmt.Println(string(S[i]))
			return
		}
	}
	fmt.Println("1")
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue> 
#include<cmath>
#include<utility>
#include<set>
#define M 1000000007
using namespace std;
int main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int h, n, a=0, x;
  cin >> h >> n;
  for(int i = 0; i < n; i++)
  {
    cin >> x;
    a+=x;
  }
  if(a >= h)
    cout << "Yes\n";
  else
    cout << "No\n";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int m = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        if (d % m == 0) {
            System.out.println(m + d);
        } else {
            System.out.println(d - m);
        }
    }
}


Measured memory_bytes: 21844
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.reverse()
A = []
i = 0
while (0 <= i <= N-2):
  if (L[i] == L[i+1]):
    A.append(L[i])
    i += 2
    if (len(A) == 2):
      break
  else:
    i += 1
if (len(A) == 2):
  print(A[0]*A[1])
else:
  print(0)

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

int main(){
    string S, T;
    int sum = 0;
    cin >> S >> T;
    for(int i=0;i<S.length();i++){
        if(S.at(i) != T.at(i)) sum++;
    }
    cout << sum << endl;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(1!=a && 1!=b){
    cout << 1 << endl;
  }
  else if(2!=a && 2!=b){
    cout << 2 << endl;
  }
  else if(3!=a && 3!=b){
    cout << 3 << endl;
  }
}


Measured memory_bytes: 256
n, m = map(int, input().split())  # n: num problem, m: num submit
lst = [input().split() for i in range(m)]

ac = [False] * n
wa = [0] * n

for i in range(m):
    p_i = int(lst[i][0])
    s_i = lst[i][1]
    if s_i == 'AC':
        ac[p_i-1] = True
    else:
        if ac[p_i-1] is False:
            wa[p_i-1] += 1

# num_ac = sum(ac)
# pnlt = sum(wa)

a = 0
b = 0
for i in range(n):
    if ac[i]:
        a += 1
        b += wa[i]
print(*[a, b])
# print(*[num_ac, pnlt])


Measured memory_bytes: 33692
N, M = map(int, input().split())

l_list = [None] * M
r_list = [None] * M

allows = [0] * (N + 1)
for i in range(M):
    l, r = map(int, input().split())

    allows[l - 1] += 1
    allows[r] -= 1

total = 0
count = 0
for n in allows:
    total += n
    if total == M:
        count += 1
print(count)


Measured memory_bytes: 5492
#include <iostream>

using namespace std;

int main() {
    int a, b, temp;
    int output[10001];
    for (int i=0; i<3000; i++) {
        cin >> a >> b;
        if (a == 0 && b == 0) {
            break;
        }
        if (a > b) {
            temp = a;
            a = b;
            b = temp;
        }
        cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
  vector<int >nos(n,0);
  for(int i=0;i<n;i++)cin>>nos[i];
  int maxi=0;
  int count_maxi=0;
  int second_maxi=0;
  for(int i=0;i<n;i++)maxi = max(maxi,nos[i]);
  for(int i=0;i<n;i++)if(nos[i]==maxi)count_maxi++;
  if(count_maxi==1){
  	for(int i=0;i<n;i++)if(nos[i]<maxi)second_maxi = max(second_maxi,nos[i]);
  }
  if(count_maxi>1){
  	for(int i=0;i<n;i++)cout<<maxi<<'\n';
  }
  else{
  	for(int i=0;i<n;i++){
    	if(nos[i]==maxi)cout<<second_maxi;
      else cout<<maxi;
      cout<<'\n';
    }
  }
}

Measured memory_bytes: 2432
#include <iostream>

using namespace std;

int main(){

  int x,y;

  while (1){

    cin >> x >> y;
    
    if(x==0 && y==0){
      break;
    }


    if(x>y)
      cout << y <<" "<< x << endl;
    else
      cout << x << " " << y <<endl;

  }

  return 0;

}

Measured memory_bytes: 3008
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	int a, b, c[200000] = {0}, d[200000] = {0};
	for (int i = 0 ; i < m ; i++) {
		cin >> a >> b;
		if (a == 1) c[b - 1] = 1;
		if (b == n) d[a - 1] = 1; 
	}
	for (int i = 0 ; i < m ; i++) {
		if (c[i] == 1 && d[i] == 1) {
			cout << "POSSIBLE";
			return 0;
		}
	}
	cout << "IMPOSSIBLE";
}   

Measured memory_bytes: 1792
#include<stdio.h>

int main(void)

{
	int x[11];
	int d, r, i;
	scanf("%d", &r);
	scanf("%d", &d);
	scanf("%d",&x[0]);
	
	
	for (i = 0; i < 10; i++) {
		x[i + 1] = (x[i] * r) - d;
		printf("%d\n", x[i + 1]);
	}
	return 0;

}

Measured memory_bytes: 128
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

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;
}

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    sort(a.begin(),a.end());
    cout << a[N-1] - a[0] << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007LL;
int main()
{
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> dp(N + 1, vector<ll>{1, 0});
    dp[0][0] = 0, dp[0][1] = 1;
    for (int i = 0; i < M; i++) {
        vector<vector<ll>> tmp(N + 1, vector<ll>(2, 0));
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k < 2; k++) {
                if (j == 0) {
                    (tmp[j][k] += dp[j][k]) %= MOD, (tmp[j + 1][k] += dp[j][k]) %= MOD;
                } else if (j == 1) {
                    if (j != N) { (tmp[j][k] += dp[j][k]) %= MOD, (tmp[j + 1][k] += dp[j][k]) %= MOD; }
                    (tmp[j - 1][1] += dp[j][k]) %= MOD, (tmp[j][1] += dp[j][k]) %= MOD;
                } else if (j == N) {
                    (tmp[j][k] += dp[j][k]) %= MOD, (tmp[j - 1][k] += dp[j][k]) %= MOD;
                } else {
                    (tmp[j][k] += 2 * dp[j][k]) %= MOD, (tmp[j + 1][k] += dp[j][k]) %= MOD, (tmp[j - 1][k] += dp[j][k]) %= MOD;
                }
            }
        }
        dp = tmp;
    }
    ll ans = 0;
    for (int i = 0; i <= N; i++) { (ans += dp[i][1]) %= MOD; }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 624
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] sdate = s.split("/",0);
		int[] date = new int[3];
		for(int i = 0;i < 3;i ++) {
			date[i] = Integer.parseInt(sdate[i]);
		}
		if(date[0] <= 2019 && date[1] <= 4 && date[2] <= 30) {
			System.out.println("Heisei");
		}else {
			System.out.println("TBD");
		}
	}
}

Measured memory_bytes: 21844
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define PI 3.141592653589793238
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
ll arr[10000001];
const ll N=10000000;
void sieve(){
    memset(arr,0,sizeof(arr));
    for(ll i=1;i<=N;i++)
        for(ll j=i;j<=N;j+=i)
            arr[j]++;
    for(ll i=1;i<=N;i++)
    {
        arr[i]*=i;
        if(i>=2)
            arr[i]+=arr[i-1];
    }
}
void solve(){
    sieve();
    ll n;cin>>n;
    cout<<arr[n]<<endl;
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);cout.tie(NULL);

//    ll t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 81756
//package abc176;

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static PrintWriter out;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		out=new PrintWriter(System.out);
		
		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();			
		}
		int max=a[0];
		long ans=0;
		for(int i=1;i<n;i++) {
			if(max>a[i]) {
				ans+=max-a[i];
			}
			else {
				max=Math.max(max, a[i]);
			}
		}
		out.println(ans);
		
		out.close();
		sc.close();
	}

}


Measured memory_bytes: 59948
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    vector<ll>a(n+1);
    rep(i,n){
        ll aa;cin>>aa;
        a[i+1]=a[i]+aa;
    }
    ll cnt1=0;
    ll cnt2=0;
    ll cnt=0;
    REP(i,1,n+1){
        if(i%2){
            if(a[i]+cnt<=0){
                cnt1+=1-a[i]-cnt;
                cnt+=1-a[i]-cnt;
            }
        }else{
            if(a[i]+cnt>=0){
                cnt1+=1+a[i]+cnt;
                cnt+=-a[i]-cnt-1;
            }
        }
    }
    cnt=0;
    REP(i,1,n+1){
        if(i%2){
            if(a[i]+cnt>=0){
                cnt2+=1+a[i]+cnt;
                cnt+=-a[i]-cnt-1;
            }
        }else{
            if(a[i]+cnt<=0){
                cnt2+=1-(a[i]+cnt);
                cnt+=1-(a[i]+cnt);
            }
        }
    }
    cout<<min(cnt1,cnt2)<<endl;
}

Measured memory_bytes: 1024
// https://atcoder.jp/contests/abc094/tasks/arc095_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <regex>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v, w;
    v.resize(n);
    w.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    copy(v.begin(), v.end(), w.begin());
    sort(ALL(w));

    for (int i = 0; i < n; i++) {
        if (v[i] < w[n / 2]) {
            cout << w[n / 2] << "\n";
        } else {
            cout << w[n / 2 - 1] << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 3840
// Ver19.03
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a;
  char b[11];
  scanf("%d%s", &a, b);
  puts(a >= 3200 ? b : "red");
  return 0;
}

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

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

fn main() {
    let x = input::<i64>();

    let mut ans = 1;
    for i in 2..x + 1 {
        let mut m = i * i;
        while m <= x {
            ans = std::cmp::max(ans, m);
            m *= i;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define lld long long
#define N 2000005
lld power(lld a,lld b,lld c){
  lld ans=1;
  while(b){
    if(b&1){
      ans=ans*a%c;
    }
    a=a*a%c;
    b=b/2;
  }
  return ans;
}
int main() {
	int h,w; cin>>h>>w;
	vector<string> s;
	for(int i=0;i<w;++i){
		string b; cin>>b;
		s.push_back(b);
	}
	int dp[h][w];
	if(s[0][0]=='#')dp[0][0]=1;
	else dp[0][0]=0;
	for(int i=1;i<w;i++)if(s[0][i]=='#'&&s[0][i-1]=='#')dp[0][i]=dp[0][i-1]; else dp[0][i]=dp[0][i-1]+(s[0][i]=='#');
	for(int i=1;i<h;++i)if(s[i][0]=='#'&&s[i-1][0]=='#')dp[i][0]=dp[i-1][0]; else dp[i][0]=dp[i-1][0]+(s[i][0]=='#');
	for(int i=1;i<h;++i)
	{
		for(int j=1;j<w;++j){
			if(s[i][j]=='.')dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
			else{
				dp[i][j]=1+min(dp[i-1][j],dp[i][j-1]);
				if(s[i-1][j]=='#')dp[i][j]=min(dp[i][j],dp[i-1][j]);
				if(s[i][j-1]=='#')dp[i][j]=min(dp[i][j],dp[i][j-1]);
			}
		}
	}
	cout<<dp[h-1][w-1];
}

Measured memory_bytes: 256
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n,o;
		cin>>n;
		o=(n+1)/2;
		cout<<setprecision(12)<<double(o)/n;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
const ll INF=(1LL<<50);
struct max_flow {
    struct edge { ll to, cap, rev; };
    ll V;
    vector<vector<edge>> G;
    vector<ll> itr, level;

    max_flow(ll V) : V(V) { G.assign(V,vector<edge>()); }

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

    void bfs(ll s) {
        level.assign(V,-1);
        queue<ll> q;
        level[s] = 0; q.push(s);
        while (!q.empty()) {
            ll v = q.front(); q.pop();
            for(auto &e: G[v]){
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

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

    ll run(ll s, ll t) {
        ll ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(V,0);
            while ((f = dfs(s, t, INF)) > 0) ret += f;
        }
        return ret;
    }
};


void solve(long long N, std::vector<long long> a){
    auto flow = max_flow(N+2);
    ll ans=0;
    REP(N){
        ll tmp=max(0LL,a[i]);
        ans+=tmp;
        flow.add_edge(0,i+1,tmp-a[i]);
        flow.add_edge(i+1,N+1,tmp-0LL);
        FOR(j,i+2,N+1){
            if(j!=(i+1)&&j%(i+1)==0){
                flow.add_edge(i+1,j,INF);
            }
        }
    }
    dump(ans);
    ans-=flow.run(0,N+1);
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

int main() {
    int c[3][3];
    rep(i,3)rep(j,3) {
        int C;
        cin >> C;
        c[i][j] = C;
    }
    int C1 = c[0][1]-c[0][0];
    int C2 = c[0][2]-c[0][1];
    int C3 = c[1][0]-c[0][0];
    int C4 = c[2][0]-c[1][0];

    string ans = "Yes";
    rep(i,3){
        if(c[i][1]-c[i][0] != C1) ans = "No";
        if(c[i][2]-c[i][1] != C2) ans = "No";
        if(c[1][i]-c[0][i] != C3) ans = "No";
        if(c[2][i]-c[1][i] != C4) ans = "No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int M = 60;
int a[M],b[M];
int main(){
	int n;
	cin>>n;
	for(int i = 0; i < n;i++){
		cin>>a[i];
		b[i] = a[i];
	}
	sort(a,a+n);
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(a[i]!=b[i])
			ans++;
	}
	if(ans == 2 || ans == 0)
		cout<<"YES\n";
	else
		cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
mod=10**9+7
grid=[]
for i in range(H):
    s=str(input())
    grid.append(s)
dp=[[0 for i in range(W)]for j in range(H)]
dp[0][0]=1
for i in range(H):
    for j in range(W):
        if (i+1 < H) and (grid[i+1][j]=="."):
            dp[i+1][j]+=dp[i][j]
        if (j+1 < W) and (grid[i][j+1]=="."):
            dp[i][j+1]+=dp[i][j]
print(dp[-1][-1]%mod)


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int N;
int A[100010];

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

	cin >> N;
	rep(i, 0, N)
	{
		cin >> A[i];
	}

	sort(A, A + N);

	int mi = -1;
	double md = INF;
	rep(i, 0, N-1)
	{
		if (chmin(md, abs(A[N - 1] / 2.0 - (double)A[i])))
		{
			mi = A[i];
		}
	}

	cout << A[N - 1] << " " << mi << endl;

	return 0;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
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;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

	int n, k;
	std::cin >> n >> k;
	int ans = 0;
	rep(i, n) {
		int hi;
		std::cin >> hi;
		if (hi >= k)
			ans++;
	}
	std::cout << ans << "\n";
}


Measured memory_bytes: 256
// 全探索
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>

using namespace std;

const int MAX_N = 20;
const int MAX_N_2 = 10000000;
const int MAX_Q = 200;

// 入力値を保持するバッファ
int input_buffer[MAX_N + 1];
// 組み合わせの管理用バッファ
int comb_buffer[MAX_N + 1];
// 組み合わせから求めた和を格納する配列
int pos = 0;
int add_buffer[MAX_N_2];

void combinations(int n, int r);
void comb_sub(int n, int r, int m);
void add_combination(int m);

int main(void)
{
    int n, q, Q[MAX_Q + 1];

    scanf("%d", &n);

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

    scanf("%d", &q);

    for(int i = 0; i < q; i++)
    {
        scanf("%d", &Q[i]);
    }

    for(int i = 0; i < n; i++)
    {
        combinations(n, i);
    }

    for(int i = 0; i < q; i++)
    {
        bool judge = false;

        for(int j = 0; j < pos; j++)
        {
            if( add_buffer[j] == Q[i] )
            {
                judge = true;
                break;
            }
        }

        if( judge )
        {
            printf("yes\n");
        }
        else
        {
            printf("no\n");
        }
    }

    return 0;
}

// 組み合わせを生成する関数の入り口
void combinations(int n, int r)
{
	if (r > 0 && r <= MAX_N)
	{
		comb_sub(n, r, 0);
	}
}

// 組み合わせを生成する関数
// n : 選択する数値の範囲 ( 1〜 n )
// r : 選ぶ数値の個数
// m : 選んだ数値の個数
void comb_sub(int n, int r, int m)
{
	if ( r == 0 )
	{
        // r が 0 になったので、組み合わせを一つ生成できた
		add_combination(m);
	}
	else if ( n == r )
	{
		for (int i = r; i > 0; i--)
		{
			// n が r と等しくなったならば、残りの数字 (1 から r まで) を全て選択
			comb_buffer[m++] = i;
		}

		add_combination(m);
	}
	else
	{
		// nを選ばない場合
		// 残りの数字の中から r 個の数字を選びます。
		comb_sub(n - 1, r, m);

		// nを選ぶ場合
		// 数字 n を comb_buffer に追加して、残りの数字の中から r - 1 個を選びます。
		comb_buffer[m] = n;
		comb_sub(n - 1, r - 1, m + 1);
	}

    return;
}

// 入力数値の和を求める
void add_combination(int m)
{
    // 配列の初期化
    add_buffer[pos] = 0;

    for(int i = 0; i < m; i++)
    {
    	// 入力された数列の和を順番に求める
        add_buffer[pos] += input_buffer[comb_buffer[i] - 1];
    }

    // 要素を進める
    pos++;

    return;
}



Measured memory_bytes: 7168
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>

typedef long long ll;

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	while (true)
	{
		int d[5];
		for (int i = 0 ; i < 5; ++i, n /= 10)
			d[4-i] = n % 10;

		char soro[7][5 + 1];
		memset(soro, '*', sizeof(soro));
		for (int i = 0; i < 7; ++i)
			soro[i][5] = '\0';

		for (int i = 0; i < 5; ++i)
			soro[d[i] >= 5 ? 0 : 1][i] = ' ';
		for (int i = 0; i < 5; ++i)
			soro[d[i]%5 + 2][i] = ' ';

		for (int i = 0; i < 7; ++i)
		{
			puts(soro[i]);
			if (i == 1)
				puts("=====");
		}
		if (scanf("%d", &n) != EOF)
			putchar('\n');
		else
			break;
	}

	return 0;
}

Measured memory_bytes: 0
type
  node=record
      num,id:longint;
  end;
var father,num,now,first:array[0..105000]of longint;
    p:array[0..105000]of node;
    heap:array[0..105000,0..2]of longint;
    i:longint;
    x,y:longint;
    n,m:longint;
    totin,totout:longint;
    qwq,ans,have,h,z:int64;

function getfather(x:longint):longint;
begin
  if father[x]=x then exit(x) else
  begin
    father[x]:=getfather(father[x]);
    getfather:=father[x];
  end;
end;
procedure adde(x,y:longint);
var fx,fy:longint;
begin
  fx:=getfather(x);
  fy:=getfather(y);
  if fx<>fy then
  begin
    father[fx]:=fy;
    inc(num[fy],num[fx]);
  end;
end;
procedure qs(l,r:longint);
var i,j:longint;
    t,m:node;
begin
  i:=l;
  j:=r;
  m:=p[(l+r)>>1];
  repeat
    while (p[i].id<m.id)or((p[i].id=m.id)and(p[i].num<m.num)) do inc(i);
    while (p[j].id>m.id)or((p[j].id=m.id)and(p[j].num>m.num)) do dec(j);
    if i<=j then
    begin
      t:=p[i];p[i]:=p[j];p[j]:=t;
      inc(i);
      dec(j);
    end;
  until i>j;
  if l<j then qs(l,j);
  if i<r then qs(i,r);
end;
procedure swap(var a,b:longint);
var t:longint;
begin
  t:=a;a:=b;b:=t;
end;
procedure up(x,bool:longint);
begin
  while x>1 do
  begin
    //writeln(heap[x,bool],'qwq');
    if p[now[heap[x,bool]]].num<p[now[heap[x>>1,bool]]].num then
    begin
      swap(heap[x,bool],heap[x>>1,bool]);
      x:=x>>1;
    end else break;
  end;
end;
procedure down(x,bool:longint);
var min,tot:longint;
begin
  if bool=1 then tot:=totin else tot:=totout;
  while x*2<=tot do
  begin
    min:=x*2;
    if (x*2+1<=tot)and
    (p[now[heap[x*2+1,bool]]].num<p[now[heap[min,bool]]].num) then inc(min);
    if (p[now[heap[x,bool]]].num>p[now[heap[min,bool]]].num) then
    begin
      swap(heap[x,bool],heap[min,bool]);
      x:=min;
    end else break;
  end;
end;
begin
  read(n,m);
  for i:=1 to n do
  begin
    read(p[i].num);
    father[i]:=i;
    num[i]:=1;
  end;
  for i:=1 to m do
  begin
    read(x,y);
    inc(x);
    inc(y);
    adde(x,y);
  end;
  for i:=1 to n do
  p[i].id:=getfather(i);
  qs(1,n);
  p[0].num:=maxlongint;
  i:=1;
  while i<=n do
  begin
    inc(ans,p[i].num);
    if num[p[i].id]>1 then
    begin
      now[p[i].id]:=i+1;
      inc(have,num[p[i].id]);
      inc(h);
    end else
    begin
      now[p[i].id]:=0;
      inc(z);
    end;
    inc(totout);
    heap[totout,0]:=p[i].id;
    up(totout,0);
    first[p[i].id]:=i;
    i:=i+num[p[i].id];
  end;
  if totout=1 then
  begin
    writeln(0);
    exit;
  end;
  have:=have-(h-1)*2;
  if have<z then
  begin
    writeln('Impossible');
    exit;
  end;
  while totout>0 do
  begin
    inc(qwq);
    x:=heap[1,0];
    if now[x]<>0 then
    begin
      inc(totin);
      heap[totin,1]:=x;
      up(totin,1);
    end;
    if (qwq>2)and(totin>0) then
    begin
      x:=heap[1,1];
      inc(ans,p[now[x]].num);
      inc(now[x]);
      if (now[x]>=first[x]+num[x]) then
      begin
        now[x]:=0;
        heap[1,1]:=heap[totin,1];
        dec(totin);
      end;
      if totin>0 then down(1,1);
    end;
    heap[1,0]:=heap[totout,0];
    dec(totout);
    down(1,0);
  end;
  writeln(ans);
end.


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int N, M; cin >> N >> M;
  vector<pair<int, int>> keys(M);
  for(int i=0; i<M; i++){
    int a, b; cin >> a >> b;
    int s = 0;
    for(int j=0; j<b; j++){
      int c; cin >> c;
      s += 1 << (c-1);
    }
    keys[i] = make_pair(a, s);
  }
  
  vector<int> dp((1<<N), INF);
  dp[0] = 0;
  for(int i=0; i<M; i++){
    for(int s=0; s<(1<<N); s++){
      int next = s | keys[i].second;
      dp[next] = min(dp[next], dp[s] + keys[i].first);
    }
  }
  
  if(dp[(1<<N) - 1] == INF)
    cout << -1 << endl;
  else
    cout << dp[(1<<N) - 1] << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int N,K;
	cin>>N>>K;
	int arr[N];
	for(auto &it:arr){cin>>it;}
	K=min(N,K);
	int dp[N];
	dp[0]=0;
	for(int i=1;i<N;i++)
	{
		dp[i]=INT_MAX;
		for(int j=max(0,i-K);j<=i;j++)
		{
			dp[i]=min( dp[i], abs(arr[j]-arr[i]) + dp[j] );
		}
	}
	cout<<dp[N-1];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
int n;
ll a, ac, ans;
map<ll, int> mp;
int main(){
	scanf("%d", &n);
	mp[0]++;
	rep(i,n){
		scanf("%lld", &a);
		mp[ac += a]++;
	}
	for(auto it: mp){
		ll t = it.second;
		ans += t * (t-1) / 2;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 12800
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<memory>

using namespace std;

class UnionFind{
private:
  UnionFind *parent;
  int rank;
  //UnionFind *t_root;
public:
  UnionFind(){
    parent=this;
    rank=0;
  }
  UnionFind *root(UnionFind *x){
    if(x->parent == x){
      return x;
    }
    else{
      //return root(x->parent);
      x->parent=root(x->parent);
      return x->parent;
    }

    return 0;
  }
  int _union(UnionFind *x){
    UnionFind *rx=root(x);
    UnionFind *rt=root(this);

    if(rx->rank > rt->rank) rt->parent = rx;
    else if(rx->rank < rt->rank) rx->parent = rt;
    else if(rx != rt){
      rt->parent = rx;
      rx->rank+=1;
    }

    //rx->parent=rt;
    return 0;
  }
  int find(UnionFind *x){
    if(root(x) == root(this)){
      return 1;
    }
    else{
      return 0;
    }
  }
  void show_root(){
    cout << this->root(this) << endl;
  }
};

void show_v(vector< vector<int> > &v,int n);

int par[100001];
int rnk[100001];

void init(int);
int rt(int);
bool same(int,int);
void unite(int,int);

int main(void){

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

  vector<int> p(n+1);
  vector<int> x(m);
  vector<int> y(m);
  /*
  vector< vector<int> > v(n,vector<int>(n,0));
  */
  int cnt=0;

  for(int i=1;i<n+1;i++){
    cin >> p[i];
  }

  for(int i=0;i<m;i++){
    cin >> x[i];
    cin >> y[i];
  }

  //show_v(v,n);
  /*
  for(int i=0;i<m;i++){
    v[y[i]-1][x[i]-1] = 1;
  }
  */
  init(n);

  for(int i=0;i<m;i++){
    unite(x[i],y[i]);
    //unite(y[i]-1,x[i]-1);
  }

  for(int i=1;i<n+1;i++){
    if(i == p[i]){
      cnt++;
      continue;
    }
    else{
      cnt += (int)same(i,p[i]);
    }
  }
  cout << cnt << endl;

  //show_v(v,n);
  /*
  vector< UnionFind > graph(n);

  for(int i=0;i<m;i++){
    graph[y[i]-1]._union(&graph[x[i]-1]);
  }

  for(int i=0;i<n;i++){
    //graph[i].show_root();
  }

  for(int i=0;i<n;i++){
    cnt+=graph[i].find(&graph[p[i]-1]);
  }

  cout << cnt << endl;
  */
  //cout << "debug" << endl;

  //for(int i=1;i<n+1;i++) cout << par[i] << endl;

  return 0;
}

void show_v(vector< vector<int> > &v,int n){
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cout << v[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rnk[i]=0;
  }
}
int rt(int x){

  return par[x]==x ? x : par[x]=rt(par[x]);
}
bool same(int x,int y){
  return rt(x) == rt(y);
}
void unite(int x,int y){
  int temp_x;
  int temp_y;
  temp_x=rt(x);
  temp_y=rt(y);

  if(temp_x==temp_y) return ;
  if(rnk[temp_x] < rnk[temp_y]){
    par[temp_x]=temp_y;
  }
  else{
    par[temp_y]=temp_x;
    if(rnk[temp_x] == rnk[temp_y]) rnk[temp_x]++;
  }
}


Measured memory_bytes: 2176
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
using namespace std;

typedef long long ll;
ll mod = 998244353;
ll cnt[100005];

int main(){
   int N;
   cin >> N;
   vector<int> D(N);
   int Max = 0;
   for(int i = 0; i < N; i++){ 
      cin >> D[i];
      cnt[D[i]]++;
      Max = max(Max, D[i]);
   }
   ll ans = 0;
   if(D[0] != 0) ans = 0;
   else{
      ans = 1;
      if(cnt[0] != 1) ans = 0;
      for(int i = 1; i <= Max; i++){
         if(cnt[i] == 0) ans = 0;
         for(int j = 0; j < cnt[i+1]; j++){
            ans = ans * cnt[i] %mod;
         }
      }
   }
   cout << ans << endl;
}



Measured memory_bytes: 1408
N,M=map(int,input().split())
xyz= [list(map(int,input().split())) for _ in [0]*M]
par = [-1]*N
def get_parent(n):
    if par[n]==-1:return n
    else:
        par[n] = get_parent(par[n])
        return par[n]
def merge(i,j):
    i = get_parent(i)
    j = get_parent(j)
    if i!=j:par[j] = i
    return
for x,y,z in xyz:
    merge(x-1,y-1)
print(par.count(-1))

Measured memory_bytes: 30680
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include<list>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int k, n;
    cin >> k >> n;
    char** bitmap;
    char** bitmap_r;
    char** bitmap_c;
    bitmap = new char*[n];
    bitmap_r = new char*[n];
    bitmap_c = new char*[n];
    rep(i, n){
        bitmap[i] = new char[n];
        bitmap_r[n-1-i] = new char[n];
        bitmap_c[n-1-i] = new char[n];
        string p;
        cin >> p;
        rep(j, n){
            bitmap[i][j] = p[j];
            bitmap_c[n-1-i][j] = p[j];
            bitmap_r[n-1-i][n-1-j] = p[j];
        }
    }

    int ans = 0;
    bool flag_t = false;
        rep(j, n){
            if(memcmp(bitmap[j], bitmap_r[j], sizeof(char)*n)){
                flag_t = true;
                break;
            }else if(memcmp(bitmap[j], bitmap_c[j], sizeof(char)*n)){
                flag_t = true;
                break;
            }
        }
        if(!flag_t){
            ++ans;
        }

    rep(i, k-1){
        int d, r, c;
        cin >> d;
        rep(j, d){
            cin >> r >> c;
            --r;
            --c;
            bitmap[r][c] = bitmap[r][c]^1;
            bitmap_r[n-1-r][n-1-c] = bitmap[r][c];
            bitmap_c[n-1-r][c] = bitmap[r][c];
        }

        bool flag = false;
        rep(j, n){
            if(memcmp(bitmap[j], bitmap_r[j], sizeof(char)*n)){
                flag = true;
                break;
            }else if(memcmp(bitmap[j], bitmap_c[j], sizeof(char)*n)){
                flag = true;
                break;
            }
        }
        if(!flag){
            ++ans;
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 6148
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n];
  int count=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]>=k)
      count++;
  }
  cout<<count<<"\n";
}
  


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& 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;
}

bool check(pair<int,int> a, pair<int,int> b) {
	return a < b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long 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;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	vint a(32, 0), b(32, 0);//aが0の個数
	rep(i, n) {
		int x;
		cin >> x;
		for (int j = 0; j < 32; j++) {
			if (x % 2 == 0) {
				a[j]++;
			}
			else {
				b[j]++;
			}
			x /= 2;
		}
	}
	rep(i, 32) {
		if (b[i] != 0) {
			if (a[i] * 2 != b[i]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
typedef vector<long long> vlint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<vector<long long>> vlint2;

lint powmod(lint a, lint b, lint mod = 1000000007) {
   lint res = 1;
   for (a %= mod; b; a = a * a % mod, b >>= 1)
     if (b & 1) res = res * a % mod;
   return res;
}


int main() {
  lint x; cin >> x;
  lint y; lint a, ans_b;
  bool has_ans = false;
  for (lint b = -100000; b <= 100000; b++){
    y = x + b*b*b*b*b;
    lint left = -10000;
    lint right = 10000;
    lint mid = (left + right) / 2;
    while(left < right){
      mid = (left + right) / 2;
      if (mid * mid * mid * mid * mid == y){
        has_ans = true;
        a = mid; ans_b = b;
        break;
      };
      if (mid * mid * mid * mid * mid > y){
        right = mid - 1;
      }
      else{
        left = mid + 1;
      }
    }
    if (has_ans) break;
  }
  cout << a << " " << ans_b << endl;
}




Measured memory_bytes: 3636
import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
C = [int(a) - 1 for a in input().split()]
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

def EulerTour(n, X, i0):
    f = lambda k: k * (k + 1) // 2
    USED = [0] * n
    ORG = [0] * n
    TMP = [0] * n
    P = [-1] * n
    Q = [~i0, i0]
    ct = -1
    ET1 = [0] * n
    ET2 = [0] * n
    ANS = [f(n)] * n
    done = [0] * n
    while Q:
        i = Q.pop()
        if i < 0:
            i = ~i
            ET2[i] = ct
            USED[C[i]] += 1 + TMP[i]
            if i:
                k = ET2[i] - ET1[i] + 1 - USED[C[P[i]]] + ORG[i]
                ANS[C[P[i]]] -= f(k)
                TMP[P[i]] += k
            continue
        done[i] = 1
        if i: ORG[i] = USED[C[P[i]]]
        ct += 1
        ET1[i] = ct
        for a in X[i]:
            if done[a]: continue
            P[a] = i
            Q.append(~a)
            Q.append(a)
    for i in range(n):
        ANS[i] -= f(n - USED[i])
    return ANS

print(*EulerTour(N, X, 0), sep = "\n")

Measured memory_bytes: 85812
# coding: utf-8
# Your code here!
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
    
X,Y=map(int,input().split())

if (X+Y)%3==0 and Y<=2*X and Y>=X/2:
    temp=(X+Y)//3
    temp2=X-Y
    x=(temp+temp2)//2
    y=(temp-temp2)//2
    
    m=10**9+7
    ans=1
    for i in range(x+y):
        ans=ans*(i+1)%m
    for i in range(x):
        ans=ans*mod_inv(i+1,m)%m
    for i in range(y):
        ans=ans*mod_inv(i+1,m)%m
    print(ans%m)
    
else:
    print(0)
    



Measured memory_bytes: 42780