akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	int n, h;
	cin >> n >> h;
	int a, b[100001] = {};
	int ma = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b[i];
		ma = max(ma, a);
	}
	sort(b, b + n, greater<int>());
	int ans = 0;
	for (int i = 0; i <= n; ++i) {
		if (b[i] > ma && h > 0) {
			h -= b[i];
			ans++;
		}
	}
	if (h > 0) ans += (h + ma - 1) / ma;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String args[] ) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = Integer.valueOf(  sc.nextLine() ) ;

		Set<String> set = new HashSet<>() ;
		for ( int j=0 ; j<N ; j++ ) 
			 set.add ( sc.nextLine() ) ;
		System.out.println( set.size() ) ;
	 }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}


using namespace std;

const int max_n = 1e3 + 5;

int dp[55][55][55];
VI v, w;
bool check(int k) {
	FOR(i,0,v.size()) {
		if (dp[v[i]][w[i]][k] == 0) {
			return false;
		}
	}
	return true;
}

int main() {
	make(n);
	readv(v,n);
	readv(w,n);
	FOR(i,0,51) FOR(j,0,51) {
		dp[i][j][0] = (i == j) ? 1 : 0;
	}
	FOR(k,1,51) {
		FOR(i,0,51) FOR(j,0,51) {
			if (dp[i][j][k-1] == 1 || dp[i%k][j][k-1]==1) {
				dp[i][j][k] = 1;
			}
		}
	}
	bool dasie = true;
	FOR(i,0,n) {
		if (dp[v[i]][w[i]][50] == 0) dasie = false;
	}
	if (!dasie) {
		printf("-1\n"); return 0;
	}
	lint ans = 0;
	while (1) {
		int k = 0;
		while (!check(k)) {
			k++;
		}
		if (k==0) break;
		ans += (1LL<<k);
		FOR(u,0,k) {
			FOR(i,0,51) FOR(j,0,51) {
				if (dp[i%k][j][u] == 1) dp[i][j][u] = 1;
			}
		}
		vector<PII> pary;
		FOR(i,0,51) FOR(j,0,51) if (i!=j && dp[i][j][0] == 1) pary.pb(mp(i,j));
		FOR(i,0,51) FOR(j,0,51) {
			FORE(x, pary) {
				if (dp[x->nd][i][j] == 1) dp[x->st][i][j] = 1;
			}
		}
	}
	printf("%lld\n", ans);
}


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

XY = []
for _ in range(N):
    A = int(input())

    temp = []
    for _ in range(A):
        temp.append(list(map(int, input().split())))

    XY.append(temp)


max_honest = 0
for c in range(1 << N):
    check = [0] * N
    contradict = False

    cnt1 = 0
    while c != 0:
        if 1 & c:
            check[cnt1] = 1

        c >>= 1
        cnt1 += 1

    for i in range(N):
        if check[i] == 1:
            for x, y in XY[i]:
                if check[x - 1] != y:
                    contradict = True
                    break

            if contradict:
                break

    if not contradict:
        max_honest = max(max_honest, sum(check))


print(max_honest)


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	int N; scanf("%d", &N);
	int p[100],p_copy[100];
	for (int i = 0; i < N; i++){
		scanf("%d", p + i);
		p_copy[i] = p[i];
	}

	sort(p_copy, p_copy + N);

	int diff = 0;
	for (int i = 0; i < N; i++){
		if (p[i] != p_copy[i]){
			diff++;
		}
	}

	if (0 == diff || 2 == diff){
		printf("YES");
	}
	else{
		printf("NO");
	}

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

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

int main(){
  int n,h,w,ans=0,i,a,b;
  cin >> n >> h >> w;
  for(i=0; i<n; i++){
    cin >> a >> b;
    if(a>=h && b>=w){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
int n;
set<int> st;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		st.insert(a);
	}
	cout<<(sz(st)==n?"YES":"NO");
	re 0;
}

Measured memory_bytes: 12984
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;



int main(){

  int n;
  cin >> n;
  vector<int> p(n);
  REP(i,n) cin >> p[i];
  int cnt = 0;

  REP(i,n){
    --p[i];
    if(p[i] != i) ++cnt;
  }

  if(cnt == 0 || cnt == 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  //cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3588
use std::io::Read;

fn partition_point<Pred>(s: &[i32], pred: Pred) -> usize
where
    Pred: Fn(i32) -> bool,
{
    let mut left = 0;
    let mut right = s.len();
    while right - left > 0 {
        let mid = (left + right) / 2;
        if pred(s[mid]) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    right
}

fn solve(_n: usize, a: &mut [i32], b: &mut [i32], c: &mut [i32]) -> usize {
    a.sort();
    b.sort();
    c.sort();
    b.iter()
        .map(|&x| partition_point(a, |y| y < x) * (c.len() - partition_point(c, |y| y <= x)))
        .sum::<usize>()
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut a = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect::<Vec<_>>();
    let mut b = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect::<Vec<_>>();
    let mut c = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect::<Vec<_>>();
    let r = solve(n, &mut a, &mut b, &mut c);
    println!("{}", r);
}


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

int main() {
	int n;
	int cards[4][13];
	char mark;
	int num;

	for(int i=0; i<4; i++) {
		for(int j=0; j<13; j++) {
			cards[i][j] = 0;
		}
	}

	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> mark >> num;
		switch(mark){
			case 'S': cards[0][num-1] = 1; break;
			case 'H': cards[1][num-1] = 1; break;
			case 'C': cards[2][num-1] = 1; break;
			case 'D': cards[3][num-1] = 1; break;
			default: break;
		}
	}

	for(int i=0; i<4; i++) {
		for(int j=0; j<13; j++) {
			if(cards[i][j] == 0) {
				switch(i) {
					case 0: cout << "S " << j+1 << endl; break;
					case 1: cout << "H " << j+1 << endl; break;
					case 2: cout << "C " << j+1 << endl; break;
					case 3: cout << "D " << j+1 << endl; break;
					default: break; 
				}
			}
		}
	}

	return 0;
}


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

int main() {
	long long n,k,m=1000000007,fol;
	cin>>n>>k;
	long long h[n];
	for(int i=0;i<n;i++){
	    cin>>h[i];
	}
	sort(h,h+n);
	for(int i=0;i<n-k+1;i++){
	    fol=h[k-1+i]-h[i];
	    m=min(m,fol);
	}
	cout<<m;
	return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n)
	fmt.Scan(&k)

	const M int64 = 1000000007

	fa := make([]int64, n+1, n+1)
	fi := make([]int64, n+1, n+1)

	fa[0] = 1
	fi[0] = 1

	for i := 1; i <= n; i++ {
		fa[i] = fa[i-1] * int64(i) % M
		fi[i] = modinv(fa[i], M)
	}

	for i := 1; i <= k; i++ {
		if i > n-k+1 {
			fmt.Println(0)
		} else {
			tmp := fa[n-k+1]
			tmp = tmp * fi[n-k+1-i] % M
			tmp = tmp * fi[i] % M
			tmp = tmp * fa[k-1] % M
			tmp = tmp * fi[i-1] % M
			tmp = tmp * fi[k-i] % M
			fmt.Println(tmp)
		}
	}
}

func modpow(a int64, n int64, m int64) int64 {
	if n == 0 {
		return 1
	}
	tmp := modpow(a, n/2, m)
	if n%2 == 0 {
		return tmp * tmp % m
	}
	return tmp * tmp % m * a % m
}

func modinv(a int64, m int64) int64 {
	return modpow(a, m-2, m)
}


Measured memory_bytes: 1804
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s = "aeiou";
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    char c;
    cin >> c;

    bool check = false;
    for(int i = 0; i < 5; ++i){
        if(c == s[i])
        check = true;
    }
    cout << (check ? "vowel" : "consonant") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
   string s;
   cin>>s;
   ll no=0;
   ll n = s.length();
   ll i;
   for(i=0;i<n;i++)
   {
      no+=(s[i]-'0');
      no%=9;
   }
   no%=9;
   if(no==0)
   {
       cout<<"Yes\n";
   }
   else{
       cout<<"No\n";
   }
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


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


return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int n;
bool temp;
int a[10],b[10],las[10];
int x=1,u,v;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		las[i]=i;
		x*=i;
	}
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	for(int i=1;i<=x;i++){
		temp=1;
		for(int j=1;j<=n;j++){
			if(a[j]!=las[j]){
				temp=0;
				break;
			}
		}
		u=temp?i:u;
		temp=1;
		for(int j=1;j<=n;j++){
			if(b[j]!=las[j]){
				temp=0;
				break;
			}
		}
		v=temp?i:v;
		if(i<x){
			next_permutation(las+1,las+1+n);
		}
	}
	cout<<abs(u-v);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n;
  cin>>n;
  LL a[n], b[n];
  REP(i, n) cin>>a[i]>>b[i];
  LL ans=0;
  for(int i=n-1; i>-1; --i){
    if((a[i]+ans)%b[i]>0)ans += (b[i] - (a[i]+ans)%b[i]);
  }
  ECHO(ans);
  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll
signed main(){
	int n; cin>>n;
	int x; cin>>x;
	int a[n];
	for(int i = 0; i < n; i++){
		cin>>a[i];
	}
	sort(a, a + n);
	int ans = 0;
	int sum = 0;
	for(int i = 0; i < n; i++){
		sum += a[i];
		if(sum <= x){
			ans = i+1;
		}
	}
	if(ans == n && sum != x) ans--;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=200050;

int f[maxn],s[maxn];

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

int main()
{
	int n,m;
	cin>>n>>m;
	int ans=0;
	for(int i=1;i<=n;++i)
	  {
	  	  f[i]=i;
	  	  s[i]=1;
	  }
	for(int i=1;i<=m;++i)
	  {
	  	  int x,y;
	  	  cin>>x>>y;
	  	  if(find(x)!=find(y))
	  	  {
	  	  	  ans--;
	  	  	  s[find(y)]+=s[find(x)];
	  	  	  f[find(x)]=find(y);
	  	  }
	  }  
	for(int i=1;i<=n;++i)
	  {
	  	  if(s[i]>ans) ans=s[i];
	  }
	cout<<ans<<endl;    
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, m;
  vector<vector<int>> t;
  vector<int> dep, cntout;
  vector<pair<int, int>> ans;
  Solver2(LL n, LL m) : n(n), m(m), t(n), dep(n, -1), cntout(n){};

  void solve() {
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      t[--a].push_back(--b);
      t[b].push_back(a);
    }

    if (m % 2) {
      cout << -1 << endl;
    } else {
      dfs(0, -1, 0);
      for (auto p : ans) {
        cout << p.first + 1 << " " << p.second + 1 << endl;
      }
    }
  }

  void dfs(int c, int p, int d) {
    DBG(c, p, d, dep[c])
    if (dep[c] != -1) {
      if (dep[c] < dep[p]) {
        ans.emplace_back(p, c);
        cntout[p]++;
      }
      return;
    }
    dep[c] = d;
    for (int v : t[c]) {
      if (v != p) {
        dfs(v, c, d + 1);
      }
    }
    if (p != -1) {
      if (cntout[c] % 2) {
        ans.emplace_back(c, p);
        cntout[c]++;
      } else {
        ans.emplace_back(p, c);
        cntout[p]++;
      }
    }
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


Measured memory_bytes: 12020
import sys

for v in iter(sys.stdin.readline,''):
    h,w = map(int,v.split())

    if h == 0 and w == 0:
        break

    print('#'*w)

    for i in range(h-2):
        print('#'+('.'*(w-2))+'#')

    print('#'*w)
    print('')

Measured memory_bytes: 6340
#include <bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v)              \
  cerr << #v ":[ ";          \
  for (auto macro_vi : v)    \
  {                          \
    cerr << macro_vi << " "; \
  }                          \
  cerr << "]" << endl;
#define ddump(v)                     \
  cerr << #v ":" << endl;            \
  for (auto macro_row : v)           \
  {                                  \
    cerr << "[";                     \
    for (auto macro__vi : macro_row) \
    {                                \
      cerr << macro__vi << " ";      \
    }                                \
    cerr << "]" << endl;             \
  }
#define damp(m)                                                   \
  for (auto macro_pair : m)                                       \
  {                                                               \
    cerr << macro_pair.first << ":" << macro_pair.second << endl; \
  }
#define dpair(p) cerr << #p ":" \
                      << "(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v, i) macro_v.begin() + i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 == m2)
  {
    cout << 0 << endl;
  }
  else
  {
    cout << 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
local mce, msq, mmi, mma, mab = math.ceil, math.sqrt, math.min, math.max, math.abs
local mfl = math.floor
local mod = 1000000007

local function bmul(x, y)
  return (x * y) % mod
end
local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = pow // 2
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if allnums[i] then
      table.insert(primes, i)
      local lim = x // i
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end

local function getdivisorparts(x, primes)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while(primepos <= prime_num and dv <= lim) do
    if(x % dv == 0) then
      local asdf = {}
      asdf.p = dv
      asdf.cnt = 1
      x = x // dv
      while(x % dv == 0) do
        x = x // dv
        asdf.cnt = asdf.cnt + 1
      end
      table.insert(tmp, asdf)
      lim = mce(msq(x))
    end
    if(primepos == prime_num) then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if(x ~= 1) then
    local asdf = {}
    asdf.p, asdf.cnt = x, 1
    table.insert(tmp, asdf)
  end
  return tmp
end


local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local primes = getprimes(1000)
local alldvs = {}
local dvs = {}
for i = 1, n do
  dvs[i] = getdivisorparts(a[i], primes)
  for j = 1, #dvs[i] do
    local p, c = dvs[i][j].p, dvs[i][j].cnt
    if not alldvs[p] then
      alldvs[p] = c
    else
      alldvs[p] = mma(alldvs[p], c)
    end
  end
end
local ret = 0
local mul = 1
for p, c in pairs(alldvs) do
  mul = bmul(mul, modpow(p, c))
end
for i = 1, n do
  local z = 1
  for j = 1, #dvs[i] do
    local p, c = dvs[i][j].p, dvs[i][j].cnt
    z = bmul(z, modpow(p, c))
  end
  ret = badd(ret, bmul(mul, modinv(z)))
end
print(ret)


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

int main() {
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'C') {
			for (int j = i; j < S.size(); j++) {
				if (S[j] == 'F') {
					printf("Yes");
					return 0;
				}
			}
		}
	}
	printf("No");
	return 0;
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

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

int main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N); REP(i, N) cin >> A[i];
    
    ll M = 0;
    ll G = A[0];
    REP(i, N) {
        M = max(M, A[i]);
        G = gcd(G, A[i]);
    }
    
    if (M >= K && K % G == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

ll f[100000 + 1010];
const ll mod = 1e9 + 7;

ll binpow(ll x, ll n)
{
	ll p = 1;
	while (n)
	{
		if (n % 2 != 0)
		{
			p = (p%mod)*(x%mod) % mod;
			n--;
		}
		x = (x%mod)*(x%mod) % mod;
		n /= 2;
	}
	return p % mod;
}

ll C(ll n, ll k)
{
	ll ans = f[n];
	ll obr = f[k];
	obr = binpow(obr, mod - 2);
	ans = (ans%mod)*(obr%mod) % mod;
	ll obr2 = f[n - k];
	obr2 = binpow(obr2, mod - 2);
	ans = (ans%mod)*(obr2%mod) % mod;
	return ans%mod;
}

void solve()
{
	f[0] = 1;
	for (ll i = 1; i < 100000 + 1010; i++)
		f[i] = (f[i - 1] * i)%mod;

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	input(a);

	if (k == 1)
	{
		cout << 0;
		return;
	}

	ll sum_min = 0, sum_max = 0;
	
	sort(all(a));
	for (int i = 0; i <= n - k; i++)
	{
		ll tmp = (a[i] % mod)*(C(n - i - 1, k - 1) % mod) % mod;
		sum_min = (sum_min%mod + tmp+mod) % mod;
	}
	for (int i = n - 1; i >= k - 1; i--)
	{
		ll tmp = (a[i] % mod)*(C(i, k - 1) % mod) % mod;
		sum_max = (sum_max%mod + tmp % mod + mod) % mod;
	}

	cout << (sum_max%mod-sum_min%mod+mod)%mod;

}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
import math

###
# main
if(__name__ == '__main__'):
    # input
    n, k = map(int, input().split(" "))

    num = 0
    for pick in range(k, n+2):
        tgt = (pick * (n-pick+1) + 1)
        num += tgt % (10**9 + 7)
        num %= 10**9 + 7
    
    print(num)

# else:
    # do nothing


Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s[10];
ll cnt,h,w,k;
int main()
{
    ios::sync_with_stdio(false);
    cin>>h>>w>>k;
    for(ll i=0;i<h;i++) cin>>s[i];
    for(ll x=0;x<(1LL<<(h+w));x++)
    {
        ll a[6]={0},b[6]={0},t=x,num=0;
        for(ll i=0;i<h;i++)
        {
            a[i]=t&1;
            t>>=1;
        }
        for(ll i=0;i<w;i++)
        {
            b[i]=t&1;
            t>>=1;
        }
        for(ll i=0;i<h;i++)
        {
            if(a[i]==0)
            for(ll j=0;j<w;j++)
            {
                if(b[j]==0&&s[i][j]=='#') num++;
            }
        }
        if(num==k) cnt++;
    }
    cout<<cnt;
    return 0;
}


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

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

  // 人数の合計
  int l, r, sum;
  sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum += (r - l) + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.PriorityQueue;
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();
        PriorityQueue<Integer> queue= new PriorityQueue<Integer>();
        int count=0;

        for(int i=0; i<N; i++) {
            int num = sc.nextInt();
            queue.add(num);
        }


        for(int i=0;i<K;i++) {
            int num = queue.poll();
            count+=num;
        }
        System.out.println(count);
	}

}


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

#define int long long

int a, b, x;

signed main() {
    cin >> a >> b >> x;
    if (a != 0) {
        cout << b / x - (a - 1) / x << endl;
    }else {
        cout << b / x + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int n, ra, rb, pas;
int main() {
    DAU
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> b[i];
    for (int i = 0; i < n; ++i)
        c[i] = i + 1;
    do {
        ++pas;
        if (c == a)
            ra = pas;
        if (c == b)
            rb = pas;
    } while (next_permutation(c.begin(), c.end()));
    cout << abs(ra - rb);
    PLEC
}


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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 1e18;
const int MAXN = 3e5 + 5;

int N, R[4005], G[4005], B[4005];
ll ans;
char A[4005];

void solve(char a, char b, char c) {
	for(int i=1; i<N; i++) if(A[i] == a) {
		for(int j=i+1; j<N; j++) if(A[j] == b) {
			if(c == 'R') ans += R[N] - R[j];
			if(c == 'G') ans += G[N] - G[j];
			if(c == 'B') ans += B[N] - B[j];
			int k = j + (j - i);
			if(k <= N && A[k] == c) ans--;
		}
	}
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> A+1;
	for(int i=1; i<=N; i++) R[i] = R[i-1] + (A[i] == 'R');
	for(int i=1; i<=N; i++) G[i] = G[i-1] + (A[i] == 'G');
	for(int i=1; i<=N; i++) B[i] = B[i-1] + (A[i] == 'B');
	solve('R', 'G', 'B'); solve('G', 'R', 'B');
	solve('R', 'B', 'G'); solve('B', 'R', 'G');
	solve('G', 'B', 'R'); solve('B', 'G', 'R');
	cout << ans;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    ll a,b,k;
    cin>>a>>b>>k;
    if(a-k>=0){
        a=a-k;
    }
    else{
        k=k-a;
        a=0;
        if(b-k>=0){
            b=b-k;
        }
        else{
            b=0;
        }
    }
    cout<<a<<" "<<b;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (void)
{
	int w, h, x, y, r;

	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

	if (0 > x-r || 0 > y-r || w < x+r || h < y+r)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> lp(N, vector<int>(N, 0));
    for (int i = 0; i < M; i++)
    {
        int l, r;
        cin >> l >> r;
        lp[l - 1][r - 1]++;
    }
    vector<int> ans(Q, 0);
    vector<vector<int>> sublp(N, vector<int>(N, 0));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            sublp[i][j] = lp[i][j] + (j == 0 ? 0 : sublp[i][j - 1]);
        }
    }

    for (int i = 0; i < Q; i++)
    {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        for (int j = p; j <= q; j++)
        {
            ans[i] += sublp[j][q] - (p == 0 ? 0 : sublp[j][p - 1]);
        }
    }
    for (int i = 0; i < Q; i++)
    {
        cout << ans[i] << "\n";
    }
}


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

int main() {
	int a, b; scanf("%d%d", &a, &b);
	int sum = 1;
	int ans = 0;
  	while (sum < b) {
  		sum--;
  		sum += a;
  		ans++;
  	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
namespace io
{
	template<typename T>void read(T &x)
	{
		x=0;char str=getchar();int ng=1;
		while(!isdigit(str)){if (str=='-')ng=-1;str=getchar();}
		while(isdigit(str)){x=(x<<3)+(x<<1);x+=str-48;str=getchar();}
		x*=ng;
	}
	int buf[100],top;
	template<typename T>void print(T x)
	{
		if (!x)putchar('0');
		if (x<0)putchar('-'),x=-x;
		while(x)buf[++top]=x%10,x/=10;
		while(top)putchar(buf[top--]+48);
	}
}
using io::read;
using io::print;
using namespace std;
const int maxn=100010;
int n;
struct robot
{
	int x,l;
}r[maxn];
bool cmp(robot a,robot b)
{
	if (a.x!=b.x)return a.x<b.x;
	return a.l<b.l;
}
int stk[maxn],top;
int main()
{
	read(n);
	for (re int i=1;i<=n;++i)read(r[i].x),read(r[i].l);
	sort(r+1,r+n+1,cmp);
	stk[++top]=1;
	for (re int i=2;i<=n;++i)
	{
		if (r[i].x+r[i].l<=r[stk[top]].x+r[stk[top]].l)stk[top]=i;
		else if (r[i].x-r[i].l>=r[stk[top]].x+r[stk[top]].l)stk[++top]=i;
	}
	print(top);
	puts("");
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int arr[n+5];
    for(int i=1;i<=n;i++)
    {
    scanf("%d",&arr[i]);
    }
    int dp[n+5];
    for(int i=0;i<=n;i++)dp[i]=1e9+5;
    dp[1]=0;
   for(int i=1;i<=n;i++)
    {
     
         dp[i+1]=min(dp[i+1],dp[i]+abs(arr[i]-arr[i+1]));
     
    
        dp[i+2]=min(dp[i+2],dp[i]+abs(arr[i]-arr[i+2]));
        
    
    }
    printf("%d",dp[n]);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
struct edge {
    int to, cost;
};

int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

map<int,int> factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////

signed main() {
  int n;
  cin>>n;
  cout<<10-n/200;
}


Measured memory_bytes: 3628
//
//  main.cpp
//
// g++ -std=c++14 main.cpp
//

//#include "main.hpp"
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <tuple>
using namespace std;
typedef long long ll;

int main(void){
    int n;
    cin >> n;
    
    bool ans[105][105] = {};
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            ans[u - 1][v - 1] = true;
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j != 0) cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }
}
// g++ -std=c++14 main.cpp



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

int main()
{
    // つけてみたver
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    float K;
    cin >> N >> K;
    int A[N];
    for (int i = 0; i < N; i++)
        cin >> A[i];

    int res = 1;
    if (N != K)
    {
        res += ceil((N - K) / (K - 1.0));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

int gcd(int a, int b){
    if(a < b){
        swap(a, b);
    }
    int r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = a[0];
    for(int i = 1; i < n; i++){
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  lll n,k;

  cin >> n >> k;

  vector<int> a(n);
  vector<int> root;
  set<int> s;
  for(ii=0;ii<n;ii++){
    cin >> a[ii];
    //cout << a[ii] << endl;
  }

  int pos = 0;
  root.push_back(pos);
  s.insert(pos);
  
  while(true){
    pos = a[pos] -1;
    //cout << pos << "->" ;

    if(s.find(pos) != s.end()){
      root.push_back(pos);
      break;
    }
    else{
      root.push_back(pos);
      s.insert(pos);
    }

  }

  //for(ii=0;ii<root.size();ii++){
  //  cout << root[ii] << "->";
  //}
  //cout << endl;
  
  int last = root[root.size()-1];
  //cout << "last:" << last << endl;
  lll loopNum=0;
  lll loopStart = 0;
  for(ii=root.size()-2;ii>=0;ii--){
    //cout << root[ii] << "->" ;

    if(last == root[ii]){
      loopNum++;
      loopStart = ii;
      //cout << endl;
      break;
    }
    else{
      loopNum++;
    }
    
  }

  //cout << "loopStart:"  << loopStart << endl;
  //cout << "loopNum:" << loopNum << endl;
  lll lastPos;
  lll ans;
  if(loopStart >= k){
    ans = root[k] + 1;
  }
  else{
    lll startPos;
    startPos = k - loopStart;
    lll goNum = startPos % loopNum;

    ans = root[loopStart+goNum] + 1;
    //for(ii=loopStart;ii<goNum;ii++){
    //  
    //}
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13900
import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# TLE

N = int(readline())
PATH = [[] for _ in range(N + 1)]
MOD = 10 ** 9 + 7

for _ in range(N - 1):
    x, y = map(int, readline().split())
    PATH[x].append(y)
    PATH[y].append(x)


dp = [[1] * 2 for _ in range(N+1)]


def dfs(x, parent):
    for v in PATH[x]:
        if v == parent:
            continue
        dfs(v, x)

        dp[x][0] *= (dp[v][0] + dp[v][1])
        dp[x][0] %= MOD
        dp[x][1] *= dp[v][0]
        dp[x][1] %= MOD

    return 0


dfs(1, -1)
ans = sum(dp[1])
ans %= MOD
print(ans)


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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  double la, lb, ta, tb;
  cin >> la >> lb >> ta >> tb;
  ta = (ta+tb/60)*M_PI*2/12;
  tb *= M_PI*2/60;
  double dx = cos(ta)*la-cos(tb)*lb;
  double dy = sin(ta)*la-sin(tb)*lb;
  cout << setprecision(20) << sqrt(dx*dx+dy*dy) << endl;
}


Measured memory_bytes: 4172
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

const int MAXN = 120000;
int n;
ll a[120000];
vector<int> eds[MAXN];
int was[MAXN];

ll dfs1(int v) {
	was[v] = 1;
	vector<ll> vv;
	if (eds[v].size() == 1) {
		return a[v];
	}
	for (int u: eds[v]) {
		if (!was[u]) {
			vv.push_back(dfs1(u));
		}
	}
	sort(vv.begin(), vv.end());
	ll sum = 0;
	for (int i = 0; i < vv.size(); ++i)
		sum += vv[i];
	ll mxp = min(sum - vv.back(), sum / 2);
	if (a[v] > sum) {
		cout << "NO\n";
		exit(0);
	}
	if (a[v] < sum - mxp) {
		cout << "NO\n";
		exit(0);
	}
	ll gg = sum - a[v];
	return sum - 2 * gg;
}



int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%lld", a + i);
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		--a, --b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	if (n == 2) {
		if (a[0] == a[1]) {
			cout << "YES\n";
		}
		else {
			cout << "NO\n";
		}
		return 0;
	}
	for (int i = 0; i < n; ++i)
		if (eds[i].size() != 1) {
			ll x = dfs1(i);
			if (x == 0) {
				cout << "YES\n";
			}
			else {
				cout << "NO\n";
			}
			return 0;
		}
	return 0;
}




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

int main(){

  int n,x,i;
  int l[105];
  int d[105];
  int cnt = 1;

  scanf("%d %d", &n, &x);

  for(i = 1;i <= n;i++) scanf("%d", &l[i]);

  d[1] = 0;
  for(i = 2;i <= n + 1;i++){
    d[i] = d[i - 1] + l[i - 1];
    if(d[i] <= x) cnt++;
  }

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 128
module ABC110

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public  :: task_A
  private :: calculate_maximum_allowance

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_A

    ! variables for this <subroutine>
    integer(INT8) :: A, B, C

    ! STEP.01
    ! read out the given data
    read(unit=INPUT_UNIT, fmt=*) A, B, C

    ! STEP.02
    ! calculate & output the answer of the task
    write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') calculate_maximum_allowance (A, B, C)

    ! STEP.END
    return

  end subroutine task_A

  pure function calculate_maximum_allowance (A, B, C) result(allowance)

    ! arguments for this <function>
    integer(INT8), intent(in) :: A, B, C

    ! return value of this <function>
    integer(INT8) :: allowance

    allowance = max(A, B, C) * 9_INT8 + sum([A, B, C])

    return

  end function calculate_maximum_allowance

end module ABC110


program main

  ! <module>s to import
  use, non_intrinsic :: ABC110

  ! require all variables to be explicitly declared
  implicit none

  call task_A

end program main

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

#define lli long long int
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define true 1
#define false 0



int main(void){
	int i;
	char *s;
	int g,p;
	int n = 100004;
	s = calloc(sizeof(char),n);
	g = 0;p = 0;
	scanf("%s",s);
	while(*s!='\0'){
		if(*s == 'g'){
			g++;
		}else{
			p++;
		}
		s++;
	}
	printf("%d\n", (g-p)/2);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


const int mod=1e9+7;
int binomialCoeff(int n,int r){
    int res=1;
    if(r>n-r)r=n-r;
    for(int i=0;i<r;i++){
        res*=(n-i);
        res/=(i+1);
    }
    return res;
}


int power(int x,int n,int mod){
    //(x^n)%mod
    int result=1;
    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

int inverseMod(int x,int mod){
    return power(x,mod-2,mod);
}
int32_t main() {

    fast
    int n;
    cin>> n;
    cout<<(1-n);    



    return 0;
}



Measured memory_bytes: 3652
n = int(input())

dp = [float('INF')] * (n+1)
dp[0] = 0

pow6 = []
i = 1
while 6**i <= 10**5:
    pow6.append(6**i)
    i += 1
pow9 = []
i = 1
while 9**i <= 10**5:
    pow9.append(9**i)
    i += 1
money = [1] + pow6 + pow9

for i in range(n):
    for k in money:
        if n >= i+k >= 0:
            dp[i+k] = min(dp[i+k], dp[i] + 1)

print(dp[-1])


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

int main() {
	int a, b; cin >> a >> b;
	cout << a / b << ' ' << a%b << ' ';
	printf("%.7lf\n", (double)a / b);
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    
    vector<int> im;
    map<int, lli> m;
    int n, a;
    cin >> n;
    rep(i, n){
        cin >> a;
        m[a]++;
        im.push_back(a);
    }

    lli sum = 0;
    for(auto p : m){
        sum += (p.second) * (p.second-1) / 2;
    }


    for(auto p : im){
        lli sub = m[p] - 1;
        cout << sum - sub << endl;
    }
    return 0;
}

Measured memory_bytes: 10356
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();
		long lcm =C*D/gcd(C,D);
		long sumA = (A-1) - (A-1)/C -(A-1)/D + (A-1)/lcm;
		long sumB = B - B/C -B/D + B/lcm;
		System.out.println(sumB - sumA);
	}

	private static long gcd(long a,long b) {
		if(a < b) {
			return gcd(b, a);
		}
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
}

Measured memory_bytes: 23252
import Data.List
import Control.Monad

main :: IO ()
main = do
    [n, _m, x] <- map read . words <$> getLine
    ca <- replicateM n $ do
        (c: as) <- map read . words <$> getLine
        return (c, as)

    let ans = foldl min maxBound $ do
        sel <- replicateM n [False, True]
        let (cs, as) = unzip [ t | (b, t) <- zip sel ca, b]
        guard $ not $ null as
        guard $ all (>= x) $ map sum $ transpose as
        return $ sum cs

    print (if ans == maxBound then -1 else ans :: Int)


Measured memory_bytes: 5308
# import numpy as np
a, b, c = map(int, input().split())
ans_bool =  (0 < (a**2 + c**2 + b**2 - 2*a*c - 2*b*c - 2*a*b)) & ((c-a-b)>0)
if ans_bool:
    print('Yes')
else :
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
#define ALL(x) (x).begin(),(x).end()

int main(){
	int N;
	string S;
	cin >> N >> S;
	// 真ん中がR,G,Bか
	string rgb = "RGB";
	vector<ll> R(N+1,0), G(N+1,0), B(N+1,0);
	for(int i=1;i<=N;i++) {
		R[i] = R[i-1] + ((S[i-1]=='R') ? 1 : 0);
		G[i] = G[i-1] + ((S[i-1]=='G') ? 1 : 0);
		B[i] = B[i-1] + ((S[i-1]=='B') ? 1 : 0);
	}
	ll ans = 0;
	for(int i=1;i<=N;i++) {
		if(S[i-1] == 'R') {
			for(int j=i+1;j<=N;j++) {
				if(S[j-1]=='G') {
					// RGB
					ll n = B[N] - B[j];
					ans += n;
					if(1 <= 2*j-i and 2*j-i <= N) {
						ans -= (B[2*j-i] - B[2*j-i-1]);
					}
				} else if(S[j-1]=='B') {
					// RBG
					ll n = G[N] - G[j];
					ans += n;
					if(1 <= 2*j-i and 2*j-i <= N) {
						ans -= (G[2*j-i] - G[2*j-i-1]);
					}
				}
			}
		} else if(S[i-1] == 'G') {
			for(int j=i+1;j<=N;j++) {
				if(S[j-1]=='R') {
					// GRB
					ll n = B[N] - B[j];
					ans += n;
					if(1 <= 2*j-i and 2*j-i <= N) {
						ans -= (B[2*j-i] - B[2*j-i-1]);
					}
				} else if(S[j-1]=='B') {
					// GBR
					ll n = R[N] - R[j];
					ans += n;
					if(1 <= 2*j-i and 2*j-i <= N) {
						ans -= (R[2*j-i] - R[2*j-i-1]);
					}
				}
			}
		} else if(S[i-1] == 'B') {
			for(int j=i+1;j<=N;j++) {
				if(S[j-1]=='R') {
					// BRG
					ll n = G[N] - G[j];
					ans += n;
					if(1 <= 2*j-i and 2*j-i <= N) {
						ans -= (G[2*j-i] - G[2*j-i-1]);
					}
				} else if(S[j-1]=='G') {
					// GBR
					ll n = R[N] - R[j];
					ans += n;
					if(1 <= 2*j-i and 2*j-i <= N) {
						ans -= (R[2*j-i] - R[2*j-i-1]);
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3704
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] l1 = br.readLine().split(" ");
		String[] l2 = br.readLine().split(" ");
		
		int k = Integer.parseInt(l1[0]);
		int n = Integer.parseInt(l1[1]);
		int[] a = Arrays.stream(l2).mapToInt(s -> Integer.parseInt(s)).toArray();
		
		int max = Integer.MIN_VALUE;
		for(int i = 1; i<n; ++i) {
			int dis = a[i] - a[i-1];
			if(max < dis) {
				max = dis;
			}
		}
		int dis = k - a[n -1] + a[0];
		if(max < dis) {
			max = dis;
		}
		
		System.out.println(String.format("%d", k - max));
		
	}

}

Measured memory_bytes: 49744
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int n,i,j,count=0;
		int a[]=new int[1000000];
		while(s.hasNext()){
			n=s.nextInt();
			for(i=0;i<=n;i++){
				a[i]=i;
			}

			for(i=2;i<=n;i++){
				if(a[i]!=0){
					for(j=2;j*i<=n;j++){
						a[j*i]=0;
					}
				}
			}

			for(i=2;i<=n;i++){
				if(a[i]!=0){
					count++;
				}
			}
			System.out.println(count);
			count=0;
		}//has while

	}
}

Measured memory_bytes: 16000
import sys
n = int(input())
a_li = [int(w) for w in input().split()]

for a in a_li:
    if a % 2 == 0:
        if a % 3 == 0 or a % 5 == 0:
            continue
        else:
            print("DENIED")
            sys.exit()

print("APPROVED")


Measured memory_bytes: 2940