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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N, res = 0;
	int64_t D;
	cin >> N >> D;

	forn(i, N)
	{
		int64_t x, y;
		cin >> x >> y;
		int64_t d = x * x + y * y;
		if (d <= D * D)
			++res;
	}
	cout << res;
	
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) swap(a, b);
	
	string ans;
	REP(i, b) ans += '0' + a;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#define MAX_INT 2100000000
using namespace std;
typedef long long int ll;
//#include "Header.h"

ll absint(ll a)
{
	return max(a, -a);
}

int main()
{
	static ll n, a[100000 + 10], i, j=0,mina=MAX_INT,sum=0;
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
		mina = min(mina, absint(a[i]));
		sum += absint(a[i]);
		if (a[i] < 0) j++;
	}
	if (j % 2) cout << sum - 2 * mina << endl;
	else cout << sum << endl;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    string S;
    int Q;
    cin >> S >> Q;
    deque<char> dque;
    for (auto c : S) {
        dque.push_back(c);
    }
    int order = 1;
    rep(i, Q) {
        int t;
        cin >> t;
        if (t == 1) {
            order *= -1;
        } else if (t == 2) {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                if (order == 1) {
                    dque.push_front(c);
                } else {
                    dque.push_back(c);
                }
            } else if (f == 2) {
                if (order == 1) {
                    dque.push_back(c);
                } else {
                    dque.push_front(c);
                }
            }
        }
    }
    if (order == -1) { reverse(all(dque)); }

    string ans = "";
    for (auto c : dque) {
        ans.push_back(c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int a[3003],b[3003];
int dp1[3003][3003]; // dp1[i][j] := 左からi番目まで見て時刻jまでに食べる時の最大の美味しさ
int dp2[3003][3003]; // dp2[i][j] := 右からi番目まで見て時刻jまでに食べる時の最大の美味しさ
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,t;
    cin >> n >> t;
    rep(i,n)cin >> a[i] >> b[i];
    rep(i,n){
        rep(j,3000){
            dp1[i+1][j] = dp1[i][j];
            if(j-a[i]>=0)chmax(dp1[i+1][j],dp1[i][j-a[i]]+b[i]);
        }
    }
    for(int i=n-1;i>=0;i--){
        rep(j,3000){
            dp2[i][j] = dp2[i+1][j];
            if(j-a[i]>=0)chmax(dp2[i][j],dp2[i+1][j-a[i]]+b[i]);
        }
    }
    int ans = 0;
    rep(i,n){
        rep(j,t){
            int x = b[i];
            x += dp1[i][j] + dp2[i+1][t-j-1];
            ans = max(ans,x);
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

int main()
{
  ll a, b;
  cin >> a;
  cin >> b;
  set<ll> s = {1, 2, 3};
  s.erase(a);
  s.erase(b);
  for (auto x : s)
  {
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define repss(name, start, stop, step) for (int name = start; name < stop; name += step)
#define reps(name, start, stop) repss(name, start, stop, 1)
#define rep(name, stop) reps(name, 0, stop)

using namespace std;

int main() {
  int A, B, C, X, Y;
  scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);

  int p1 = min(A + B, 2 * C);
  int p2 = min(A, 2 * C);
  int p3 = min(B, 2 * C);

  int t = min(X, Y);

  X -= t; Y -= t;

  printf("%d\n", X * p2 + Y * p3 + t * p1);
}

Measured memory_bytes: 256
def tyousei(a):
    tyousei_ = [0]
    for i in range(a):
        tyousei_.append(tyousei_[i]+i+1)
    return tyousei_[a]

s = input()
count = 0
length = 0

for i in range(len(s)):
    if s[i]=='B':
        length = length + i
        count = count + 1
    
print((len(s)-1)*count-length-tyousei(count-1))   

Measured memory_bytes: 12416
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define vz(x) x.size()
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
const int N = 1e6 + 10;
const int INF = 1e9 + 50;
const int MOD = 1e9 + 7;
int n, spf[N], factor[N];

void precompute() {
   for (int i = 0 ; i < N ; i++)
      spf[i] = i;
   for (int i = 2 ; i * i < N ; i++) {
      if (spf[i] != i) continue;
      for (int j = i * i ; j < N ; j += i) {
        spf[j] = min(spf[j] , i);
      }
   }
}


int freq[N];
int main() {
  precompute();
  in(n);
  int sol = 0;
  for (int c = 1 ; c < n ; c++) {
    int cur = n - c;
    if (cur == 1) {
      sol++;
    } else {
      vector <ii> kp;
      while (cur > 1) {
        freq[spf[cur]]++;
        if (freq[spf[cur]] == 1) {
          kp.pb({spf[cur] , 1});
        } else {
          kp.back().se++;
        }
        cur /= spf[cur];
      }
      int curAns = 1;
      for (ii x : kp) {
        freq[x.fi] = 0;
        curAns *= x.se + 1;
      }
      sol += curAns;
    }
  }
  printf("%d\n" , sol);
  return 0;
}

void in(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 11532
//Code By CXY07
#include<bits/stdc++.h>
using namespace std;

//#define FILE
//#define int long long
//#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fst first
#define scd second
#define inv(x) ksm(x,mod - 2)

const int MAXN = 2e5 + 10;
const int INF = 2e9;
const int G = 3;
const double PI = acos(-1);
//const int mod = 1e9 + 7;
//const int mod = 998244353;

int n,ans;
char s[MAXN];

template<typename T> inline void read(T &a) {
	a = 0; char c = getchar(); int f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') {a = a * 10 + (c ^ 48); c = getchar();}
	a *= f;
}

signed main () {
#ifdef FILE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	cin >> n;
	cin >> s + 1;
	int p1,p2; p1 = 1,p2 = n;
	while(p1 < p2) {
		while(s[p1] != 'W' && p1 <= n) p1++;
		while(s[p2] != 'R' && p2 >= 1) p2--;
		if(p1 < p2) swap(s[p1],s[p2]),ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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;}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k % 2)
  {
    if (abs(b-a) > 1e18) cout << "Unfair" << endl;
    else cout << b-a << endl;
  }
  else
  {
    if (abs(b-a) > 1e18) cout << "Unfair" << endl;
    else cout << a-b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define soja(i,a,n) for(ll i=a;i<=n;i++)
#define ulta(i,n,a) for(ll i=n;i>=a;i--)
#define pb push_back
int main()
{
   string a,b;
   ll n,m,k,sum=1000;
   cin>>a>>b;
   soja(i,0,a.size()-b.size())
{
  k=0;
  soja(j,0,b.size()-1)
{
if(b[j]!=a[i+j]) k++;
}

sum=min(sum,k);
}   
cout<<sum<<endl; 
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define eps 1e-8
ll n,k,a[200005],q,ans;
int main()
{  cin>>n;
   for(int i=1;i<=n;i++)
   {  int x;
      cin>>x;
      a[x]++;
      ans=ans+(long long int)x;
   }
   cin>>q;
   while(q--)
   {  ll b,c;
      cin>>b>>c;
      ll num=a[b];
      ans=ans+num*(c-b);
      a[b]=0;
      a[c]=a[c]+num;
      cout<<ans<<endl;
   }

}

Measured memory_bytes: 4336
/*
 * Author: Anmol Choudhary
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nextl cout<<"\n"
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<"["<<#x<<"="<<x<<"] , ["<<#y<<"="<<y<<"]"<<"\n"
const ll mod = 1000000007;
const ll maxn = 100005;
const ll mm = 1e+18;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
pair<ll,ll>go(ll n){
    vector<ll>v;
    while(n){
        v.pb(n%10);
        n/=10;
    }
    int x=v.si;
    pair<ll,ll>p;
    p.f=v[x-1];
    p.s=v[0];
    return p;
}
void solve()
{
    ll n;
    cin>>n;
    map<pair<ll,ll>,ll>mp;
    rep1(i,n){
        pair<ll,ll>p=go(i);
        //deb2(p.f,p.s);
        mp[p]++;
    }
    ll an=0;
    auto it=mp.beg;
    while(it!=mp.en){
        pair<ll,ll>p=it->first;
        pair<ll,ll>p1;
        p1.f=p.s;
        p1.s=p.f;
        an+=mp[p1]*it->second;
        ++it;
    }
    pr(an);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nextl;
    }
    return 0;
}


Measured memory_bytes: 256
A = int(input())
B = list(map(int,input().split(" ")))
C = list(map(int,input().split(" ")))
D = list(map(int,input().split(" ")))
count = 0
before = -2
full_percent = 0
for i in range(A):
    full_percent += C[B[count] - 1]
    if before + 1 == B[count]:
        full_percent += D[before - 1]
    before = B[count]
    count += 1
print(str(full_percent))

Measured memory_bytes: 3064
import math
if __name__ == '__main__':
    N = int(input())
    s = input().rstrip().split(' ')
    temp = [int(elem) for elem in s] 
    A = [-1]*(N+1)
    for i in range(2,N+1):
        A[i] = temp[i-2]

    assign = {}
    for i in range(2, N+1):
        if A[i] in assign:
            assign[A[i]] += 1
        else:
            assign[A[i]] = 1

    for i in range(1, N+1):
        if not i in assign:
            assign[i] = 0

    for i in range(1,N+1):
        print(assign[i])


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

int main() {
  int N;
  cin >> N;
  int over_3200 = 0;
  int flags = 0;
  int ans_min = 0;
  for (int i = 0; i < N; i++) {
    int rate;
    cin >> rate;
    if (rate >= 3200) {
      over_3200++;
    }
    else {
      int phase = rate / 400;
      int color_bit = 1 << phase;
      if (!(color_bit & flags)) {
        ans_min++;
        flags += color_bit;
      }
    }
  }
  int ans_max = ans_min;
  for (int i = 0; i < over_3200; i++) {
    ans_max++;
  }
  if (ans_min == 0) {
    ans_min++;
  }
  cout << ans_min << ' ' << ans_max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int N,K;
  cin>>N>>K;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  sort(ALL(vec));
  int res = 0;
  for (int i = 0; i < K; i++)
  {
    res += vec[i];
  }
  cout<<res<<endl;
  

  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3644
/// Love it~

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
#define x1 qeerdx
#define y1 qeerdy
 
#define lb lower_bound
#define ub upper_bound
 
#define endl '\n'
#define fast_in ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define mp  make_pair
#define pb  push_back
 
#define fi first
#define se second
 
#define   sz(x)  (int)x.size()
#define  all(x)  x.begin(), x.end()
#define  bit(x)  __builtin_popcountll(x)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair <string,ll> pii;
 
const int inf = (int) 1e9+99999, mod = (int)1e9+7;
const ll linf = (ll) 2e18+99999;
 
int kob (int x, int y) { return ((ll)x * y) % mod; } 
int aza (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int kos (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }
 
const int maxn = (int)1e6, maxn2 = (int) 1e6+55;
 
static long holdrand = 1L;
void srand(unsigned int seed){holdrand = (long) seed;} 
int rand() {return (((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);}

pair <pii, int> s[maxn];

bool cmp (pair <pii, int> a, pair <pii, int> b) {
	if (a.first.first > b.first.first)
		return 0;
	else if (a.first.first < b.first.first)
		return 1;
	else {
		if (a.first.second > b.first.second)
			return 1;
		else
			return 0;
	}
}

int main () {
	int n; cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> s[i].first.first >> s[i].first.second;
		s[i].second = i;
	}

	sort (s + 1, s + n + 1, cmp);

	for (int i = 1; i <= n; i ++) {
		cout << s[i].second << endl;
	}
}


Measured memory_bytes: 23680
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;

#define INF 1e18
#define int long long

const int MAX = 1000100;
const int MOD = 1000000007;

int 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;
    }
}

int 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;
}

signed main() {
    COMinit();

    int x, y;
    cin >> x >> y;

    int n = (2 * y - x) / 3;
    int m = (2 * x - y) / 3;

    if((x + y) % 3 != 0 || m < 0 || n < 0) {
        cout << 0 << endl;
        return 0;
    }

    int ans = COM(n + m, m);

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 23680
<?php
list($K) = ints();
$sum6 = 0;
$sum1 = 0;
for($i = 1; $i <= $K; $i++)
for($j = 1; $j <= $K; $j++)
$memo[$i][$j] = $memo[$j][$i] = (int)gmp_gcd($i, $j);

for($i = 1; $i <= $K; $i++)
for($j = $i+1; $j <= $K; $j++){
    $ij = $memo[$i][$j];
    for($k = $j+1; $k <= $K; ++$k)
        $sum6+=$memo[$ij][$k];
}
for($i = 1; $i <= $K; $i++)
for($j = $i+1; $j <= $K; $j++)
    $sum6+=$memo[$i][$j];

for($i = 1; $i <= $K; $i++)
    $sum1+=$i;

echo $sum6*6+$sum1;


function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$N = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}


Measured memory_bytes: 19100
#include <iostream>
#include <algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF = 1e9L + 7;

int main() {
    int n;
    scanf("%d", &n);
    // dp[heads]
    // if we had i tosses, then tails=i-heads
    vector<double> dp(n + 1);
    // dp[i] - p-bility that there are i heads so far
    dp[0] = 1;
    for(int coin = 0; coin < n; ++coin) {
        double p_heads;
        cin>>p_heads;
        for(int i = coin + 1; i >= 0; --i) {
            dp[i] = (i == 0 ? 0 : dp[i-1] * p_heads) + dp[i] * (1 - p_heads);
        }
    }
   double answer = 0;
    for(int heads = 0; heads <= n; ++heads) {
        int tails = n - heads;
        if(heads > tails) {
            answer += dp[heads];
        }
    }
    printf("%.10lf\n", answer);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
#3で割り切れるFizzの和
sho3 = N // 3
wa3 = 3 * sho3 * (sho3 + 1) / 2

#Buzzの和
sho5 = N // 5
wa5 = 5 * sho5 * (sho5 + 1) / 2

#FizzBuzzの和
sho15 = N // 15
wa15 = 15 * sho15 * (sho15 + 1) / 2

wa = N * (N + 1) / 2
sum =int(wa - (wa3 + wa5 - wa15))
print(sum)

Measured memory_bytes: 61700
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const ll mod = 998244353;



int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s; cin >> s;
    int n = s.size();
    int mx = 0;
    FOR(i, 0, n)
    {
        int c = 0;
        while (i < n && s[i] == 'R') 
        {
            c++;
            i++;
        }
        mx = max(mx, c);
    }
    cout << mx;
    
    return 0;
}





Measured memory_bytes: 3160
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		
		int[] l = new int[n];
		Arrays.setAll(l, i -> sc.nextInt());
		
		int i = 0;
		int dis = 0;
		while (dis < x && i < n) {
			dis += l[i];
			if (dis <= x) i++;
		}
		
		System.out.println(i + 1);
		
		sc.close();
	}
	
}




Measured memory_bytes: 32328
N,K = map(int,input().split())
sunukes = [1 for i in range(N)]

for i in range(K):
  d = int(input())
  indexs = [int(i) - 1 for i in input().split()]
  for index in indexs:
    sunukes[index] = 0
print(sum(sunukes))

Measured memory_bytes: 9036
#include<stdio.h>

int main(void) {

	int r, g, b;
	int num;

	scanf("%d %d %d", &r, &g, &b);
	
	num = 100 * r + 10 * g + b;

	if (num % 4 == 0) 
		printf("YES");
	else 
		printf("NO");

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  
  int a;
  cin>>a;
  bool hasNine=false;
  while(a){
    int d=a%10;
    if(d==9)
    {
      hasNine=true;
      break;
    }
    a/=10;
  }
 	
  if(hasNine) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::input;

const N: usize = 1000001;

fn main() {
    input! {
        n: usize,
        aa: [usize;n]
    }
    let mut bb = vec![0;N];
    for a in &aa {
        let mut i = *a;
        let b = bb[i] != 0;
        while i < N {
            bb[i] += 1;
            i += a;
            if b { break; }
        }
    }
    println!("{}", aa.iter().filter(|a|{ bb[**a] == 1 }).count());
}

Measured memory_bytes: 8948
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
 
#define int long long 
#define pb push_back
#define all(s) s.begin(),s.end()
#define pii pair<int,int>
#define fr first
#define sc second
#define bst ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define no cout << "NO" << endl;
#define yes cout << "YES" << endl;

using namespace std;

const int N = 5e5 + 10, mod = 1e9 + 7, inf = 1e18 + 7, logn = 23;
const double pi = acos(-1);

int h[N], dp[N];

void solve() {
	//soln
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	for(int i = 3; i <= n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n];
}
main() {
	bst;
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}


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

using namespace std;

#define MAX_N 16
#define MAX_M 16

int M, N;
double P[MAX_M][MAX_N];
double dp[MAX_N][1<<MAX_M];

double solve(int n, int m)
{   
    double &res = dp[n][m];
    
    if (res != -1) {
        return res;
    }
    res = 0;

    for (int i = 0; i < M; i++) {
        if (!(m >> i & 1)) continue;
        double p = 1.0, q = 0.0;
        for (int j = n; j < N; j++) { 
            q += p * (1 - P[i][j]) * solve(j, m & ~(1<<i));
            p *= P[i][j];
        }
        q += p;
        res = max(res, q);
    }    
    return res;
}

int main()
{
    cin >> M >> N;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            cin >> P[i][j];
        }
    }
    fill(dp[0], dp[MAX_N], -1);
    printf("%.10f\n", solve(0, (1<<M)-1));
    return 0;
}

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

bool is_invalid(int n, vector<bool> dislike)
{
    while (n > 0)
    {
        if (dislike[n % 10])
        {
            return true;
        }
        n /= 10;
    }
    return false;
}

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

    vector<bool> dislike(10, false);
    int D;
    for (int i = 0; i < K; i++)
    {
        cin >> D;
        dislike[D] = true;
    }

    while (is_invalid(N, dislike))
    {
        N++;
    }
    cout << N << endl;
}


Measured memory_bytes: 256
n=int(input())
X=0
Y=0
T=0
f=1
for _ in range(n):
    t,x,y=map(int,input().split())
    dx=abs(x-X)
    dy=abs(y-Y)
    dt=t-T
    if dt>=dx+dy and dt%2==(dx+dy)%2:
        pass
    else:
        f=0
print("Yes" if f else "No")


Measured memory_bytes: 45032
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

namespace {

}

int main()
{
	int N = 0;
	string S;

	cin >> N;
	cin >> S;

	// 切断箇所のループ
	int maxCount = 0;
	for (int i = 0; i < N; ++i){
		string sl = S.substr(0, i);
		string sr = S.substr(i, S.size() - i);

		map<char, int> sCount;
		for (auto elem : sl){
			sCount[elem] = 1;
		}
		for (auto elem : sr){
			if (sCount[elem] == 1){
				sCount[elem] = 2;
			}
		}

		int tmpCount = 0;
		for (auto elem : sCount){
			if (elem.second == 2){
				++tmpCount;
			}
		}
		maxCount = max(maxCount, tmpCount);
		
	}
	cout << maxCount;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 1000000000

int main() {
    int n;
    ll d,ans=0,x,y;
    cin >> n >> d;
    rep(i,n){
        cin >> x >> y;
        ans += bool(x*x+y*y<=d*d);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <stdio.h>

int main(void)
{
	int n,x,min,max,i;
	scanf("%d",&n);
	scanf("%d",&x);
	min=x;
	max=x;
	for(i=1;i<n;i++){
		scanf("%d",&x);
		if(min>x){
			min=x;
		}
		if(max<x){
			max=x;
		}
	}
	printf("%d\n",(max-min+1)/2);
	return 0;
}



Measured memory_bytes: 2112
// use std::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) 
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator, 
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

fn main() {
    let (n, m) = readl!(usize, usize);
    let mut cnt = vec![0; n];
    for _ in 0..m {
        let (a, b) = readl!(usize, usize);
        cnt[a-1] += 1;
        cnt[b-1] += 1;
    }
    let sum: i32 = cnt.into_iter().map(|x| x%2).sum();
    if sum > 1 {
        println!("{}", "NO");
    } else {
        println!("{}", "YES");
    }
}



Measured memory_bytes: 4352
#include <stdio.h>

int main()
{
	const long long lim = 2000000000000000000ll;

	int N; scanf ("%d", &N); long long A = 1;
	while (N--){
		long long a; scanf ("%lld", &a);
		if (a && A > lim / a) A = lim;
		else A *= a;
		if (A > lim) A = lim;
	}
	if (A > lim / 2) A = -1;
	printf ("%lld\n", A);
	return 0;
}


Measured memory_bytes: 3180
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

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

using namespace std;

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;
}

void trace(int A[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

using ll = long long;
using P = pair<int, int>;

const unsigned long long INF = 1LL << 60;

////////////////////////////////////////////////////////////

int H, W;
string S[50];

int main() {
    cin >> H >> W;
    rep(i, H) cin >> S[i];

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; ++j) {
            if (S[i][j] == '.') {
                S[i][j] = '0';
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; ++j) {
            char c = S[i][j];
            if (c == '#') {
                for (int k = i - 1; k <= i + 1; ++k) {
                    for (int l = j - 1; l <= j + 1; ++l) {
                        if (k >= 0 && k < H && l >= 0 && l < W) {
                            if (S[k][l] == '#') {
                                continue;
                            } else {
                                S[k][l] += 1;
                            }
                        }
                    }
                }
            }
        }
    }

    rep(i, H) cout << S[i] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define F first
    #define S second
    using ll = long long;
    const ll mod = 1000000007;
    const ll infi = 1000000000000000;
    const ll md = 998244353;
    using namespace std;
    using vl = vector<ll>;
    using pll =  pair<ll,ll>;
    
  
   
    void solve(){
        int n; 
        cin>>n;
        string s;
        cin>>s;
        //vl a(n);for(int i=0;i<n;i++) cin>>a[i];
        for(int i=0;i<s.size();i++){
            s[i] =( s[i]-'A'+n)%26+'A';
        }
        cout<<s;
    }
     
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
       // int n; cin>>n; for(int i=0;i<n;i++)
        solve();
        return 0;
    } 
    

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

#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 FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   int x,y,z;
   cin >> x >> y >> z;
   int ans = 1;
   while(ans*y+(ans+1)*z<=x)ans++;
   ans--;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        if(N < K){
            Stream.generate(()->sc.nextInt()).limit(N);
            System.out.println(0);
        }else {
        long res = Stream.generate(()->sc.nextInt()).limit(N)
                .sorted().limit(N-K).collect(Collectors.summingLong(Integer::longValue));
            System.out.println(res);
        }
    }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	if((B*10+C)%4==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

using namespace std;

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

    int n, m;
    while (true)
    {
        cin >> n >> m;
        if (n == 0)
            break;
        bool infected[n + 1];
        for (int i = 2; i < n + 1; i++)
            infected[i] = false;
        infected[1] = true;
        int s[m + 1], d[m + 1];
        vector<pair<int, int>> t;
        for (int i = 1; i <= m; i++)
        {
            int tmp;
            cin >> tmp >> s[i] >> d[i];
            t.push_back(make_pair(tmp, i));
        }
        sort(t.begin(), t.end());
        for (int i = 0; i < m; i++)
        {
            int idx = t[i].second;
            if (infected[s[idx]])
                infected[d[idx]] = true;
        }
        int res = 0;
        for (int i = 1; i <= n; i++)
            if (infected[i])
                res++;
        cout << res << endl;
    }
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}


int main() {
    string s;
    cin >> s;

    LL np = 0;
    EACH(c, s) {
        if (c == 'p') np++;
    }
    cout << SZ(s) / 2 - np << endl;
	
    return 0;
}


Measured memory_bytes: 512
while n = gets()
  if (n.nil? or n == "\n" or n == "\n\r") then break end
  n = n.to_i
  count = 0
  (0..9).each do |a|
    (0..9).each do |b|
      (0..9).each do |c|
        (0..9).each do |d|
          if a + b + c + d == n then
            count += 1
          end
        end
      end
    end
  end
  puts count
end

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in();
    vector<vector<pint>> b(n);
    rep(i, n)
    {
        int a = in();
        rep(j, a)
        {
            int x = in(), y = in();
            --x;
            b[i].emplace_back(x, y);
        }
    }

    int ans = 0;
    rep(bit, (1 << n))
    {
        vector<bool> is_correct(n, false);
        int cnt = 0;
        rep(i, n)
        {
            if (bit & (1 << i))
            {
                is_correct[i] = true;
                ++cnt;
            }
        }

        bool ok = true;
        rep(i, n)
        {
            rep(j, b[i].size())
            {
                int x = b[i][j].first;
                int y = b[i][j].second;
                if (is_correct[i] == true)
                {
                    if (y == 1 && !is_correct[x])
                    {
                        ok = false;
                    }
                    else if (y == 0 && is_correct[x])
                    {
                        ok = false;
                    }
                }
            }
        }
        if (ok)
        {
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

void Main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> jobs(M+1);
  for (int i=0; i<N; ++i) {
    int a, b;
    cin >> a >> b;
    if (a <= M) jobs[a].push_back(b);
  }

  int reward = 0;
  priority_queue<int> que;
  for (int i=1; i<=M; ++i) {
    for (auto &j : jobs[i]) que.push(j);
    if (not que.empty()) {
      reward += que.top();
      que.pop();
    }
  }
  cout << reward << "\n";
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  Main();
}


Measured memory_bytes: 5632
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF INT_MAX

int a[2000];

int main(){
    while(1){
        int n;
        scanf("%d",&n);
        if(n == 0)
            break;
        REP(i,n)
            scanf("%d",&a[i]);
       
        int min = INF; 
        for(int i = 0;i < n;i++){
            for(int j = i + 1;j < n;j++){
                if(min > abs(a[i] - a[j]))
                    min = abs(a[i] - a[j]);
            }
        }
        printf("%d\n",min);
    }
    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n;
  ll ar[n];
  rep(i,0,n) cin>>ar[i];
  m+=1000;
  rep(i,0,n-1)
  {
    if( i+1<n && ar[i]<ar[i+1])
    {
      k=m/ar[i];
      m%=ar[i];
    //  i++;
      m+=(k*ar[i+1]);
    }
  }
  cout<<m<<endl;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3600
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
 
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    /*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        n:usize,
        ass: [usize;n],
    }
    let max = ass.iter().max().unwrap();
    let mut rev_vec = vec![0;*max + 3];
    for &i in ass.iter(){
        rev_vec[i] += 1;
        rev_vec[i + 1] += 1;
        rev_vec[i + 2] += 1;
    }
    println!("{}",rev_vec.iter().max().unwrap());
}    


Measured memory_bytes: 6396
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
using namespace std;

const long MOD = 1e9 + 7;
int main()
{
  long n, m;
  cin >> n >> m;

  vector<long> a(n);
  vector<long> b(n);
  vector<long> c(m);
  vector<long> d(m);

  for (int i = 0; i < n; ++i)
  {
    cin >> a[i] >> b[i] ;
  }
  for (int i = 0; i < m; ++i)
  {
    cin >> c[i] >> d[i] ;
  }

  for (int i = 0; i < n; ++i)
  {
    int chk=-1;
    long dist = MOD;
    for (int j = 0; j < m; ++j)
    {
      long tmpdist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (dist> tmpdist){
        dist = tmpdist;
        chk = j+1;
      }
    }
    cout <<chk <<endl;
  }



  return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
#define MOD 1000000007

long long int A[200000 + 1];
long long int B[200000 + 1];

int main(){
  
  int n;
  long long int ans = 0;
  
  scanf("%d",&n);
  
  for(int i = 0;i < n;++i){
    
    scanf("%lld",A + i);
    B[i + 1] = B[i] + A[i]; 
    
  }
  
  for(int i = 0;i < n;++i){
    
    long long int sum = (B[n] - B[1 + i]) % MOD;
    ans += sum * A[i];
    ans %= MOD;
    
  }
  
  
  printf("%lld\n",ans);
  
  return 0;
}

Measured memory_bytes: 4856
n, k = map(int, input().split())

L = list(map(int, input().split()))

t = 0
for i in range(n):
    for j in range(i + 1, n):
        if L[i] > L[j]:
            t += 1

t = (t * k) % (10**9 + 7)

L = sorted(L)
s = 0
for i in range(n):
    for j in range(i + 1, n):
        if L[i] < L[j]:
            s += 1
k = k - 1
sum = (k * (k + 1)//2)% (10**9 + 7)
s = (s * sum) % (10**9 + 7)
print((t + s) % (10**9 + 7))

Measured memory_bytes: 41708