akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
typedef pair<int, int> P;

int main(){
    int f_c=0, s_c=0;
    rep(i, 3){
        int num; cin >> num;
        if(num==7) s_c++;
        else if(num==5) f_c++;
    }
    if(f_c==2&&s_c==1) out("YES");
    else out("NO");
}


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

void solve(long long N, long long K, std::vector<long long> P, std::vector<long long> C)
{
    ll ans = -INT_MAX;
    for (ll i = 0; i < N; i++)
    {
        ll u = i;
        ll cycle_sum = 0;
        ll cycle_num = 0;
        for (ll j = 0; j < K; j++)
        {
            cycle_num++;
            cycle_sum += C[u];
            u = P[u];
            if (u == i)
            {
                break;
            }
        }

        u = i;
        ll res = 0;
        for (ll j = 0; j < K; j++)
        {
            res += C[u];
            ans = max(ans, res);
            ans = max(ans, res + cycle_sum * ((K - j - 1) / cycle_num));
            u = P[u];
            if (u == i)
            {
                break;
            }
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3732
s = input()


def is_kaibun(kaibun):
    for i in range(len(kaibun) // 2):
        if kaibun[i] != kaibun[-i - 1]:
            return False
    return True


if is_kaibun(s) is True and is_kaibun(s[:len(s) // 2]) is True and is_kaibun(s[len(s) // 2 +1:]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<cstdio>
const int N=200005;
int n,S,dis[N];
struct ed{ed*nxt;int to;}pool[N<<1],*p=pool,*lnk[N];
void ae(int u,int v){*++p=(ed){lnk[u],v},lnk[u]=p;}
void dfs(int u,int fa){
	dis[u]=dis[fa]+1;
	if(dis[u]>dis[S])S=u;
	for(ed*i=lnk[u];i;i=i->nxt)if(i->to!=fa)dfs(i->to,u);
}
int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;++i){
		scanf("%d%d",&u,&v);
		ae(u,v),ae(v,u);
	}
	dfs(1,0);
	dfs(S,0);
	printf("%s\n",dis[S]%3==2?"Second":"First");
	return 0;
}

Measured memory_bytes: 14976
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int                 long long   
#define double              long double
#define endl                "\n"
#define pb                  push_back
#define PI                  3.1415926535897932384626433832795l
#define F                   first
#define S                   second
#define mp                  make_pair
#define f(i,n)              for(int i=0;i<n;i++)
#define fastio              ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define gcd(a,b)            __gcd((a),(b))
#define fill(a,value)       memset(a,value,sizeof(a));
#define minn(v)             *min_element(v.begin(), v.end());
#define maxx(v)             *max_element(v.begin(), v.end());
#define print(x)            cout<<(x)<<endl;
#define sum(v)+x            accumulate(v.begin(), v.end(),x);
#define debug(x)            cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int> pii;  
typedef vector<int> vi;

signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int n;
    cin>>n;
    vi a(n);
    f(i,n)cin>>a[i];
    map<int,int>m;
    f(i,n)
    {
        m[(i+1)-a[i]]++;
    }
    int ans=0;
    f(i,n)
    {
        ans+=m[a[i]+i+1];
    }
    print(ans)
    
    

    
    
    
    
    
    return 0;
}

Measured memory_bytes: 27396
main :: IO ()
main = do
  readLn >>= putStrLn . unwords . map show . solve' 

solve' :: Integer -> [Integer]
solve' s
  | s == 10^18 = [0,0,10^9,0, 0, 10^9]
  | otherwise = [0, 0, 10^9, 1, x, y] 
  where
    check = area [0, 0, 10^9, 1, x, y] 
    (b, a) = quotRem s (10^9)
    x = 10^9 - a
    y = b + 1
    area [_, _, ax, ay, bx, by] = abs (ax*by - ay*bx)


Measured memory_bytes: 508
#include <algorithm>
#include <iostream>
#include <vector>

int main()
{
    std::string a, b;
    std::cin >> a >> b;

    std::reverse(a.begin(), a.end());
    std::reverse(b.begin(), b.end());

    while (a.size()) {
        std::cout << a.back();
        a.pop_back();

        if (b.size()) {
            std::cout << b.back();
            b.pop_back();
        }
    }
    putchar('\n');
}


Measured memory_bytes: 256
package main

import (
        "fmt"
        "sort"
)

func main() {
        var n int
        var c int64
        fmt.Scan(&n, &c)
        s := make([]sushi, n)
        for i := range s {
                fmt.Scan(&s[i].x, &s[i].v)
        }
        sort.Sort(counter(s))
        s = append([]sushi{sushi{0, 0}}, s...)
        s = append(s, sushi{c, 0})

        eatr := make([]int64, len(s))
        eatr[0] = s[0].v
        for i := 1; i < len(s); i++ {
                eatr[i] = eatr[i-1] + s[i].v
        }
        eatl := make([]int64, len(s))
        eatl[len(s)-1] = s[len(s)-1].v
        for i := len(s) - 2; i >= 0; i-- {
                eatl[i] = eatl[i+1] + s[i].v
        }
        maxr := make([]int64, len(s))
        maxr[0] = eatr[0] - s[0].x
        for i := 1; i < len(s); i++ {
                maxr[i] = eatr[i] - s[i].x
                if maxr[i-1] > maxr[i] {
                        maxr[i] = maxr[i-1]
                }
        }
        maxr2 := make([]int64, len(s))
        maxr2[0] = eatr[0] - 2*s[0].x
        for i := 1; i < len(s); i++ {
                maxr2[i] = eatr[i] - 2*s[i].x
                if maxr2[i-1] > maxr2[i] {
                        maxr2[i] = maxr2[i-1]
                }
        }

        var max int64
        for i := 1; i < len(s); i++ {
                call := eatl[i] - c + s[i].x
                cal := maxr2[i-1] + call
                if cal > max {
                        max = cal
                }
                call = eatl[i] - 2*c + 2*s[i].x
                cal = maxr[i-1] + call
                if cal > max {
                        max = cal
                }
        }
        fmt.Println(max)
}

type sushi struct {
        x, v int64
}

type counter []sushi

func (c counter) Len() int           { return len(c) }
func (c counter) Less(i, j int) bool { return c[i].x < c[j].x }
func (c counter) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }

Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(void){
  int n,m,max;
  int i,j,k;
  int car[20000];
 
  while(1){
    max=0;
 
    cin >> n >> m;
    if( n == 0 && m == 0 ) break;
 
    for( i = 0 ; i < n ; i++ ){
      cin >> car[i];
    }
 
    for( j = n ; j < n + m ; j++ ){
      cin >> car[j];
    }
 
    sort( car , car + n+m );
 
    for( k = 0 ; k < n + m ; k++ ){
 
      if( max < car[k] - car[k-1] ) max = car[k] - car[k-1];
 
    }
 
    cout << max << endl;
 
  }
 
  return 0;
 
}

Measured memory_bytes: 1252
C = []
for i in range(3):
    C.append(list(map(int, input().split())))
if ((C[0][0]-C[1][0])==(C[0][1]-C[1][1])==(C[0][2]-C[1][2]) and\
 (C[1][0]-C[2][0])==(C[1][1]-C[2][1])==(C[1][2]-C[2][2]) and\
 (C[2][0]-C[0][0])==(C[2][1]-C[0][1])==(C[2][2]-C[0][2]) and\
 (C[0][0]-C[0][1])==(C[1][0]-C[1][1])==(C[2][0]-C[2][1]) and\
 (C[0][1]-C[0][2])==(C[1][1]-C[1][2])==(C[2][1]-C[2][2]) and\
 (C[0][2]-C[0][0])==(C[1][2]-C[1][0])==(C[2][2]-C[2][0])):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<cmath>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  2000007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main() {
    int n;
    I(n);
    int re =0;
    for(int i = 2; i<= n; i+=2){
        for(int j = 1;j<=n;j+=2){
            re++;
        }
    }

    cout<<re<<endl;
    return 0;
}

Measured memory_bytes: 3740
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n , k ;
    cin >> n >> k ; 
    vector<int> v(n) ;
    for(int i = 0; i < n; i++){
        cin >> v[i] ;
    }
    int L = 1, R = 2e9 ;
    int ans = -1 ;
    while(L <= R){
        int mid = L + (R - L) / 2;
        int cuts = 0 ;
        for(int i = 0; i < n; i++){
            int c = (v[i] + mid - 1) / mid ;
            cuts += c - 1 ;
        }
        if ( cuts <= k ){
            ans = mid ;
            R = mid - 1;
        }
        else L = mid + 1;
    }
    assert(ans != -1) ;
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 4772
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	sc := NewScanner()

	s := sc.NextLine()
	ans := math.MaxInt32
	for i := 0; i < len(s)-2; i++ {
		tmp := s[i : i+3]
		num, _ := strconv.Atoi(string(tmp))
		//		fmt.Printf("%+v\n", num) // output for debug

		cand := int(math.Abs(float64(num) - 753))
		if cand < ans {
			ans = cand
		}
	}
	fmt.Printf("%v\n", ans)

}

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) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	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
n, k = gets.split.map(&:to_i)
sushi = Hash.new { |h, k| h[k] = [] }

s_0 = []
s_1 = []

n.times do
  t, d = gets.split.map(&:to_i)
  sushi[t] << d
end
sushi.values.each do |arr|
  arr.sort!.reverse!
  arr.each_with_index do |a, i|
    if i == 0
      s_1 << a
    else
      s_0 << a
    end
  end
end
s_0.sort!.reverse!
s_1.sort!.reverse!

n_0 = s_0.size
n_1 = s_1.size

# 累積和
sum_0 = [tmp = 0].concat(s_0.map { |si| tmp += si })
sum_1 = [tmp = 0].concat(s_1.map { |si| tmp += si })

ans = 0
(k + 1).times do |i|
  next if i == 0
  # s_1 からi個とる
  x = i
  y = k - i
  # 取れないときのための微調整
  if x > n_1
    y += x - n_1
    x = n_1
  end
  if y > n_0
    x += y - n_0
    y = n_0
  end
  sum = sum_1[x] + sum_0[y] + x * x
  ans = sum if sum > ans
end

p ans


Measured memory_bytes: 18540
#include<bits/stdc++.h>
using namespace std;
string s[3];long k,a[3],i,j;
int main(){
  cin>>s[0]>>k;
  for(i=0;i<2;++i)s[i+1]=s[i]+s[0];
  for(i=0;i<3;++i)for(j=1;j<s[i].size();++j)if(s[i][j]==s[i][j-1])++a[i],++j;
  cout<<(k&1?a[0]:a[1])+(k-1)/2*(a[2]-a[0])<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <string>
#include <vector>
#include <set>
using namespace std;

#define int long long
#define rep(n, i) for (int i = 0; i < n; i++)
#define rep2(m, n, i) for (int i = m; i < n; i++)
#define rep_r(n, i) for (int i = n - 1; i >= 0; i--)

const int INF = 1LL << 60;
const int MOD = 1e9 + 7;

signed main() {
    int n, a, b;
    cin >> n >> a >> b;
    if ((a + b) % 2) {
        cout << "Borys" << endl;
    } else {
        cout << "Alice" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#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 = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int n, m, s[114514], sum = 0;
	cin >> n;
	REP(i, n) {
		cin >> s[i];
		sum += s[i];
	}
	cin >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		cout << sum + b - s[a - 1] << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int ans = 1;

    if (b != a)
        ans += 1;

    if (c != b && c != a)
        ans += 1;

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()

int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int ans=h[0];
    for(int i=0;i<n-1;i++){
        if(h[i]<h[i+1]){
            ans+=h[i+1]-h[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  swap(A,B);
  swap(A,C);
  cout<<A<<" "<<B<<" "<<C<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#define D(x) cout<<"D:"<<#x<<'='<<x<<endl;
using namespace std;
typedef long long ll;
vector<string> v[200050];
string w[200050];
map<string, int> m;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, Max = 0;
	cin>>n;
	for(int i = 0; i < n; i++)
	{
		 cin>>w[i];
		 if (m.count(w[i]) != 1) m.insert(make_pair(w[i], 0));
		 m[w[i]]++;
	}
	for(auto& val : m)
		Max = max(Max, val.second), v[val.second].push_back(val.first);
	auto& p = v[Max]; 
	sort(p.begin(), p.end());
	for(int i = 0; i < p.size(); i++) cout<<p[i]<<endl;
	return 0;
}

Measured memory_bytes: 31856
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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


class UnionFind
{
	//par[i]：ノードiの親
	//count[i]：iが親の時、iが属するグループのノード数
	vector<int> par;
	vector<int> count;

	int m_groupCount = 0;

public:
	UnionFind(int N)
	{
		par.push_back(0);
		count.push_back(0);

		m_groupCount = N;

		for (int i = 1; i <= N; i++)
		{
			//最初は全てが根であるとして初期化
			par.push_back(i);
			count.push_back(1);
		}
	}

	//データxが属する木の根を再帰で得る：root(x) = {xの木の根}
	int root(int x)
	{
		if (par[x] == x) return x;

		//ついでに親を張り替え
		return par[x] = root(par[x]);
	}

	//xとyの木を併合
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return;
		//xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		par[rx] = ry;

		//要素数の変更
		count[ry] += count[rx];
		count[rx] = 0;

		//木の併合によってグループが1つ減る
		m_groupCount--;
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y)
	{
		return root(x) == root(y);
	}

	//指定したデータxが属するグループの要素数を返す
	int size(int x)
	{
		return count[root(x)];
	}

	//UnionFindのグループの個数を返す
	int groupCount()
	{
		return m_groupCount;
	}
};



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

	int N, M;
	cin >> N >> M;

	vi p(N);
	rep(i, N) cin >> p[i];

	UnionFind uf(N);

	rep(i, M)
	{
		int x, y;
		cin >> x >> y;
		uf.unite(x, y);
	}

	int count = 0;
	rep(i, N)
	{
		if (uf.same(i + 1, p[i])) count++;
	}

	cout << count << endl;

    return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N,M,K;

int main(){
	cin >> N >> M >> K;
	repp(i,0,N+1){
		repp(j,0,M+1){
			if(i*M+j*N-i*j*2 == K){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    int fact[1000005];
    bool ok=false;
 
    void f(int x){
        if(ok==true)
            return;
        for(int i=1;i*i<=x;i++){
            if(x%i==0){
                int a=i;
                int b=x/i;
                if(a==b){
                    a=i;
                    b=1;
                }
                if(a!=1){
                    if(fact[a]){
                        ok=true;
                        return;
                    }
                    fact[a]++;
                }
                if(b!=1){
                    if(fact[b]){
                        ok=true;
                        return;
                    }
                    fact[b]++;
                }
            }
        }
    }
 
    void solve(){  
        int n;
        cin>>n;
        vector<int>a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        int gcd=a[0];
        // cout<<"in "<<ok<<"\n";
        f(a[0]);
        // cout<<"in "<<ok<<"\n";
        for(int i=1;i<n;i++){
            f(a[i]);
            gcd=__gcd(gcd,a[i]);
            // cout<<"in "<<ok<<"\n";
        }
        if(!ok){
            cout<<"pairwise coprime";
        }
        else if(gcd==1){
            cout<<"setwise coprime";
        }
        else{
            cout<<"not coprime";
        }
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }


Measured memory_bytes: 7572
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String sa = sc.next();
		String sb = sc.next();
		BigDecimal A = new BigDecimal(sa);
		BigDecimal B = new BigDecimal(sb);
		System.out.println(A.multiply(B).setScale(0, BigDecimal.ROUND_DOWN));
	}
}


Measured memory_bytes: 36024
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int n,A,B;
inline int lowbit(int x){return x&(-x);}
void Solve(int p,int pre,int has,int x,int y)
{
   // cout<<"Solve"<<p<<" "<<pre<<" "<<has<<" "<<x<<" "<<y<<endl;
    if(p==1)  printf("%d %d ",pre^x,pre^y);
    else
    {
        int b=lowbit(x^y),del=(1<<n)-1-b,mod=lowbit(has^=b);
        if(b&x) 
            Solve(p-1,pre|b,has,x^b,x^b^mod),
            Solve(p-1,pre  ,has,x^b^mod,y);
        else 
            Solve(p-1,pre  ,has,x,x^mod),
            Solve(p-1,pre|b,has,x^mod,y^b);
    }
}
int main()
{
    n=read();A=read();B=read();
    int num=0;for(int k=B^A;k;k>>=1) num+=(k&1);
    if(~num&1) return 0*puts("NO"); puts("YES");
    Solve(n,0,(1<<n)-1,A,B);
    return 0;
}

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

#define MAX 2000000
typedef long long ll;


int main(){

  int n;
  cin >> n;
  //cout << "hoge" << endl;
  int c[10001], *b, *a;
  b = new int[n];
  a = new int [n];
  //cout << "hoge" << endl;
  memset(c,0,sizeof(c));

  for(int i = 0; i < n; i++){
    cin >> a[i];
    c[a[i]]++;
  }
  for(int i = 1; i <= 10001; i++){
    c[i] = c[i] + c[i-1];
   // cout << c[i] << " ";
  }

  for(int i = n-1; i >= 0; i--){
    b[c[a[i]]] = a[i];
    c[a[i]]--;
  }

  for(int i = 1; i <= n; i++){
    if(i != n) cout << b[i] << " " ;
    else cout << b[i];
  }
  cout << endl;

}

Measured memory_bytes: 16852
# 2019/05/16
# AtCoder Beginner Contest 091 - B

# Input
n = int(input())
bc = list()
for i in range(n):
    bc.append(input())

m = int(input())
rc = list()
for j in range(m):
    rc.append(input())

bc.sort()
rc.sort()

# Count up
strdict = dict()
wk_str = bc[0]
wk_cnt = 1
for i in range(1, n):
    if wk_str != bc[i]:
        strdict[wk_str] = wk_cnt
        wk_cnt = 1
        wk_str = bc[i]
    else:
        wk_cnt += 1

strdict[wk_str] = wk_cnt

wk_str = rc[0]
wk_cnt = 1

for j in range(1, m):
    if wk_str != rc[j]:
        if strdict.get(wk_str) == None:
            strdict[wk_str] = wk_cnt * -1
        else:
            strdict[wk_str] += wk_cnt * -1
        wk_cnt = 1
        wk_str = rc[j]
    else:
        wk_cnt += 1

if strdict.get(wk_str) == None:
    strdict[wk_str] = wk_cnt * -1
else:
    strdict[wk_str] += wk_cnt * -1

# Search max
maxval = -101
for k in strdict.keys():
    if maxval < strdict[k]:
        maxval = strdict[k]

ans = max(maxval, 0)

print(ans)

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

const int INF = 1 << 28;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
typedef pair<int, int> Point;

int H, W, K;
char grid[64][64];
vector<Point> rem[4];
int vis[64][64];
int dp[50][50][4][1 << 12];

void init()
{
	memset(grid, '#', sizeof(grid));
	memset(dp, -1, sizeof(dp));
	
	for (int k = 0; k <= 3; k++){
		for (int x = -k; x <= (3 - k); x++){
			for (int y = -k; y <= (3 - k); y++){
				//if (x == 0 && y == 0) continue;
				if (-k <= (x + y) && (x + y) <= (3 - k)){
					rem[k].push_back(Point(x, y));
				}
			}
		}
	}
}

int calcBit(int x, int y, int k)
{
	int res = 0;
	for (Point &p : rem[k]){
		res <<= 1;
		int X = x + p.first;
		int Y = y + p.second;
		if (vis[X][Y] > 0) res |= 1;
	}
	return res;
}

int calc(int x, int y, int k)
{
	int bit = calcBit(x, y, k);
	int &res = dp[x - 3][y - 3][k][bit];
	if (~res) return res;
	
	int add = 0;
	if (grid[x][y] >= '1' && grid[x][y] <= '9'){
		if (vis[x][y] == 0){
			add = grid[x][y] - '0';
		}
	}
	
	if (x == H + 2 && y == W + 2 && k == 0){
		return res = add;
	}
	
	res = -INF;
	
	vis[x][y]++;
	for (int dir = 0; dir < 4; dir++){
		int nx = x + dx[dir];
		int ny = y + dy[dir];
		int nk = k - (dir < 2);
		if (grid[nx][ny] == '#') continue;
		if (nk < 0) continue;
		res = max(res, calc(nx, ny, nk));
	}
	vis[x][y]--;
	
	return res += add;
}

int main(void)
{
	init();
	
	scanf("%d %d %d", &H, &W, &K);
	
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			scanf(" %c", &grid[i + 3][j + 3]);
		}
	}
	
	printf("%d\n", calc(3, 3, K));
	
	return 0;
}

Measured memory_bytes: 161208
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

signed main()
{
	string s = in<string>();
	lint k = in();
	auto itr = find_if_not(ALL(s), [](char c) {return c == '1'; });
	lint ones = itr - s.begin();
	if (k <= ones)cout << '1' << endl;
	else cout << *itr << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define vi vector <int>
#define si set <int>
#define mii map <int,int>
#define pii pair <int,int>
#define endl "\n"
#define FOR(P,Q) for(int P=0;P<(Q);P++)
#define FORR(P,Q) for(int P=1;P<=(Q);P++)
#define rep(P,R,Q) for(int P=(R);P<=(Q);P++)
#define repb(P,R,Q) for(int P=(R);P>=(Q);P--)
#define pb push_back
#define eb emplace_back
#define bug(j) cerr<<j<<" "
#define NL cerr<<endl
#define D1(arr,a) rep(i,1,a) bug(arr[i]) 
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;

const int mod = 1e9+7;
    
int32_t main()
{
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("error.txt","w",stderr);
	#endif
	int tces=1;
	// cin>>tces;
	while(tces--){
		// int n;
		// cin>>n;
		// vi v(n+5);
		// FORR(i,n){
		// 	cin>>v[i];
		// }
		int n,k;
		cin>>n>>k;
		int ncr[2005][2005];
		memset(ncr,0, sizeof(ncr));
		ncr[0][0]=1;
		FOR(i,n+1){
			ncr[i][0]=1;
		}
		FORR(i,n+1){
			FORR(j,n){
				ncr[i][j]=(ncr[i-1][j-1]%mod+ncr[i-1][j]%mod)%mod;
			}
		}
		FORR(i,k){
			int ans=(ncr[k-1][i-1]%mod * ncr[n+1-k][i]%mod)%mod;
			cout<<ans<<endl;
		}
		// unordered_map<int,int> m;
		// FORR(i,n-1){
		// 	m[v[i+1]-v[i]]++;
		// }

	}
	
return 0;
}

Measured memory_bytes: 35044
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e5;
int T,K;
int dp[mxn+5];
int a[mxn+5];

int fn(int pos){
    if(pos==T-1) return 0;
    if(pos>=T) return 1<<30;
    if(dp[pos]!=-1) return dp[pos];
    int res = 1<<30;
    for(int i=1; i<=K; i++)
        res = min( fn(pos+i)+abs(a[pos]-a[pos+i]) , res );

    return dp[pos] = res;
}

void solve(){

    cin>>T>>K;
    memset(dp,-1,sizeof(dp));
    for(int i=0; i<T; i++)
        cin>>a[i];

    cout<<fn(0)<<"\n";

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}




Measured memory_bytes: 5760
#include<stdio.h>

typedef struct {
	char mark;
	int number;
} Card;

void print(Card C[], int N)
{
	int i;
	for(i=0;i<N;i++)
	{
		printf("%c%d",C[i].mark,C[i].number);
		if(i != N-1)
		{
			printf(" ");
		}
		else
		{
			printf("\n");
		}
	} 
}

void BubbleSort(Card C[],int N)
{
	
	Card tmp;
	
	for(int i=0;i<N;i++)
	{
		for(int j=N-1;j>i;j--)
		{
			
			if(C[j].number <C[j-1].number)
			{
				tmp = C[j];
				C[j] = C[j-1];
				C[j-1] = tmp;
				/*print(C,N);*/
			}
		}
	}
	print(C,N);
	printf("Stable\n");
}
	
void SelectionSort(Card C[], int N)
{
	int min;
	Card tmp;
		
	for(int i=0;i<N;i++)
	 {
 		 min = i;
 		 for(int j=i;j<N;j++)
	     {
			if(C[j].number < C[min].number)
			{
				min = j;
			}
		 } 
		
		
			tmp =C[i];
			C[i]=C[min];
			C[min]=tmp;
	 }
	print(C,N);
	
}


int main(void)
{
	int N,i;
	int flag = 1;
	Card C[36],C2[36];
	
	scanf("%d",&N);
	
	/*printf("N=%d\n",N);*/
		for(i=0;i<N;i++)
		{
			scanf(" %c%d",&C[i].mark,&C[i].number);
			/*printf("i=%d\n",i);
			printf("mark0=%c\n",C[i].mark[0]);
			printf("mark1=%c\n",C[i].mark[1]);*/
			/*C[i].number=C[i].mark[1]-'0';*/
			C2[i]=C[i];
			//printf(" %s", C2[i].mark);
			//printf("%d", C2[i].number);
		}
	
	//printf("\n");
	
	/*
		print(C,N);
	printf("\n");*/
		BubbleSort(C,N);
		SelectionSort(C2,N);
		
		for(i=0;i<N;i++)
		{
			if(C[i].mark != C2[i].mark)
			{
				flag = 0;
				break;
			}
		}
		
		if(flag)
		{
			printf("Stable\n");
		}
		else 
		{
			printf("Not stable\n");
		}
	
	return 0;
}


Measured memory_bytes: 2092
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int X;

int main() {

	cin >> X;

	int r = X / 100, l = X % 100;
	if (l <= r * 5) {
		cout << 1 << endl;
		return 0;
	}

	cout << 0 << endl;

	return 0;
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n;
    cin >> n;

    int ans = 0;
    // 処理
    rep(i, n) { ans += i + 1; }

    // 出力
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string S;
  cin >> S;
  int length = sz(S);
  string ans;
  rep(i, length) ans += 'x';
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n,t;
  cin>>n>>t;
  vector<int64_t> a(n);
  for(auto&& e: a) {
    cin>>e;
  }
  vector<int64_t> vec;
  vec.emplace_back(0);
  int64_t max=a.back();
  std::map<int64_t, int64_t> mp;
  for (int i = n-2; i >= 0; --i)
  {
    if(a[i]<max){
      vec.emplace_back(max-a[i]);
    }
    else{
      vec.emplace_back(0);
      max=a[i];
    }
  }
  for(auto&& e: vec) {
    mp[e]++;
  }
  cout<<mp[*max_element(vec.begin(), vec.end())];
}

Measured memory_bytes: 8052
// AtCoder Grand Contest 015
// D - A or...or B Problem

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


ll A, B;

int main() {

    ll d, k, ans;

    cin >> A >> B;
    for (d = (1LL << 60); d > 0; d >>= 1) {
        if ((A & d) != (B & d)) {
            break;
        }
    }
    for (k = (d >> 1); k > 0; k >>= 1) {
        if (B & k) {
            break;
        }
    }
    k = max(k - 1, 0LL);
    d = max(d - 1, 0LL);
    ans = (B | k) - A + 1;
    ans += (B | d) - max((B | k) + 1, (B & ~d) | (A & d)) + 1;

    cout << ans << endl;


    return 0;

}





Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

    int main(){
        lint n,a,b;
        cin>>n>>a>>b;
        lint v[n];
        M m1,m2;
        rep(i,n){
            cin>>v[i];
            m1[v[i]]++;
        }
        sort(v,v+n,greater<lint>());
        long double ave=0;
        rep(i,a){
            m2[v[i]]++;
            ave+=v[i];
        }
        ave/=a;
        if(m2.size()!=1){
            lint g;
            for(auto x:m2){
                g=x.first;
                break;
            }
            lint x=m1[g],y=m2[g];
            Bint ans=1;
            rep(i,x)ans*=(i+1);
            rep(i,y)ans/=(i+1);
            rep(i,x-y)ans/=(i+1);
            printf("%.9Lf\n",ave);
            cout<<ans<<endl;
        }else{
            lint g;
            for(auto x:m2){
                g=x.first;
                break;
            }
            lint l=m1[g];
            Bint ans=0;
            repp(i,a,min(b+1,l+1)){
                Bint add=1;
                rep(j,l)add*=(j+1);
                rep(j,i)add/=(j+1);
                rep(j,l-i)add/=(j+1);
                ans+=add;
            }
            printf("%.9Lf\n",ave);
            cout<<ans<<endl;

        }


    }
      

Measured memory_bytes: 3868
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
  ll n,w;
  cin>>n>>w;
  v(ll) weight(n),value(n);
  rep(i,n) cin>>weight[i]>>value[i];
  vv(ll) dp(n+1,v(ll)(w+1));
  rep(i,n){
    for(ll sum=0;sum<=w;sum++){
      if(sum-weight[i]>=0){
        maxs(dp[i+1][sum],dp[i][sum-weight[i]]+value[i]);
      }
      maxs(dp[i+1][sum],dp[i][sum]);
    }
  }
  cout<<dp[n][w]<<endl;
} 

Measured memory_bytes: 83264
N=int(input())
ST=[list(input().split()) for _ in range(N)]
X=input()
ind=0
for i in range(N):
    if ST[i][0]==X:
        ind=i+1
        break
ST=ST[ind:]
ans=0
for st in ST:
    ans+=int(st[1])

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	s[k - 1] -= 'A' - 'a';
	cout << s << endl;


    return 0;
}


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

signed main(){
  ll n, K; cin >> n >> K;
  vector<ll> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  vector<vector<ll> > dp(50, vector<ll> (2, -1));
  dp[40][0] = 0;
  for(int d = 45; d >= 0; d--){
   ll num = 0, mask = 1LL << d;
   for(int j = 0; j < n; j++) if(a[j] & mask) num++;
   if(dp[d + 1][1] != -1) dp[d][1] = max(dp[d][1], dp[d + 1][1] + mask * max(num, n - num));
   if(dp[d + 1][0] != -1){
     if(K & mask){
       dp[d][1] = max(dp[d][1], dp[d + 1][0] + mask * num);
       dp[d][0] = max(dp[d][1], dp[d + 1][0] + mask * (n - num));
     }
     else dp[d][0] = max(dp[d][0], dp[d + 1][0] + mask * num);
   }
  }
  cout << max(dp[0][0], dp[0][1]) << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define ii pair<int,int>
#define x first
#define y second

using namespace std;

bool check(vector<int>&a,vector<int>&b){
    for(int i = 0;i <a.size();i++){
        if(a[i]!= b[i]){
            return false;
        }
    }
    return true;
}

int main(){
    int n; cin >> n;
    string a;cin >> a;
    string b = "ABC";
    int j = 0;
    int ans = 0;
    for(int i = 0;i <n;i++){
        j = 0;
        while(j < 3 && a[i+j] == b[j]){
            j++;
        }
        if(j == 3){
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,k,q,bx,cx,ans=INT_MAX,a[2001],s[2001],b[2001],c[2001];
inline long long read()
{
   long long sum=0,x=1;
   char ch=getchar();
   while (ch<'0'||ch>'9')
   {
       if (ch=='-')
	     x=-1;
	   ch=getchar();
   }
   while (ch>='0'&&ch<='9')
   {
   	   sum=sum*10+ch-'0';
	   ch=getchar();
   }
   return sum*x;
}
inline void write(long long x)
{
    if (x<0)
	{
        putchar('-');
        x=-x;
    }
    if (x>9)
      write(x/10);
    putchar(x%10+'0');
    return;
}
int main()
{
    n=read();k=read();q=read();
    for (register int i=1;i<=n;++i)
	  s[i]=a[i]=read();
    sort(s+1,s+1+n);
    for (register int i=1;i<=n;++i)
    {
    	int l=1,r=1;
    	bx=0;
	    while (l<=n)
		{
        	cx=0;
 	        while (a[l]<s[i]&&l<=n)
			  ++l;
        	r=l;
    	    while (a[r]>=s[i]&&r<=n)
			  ++r;
    	    for (register int i=l;i<r&&i<=n;++i)
        	  c[++cx]=a[i];
    	    if (cx>=k)
			{
            	sort(c+1,c+1+cx);
        	    for (register int i=1;i<=cx-k+1;++i)
            	  b[++bx]=c[i];
        	}
        	l=r;
    	}
    	sort(b+1,b+1+bx);
    	if (bx>=q)
	 	  ans=min(ans,b[q]-b[1]);
	}
    write(ans);
    return 0;
}

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

using namespace std;
using LL = long long;
const int N = 1024;
const int INF = 1E9;
const double EPS = 1E-9;

int a[N];
int n, m;

int main() {
    ios_base::sync_with_stdio(false);

#ifdef CF_DEBUG
    freopen("../cf/input.txt","r",stdin);
#endif
    cin>>n>>m;
    int t=0;
    for(int i=0;i<n;++i){
        cin>>a[i];
        t+=a[i];
    }
    int v=0;
    for(int i=0;i<n;++i){
        if(a[i]*4*m >= t){
           v+=1;
        }
    }
    if(v>=m){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

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

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if(e - a <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}

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

int list[78498];

void list_prime(int);
int count_prim(int);

int main(){
	int count, num;

	list_prime(999999);

	while(scanf("%d", &num) != EOF){
		count = count_prim(num);
		printf("%d\n", count);
	}

	return 0;
}

void list_prime(int num){
	int count = 0, i,j;
	int flag;

	list[count++] = 2;

	// 3 ~ num まで素数をチェック
	for(i=3;i<=num;i+=2){
		// とりあえず素数として見ておく
		flag = 1;
		// 2の倍数だったらフラグ折る
		if((i % 2) == 0){
			printf("i = %d\n", i);
			flag = 0;
		}
		// j(3 ~ ルートi までの数字)で割っていく
		for(j=3;j<=sqrt(i);j+=2){
			if((i % j) == 0){
				flag = 0;
			}
		}
		if(flag){
			list[count++] = i;
		}
	}
}

int count_prim(int num){
	int i,count=0;
	for (i = 0; i < 78498; i++)
	{
		if(list[i] > num){
			break;
		}
		count++;
	}
	return count;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50
int n, a, b;
bool enough(int expl, vi health)
{
    vi v(health);
    int ct = expl;

    for(int i = 0; i < v.size(); i++)
    {
        v[i] -= expl*b;
        if(v[i] > 0)
        {
            ct -= ceil((double)v[i]/(a-b));
            if(ct < 0)
            {
                return false;
            }
        }
    }
    return true;
}
int main()
{
    cin >> n >> a >> b;
    vi health(n);
    for(int i = 0; i < n; i++)
    {
        cin >> health[i];
    }

    int i = -1;

    for(int c = 1000000000/b; c >= 1; c /= 2)
    {
        while(!enough(i+c, health))
        {
            i += c;
        }
    }
    i++;
    cout << i << endl;


}


Measured memory_bytes: 1472