akhauriyash/Code-Regression huggingface dataset:
class Node
  attr_accessor :parent, :rank
 
  def initialize
    @parent = -1 # Positive value means its parent,and Negative value means its size.
    @rank = 0
  end
end
 
class UnionFindTree
  def initialize(n)
    @nodes = (0...n).to_a.map { |i| Node.new }
  end
 
  def find(x)
    return @nodes[x].parent < 0 ? x : @nodes[x].parent = find(@nodes[x].parent)
  end
 
  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b
 
    if @nodes[a].rank < @nodes[b].rank
      @nodes[b].parent += @nodes[a].parent
      @nodes[a].parent = b
    else
      @nodes[a].parent += @nodes[b].parent
      @nodes[b].parent = a
      @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
    end
  end
 
  def same?(a, b)
    find(a) == find(b)
  end
  
  def size(a)
    -@nodes[find(a)].parent
  end
 
  # 確認用。アルゴリズムとは関係無い
  def parents
    @nodes.map(&:parent)
  end
end

# n = gets.to_i
n, m, k = gets.split.map(&:to_i)


uft = UnionFindTree.new(n)
friends = Array.new(n){[]}
blocks = Array.new(n){[]}

m.times do |i|
    x,y = gets.split.map(&:to_i).map{|k| k-=1 }
    uft.unite(x, y)
    friends[x] << y
    friends[y] << x
end

k.times do |i|
    x,y = gets.split.map(&:to_i).map{|k| k-=1 }
    if uft.same?(x,y)
        blocks[x] << y
        blocks[y] << x
    end
end

n.times do |i|
    print uft.size(i) - 1 - friends[i].size - blocks[i].size 
    print i == n - 1 ? "\n" : " "
end

Measured memory_bytes: 31340
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

int main(){
    ll n; std::cin>>n;
    std::vector<ll> a;
    for(int i=0; i<n; ++i){
        ll b; std::cin>>b; a.push_back(b);
    }

    std::vector<ll> flag(9, 0);
    for(int i=0; i<n; ++i){
        if(1<=a[i]&&a[i]<400){
            ++flag[0];
        }else if( 400<=a[i]&&a[i]<800){
            ++flag[1];
        }else if( 800<=a[i]&&a[i]<1200){
            ++flag[2];
        }else if(1200<=a[i]&&a[i]<1600){
            ++flag[3];
        }else if(1600<=a[i]&&a[i]<2000){
            ++flag[4];
        }else if(2000<=a[i]&&a[i]<2400){
            ++flag[5];
        }else if(2400<=a[i]&&a[i]<2800){
            ++flag[6];
        }else if(2800<=a[i]&&a[i]<3200){
            ++flag[7];
        }else{
            ++flag[8];
        }
    }

    ll ans = 0;
    for(int i=0; i<8; ++i){
        if(flag[i]>0) ++ans;
    }
    std::cout << std::max(ans, 1LL) << " " << ans + flag[8];
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
bool gg;
int E,nxt[500010],hed[500010],P,Q,nedge,too[500010],val[500010],d[500010],n,m,x,y,cnt[3];
LL ans;
void ae(int x,int y,int w){
	nxt[++nedge]=hed[x];
	hed[x]=nedge;
	too[nedge]=y;
	val[nedge]=w;
}
void dfs(int x,int D){
	++cnt[D];
	d[x]=D;
	for (int i=hed[x];i;i=nxt[i]){
		int y=too[i];
		++E;
		if (d[y]==-1) dfs(y,(D+val[i]+3)%3);
		if ((D+val[i]+3)%3!=d[y]) gg=1;
	}
}
int main(){
	cin>>n>>m;
	FOR(i,1,m){
		getint(x),getint(y);
		ae(x,y,1),ae(y,x,-1);
	}
	memset(d,-1,sizeof(d));
	FOR(rp,1,n) if (d[rp]==-1){
		cnt[0]=cnt[1]=cnt[2]=0;
		gg=0;
		E=0;
		dfs(rp,0);
		if (gg) ans+=1ll*(cnt[0]+cnt[1]+cnt[2])*(cnt[0]+cnt[1]+cnt[2]);
		else if (!cnt[0] || !cnt[1] || !cnt[2]) ans+=E/2;
		else ans+=1ll*cnt[0]*cnt[1]+1ll*cnt[1]*cnt[2]+1ll*cnt[2]*cnt[0];
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


struct process{
	string name;
	int time;
};

signed main(){

	int n, q;
	queue<process> que;
	vector<pair<string, int> > v;

	cin >> n >> q;
	for (int i = 0; i < n; i++){
		process p;
		cin >> p.name >> p.time;
		que.push(p);
	}

	int time = 0;
	while (que.size()>0){
		process p = que.front();
		if (p.time > q){
			p.time -= q;
			time += q;
			que.pop();
			que.push(p);
		}
		else{
			process p = que.front();
			pair<string, int> a;
			a.first = p.name;
			a.second = time + p.time;

			time += p.time;
			que.pop();
			v.push_back(a);
		}
	}

	for (int i = 0; i < v.size(); i++){
		cout << v[i].first << " " << v[i].second << endl;
	}

	return 0;
}



Measured memory_bytes: 6892
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<ll> A, B;
    int nA = N+1;
    int nB = N;
    while(nA--) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    while(nB--) {
        ll b;
        cin >> b;
        B.push_back(b);
    }

    ll nm = 0;
    for (int i=0; i<N; i++) {
        int hit = min(A[i], B[i]);;
        // A[i] -= hit;
        B[i] -= hit;
        nm += hit;

        hit = min(A[i+1], B[i]);
        A[i+1] -= hit;
        // B[i] -= hit;
        nm += hit;
    }

    cout << nm << endl;

    return 0;
}

Measured memory_bytes: 2548
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<iomanip>
#include<string>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e5+10;
int main()
{
    int k,a,b;
    cin>>k>>a>>b;
    if(a%k==0||b%k==0) cout<<"OK"<<endl;
    else if(b-a>=(k-(a%k))) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] nums = sc.nextLine().split(" ");
		int a = Integer.parseInt(nums[0]);
		int b = Integer.parseInt(nums[1]);
		int c = Integer.parseInt(nums[2]);
		if(a < b && b < c){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 17284
#include <cstdio>

int main() {
    int r, g, b;
    scanf("%d %d %d", &r, &g, &b);

    int num = 100*r + 10*g + 1*b;
    if (num%4 == 0)
        printf("YES");
    else
        printf("NO");

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
long long mod = 1e9+7;

long long f(long long x, long long c, long long d) {
  long long cd = c*d/__gcd(c, d);
  return x - (x/c + x/d - x/cd);
}

int main(void) {
  long long a, b, c, d; cin >> a >> b >> c >> d;
  long long ans = f(b, c, d) - f(a-1, c, d);
  cout << ans << endl;

  return 0;
}

// EOF


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author emli
 */


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

class CPeaks {
public:

    void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);

        int n,m;

        cin >> n >> m;

        vector<int> h(n + 1);

        vector<bool> used(n + 1,true);
        for (int i = 1; i <= n; ++i) {
            cin >> h[i];
        }


        for (int j = 0; j < m; ++j) {
            int x,y;
            cin >> x >> y;
            if (h[x] <= h[y]){
                used[x] = false;
            }
            if (h[y] <= h[x]){
                used[y] = false;
            }
        }

        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            ans += used[i];
        }

        cout << ans << endl;


	}
};


int main() {
	CPeaks solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3728
#include <stdio.h>

int main(){
    int N,A,B;
    int n;
    int dig,num,sum,sum2;

    scanf("%d %d %d",&N,&A,&B);

    for(n = 1; n <= N; n++){
        num = n;

        sum = 0;
        while(1){
            dig = (num % 10);
            sum += dig;
            num /= 10;
            if(num == 0) break; 
        }

        if(sum >= A && sum <= B){
            sum2 += n;
        }
    }

    printf("%d",sum2);

    return 0;
}

Measured memory_bytes: 128
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let line = read_as_vec::<usize>();
    let (x, y) = (line[0], line[1]);
    for turu in 0..=x {
        let tartle = x - turu;
        if y == turu * 2 + tartle * 4 {
            println!("Yes");
            return;
        }
    }

    println!("No");
}


Measured memory_bytes: 2132
#include <stdio.h>
int main(void)
{
  int a,b,c;
  scanf("%d %d %d", &a,&b,&c);
    if (a < b)
        if(b<c)
            puts("Yes");
        else
            puts("No");
    else 
        puts("No");
    return 0;
}



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

int main(void){
  int n;
  cin >> n;
  int p[n];
  for(int i = 0; i < n; i++) cin >> p[i];
  int ans = 0;
  int i = 0;
  while(i < n){
    if(p[i] == i + 1){
      ans++;
      i += 2;
    }else{
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val Array(a, b, c, d) = sc.nextLine.split(" ").map(_.toInt)
    if (Array(b, d).min - Array(a, c).max <= 0) println(0)
    else println(Array(b, d).min - Array(a, c).max)
  }
}


Measured memory_bytes: 27572
import java.util.Scanner;
 
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int x = scanner.nextInt();

        int currentPlace = 0;
        int c = 0;
        for(int k = 0; k < n; k++) {
        	if(currentPlace <= x) {
        		c ++;
        	} 
        	currentPlace = currentPlace + scanner.nextInt();
        }
        
        if(currentPlace <= x) {
        	c++;        }
        System.out.println(c);
    }
 
}

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

int main() {
  int K, S;
  cin >> K >> S;
  
  int count = 0;
  
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (0 <= z && z <= K) count ++;
    }
  }
  
  cout << count << endl;
}

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

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

    vector<int> L(N);
    for(int i = 0; i < N; i++) cin >> L.at(i);

    bool check;
    int Max, ans = 0;

    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            for(int k = j+1; k < N; k++){
                check = true;

                if(L.at(i) == L.at(j) || L.at(j) == L.at(k) || L.at(k) == L.at(i))
                check = false;

                Max = max(max(L.at(i), L.at(j)), L.at(k));
                if(check && (Max < L.at(i) + L.at(j) + L.at(k) - Max)) ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long h = Long.parseLong(sc.next());
    if (h == 1) {
      pw.println("1");
      return;
    }
    long ans = 0;
    long numberOfNodes = 1;
    long nextH = h;
    while (nextH != 1) {
      ans += numberOfNodes;
      numberOfNodes *= 2;
      nextH /= 2;
    }
    ans += numberOfNodes;
    pw.println(ans);
  }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long N,K;cin>>N>>K;
    vector<long long>A(N);
    vector<long long>B(N,0);
    for(long long i=0;i<N;i++){
        cin>>A[i];
        B[A[i]-1]++;
    }
    long long count=0;
    for(long long i=0;i<N;i++){
        if(B[i]>=1){
            count++;
        }
    }
    sort(B.begin(),B.end());
    long long ans=0;
    long long i=0;
    while(count>K){
        if(B[i]>=1){
            count--;
            ans+=B[i];
        }
        i++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6364
//B
//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	LL x;
	scanf("%lld", &x);
	LL cnt = 100;
	int ans = 0;
	while (cnt < x) {
		cnt += cnt / 100;
		ans++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3828
N, K = map(int, input().split())
H = list(map(int, [0] + input().split() + [0]))
d = [[10**18]*(K+1) for _ in range(N+2)]
for i in range(K+1):
    d[0][i] = 0
for hi in range(N+1):
    hi+=1
    h = H[hi]
    for i in range(min(K+1, hi)):
        for k in range(i+1):
            d[hi][i] = min(d[hi][i], d[hi-k-1][i-k] + max(H[hi-k-1]-h, 0))
print(min(d[-1]))


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL H, W, D;
  cin >> H >> W >> D;

  VVL xs(H, VL(W));
  vector<PLL> pos(H*W);
  REP(y,H) REP(x,W){
	cin >> xs[y][x];
	--xs[y][x];
	pos[xs[y][x]] = MP(y, x);
  }

  LL HW = H * W;
  VVL num(D);
  VL acc(D);
  REP(y,H) REP(x,W){
	if(xs[y][x] >= D) continue;

	LL d = xs[y][x];
	LL d_ = d;
	num[d].PB(0);
	acc[d] = 0;
	d += D;
	while(d < HW){
	  acc[d_] += abs(pos[d].FF - pos[d-D].FF) + abs(pos[d].SS - pos[d-D].SS);
	  num[d_].PB(acc[d_]);
	  d += D;
	}
	if(0 <= d-D && d-D < HW)
	  acc[d_] += abs(pos[d-D].FF - pos[xs[y][x]].FF) + abs(pos[d-D].SS - pos[xs[y][x]].SS);
  }

  LL Q;
  cin >> Q;
  while(Q--){
	LL l, r;
	cin >> l >> r;
	--l;
	--r;
	LL d = l % D;
	LL lx = num[d][(l-d)/D];
	LL rx = num[d][(r-d)/D];
	if(lx <= rx) cout << rx-lx << endl;
	else cout << acc[d] - (lx - rx) << endl;
  }

  return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <cstring>

using namespace std;

int road[200005][2];

bool to[200005];

int main()
{
	int n,m;
	cin>>n>>m;
	
	memset(road,0,sizeof road);
	memset(to,0,sizeof to);
	for(int i=0;i<m;i++)
	{
		cin>>road[i][0]>>road[i][1];
		if(road[i][0]==1) to[road[i][1]]=1;
	}
	for(int i=0;i<m;i++)
	{
		if(to[road[i][0]] && road[i][1]==n)
		{
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 2048
N = int(input())
#N,M = map(int,input().split())
#A = list(map(int,input().split()))
#A = [list(map(int,input().split())) for i in range(N)]
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
ans = 1
mod = 10**9+7
prime = primes(N)
for i in prime:
    isum = 0
    for n in range(2,N+1):
        while n%i == 0:
            isum += 1
            n //= i
    ans = (ans*(isum+1))%mod
print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N * 3);
  for (int i = 0; i < N * 3; i++) cin >> A.at(i);
  sort(A.rbegin(), A.rend());
  long ans = 0;
  for (int i = 1, cnt = 0; i < N * 3; i += 2) {
    ans += A.at(i);
    cnt++;
    if (cnt == N) break;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
 int a;
 cin >> a;
 string b, c;
 cin >> b >> c;
  for(int i = 0;i<a;i++){
   cout << b.at(i) << c.at(i);
 }
  cout << endl;
}


Measured memory_bytes: 3564
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int N, A, B;
  cin >> N >> A >> B;
  vector<int> X(N);
  for(int& x : X) cin >> x;
  
  long long ans = 0;
  for(int i = 0; i < N - 1; i++){
    ans += min(1LL * A * (X[i + 1] - X[i]), 1LL * B);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>

#include <bits/stdc++.h> 

using namespace std; 



int main()

{

int a[3],s=0,i;

for(i=0;i<3;i++)
scanf("%d",&a[i]);

sort(a, a+3);

for(i=0;i<2;i++)
	
  s=s+(a[i+1]-a[i]);


printf("%d\n",s);

return 0;

}



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

const int k_mod = ( int )1e9 + 7;
int main( void ){
	int n;
	if (!scanf( "%d", &n ))
		return -1;
	string str;
	cin >> str;
	rep(i, 0, str.length()){
		int temp = (int)str[i] - (int)'A' + n;
		temp%=26;
		printf("%c", (char)(temp + (int)'A'));
	}
	return 0;
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    ll n, h;
    cin >> n >> h;
    
    v_ll b(n);
    ll max_a = -1;

    irep(i, n) {
        ll a; 
        cin >> a >> b[i];
        if(a > max_a) { max_a = a; }
    }

    sort(b.rbegin(), b.rend());

    ll ans = 0;
    irep(i, n) {
        if(max_a > b[i] || h <= 0) { break; }
        h -= b[i];
        ans++;
    }

    if(h>0) {
        ans += (h+max_a-1)/max_a;
    }

    cout << ans << endl;
    return 0;
}
/** atcoder **/


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, ans = 0; cin >> n;
	for (int i = 0; i < n; i++) {
		int p; cin >> p;
		ans += p - 1;
	}
	cout << ans << endl;
}

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


int main () {

int a,b,c;
cin >> a >> b >> c;
bool flag=false;

if(a==b && b!=c ) {
	 flag=true;
}
if(b==c && a!=b)
{
	 flag=true;
}
if(c==a && b!=a)
{
	flag=true;
}

if(flag)
{
	cout << "Yes";
}
else
{
	cout << "No";
}

	return 0;
}











Measured memory_bytes: 3096
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

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

int main() {
  int k;
  cin >> k;
  ll ans = 0;
  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= k; ++j) {
      for (int l = 1; l <= k; ++l) {
        ans += gcd(i, gcd(j, l));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e18
#define mod pow(10,9)+7
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
// void c_p_c()
// {
// 	ios_base::sync_with_stdio(0);
// 	cin.tie(0);
// 	cout.tie(0);
// #ifndef  ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
// }
int32_t main()
{
	//c_p_c();
	int n;
	cin >> n;
	int a[n];
	int i;
	for (i = 0; i < n; i++)
		cin >> a[i];
	int c = 0;
	for (i = 1; i < n - 1; i++)
	{
		if ((a[i] > a[i - 1] && a[i] < a[i + 1]) || (a[i] < a[i - 1] && a[i] > a[i + 1]))
			c++;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
d = list(input().split())
num = [str(i) for i in range(10)]
for i in range(k):
    num.remove(d[i])
    
import itertools, heapq
ans = []
heapq.heapify(ans)
for i in itertools.product(num, repeat=len(str(n))):
    s = int(''.join(i))
    if s >= n:
        heapq.heappush(ans, s)
        
if len(ans) == 0:
    for i in itertools.product(num, repeat=len(str(n)) + 1):
        s = int(''.join(i))
        if s >= n:
            heapq.heappush(ans, s)
    print(heapq.heappop(ans))
    
else:
    print(heapq.heappop(ans))

Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    long long sum=0;
    int mi=1000000010,minus=0,count0=0;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        if(a==0)count0++;
        if(a<0)minus++;
        mi=min(mi,abs(a));
        sum+=abs(a);
    }
    if(count0||minus%2==0)cout<<sum<<endl;
    else cout<<sum-2*mi<<endl;
}

Measured memory_bytes: 256
D,N = gets.split(" ").map { |e| e.to_i }

if N == 100
  if D == 0
  num = N+1
  else
  num = 100**D * (N+1)
  end
else
  if D == 0
    num = N
  else
    num = 100**D * N
  end
end

puts num


Measured memory_bytes: 1788
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdint>
#include <algorithm>
using namespace std;
using i64 = int64_t;

int main(void){
    i64 a, b, c, d;
    cin >> a >> b >> c >> d;
    i64 ans = max(max(a*c, a*d), max(b*c, b*d));
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

ll powINF(ll x, ll y){
    ll n;
    if(y==0) n=1;
    else if(y%2==0) n=powINF(x,y/2)*powINF(x,y/2);
    else if(y%2==1) n=x*powINF(x,y-1);
    return n%1000000007;
}

int main(){
    ll S;
    cin >> S;
    ll mx=S/3;
    ll ans=0;
    ll INF = 1000000007;
    for(ll i=1; i<=mx; i++){
        ll a=S-3*i;
        ll n=a+i-1;

        ll x=1;
  	    ll y=1;
        for(ll i=n-a+1; i<=n; i++){
            x *= i;
            x %= INF;
        }
        for(ll i=1; i<=a; i++){
            y *= i;
            y %= INF;
        }
  	
        ll c;
  	    c=powINF(y,INF-2);
  	    c *= x;
  	    c %= INF;
		
        ans += c;
        ans = ans%INF;
      	
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
// 24/01/20 // 9:53 PM //

#include <bits/stdc++.h>

using namespace std;

const int MAXN = (int)(3e2) + 10;

int n;
double memo[MAXN][MAXN][2];

void solve(int x, int y, int z){
    for(int c=0; c<=z; c++)
        for(int b=0; b<=y+z; b++)
            for(int a=0; a<=x+y+z; a++){
                if(a+b+c>n || (a==0 && b==0 && c==0)) continue;

                double& estado = memo[a][b][c&1];
                double dn=n, da = a, db = b, dc = c;

                estado = dn;
                if(a>0) estado += da * memo[a-1][b][c&1];
                if(b>0) estado += db * memo[a+1][b-1][c&1];
                if(c>0) estado += dc * memo[a][b+1][~c&1];

                estado /= (da+db+dc);
            }
}

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

    cin >> n;

    int a=0, b=0, c=0;
    for(int i=0; i<n; i++){
        int temp;
        cin >> temp;

        a += (temp==1);
        b += (temp==2);
        c += (temp==3);
    }

    solve(a, b, c);

    cout.precision(10);
    cout.setf(ios::fixed);
    cout << memo[a][b][c&1] << endl;

    return 0;
}


Measured memory_bytes: 1664
N = int(input())

# 4**9 = 2**18 <= 10^6

def dfs(keta,x):
    if x > N:
        return 0
    if keta == 9:
        three = 0
        five = 0
        seven = 0
        while x:
            if x % 10 == 3:
                three += 1
            elif x % 10 == 5:
                five += 1
            elif x % 10 == 7:
                seven += 1
            else:
                return 0
            x //= 10
        if three > 0 and five > 0 and seven > 0:
            return 1
    else:
        ans = 0
        x *= 10
        ans += dfs(keta+1,x)
        ans += dfs(keta+1,x+3)
        ans += dfs(keta+1,x+5)
        ans += dfs(keta+1,x+7)
        return ans
    return 0

print(dfs(0,0))

Measured memory_bytes: 9152
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long ll;
 ll  pp=1e9+7; 
double pi=3.141592653589793238;
  
 int main() {
        ff;
        ll n,k;
        cin>>n>>k;
        ll a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        ll s=0;
        for(int i=0;i<k;i++){
            s+=a[i];
        }
		cout<<s<<endl;
    return 0;
}

            
		
        
           
  

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 501;

int a[250001];

int main()
{
	int n;
	bool flag = false;
	cin >> n;
    vp vec(n);
	rep(i,n){
		cin >> vec[i].fi;
        vec[i].fi--;
		vec[i].se = i;
	}
	sort(all(vec));
	int cur=0;
	for(int i=0;i<n;i++){
		if(a[vec[i].fi] == 0){
			a[vec[i].fi] = vec[i].se+1;
		}else{
			flag = true;
			break;
		}
		int m = 0;
		while(m < vec[i].se){
			if(cur > vec[i].fi){
				flag = true;
				break;
			}
			if(a[cur] == 0){
				a[cur] = vec[i].se+1;
				cur++;
				m++;
			}else{
				cur++;
			}
		}
		if(flag == true){
			break;
		}
	}
	if(flag == false){
		cur = n*n-1;
		rrep(i,n){
			int m = 0;
			while(m < n-1-vec[i].se){
				if(cur < vec[i].fi){
					flag = true;
					break;
				}
				if(a[cur] == 0){
					a[cur] = vec[i].se+1;
					cur--;
					m++;
				}else{
					cur--;
				}
			}
			if(flag == true){
				break;
			}
		}
	}
	if(flag == true){
		cout << "No";
	}else{
		cout << "Yes" << "\n";
		for(int i=0;i<n*n-1;i++){
			cout << a[i] << " ";
		}
		cout << a[n*n-1];
	}
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll kane = 1000;
    ll kabu = 0;

    for (ll i = 0; i < N-1; i++) {
        kane += kabu * A[i];
        kabu = 0;

        if(A[i] < A[i+1]){
            kabu = kane / A[i];
            kane = kane - kabu * A[i];
        }
    }
    kane += kabu * A[N-1];
    printf("%lld\n", kane);
}

Measured memory_bytes: 3720
class SegTree:

    def __init__(self, N, S):
        self.N = 1
        while self.N < N:
            self.N *= 2
        self.tree = [0 for i in range(2 * self.N - 1)]
        for i in range(len(S)):
            self.tree[self.N - 1 + i] = 1 << (ord(S[i]) - ord('a'))
        for i in range(self.N - 2, -1, -1):
            self.tree[i] = self.tree[i * 2 + 1] | self.tree[i * 2 + 2]

    def update(self, index, char):
        i = self.N - 1 + index
        self.tree[i] = 1 << (ord(char) - ord('a'))

        while i > 0:
            i = (i - 1) // 2
            self.tree[i] = self.tree[i * 2 + 1] | self.tree[i * 2 + 2]

    def get(self, a, b):
        return self.query(a, b, 0, 0, self.N)

    def query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return 0
        elif a <= l and r <= b:
            return self.tree[k]
        else:
            left = self.query(a, b, 2 * k + 1, l, (l + r) // 2)
            right = self.query(a, b, 2 * k + 2, (l + r) // 2, r)
            return left | right


def solve():

    N = int(input())
    S = list(input())
    tree = SegTree(N, S)

    Q = int(input())
    for _ in range(Q):
        t_q, in_1, in_2 = input().split()
        if t_q == '1':
            i_q = int(in_1)
            c_q = in_2
            tree.update(i_q-1, c_q)
        elif t_q == '2':
            l_q = int(in_1)
            r_q = int(in_2)
            print(bin(tree.get(l_q-1, r_q)).count('1'))


solve()


Measured memory_bytes: 47400
#include<bits/stdc++.h>
using namespace std;
long long n,m;
int main(){
	cin>>n>>m;
	long long ansx;
	for(int i=m/n;i>=1;i--){
		if(m%i==0){
			ansx=i;
			break;
		}
	}
	cout<<ansx<<endl;
	
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

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

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let a = get!([usize]);

    let mut vec = vec![0usize; n+1];
    for i in 0..n {
        vec[a[i]] += 1;
    }
    let mut sum = 0;
    for i in 0..n+1 {
        if vec[i] == 0 {
            continue;
        }
        sum += vec[i]*(vec[i]-1)/2;
    }

    for k in 0..n {
        println!("{}", sum+1-vec[a[k]]);
    }
}


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

using namespace std;


int main(){
 int a;
 int b;
 int max;
 
cin>>a>>b;
max= a+b;
if(max < a*2-1){
	max = a*2-1;
}
if(max < b*2-1){
	max = b*2-1;
}

cout << max;
return 0;
}

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

int main(){
  
  int k; cin>>k;
  int ans=1;
  ll i = 7, x = 7;
  if(k%2==0||k%5==0){
    cout << -1 << endl;
    return 0;
  }
  x %= k;
  while(1){
    if(x == 0){
      cout << ans << endl;
      return 0;
    }
    i *= 10;
    i %= k;
    x += i;
    x %= k;
    ans++;
  }
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static double x1,x2,y1,y2,x3,y3,a,b,c,a1,b1,c1,xp,yp;
  	static double z(double z1, double z2, double z3, double z4){
        return Math.sqrt(Math.pow(z3-z1, 2) + Math.pow(z4-z2, 2));
  	}
    public static void main(String[] args) {
    	Scanner sc=new Scanner(System.in);
    	while(sc.hasNextInt()){
    		int n=sc.nextInt();
    		for(int i=0;i<n;i++){
    			  x1=sc.nextDouble();
    	          y1=sc.nextDouble();
    	          x2=sc.nextDouble();
    	          y2=sc.nextDouble();
    	          x3=sc.nextDouble();
    	          y3=sc.nextDouble();
    	          a=2*(x2-x1);
    	          a1=2*(x3-x1);
    	          b=2*(y2-y1);
    	          b1=2*(y3-y1);
    	          c=Math.pow(x1,2)-Math.pow(x2,2)+Math.pow(y1,2)-Math.pow(y2,2);
    	          c1=Math.pow(x1,2)-Math.pow(x3,2)+Math.pow(y1,2)-Math.pow(y3,2);
    	          xp=(b*c1-b1*c)/(a*b1-a1*b);
    	          yp=(c*a1-c1*a)/(a*b1-a1*b);
    	          System.out.printf("%.3f %.3f %.3f\n",xp,yp,z(x1,y1,xp,yp));
    		}
    	}
    }
  
}

Measured memory_bytes: 20788
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<string, string> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

map<P, ll> mp[2];

int main(void){
	int n,i,j,m;
	string s;
	ll ans=0ll;
	cin >> n;
	cin >> s;
	m = (1<<n);
	i = n; j = 2*n-1;
	while(i < j){
		swap(s[i],s[j]);
		++i; --j;
	}
	for(i=0; i<m; ++i){
		string a,b,c,d;
		for(j=0; j<n; ++j){
			if(i&(1<<j)){
				a.push_back(s[j]);
				c.push_back(s[j+n]);
			}else{
				b.push_back(s[j]);
				d.push_back(s[j+n]);
			}
		}
		++mp[0][P(a,b)];
		++mp[1][P(c,d)];
	}
	for(auto itr = mp[0].begin(); itr != mp[0].end(); ++itr){
		ans += itr->second * mp[1][itr->first];
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
	int n;
	cin >> n;
	if (n%10==3){
		cout << "bon" << endl;
    }
	else if (n%10==0 || n%10==1 || n%10==6 || n%10==8){
		cout << "pon" << endl;
    }
	else{
		cout << "hon" << endl;
    }
}

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

using namespace std;

using ll = long long;

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    vector<ll> a(3);
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0) {
        cout << 0 << endl;
    } else {
        cout << a[0] * a[1] << endl;
    }
}

Measured memory_bytes: 764
#include <stdio.h>

int main()
{
	char s[4],a[91] = {0};
	int i,m,p = 0;
	gets(s);
	for(i = 0;i < 4;i++){
		m = s[i];
		a[s[i]]++;
	}
	for(i = 65;i < 91;i++){
		if(a[i] != 0){
			p += 1;
		}
	}
	if(p == 2)
		printf("Yes");
	else
		printf("No");
	return 0;
}

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

using namespace std;


typedef long long LL;

const LL MOD=1e9+7;
#define SZ 2000000
LL fact[SZ];
struct cww{cww(){
    ios::sync_with_stdio(false);cin.tie(0);
    fact[0]=1;
    for(LL i=1;i<SZ;i++)
        fact[i]=fact[i-1]*i%MOD;
}}init;
// a x + b y = gcd(a, b)
// O(log (a+b) )
LL extgcd(LL a, LL b, LL &x, LL &y) {
  LL g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

// mを法とするaの逆元
// O(log a)
LL invMod(LL a) {
	LL x, y;
	if (extgcd(a, MOD, x, y) == 1)return (x + MOD) % MOD;
	else	 return 0; // unsolvable
}


// 組み合わせnCk (mod MOD)
// O(n)
LL Comb(LL n,LL k){
    LL u=fact[n];
    LL d=(fact[k]*fact[n-k])%MOD;
    return (u*invMod(d))%MOD;
}

//a^n (mod MOD)
//O(log a)
LL pow_mod(LL a,LL n){
    LL res=1;
    LL b=1;
    a%=MOD;
    while(n>=b){
        if(n&b)
            res=(res*a)%MOD;
        a=(a*a)%MOD;
        b<<=1;
    }
    return res;
}

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

    LL res=pow_mod(3,M+K);
    LL bg=0,ed=0,sum=1;
    for(LL i=1;i<=M+K;i++){
        LL ne=min(M,i);
        LL nb=max(0ll,i-K);
        sum*=2;
        if(nb>bg)sum+=MOD-Comb(i-1,bg);
        if(ne==ed)sum+=MOD-Comb(i-1,ed);
        sum%=MOD;
        // cout<<sum<<endl;
        LL a=Comb(N-1+i,N-1)*sum%MOD;
        a=a*pow_mod(3,M+K-i)%MOD;
        res=(res+a)%MOD;
        ed=ne,bg=nb;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9

lli n,a,b,c,d;
map<lli,lli>mm;
lli func0(lli num)
{
    lli t=1e18;
    lli q=t/a;
    if(num>q)
        return t;
    else
        return a*num;
}

lli func(lli num)
{
    if(mm.find(num)!=mm.end())
        return mm[num];
    if(num==0)
        return 0;
    if(num==1)
        return a;
    lli a0=func0(num),a1,a2,a3;
    if(num%2==0)
        a1=b+func(num/2);
    else
        a1=b+min(a+func((num-1)/2),a+func((num+1)/2));
    lli r=num%3;
    if(r==0)
        a2=c+func(num/3);
    else
        a2=c+min(r*a+func((num-r)/3),(3-r)*a+func((num+3-r)/3)); 
    r=num%5;
    if(r==0)
        a3=d+func(num/5);
    else
        a3=d+min(r*a+func((num-r)/5),(5-r)*a+func((num+5-r)/5)); 
    // << num << endl;
    //cout << a0 << " " << a1 << " " << a2 << " " <<  a3 << endl;
    lli ans=min({a0,a1,a2,a3});
    mm[num]=ans;
    return ans;
}

int main()
{
    fastio;
    int te;
    cin >> te;
    for(int w=0;w<te;w++)
    {
        mm.clear();
        cin >> n  >> b >> c >> d >> a;
        cout << func(n) << endl;
    }
}

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

bool evenChecker(int a[], int size){
    for(int i=0; i<size; i++){
        if(a[i]%2) return false;
    }
    return true;
}

int main(){
    int n,c=0;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++) cin>>a[i];
    while( evenChecker(a,n) ){
        for(int i=0; i<n; i++) a[i]/=2;
        c++;
    }
    cout<<c;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string s1 = S.Substring(0, (S.Length - 1) / 2);
            string s2 = S.Substring((S.Length + 3-1 ) / 2);
            if (s1 == s2)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

//文字列の入力
//string s = Console.ReadLine();
//整数の入力
//long n = long.Parse(Console.ReadLine());
//文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine();
//Console.ReadKey();


Measured memory_bytes: 25912
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


A = [LMI() for _ in range(3)]
N = I()
B = [I() for _ in range(N)]

bingo = [[False] * 3 for _ in range(3)]

for b in B:
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                bingo[i][j] = True
if all(bingo[0]) or all(bingo[1]) or all(bingo[2]):
    print('Yes')
elif all(row[0] for row in bingo) or all(row[1] for row in bingo) or all(row[2] for row in bingo):
    print('Yes')
elif bingo[0][0] and bingo[1][1] and bingo[2][2]:
    print('Yes')
elif bingo[0][2] and bingo[1][1] and bingo[2][0]:
    print('Yes')
else:
    print('No')

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int price[4] = {6000, 4000, 3000, 2000};
	for(int i = 0; i < 4; i++)
	{
		int ticket = in();
		int num = in();
		printf("%d\n", price[ticket - 1] * num);
	}
	return (0);
}

Measured memory_bytes: 1188
import java.util.Scanner;

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

		int[] seikai = new int[N + 1];

		for(int i = 1;i <= Q;i++) {
			int A = sc.nextInt();
			seikai[A]++;
		}
		sc.close();

		//プレイヤーiはseikai[i]回正解した
		//つまり、プレイヤーiは(Q-seikai[i])回不正解した
		//したがって、プレイヤーiの得点は、
		//K-(Q-seikai[i]) = K-Q+seikai[i]
		//これが0より大きければ勝ち抜け

		for(int i = 1;i <= N;i++) {
			System.out.println(K - Q + seikai[i] > 0 ? "Yes" : "No");
		}

	}
}

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

#ifdef DEBUG
#include "../.inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

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

    int a, b;
    vector<vector<int>> G(n);
    for (int i=0; i<m; ++i) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    if (m % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> dep(n, -1);
    vector<int> deg(n, 0);
    function<void(int,int,int)> dfs = [&](int v, int par, int d) {
        dep[v] = d;
        for (int to: G[v]) {
            if (dep[to] < 0) {
                dfs(to, v, d+1);
            } else if (d < dep[to]) {
                cout << v+1 << " " << to+1 << endl;
                deg[v] ++;
            }
        }
        if (par < 0) return;
        if (deg[v] % 2 == 1) {
            cout << v+1 << " " << par+1 << endl;
            deg[v] ++;
        } else {
            cout << par+1 << " " << v+1 << endl;
            deg[par] ++;
        }
    };

    dfs(0, -1, 0);

    return 0;
}

Measured memory_bytes: 20224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	string S;
	cin >> S;

	int OK = 1;
	rep(i, S.size()) {
		if (i % 2 == 0) {
			if (S[i] == 'L') OK = 0;
		}
		else {
			if (S[i] == 'R') OK = 0;
		}
	}
	if (OK) co("Yes");
	else co("No");

	Would you please return 0;
}

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

int msb(int a) {
  int res{0};
  while (a) {
    a >>= 1;
    res++;
  }
  return res;
}

int main() {
  int N;
  std::cin >> N;
  std::cout << (1 << (msb(N) - 1)) << std::endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define fi first
#define se second
#define sqrt(x) sqrt(abs(x))
#define sqr(x) ((x) * (x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define fill(x, y) memset(x, y, sizeof(x))
#define mp make_pair
#define pb emplace_back
#define popcnt __builtin_popcount
#define ctz __builtin_ctz

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
template <class T> using indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T>
istream& operator >> (istream &in, vector <T> &a) {
    for (T &i: a) in >> i;
    return in;
}

template <class T>
ostream& operator << (ostream &out, vector <T> &a) {
    for (T &i: a) out << i << ' ';
    return out;
}

template <class T>
ostream& operator << (ostream &out, set <T> &a) {
    for (auto &i: a) out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator >> (istream &in, pair <T, U> &p) {
    in >> p.first >> p.second;
    return in;
}

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

void fastIO() {
    ios_base:: sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
}

ld s;

signed main() {
    fastIO();

    cin >> s;
    cout << fixed << setprecision(8);
    cout << sqr(s / 3) * (s / 3);

    return 0;
}

/// ЗАПУСКАЕМ ГУСЯ:
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */



Measured memory_bytes: 256