akhauriyash/Code-Regression huggingface dataset:
import Foundation

extension String {
    func wordsMap<T>(_ f: (Substring) -> T?) -> [T] {
        return self.split(separator: " ").compactMap(f)
    }
}

private func readWords<T>(_ f: (Substring) -> T?) -> [T] {
    return readLine()!.wordsMap(f)
}

extension Optional {
    func pleaseAC(){
        print(self!)
    }
}

readLine().map { line -> Any in 
    let hwk = line.wordsMap { Int($0) }
    let H = hwk[0]
    let W = hwk[1]
    let K = hwk[2]

    var count = 0
    let grid = (0..<H).map { _ -> [Character] in 
        let row = Array(readLine()!)
        count += row.filter { $0 == "#" }.count
        return row
    }

    var points = [[Int]]()
    for h in 0..<H {
        points.append([h, -1])
    }

    for w in 0..<W {
        points.append([-1, w])
    }

    var ans = 0
    if count == K {
        ans += 1
    }
    for i in 1...H+W {
        for comb in Combinations(points, i) {
            var tmp = 0
            let reds = Set(comb)
            for h in 0..<H {
                for w in 0..<W {
                    if reds.contains([h, -1]) || reds.contains([-1, w]) {
                        continue
                    }
                    if grid[h][w] == "#" {
                        tmp += 1
                    }
                }   
            }
            if tmp == K {
                ans += 1
            }
        }
        
    }
    return ans

}
.pleaseAC()

struct Combinations<Seq: Sequence>: Sequence, IteratorProtocol {
    let pool: [Seq.Element]
    let r: Int

    var indecies: [Int]
    var first = true

    init(_ seq: Seq, _ r: Int) {
        self.pool = [Seq.Element](seq)
        self.r = r
        self.indecies = [Int](0..<r)
    }

    mutating func next() -> [Seq.Element]? {
        let n = pool.count
        guard 0...n ~= r else { return nil }
        guard !first else {
            first = false
            return indecies.map { pool[$0] }
        }

        var i = r - 1
        while indecies[i] == i + n - r {
            if i > 0 {
                i -= 1
            } else {
                return nil
            }
        }

        indecies[i] += 1
        for j in i+1..<r {
            indecies[j] = indecies[j - 1] + 1
        }

        return indecies.map { pool[$0] }
    }
}

Measured memory_bytes: 13716
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  string s, t;
  cin >> s >> t;

  sort(ALL(s));
  sort(ALL(t));
  reverse(ALL(t));

  if(s<t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,m;
	cin>>n>>m;
	cout<<(n-1)*(m-1); 
	return 0;
}


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

S = input()
dream_set = {"dream", "dreamer", "erase", "eraser"}
# 感動的計画法やるぞ

while len(S) > 0:
    if S.endswith("dream") or S.endswith("erase"):
        S = S[:-5]
    elif S.endswith("eraser"):
        S = S[:-6]
    elif S.endswith("dreamer"):
        S = S[:-7]
    else:
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 3188
while(1):
    [n,m,d]=[int(x) for x in raw_input().split()]
    if n==0:
        break
    else:
        total=0
        winner=0
        for i in range(1,n+1):
            buy=int(raw_input())
            total=total+buy*100
            if i==m:
                winner=buy
    prize=total*(100-d)/100.
    if winner==0:
        print 0
    else:
        print int(prize/winner)

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

using namespace std;

int main(int argc, char const *argv[]) {
    int t, n, s, f;
    int total;
    while (cin>>t, t) {
        total = 0;
        cin>>n;
        for (int i = 0; i < n; ++i) {
            cin>>s>>f;
            int tmp = f - s;
            total += tmp;
        }

        if (total >= t) cout<<"OK"<<endl;
        else cout<< t - total << endl;

    }
    return 0;
}

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

int main() {
  string s,t;
  cin>>s>>t;
  int ans=0;
  rep(i,3){
    if(s[i]==t[i]) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main(void)
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0;i<N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end(), greater<int>());
  int ans = 0;
  
  for (int i=0;i<N;i++){
    ans += a.at(i) * (i & 1 ? -1 : 1);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100

int main(){
  int M[MAX+1][MAX+1];
  int n,i,j,v,k,u;

  scanf("%d",&n);

  for(i=0;i<n+1 ;i++){
    for(j=0;j<n+1;j++){
      M[i][j]=0;
    }
  }

    for(i=1;i<=n;i++){
      scanf("%d %d",&u,&k);

      for(j=1;j<=k;j++){
	scanf(" %d",&v);

	M[u][v] = 1;
      }
    }

    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
	if(j > 1)printf(" ");
	printf("%d",M[i][j]);
      }
      printf("\n");
    }

    return 0;
}
    

    



Measured memory_bytes: 2108
N = int(input().strip())

prevt, prevx, prevy = 0, 0, 0
t = True
for n in range(N):
  t, x, y = map(int, input().strip().split())
  if t - prevt >= abs(x-prevx) + abs(y-prevy) and (t-prevt) % 2 == (abs(x-prevx) + abs(y-prevy)) % 2:
    prevt, prevx, prevy = t, x, y
  else:
    t = False
    break

if t:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3188
#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ar array


void solve(){
    int h, w, m;
    cin >> h >> w >> m;
    map<int,int> rows, cols;
    set<pair<int,int>> ss;
    for(int i = 0,a,b;i < (int)m; i++) {
        cin >> a >> b;
        ss.insert(make_pair(a,b));
        rows[a]++;
        cols[b]++;
    }
    int ans = 0;
    int maxr = 0, maxc = 0;
    for(auto itr : rows) maxr = max(itr.second,maxr);
    for(auto itr : cols) maxc = max(itr.second,maxc);
    vector<int> a1,a2;
    for(int i = 0;i < (int)rows.size(); i++) {
        if(rows[i] == maxr) a1.push_back(i);
    }   
    for(int i = 0;i < (int)cols.size(); i++) {
        if(cols[i] == maxc) a2.push_back(i);
    }
    bool flag = 0;
    for(int i = 0;i < (int)a1.size(); i++){
        for(int j = 0;j < (int)a2.size(); j++){
            if(!ss.count({a1[i],a2[j]})) {
                flag = 1;
                break;
            }  
        }
        if(flag) break;
    }
    if(flag) cout << maxr + maxc << "\n";
    else cout << maxr + maxc - 1 << "\n";
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int TC = 1;
    while(TC--)
        solve();        
    
    return 0;
}



Measured memory_bytes: 67816
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    ll res = 0;
    rep(i, N) {
        if(i < K) {
            res += X;
        } else {
            res += Y;
        }
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        ll n = inl();

        vl d(n);
        rep(i, n) cin >> d[i];

        sort(all(d));

        cout << d[n / 2] - d[n / 2 - 1] << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
	reg char ch=getchar();
	reg int res=0;
	while(ch<'0'||'9'<ch)ch=getchar();
	while('0'<=ch&&ch<='9')res=10*res+ch-'0',ch=getchar();
	return res;
}

int n;
vector<ll> a,b,ta,tb;

int main(void){
	n=read();
	for(reg int i=1;i<=n;++i){
		static ll x;
		x=read();
		a.push_back(x);
	}
	for(reg int i=1;i<=n;++i){
		static ll x;
		x=read();
		b.push_back(x);
	}
	reg ll ans=0;
	for(reg int i=0;i<30;++i){
		ta=a,tb=b;
		reg ll T=(1<<i),mod=(T<<1);
		for(reg int j=0;j<n;++j){
			ta[j]&=mod-1;
			tb[j]&=mod-1;
		}
		sort(tb.begin(),tb.end());
		reg int cnt=0;
		for(reg int j=0;j<n;++j){
			cnt+=lower_bound(tb.begin(),tb.end(),T*2-ta[j])-lower_bound(tb.begin(),tb.end(),T-ta[j]);
			cnt+=lower_bound(tb.begin(),tb.end(),T*4-ta[j])-lower_bound(tb.begin(),tb.end(),T*3-ta[j]);
		}
		if(cnt&1)
			ans|=T;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6768
s = input()
Q = int(input())
flag = True  # flagがTrueのとき、偶数回数の反転が行われている
cnt = 0
query = [list(map(str, input().split())) for _ in range(Q)]
before = []  # 先頭に追加する時
after = []  # 末尾に追加する時
for i in range(Q):
    a = query[i]
    if len(a) == 1:  # 1のqueryのとき
        cnt += 1
        if flag:
            flag = False
        else:
            flag = True
    else:
        f, c = a[1], a[2]
        if f == "1":  # 先頭に追加するもの
            if flag:
                # s = c + s  # 偶数回の反転なら素直に先頭に追加する
                before.append(c)
            else:
                # s += c  # 奇数会の反転なら後ろに追加する
                after.append(c)
        else:  # 末尾に追加する
            if flag:
                # s += c  # 末尾に追加
                after.append(c)
            else:
                # s = c + s  # 先頭に追加
                before.append(c)
before.reverse()
# print(before)
# print(s)
# print(after)
s = "".join(before) + s + "".join(after)
if cnt % 2 == 1 and cnt != 0:
    s = s[::-1]
print(s)


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

#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*****************************************************START******************************************************************/


int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1;
	 //cin >> T;
	// cin.ignore(); must be there when using getline(cin, s)
	while (T--)
	{
		int n,k; 
		cin >> n >> k; 
		vector<ll>W(n) , V(n);
		int value_sum = 0;
		for(int i=0; i<n; i++){
			cin >> W[i] >> V[i];
			value_sum += V[i];
		}
		vector<ll>dp(value_sum+1,inf);
		//dp[i] is the minimum weight for which the value is i;
		dp[0] = 0;
		for(int i=0; i<n; i++){
			
			for(ll value_already = value_sum - V[i]; value_already >= 0; value_already--){
				dp[value_already+V[i]] = min(dp[value_already] + W[i] , dp[value_already + V[i]]);
			}
		}
		int ans = 0; 
		for(int i=0; i<= value_sum; i++){
			 if(dp[i] <= k){
				ans = max(ans , i);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

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

    
    vector<ll> a;
    if(N == 3) {
        a = {2, 5, 63};
    } else if(N == 4) {
        a = {2, 5, 20, 63};
    } else if(N == 5) {
        a = {2, 5, 20, 30, 63};
    } else {
        REP(k, N / 4 + 10){
            a.push_back(6 * k + 2);
            a.push_back(6 * k + 3);
            a.push_back(6 * k + 4);
            a.push_back(6 * k + 6);
        }

        while(a.size() > N){
            a.pop_back();
        }

        ll sum = 0;
        REP(i, a.size()) sum += a[i];

        if(sum % 6 == 2) a[4] = 30000;
        else if(sum % 6 == 3) a[5] = 30000;
        else if(sum % 6 == 5) a[5] = 30000 - 6 + 4;
    }

    showVector(a)

    return 0;
}


Measured memory_bytes: 640
class Factorial():
    def __init__(self, mod=10**9 + 7):
        self.mod = mod
        self._factorial = [1]
        self._size = 1
        self._factorial_inv = [1]
        self._size_inv = 1

    def __call__(self, n):
        return self.fact(n)

    def fact(self, n):
        ''' n! % mod '''
        if n >= self.mod:
            return 0
        self._make(n)
        return self._factorial[n]
    
    def _make(self, n):
        if n >= self.mod:
            n = self.mod
        if self._size < n+1:
            for i in range(self._size, n+1):
                self._factorial.append(self._factorial[i-1]*i % self.mod)
            self._size = n+1

    def fact_inv(self, n):
        ''' n!^-1 % mod '''
        if n >= self.mod:
            raise ValueError('Modinv is not exist! arg={}'.format(n))
        if self._size_inv < n+1:
            self._factorial_inv += [-1] * (n+1-self._size_inv)
            self._size_inv = n+1
        if self._factorial_inv[n] == -1:
            self._factorial_inv[n] = self.modinv(self.fact(n))
        return self._factorial_inv[n]
    
    def _make_inv(self, n, r=2):
        if n >= self.mod:
            n = self.mod - 1
        if self._size_inv < n+1:
            self._factorial_inv += [-1] * (n+1-self._size_inv)
            self._size_inv = n+1
        self._factorial_inv[n] = self.modinv(self.fact(n))
        for i in range(n, r, -1):
            self._factorial_inv[i-1] = self._factorial_inv[i]*i % self.mod
    
    @staticmethod
    def xgcd(a, b):
        '''
        Return (gcd(a, b), x, y) such that a*x + b*y = gcd(a, b)
        '''
        x0, x1, y0, y1 = 0, 1, 1, 0
        while a != 0:
            (q, a), b = divmod(b, a), a
            y0, y1 = y1, y0 - q * y1
            x0, x1 = x1, x0 - q * x1
        return b, x0, y0

    def modinv(self, n):
        g, x, _ = self.xgcd(n, self.mod)
        if g != 1:
            raise ValueError('Modinv is not exist! arg={}'.format(n))
        return x % self.mod

    def comb(self, n, r):
        ''' nCr % mod '''
        if r > n:
            return 0
        t = self(n)*self.fact_inv(n-r) % self.mod
        return t*self.fact_inv(r) % self.mod
    
    def comb_(self, n, r):
        '''
        nCr % mod
        when r is not large and n is too large
        '''
        c = 1
        for i in range(1, r+1):
            c *= (n-i+1) * self.fact_inv(i)
            c %= self.mod
        return c

    def comb_with_repetition(self, n, r):
        ''' nHr % mod '''
        t = self(n+r-1)*self.fact_inv(n-1) % self.mod
        return t*self.fact_inv(r) % self.mod

    def perm(self, n, r):
        ''' nPr % mod '''
        if r > n:
            return 0
        return self(n)*self.fact_inv(n-r) % self.mod

n, m, k = map(int, input().split())
mod = 998244353
f = Factorial(mod)
f._make_inv(n-1)
comb = f.comb
s = 0
for i in range(k+1, n):
    t = comb(n-1, i)*m % mod
    t = t*pow(m-1, n-1-i, mod) % mod
    s = (s+t) % mod
ans = (pow(m, n, mod)-s) % mod
print(ans)

Measured memory_bytes: 24472
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i<(n); i++)
using namespace std;
using vec2div = vector<vector<long long>>;
using vec = vector<long long>;
using ll = long long;


int main(){
	ll n;
	ll i;
	for(i=0;i<5;i++){
		cin >> n;
		if(n==0){
			cout << i+1 << endl;
			break;
		}
	}
}

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


int32_t main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    int n, m; cin >> n >> m;
    int q; cin >> q;
    vector<vector<int>> l(n), r(m);
    for (; q; q--) {
        int x, y; cin >> x >> y; x--; y--;
        l[x].push_back(y); r[y].push_back(x);
    }
    int mxl = l[0].size();
    for (int i = 1; i < n; i++) mxl = max(mxl, (int)l[i].size());
    int mxr = r[0].size();
    for (int i = 0; i < m; i++) mxr = max(mxr, (int)r[i].size());
    vector<int> lft, rght;
    for (int i = 0; i < n; i++) {
        sort(l[i].begin(), l[i].end());
        if (l[i].size() == mxl) lft.push_back(i);
    }
    for (int i = 0; i < m; i++) {
        sort(r[i].begin(), r[i].end());
        if (r[i].size() == mxr) rght.push_back(i);
    }
    bool fl = false;
    for (auto i : lft) {
        int x = 0, y = 0;
        while (x < l[i].size() && y < rght.size()) {
            if (l[i][x] < rght[y]) x++;
            else {
                if (l[i][x] != rght[y]) {
                    fl = true; break;
                }
                y++;
            }
        }
        if (y != rght.size()) fl = true;
        if (fl) break;
    }
    if (fl) cout << mxl + mxr << endl;
    else cout << mxl + mxr - 1 << endl;

    return 0;
}


Measured memory_bytes: 40284
#include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long
const int maxn=2e6+50;
int QuickPow(int x,int N){
    int res = x;
    int ans = 1;
    while(N){
        if(N&1){
            ans = ans * res;
        }
        res = res*res;
        N = N>>1;
    }
    return ans;
}//矩阵快速幂求  x  的 n  次方
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}//快读
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int sum=a+b+c;
    if(sum>=22){
        cout<<"bust"<<endl;
    }else{
        cout<<"win"<<endl;
    }

    return 0;
}












Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}

debug dbg;

class BKThCommonDivisor {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int a, b, k;
	    in >> a >> b >> k;

	    map<int, int> mp;
	    for(int i=1; i<= a; i++){
            if(a % i == 0){
                mp[i] = 1;
            }
	    }
	    mp[a] = 1;

	    vector<int> resv;
	    for(int i=1; i<= b; i++){
	        if(b % i == 0 && mp[i]){
	            resv.push_back(i);
	        }
	    }
	    sort(resv.begin(), resv.end(), greater<int>());

	    //dbg.vdeb(resv);

	    out << resv[k-1] << endl;
	}
};


int main() {
	BKThCommonDivisor solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		int count = 0;
		for(int i = 1; i <= n; ++i)
		{
			int temp = i;
			while( temp >= 5 && temp % 5 == 0)
			{
				temp /= 5;
				count++;
			}
		}
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// DAME:

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int k;
    cin >> s >> k;
    if (s.size() < k){
        cout << 0 << endl;
        return 0;
    }
    int n = s.size();

    if (k==1){
        ll ans = (n-1)*9 + (s[0]-'0');
        cout << max(ans, 0LL) << endl;
        return 0;
    }else if (k==2){
        ll ans = 0LL;
        ans = (n-1)*(n-2)/2 * 81;
        ans += (s[0]-'0'-1) * (n-1) * 9;
        for(int i=1; i<n; i++){
            if (s[i] != '0'){
                ans += (n-1-i)*9;
                ans += (s[i]-'0');
                break;
            }
        }
        cout << max(ans, 0LL) << endl;
    }else if (k==3){
        ll ans = 0LL;
        ans = (n-1)*(n-2)*(n-3)/6 * 81 * 9;
        ans += (s[0]-'0'-1) * (n-1)*(n-2)/2 * 81;

        int count = 0;
        int prei = 0;
        for(int i=1; i<n; i++){
            if (count == 2) break;
            if (s[i]!='0'){
                if (count==0){
                    if (i == n-1) break;
                    prei = i;
                }else{
                    // 1つ目を選んで実際の値で, 2つ目を選ばない
                    ans += max((n-i-1)*9, 0);
                
                    // 1つ目を選んで実際の値で, 2つ目を選ぶ
                    ans += (s[i]-'0');
                }
                count++;
            }
        }
        // １つ目の０以外のもの以下を二つ選ぶ
        ans += (n-prei-1)*(n-prei-2)/2*81;
        // １つ目を選ぶがその値は実際の値より小さい
        ans += (s[prei] - '0' - 1)*(n-prei-1)*9;


        cout << max(ans, 0LL) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int
main(int argc, char argv[])
{
  int a, b;
  scanf("%d%d", &a, &b);
  
  int ans = 0;
  for(int i = 0; i < 2; i++){
  if(a >= b){
    ans += a;
    a -= 1;
  }
    else{
      ans += b;
      b -= 1;
  }
    
  }
  
  printf("%d\n", ans);
  return 0;
}

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

ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; 
      swap(a,b);
      u-=t*v; 
      swap(u,v);
   }
   u%=m;
   if(u<0) u+=m;
   return u;
}

ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



int main(){
   string s;
   cin>>s;
   int ans=0;
   
   rep(i,s.size()){
      int kari=0;
      for(int j=i;j<s.size();j++){
         bool f=false;
        if(s[j]=='A'||s[j]=='T'||s[j]=='G'||s[j]=='C') f=true;
        if(f){
           kari++;
           ans=max(ans,kari);
           
        }
        else{
           break;
        }
        
      }

   }
   cout<<ans;

   
   return 0;
}



Measured memory_bytes: 256
open System

let N = stdin.ReadLine() |> int
let A = stdin.ReadLine().Split(' ') |> Array.map int

let rec canDiv2 = fun v -> if v % 2 = 1 then 0 else (1 + canDiv2(v / 2))

A
|> Array.map canDiv2
|> Array.min
|> printfn "%d"

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int MOD = (int)1e9 + 7;
int n;
VI A;

int mul(int a, int b) {
	return (1ll * a * b) % MOD;
}
bool check()
{
	VI num(n, 0);
	for(auto i : A)
		++num[i];
	
	int d = num[n - 1];
	for(int i = n - 3; i >= 1; i -= 2)
		if(num[i] != d)
			return false;
	
	return (n % 2 == 1) ? num[0] == 1 : true;
}

int mpow(int b, int p)
{
	if(p == 0) return 1;
	if(p == 1) return b;
	int mu = mpow(b, p / 2);
	return mul(mul(mu, mu), mpow(b, p % 2));
}

int orders()
{
	if(check() == false)
		return 0;	
	
	return mpow(2, n / 2);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n;

	A.resize(n);
	REP(i, 0, n) cin >> A[i];

	cout << orders() << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mod = 1e9+7;
constexpr ll infl = 1ll<<60;

constexpr int nr = 800;
vector<pair<int,int>> mo[nr];
vector<pair<int,int>> query(500050);
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,q;
    cin>>n>>q;
    vector<int> c(n);
    for(int i=0;i<n;++i) cin>>c[i];
    for(int i=0;i<q;++i){
        cin>>query[i].first >> query[i].second;
        query[i].first--;
        mo[query[i].first/nr].push_back({query[i].second,i});
    }
    int x;
    array<int,500050> num{};
    array<int,500050> ret{};
    for(int i=0;i<nr;++i){
        sort(mo[i].begin(),mo[i].end());
        fill(num.begin(),num.end(),0);
        int curl,curr;
        curl = curr = 0;
        int count =0 ;
        for(auto && a : mo[i]){
            x = a.second;
            while(curr <query[x].second){
                if(num[c[curr]] == 0 ){
                    count++;
                }
                num[c[curr]]++;
                curr++;
            }
            while(curl < query[x].first){
                num[c[curl]]--;
                if(num[c[curl]] == 0)count--;
                curl++;
            }
            while(curl > query[x].first){
                curl--;
                num[c[curl]]++;
                if(num[c[curl]] == 1)count++;
            }
            ret[x] = count;
        }
    }
    for(int i=0;i<q;++i)cout << ret[i] << endl;
    return 0;
}

Measured memory_bytes: 19940
var input = require('fs').readFileSync('/dev/stdin', 'utf8');

var inputs = input.split('\n');

var first = inputs.shift().split(' ');
var N = +first[0];
var K = +first[1];

var P = inputs.shift().split(' ').map(function(p){ return +p });

P.sort(function(a,b){ return a > b ? 1 : -1 });

var sum = 0;
for(var i = 0 ; i < K; i++){
    sum += P[i];
}

console.log(sum);

Measured memory_bytes: 29744
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const double eps = 1e-9;
int main(void){
    IOS;
    ll x; cin >> x;
    ll y = 100;
    for (int i = 1; ; ++i){
        double z = y;
        z = z*1.01;
        y = z;
        if (y >= x){
            cout << i << endl; return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

vecl color(100010,-1),dist0(100010);

void dfs(vector<vector<Pl>> &G, int s) {
    for(auto p : G[s]) {
        int v = p.first;
        ll c = p.second;
        if(color[v] != -1) continue;
        if((dist0[s]+c)%2 == 0) color[v] = 0;
        else color[v] = 1;
        dist0[v] = dist0[s]+c;
        dfs(G,v);
    }
}

int main() {
    int N; cin >> N;
    vector<vector<Pl>> G(N);
    
    REP(i,N-1) {
        int u,v;
        ll w;
        cin >> u >> v >> w;
        u--;v--;
        G[u].push_back({v,w});
        G[v].push_back({u,w});
    }
    
    color[0] = 0;
    dfs(G,0);
    REP(i,N) cout << color[i] << endl;
}

Measured memory_bytes: 13752
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX-1
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };

ll n, m, s, t;
vector<vector<pair<ll,ll>>>edges_y(101010);
vector<vector<pair<ll,ll>>>edges_s(101010);
ll d_y[101010];
ll d_s[101010];


void dijkstra_y(ll e) {
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>que;
	fill(d_y, d_y + n, inf);
	d_y[e] = 0;
	que.push({0,e});

	while (!que.empty()) {
		auto p = que.top();
		que.pop();
		ll v = p.second;
		if (d_y[v] < p.first)continue;
		rep(i, 0, edges_y[v].size()) {
			ll to = edges_y[v][i].first;
			ll cost = edges_y[v][i].second;
			if (d_y[to] > d_y[v] + cost) {
				d_y[to] = d_y[v] + cost;
				que.push({ d_y[to],to });
			}
		}
	}
}

void dijkstra_s(ll e) {
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>que;
	fill(d_s, d_s + n, inf);
	d_s[e] = 0;
	que.push({ 0, e });

	while (!que.empty()) {
		auto p = que.top();
		que.pop();
		ll v = p.second;
		if (d_s[v] < p.first)continue;
		rep(i, 0, edges_s[v].size()) {
			ll to = edges_s[v][i].first;
			ll cost = edges_s[v][i].second;
			if (d_s[to] > d_s[v] + cost) {
				d_s[to] = d_s[v] + cost;
				que.push({ d_s[to], to });
			}
		}
	}
}


int main(){
	cin >> n >> m >> s >> t;
	s--; t--;
	rep(i, 0, m) {
		ll u,v,a,b;
		cin >> u >> v >> a >> b;
		u--; v--;
		edges_y[u].pb({v,a});
		edges_y[v].pb({u,a});
		edges_s[u].pb({v,b});
		edges_s[v].pb({u,b});
	}

	dijkstra_y(s);
	dijkstra_s(t);

	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>cost;
	//中継点を全探索
	rep(i, 0, n) {
		ll c1 = d_y[i];
		ll c2 = d_s[i];
		cost.push({c1+c2,i});
	}

	//i年後
	rep(i, 0, n) {
		while (1) {
			auto p = cost.top();
			if (p.second+1 <= i) {
				cost.pop();
			}
			else {
				break;
			}
		}
		auto ans = cost.top();
		cout << 1000000000000000 - ans.first << endl;
	}


	return 0;
}

Measured memory_bytes: 19964
// =====================================================================================
//
//       Filename:  atcoder.cpp
//
//    Description:  
//
//        Version:  1.0
//        Created:  26/04/20 03:38:51 AM IST
//       Revision:  none
//       Compiler:  g++
//
//         Author:  Kiran Bhanushali (), kiranbhanushali143.kb143@gmail.com
//   Organization:  
//
// =====================================================================================

#include<bits/stdc++.h>


using namespace std;

#define int long long 
#define pb push_back
//#define _SHOW_TIME

void solve(){
    int x;
    cin>>x;
    cout<<(x-1)*(x)/2<<endl;
}
int32_t main(){
 /////////////////////////////////////
    #ifdef _SHOW_TIME
	int tt = (int) clock();
    #endif
    /////////////////////////////////////
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /////////////////////////////////////
    solve();
    /////////////////////////////////////
    #ifdef _SHOW_TIME
        cerr << "TIME = " << (double)(clock() - tt) / CLOCKS_PER_SEC << endl;
    #endif
    /////////////////////////////////////
    return 0;

}



Measured memory_bytes: 256
#include <stdio.h>
 
int ans;
int p,q,a,n;
 
void DFS (int cnt,int count,int tp,int tq,int mul)
{//已搜索到分母,个数,分数当前和分子,分母,乘积
	if (mul>a) return;
	if (p*tq==q*tp && tq!=0)
	{//找到
		ans++;
		return;
	}
	if (count>=n) return;  //个数超
	if (p*tq<q*tp) return; //比原来大
	int x,y;
	if (tq)
	{
		x=tq+cnt*tp;
		y=cnt*tq;
	}
	else x=1,y=cnt;
	if (mul*cnt<=a)
		DFS (cnt,count+1,x,y,mul*cnt);
	if (cnt+1<=a && mul*(cnt+1)<=a) //剪枝
		DFS (cnt+1,count,tp,tq,mul);
}
 
void dfs (int p,int q,int x,int dep,int mul)
{//参考acm.hust.edu.cn/vjudge/problem/viewSource.action?id=199708
	if (p==0 && mul<=a)
	{
		ans++;
		return;
	}
	if (dep==0 || p*x>q*dep || mul*x>a) return;
	
	for (int i=x;i<=a;i++)
		if (mul*i<=a)
		{
			int nt=p*i-q;
			if (nt>=0)
				dfs (nt,q*i,i,dep-1,mul*i);  
		}
		else break;
}
 
int main ()
{
	while (scanf("%d %d %d %d",&p,&q,&a,&n), p||q||a||n)
	{
		ans=0;
		dfs (p,q,1,n,1);   //219ms
		printf("%d\n",ans);
	}
	return 0;
}




Measured memory_bytes: 2036
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    double r;
    cin >> r;

    cout << setprecision(20)  << r*2.*3.1415926535 << endl;

    return 0;
}


Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
class Dice{
  private:

  vector<int> num;

  public:

  Dice(vector<int> input):num(input){};

  void operate(int cmd){
    vector<int>ret = num;
    if(cmd == 0){ //E方向
      ret[0] = num[3]; 
      ret[2] = num[0]; 
      ret[5] = num[2]; 
      ret[3] = num[5]; 
    }
    if(cmd == 1){ // N方向
      ret[0] = num[1];
      ret[1] = num[5];
      ret[5] = num[4];
      ret[4] = num[0];
    }
    if(cmd == 2){// S方向
      ret[1] = num[0];
      ret[5] = num[1];
      ret[4] = num[5];
      ret[0] = num[4];
    }
    if(cmd == 3){ // W方向
      ret[3] = num[0]; 
      ret[0] = num[2]; 
      ret[2] = num[5]; 
      ret[5] = num[3]; 
    }
    num = ret;
  }
  static int dir(char c){
    if(c == 'E')return 0;
    if(c == 'N')return 1;
    if(c == 'S')return 2;
    if(c == 'W')return 3;
  }
  int top(){
    return num[0];
  }
  void print(){
    for(int i = 0; i < 6; i++){
      cout << num[i] << " ";
    }
    cout << endl;
  }
  vector<int> nums(){
    return num;
  }
  using F = function<bool(vector<int>)>;
  vector<int> search(const F &check){
    int limit = 1;
    for(int i = 0; i < 4; i++)limit *= 4;
    for(int i = 0; i < limit; i++){
      vector<int>cmd_num(4);
      int n = i;
      for(int j = 0; j < 4; j++){
        cmd_num[j] = n % 4;
        n >>= 2;
      }
      Dice copy = *this;
      for(int j = 0; j < 4; j++){
        for(int k = 0; k < cmd_num[j]; k++){
          copy.operate(j);
        }
      }
      if(check(copy.nums()))return copy.nums();
    }
  }
};

int main(){
  vector<int>a(6);
  for(int i = 0; i < 6; i++)cin >> a[i];
  Dice dice(a);
  int q;
  cin >> q;
  while(q--){
    int x, y;
    cin >> x >> y;
    auto check = [&](vector<int>num){
      return num[0] == x && num[1] == y;
    };
    auto v = dice.search(check);
    cout << v[2] << endl;
  }
}


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

typedef long long ll ;
#define pb push_back
ll ans[200][200006] ;
vector<ll> w , v ;

ll n , cap ;

ll knp(ll id , ll wi){

    if (id==n+1)
        return 0 ;
    else if (ans[id][wi]!=-1) return ans[id][wi] ;
    if (wi+w[id]<=cap) {
        ans[id][wi] = v[id] + knp (id+1,wi+w[id]) ;
    }
    return ans[id][wi] = max(ans[id][wi], knp (id+1,wi)  ) ;

}

int main() {

    ll i ,j;
    cin >> n >> cap ;
    w.resize(n+2) ;
    v.resize(n+2) ;

    for(i=1;i<=n;i++)   cin >> w[i] >> v[i] ;

    for(i=0;i<=n;i++) for(j=0;j<=cap;j++) ans[i][j] = -1 ;
    cout << knp(1,0) << endl ;
   // for(i=0;i<=n;i++) { for(j=0;j<=cap;j++) cout << ans[i][j] << ' ' ;cout << endl ;}
   // cout << ans[1][0] << endl ;

    return 0 ;


}


Measured memory_bytes: 157184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    ll n, k, q; cin >> n >> k >> q;
    vector<ll> a(n);
    for(int i=0; i<n; i++){
        a[i] = 0;
    }
    for(int i=0; i<q; i++){
        ll tmp; cin >> tmp;
        a[tmp-1] += 1;
    }
    for(int i=0; i<n; i++){
        if(a[i] > q-k){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
from heapq import heappush, heappop

n, m = map(int, input().split())
jobs = {}
for i in range(n):
    a, b = map(int, input().split())
    if a > m:
        continue
    k = m - a
    if k not in jobs:
        jobs[k] = []
    jobs[k].append(b)
h = []
ans = 0
for i in range(m - 1, -1, -1):
    if i in jobs:
        for b in jobs[i]:
            heappush(h, -b)
    if len(h) > 0:
        ans += -heappop(h)
print(ans)

Measured memory_bytes: 27344
MOD = 10 ** 9 + 7

N, M, K = map(int, input().split())

def f(x):
    return (x * (x + 1) * (x - 1)) // 6 % MOD

tmp = (N * N * f(M)) % MOD + (M * M *f(N)) % MOD

class Factorial:
    def __init__(self, n, mod):
        self.f = [1]
        self.mod = mod
        for j in range(1, n + 1):
            self.f.append(self.f[-1] * j % mod)
        self.i = [pow(self.f[-1], mod - 2, mod)]
        for j in range(n, 0, -1):
            self.i.append(self.i[-1] * j % mod)
        self.i.reverse()
    def factorial(self, j):
        return self.f[j]
    def ifactorial(self, j):
        return self.i[j]
    def comb(self, n, k):
        return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0


c = Factorial(N * M - 2, MOD).comb

tmp *= c(N * M - 2, K - 2)
tmp %= MOD

print (tmp)


Measured memory_bytes: 18964
#include<bits/stdc++.h>
#define ha 1000000007
#define fuck {puts("0");return 0;}
using namespace std;

const int N=100010;
int nxt[N],n;
int pre[N][2];
int ring[N],f[N];
bool vis[N];

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",nxt+i);
        if(!pre[nxt[i]][0]) pre[nxt[i]][0]=i;
        else if(!pre[nxt[i]][1]) pre[nxt[i]][1]=i;
        else fuck
    }
    int ans=1;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]) continue;
        int j=i,sz=0;
        while(!vis[j])
            vis[j]=1,j=nxt[j];
        int p=j,q;
        do{
            sz++;q=nxt[p];
            if(pre[q][0]!=p)
                swap(pre[q][0],pre[q][1]);
        }while((p=q)!=j);
        bool flag=1;int cur=1;
        do{
            if(!pre[p][1]) continue;
            int a=pre[p][0],b=pre[p][1];
            flag=0;vis[b]=1;
            while(pre[b][0])
            {
                if(pre[a][1]||pre[b][1]) fuck
                a=pre[a][0];b=pre[b][0];vis[b]=1;
            }
            if(!pre[a][1]) (cur<<=1)%=ha;
        }while((p=nxt[p])!=j);
        if(flag) ring[sz]++;
        else ans=1ll*ans*cur%ha;
    }
    for(int i=1;i<=n;i++)
    {
        bool flag=(i&1)&&(i!=1);
        f[0]=1;f[1]=flag+1;
        for(int j=2;j<=ring[i];j++)
            f[j]=(1ll*f[j-2]*(j-1)%ha*i+(f[j-1]<<flag))%ha;
        ans=1ll*ans*f[ring[i]]%ha;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
	int n, c = 0;
	bool b[8] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a >= 3200)c++;
		else b[a / 400]++;
	}
	int mi = 0;
	for (int i = 0; i < 8; i++) {
		if (b[i])mi++;
	}
	cout << max(1, mi) << " " << mi + c << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
N, X, M = map(int, input().split())
from collections import defaultdict
check = defaultdict(int)
L = [0,X]
L_ans = [0,X]
roop_end = 0

ans = X

old_a = X
for i in range(2,N+1):
  a = (old_a**2)%M
  ans += a
  old_a = a
  L.append(a)
  L_ans.append(ans)
  
  if check[a] != 0:
    roop_first = check[a]
    roop_end = i
    roop_iter = roop_end - roop_first
    ans = L_ans[roop_first - 1]
    roop_first_ans = L_ans[roop_first]
    roop_end_ans = L_ans[roop_end]
    roop_plus = roop_end_ans - roop_first_ans
    break
  else:
    check[a] = i
if roop_end == 0:
  print(ans)
else:
  roop_phase = N - roop_first + 1
  roop_num = roop_phase // roop_iter
  ans += roop_plus * roop_num
  roop_addition = roop_phase % roop_iter
  addition = L_ans[roop_first - 1 + roop_addition] - L_ans[roop_first - 1]
  ans += addition
  print(ans)

Measured memory_bytes: 18592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		print();
	}

	private static void print() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int x = Integer.valueOf(str);

		int multiple = x * x * x;
		System.out.println(multiple);
	}

}

Measured memory_bytes: 24296
#include <bits/stdc++.h> 
using namespace std;
typedef vector<int> int_vector;
typedef vector<long> long_vector;
typedef vector<double> double_vector;

typedef vector< vector<int> > int_matrix;
typedef vector<string> string_vector;
typedef vector< vector<string> > string_matrix;
double_vector mps;

int fac(int n, int_vector &memo){
    int f;
    if (memo[n] != -1) return memo[n];
    else if (n==1) f=1;
    else f = n*fac(n-1, memo);
    memo[n] = f;
    return f;
    }

int order(int n, int_vector &v, int_vector &memo){
    int s=1;

    for (size_t i = 0; i < n; i++)
    {
        int cnt=0;
        for (size_t j = i+1; j < n; j++)
        {
            if (v[i] > v[j]) cnt++;
        } 
        
        s+=cnt*fac((n-i-1), memo);
    }
    return s;
}



int main(){
    int n;
    cin >> n;
    int_vector ps,qs, memo(n, -1);
    for (size_t i = 0; i < n; i++)
    {
        int p;
        cin >> p;
        ps.push_back(p);
    }

    for (size_t i = 0; i < n; i++)
    {
        int q;
        cin >> q;
        qs.push_back(q);
    }

    cout << abs(order(n, ps, memo) - order(n, qs, memo))<< endl;
 
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x, i, j;

	scanf("%d", &x);

	for (i = 1; i * i <= x; i++)
		if (x % i == 0)
		{
			int k = i, other = x / i;

			for (j = -1000; j <= 1000; j++)
			{
				int calc = (j + k) * (j + k) * (j + k) * (j + k) + (j + k) * (j + k) * (j + k) * j + (j + k) * (j + k) * j * j + (j + k) * j * j * j + j * j * j * j;

				if (calc == other)
				{
					printf("%d %d", j + k, j);
					return 0;
				}
			}
		}
	return 0;
}

Measured memory_bytes: 1736