akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    vector<int> vec(3);
    for (int i = 0; i < 3; ++i) {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    int els = unique(vec.begin(), vec.end()) - vec.begin();
    if (els == 2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#include <numeric>
#include <stdio.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    cin >> n;
    int x[n];
    ll INF = 1001002003004005006ll;
    for(int i=0; i<n; i++) {
        cin >> x[i];
    }
    ll sum;
    sum = 0;
    for(int i = 1; i < 101; i++) {
        sum = 0;
        for(int j=0;j<n;j++) {
            sum += (x[j] - i) * (x[j] - i);
        }
        INF = min(INF, sum);
    }
    cout << INF << endl;


    
}

Measured memory_bytes: 256
from collections import defaultdict
from collections import OrderedDict

N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k] += 1
    else:
        ans.update({k: 1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)

Measured memory_bytes: 45268
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H,W, N;
    cin >> H >> W >> N;
    auto T = max(H, W);
    int add = 0;
    if (N % T != 0)
        add = 1;
    int ans = N / T + add;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=6000;
const ll mod=998244353;
const int LG=26;


ll C[MX], mp[MX], cn, k;

vector<int>g[MX];

ll cycle[MX];
ll mx=-1e18;

void dfs(int x, int c)
{
    if(c>k) return;

    if(mp[x])
    {
        cn+=C[x];
        int need=k-c;
        int cyc=c-mp[x];
        ll how=need/cyc;
        ll csm=cn-cycle[mp[x]];


        if(csm>0) cn+=how*csm, mx=max(mx, cn);

        int r=need-how*cyc;

        for(int i=mp[x]+1, j=0; j<r; j++, i++)
        {
            cn+=cycle[i]-cycle[i-1];
            mx=max(mx, cn);
        }
        return;
    }

    mp[x]=c; cn+=C[x];

    mx=max(mx, cn);

    cycle[c]=cn;

    for(auto u:g[x])
    {
        dfs(u, c+1);
    }
}

int main()
{
    FasterIO;

    int n;

    cin>>n>>k;

    for(int i=1; i<=n; i++)
    {
        int x; cin>>x; g[i].push_back(x);
    }

    for(int i=1; i<=n; i++) cin>>C[i];



    for(int i=1; i<=n; i++)
    {
        mem(mp, 0);
        mem(cycle, 0);
        cn=0;


        if(g[i][0]==i)
        {
            cn=C[i]*k;
            mx=max(mx, cn);
            mx=max(mx, C[i]);
            continue;
        }



        dfs(i, 1);
    }

    cout<<mx<<endl;

    return 0;
}


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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ll t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define nl cout<<endl
#define P 1000000007
#define MOD(x) ((x%P)+P)%P

int main()
{

    
            int s;
      cin>>s;
 
      int a = s%100;
      int b =s/100;
 
      if(a<=12 && a>= 1)
      {
            if(b>=1 && b<=12)
                  cout<<"AMBIGUOUS";
            else if(b>12 || b == 0)
                  cout<<"YYMM";
              else
              	cout<<"NA";
      }
      else if(a == 0 || a>12)
      {
            if(b>=1 && b<=12)
                  cout<<"MMYY";
            else
                  cout<<"NA";
      }

      else
      {
      	cout<<"NA";
      }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(ll i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 998244353ll;
const dou pi=3.141592653589793*2;

int main(){
    int k;
    std::cin >> k;
    string s;
    std::cin >> s;
    if(s.size()<=k){
        std::cout << s << std::endl;
    }
    else{
        std::cout << s.substr(0,k)<<"..." << std::endl;
    }
}

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

int N;
int A[100000];

int main() {
  cin >> N;
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A, A + N);
  int k = lower_bound(A, A + N, A[N - 1] / 2) - A;
  int res;
  if(k == N - 1) res = A[k - 1];
  else if(k > 0 && A[N - 1] / 2 - A[k - 1] < A[k] - A[N - 1] / 2) {
    res = A[k - 1];
  } else {
    res = A[k];
  }
  cout << A[N - 1] << " " << res << endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
char s[101];
int main(){
    scanf("%s",s);
    int n=strlen(s);
    int count=0;
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n-1-i])count++;
    }
    printf("%d\n",count);
}

Measured memory_bytes: 128
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll d[100100][2];

int main(){
  clr(d,0);
  ll n,m;
  cin>>n>>m;
  rep(i,0,m){
    ll a;
    string s;
    cin>>a>>s;
    if(s=="AC"){
      d[a][0]++;
    }
    else{
      if(d[a][0]==0){
        d[a][1]++;
      }
    }
  }
  ll ans1 = 0;
  ll ans2 = 0;
  rep(i,0,100100){
    if(d[i][0]>0)ans1++;
    if(d[i][0]>0){
      ans2 += d[i][1];
    }
  }
  cout << ans1 << " " << ans2 << endl;
  return 0;
}

Measured memory_bytes: 1920
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INF 1<<29
#define R 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}

#pragma endregion 

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

	int n, q;
	st s;
	cin >> n >> q >> s;
	vi l(q), r(q);
	f_v2I(l, r, q);
	vi sum(n + 1);
	sum[0] = 0;
	f(i, 0, n) {
		if (s[i] == 'A'&&s[i + 1] == 'C') {
			sum[i + 1] = sum[i] + 1;
		}
		else {
			sum[i + 1] = sum[i];
		}
	}
	f(i, 0, q) {
		cout << sum[r[i] - 1] - sum[l[i] - 1] << endl;
	}
	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
ll a[300010];
ll cmax[300010];
ll cmin[300010];

#define error(args...) { vector<string> _debug = split(#args, ',');err(begin(_debug), args);}

vector<string> split(const string& s, char c){
	vector<string> v;stringstream ss(s);string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {cerr << endl;}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a,Args... args){
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << " ",err(++it, args...);
}


int main(void){
	int n;
	cin >> n;
	rep(i,3*n) cin >> a[i];

	{
		ll cur = 0LL;
		priority_queue<ll,vector<ll>,greater<ll>> q;

		rep(i,3*n){
			cur += a[i];
			q.push(a[i]);

			if(q.size()>n){
				cur -=q.top();
				q.pop();
			}
			//error(i,cur);
			if(q.size()==n) cmax[i]=cur;
		}
	}

	{
		ll cur = 0LL;
		priority_queue<ll> q;

		rrep(i,3*n){
			cur += a[i];
			q.push(a[i]);

			if(q.size()>n){
				cur -=q.top();
				q.pop();
			}

			if(q.size()==n) cmin[i]=cur;
		}
	}

	ll ans = cmax[n-1]-cmin[n];
	rep(i,n-1,2*n){
		//error(i,cmax[i],cmin[i+1]);
		chmax(ans,cmax[i]-cmin[i+1]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8676
from functools import reduce
from fractions import gcd
import math


def least_common_multiple(iter):
    '''
    最小公倍数を返す
    '''
    lcm = lambda x, y: x*y//gcd(x, y)
    return reduce(lcm, iter)


N, M = map(int, input().split())
A = list(map(int, input().split()))
l = least_common_multiple(map(lambda x: x//2, A))

div_num = 0
num = A[0]
flag = False
while num % 2 == 0:
    num = num // 2
    div_num += 1
for a in A:
    cnt = 0
    while a % 2 == 0:
        a = a // 2
        cnt += 1
    if div_num != cnt:
        flag = True

baisuu = M // l
if flag:
    print(0)
elif baisuu & 1:
    print((baisuu + 1)//2)
else:
    print(baisuu//2)


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

void solve() {
	int n;
	cin >> n;
	int s;
	cin >> s;
	vector<int> a(n);
	for (auto &x: a)
		cin >> x;
	sort(a.begin(), a.end());
	int cnt = 0;
	for (auto &x: a)
		if (s >= x) {
			cnt++;
			s -= x;
		}
	if (cnt == n && s > 0)
		cnt--;
	cout << cnt;
}

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


Measured memory_bytes: 256
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    For(i,n) for(int i=0;i<n;i++)
#define    rFor(i,n) for(int i=n-1;i>=0;i--)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    all(v) v.begin(),v.end()
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    test  int tt;cin>>tt;for(int ii=0;ii<tt;ii++)
#define    min3(a,b,c)     min(a,min(b,c))
#define    max3(a,b,c)     max(a,max(b,c))
#define    min4(a,b,c,d)   min(min(a,b),min(c,d))
#define    max4(a,b,c,d)   max(max(a,b),max(c,d))
#define    Max(a)  *max_element(a,a+sizeof(a)/sizeof(a[0]))
#define    Min(a)  *min_element(a,a+sizeof(a)/sizeof(a[0]))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long 
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//
int main()
{
MP;
    //test
    {
        int n;
        cin>>n;
        string s="ACL";
        For(i,n)cout<<s;
    }
    
End;
}


Measured memory_bytes: 3652
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;

ll A[110];
ll dp[110][21];

int main()
{
	int N; cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];
	
	dp[0][A[0]] = 1;
	for (int i = 1; i < N - 1; i++) {
		for (int j = 0; j <= 20; j++) {
			if (dp[i - 1][j] == 0) continue;
			if (j - A[i] >= 0)dp[i][j - A[i]] += dp[i - 1][j];
			if (j + A[i] <= 20)dp[i][j + A[i]] += dp[i - 1][j];
		}
	}
	cout << dp[N - 2][A[N - 1]] << endl;
	return 0;
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define int long long
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
const int mod=1e9+7;
int dp[5001][5001],f[10001],g[10001],siz[10001],head[100001],cnt;
struct node {
	int to,next;
}a[100001];
void add(int x,int y){
	a[++cnt].next=head[x];
	a[cnt].to=y;
	head[x]=cnt;
}
void dfs(int x,int fa){
    siz[x]=1;
    dp[x][1]=1;
    for(int i=head[x];i;i=a[i].next){
        int v=a[i].to;
        if(v==fa) continue;
        dfs(v,x);
        for(int j=0;j<=siz[x];j++)
            g[j]=dp[x][j],dp[x][j]=0;
        for(int j=0;j<=siz[x];j++)
            for(int k=0;k<=siz[v];k++)
                dp[x][j+k]+=g[j]*dp[v][k]%mod,dp[x][j+k]%=mod;
        siz[x]+=siz[v];
    }
    for(int i=0;i<=siz[x];i+=2)
        dp[x][0]=(dp[x][0]-dp[x][i]*f[i]%mod+mod)%mod;
}
main(){
	int n=read(),x,y;
    for(int i=1;i<n;i++)
		x=read(),y=read(),add(x,y),add(y,x);
    f[0]=1;
    for(int i=2;i<=n;i+=2)
        f[i]=f[i-2]*(i-1)%mod;
    dfs(1,0);
    printf("%lld",mod-dp[1][0]);
}

Measured memory_bytes: 196096
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    static int BinSearchIndex(int v, int[] list)
    {
        int minRange = 0;
        int maxRange = list.Count();
        while (minRange != maxRange)
        {
            var center = (minRange + maxRange) / 2;
            if (list[center] < v)
            {
                minRange = center + 1;
            }
            else
            {
                maxRange = center;
            }
        }

        return minRange;
    }

    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var L = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(x => x).ToArray();

        long pattern = 0;
        for (int i = 0; i < L.Length; i++)
        {
            for (int j = i + 1; j < L.Length; j++)
            {
                var a = L[i];
                var b = L[j];
                var min = Math.Max(a - b, b - a);
                var max = a + b;

                var left = BinSearchIndex(min, L);
                while (left < N && L[left] <= min)
                {
                    left++;
                }
                left = Math.Max(left, j + 1);
                var right = BinSearchIndex(max, L);
                while (0 <= right && right < N && L[right] >= max)
                {
                    right--;
                }
                if (right == N)
                {
                    right--;
                }

                var count = Math.Max(right - left + 1, 0);
                pattern += count;
            }
        }

        Console.WriteLine(pattern);
    }
}

Measured memory_bytes: 13416
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    char s[200005],t[200005];
    ll n;
    scanf("%s%s",s,t);
    n= strlen(s);
    ll cnts[26]={},cntt[26]={};
    rep(i,0,n){
        cnts[(ll)s[i]-97]++;
        cntt[(ll)t[i]-97]++;
    }
    sortup(cnts,26);
    sortup(cntt,26);
    rep(i,0,26){
        if(cnts[i]!=cntt[i]){
            NO;
            return 0;
        }
    }
    YES;
    return 0;
}


Measured memory_bytes: 512
N, Y = gets.split.map(&:to_i)
test = -> do
  0.step N do |i|
    y = Y
    m = N - i
    y -= i * 10000
    0.step m do |j|
      yy = y
      k = m - j
      yy -= j * 5000
      yy -= k * 1000
      return "#{i} #{j} #{k}" if yy == 0
    end
  end
  '-1 -1 -1'
end
puts test.()

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    vector<string> W(n);
    unordered_map<string, int> m;
    bool ans = true;
    rep(i, n) {
        cin >> W[i];
        if(m[W[i]] != 1) m[W[i]] = 1;
        else ans = false;
    }
    
    rrep(i, n - 1) {
        if(*W[i].begin() != *(W[i - 1].end() - 1)) {
            ans = false;
            break;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 9;
const int AL = 26;

int nxt[AL];

int dp[N];
int let[N];
int pos[N];

int main(){
    fastIO;
    string t;
    cin >> t;
    int n = t.size();
    for(int i = 0 ; i < AL; i ++ )
        nxt[i] = n+1;
    for(int i = 0 ; i < N; i ++ ){
        dp[i] = n + 12412;
        let[i] = -1;
        pos[i] = i;
    }
    int f;
    dp[n]=1;
    dp[n+1]=0;
    for(int i = n - 1; i >= 0 ; i -- ){
        f = t[i] - 'a';
        nxt[f] = i + 1;
        for(int j = 0 ; j < AL; j ++ ){
            if(dp[nxt[j]] + 1 < dp[i]){
                dp[i] = dp[nxt[j]] + 1;
                pos[i] = nxt[j];
                let[i] = j;
            }
        }
    }
    int p = 0;
    while(p < n){
        cout << char('a'+let[p]);
        p = pos[p];
    }
    return 0;
}

Measured memory_bytes: 2964
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := readInt()
	ans := make(map[int]bool, n)
	for i := 0; i < n; i++ {
		a := readInt()
		if _, ok := ans[a]; ok {
			delete(ans, a)
			continue
		}
		ans[a] = true
	}
	fmt.Println(len(ans))
}


Measured memory_bytes: 3968
#include <stdio.h>
int main()
{
    int num[10010],i;
    for(i=1;i<10010;i++)
    {
    	scanf("%d",&num[i]);
		if(num[i]==0)
		break;
	}
	for(int i=1;i<10010;i++)
    {
     	if(num[i]==0)
    	break;
    	printf("Case %d: %d\n",i,num[i]);
	}
    return 0;
}


Measured memory_bytes: 2028
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;

long long a[100000];
int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
	}
	int count0 = 0, count1 = 0, count2 = 0;
	for (int i = 0; i < N; i++) {
		if (a[i] % 4 == 0) {
			count2++;
		}
		else if (a[i] % 2 == 0) {
			count1++;
		}
		else if (a[i] % 2 == 1) {
			count0++;
		}
	}
	//printf("%d %d %d\n", count0, count1, count2);
	if (count1 > 0) {
		count0 += 1;
	}
	//printf("%d %d %d\n", count0, count1, count2);
	if (count2 + 1 >= count0) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 896
//dp[i][k] i位mod13=k 的 
#include<cstdio>
#include<cstring>

using namespace std;

const int mod=1e9+7;
#define N 100003

char s[N]; 

int dp[N][13];

int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	int bit=1;
	if(s[n]=='?') 
		for(int i=0;i<10;++i) dp[n][i]=1;
	else dp[n][s[n]-'0']=1; 
	int k;
	for(int i=n-1;i;i--)
	{ 
		bit=1LL*bit*10%13;
		if(s[i]!='?')
		{
			k=1LL*(s[i]-'0')*bit%13;
			for(int j=0;j<13;++j)
			{
				dp[i][(k+j)%13]+=dp[i+1][j];
				dp[i][(k+j)%13]%=mod;
			//	if(dp[1][5]) printf("\n%d\n",j);
			}
			
		}
		else
		{
			for(int j=0;j<10;++j)
			{
				k=1LL*j*bit%13;
				for(int p=0;p<13;++p)
				{
					dp[i][(k+p)%13]+=dp[i+1][p];
					dp[i][(k+p)%13]%=mod;
				}
			//	if(dp[2][7]) printf("\n%d\n",j);
			}
		}
	}
	printf("%d",dp[1][5]);	
} 

Measured memory_bytes: 5376
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/



int main() {
	lint MOD = 1000000007;
	int N, M;
	cin >> N >> M;
	vector<int>a(M);
	for (int i = 0; i < M; i++) {
		cin >> a[i];
	}
	vector<int>C(N+1);
	for (int i = 0; i < M; i++) {
		C[a[i]]++;
	}
	vector<lint>dp(N+1);
	dp[0] = 1;
	if (C[1] == 0) dp[1] = 1;
	if (C[1] == 1) dp[1] = 0;
	for (int i = 2; i < N+1; i++) {
		if (C[i] == 0) {
			dp[i] = (dp[i - 1] + dp[i - 2])%MOD;
		}
		else C[i] = 0;
	}
		cout << dp[N] << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int vis[15];
char s1[15];
int n;
int num;
void dfs(int x,char y)
{
	s1[x-1]=y;
	if(x==n)
	{
		puts(s1);
		return ;
	}
	for(int i=0;i<=x;i++)
	{
		if(!vis[i] && !vis[i-1])
		{
			break;
		}
		vis[i]++;
		dfs(x+1,'a'+i);
		vis[i]--;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		s1[i]='a';
	}
	vis[0]=1;
	dfs(1,'a');
	return 0;
}

Measured memory_bytes: 1536
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int ans = 0;
    
    if(400<=x && x <= 599){
      ans = 8;
    }else if(600<=x && x <= 799){
      ans = 7;
    }else if(800<=x && x <= 999){
      ans = 6;
    }else if(1000<=x && x <= 1199){
      ans = 5;
    }else if(1200<=x && x <= 1399){
      ans = 4;
    }else if(1400<=x && x <= 1599){
      ans = 3;
    }else if(1600<=x && x <= 1799){
      ans = 2;
    }else if(1800<=x && x <= 1999){
      ans = 1;
    }
    
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 35840
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    string N = readln.chomp;
    writeln(N[0] == N[2] ? "Yes" : "No");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
import collections

N = int(input())
L = [int(i) for i in input().split()]
M = max(L)
c = collections.Counter(L)
li = [c[i] for i in range(M+1)]

ans = 0
for i in range(1,M+1):
    for j in range(i,M+1):
        if i == j:
            ans += int(li[i] * (li[i] - 1) * (li[i] - 2) / 6)
            ans += int(sum(li[j+1:min(M+1, i+j)]) * li[i] * (li[i] - 1) / 2)
        else:
            ans += int(li[i] * li[j] * (li[j] - 1) / 2)
            ans += li[i] * li[j] * sum(li[j+1:min(M+1, i+j)])
print(int(ans))


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    ll a[n];
    rep(i, 0, n) cin >> a[i];
    ll sum[n + 1] = {};
    rep(i, 0, n) {
        sum[i + 1] = sum[i] + a[i];
    }

    map<ll, ll> mp;
    rep(i, 0, n + 1) mp[sum[i] % m]++;
    ll ans = 0;
    for (auto i : mp) {
        ans += i.second * (i.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int h1,h2,k1,k2,a,b,c,d;
    cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;

    int hiroshi,kenjiro;

    hiroshi=h1*a+(h1/10)*c+h2*b+(h2/20)*d;

    kenjiro=k1*a+(k1/10)*c+k2*b+(k2/20)*d;

    if(hiroshi<kenjiro){
        cout << "kenjiro" << endl;
    }

    else if(hiroshi>kenjiro){
        cout << "hiroshi" << endl;
    }

    else{
        cout << "even" << endl;
    }

    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    int A,B,C,K;
    cin >> A >> B >> C;
    cin >> K;
    int min = 0;
    while(A >= B){
        B <<= 1;
        min++;
    }
    while(B >= C){
        C <<= 1;
        min++;
    }
    if(min<=K){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3620
parseInt(x) = parse(Int, x)

function main()
	n,k = parseInt.(split(readline()))
	a = readline() |> split |> x->parseInt.(x)
	a = sort(a)
	s = Int[]
	count = 1
	for i in 2:n
		if a[i] != a[i-1]
			push!(s, count)
			count = 1
		else
			count += 1
		end
	end
	if count != 0 || a[n] != a[n-1]
		push!(s, count)
	end
	s = sort(s)
	sum = 0
	if length(s) > k
		for i in 1:length(s)-k
			sum += s[i]
		end
	end
	print(sum)
end

main()

Measured memory_bytes: 174056
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int n; cin >> n;
	int n_copy = n;
	vector<int> v(3);
	v[0] = n % 10;
	n /= 10;
	v[1] = n % 10;
	n /= 10;
	v[2] = n % 10;
	if ((100 * v[0] + 10 * v[1] + v[2]) == n_copy) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3612
import fractions
from functools import reduce

N, M = map(int, input().split())
a = list(map(int, input().split()))

def f(x):
    res = 0
    while x % 2 == 0:
        x //= 2
        res += 1
    return res  

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  

for i in range(len(a)):
    if a[i] % 2 == 1:
        print(0)
        exit()
    a[i] //= 2

t = f(a[0])
for i in range(len(a)):
    if f(a[i]) != t:
        print(0)
        exit()
    a[i] >>= t #a[i] //= 2 ** t
M >>= t

l = 1
for i in range(N):
    l = lcm(l, a[i])
    if l > M:
        print(0)
        exit()

M //= l
ans = (M+1) // 2
print(ans)

Measured memory_bytes: 16296
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] array= new int[n];
		int[] x = new int[m];
		int[] y = new int[m];
		for(int i = 0; i<n; i++){
			array[i]=sc.nextInt()-1;
		}
		Unionfind uf = new Unionfind(n);
		for(int i = 0; i<m; i++){
			x[i]=sc.nextInt()-1;
			y[i]=sc.nextInt()-1;
			uf.unite(x[i],y[i]);
		}
		int count=0;
		for(int i = 0; i<n; i++){
			if(uf.same(i,array[i])){
				count++;
			}
		}
		System.out.println(count);
	}
	static class Unionfind{
		int[] parent;
		public Unionfind(int n){
			this.parent=new int[n];
			for(int i = 0; i<n; i++){
				parent[i]=i;
			}
		}
		public int root(int t){
			if(parent[t]==t){
				return t;
			}else{
				return parent[t]=root(parent[t]);
			}
		}
		public void unite(int x,int y){
			if(same(x,y)){
				return;
			}
			int xroot = root(x);
			int yroot = root(y);
			parent[yroot]=xroot;
		}
		public boolean same(int x,int y){
			return root(x)==root(y);
		}
	}
}

Measured memory_bytes: 89556
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    if(max(a,c)-min(a,c) <= d) cout << "Yes" << endl;
    else if(max(a,b)-min(a,b) <= d &&max(b,c)-min(b,c) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
//#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<queue>
//#include<time.h>
//#include<complex>
#include<algorithm>
#include<stdlib.h>
using namespace std;

int n,m;
#define maxn 222
#define maxm 100011
struct Edge{int from,to,next,cap,flow;};
const int inf=0x7fffffff;
struct Network
{
    Edge edge[maxm];int n,s,t,le;
    int first[maxn],dis[maxn],cur[maxn];
    void clear(int n)
    {
        memset(first,0,sizeof(first));
        le=2;this->n=n;
    }
    void add_edge(int x,int y,int v)
    {
        Edge &e=edge[le];
        e.to=y;e.from=x;
        e.cap=v;e.flow=0;
        e.next=first[x];
        first[x]=le++;
    }
    void insert(int x,int y,int v)
    {
        add_edge(x,y,v);
        add_edge(y,x,0);
    }
    int que[maxn],head,tail;
    bool bfs()
    {
        memset(dis,0,sizeof(dis));
        dis[s]=1;
        que[head=(tail=1)-1]=s;
        while (head!=tail)
        {
            const int x=que[head++];
            for (int i=first[x];i;i=edge[i].next)
            {
                Edge &e=edge[i];
                if (e.cap>e.flow && !dis[e.to])
                {
                    dis[e.to]=dis[x]+1;
                    que[tail++]=e.to;
                }
            }
        }
        return dis[t];
    }
    int dfs(int x,int a)
    {
        if (x==t || !a) return a;
        int flow=0,f;
        for (int &i=cur[x];i;i=edge[i].next)
        {
            Edge &e=edge[i];
            if (dis[e.to]==dis[x]+1 && (f=dfs(e.to,min(a,e.cap-e.flow)))>0)
            {
                flow+=f;
                a-=f;
                e.flow+=f;
                edge[i^1].flow-=f;
                if (!a) break;
            }
        }
        return flow;
    }
    int Dinic(int s,int t)
    {
        this->s=s;this->t=t;
        int ans=0;
        while (bfs())
        {
            for (int i=1;i<=n;i++) cur[i]=first[i];
            ans+=dfs(s,inf);
        }
        return ans;
    }
}g;

int a[maxn],b[maxn],c[maxn],d[maxn];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	for (int i=1;i<=n;i++) scanf("%d%d",&c[i],&d[i]);
	int s=n*2+1,t=s+1; g.clear(t);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (a[i]<c[j] && b[i]<d[j]) g.insert(i,j+n,1);
	for (int i=1;i<=n;i++) g.insert(s,i,1),g.insert(i+n,t,1);
	printf("%d\n",g.Dinic(s,t));
	return 0;
}

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

int main(){
	string in;
	getline(cin, in);

	for(int i = 0; i < in.size() - 4; i++){
		if(in[i] == 'a' && in[i+1] == 'p' && in[i+2] == 'p' && in[i+3] == 'l' && in[i+4] == 'e'){
			in[i] = 'p';
			in[i+1] = 'e';
			in[i+2] = 'a';
			in[i+3] = 'c';
			in[i+4] = 'h';
		}else if(in[i] == 'p' && in[i+1] == 'e' && in[i+2] == 'a' && in[i+3] == 'c' && in[i+4] == 'h'){
			in[i] = 'a';
			in[i+1] = 'p';
			in[i+2] = 'p';
			in[i+3] = 'l';
			in[i+4] = 'e';
		}
	}

	cout << in << endl;

	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while(t--){
    ll n,m,a,b;
    cin >> n >> m >> a >> b;
    cout << floor_sum(n,m,a,b) << '\n';
  }
  return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff first
#define INF 1000000001
#define inf1 1000000000000000001
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 300000+5;
const lli mod= 1000000007;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli digit(lli n){int res=(int)log10(n)+1;return res;}
lli lcm(lli a,lli b){lli ans=(a*b)/(__gcd(a,b));return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}

lli inf = 5e17;
///=================== ALWAYS CHECK 1 or 0 base case=================================================================================///
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------//


void solve()
{
    int n;cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    reverse(b,b+n);
    int l=0,r=n-1;
    for(int i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            if(b[l]!=b[i] and a[l]!=b[i])
            {
                swap(b[i],b[l]);
                l++;
            }
            else if(b[r]!=b[i] and a[r]!=b[i])
            {
                swap(b[i],b[r]);r--;
            }
            else
            {
                cout<<"No\n";return;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            cout<<"No\n";return;
        }
    }
    cout<<"Yes\n";
    for(int i=0;i<n;i++)cout<<b[i]<<" ";
    cout<<endl;

}
int main()
{
    solve();
}


Measured memory_bytes: 5240
import java.util.*;

public class Main {
    public static void main(String[] args)  {

        Scanner sc = new Scanner(System.in);

        int H = sc.nextInt();
        int W = sc.nextInt();
        int N = sc.nextInt();
        int[] A = new int[N];

        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve(H, W, N, A));
    }

    private static String solve(int H, int W, int N, int[] A) {
        List<Integer> numbers = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int n = i + 1;
            int a = A[i];
            for (int j = 0; j < a; j++) {
                numbers.add(n);
            }

        }

        StringJoiner j = new StringJoiner("\n");
        for (int h = 0; h < H; h++) {
            int start = h*W;
            int end = h*W + W;

            List<Integer> line = new ArrayList<>(numbers.subList(start, end));
            if(h % 2 == 1) {
                Collections.reverse(line);
            }

            StringJoiner j2 = new StringJoiner(" ");
            line.forEach( i -> j2.add(i.toString()));

            j.add(j2.toString());
        }

        return j.toString();
    }
}


Measured memory_bytes: 35620
K=gets.to_i
A=gets.split.map &:to_i

min=2
max=2

A.reverse.map{|a|
	if (min-1)/a*a+a<=max
		min=(min-1)/a*a+a
		max=max/a*a+a-1
	else
		puts -1
		exit
	end
}

puts [min,max]*" "


Measured memory_bytes: 10116
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  long long a,b,v,w,t;
  cin >> a >> v >> b >> w >> t;
  if(v>w&&abs(b-a)<=t*(v-w))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3128
n = gets.to_i
kiroku = []
n.times do |i|
  count = 0
  x = i+1
  while x%2 == 0
    count+=1
    x = x/2
  end
  if count > 0
    kiroku.push({n: i+1, c: count})
  end
end

if kiroku.length == 0
  puts 1
else
  puts kiroku.sort {|a,b| b[:c] <=> a[:c] }.first[:n]
end

Measured memory_bytes: 1788
def count_2_5(a):
  c2 = c5 = 0
  while a % 2 == 0:
    c2 += 1
    a //= 2
  while a % 5 == 0:
    c5 += 1
    a //= 5
  return c2, c5

N = int(input())

# [-9, -8, ..., -1, 0, 1, ..., 8, 9]
base = 9
MAP = [[0]*19 for i in range(19)]
A = []
for i in range(N):
  a = input()
  if '.' in a:
    a, b = a.split('.')
    if int(b):
      c2, c5 = count_2_5(int(a+b))
      c2 -= len(b); c5 -= len(b)
    else:
      c2, c5 = count_2_5(int(a))
  else:
    c2, c5 = count_2_5(int(a))
  
  c2 = min(c2, 9); c5 = min(c5, 9)
  A.append((c2, c5))
  c2 += base; c5 += base
  MAP[c2][c5] += 1

def get_map(i, j):
  try:
    return MAP[i][j]
  except:
    return 0

for i in range(18, -1, -1):
  for j in range(18, -1, -1):
    MAP[i][j] += get_map(i+1, j) + get_map(i, j+1) - get_map(i+1, j+1)

ans = 0
for c2, c5 in A:
  ans += get_map(base-c2, base-c5)
  if c2 >= 0 and c5 >= 0:
    ans -= 1

print(ans//2)

Measured memory_bytes: 26720
#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 = 1e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , m ; 
vector<int> p ;
vector<int> parent(N) ;
int Find(int x){
    if ( parent[x] == x ) return x ;
    return parent[x] = Find(parent[x]) ;
}
void Union(int x, int y){
    int px = Find(x) ;
    int py = Find(y) ;
    if ( px == py ) return ;
    parent[px] = py ;
}
signed main(){
    fastio
    for(int i = 0; i < N; i++){
        parent[i] = i ;
    }
    cin >> n >> m ;
    p = vector<int>(n) ;
    for(int i = 0; i < n; i++){
        cin >> p[i] ; 
        p[i]--;
    }
    for(int i = 0; i < m; i++){
        int x , y ;
        cin >> x >> y ; 
        x--, y--;
        Union(x, y) ;
    }
    vector<int> ans(n) ;
    for(int i = 0; i < n; i++){
        int a = Find(i) ;
        int b = Find(p[i]) ;
        if ( a == b ) ans[a]++;
    }
    int answer = 0 ;
    for(int i = 0; i < n; i++){
        answer += ans[i] ;
    }
    cout << answer << endl;
    return 0; 
}

Measured memory_bytes: 5504
ls = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
dic = {"A":1,"B":2,"C":3,"D":4,"E":5,"F":6,"G":7,"H":8,"I":9,"J":10,"K":11,"L":12,"M":13,"N":14,"O":15,"P":16,"Q":17,"R":18,"S":19,"T":20,"U":21,"V":22,"W":23,"X":24,"Y":25,"Z":26}

n = int(input())
s = input()
ans = ""
for i in range(len(s)):
  ans += ls[(dic[s[i]]+n-1) % 26]
print(ans)


Measured memory_bytes: 3064
fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        k: usize,
    }
    for i in 0..=n {
        for j in 0..=m {
            let num = n * m - (i * j + (n - i) * (m - j));
            if num == k {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}


Measured memory_bytes: 2096
#require 'pp' 

a = gets.to_i
#b,c=gets.chomp.split(" ").map(&:to_i);
s = gets.chomp

w_counts = []
e_counts = []
w_sum = e_sum = 0

s.each_char do |c| 
  if c == "W"
    w_sum += 1
  else
    e_sum += 1
  end
  w_counts << w_sum
  e_counts << e_sum
end

#pp w_counts
#pp e_counts

min = e_sum - (s[0] == "E"? 1 : 0)
tmp = w_counts[a.size - 1 -1]

a.times do |i|
  i= i -1
  next if (i == 0 || a.size - 1 == i)
  count = w_counts[i-1] + (e_sum - e_counts[i])
  min = count if count < min
#  puts min
end

puts min


Measured memory_bytes: 7188