akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
primes = list(range(2,101))
for i in range(len(primes)):
    if primes[i]:
        j = i
        j += primes[i]
        while j < len(primes):
            primes[j] = None
            j += primes[i]
primes = [p for p in primes if p]
N = int(input())
fact = defaultdict(int)
for p in primes:
    i = p
    while i <= N:
        fact[p] += N//i
        i *= p
f2 = set()
f4 = set()
f14 = set()
f24 = set()
f74 = set()
for p in fact:
    if fact[p] >= 2:
        f2.add(p)
    if fact[p] >= 4:
        f4.add(p)
    if fact[p] >= 14:
        f14.add(p)
    if fact[p] >= 24:
        f24.add(p)
    if fact[p] >= 74:
        f74.add(p)
ans = 0
ans += len(f74)
ans += len(f24)*(len(f2)-1)
ans += len(f14)*(len(f4)-1)
ans += (len(f2)-2)*len(f4)*(len(f4)-1)//2
print(ans)

Measured memory_bytes: 9436
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

int main(void){
	int n;
	
	while(cin >> n && n){
		int hand[2*n+1]; //hana:0 taro:1
		bool used[2*n+1];
		int tmp;
		memset(hand,0,sizeof(hand));
		
		for(int i=0;i<n;i++){
			cin >> tmp;
			hand[tmp] = 1;
		}
		
		vector<int> hands[2];
		for(int i=1;i<=2*n;i++){
			if(hand[i] == 0){
				hands[0].push_back(i);
			}else{
				hands[1].push_back(i);
			}
		}
		sort(hands[0].begin(), hands[0].end());
		sort(hands[1].begin(), hands[1].end());
		
		int field = 0;
		int turn = 1; //0:hana 1:taro
		int index;
		do{
			bool canpush = false;
			for(int i=0;i<hands[turn].size();i++){
				if(field < hands[turn][i]){
					canpush = true;
					index = i;
					break;
				}
			}
			
			if(canpush == false){
				field = 0;
			}else{
				field = hands[turn][index];
				hands[turn].erase(hands[turn].begin()+index);
			}
			turn = 1 - turn;
		}while(hands[0].size() != 0 && hands[1].size() != 0);
		
		cout << hands[0].size() << endl;
		cout << hands[1].size() << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=100005,MOD=1000*1000*1000+7;
string s;
ll cnt[N][14];
int main()
{
    cnt[0][0]=1;
    cin>>s;
    int n=s.size();
    s='s'+s;
    for(int i=1;i<=n;i++){
        if(s[i]!='?'){
            int vl=s[i]-'0';
            for(int e=0;e<13;e++){
                cnt[i][(e*10+vl)%13]=cnt[i-1][e];
            }
        }else{
            for(int vl=0;vl<=9;vl++){
                for(int e=0;e<13;e++){
                cnt[i][(e*10+vl)%13]=(cnt[i][(e*10+vl)%13]+cnt[i-1][e])%MOD;
            }
            }
        }
    }
    cout<<cnt[n][5];
    return 0;
}


Measured memory_bytes: 11388
#include<stdio.h>
#define maxn 1005
int a[maxn];

int main(){
int n,flag=1;
scanf("%d",&n);
for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]%2==0)
        if(a[i]%3!=0&&a[i]%5!=0)
        {flag=0;break;}
}
if(flag) printf("APPROVED\n");
else printf("DENIED\n");
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    n *= 3;
    vi xs(n);
    for (int& x:xs) cin>>x;
    sort(all(xs));
    ll ans=0;
    for (int i=0, j=n-2; i<j; i++, j-=2)
        ans += xs[j];
    cout << ans << '\n';
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<ll>x(m),y(m);
  rep(i,0,m){
    cin>>x[i]>>y[i];
    x[i]--;y[i]--;
  }
  vector<ll>t(n),k(n,1);
  t[0]=1;
  rep(i,0,m){
    if(t[x[i]]==1){
      t[y[i]]=1;
      if(k[x[i]]==1)t[x[i]]=0;
      k[x[i]]--;
      k[y[i]]++;
    }
    else{
      k[x[i]]--;
      k[y[i]]++;
    }
  }
  rep(i,0,n)if(t[i]==1)res++;
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3456
package main

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

func main() {
	sc := NewScanner()
	S, T := sc.Next(), sc.Next()

	fmt.Println(T + S)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int n, x; cin >> n >> x;
    vector<ll> data(n); rep(i,n) cin >> data[i];
    ll ans = 0;
    rep(i,n-1){
        if(data[i]+data[i+1] <= x) continue;
        ll k = data[i]+data[i+1]-x;
        ans += k;
        data[i+1] -= k;
    }
    if(data[n-1] > x) ans += data[n-1]-x;
    cout << ans <<  endl;
}



Measured memory_bytes: 4024
#include <stdio.h>
#include <stdlib.h>
#define INFTY 1000000000
void merge(int [],int, int, int); 
void mergesort(int [],int,int); 


int c=0; 


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

   left=0; 
   right=n; 
   mergesort(S,left,right); 
        for(i=0;i<n;i++){ 
     printf("%d",S[i]);
     if(i==n-1) break;
     printf(" ");
   } 
   printf("\n"); 
   printf("%d\n",c); 

   return 0; 
 } 
 void merge(int S[],int left,int mid,int right) 
 { 
   int i,j; 
   int n1; 
   int n2; 
   int *L,*R;
   int k; 

   n1=mid-left; 
   n2=right-mid;
   L=malloc(sizeof(int)*n1+1);
   R=malloc(sizeof(int)*n2+1);
   for(i=0;i<n1;i++){ 
     L[i]=S[left+i]; 
   } 
   for(i=0;i<n2;i++){ 
     R[i]=S[mid+i]; 
   } 
   L[n1]=INFTY; 
   R[n2]=INFTY; 
   i=0; 
   j=0; 

   for(k=left;k<right;k++){ 
     if(L[i]<=R[j]){ 
       S[k]=L[i]; 
       i++; 
       c++; 
     } 
     else { 
       S[k]=R[j]; 
       j++; 
       c++; 
      
     } 
   } 
 }
 void mergesort(int S[],int left, int right) 
 { 
   int mid; 
   if(left+1<right){ 
     mid=(left+right)/2; 
    mergesort(S,left,mid);
    mergesort(S,mid,right);
    merge(S,left,mid,right);
  }
}
 
  
    
  

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

int main() {
    int a; cin >> a;
    cout << a + a*a + a*a*a << endl;

    return 0;
}

Measured memory_bytes: 3616
import math
a,b,x = map(int,input().split())
if x>=(a**2)*b/2:
  y = 2*b-2*x/(a**2)
  print(math.degrees(math.atan2(y,a)))
else:
  y = 2*x/(a*b)
  print(90-math.degrees(math.atan2(y,b)))

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

using namespace std;
using nagai = long long;
using ll = long long;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    if (s[n - 1] == '1' || s[0] == '0')
    {
        cout << -1 << '\n';
        return 0;
    }
    for (int i = 0; i < s.size() - 1; ++i)
        if (s[s.size() - 2 - i] != s[i])
        {
            cout << -1 << '\n';
            return 0;
        }
    int curv = 1;
    int cursz = 1;
    int last = 0;
    vector<pair<int, int>> edg;
    for (int i = 2; i <= n; ++i)
    {
        if (i == n || s[i - 1] == '1')
        {
            int nw = curv++;
            edg.emplace_back(last, nw);
            for (int j = 0; j < i - cursz - 1; ++j)
                edg.emplace_back(curv++, nw);
            last = nw;
            cursz = i;
        }
    }
    for (auto& x : edg)
        cout << x.first + 1 << ' ' << x.second + 1 << '\n';


	return 0;
}



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

#define COIN_VALUE 500

int main()
{
	int inputK, inputJ;
	scanf("%d""%d", &inputK, &inputJ);

	if (inputK * COIN_VALUE >= inputJ)
	{
		printf("Yes \n");
	}
	else
	{
		printf("No \n");
	}

	return 0;
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;


void Main()
{
	int N;
	std::cin >> N;
	std::vector<int> vec(N);
	for (auto& v : vec)
	{
		std::cin >> v;
	}
	int count = 0;
	for (auto i : boost::irange(1, N - 1))
	{
		auto min = std::min({ vec[i - 1],vec[i],vec[i + 1] });
		auto max = std::max({ vec[i - 1],vec[i],vec[i + 1] });
		if (vec[i] != min && vec[i] != max)
		{
			++count;
		}
	}
	std::cout << count << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
import sys
a = []
line_count = 0
for line in sys.stdin:
    a.append(int(line))
    line_count += 1
for i in range(line_count):
    if a[i] == 0:
        break
    else:
        print('Case' + ' ' + str(i + 1) + ': ' + str(a[i]))


Measured memory_bytes: 5960
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
#define P pair<int, int>
using namespace std;

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int cnt = 0;
  int it = 1;
  rep(i, n){
    if(a[i] != it){
      cnt++;   
    }else{
      it++;
    }
  }
  if(it != 1){
    cout << cnt << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  vector<ll>vec(101,-1);
  vec.at(a)=1;
  for(ll i=0;;i++){
    if(a%2==0){
      a=a/2;
    }
    else{
      a=3*a+1;
    }
    if(a<=100){
      if(vec.at(a)==-1){
        vec.at(a)=1;
      }
    else{
      cout<<i+2<<endl;
      return 0;
    }
  }
  }
}
    
    
  


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
  int n,m,d;
  cin>>n>>m>>d;
  double ans=0;
  r(i,m-1){
    if(d==0)ans+=n;
    else ans+=(n-d)*2;
  }

  r(i,m){
    if(i>1)ans*=n;
    ans/=n;
  }
  printf("%.9lf\n",ans);
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int, readline().split()))

INF = 10**18
limit = 4
S = (2*limit+3)
dpb = [-INF]*S
dpw = [-INF]*S
dpw[0] = 0
for i in range(N):
    a = A[i]
    dpb2 = [-INF]*S
    dpw2 = [-INF]*S
    for j in range(-limit, limit):
        if -limit <= j - 1 < limit:
            dpw2[j-1] = max(dpw2[j-1], dpb[j], dpw[j])
            dpb2[j-1] = max(dpb2[j-1], dpb[j], dpw[j])
        if -limit <= j + 1 < limit:
            dpb2[j+1] = max(dpb2[j+1], dpw[j]+a)
    dpw = dpw2[:]
    dpb = dpb2[:]

idx = N//2*2 - N
print(max(dpw[idx], dpb[idx]))
    

Measured memory_bytes: 92088
A = int(input())
B = int(input())

if (A==1 and B==2) or (A==2 and B==1):
  print(3)
elif (A==1 and B==3) or (A==3 and B==1):
  print(2)
elif (A==2 and B==3) or (A==3 and B==2):
  print(1)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/tenka1-2018/editorial.pdf
　　　https://ferin-tech.hatenablog.com/entry/2018/10/29/135010
　　　https://babcs2035.hateblo.jp/entry/2018/11/03/143845
　　　https://naoyat.hatenablog.jp/entry/tenka1-2018-vc
　　　https://atcoder.jp/contests/tenka1-2018-beginner/submissions/3996670
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

cnt = 1
add = 2
while cnt < N:
    cnt += add
    add += 1
# 条件を満たすものを構成できる
if cnt == N:
    # 各部分集合の要素数:c 部分集合の数:add
    c = add - 1
    ans = list2d(add, c, 0)
    k = 1
    for i in range(add):
        for j in range(i, c):
            ans[i][j] = k
            ans[j+1][i] = k
            k += 1
    print('Yes')
    print(add)
    for i in range(add):
        print(c, *ans[i])
else:
    print('No')


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

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << "\n";
    return 0;
}

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

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

    map<long int,long int> cnt;
    cnt['R'] = 0;
    cnt['G'] = 0;
    cnt['B'] = 0; 
    rep(i,N) {
        if(S.at(i)=='R') {
            cnt.at('R')++;
        }
        if(S.at(i)=='G') {
            cnt.at('G')++;
        }
        if(S.at(i)=='B') {
            cnt.at('B')++;
        }                
    }

    long int total = cnt.at('R')*cnt.at('G')*cnt.at('B');

    rep(i,N) {
        for(int j=i+1;j<N;j++) {
            if((2*j-i)>=0 && (2*j-i)<N){
                if(S.at(i)!=S.at(j) && S.at(j)!=S.at(2*j-i) && S.at(2*j-i)!=S.at(i)) {
                    total -= 1;
                  	//cout << i << j << endl;
                }
            }
        }
    }

    cout << total << endl;
}

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

#define INF (1 << 30)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int a[M], b[M];
    rep(i, M){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    int ans = 0;
    rep(i, M){ // for each hen
        int nodes[N];
        map<int, bool> m;
        rep(j, N){
            nodes[j] = j;
        }
        rep(j, M){
            if(j != i){
                int big = max(nodes[a[j]], nodes[b[j]]);
                int les = min(nodes[a[j]], nodes[b[j]]);
                rep(k, N){
                    if(nodes[k] == big){
                        nodes[k] = les;
                    }
                }
                
            }
        }

        rep(j, N){
            m[nodes[j]] = true;
        }
        if(m.size() > 1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  int n;
  cin >> n;
  double a, s=0.0;
  for(int i=0; i<n; i++){
    cin >> a;
    s+=1/a;
  }
  cout << fixed << setprecision(6) << 1/s;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main()
{
  ll x; cin >> x;
  ll n = 100;
  ll ans = 0;
  while (n < x) {
    n *= 1.01;
    ans++;
  }

  cout << ans << endl;

  return 0;
}


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

class union_find {
public:
  vector<ll> data;

  union_find(){};
  union_find(ll size) { data.assign(size, -1); }

  bool unite(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return false;
    }
    if (data[x] > data[y]) {
      swap(x, y);
    }
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  bool same(int x, int y) { return root(x) == root(y); }

  ll root(ll x) {
    if (data[x] < 0) {
      return x;
    }
    else {
      return data[x] = root(data[x]);
    }
  }

  ll size(ll x) { return (-data[root(x)]); }
};

class point {
public:
  int x, y;
  point(){};
  point(int a, int b) {
    x = a;
    y = b;
  }
};

int N, M;
vector<int> P;
vector<point> A;

void abc097d() {
  union_find uf = union_find(N + 1);
  for (int j = 1; j <= M; j++) {
    int nx = A[j].x, ny = A[j].y;
    uf.unite(P[nx], P[ny]);
  }
  int res = 0;
  for (int i = 1; i <= N; i++) {
    if (uf.same(i, P[i])) {
      res++;
    }
  }
  cout << res << "\n";
  return;
}

int main() {
  cin >> N >> M;
  P.resize(N + 1);
  A.resize(M + 1);
  for (int i = 1; i <= N; i++) {
    cin >> P[i];
  }
  for (int j = 1; j <= M; j++) {
    cin >> A[j].x >> A[j].y;
  }
  abc097d();
  return 0;
}


Measured memory_bytes: 2176
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		String msg = "Yes";
		String[] num = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

		for (int i = 0; i < s.length(); i++) {

			if (i < a || i > a) {
				if (!(Arrays.asList(num).contains(s.substring(i, i+1)))) {
					msg = "No";
					break;
				}
			}

			if (i == a) {
				if (s.charAt(i) != '-') {
					msg = "No";
					break;
				}
			}

		}

		System.out.println(msg);
	}

}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


int main() {

	int mp[105][105] = {};

	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int v, k;
		cin >> v >> k;
		v--;
		for (int j = 0; j < k; j++)
		{
			int c;
			cin >> c;
			c--;
			mp[v][c] = 1;
		}
	}

	for (int i = 0; i < n; i++)
	{
		
		for (int j = 0; j < n; j++)
		{
			if (j == 0) {
				cout << mp[i][j];
			}
			else
			{
				cout << " " << mp[i][j];
			}
		}
		cout << endl;
	}



	return 0;
}


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

using namespace std;

void update(vector<long long> &f, long long n, int a, int b) {
	for (int i = a; i <= n; i++) {
		f[i] = max(f[i], f[i - a] + b);
	}
}

int main() {
	long long n, m;
	cin >> n;
	vector<int> a(3), b(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 3; i++) {
		cin >> b[i];
	}
	vector<long long> f;
	// A -> B
	f = vector<long long>(n + 1, 0);
	for (int i = 0; i < 3; i++) {
		if (a[i] < b[i]) {
			update(f, n, a[i], b[i]);
		}
	}
	m = 0;
	for (int i = n; i >= 0; i--) {
		m = max(f[i] + n - i, m);
	}
	n = m;
	// cout << n << endl;
	// B -> A
	f = vector<long long>(n + 1, 0);
	for (int i = 0; i < 3; i++) {
		if (a[i] > b[i]) {
			update(f, n, b[i], a[i]);
		}
	}
	m = 0;
	for (int i = n; i >= 0; i--) {
		m = max(f[i] + n - i, m);
	}
	cout << m << endl;
	return 0;
}

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

int main () {
	int n, k; cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++) 
		cin >> a[i];
	sort(a,a+n);
	int m = 1e9+7;
	for (int i = 0; i+k-1 < n; i++) {
		// cout << a[i+k-1] << '-' << a[i] << endl;
		m = min(m, a[i+k-1]-a[i]);
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
using namespace std;

#define ll long long
#define forn(i,n)for(i=0;i<n;i++)
#define forc(i,c,n)for(i=c;i<=n;i++)
typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

int main() {
	ifstream fin("Text.txt");
	int i, j, q;
	ll a, b, c, h,w,e, f, n, t, m, r, d, k, x, y, ans;
	string st;
	cin >> h >> w;
	VEC cnt(30);
	forn(i, h) {
		cin >> st;
		forn(j, w) {
			cnt[st[j] - 'a']++;
		}
	}
	a = 0; b = 0; c = 0;
	forn(i, 26) {
		d = cnt[i];
		x = d / 4;
		d %= 4;
		a += x;
		x = d / 2;
		d %= 2;
		b += x;
		c += d;
	}
	
	if (h&1 && w&1) {
		d = (h - 1)*(w - 1);
		d /= 4;
		a -= d;
		if (a < 0)
			cout << "No" << endl;
		else if (c == 1)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	else if (!(h & 1) && !(w & 1)) {
		if (b || c)
			cout << "No" << endl;
		else
			cout << "Yes" << endl;
	}
	else {
		d = h*w - ( h&1 ? w : h);
		d /= 4;
		a -= d;
		if (a < 0)
			cout << "No" << endl;
		else if (c)
			cout << "No" << endl;
		else
			cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE TypeApplications #-}
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.List
import Control.Monad

readInt = readLn :: IO Int
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

main :: IO ()
main = do
  n <- readInt
  as <- sort <$> readIntegers
  print $ fromMaybe (-1) $ foldM f 1 as
    where
      f :: Integer -> Integer -> Maybe Integer
      f a b
        | a * b <= 10 ^ 18 = Just $ a * b
        | otherwise = Nothing


Measured memory_bytes: 19208
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 5);
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    
    int ans = 0;
    for(int l = 0; l <= k; ++l) {
        for(int r = 0; r <= k; ++r) {
            if(l + r > k || l >= n - r + 1)
                break;
            
            int left = k - l - r;
            vector<int> hand;
            int sum = 0;
            for(int i = 1; i <= l; ++i)
                hand.push_back(a[i]), sum += a[i];
            for(int i = n; i >= n - r + 1; --i)
                hand.push_back(a[i]), sum += a[i];

            sort(hand.begin(), hand.end());
            for(int i = 0; i < min((int)hand.size(), left); ++i) {
                if(hand[i] < 0)
                    sum -= hand[i];
            }
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		int M=500000001;
		for(;;)
		{
			int c=in.nextInt();//チケットの数
			int n=in.nextInt(),m=in.nextInt();//バス停の数,道の数
			int s=in.nextInt(),d=in.nextInt();//スタート&ゴール
			if((c|n|m|s|d)==0)
				return;
			int cost[][]=new int[n+1][n+1];
			for(int i=0;i<=n;i++)
				Arrays.fill(cost[i], M);
//			for(int q[]: cost) {
//				Arrays.fill(q, M);
//			}
			for(int i=1;i<=n;i++)
				cost[i][i]=0;
			for(int i=0;i<m;i++)
			{
				int a=in.nextInt();
				int b=in.nextInt();
				int f=in.nextInt();
				cost[a][b]=f;
				cost[b][a]=f;
			}
			int p=0,w=0;
			int v[][] = new int[n+1][c+1];// decision flag
			int leng[][]=new int[n+1][c+1];// minimum distance
			for(int i=0;i<=n;i++)
				for(int k=0;k<=c;k++)
				{
					leng[i][k]=M;
					v[i][k]=0;
				}
			leng[s][c]=0;
			for(;;)
			{
				int min=M;//最小の節点を探す
				for(int l=1;l<=n;l++)
					for(int k=0;k<=c;k++)
					{
						if(v[l][k]==0&&leng[l][k]<min)
						{
							p=l;
							w=k;
							min=leng[l][k];
						}
					}
				if(min==M)
					break;
				v[p][w]=1;//確定フラグ
				for(int l=1;l<=n;l++) //pを経由してlに至る長さがそれまでの最短経路より小さければ更新
				{
					leng[l][w]=Math.min(leng[l][w], leng[p][w]+cost[p][l]);
					if (w>0)
						leng[l][w-1]=Math.min(leng[l][w-1], leng[p][w]+cost[p][l]/2);
				}
			}
			int ans=M;
			for(int i=0;i<=c;i++)
				ans=Math.min(ans, leng[d][i]);
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#include <unordered_map>
#define inputarr(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define prllarr(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define in(n) scanf("%lld",&n);
#define in2(x,y) scanf("%lld %lld",&(x),&(y));
#define in3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z));
#define out(n) printf("%lld\n",n);
#define out2(x,y) printf("%lld %lld\n",x,y);
#define test(t)  ll t; in(t);while(t--)
#define set(arr,n,s) for(ll i=0;i<n;i++){arr[i]=s;}


/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1){res=(res*x)%p;} y=y>>1;x=(x*x)%p;}return res;}
ll modInverse(ll a,ll p){return power(a,p-2,p);}//used with feemat little

ll gcd(ll x,ll y){if(x==0 || y==0){return max(y,x);}return gcd(y%x,x);}
ll gcdExtended(ll a,ll b,ll &x,ll &y){if(a==0){x=0;y=1;return b;}ll x1,y1;ll gcd = gcdExtended(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return gcd;}//o(log(b))
;
ll arr[104];
ll dp[100005];
int main()
{
	ll n,k;
	in2(n,k)
	ll mini=1e10;
	for(ll i=0;i<n;i++){
		in(arr[i])
		mini=min(mini,arr[i]);
	}
	for(ll i=mini;i<=k;i++){
		dp[i]=0;
		for(ll j=0;j<n;j++){
			if(i-arr[j]>=0){
				dp[i]|=(dp[i-arr[j]]==0);
			}
		}
	}
	if(dp[k])cout<<"First"<<endl;
	else cout<<"Second"<<endl;


}






Measured memory_bytes: 1024
//ALDS1_7A
#include <iostream>
using namespace std;

#define MAX 100005
#define NIL -1

struct Node{int p,l,r;};
Node T[MAX];
int n,D[MAX];

void print(int u){
 int i,c;
 cout<<"node "<<u<<": ";
 cout<<"parent = "<<T[u].p<<", ";
 cout<<"depth = "<<D[u]<<", ";
 if (T[u].p==NIL) cout<<"root, ";
 else if(T[u].l==NIL) cout<<"leaf, ";
 else cout<<"internal node, ";
 cout<<"[";
 for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
  if(i) cout<<", ";
  cout<<c;
 }
 cout<<"]"<<endl;
}

int rec(int u,int p){
 D[u]=p;
 if(T[u].r!=NIL) rec(T[u].r,p);
 if(T[u].l!=NIL) rec(T[u].l,p+1);
}

int main(){
 int i,j,d,v,c,l,r;
 cin>>n;
 for(i=0;i<n;i++) T[i].p=T[i].l=T[i].r=NIL;
 for(i=0;i<n;i++){
  cin>>v>>d;
  for(j=0;j<d;j++){
   cin>>c;
   if(j==0) T[v].l=c;
   else T[l].r=c;
   l=c;
   T[c].p=v;
  }
 }
 for(i=0;i<n;i++){
  if(T[i].p==NIL) r=i;
 }
 rec(r,0);
 for(i=0;i<n;i++) print(i);
 return 0;
}

Measured memory_bytes: 5840
s = input()

a = int(s[:2])
b = int(s[2:])
if 0 < a < 13:
    if 0 < b < 13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif 0 < b < 13:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
n, m = map(int, input().split())
c = [0] * n
d = [0] * n
for i in range(m):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    c[l] += 1
    d[r] += 1

c.reverse()
for i in range(n):
    if c[i] != 0:
        a = i
        break
for i in range(n):
    if d[i] != 0:
        b = i
        break

if b-n+a+2 < 0:
    print(0)
else:
    print(b-n+a+2)


Measured memory_bytes: 4596
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let s: String = read();
    let s = &s[..];

    println!("{}", 
        if s[n/2..] == s[..n/2] {
            "Yes"
        } else {
            "No"
        }
    );
}

Measured memory_bytes: 4352
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


class RangeUpdate:
    def __init__(self, n):
        self.p = BIT(n + 1)
        self.q = BIT(n + 1)

    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

    def sum(self, s, t):
        t += 1
        return self.p.sum(t) + self.q.sum(t) * t - \
            self.p.sum(s) - self.q.sum(s) * s


def main():
    from string import ascii_lowercase
    dic = {s: i for i, s in enumerate(ascii_lowercase)}
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = [dic[s] for s in input().rstrip()]
    Q = int(input())
    Query = [[i for i in input().split()] for _ in [0]*Q]
    BIT26 = [RangeUpdate(N) for _ in [0]*26]
    for i, j in enumerate(S, start=1):
        BIT26[j].add(i, i, 1)
    answer = []
    for A in Query:
        if A[0] == "1":
            i = int(A[1])
            j = S[i-1]
            BIT26[j].add(i, i, -1)
            j = dic[A[2]]
            S[i-1] = j
            BIT26[j].add(i, i, 1)
        else:
            le = int(A[1])
            ri = int(A[2])
            ans = 0
            cur = 0
            for i in range(26):
                v = BIT26[i].sum(le, ri)
                if 0 < v:
                    ans += 1
                cur += v
                if ri - le + 1 == v:
                    break
            answer.append(ans)
    print(*answer, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 253600
#include<iostream>

using namespace std;

int main(){
        int w, h, x,y;
        cin >> w >> h >> x >> y;
        cout << (double)w * h / 2.0 << " ";
        if(2 * x == w && 2 * y == h){
                cout << 1 << endl;
        }
        else{
                cout << 0 << endl;
        }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>

#define REP(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define RREP(i,x,y) for(int i=(int)(x);i>=(int)(y);i--)
#define all(x) (x).begin(),(x).end()

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

typedef long long ll;

using namespace std;

const int MAX_N = 100000;
const ll MOD = 1000000000 + 7;

ll F[MAX_N+1];
int N, M;

// k!
void factorial(){
    F[0] = 1;
    F[1] = 1;
    REP(i, 2, MAX_N+1){
        F[i] = F[i-1] * i % MOD;
        eprintf("F[%d]=%d\n",i,F[i]);
    }
}

int extgcd(int a, int b, int &x, int &y) {
    for (int u = y = 1, v = x = 0; a;) {
        int q = b / a;
        swap(x -= q * u, u);
        swap(y -= q * v, v);
        b -= q*a; swap(b, a);
    }
    return b;
}

int invmod(int a, int m) {
    int x, y;
    if (extgcd(a, m, x, y) == 1) return (x + m) % m;
    else return 0; // unsolvable
}

int combination(int _n ,int _r){
    if(F[0] != 1) factorial();

    // nCr = n!/(n-r)!r!
    ll combination = 1;

    combination = F[_n];
    combination *= invmod(F[_n - _r], MOD);
    combination %= MOD;
    combination *= invmod(F[_r], MOD);
    combination %= MOD;

    return combination;
}

ll solve() {
    factorial();
    if(max(N - M, M - N) == 0) return (((F[N] % MOD) * (F[M] % MOD)) % MOD * 2) % MOD;
    if(max(N - M, M - N) == 1) return ((F[N] % MOD) * (F[M] % MOD))% MOD;
    else return 0;
}

int main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    cout << solve() << "\n";
    return 0;
}


Measured memory_bytes: 1024
import collections
n, m = map(int, input().split())
wa = []
submission = set()
for i in range(m):   
    p, s = input().split()
    if p in submission:
        continue

    if s == "AC":
        submission.add(p)
    else:
        wa.append(p)
wa_count = collections.Counter(wa)
pena = 0
for j in submission:
    x = wa_count[j]
    pena += x

print(len(submission), pena)


Measured memory_bytes: 14396
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_P = 2000 * 2000 + 1;
const int MOD = (int)1e9 + 7;

int fact[MAX_P], rfact[MAX_P];

ll extgcd (ll a, ll b, ll &x, ll &y){
	if (b == 0){x = 1LL; y = 0LL; return a;}
	ll g = extgcd (b, a%b, y, x); y -= a/b*x;
	return g;
}

ll mod_inv(ll a, ll M){
	ll x, y;
	extgcd (a, M, x, y);
	return (M+x%M)%M;
}

void init(void){
	fact[0] = rfact[0] = 1;
	for (int i = 1; i < MAX_P; i++ ){
		fact[i] = ((ll)fact[i-1]*i)%MOD;
		rfact[i] = ((ll)rfact[i-1]*mod_inv((ll)i,(ll)MOD))%MOD;
	} // end for
}
	
int comb(int n, int k){
	if (n < k) return 0;
	return (((ll)fact[n]*rfact[n-k])%MOD)*rfact[k]%MOD;
}

ll dp[2001][2001];

int main()
{
	memset(dp, 0LL, sizeof(dp));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, K; cin >> N >> K;
	init();

	rep (i, N+1) dp[i][0] = 1LL;
	if (N != 1 && K != 1){
		for (int i = 1; i <= N; ++i){
			for (int j = 1; j <= i; ++j){
				dp[i][j] = (dp[i-1][j] + (ll)comb(N - i + (N - j + 1)*(K - 1) - 1, K-2) * dp[i][j-1]) % (ll)MOD;
			} // end for
		} // end for
		ll res = (dp[N][N] * fact[N]) % (ll)MOD;
		cout << res << endl;			
	}else{
		cout << 1 << endl;
	} // end if

	return 0;
}

Measured memory_bytes: 62848
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    int N;
    cin >> N;
    int tmp, tmpm = -1, sum = 0;   
    REP(i, N){
        cin >> tmp;
        tmpm = max(tmpm, tmp);
        sum += tmp;
    }
    string s = "No";
    if (sum - tmpm > tmpm) s = "Yes";
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline void chmin(T &a, T b){if(a>=b)a=b;}
template<class T> inline void chmax(T &a, T b){if(a<=b)a=b;}
typedef long long ll;
const int INF = 1e9;

int H,W;
string maze[55];
int dist[55][55];


int main()
{
    cin >> H >> W;
    int sx, sy, gx, gy;
    REP(i,H) cin >> maze[i];
    int cntWall = 0;
    REP(i,H) REP(j,W){
        if(maze[i][j]=='#') ++cntWall;
    }

    // 初期化
    REP(i,H) REP(j,W) dist[i][j] = INF;

    queue<pair<int,int> > q;
    int movy[4] = {0,-1,0,1};
    int movx[4] = {-1,0,1,0};

    dist[0][0] = 0;
    q.push(make_pair(0,0));
    while(!q.empty()){
        int y = q.front().first;
        int x = q.front().second;

        q.pop();
        REP(i,4){
            int dy = y + movy[i];
            int dx = x + movx[i];
            if(dy < H && dy >= 0 && dx < W && dx >= 0 && maze[dy][dx]!='#' && dist[dy][dx]==INF){
                dist[dy][dx] = dist[y][x] + 1;
                q.push(make_pair(dy,dx));
            }
        }
    }
    if(dist[H-1][W-1]==INF) cout << -1 << endl;
    else cout << H * W - cntWall - dist[H-1][W-1] - 1 << endl;
    return 0;
}

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

int makeBigInt(char*, const char*);
int sumBigInt(char*, const char*, const char*);

int main(void){
	int i, n, err;
	char buf[1024], a[81], b[81];
	
	scanf("%d", &n);
	
	while(n--){
		err = 0;
		
		scanf(" %s", buf);
		err += makeBigInt(a, buf);
		
		scanf(" %s", buf);
		err += makeBigInt(b, buf);
		
		err += sumBigInt(buf, a, b);
		
		if(err < 0){
			printf("overflow\n");
			continue;
		}
		
		for(i = 0; i < 79; i++)
			if(buf[i] != '0') break;
		
		printf("%s\n", buf + i);
	}
	
	return 0;
}

int makeBigInt(char *s, const char *t){
	int l, i;
	
	l = 80 - strlen(t);
	
	if(l < 0) return -1;
		
	for(i = 0; i < l; i++)
		s[i] = '0';
	
	strcpy(s + l, t);
	
	return 0;
}

int sumBigInt(char *sum, const char *a, const char *b){
	int i, n;
	int m = 0;
	
	for(i = 79; i >= 0; i--){
		n = (a[i] - '0') + (b[i] - '0') + m;
		m = n / 10;
		sum[i] = (n % 10) + '0';
	}
	
	sum[80] = '\0';
	
	return (m ? -1 : 0);
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);
 
int main() {
    ll n;
    cin >> n;
 
    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }
 
    ll ans = INF;
    exrep(i, -100, 100) {
        ll now = 0;
        rep(j, n) {
            now += (a[j] - i)*(a[j] - i);
        }
        chmin(ans, now);
    }
 
    out(ans);
    re0;
}

Measured memory_bytes: 256
A,B,C =map(int,input().split())

res = 0
s = A+B+C
if (max(A,B,C)*3-s)%2 == 0:
    res = (max(A,B,C)*3-s)//2
else:
    res = ((max(A,B,C)+1)*3-s)//2
print(res)

Measured memory_bytes: 38384
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
root0 = 0
rootn = 0
for i in range(1,x):
  if i in a:
    root0 += 1
for i in range(x+1,n+1):
  if i in a:
    rootn += 1
print(min(root0,rootn))

Measured memory_bytes: 9188
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int r[][8] = {
	{1, 2, 3, 0, 5, 6, 7, 4},
	{1, 5, 6, 2, 0, 4, 7, 3}
};
set<int> s;
void rec(const vi &v){
	int h = 0;
	rep(i, 7) h *= 8, h += v[i];
	if(s.count(h)) return;
	s.insert(h);
	
	rep(d, 2){
		vi nv;
		rep(i, 8) nv.pb(v[r[d][i]]);
		rec(nv);
	}
}
int main(){
	string in[8];
	while(cin >> in[0]){
		rep(i, 7) cin >> in[i + 1];
		map<string, int> m;
		rep(i, 8) m[in[i]]++;
		vi v;
		int k = 0, ans = 0;
		each(i, m){
			rep(j, i->second) v.pb(k);
			k++;
		}
		s.clear();
		do{
			int h = 0;
			rep(i, 7) h *= 8, h += v[i];
			if(!s.count(h)){
				rec(v);
				ans++;
			}
		}while(next_permutation(all(v)));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;

  int hun = H * 60 + M;

  double sita_h = hun * 0.5;
  double sita_m = hun * 6;

  double ans = sqrt( (A*cos(PI*sita_h/180)-B*cos(PI*sita_m/180))*(A*cos(PI*sita_h/180)-B*cos(PI*sita_m/180))
                     + (A*sin(PI*sita_h/180)-B*sin(PI*sita_m/180))*(A*sin(PI*sita_h/180)-B*sin(PI*sita_m/180))  );
  cout << setprecision(20) << ans  << endl;

}


Measured memory_bytes: 4160
n = int(input())
numbers = [[0] * 39 for _ in range(39)]
offset = 19
for _ in range(n):
    a = input()
    log2 = 0
    log5 = 0
    if '.' in a:
        b, c = a.split('.')
        log2 -= len(c)
        log5 -= len(c)
        d = int(b + c)
    else:
        d = int(a)
    while d % 2 == 0:
        d //= 2
        log2 += 1
    while d % 5 == 0:
        d //= 5
        log5 += 1
    log2 = min(log2, 19)
    numbers[log2 + offset][log5 + offset] += 1

acc = [[0] * 39 for _ in range(39)]

for i in range(37, -1, -1):
    acc[i][-1] = numbers[i][-1] + acc[i + 1][-1]

for j in range(37, -1, -1):
    acc[-1][j] = numbers[-1][j] + acc[-1][j + 1]

for i in range(37, -1, -1):
    for j in range(37, -1, -1):
        acc[i][j] = numbers[i][j] + acc[i + 1][j] + acc[i][j + 1] - acc[i + 1][j + 1]

ans = 0

for i in range(39):
    for j in range(39):
        if numbers[i][j] == 0:
            continue
        log2 = i - offset
        log5 = j - offset
        pi = -log2 + offset
        pj = -log5 + offset
        tmp = acc[pi][pj]
        if pi <= i and pj <= j:
            tmp -= 1
        ans += numbers[i][j] * tmp

ans //= 2
print(ans)


Measured memory_bytes: 9284
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<functional>
#include<map>
using namespace std;
int main()
{
	string s1,t,s;
	int a=-1,f=0,c,i,j;
	cin >> s1 >> t;
	int n = s1.size();
	int m = t.size();
	for (i = 0; i <= (n - m); i++)
	{
		f = 0;
		for (j = 0; j <m; j++)
		{
			if (s1[j+i] != '?'&&s1[j+i] != t[j]) { f++; break; }
		}
		if (f == 0)a = i;
	}
	if (a == -1) {
		cout << "UNRESTORABLE" << endl; return 0;
	}
	else {
		for (j = 0; j < m; j++)
		{
			s1[a + j] = t[j];
		}
		for (i = 0; i < n; i++)
			if (s1[i] == '?')s1[i] = 'a';
		cout << s1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256