akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

vector<int> edge[5 + (int)1e5];
const long long MOD = 1000000007;
int N, K;

long long solve(int pos, int from) {
  long long res = 1;
  int loop;
  long long cand;
  if (from == -1) {
    res = K;
    cand = K - 1;
    loop = edge[pos].size();
  } else {
    cand = K - 2;
    loop = edge[pos].size() - 1;
  }
  for (int i = 0; i < loop; i++) {
    res *= cand;
    res %= MOD;
    cand--;
  }

  for (int i = 0; i < edge[pos].size(); i++) {
    int next = edge[pos][i];
    if (next == from) {
      continue;
    }
    res *= solve(next, pos);
    res %= MOD;
  }
  return res;
}

int main() {
  while (cin >> N >> K) {
    for (int i = 0; i < N; i++) {
      edge[i].clear();
    }
    for (int i = 0; i < N - 1; i++) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      edge[a].push_back(b);
      edge[b].push_back(a);
    }
    cout << solve(0, -1) << endl;
  }
}


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

int main(){
    vector<int> x(5);
    rep(i,5) cin >> x[i];
    int ans = 0;
    rep(i,5){
        if(x[i] == 0) ans = i+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char alpha; cin >> alpha;
    if('a' <= alpha && alpha <= 'z') cout << 'a';
    else cout << 'A';
    cout << endl;
    return 0;
}

Measured memory_bytes: 3548
// C - Alchemist
// https://atcoder.jp/contests/abc138/tasks/abc138_c
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)
	vi := []float64{}
	for i := 0; i < n; i++ {
		vi = append(vi, nextFloat64(sc))
	}

	sort.Sort(sort.Float64Slice(vi))

	for i := 1; i < n; i++ {
		vi[i] = (vi[i] + vi[i-1]) / 2
	}

	fmt.Println(vi[len(vi)-1])
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextFloat64(sc *bufio.Scanner) float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f64
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int N, Q;
    string s;
    cin >> N >> Q >> s;
    vector<int> a(100010);//a[i] := i番目までの'AC'の個数
    a[0] = 0;
    a[1] = 0;
    rep2(i, 2, N+1)
    {
        a[i] = a[i-1];
        string t = s.substr(i-2, 2);
        //cout << i << "/" << t << endl;
        if(t == "AC")
        {
            a[i] += 1;
        }
    }
    // rep2(i, 0, N+1)
    // {
    //     cout << a[i]<< ",";
    // }
    rep(i, Q)
    {
        int l, r;
        cin >> l >> r;
        //--l;
        cout << a[r] - a[l] << endl;
    }
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int cnt[m]{};
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      a--;
      cnt[a]++;
    }
  }
  cout << count(cnt, cnt + m, n) << endl;
  return 0;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if((a>=c && a-c<=d) || (a<=c && c-a<=d) || (a>=b && b>=c && a-b<=d && b-c<=d) || (a<=b && b<=c && b-a<=d && c-b<=d)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<endl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<"\n"
#define mod 1000000007ll
#define inf 9999999999999999ll
#define nl endl

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    map <ll,ll> c;
    vi a(n);
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        a[i]=x;
        c[x]++;
    }
    ll total=0;
    for(auto &i:c)
    {
        total+=(i.S)*(i.S-1)/2;
    }
    for(ll i=0;i<n;i++)
    {
        ll count=(c[a[i]])*(c[a[i]]-1)/2;
        ll ans=total-count+(c[a[i]]-1)*(c[a[i]]-2)/2;
        cout<<ans<<nl;
    }
}


Measured memory_bytes: 11136
str = gets.chomp
needles = ['dream', 'dreamer', 'erase', 'eraser']

rstr = str.reverse
rneedles = needles.map(&:reverse)

while rstr.length > 0 do
  can = false
  rneedles.each do |needle|
    if rstr.start_with?(needle)
      can = true
      rstr = rstr.sub(needle, '')
    end
  end
  break if can == false
end

puts rstr.empty? ? 'YES' : 'NO'

Measured memory_bytes: 78676
s = int(input())
ans = 0
if s == 1 or s == 2:
    print(4)
    exit()
for i in range(1000000):
    if s == 4:
        ans = i + 4
        break
    if s % 2 == 0:
        s //= 2
    else:
        s = s * 3 + 1
print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<float>vec;
    float n;
    cin>>n;
    float result=0;
    while(n--)
    {
        float p;
        cin>>p;
        vec.push_back(p);
    }
    if(vec.size()==2)cout<<(vec[0]+vec[1])/2<<endl;
    else
    {
        sort(vec.begin(),vec.end());
        float result=vec[0];

        for(int i=1;i<vec.size();i++)
        {
            result+=vec[i];
            result=result/2;
        }
        cout<<result<<endl;

    }
    return 0;

}


Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char s[4];
    scanf("%s", s);
    int a = 0, b = 0;
    for (int i = 0; i < 3; i++)
        if (s[i] == 'A')
            a = 1;
        else
            b = 1;

    printf(a && b ? "Yes\n" : "No\n");

    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()

ri = [i for i, x in enumerate(s) if x=='R']
gi = [i for i, x in enumerate(s) if x=='G']
bi = [i for i, x in enumerate(s) if x=='B']

ans = len(ri) * len(gi) * len(bi)

for i in range(n):
    for d in range(n):
        j=i+d
        k=i+2*d
        if k>=n:
            break
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            ans -= 1

print(ans)

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int>a(N);

    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int number = 1;
    int ans = 0;
    bool check = false;
    for (int i = 0; i < N; i++) {
        if (a[i] == number) {
            check = true;
            number++;
        } else {
            ans++;
        }
    }
    if (check) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 1024
a = []
check = []
for i in range(3):
    a.append([int(j) for j in input().split()])
 
d1 = [a[0][0],a[1][1], a[2][2]]
d2 = [a[0][2],a[1][1], a[2][0]]
col1 = [a[0][0],a[1][0], a[2][0]]
col2 = [a[0][1],a[1][1], a[2][1]]
col3 = [a[0][2],a[1][2], a[2][2]]
 
n = input()
n = int(n)
for i in range(n):
    check.append(int(input()))
 
if all(elem in check for elem in d1):
    print("Yes")
elif all(elem in check for elem in d2):
    print("Yes")
elif all(elem in check for elem in col1):
    print("Yes")
elif all(elem in check for elem in col2):
    print("Yes")
elif all(elem in check for elem in col3):
    print("Yes")
elif all(elem in check for elem in a[0]):
    print("Yes")
elif all(elem in check for elem in a[1]):
    print("Yes")
elif all(elem in check for elem in a[2]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main() {
	int N,a=0,b=0,c=0,d=0,e=0;
	string h;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> h;
		if(h =="AC")
			a++;
		if (h == "WA")
			b++;
		if (h == "TLE")
			c++;
		if (h == "RE")
			d++;
	}
	cout << "AC x " <<a << endl;
	cout << "WA x " <<b << endl;
	cout << "TLE x "<< c << endl;
	cout << "RE x "<< d << endl;
	return 0;
}

Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  int c = 0;
  F0R(i, N) {
    int h;
    cin >> h;
    if (h >= K) c++;
  }
  cout << c;
}
#endif


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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

struct mint {
  ll v;
  mint() : v(0) {}
  mint(ll v) : v((v % MOD + MOD) % MOD) {}
  mint pow(ll t) const;
  mint inv() const;
};
mint& operator+=(mint& a, mint b) { return a = a.v + b.v; }
mint& operator-=(mint& a, mint b) { return a = a.v - b.v; }
mint& operator*=(mint& a, mint b) { return a = a.v * b.v; }
mint operator+(mint a, mint b) { return a += b; }
mint operator-(mint a, mint b) { return a -= b; }
mint operator*(mint a, mint b) { return a *= b; }
mint operator-(mint a) { return 0 - a; }
mint& operator/=(mint& a, mint b) { return a *= b.inv(); }
mint operator/(mint a, mint b) { return a /= b; }
mint mint::pow(ll t) const {
  if (!t) return 1;
  mint a = pow(t >> 1);
  a *= a;
  if (t & 1) a *= *this;
  return a;
}
mint mint::inv() const { return pow(MOD - 2); }
bool operator==(mint a, mint b) { return a.v == b.v; }
bool operator!=(mint a, mint b) { return a.v != b.v; }
istream& operator>>(istream& os, mint& a) { return (os >> a.v); }
ostream& operator<<(ostream& os, const mint& a) { return (os << a.v); }

mint dp[2][2002][2002];

void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> s(N), t(M);
  rep(i, N) cin >> s[i];
  rep(i, M) cin >> t[i];
  dp[0][0][0] = 1;
  rep(i, N + 1) rep(j, M + 1) {
    dp[0][i + 1][j] += dp[0][i][j];
    dp[1][i][j] += dp[0][i][j];
    dp[1][i][j + 1] += dp[1][i][j];
    if (i < N && j < M && s[i] == t[j]) {
      dp[0][i + 1][j + 1] += dp[1][i][j];
    }
  }
  cout << dp[1][N][M] << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 62848
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1e9+7
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
int main(){
	int n,k; cin >> n >> k;
	vector<int> dp(k+1); dp[0] = 1;
	for(int i = 0; i < n; i++){
		int c; cin >> c;
		vector<int> pfx(k+1);
		for(int cur = k; cur >= 0; cur--){
			int rb = min(k - cur, c);
			if(rb < 1) continue;
			(pfx[cur + 1] += dp[cur]) %= p;
			if(cur + rb + 1 <= k) (pfx[cur + rb + 1] -= dp[cur] - p) %= p;
		}
		for(int i = 1; i <= k; i++) (pfx[i] += pfx[i-1]) %= p, (dp[i] += pfx[i]) %= p;
	}
	cout << dp[k] << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

long long int gcd(long long int n, long long int m)
{
	if(m == 0) return n;
	else return gcd(m, n % m);
}

int main()
{
	int n;
	cin >> n;
	long long int ans = 1;
	for(int i = 0; i < n; i++){
		long long int t;
		cin >> t;
		ans = ans * (t / gcd(max(ans, t), min(ans, t)));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
H=list(map(int,input().split()))

dp=[0]*n
dp[1]=abs(H[1]-H[0])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
print(dp[-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    int n,k,c;
    cin>>n>>k>>c;
    string s;cin>>s;
    int i,j; 

    vector<int> L(k);
    vector<int> R(k);
    int cnt = c,ind = 0;
    for(i=0;i<n && ind<k;i++){
        if(s[i]=='o' && cnt>=c){
            L[ind++] = i+1;
            cnt = 0;
        }else{
            cnt++;
        }
    }
    cnt = c,ind = k-1;
    for(i=n-1;i>=0 && ind>=0;i--){
        if(s[i]=='o' && cnt>=c){
            R[ind--] = i+1;
            cnt = 0;
        }else{
            cnt++;
        }
    }
    
    for(i=0;i<k;i++){
        if(L[i]==R[i]) cout<<L[i]<<"\n";
    }

    return;
}

int main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3332
#include<cstdio>
using namespace std;
#define N 105
int as1=1e8,n,head[N],cnt,in[N],dep[N],a,b,s[N][2];
long long as2;
struct edge{int t,next;}ed[N*2];
void adde(int f,int t){ed[++cnt]=(edge){t,head[f]};head[f]=cnt;ed[++cnt]=(edge){f,head[t]};head[t]=cnt;in[f]++,in[t]++;}
void dfs(int u,int fa){dep[u]=dep[fa]+1;for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs(ed[i].t,u);}
void solve1(int x)
{
	dfs(x,0);
	int mxdep=0;long long as=1;
	for(int i=1;i<=n;i++)if(dep[i]>mxdep)mxdep=dep[i];
	for(int i=1;i<mxdep;i++)
	{
		int mx=1;
		for(int j=1;j<=n;j++)
		if(dep[j]==i&&mx<in[j]-1)mx=in[j]-1;
		if(i==1)mx++;
		as*=mx;
	}
	if(as1>mxdep||(as1==mxdep&&as2>as))as1=mxdep,as2=as;
}
void solve2(int x,int y)
{
	dep[y]=0;dfs(x,y);dep[x]=0;dfs(y,x);dep[x]=1;
	int mxdep=0;long long as=2;
	for(int i=1;i<=n;i++)if(dep[i]>mxdep)mxdep=dep[i];
	for(int i=1;i<mxdep;i++)
	{
		int mx=1;
		for(int j=1;j<=n;j++)
		if(dep[j]==i&&mx<in[j]-1)mx=in[j]-1;
		as*=mx;
	}
	if(as1>mxdep||(as1==mxdep&&as2>as))as1=mxdep,as2=as;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)scanf("%d%d",&s[i][0],&s[i][1]),adde(s[i][0],s[i][1]);
	for(int i=1;i<=n;i++)solve1(i);
	for(int i=1;i<n;i++)solve2(s[i][0],s[i][1]);
	printf("%d %lld\n",as1,as2);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t1,t2,a1,a2,b1,b2;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    if(a1>b1 and a2>b2){
        puta(0);
        return 0;
    }
    if(a1<b1 and a2<b2){
        puta(0);
        return 0;
    }

    ll da=t1*a1+t2*a2, db=t1*b1+t2*b2;
    if(da==db){
        puta("infinity");
        return 0;
    }
    if(a1>b1 and da>db){
        puta(0);
        return 0;
    }
    if(a1<b1 and da<db){
        puta(0);
        return 0;
    }
    if(b1>a1){
        ll r=t1*(b1-a1);
        ll d=da-db;
        ll ans=r/d;
        puta(ans*2 + (ans*d+t1*a1 != t1*b1));
    }else{
        ll r=t1*(a1-b1);
        ll d=db-da;
        ll ans=r/d;
        puta(ans*2 + (ans*d+t1*b1 != t1*a1));
    }

    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++)
int64_t MOD=998244353;
const long long INF = 1LL<<60;


int main() {
  int64_t N,X,M,countf=0,countr=0,RT=0,FT=0,ans=0;
  cin>>N>>X>>M;
  auto XX=X;
  queue<int64_t> R,F;
  vector<int64_t> C(M,0);
  while(true){
    if(C[X]==0){
      countf++;
      C[X]++;
    }
    else if(C[X]==1){
      R.push(X);
      C[X]++;
      RT+=X;
      countr++;
    }
    else if(C[X]==2){
      break;
    }
    X=(X*X)%M;
  }
  countf-=countr;
  rep(i,countf){
    FT+=XX;
    F.push(XX);
    XX=(XX*XX)%M;
  }
  if(N<=countf){
    rep(i,N){
      auto t=F.front();
      F.pop();
      ans+=t;
    }
  }
  else{
    N-=countf;
    auto rc=N/countr, a=N%countr;
    ans+=FT+RT*rc;
    rep(i,a){
      auto t=R.front();
      R.pop();
      ans+=t;
    }
  }
  cout<<ans;
}



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

int main() {
    ll l, r;
    cin >> l >> r;
    if (l / 2019 != r / 2019) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1001001001;
    for (ll i = l; i < r; ++i) {
        for (ll j = i + 1; j <= r; ++j) {
            ans = min(ans, (i % 2019) * (j % 2019) % 2019);
        }
    }
    cout << ans << endl;
}


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

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

using ll = long long;

ll dp[105][100005];

const long long INF = 1LL<<60;

int main() {
  ll N, W;
  cin >> N >> W;
  vector<vector<ll>> vv(N, vector<ll> (2));
  ll VM=0LL;
  for (ll i = 0LL; i < N; i++) {
    cin >> vv.at(i).at(0) >> vv.at(i).at(1);
    VM += vv.at(i).at(1);
  }
  for (ll i = 0; i < 105; i++) for (ll j = 0; j < 100005; j++) dp[i][j] = INF;
  for (ll i = 0; i<= vv.at(0).at(1); i++) {
    dp[0][i] = vv.at(0).at(0);
  }
  for (ll i = 0; i < N-1; i++) {
    for (ll j = 0; j <= VM; j++) {
      if (j - vv.at(i+1).at(1) <= 0) chmin(dp[i+1][j], min(dp[i][j], vv.at(i+1).at(0)));
      else {
        chmin(dp[i+1][j], min(dp[i][j], dp[i][j-vv.at(i+1).at(1)]+vv.at(i+1).at(0)));
      }
    }
  }
  ll ans = 0;
  while (dp[N-1][ans] <= W) ans++;
  cout << ans-1 << endl;
}

Measured memory_bytes: 82304
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
	int N; SCD(N);
	ll X = 0;
	ll Y = 0;
	ll ans = 0;

	REP(i,N){
		ll T,A;
		SCLLD2(T,A);
		ll n = max((X + (T - 1)) / T,(Y + (A - 1)) / A);
		if (n==0) ++n;
		ans += ((n * T) - X + (n * A) - Y);
		//printf("n = %lld, ans = %lld\n",n,ans);
		X = n * T;
		Y = n * A;

	}
	PRINTLLD(ans);
	return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<vector<int>> G(N);
	vector<P> E;
	rep(i,N-1){
		int a,b; cin >> a >> b; a--; b--; 
		G[b].push_back(a); G[a].push_back(b);	
		E.push_back(P(a,b));
	}

	int K=0;
	map<P,int> I;
	vector<int> cl(N);

	vector<int> used(N);
	queue<int> que;
	que.push(0);
	used[0]=1;
	while(!que.empty()){
		int v=que.front(); que.pop();
		if(K<(int)G[v].size())K=G[v].size();
		int cr = 1;
		for(int u : G[v]){
			if(used[u])continue;
			if(cr==cl[v])cr++;
			cl[u] = I[make_pair(u,v)] = I[make_pair(v,u)] = cr++;
			used[u] = 1;
			que.push(u);
		}
	}
	cout << K << endl;
	for(P u : E) cout << I[u] << endl;

	return 0;
}



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


int main() {
  std::string s = "";
  std::string t = "";
    cin >> s;
    cin >> t;
    int length_s = s.length();
    int length_t = t.length();
    int max_res = 0;
    int res = 0;

    for(int len = 0;length_s - length_t >= len ;len++){
      
      if(max_res < res){
        max_res = res;
      }
      res = 0;
     for(int len_t = 0; length_t > len_t; len_t++){
       
       if(s[len + len_t] == t[len_t]){
         res++;
       }
     }
    }
     if(max_res < res){
        max_res = res;
      }
    cout << length_t - max_res;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    cin >> s;
    if (s[0] >= 97) s[0] -= 32;
    cout << "A" << s[0] << "C";
}

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



typedef struct card
{
  char mark;
  int num;
}card;



/***** merge sort *****/
#define MAX 500000
#define INFINITY INT_MAX

card L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(card A[], int n, int left, int mid, int right)
{
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i = 0; i < n1; i++) L[i] = A[left + i];
  for(int i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1].num = R[n2].num = INFINITY;
  for(int i = 0, j = 0, k = left; k < right; k++)
  {
    cnt++;
    if(L[i].num <= R[j].num) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

void mergeSort(card A[], int n, int left, int right)
{
  if(left+1 < right)
  {
    int mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}



/***** quick sort *****/
int partition(card A[], int p, int r)
{
  int x = A[r].num;
  int i = p-1; // -1 ?

  for(int j = p; j < r; j++)
  {
    if(A[j].num <= x)
    {
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i+1;
}

void quickSort(card A[], int p, int r)
{
  if(p < r)
  {
    int q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
  }
}





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

  card A[100000];
  for(int i = 0; i < n; i++) cin >> A[i].mark >> A[i].num;

  card B[100000];
  for(int i = 0; i < n; i++) B[i] = A[i];

  //int q = partition(A, 0, n-1);
  quickSort(A, 0, n-1);
  mergeSort(B, n, 0, n);

  int isStable = 1;
  for(int i = 0; i < n; i++) if(A[i].mark != B[i].mark) isStable = 0;
  if(isStable == 0) cout << "Not stable" << endl;
  else cout << "Stable" << endl;

  for(int i = 0; i < n; i++) cout << A[i].mark << " " << A[i].num << endl;

  return 0;
}



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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

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


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

    int n;
    cin >> n;

    vector<int> a(n+1);
    rep(i, n){
        int x;
        cin >> x;

        a[i+1] = x;
    }

    int i = 1;
    int ans = 0;
    while(i != 2){
        i = a[i];
        ans++;
        if(ans > n) break;
    }

    if(ans > n){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

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

    auto judge = [&]() -> bool
    {
        unordered_set<string> S;
        string prev;
        for (int i = 0; i < N; ++i)
        {
            string word;
            cin >> word;

            if (S.count(word) > 0)
                return false;
            if (i > 0 and word.front() != prev.back())
                return false;
            
            S.insert(word);
            prev = word;
        }
        return true;
    };
    cout << (judge() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

struct edge {
    ll from, to, cost;
    edge() {}
    edge(ll f, ll t, ll c) {
        from = f; to = t; cost = c;
    } 
};

edge es[2000];

ll d[1000];
int V,E;

//s番目の頂点から各頂点への最短距離を求める
bool bellman_ford(int s){
    for (int i = 0; i < V; i++) d[i] = 1e18;
    d[s] = 0;
    int cnt = 0;
    for (int i = 0; i < V; i++) {
        cnt++;
        bool updated = false;
        for (int j = 0; j < E; j++) {
            edge &e = es[j];
            if (d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                if (i == V-1) return true;
                updated = true;
            }
        }
        if (!updated) return false;
    } 
}

int main() {

    cin >> V >> E; 
    for (int i = 0; i < E; i++) {
        ll a, b, c; cin >> a >> b >> c;
        es[i] = edge(a-1,b-1,-1 * c);
    }
    bool closed = bellman_ford(0);


    vector<bool> negative(V,false);
    for (int loop = 0; loop < V; loop++) {
        for (int i = 0; i < E; i++) {
            if (d[es[i].from] == 1e18) continue;
            if (d[es[i].to] > d[es[i].from] + es[i].cost) {
                d[es[i].to] = d[es[i].from] + es[i].cost;
                negative[es[i].to] = true;
            }
            if (negative[es[i].from]) negative[es[i].to] = true;
        }
    }

    if (negative[V-1]) {
        cout << "inf" << endl;
    } else {
        cout << -1*d[V-1] << endl;
    }








}


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

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

using namespace std;

const int INF = 2e9 + 7;

int pow(int a, int p) {
    int t = 1;
    for (int i = 0; i < p; i++) t *= a;
    return t;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> arr(m);
    for (int i = 0; i < m; i++) {
        cin >> arr[i].first >> arr[i].second;
        arr[i].first--;
    }
    for (int i = n == 1 ? 0 : pow(10, n - 1); i < pow(10, n); i++) {
        bool ok = true;
        string s = to_string(i);
        for (const auto &j : arr) {
            if (s[j.first] != (j.second + '0')) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << s;
            return 0;
        }
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 256
from collections import deque


N, Q = map(int, input().split())
t = [[] for i in range(N + 1)]

for i in range(N - 1):
    a, b = map(int, input().split())
    t[a].append(b)
    t[b].append(a)

score = [0] * (N + 1)
for i in range(Q):
    p, x = map(int, input().split())
    score[p] += x

is_read = [False] * (N + 1)
d = deque()
d.append(1)

while len(d) != 0:
    now = d.popleft()
    is_read[now] = True
    for c in t[now]:
        if is_read[c]:
            continue
        score[c] += score[now]
        d.append(c)
print(" ".join(map(str, score[1:])))


Measured memory_bytes: 146792
A = [[], [], []]
for i in range(3):
  A[i] = list(map(int, input().split())) 
N = int(input())
for i in range(N):
  x = int(input())
  for j in range(3):
    for i in range(3):
      if A[i][j] == x:
        A[i][j] = 0
ans = "No"
if A[0][0] == 0 and A[0][1] == 0 and A[0][2] == 0:
  ans = "Yes"
elif A[1][0] == 0 and A[1][1] == 0 and A[1][2] == 0:
  ans = "Yes"
elif A[2][0] == 0 and A[2][1] == 0 and A[2][2] == 0:
  ans = "Yes"
elif A[0][0] == 0 and A[1][0] == 0 and A[2][0] == 0:
  ans = "Yes"
elif A[0][1] == 0 and A[1][1] == 0 and A[2][1] == 0:
  ans = "Yes"
elif A[0][2] == 0 and A[1][2] == 0 and A[2][2] == 0:
  ans = "Yes"
elif A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
  ans = "Yes"
elif A[0][2] == 0 and A[1][1] == 0 and A[0][2] == 0:
  ans = "Yes"
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int mod = 1'000'000'007;

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

int mul(int a, int b) {
  return (int)((long long)a * b % mod);
}

int pw(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b /= 2;
  }
  return res;
}

const int N = 16;

int fac[1 << N];
int inv[1 << N];

int choose(int n, int k) {
  return mul(fac[n], mul(inv[k], inv[n - k]));
}

int a[N];
int f[1 << N];

int main() {
  fac[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < (1 << N); ++i) {
    fac[i] = mul(fac[i - 1], i);
    inv[i] = pw(fac[i], mod - 2);
  }
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d", a + i);
  }
  memset(f, 0, sizeof f);
  f[0] = 1;
  for (int i = m - 1; i >= 0; --i) {
    int tot = (1 << n) - a[i] + 1;
    for (int mask = (1 << n) - 1; mask >= 0; --mask) {
      int sum = 0;
      for (int j = 0; j < n; ++j) {
        if (mask >> j & 1) {
          sum += 1 << j;
        }
      }
      if (sum > tot) {
        continue;
      }
      for (int j = 0; j < n; ++j) {
        if (mask >> j & 1) {
          add(f[mask], mul(f[mask ^ 1 << j], mul(choose(tot - sum + (1 << j) - 1, (1 << j) - 1), fac[1 << j])));
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    int sum = 0, cnt = 0;
    for (int j = 0; j < n; ++j) {
      if (i >> j & 1) {
        sum += 1 << j;
        ++cnt;
      }
    }
    int cur = mul(f[i], mul(fac[(1 << n) - sum - 1], 1 << n));
    if (cnt % 2 == 0) {
      add(ans, cur);
    } else {
      add(ans, mod - cur);
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int K;
  cin >> K;

  REP(i, K) cout << "ACL";
  cout << "\n";

  return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dp[101010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, K; cin >> N >> K;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    fill(dp, dp+N, inf);
    dp[0] = 0;
    rep(i, N) REPS(k, 1, K) chmin(dp[i+k], dp[i] + abs(h[i+k] - h[i]));
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//constexpr long long MOD = 1e9 + 7;
//constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

bool compare_first(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.first != y.first) {
        return x.first < y.first;
    }
    else {
        return x.second < y.second;
    }
}

bool compare_second(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.second != y.second) {
        return x.second < y.second;
    }
    else {
        return x.first < y.first;
    }
}

struct {
    bool operator()(pair<string, int> x, pair<string, int> y) const
    {
        return x.second <= y.second && x.first < y.first;
    }
} compare_map;

const ll MAX = 500000000;
const ll MOD = 1000000007;

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

    string s;
    cin >> s;

    if (s.size() % 2 != 0) {
        cout << "No" << "\n";
        return 0;
    }

    for (int i = 0; i < s.size() - 1; i+=2)
    {
        if (s[i] != 'h' || s[i + 1] != 'i') {
            cout << "No" << "\n";
            return 0;
        }
    }

    cout << "Yes" << "\n";
    return 0;
}



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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) ((n)*(n))

using namespace std;
using ll = long long;

int main() {
    FAST;

    ll a, b;
    double bb;

    cin >> a >> bb;
    b = round(bb * 100);

    a *= b;
    a /= 100;
    
    cout << a;

    return 0;
}


Measured memory_bytes: 3792
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();

		long count = 0l;

		ArrayList<Integer> deque = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			deque.add(scan.nextInt());
		}

		Collections.sort(deque);

		if (n > k) {
			for (int i = 0; i < k; i++) {
				deque.remove(deque.size() - 1);
			}

			for (int i = 0; i < deque.size(); i++) {
				count += deque.get(i);
			}
		}

		System.out.println(count);
	}

}


Measured memory_bytes: 88408
import math
import itertools

n,m,q=map(int, input().split())
a=[list(map(int, input().split())) for _ in range(q)]

A = [i for i in range(1,m+1)]
sum = 0

for k in itertools.combinations_with_replacement(A,n):
  sum_tmp = 0
  for i in range(q):
    if k[a[i][1] - 1] - k[a[i][0] - 1] == a[i][2]:
        sum_tmp += a[i][3]
  
  if sum_tmp > sum:
    sum = sum_tmp

print(sum)

Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  string s;
  ll w;
  cin >> s >> w;
  for (ll i = 0; i < s.size(); i += w) {
    cout << s[i];
  }
  cout << endl;
}

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

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	ll MAX=max({a,b,c});
	if( (3*MAX -a -b -c)%2==0){
		cout << (3*MAX-a-b-c)/2;
	}
	else{
		cout << (3*MAX -a-b-c)/2+2;
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 小さい方をリターンする関数
# dpに使う
def chmin(a,b):
    if a>b:
        return b
    else:
        return a

# 小さい方をリターンする関数
# dpに使う
def chmax(a,b):
    if a<b:
        return b
    else:
        return a

N,K = map(int,input().split())
h = list(map(int,input().split()))

f_inf = float("inf")
dp = [f_inf]*N
dp[0] = 0

for i in range(1,N):
    for j in range(1,K+1):
        dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
        if i-j == 0:
            break

print(dp[N-1])



Measured memory_bytes: 55008
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int range = scan.nextInt();
		

		final String NO = "No";
		final String YES = "Yes";
		String com = NO;

		if(Math.abs(a - c) <= range){	
			com = YES;
		}

		if(Math.abs(a - b) <= range &&
		   Math.abs(b - c) <= range){
			com = YES;
		}

		System.out.println(com);
	}
}	

Measured memory_bytes: 23764
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll a, b;
    cin >> a >> b;
    if (a == b) {
        cout << 0 << endl;
    }
    else if ( ( a + b ) % 2 == 0) {
        cout << (a + b) / 2 << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
   int n,i;
   double s[1000],sum1,m,sum2,a;
   while(1){
       cin >> n;
       if(n == 0)break;
       sum1 = 0;
       for(i = 0; i < n; i++){
           cin >> s[i];
           sum1 += s[i];
       }
       m = sum1/(double)n;
       sum2 = 0;
       for(i = 0;i < n; i++){
        sum2 += (pow(s[i] - m,2));  
       }
       a = sqrt(sum2/n);                                                 
    cout << fixed << setprecision(8) << a << endl; 
   }
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> task[100001];
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        task[a].push_back(b);
    }
    int64_t ans = 0;
    priority_queue<int> que;
    for(int i=1; i<=M; i++){
        for(int a : task[i]) que.push(a);
        if(que.size()){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5632
from collections import Counter

def parse_line(line, type=int):
	return [type(x) for x in line.split(' ')]

def main():
	n, m = parse_line(input())
	counter = Counter()
	for _ in range(n):
		k_choices = parse_line(input())
		choices = k_choices[1:]
		for choice in choices:
			counter[choice] += 1
	print(len([x for x in counter.values() if x == n]))


	

if __name__ == '__main__':
	main()



Measured memory_bytes: 3316
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e5 + 5;

ll a, b, c;

int main() {
	

    cin >> a >> b >> c;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
    	cout << 0;
    	return 0;
    }
    cout << min(a, min(b, c)) * ((a + b + c) - min(a, min(b, c)) - max(a, max(b, c)));    
    return 0;
}


Measured memory_bytes: 256
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
#define N (ll)(1e6+3)
#define INF (ll)(1e18+3)
#define MOD (ll)(1e9+7)
 
#define ll long long
#define rep(i,a,n) for(ll i = a; i < n; i++)
#define per(i,a,n) for(ll i = n-1; i >= a; i--)
 
//using namespace __gnu_pbds;
using namespace std;
 
// typedef
// tree<
//     pair<ll,ll>,
//     null_type,
//     less<pair<ll,ll>>,
//     rb_tree_tag,
//     tree_order_statistics_node_update>
// ordered_set;
 
 
ll n, m;
ll cnt[N], dp[N];
ll a[N];

void solve() {
    cin >> n >> m;
    rep(i,0,n) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    rep(i,1,n+1) {
        ll l = max(0LL,i-cnt[i]+1);
        rep(j,l,i+1)
            dp[j]++;
    }
    ll ans = 0;
    rep(i,1,n+1) {
        ans += !dp[i];
    }
    rep(i,0,m) {
        ll x, y; cin >> x >> y; x--;

        ll del = a[x]-cnt[a[x]]+1;
        cnt[a[x]]--;
        if (del > 0) {
            dp[del]--;
            if (dp[del] == 0)
                ans++;
        }
        ll add = y-cnt[y];
        cnt[y]++;
        if (add > 0) {
            dp[add]++;
            if (dp[add] == 1)
                ans--;
        }
        a[x] = y;
        cout << ans << endl;
    }
}
 
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 11264
import java.util.Scanner;
public class Main{
    int a;//在庫  
    int b=1;//添え字（回数）
    int c;//添え字
    int n;//種類
  
    public void solve(){
        Scanner sc=new Scanner(System.in);
        n = sc.nextInt();
       
        while(n!=0){
         for(int i=0;i<n;i++){
             a = sc.nextInt();
             if(a>=2){
                 b+=1; 
             } else if(a==1){
                 c+=1;
             }
         }    
        if(b>=2){
          System.out.println(b+c);
        }else{
             System.out.println("NA"); 
        }  
        b=1;
        c=0;
       n = sc.nextInt();
      }         
  }
    
    public static void main(String[] args){
      Main obj=new Main();
        obj.solve();
    }
}

Measured memory_bytes: 158552