akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    char x, y;
    cin >> x >> y;
    if (x > y) {
        cout << ">" << endl;
    } else if (x == y) {
        cout << "=" << endl;
    } else {
        cout << "<" << endl;
    }
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long N,i,sum=0;
    cin >> N;
    long long a[N];
    for(i=0;i<N;i++){
        cin >> a[i];
        sum += a[i];
    }
    long long d=1000000,samune=-1;
    for(i=0;i<N;i++){
        if(a[i]*N<sum){
            if(d>sum-a[i]*N){
                samune=i;
                d=sum-a[i]*N;
            }
        }else{
            if(d>a[i]*N-sum){
                samune=i;
                d=a[i]*N-sum;
            }
        }
    }
    cout << samune << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef vector <int> vi;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=100005;
int n;
int Ask(int x){
	cout<<x<<endl;
	fflush(stdout);
	string res;
	cin>>res;
	if (res=="Vacant")
		exit(0);
	return res=="Male";
}
void Solve(int lv,int rv,int L,int R){
	int mid=(L+R)>>1,lenL=mid-L,lenR=R-mid;
	int v=Ask(mid);
	if ((lv^v)==(lenL&1))
		Solve(lv,v,L,mid-1);
	else
		Solve(v,rv,mid+1,R);
}
int main(){
	n=read();
	int s=Ask(0);
	Solve(s,s,1,n-1);
	return 0;
}


Measured memory_bytes: 852
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int h, n;
    scanf("%d%d", &h, &n);
    std::vector<std::pair<int, int>> magics(n);
    for(auto &&p : magics) std::cin >> p.first >> p.second;
    constexpr int MAX_N = 1000, MAX_H = 10000;
    // dp配列 dp[i][h]:魔法i以下のものを使って，体力をへらすために必要な魔力の最小値
    std::vector<i64> dp(2 * MAX_H + 10, 1LL << 30);
    dp[0] = 0;  // 体力を0へらすには0でいい
    rep(i, n) {
        rep(j, 2 * MAX_H) {
            if(j >= magics[i].first) {
                dp[j] = std::min(dp[j], dp[j - magics[i].first] + magics[i].second);
            }
        }
    }
    std::cout << *std::min_element(dp.begin() + h, dp.end()) << std::endl;
}

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

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;
 
#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 REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

#define MOD 1000000007LL

long long pow_mod(long long n, long long k, long long mod) {
    long long ret = 1, a = n % mod;
    while (k > 0) {
        if (k & 1) ret = (ret * a) % mod;
        a = (a * a) % mod;
        k >>= 1;
    }
    return ret;
}


int main() {
    
    ll n,k;
    cin >> n >> k;

    cout << pow_mod(n,k,MOD) << endl;

    return 0;
}

Measured memory_bytes: 3124
import math

mod = 10**9+7
def fur(n,r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod) % mod

n,a,b = map(int, input().split())
s = pow(2,n,mod)

print((s-fur(n,a)-fur(n,b)-1)%mod)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
typedef long long ll;

int f(int n){
    if(n%2 == 0) return n/2;
    else return n*3+1;
}

int main(){
    int s; cin >> s;
    int a = s;
    bool flag[1000001] = {false};

    for(int i = 1;; ++i){
        if(flag[a]){
            cout << i << endl;
            return 0;
        }
        flag[a] = true;
        a = f(a);
    }
}


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

int main() {
  int A, B, C;
  cin >> A >> B >>C;
  if (A + B + C != 17) {
    cout << "NO" << endl;
  } else if ((A == 5 || A == 7) && (B == 5 || B == 7) && (C == 5 || C ==7)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

using namespace std;

int main(){
    int n,flag=0;
    while(cin>>n,n){
        if(flag)cout<<endl;
        int m[4],c[4]={10,50,100,500},k[4]={};
        for(int i=0;i<4;++i){
            cin>>m[i];
        }
        for(int i=0;i<4;++i){
            n-=m[i]*c[i];
            k[i]+=m[i];
            if(i==3){
                k[3]-=(-n)/500;
                n+=((-n)/500)*500;
                k[2]-=(-n)/100;
                n+=((-n)/100)*100;
                k[1]-=(-n)/50;
                n+=((-n)/50)*50;
                k[0]-=(-n)/10;
                n+=((-n)/10)*10;
                break;
            }
        }
        for(int i=0;i<4;++i){
            if(k[i]<=0)continue;
            printf("%d %d\n",c[i],k[i]);
        }
        flag++;
    }
}

Measured memory_bytes: 3200
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  ;; (return-from read-fixnum 0)
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (table (make-array 100003 :element-type 'uint32)))
    (declare (uint32 n))
    (dotimes (i n) (let ((a (read-fixnum)))
                     (incf (aref table a))
                     (incf (aref table (+ a 1)))
                     (incf (aref table (+ a 2)))))
    (println (reduce #'max table))))

#-swank(main)


Measured memory_bytes: 22240
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))

op = []
for i in range(m):
    b, c = map(int, input().split())
    op.append((c, b))

op.sort(reverse=True)

j = 0
k = 0

for i in range(n):
    if a[i] >= op[j][0]:
        break

    a[i] = op[j][0]
    k += 1

    if k >= op[j][1]:
        j += 1
        k = 0

    if j >= m:
        break

print(sum(a))

Measured memory_bytes: 71576
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int x;cin >> x;
	auto check = [&](int n){
		if(n == 1)return true;
		for(int i = 2;i <= n;i++){
			for(int j = i*i;j <= n;j*=i){
				if(j == n)return true;
			}
		}
		return false;

	};
	for(int i = x;i >= 1;i--){
		if(check(i)){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define ll long long 
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//typedef long long  MOD=1000000009;
ll MOD=998244353;
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll lcm(ll x, ll y) {ll res = (x * y) / __gcd(x, y); return res;}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}

void iofoj(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}


void solution()
{
    ll k,i,j,h,n,m,w;
   cin>>n;
   ll a[n];
   for(i=0;i<n;i++)
   cin>>a[i];
    ll ans=0;
    ll maxi=a[0];
    for(i=1;i<n;i++)
    {
        if(a[i]>=maxi)
        {
            maxi=a[i];
        }
        else
        {
            ans+=maxi-a[i];
        }
    }
    cout<<ans;
}

int main(){
    fio
    //iofoj();
    // ll t;
    // cin>>t;
    // while(t--)
    solution();
    return 0; 
}





Measured memory_bytes: 5212
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
using namespace std;
const int maxn = 2e5+5;
int a[maxn];

int main(){
	int n; cin >> n;
	int x;
	for(int i = 2; i <= n; i++){
		cin >> x;
		a[x]++;
	}
	for(int i = 1; i <= n; i++){
		cout << a[i] << endl;
	}
}

Measured memory_bytes: 4428
N = int(input())
S = []
for i in range(N):
    S.append(input())

M = int(input())
T = []
for i in range(M):
    T.append(input())


from collections import Counter
c1 = Counter()
c2 = Counter()

for si in S:
    c1[si] += 1

for ti in T:
    c2[ti] += 1

# print(c1)
# print(c2)

ans = 0
for si in c1.keys():
    ans = max(ans, c1[si] - c2[si])

print(ans)

Measured memory_bytes: 3316
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		int p = 0;
		for(int i=0; i<n; i++){
			if(a[i]=='1'){
				p = i;
				break;
			}
		}
		System.out.println((n-1)%(k-1)==0 ? (n-1)/(k-1) : (n-1)/(k-1)+1);
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
const int N = 1e5 + 5;
ll n, m, sum;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    deque<ll>dq(n);
    vector<pll>v(m);
    for(int i = 0;i < n;++i)
        cin >> dq[i], sum += dq[i];
    for(int i = 0;i < m;++i)
        cin >> v[i].S >> v[i].F;
    sort(dq.begin(), dq.end());
    sort(v.rbegin(), v.rend());
    for(auto &it : v)
    {
        while(dq.size() && dq[0] < it.F && it.S)
        {
//            cout << dq[0] << ' ' << it.F << '\n';
            sum -= dq[0];
            dq.pop_front();
            sum += it.F;
            it.S--;
        }
    }
    cout << sum;
    return 0;
}


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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")   */


//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 2e6 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 2e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

int a[N];

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, s;
    cin >> n >> s;
    int ans =  0;
    for (int i = 0; i < n; i++) cin >> a[i];
    vi dp(s + 1, 0);
    for (int i = 0; i < n; i++) {
        int x = a[i];
        vi tek(s + 1, 0);
        for (int j = 0; j < s; j++) {
            if (j == 0 && x <= s) {
                tek[x] = i + 1;
            }
            else {
                if (i) {
                    tek[j] += dp[j];
                    if (j + x <= s) {
                        tek[j + x] += dp[j];
                        tek[j + x] %= mod;
                    }
                    tek[j] %= mod;
                }
            }
        }
        dp = tek;
        ans += dp[s] * (n - i);
        //cout << ans << ' ';
        ans %= mod;
    }
    cout << ans;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

char S[10];

inline bool check(char temp)
{
    return (temp == 'A' || temp == 'T' || temp == 'C' || temp == 'G');
}

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

    cin >> S;

    int ret = 0;

    int r;
    int l;
    for (l = 0; S[l]; ++l)
    {
        if (check(S[l]))
        {
            for (r = l; S[r] && check(S[r]); ++r);
            ret = MAX(ret, r - l);
        }
    }

    cout << ret << "\n";

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define printP(x) "(" << (x).first << ", " << (x).second << ")"
#define mod 1000000007
using namespace std;
typedef pair<llint, llint> P;

llint n, m;
vector<P> vec[305];
llint dp[305][305][305];

bool check(llint r, llint j, llint k)
{
	for(int i = 0; i < vec[r].size(); i++){
		llint l = vec[r][i].first, x = vec[r][i].second, c = 1;
		if(l <= j) c++;
		if(l <= k) c++;
		if(x != c) return false;
	}
	return true;
}

int main(void)
{
	cin >> n >> m;
	llint l, r, x;
	for(int i = 1; i <= m; i++){
		cin >> l >> r >> x;
		vec[r].push_back(P(l, x));
	}
	
	dp[0][0][0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= n; k++){
				if(!check(i, j, k)) continue;
				(dp[i+1][j][k] += dp[i][j][k]) %= mod;
				(dp[i+1][i][k] += dp[i][j][k]) %= mod;
				(dp[i+1][i][j] += dp[i][j][k]) %= mod;
			}
		}
	}
	llint ans = 0;
	for(int j = 0; j <= n; j++){
		for(int k = 0; k <= n; k++){
			if(check(n, j, k)) ans += dp[n][j][k], ans %= mod;
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 218624
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,n,m,k,x,y,z;
    // cin>>T;
    while(T--)
    {
        string a,b,c;
        cin>>a>>b>>c;
        n = a.length();
        m = b.length();
        k = c.length();
        x = 0; y = 0; z = 0;
        char cur = 'a';
        while(x<=n&&y<=m&&z<=k)
        {
            if(cur=='a')
            {
                x++;
                cur = a[x-1];
            }
            else if(cur=='b')
            {
                y++;
                cur = b[y-1];
            }
            else
            {
                z++;
                cur = c[z-1];
            }
        }
        if(x>n)
            cout<<'A';
        else if(y>m)
            cout<<'B';
        else
            cout<<'C';
        cout<<endl;
    }
}

Measured memory_bytes: 3604
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
cnt4=0
cnt2=0
for i in range(N):
    if A[i]%4==0:
        cnt4+=1
    elif A[i]%2==0:
        cnt2+=1
wst=N-cnt4-cnt2
wst+=cnt2%2
#print(wst,cnt4)
if (wst+cnt4)%2==0:#偶数のとき
    if wst<=cnt4:
        print('Yes')
    else:
        print('No')
else:#奇数のとき
    if wst+1>=cnt4:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 62576
#A:Pay to Win
import sys
sys.setrecursionlimit(10 ** 9)

t = int(input())
a,b,c,d = 0,0,0,0
p = {}
INF = float('inf')

def calc(x):
  global a,b,c,d,p
  #print(x)
  if x in p:
    return p[x]
  if x == 1:
    res = d
  else:
    res = INF
    if x%2 == 0:
      res = min(min(a,d*(x-x//2))+calc(x//2),res)
    else:
      res = min(min(a+d*(2-x%2),d*(x-(x+2-x%2)//2))+calc((x+2-x%2)//2),res)
      if x-x%2 > 0:
        res = min(min(a+d*(x%2),d*(x-(x-x%2)//2))+calc((x-x%2)//2),res)
    if x%3 == 0:
      res = min(min(b,d*(x-x//3))+calc(x//3),res)
    else:
      res = min(min(b+d*(3-x%3),d*(x-(x+3-x%3)//3))+calc((x+3-x%3)//3),res)
      if x-x%3 > 0:
        res = min(min(b+d*(x%3),d*(x-(x-x%3)//3))+calc((x-x%3)//3),res)
    if x%5 == 0:
      res = min(min(c,d*(x-x//5))+calc(x//5),res)
    else:
      res = min(min(c+d*(5-x%5),d*(x-(x+5-x%5)//5))+calc((x+5-x%5)//5),res)
      if x-x%5 > 0:
        res = min(min(c+d*(x%5),d*(x-(x-x%5)//5))+calc((x-x%5)//5),res)
  if x in p:
    p[x] = min(p[x],res)
  else:
    p[x] = res
  return res

def solve():
  global a,b,c,d,p
  n,a,b,c,d = map(int,input().split())
  p = {}
  #print(calc(n))
  #print(min(calc(n),calc(n+2-n%2)+d*(2-n%2),calc(n+3-n%3)+d*(3-n%3),calc(n+5-n%5)+d*(5-n%5),n*d))
  print(min(calc(n),n*d))

for i in range(t):
  solve()

Measured memory_bytes: 91932
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF (1LL << 60)
using namespace std;
typedef long long ll;

ll N, A, B, Q, X, Y, Z;

template<typename T> class SegmentTree {
public:
  ll n;
  T e;
  T (*op)(T, T);
  vector<T> dat;

  SegmentTree(T _e, T(*_op)(T, T), ll _n) {
    e = _e;
    op = _op;
    n = 1;
    while(n < _n) n *= 2;
    REP(i, 0, 2 * n - 1) dat.push_back(e);
  }

  T query(ll a, ll b) { return rquery(a, b, 0, 0, n); };

  void update(ll k, T a) {
    k += n - 1;
    dat[k] = a;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k] = op(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

private:
  T rquery(ll a, ll b, ll k, ll l, ll r) {
    if(r <= a || b <= l) return e;
    if(a <= l && r <= b) return dat[k];
    T vl = rquery(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = rquery(a, b, k * 2 + 2, (l + r) / 2, r);
    return op(vl, vr);
  }
};

ll opmin(ll a, ll b) { return min(a, b); };

int main(void) {
  SegmentTree<ll> sa(INF, opmin, 200000), sb(INF, opmin, 200000);

  cin >> N;
  REP(i, 0, N) {
    cin >> A;
    sa.update(i, A);
  }
  REP(i, 0, N) {
    cin >> B;
    sb.update(i, B);
  }
  cin >> Q;

  vector<ll> u;
  REP(i, 0, N) u.push_back(i);

  REP(q, 0, Q) {
    cin >> X >> Y >> Z;
    if(X == 1) { // update A[Y] = Z
      sa.update(Y - 1, Z);
      u.push_back(Y - 1);
    }
    if(X == 2) { // update B[Y] = Z
      sb.update(Y - 1, Z);
      u.push_back(Y - 1);
    }
    if(X == 3) { // max(A[Y], ..., A[Z])
      cout << sa.query(Y - 1, Z) << endl;;
    }
    if(X == 4) { // max(B[Y], ..., B[Z])
      cout << sb.query(Y - 1, Z) << endl;
    }
    if(X == 5) { // copy A <- B
      REP(i, 0, u.size()) sa.update(u[i], sb.dat[u[i] + sb.n - 1]);
      u.clear();
    }
    if(X == 6) { // copy B <- A
      REP(i, 0, u.size()) sb.update(u[i], sa.dat[u[i] + sa.n - 1]);
      u.clear();
    }
  }
}

Measured memory_bytes: 14776
def CountFrequency(my_list,n): 
  
    # Creating an empty dictionary  
    freq = {}
    for  i in range(1,n+1):
    	freq[i]=0

    for item in my_list: 
        if (item in freq): 
            freq[item] += 1
        else: 
            freq[item] = 1
  
    for key, value in freq.items(): 
        print (value)
  
# Driver function 
if __name__ == "__main__":  
    n=int(input())
    l=list(map(int,input().split())) 
  
    CountFrequency(l,n) 


Measured memory_bytes: 38800
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while(true) {
            int H = sc.nextInt();
            int W = sc.nextInt();

            if(H == 0 && W == 0) {
                break;
            }

            for(int i = 0; i < H; i++) {
                for(int j = 0; j < W; j++) {
                    System.out.print("#");
                }

                System.out.print("\n");
            }

            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 38448
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toLong).sorted()
    println("${aList.last()} ${aList.take(n - 1).minBy { Math.abs(aList.last().toDouble() / 2 - it) }!!}")
}

Measured memory_bytes: 76084
import           Control.Monad.Writer
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

main = do
  BS.getLine
  a <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  b <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ solve $ Cities a b

solve :: Cities -> Int
solve cities = getSum killResult
  where
    (_, killResult) = runWriter $ killThemAll cities

type MonsterCount = Int

type SavePower = Int

type KillResult = Sum Int

data Cities =
  Cities
    { monsterCounts :: [MonsterCount]
    , saverPowers   :: [SavePower]
    }

killThemAll :: Cities -> Writer KillResult ()
killThemAll Cities {saverPowers = []} = writer ((), Sum 0)
killThemAll cities = do
  cities1 <- firstSaverSaveFirstCity cities
  cities2 <- firstSaverSaveSecondCity cities1
  killThemAll $ restCities cities2
  where
    firstSaverSaveFirstCity :: Cities -> Writer KillResult Cities
    firstSaverSaveFirstCity Cities {monsterCounts = m:ms, saverPowers = s:ss} =
      writer (Cities (mAfter : ms) (sAfter : ss), killCount)
      where
        (mAfter, sAfter, killCount) = kill m s
    firstSaverSaveSecondCity :: Cities -> Writer KillResult Cities
    firstSaverSaveSecondCity Cities { monsterCounts = m1:m2:ms
                                    , saverPowers = s:ss
                                    } =
      writer (Cities (m1 : m2After : ms) (sAfter : ss), killCount)
      where
        (m2After, sAfter, killCount) = kill m2 s
    kill :: MonsterCount -> SavePower -> (MonsterCount, SavePower, KillResult)
    kill monsterCount savePower =
      (monsterCount - killCount, savePower - killCount, Sum killCount)
      where
        killCount = min monsterCount savePower
    restCities :: Cities -> Cities
    restCities Cities {monsterCounts = m:ms, saverPowers = s:ss} = Cities ms ss


Measured memory_bytes: 12412
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7; 
int main()
{
    int n;
    cin>>n;
    long long sum=0;
    long long count=0;
    long long a[N];
    long long  minn=1e15; 
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    count+=a[1]; 
    for(int i=2;i<=n;i++)
    {
        minn=min(minn,abs(sum-count*2));
        count+=a[i];
    }
    cout<<minn<<endl;
    return 0;
} 

Measured memory_bytes: 1792
#include<stdio.h>
int main(void) {

	//Input
	int N, X;
	scanf("%d",&N);
	scanf("%d",&X);
	int L[N], i;
	for (i = 0; i < N; i++) {
		scanf("%d",&L[i]);
	}

	int D[N + 1], n = 1;
	D[0] = 0;
	for (i = 1; i < N + 1; i++) {
		D[i] = D[i - 1] + L[i - 1];
		if (D[i] <= X) {
			n += 1;
		}
	}


	printf("%d\n",n);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 100100;
int par[MAX_N]; // 親
int rank[MAX_N]; // 木の深さ

// n要素で初期化
void UFinit(){
    for(int i=0;i<MAX_N;i++){
        par[i] = i;
        rank[i] = 0;
    }
}

// 木の根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y){
    return find(x) == find(y);
}

int main(){
    int n, q;
    cin >> n >> q;
    UFinit();
    rep(i,q){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0){
            unite(x, y);
        }else{
            if(same(x, y)){
                cout << '1' << endl;
            }else{
                cout << '0' << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3904
/*
不要爆零！不要爆零！不要爆零！ 
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	int x;
	cin>>x;
	cout<<360*x/__gcd(x,360)/x<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

int main(){
  int max, min;
  int n, i, j;
  int *a = NULL;

  scanf("%d", &n);
  a = (int*)malloc(sizeof(int) * n);

  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  max = INT_MIN;
  min = a[0];
  for(i = 1; i < n; i++){
    if(max < a[i] - min){
      max = a[i] - min;
    }
    if(min > a[i]){
      min = a[i];
    }
  }

  printf("%d\n", max);

  return 0;
}


Measured memory_bytes: 2536
s = input()
x,y = map(int,input().split(" "))
l = [len(c) for c in s.split("T")]
X = l[::2]
Y = l[1::2]
 
ansX = set([X[0]])
for i in range(1,len(X)):
    ansX = set([c+X[i] for c in ansX]+[c-X[i] for c in ansX])
 
ansY = set([0])
for i in range(0,len(Y)):
    ansY = set([c+Y[i] for c in ansY]+[c-Y[i] for c in ansY])
    
if x in ansX and y in ansY:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4152
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=1e9+7,MAX=1e6+1;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n,k;
    cin>>n>>k;
    ll a[n];
    lp(i,0,n)
        cin>>a[i];
    ll beg=1,end=1e9,mid,res=1e15;
    while(beg<=end){
        mid=(beg+end)/2;
        ll cnt=0;
        lp(i,0,n)
            cnt+=(a[i]-1)/mid;
        if(cnt<=k)
            res=min(res,mid),end=mid-1;
        else
            beg=mid+1;
    }
    cout<<res;
}

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

using namespace std;

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

           if ( a >= k){ cout << k << endl; }
           else if (a + b >= k) { cout << a << endl; }
           else if (a + b + c > k) { cout << a-(k-a-b) << endl; }
           else   { cout << a-c << endl; }
            
        }

Measured memory_bytes: 3588
//minamoto
#include<bits/stdc++.h>
#define R register
#define fi first
#define se second
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=55,M=N*N*N;
typedef long long ll;
typedef pair<ll,int> pi;
pi q[M];ll f[M],w[N];int sz[N],fa[N],id[N],n,m,d,h,t,lim;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d%d",&n,&m,&d);
	fp(i,1,n){
		scanf("%lld",&w[i]),sz[i]=1,id[i]=i;
		if(i>1)scanf("%d",&fa[i]);
	}
	fd(i,n,2)sz[fa[i]]+=sz[i],w[fa[i]]+=w[i];
	sort(id+1,id+1+n,[](const int &x,const int &y){return sz[x]*w[y]>sz[y]*w[x];});
	memset(f,0x3f,sizeof(f));
	lim=min(d,50),f[0]=0;
	R int s=0;
	fp(i,1,n){
		R int ss=sz[i];R ll ww=w[i];
		s+=ss*lim;
		fp(j,0,ss-1){
			h=1,t=0;
			for(R int k=0,l=j;l<=s;l+=ss,++k){
				R pi vva(f[l]-k*ww,k);
				while(h<=t&&q[t].fi>=vva.fi)--t;
				q[++t]=vva;
				while(h<=t&&k-q[h].se>lim)++h;
				f[l]=q[h].fi+k*ww;
			}
		}
	}
	R ll res=0;
	d-=lim;
	fp(j,0,s)if(f[j]<=m){
		R ll cnt=j,ret=m-f[j];
		fp(i,1,n){
			R int x=id[i];
			if(x>1&&d<=ret/w[x])cnt+=d*sz[x],ret-=1ll*d*w[x];
				else cnt+=ret/w[x]*sz[x],ret%=w[x];
		}
		cmax(res,cnt);
	}
	printf("%lld\n",res);
	return 0;
}

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

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,c;
    cin>>n>>c;
    vector<vector<int>> count(c+1,vector<int>(100050));
    for(int i=0;i<n;++i){
        int s,t,ci;
        cin>>s>>t>>ci;
        count[ci][s]++;
        count[ci][t+1]--;
    }
    for(int i=0;i<100050;++i){
        for(int ci=0;ci<=c;++ci){
        count[ci][i+1] += count[ci][i];
        }
    }
    int ret = 0;
    for(int i=0;i<100050;++i){
        int tmp = 0;
        for(int ci=0;ci<=c;++ci){
            tmp += (count[ci][i]>0);
        }
        ret = max(ret,tmp);
    }
    cout << ret << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  int Alice = 0;
  int Bob = 0;
  
  for (int i = 0; i < N; i++) {
    int max = 0;
    
    int k = 0;
    
    for (int j = 0; j < N; j++) {
      if (a.at(j) > max) {
        max = a.at(j);
        k = j;
      }
    }
    
    if (i % 2 == 0) {
      Alice += max;
    }
    else {
      Bob += max;
    }
    
    a.at(k) = -1;
  }
  
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
 
using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back
 
typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, x;
    cin >> n >> m >> x;
    int a[112];
    rep(i, m) cin >> a[i];
    int cntp = 0, cntq = 0;
    for (int i = 0; i < m;i++){
        if(a[i]<x)
            cntp++;
            if(a[i]>x)
                cntq++;
    }
    cout<<min(cntp,cntq)<<endl;
    return 0;
}

Measured memory_bytes: 256
[n, m] = [int(x) for x in raw_input().split()]
A = []

counter = 0
while counter < n:
    A.append([int(x) for x in raw_input().split()])
    counter += 1

B = [int(raw_input()) for j in range(m)]

counter = 0
while counter < n:
    result = 0
    for j in range(m):
        result += A[counter][j] * B[j]
    print(result)
    counter += 1

Measured memory_bytes: 6448
// Answer by drken1215
// cf. http://drken1215.hatenablog.com/entry/2019/09/29/012000

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

vector< vector<int> > graph;
vector< vector<int> > revGraph;

int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;
  graph.resize(N);
  revGraph.resize(N);
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    --A; --B; // 0-indexed
    graph[A].push_back(B);
    revGraph[B].push_back(A);
  }

  int shortest = INF;
  vector<int> res;
  rep(s, N) {
    vector<int> dist(N, -1);
    vector<int> prev(N, -1);
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    int t = -1;
    while (!q.empty()) {
      auto v = q.front(); q.pop();
      for (auto nv : graph[v]) {
        if (nv == s) {
          t = v;
        }
        if (dist[nv] == -1) {
          dist[nv] = dist[v] + 1;
          prev[nv] = v;
          q.push(nv);
        }
      }
    }

    if (t >= 0) { // t is found.
      int d = dist[t] + 1; // cycle length
      if (d < shortest) {
        shortest = d;
        // Update res to the found shortest path.
        res.clear();
        int cur = t;
        while (cur != s) {
          res.push_back(cur);
          cur = prev[cur];
        }
        res.push_back(s);
      }
    }
  }

  if (shortest == INF) { // shortest is not updated. So, no cycle is found.
    cout << -1 << endl;
  } else {
    cout << res.size() << endl;
    for (auto v : res) {
      cout << v + 1 << endl; // shortest path
    }
  }
}


Measured memory_bytes: 384
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr())
MOD = 10 ** 9 + 7
length = int(A.max()).bit_length()
answer = 0
for i in range(length):
    B = (A >> i) & 1
    x = np.count_nonzero(B)
    y = N - x
    x *= y
    x *= 2 ** i
    answer += x % MOD

print(answer % MOD)
# 18

Measured memory_bytes: 48800
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(vec) vec.begin(),vec.end()
#define rep(i,n) for(ll i = 0;i<n;++i)
#define repc(bit,k,n) for (ll bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;cin>>n;
  vector<int>d(n);
  vector<int>ans(n+1,102);
  rep(i,n)cin>>d[i];
  sort(ALL(d));
  repi(itr, d){
    *lower_bound(ALL(ans),*itr) = *itr;
  }
  rep(i, n+1){
    if(ans[i]==102){
      cout<<i<<endl;
      break;
    }
  }

  return 0;
}

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

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    ll n; cin >> n;
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ans += (n - 1) / i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(4);
  
  for (int i = 0; i<N; i++){
    string tmp;
    cin >> tmp;
    if(tmp == "AC"){
      a[0]++;
    }else if(tmp == "WA"){
      a[1]++;

    }else if(tmp == "TLE"){
      a[2]++;

    }else{
      a[3]++;
    }

  }
  
  cout << "AC x " << a[0] << endl;
  cout << "WA x " << a[1] << endl;
  cout << "TLE x " << a[2] << endl;
  cout << "RE x " << a[3] << endl;

  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define int long long int
#define mpp make_pair
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define F first
#define S second
#define MOD 100007
#define in_range(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)
const int MAXN = 1e6+1;
#define MAXI 2e18+3
#define all(v) v.begin(), v.end()
#define endl "\n"
# define PI 3.14159265358979323846




signed main(){
 
    fast;
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int x, i, a1=-1, a2=-1, j;
    cin>>x;
    for(i=-200;i<=200;i++){
    	for(j=-200;j<=200;j++){
    		if(pow(i, 5)-pow(j, 5)==x){
    			a1=i;
    			a2=j;
    			break;
    		}
    	}
    }
    cout<<a1<<" "<<a2<<endl;
}

Measured memory_bytes: 4048
n = gets.to_i
n.times{
    p = gets.split.map(&:to_f)
    puts ((p[2] - p[0]) * (p[7] - p[5]) - (p[3] - p[1]) * (p[6] - p[4])).abs < 1e-11 ? "YES" : "NO"
}


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

int n;
int k;
int m;

int main() {
  cin >> n;
  int V[n];

  // int型の2次元配列(3×4要素の)の宣言
  vector<vector<int>> A(n, vector<int>(n));

  for (int i=0; i<n; i++) {
    cin >> V[i];
    cin >> k;
    if (k==0) {
      continue;
    } else {
      for (int j =0; j<k; j++) {
        cin >> m;
        A[i][m-1] = 1;
      }
    }
  }

  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      if (j == n-1) {
        cout << A[i][j] << endl;
      } else {
        cout << A[i][j] << " ";
      }
    }
  }
  



 
}


Measured memory_bytes: 3196
import math
N=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[abs(b[i]-a[i]) for i in range(N)]
print(sum(c))
print(math.sqrt(sum([c[i]**2 for i in range(N)])))
print((sum([c[i]**3 for i in range(N)]))**(1/3))
print(max(c))


Measured memory_bytes: 5696
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <functional>

typedef std::vector<std::vector<int>> graph;

std::vector<int> makescc(const graph& g)
{
	const int n = g.size();
	std::vector<int> num(n), low(n), scc(n, -1);
	std::stack<int> s;
	int index = 0;

	std::function<void(int)> visit = [&](int v) -> void {
		s.push(v);
		num[v] = low[v] = ++index;
		for (const int u : g[v]) {
			if (scc[u] == -1) {
				if (num[u] == 0) {
					visit(u);
				}
				low[v] = std::min(low[v], low[u]);
			}
		}

		if (num[v] == low[v]) {
			int u;
			do {
				u = s.top();
				s.pop();
				scc[u] = v;
			} while (u != v);
		}
	};

	for (int v = 0; v < n; ++v) {
		if (num[v] == 0) {
			visit(v);
		}
	}

	return scc;
}

int main()
{
	int V, E;
	std::cin >> V >> E;
	graph g(V);
	for (int i = 0; i < E; ++i) {
		int s, t;
		std::cin >> s >> t;
		g[s].push_back(t);
	}
	auto scc = makescc(g);

	int Q;
	std::cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int u, v;
		std::cin >> u >> v;
		std::cout << (scc[u] == scc[v]) << '\n';
	}
}

Measured memory_bytes: 4612
from fractions import gcd
def lcm(a,b):
	return a*b/gcd(a,b)
	
while 1:
	inp=map(int,raw_input().split())
	if inp[0]==0:break
	am=zip(inp[::2],inp[1::2])
	count=[0]*3
	for i in range(3):
		a,m=am[i]
		w,c=a%m,1
		while w!=1:
			w=a*w%m
			c+=1
		count[i]=c
	print reduce(lcm,count)

Measured memory_bytes: 5880
#include <iostream>
#include <cstdio>
#include <algorithm>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;



int n,k;

int const MAXN = 100010;


long long fac[MAXN], finv[MAXN], inv[MAXN];
long long A[MAXN];

// テーブルを作る前処理
void init_fac(ll MOD){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
    for (int i = 2; i < MAXN; 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;
    }
}

// 二項係数計算
ll modcomb( int n, int k, ll MOD ){
	if( n < k )	return 0;
	if( n < 0 || k < 0 )	return 0;
	return fac[n] * ( finv[k] * finv[n-k] % MOD ) % MOD;
}

bool cmp_reverse( int a, int b ){
	return a > b;
}



int main(){
	ll const MOD = 1000000007L;
	init_fac(MOD);

	std::cin >> n >> k;

	for( int i = 1; i <= n; i++ )
		std::cin >> A[i];

	

	ll maxsum = 0;
	ll minsum = 0;

	std::sort( A+1, A+1+n );
	for( int i = k; i <= n; i++ ){
		// maxsum = ( maxsum + A[i] * modcomb( i-1, k-1, MOD ) % MOD ) % MOD;
		maxsum = maxsum + ( A[i] * modcomb(i-1,k-1,MOD) ) % MOD;
		maxsum %= MOD;
		// printf("maxsum = %lld\n", maxsum);
	}

	std::sort( A+1, A+1+n, cmp_reverse );
	for( int i = k; i <= n; i++ ){
		// minsum = ( minsum + A[i] * modcomb( i-1, k-1, MOD ) % MOD ) % MOD;
		minsum = minsum + ( A[i] * modcomb(i-1,k-1,MOD) ) % MOD;
		minsum %= MOD;
	}
	
	// printf("maxsum = %lld, minsum = %lld\n", maxsum, minsum );
	// std::cout << (maxsum - minsum + MOD) % MOD << std::endl;
	if( maxsum >= minsum )
		std::cout << (maxsum - minsum) % MOD << std::endl;
	else
		std::cout << maxsum - minsum + MOD << std::endl;

}


Measured memory_bytes: 3328