akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env pypy3

def ans(X):
    if X == 0: return 0
    X = X % (bin(X).count('1'))
    return 1+ans(X)

# test case injection
if False:
    import random
    X = ''.join(random.choice("1") for _ in range(2*10**5))
    N = len(X)
    # print(N, X)
    # exit(0)
else:
    N = int(input())
    X = input()

N = N-1

popcount = X.count('1')
X_int = int(X, 2)

import array

two_pow_mod_pc_plus = array.array('i', [0]*(N+1))
two_pow_mod_pc_minus = array.array('i', [0]*(N+1))

two_pow_mod_pc_plus[0] = 1 % (popcount+1)
if popcount <= 1:
    two_pow_mod_pc_minus[0] = 0
else:
    two_pow_mod_pc_minus[0] = 1 % (popcount-1)

for i in range(1, len(two_pow_mod_pc_plus)):
    two_pow_mod_pc_plus[i] = (2*two_pow_mod_pc_plus[i-1]) % (popcount+1)

for i in range(1, len(two_pow_mod_pc_minus)):
    if popcount <= 1:
        two_pow_mod_pc_minus[i] == 1
    else:
        two_pow_mod_pc_minus[i] = (2*two_pow_mod_pc_minus[i-1]) % (popcount-1)

X_mod_pc_plus = X_int % (popcount+1)
if popcount <= 1:
    X_mod_pc_minus = 0
else:
    X_mod_pc_minus = X_int % (popcount-1)

for i, x in enumerate(X):
    # if i % 1000 == 0: print(i)
    if x == '0':
        r = 1 + ans((X_mod_pc_plus + two_pow_mod_pc_plus[N-i]) % (popcount+1))
    else:
        if popcount == 1:
            print(0)
            continue
        else:
            r = 1 + ans((X_mod_pc_minus - two_pow_mod_pc_minus[N-i]) % (popcount-1))
    print(r)


Measured memory_bytes: 79144
from itertools import product

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

switches = [(0, 1) for _ in range(n)]
ans = 0
for state in product(*switches) :
    bulbs = [0 for _ in range(m)]
    for i, ((_, *ss), p) in enumerate(zip(ksskss, pp)) :
        p ^= 1
        for s in ss :
            if state[s-1] :
                p ^= 1
        if p :
            bulbs[i] = 1
    if all(bulbs) :
        ans += 1
print(ans)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    int n,h,w;
    cin >> n >> h >> w;

    cout << (n-h+1)*(n-w+1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
ll n;
	
struct struk{
		string s;
		ll p, kordinat;
	};
struk masak[105];

bool cmp(struk s1, struk s2){
		if(s1.s!=s2.s){
			return s1.s<s2.s;
		}
		else{
			return s1.p>s2.p;
		}
	}
	
int main(){
	IOS
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> masak[i].s >> masak[i].p;
		masak[i].kordinat=i+1;
	}
	sort(masak, masak+n, cmp);	
	for(int i=0;i<n;i++){
		cout << masak[i].kordinat << '\n';
	}	
}


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

using namespace std;

const int maxn = 1e5;
vector<int> edge[maxn];
int cl[maxn];

bool dfs(int u, int c){
    cl[u] = c;
    for (auto v: edge[u]){
        if (!cl[v]){
            if (!dfs(v, 3 - c)) return false;
        } else if (cl[v] + c != 3) {
            return false;
        }
    }
    return true;
}

int main()
{
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0), cin.tie(0);
    long long n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    if (dfs(0, 1)){
        long long ct = 0;
        for (int i = 0; i < n; i++){
            ct += (cl[i] == 1);
        }
        cout << ct * (n - ct) - m;
    } else {
        cout << (n * (n - 1)) / 2 - m;
    }
    return 0;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	ans += 1 * min(k, a);
	k -= min(k, a);
	k -= min(k, b);
	ans -= 1 * min(k, c);
	cout << ans;
}


Measured memory_bytes: 3652
K,N=map(int,input().split())
A=list(map(int,input().split()))
mini=1000000
for i in range(N-1):
  s=A[i]+K-A[i+1]
  if s<mini:
    mini=s
if (A[N-1]-A[0])<mini:
  mini=(A[N-1]-A[0])
print(mini)

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



int main(){
    int N;cin >> N;
    vector<LL> vec;
    vector<LL> ruiseki;
    ruiseki.push_back(0);
    for(int a = 0;a < N;a++){
        LL b;cin >> b;
        ruiseki.push_back(ruiseki.back()+b);
    }
    map<LL, LL> mp;
    for(int a = 0;a < ruiseki.size();a++){
        mp[ruiseki.at(a)]++;
    }
    LL ans = 0;
    for(auto a : mp)ans += a.second*(a.second-1);
    cout<<ans/2<<endl;
}



Measured memory_bytes: 14320
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


def array(*args, initial=0):
    def forstr(N):
        return "[{} for _ in range("+str(N)+")]"

    a = args[-1]
    ans = eval(forstr(a).format(initial))
    if len(args) == 1:
        return ans
    else:
        return array(*args[:-1], initial=ans)


def solve(K: int, D: int):
    K = str(K)
    N = len(str(K))
    DP = array(N+1, 2, D, initial=0)
    DP[0][0][0] = 1
    for i in range(N):
        for j in range(2):
            lim = 9 if j else int(K[i])
            for k in range(D):
                for d in range(lim+1):
                    DP[i+1][j or d < lim][(k+d) % D] += DP[i][j][k]
                    DP[i+1][j or d < lim][(k+d) % D] %= MOD
    print((DP[N][0][0]+DP[N][1][0]-1) % MOD)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(K, D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61924
index_list = {}

while line = gets
  word, page = line.split
  
  index_list[word] = [] if index_list[word].nil?
  index_list[word] << page.to_i
end

index_list.sort_by { |k, _| k }.each { |k, v| puts [k, v.sort.join(" ")] }

Measured memory_bytes: 8600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  string s;
  cin >> s;
  int a, z;
  rep(i, s.size())
  { 
    if(s[i]=='A'){
      a = i;
      break;
    }
  }
  rep(i,s.size()){
    if(s[i]=='Z'){
      z = i;
    }
  }
  cout << max(0, z - a + 1) << endl;

}

Measured memory_bytes: 640
// https://atcoder.jp/contests/abc153/tasks/abc153_c

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#if 1
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(a) if (DEBUG) REP(_i, a.size()) DUMP(a[_i]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(a)
#endif

const int N_MAX = 2*1e5;
const int K_MAX = 2*1e5;
const int H_I_MAX = 1e9;

int N, K;
vector<int> H;

int main() {
  cin >> N >> K;
  H = vector<int>(N);
  REP(i, N) cin >> H[i];

  sort(H.begin(), H.end());

  ll ans = 0;
  REP(i, N - K) ans += H[i];

  cout << ans << endl;
}


Measured memory_bytes: 1024
//@formatter:off
#include<bits/stdc++.h>
#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 rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int h, w;
    cin >> h >> w;
    map<int, int> mp;
    multiset<int> st;
    rep(i, w) {
        mp[i] = i;
        st.insert(0);
    }
    rep(i, h) {
        int a, b;
        cin >> a >> b;
        a--;
        auto it = mp.lower_bound(a);
        int mx = -1;
        while (it != mp.end() and it->first <= b) {
            int val = it->first - it->second;
            st.erase(st.find(val));
            mx = it->second;
            it = mp.erase(it);
        }
        if (mx != -1 and b < w) {
            st.insert(b - mx);
            mp[b] = mx;
        }
        if (st.empty()) {
            cout << -1 << '\n';
        } else {
            cout << *st.begin() + i + 1 << '\n';
        }
    }
}

Measured memory_bytes: 22336
H, W = map(int, input().split())

a = [list(map(int, input().split())) for i in range(H)]

l = []

for i in range(H):
	for j in range(W-1):
		if a[i][j]%2 == 0:
			continue
		
		l.append((i+1, j+1, i+1, j+2))
		a[i][j] -= 1
		a[i][j+1] += 1

for i in range(H-1):
	if a[i][W-1]%2 == 0:
		continue
	
	l.append((i+1, W, i+2, W))
	a[i][W-1] -= 1
	a[i+1][W-1] += 1

print(len(l))

for y, x, y_, x_ in l:
	print('{} {} {} {}'.format(y, x, y_, x_))



Measured memory_bytes: 26204
#include<stdio.h>
int main(){
	int H,R;
	scanf("%d %d",&H,&R);
		if(H+R>0){printf("1\n");
		}else if(H+R==0){printf("0\n");
		}else if(H+R<0){printf("-1\n");}
	
	
	
	return 0;
}

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

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

int N, M;
int K;
int A[200010], B[200010];

signed main()
{
    cin >> N >> M >> K;
    rep(i, N)cin >> A[i];
    rep(i, M)cin >> B[i];

    int costA = 0;
    int costB = 0;
    int ans = 0;
    int numB = M;
    rep(i, M)costB += B[i];

    rep(i, N + 1)
    {
        if(i != 0)costA += A[i - 1];
        while(numB != 0 && K < costA + costB)
        {
            costB -= B[numB - 1];
            numB--;
        }

        if(costA + costB <= K)ans = max(ans, i + numB);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6668
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
#define mod2 998244353 
#define pi 3.14159265358979323846

int solve(){
    int a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;
   // int x=
    if(w>v) cout<<"NO";
    else if(v==w&&a==b) cout<<"YES";
    else if(v==w) cout<<"NO";
    else if((abs(b-a))/(v-w)<=t){
        if((abs(b-a))%(v-w)!=0&&(abs(b-a))/(v-w)==t) cout<<"NO";
        else cout<<"YES";
    }
    else cout<<"NO";
    return 0;
}
 
signed main(){
    IOS;
    int t=1;
    //cin>>t;
    //string s;cin>>s;cout<<s.size()<<"*";
    while(t--){
        solve();
        //if(solve()) cout<<"YES";
        //else cout<<"NO";
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3652
import sys
a0 = list(map(int,input().split()))
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
c = 0
n = int(input())
for i in range(n):
    b = int(input())
    if a0.count(b) == 1:
        c += 1
        a0[a0.index(b)] = "〇"
    elif a1.count(b) == 1:
        c += 1
        a1[a1.index(b)] = "〇"
    elif a2.count(b) == 1:
        c += 1
        a2[a2.index(b)] = "〇"
if c <= 2:
    print("No")
    sys.exit()
else:
    if a0[0] == "〇":
        if a1[0] == a2[0]:
            print("Yes")
            sys.exit()
        if a0[1] == a0[2]:
            print("Yes")
            sys.exit()
        if a1[1] == a2[2]:
            print("Yes")
            sys.exit()
    if a0[1] == "〇":
        if a1[1] == a2[1]:
            print("Yes")
            sys.exit()
    if a0[2] == "〇":
        if a1[2] == a2[2]:
            print("Yes")
            sys.exit()
        if a1[1] == a2[0]:
            print("Yes")
            sys.exit()
    if a1[0] == a1[1] == a1[2]:
        print("Yes")
        sys.exit()
    if a2[0] == a2[1] == a2[2]:
        print("Yes")
        sys.exit()
print("No")

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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;++i) cin>>a[i];
    for(int i=0;i<(n-k);++i)
    {
        if(a[i]<a[i+k])
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    return 0;
}


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

typedef long long int ll;
typedef string str;

int main ()
{
	ll t,n,m,k,i,j,a,b;
	str st;
	cin >> st;
	if(st[1]=='B')
		st[1]='R';
	else
		st[1]='B';
	cout << st << endl;
	return 0;
}

Measured memory_bytes: 3548
import sys
from functools import reduce
from fractions import gcd


def main():
    n, x = list(map(int, input().split()))
    values = list(map(int, input().split()))
    values.append(x)
    values.sort()
    v = [values[i + 1] - values[i] for i in range(len(values) - 1)]
    res = v[0]
    print(reduce(gcd, v[1:], v[0]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 16308
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
vector <int> v[100005];
long long bio[100005][2];
long long modz(long long x, long long y)
{
	if(x + y >= MOD)
	{
		return x+y-MOD;
	}
	return x+y;
}
long long f(int poz, bool o, int p)
{
	if(bio[poz][o] != 0)
	{
		return bio[poz][o];
	}
	if(v[poz].size() == 1 && p != -1)
	{
		return bio[poz][o] = 1;
	}
	long long u = 1;
	for(int i = 0; i < v[poz].size(); i++)
	{
		if(p != v[poz][i])
		{
			if(o == 1)
			{
				u *= f(v[poz][i], 0, poz);
				u %= MOD;
			}
			else
			{
				u *= modz(f(v[poz][i], 1, poz), f(v[poz][i], 0, poz));
				u %= MOD;
			}
		}
	}
	return bio[poz][o] = u;
}
int main()
{
    int b;
    cin >> b;
    int p, k;
    for(int i = 0; i < b-1; i++)
    {
    	cin >> p >> k;
    	p--;
    	k--;
    	v[p].push_back(k);
    	v[k].push_back(p);
	}
	cout << modz(f(0, 0, -1), f(0, 1, -1)) << endl;
}



Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
#define ll long long int


int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	
	ll k,x,ans;
	cin>>k>>x;
	set<ll> s;
	s.insert(x);
	for(int i=1;i<k; i++){
		if(x-i>=-1e6)s.insert(x-i);
		if(x+i<=1e6)s.insert(x+i);
	} 
	auto it=s.begin();
	while(it!=s.end()){
		cout<< *it<<" ";
		it++;
	}

	return 0;
}

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

#define ul unsigned long long
#define ll long long 

class Dice {
  public:
  int d[6],n[5];
  Dice(int ds[6]) {
    for (size_t i = 0; i < 6; i++)
    {
      d[i]=ds[i];
    }
    n[0]=0;//c
    n[1]=4;//n
    n[2]=2;//e
    n[3]=3;//w
    n[4]=1;//s
  }

  void roll(char dir) {

    switch (dir) {
    case 'N':
      n[1] = n[0];     //n
      n[0] = n[4];     //c
      n[4] = 5 - n[1]; //s

      break;
    case 'E':
      n[2] = n[0];     //c->e
      n[0] = n[3];     //w->c
      n[3] = 5 - n[2]; //w=7-e

      break;
    case 'W':
      n[3] = n[0];     //c->e
      n[0] = n[2];     //w->c
      n[2] = 5 - n[3]; //w=7-e

      break;
    case 'S':
      n[4] = n[0];     //s
      n[0] = n[1];     //c
      n[1] = 5 - n[4]; //n

      break;
    }
  }

  int top(void) {
    return d[n[0]];
  }

};

int main()
{
  int ds[6];
  for (size_t i = 0; i < 6; i++)
  {
    cin>>ds[i];
  }
  
  Dice d1(ds);

  string o;
  cin>>o;
  for (size_t i = 0; i < o.length(); i++)
  {
    d1.roll(o[i]);
  }
  
  cout<<d1.top()<<endl;

  return 0;
}



Measured memory_bytes: 3192
#include<stdio.h>
int main()
{
    int i,j,k,s=0,a,b,c,x;
    scanf("%d %d %d %d",&a,&b,&c,&x);
    for(i=0;i<=a;i++)
    {
        for(j=0;j<=b;j++)
        {
            for(k=0;k<=c;k++)
            {
                if(i*500+j*100+k*50==x)
                {
                    s++;
                }
            }
        }
    }
    printf("%d",s);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int n,i,j,sum=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            sum+=a[i]*a[j];
        }
    }
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
n = gets.to_i
a = gets.split.map(&:to_i)
q = gets.to_i
bc = Array.new(q){gets.split.map(&:to_i)}
val = Array.new(10**5 + 1, 0)
a.each{|v| val[v] += 1}
total = val.map.with_index{|v, n| v * n}.sum
q.times{|i|
	total += (bc[i][1] - bc[i][0]) * val[bc[i][0]]
	val[bc[i][1]] += val[bc[i][0]]
	val[bc[i][0]] = 0
	puts total
}

Measured memory_bytes: 23972
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn gcd(m: usize, n: usize) -> usize {
    if n > m {
        gcd(n, m)
    } else if m % n == 0 {
        n
    } else {
        gcd(n, m % n)
    }
}

fn lcm(m: usize, n: usize) -> usize {
    m * n / gcd(m, n)
}

fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    }
    let ac = (a - 1) / c;
    let ad = (a - 1) / d;
    let acd = (a - 1) / lcm(c, d);
    let bc = b / c;
    let bd = b / d;
    let bcd = b / lcm(c, d);
    eprintln!("{} {} {}", ac, ad, acd);
    eprintln!("{} {} {}", bc, bd, bcd);
    println!("{}", b + 1 + bcd + ac + ad - a - bc - bd - acd);
}


Measured memory_bytes: 2164
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, X, Y);
    bool ok = false;
    repc(i, 0, 100) repc(j, 0, 100) {
        ok |= (i + j == X && 2 * i + 4 * j == Y);
    }

    const auto YesNo = [](bool p) { print(p ? "Yes" : "No"); };
    YesNo(ok);

    return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M, A[202020], B[202020];
vector<int> graph[1010], eid[1010];

bool conn[1010][1010];
bool vis[1010];
bool sol[202020];

void dfs(int q, int src)
{
	if (conn[src][q]) return;
	conn[src][q] = true;
	for (int r : graph[q]) dfs(r, src);
}

pair<int, int> orig[1010];

void visit(int p, int ec, int ori)
{
	if (p == ori) return;
	if (orig[p].second != -1) return;
	if (orig[p].first == ec) return;
	
	if (orig[p].first != -1) orig[p].second = ec;
	else orig[p].first = ec;

	for (int q : graph[p]) visit(q, ec, ori);
}

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; ++i) {
		scanf("%d%d", A + i, B + i);
		--A[i]; --B[i];
	}
	for (int i = 0; i < M; ++i) {
		graph[A[i]].push_back(B[i]);
		eid[A[i]].push_back(i);
	}
	for (int i = 0; i < N; ++i) dfs(i, i);

	for (int i = 0; i < N; ++i) {
		fill(orig, orig + N, make_pair(-1, -1));

		for (int j : graph[i]) visit(j, j, i);

		for (int j_ = 0; j_ < graph[i].size(); ++j_) {
			int ei = eid[i][j_], j = graph[i][j_];

			bool ab = orig[j].second != -1;
			bool ba = conn[j][i];
			sol[ei] = (ab == ba);
		}
	}

	for (int i = 0; i < M; ++i) {
		puts(sol[i] ? "same" : "diff");
	}
	return 0;
}


Measured memory_bytes: 7040
/////////////////////////////////////////////////////////////////////////
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define uniq(x) (x).erase(unique(all(x)),(x).end())
int qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
int qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
////////////////////////////// define /////////////////////////////////
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e16;
//const int MAX_N = 200001;

int main() {
	int n;cin >> n;
	vector<int> x(n),y(n);
	rep(n){cin >> x[i];y[i] = x[i];}
	sort(all(y));
	int m = (y[n/2 - 1] + y[n/2])/2;
	rep(n){if(x[i] <= m){cout << y[n/2] << endl;}else{cout << y[n/2 - 1] << endl;}}
	return 0;
}


Measured memory_bytes: 3712
S = input().strip()

T = "keyence"

found = False
if len(S)<len(T):
    print("NO")
else:
        for start in range(len(T)):
            if S.startswith(T[:start]) and S.endswith(T[start:]):
                found = True
                break

        if S.startswith(T):
            found = True

        if found:
            print("YES")
        else:
            print("NO")

Measured memory_bytes: 3060
import sys

alpha = 'abcdefghijklmnopqrstuvwxyz'
m = {k:0 for k in alpha}
q = ''
for line in sys.stdin:
    q += line

for s in q:
    s = s.lower()
    if s in m:
        m[s] += 1
    
for s in alpha:
    print('%s : %d' % (s, m[s]))

Measured memory_bytes: 7528
import sys
d1 = {}
l = []
while True:
  a,b = input().split(',')
  if (a,b) == ('0','0'):
    break
  else:
    d1[a] = int(b)
    if (int(b) not in l):
      l.append(int(b))
l.sort()
l.reverse()
for line in sys.stdin.readlines():
  n = line.replace('\n','')
  print(l.index(d1[n])+1)

Measured memory_bytes: 7628
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
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; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//AtCoder以外ではコメントアウトを忘れずに！
#include <atcoder/all>
using namespace atcoder;
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q, T;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vll flag, D; vector<vpll> path; //vs S;
using mint = modint998244353;
struct S {
	mint a;
	int size;
};

struct F {
	mint a, b;
};

S op(S l, S r) { return S{ l.a + r.a, l.size + r.size }; }
S e() { return S{ 0, 0 }; }
S mapping(F l, S r) { return S{ r.a * l.a + r.size * l.b, r.size }; }
F composition(F l, F r) { return F{ r.a * l.a, r.b * l.a + l.b }; }
F id() { return F{ 1, 0 }; }
int main() {
	cin >> N >> Q;
	vector<int> A(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	lazy_segtree<S, op, e, F, mapping, composition, id> T(N);
	for (i = 0; i < N; i++) {
		T.set(i, { A[i],1 });
	}
	for (i = 0; i < Q; i++) {
		ll t;
		cin >> t;
		if (t == 0) {
			ll l, r, b, c;
			cin >> l >> r >> b >> c;
			T.apply(l, r, F{ b,c });
		}
		else {
			ll l, r;
			cin >> l >> r;
			co(T.prod(l, r).a.val());
		}
	}
}

Measured memory_bytes: 21456
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;
const int INF =1e9;

int main(){
	int n;
	ci(n);
	ll ans=0;
	unordered_map<string,ll>um;
	while(n--){	
		string s;
		ci(s);
		sort(s.begin(),s.end());
		um[s]++;
		ans += um[s] -1;
	}
	co(ans);
}


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

int main(){
	int x,h;
	double s;
	while(1){
		scanf("%d",&x);
		scanf("%d",&h);
		if(x==0 && h==0) break;
		s = x*x + x*sqrt(4*h*h+x*x);
		printf("%f\n",s);
	}
	
	return 0;
}

Measured memory_bytes: 632
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

l, r = na()
if r//2019*2019 >= l:
    print(0)
else:
    mn = 9999999
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            mn = min(mn, i*j%2019)
    print(mn)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
vector<int> g[100005];
int n, k, a, b;
int ans = 1;
void dfs(int u, int p, int x){
    ans = ans*1ll*max(0, (k-x))%mod;
    x = 1;
    if(p != 0) x++;
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
        if(v == p) continue;
        dfs(v, u, x);
        x++;
    }
}
int main(){
    scanf("%d%d", &n, &k);
    for(int i=1;i<=n-1;i++){
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1, 0, 0);
    printf("%d\n", ans);
}

Measured memory_bytes: 10368
import std.functional,
       std.algorithm,
       std.container,
       std.typetuple,
       std.typecons,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main()
{
auto ip = readln.split.to!(int[]);
if(ip[0] == ip[1]) writeln("a == b");
else if(ip[0] > ip[1]) writeln("a > b");
else writeln("a < b");
}


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

using namespace std;
typedef long long ll;

const int P=1e9+7;
int n,factor[1005],m=1;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int j=i;
		for(int k=2;k<=j;k++)while(j%k==0)j/=k,factor[k]++;
	}
	for(int i=1;i<=n;i++)m=(ll)m*(factor[i]+1)%P;
	cout<<m;
	return 0;
}

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

typedef unsigned long long ull;

int main() {
    ull n, m;
    cin >> n >> m;

    // 裏返す回数が奇数なら裏になる

    // 2x2以上であれば辺と角を除くマスが裏となる
    // 464
    // 696
    // 464

    // 1xnの場合
    // 232
    // 端を除くマスが裏となる

    // 1x1の場合はその1枚は裏となる

    if (n == 1 && m == 1) {
        cout << 1 << endl;
    } else if (n == 1 || m == 1) {
        cout << m*n-2 << endl;
    } else {
        cout << (m-2)*(n-2) << endl;
    }
}



Measured memory_bytes: 256
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
    }
    let a = {
        let mut tmp = vec![0];
        tmp.append(&mut a);
        tmp.push(0);
        tmp
    };
    let all_sum = a.windows(2).fold(0, |sum, w| sum + (w[0] - w[1]).abs());
    let ans = a
        .windows(3)
        .map(|w| all_sum - ((w[0] - w[1]).abs() + (w[1] - w[2]).abs()) + (w[0] - w[2]).abs())
        .map(|x| x.to_string())
        .collect::<Vec<_>>()
        .join("\n");
    println!("{}", ans);
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

int main() {


    ll h, w;
    int n;
    cin >> h >> w >> n;
    map<ll, map<ll, bool>> m;
    map<int, ll> ans;

    set<ll> check_ys;

    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;

        m[a][b] = true;
        check_ys.insert(a - 1);
        check_ys.insert(a);
        check_ys.insert(a + 1);

    }
    check_ys.erase(-1);
    check_ys.erase(0);
    check_ys.erase(h - 1);
    check_ys.erase(h);

    for (ll check_y : check_ys) {
        set<ll> check_xs;

        for (int i = 0; i < 3; i++) {
            for (auto &&e : m[check_y - 1 + i]) {
                ll x = e.first;
                check_xs.insert(x - 1);
                check_xs.insert(x);
                check_xs.insert(x + 1);
            }
        }
        check_xs.erase(-1);
        check_xs.erase(0);
        check_xs.erase(w - 1);
        check_xs.erase(w);

        for (ll check_x : check_xs) {

            int black = 0;
            rep(x, 3)rep(y, 3) {
                    ll px = check_x - 1 + x;
                    ll py = check_y - 1 + y;
                    if (m.find(py) == m.end()) continue;
                    if (m[py].find(px) == m[py].end())continue;
                    if (m[py][px]) black++;
                }
            ans[black]++;

        }

    }


    ans[0] = (h - 2) * (w - 2);
    for (auto e : ans) {
        if (e.first == 0) continue;
        ans[0] -= e.second;
    }


    for (int i = 0; i <= 9; i++) {
        cout << ans[i] << endl;
    }

    cout << endl;


}

Measured memory_bytes: 67456
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();
        TreeSet<Long> set = new TreeSet<>();
        for (long i = a; i < a + k && i <= b; i++) {
            set.add(i);
        }
        for (long i = b; i > b - k && i >= a ; i--) {
            set.add(i);
        }
        for (Long long1 : set) {
            System.out.println(long1);
        }
    }
}

Measured memory_bytes: 36236
#include <iostream>
#include <bitset>
#include <vector>
using namespace std;

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

bitset<55> ans[22];

vector<P> g[55];
bool ok;
ll fac[55];
ll an;

void dfs(int m, int s, int prev, int t) {
 
  if(s == t) {
    ok = true;
    return;
  }

  for(int i = 0; i < g[s].size(); i++) {
    int u = g[s][i].first; int id = g[s][i].second;
    if(u == prev) continue;
    dfs(m,u,s,t);
    if(ok) {
      ans[m][id] = true;
      return;
    }
  }

  return;
}
    
				       
  
  

int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n - 1; i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(P(b,i));
    g[b].push_back(P(a,i));
  }
  int m;
  cin >> m;
  for(int i = 0; i < m; i++) {
    int x,y;
    cin >> x >> y;
    x--; y--;
    ok = false;
    dfs(i,x,-1,y);
  }
  fac[0] = 1;
  
  for(int i = 1; i < 55; i++) fac[i] = fac[i-1] * 2;
  
 

  for(int i = 1; i < (1 << m); i++) {
    int cnt = 0;
    bitset<55> tmp;
    for(int j = 0; j < 20; j++) {
      int s = (1 << j);
      if(s & i) {
	tmp |= ans[j];
	cnt++;
      }

    }
  
    if(cnt & 1) {
      an += fac[n-1-tmp.count()];
    
    }
    else an -= fac[n-1-tmp.count()];
    //   cout << cnt <<"  "<< tmp <<"   "<<n-1-tmp.count()<< endl;
  }

  cout << fac[n-1] - an << endl;
  
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    vector<int> A(N),B(M),C(N),D(N),save;
    for(int i=0;i<N;i++) cin>>A[i];
    for(int i=0;i<M;i++) cin>>B[i];
    
    int now=0;
    for(int i=0;i<M;i++){
        for(int j=0;j<B[i];j++){
            C[now+j]=i%2;
            D[now+j]=1-i%2;
        }
        now+=B[i];
    }
    save=A;
    
    int ans1=0,ans2=0;
    
    for(int i=0;i<N;i++){
        if(A[i]==C[i]) continue;
        else{
            int now=i;
            while(now<N&&A[now]!=C[i]) now++;
            if(now==N){
                ans1=INF;
                break;
            }
            ans1+=now-i;
            for(int j=now;j-1>=i;j--) swap(A[j-1],A[j]);
        }
    }
    A=save;
    
    for(int i=0;i<N;i++){
        if(A[i]==D[i]) continue;
        else{
            int now=i;
            while(now<N&&A[now]!=D[i]) now++;
            if(now==N){
                ans2=INF;
                break;
            }
            ans2+=now-i;
            for(int j=now;j-1>=i;j--) swap(A[j-1],A[j]);
        }
    }
    
    cout<<min(ans1,ans2)<<endl;
}




Measured memory_bytes: 3224
import java.util.Arrays;
import java.util.Scanner;
 
class Main {
	int n;
	int[] a;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		a = new int[3*n];
		for(int i=0;i<3*n;i++){
			a[i] = sc.nextInt();
		}
	}
	void solve(){
		Arrays.sort(a);
		long sum = 0;
		for(int i=0;i<n;i++){
			sum += a[3*n-2-2*i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 91948
#include<iostream>
#include<vector>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
    vector<long long int> height;
    vector<vector<int>> data(100001);
    int N, M, i, a, b, count, temp, j;
    cin>>N>>M;
    for(i=0;i<N;i=i+1)
    {
        cin>>a;
        height.push_back(a);
    }
    count=0;
    for(i=0;i<M;i+=1)
    {
        cin>>a>>b;
        data[a].push_back(b);
        data[b].push_back(a);
    }
    /*for(i=1;i<=N;i=i+1)
    {
        for(j=0;j<data[i].size();j=j+1)
        {
            cout<<data[i][j]<<" ";
        }
        cout<<endl;
    }*/
    for(i=1;i<=N;i=i+1)
    {
        if(data[i].size()==0)
        {
            count=count+1;
        }
        else
        {
            temp=0;
            for(j=0;j<data[i].size();j=j+1)
            {
                if(height[data[i][j]-1]>=height[i-1])
                {
                    temp=1;
                    break;
                }
            }
            if(temp==0)
            {
                count+=1;
            }
        }
    }
    cout<<count<<endl;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,F;
    cin>>N>>F;

    map<pair<string,string>,int>cnt;
    rep(i,N){
        int m;cin>>m;
        vector<string>v(m);rep(j,m)cin>>v[j];
        sort(all(v));
        for(int j=0;j<m;j++){
            for(int k=j+1;k<m;k++)cnt[{v[j],v[k]}]++;
        }
    }

    vector<pair<string,string>>ans;
    each(it,cnt){
        if(it->se<F)continue;
        ans.pb(it->fi);
    }

    cout<<ans.size()<<endl;
    rep(i,ans.size())cout<<ans[i].fi<<" "<<ans[i].se<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
int r,c,n;
inline bool compare(pair<pii,int> uu,pair<pii,int> vv)
{
	if(uu.first.second==0)
	{
		if(vv.first.second==0)
		{
			return uu.first.first<vv.first.first;
		}
		return true;
	}
	else
	{
		if(vv.first.second==0)
		{
			return false;
		}
		if(uu.first.first==r)
		{
			if(vv.first.first==r)
			{
				return uu.first.second<vv.first.second;
			}
			return true;
		}
		else
		{
			if(vv.first.first==r)
			{
				return false;
			}
			if(uu.first.second==c)
			{
				if(vv.first.second==c)
				{
					return uu.first.first>vv.first.first;
				}
				return true;
			}
			else
			{
				if(vv.first.second==c)
				{
					return false;
				}
				// if(uu.first.first==0)
				// {
				// 	if(vv.first.first==0)
				// 	{
						return uu.first.second>vv.first.second;
				// 	}
				// 	return true;
				// }
				// else
				// {
				// 	if(vv.first.first==0)
				// 	{
				// 		return false;
				// 	}
				// }
			}
		}
	}
}
vector<pair<pii,int> > v;
inline bool bound(int x,int y)
{
	if(x==0||x==r||y==0||y==c)
	{
		return true;
	}
	return false;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>r>>c>>n;
	int x1,y1,x2,y2;
	for(int i=0;i<n;i++)
	{
		cin>>x1>>y1;
		cin>>x2>>y2;
		if(bound(x1,y1)&&bound(x2,y2))
		{
			v.pb(mk(mk(x1,y1),i));
			v.pb(mk(mk(x2,y2),i));
		}
	}
	sort(v.begin(),v.end(),compare);
	bool reached[n+1];
	stack<int> s;
	memset(reached,false,sizeof(reached));
	for(int i=0;i<v.size();i++)
	{
		//cout<<v[i].second<<"\n";
		//cout<<v[i].first.first<<" "<<v[i].first.second<<"\n";
		if(reached[v[i].second])
		{
			if(s.top()==v[i].second)
			{
				s.pop();
			}
			else
			{
				cout<<"NO\n";
				return 0;
			}
		}
		else
		{
			s.push(v[i].second);
			reached[v[i].second]=true;
		}
	}
	cout<<"YES\n";
}

Measured memory_bytes: 4852