akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define rep(I, N) for (int I = 1; I <= (N); ++I)
#define repp(I, N) for (int I = 0; I < (N); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORR(I, A, B) for (int I = (A); I >= (B); I--)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
const int N = 2e5 + 5;
const double eps = 1e-7;
const int mod = 1e9 + 7;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
LL gcd(LL a,LL b){return b>0?gcd(b,a%b):a;}
LL ksm(LL a,LL b){LL ans = 1;while(b){if(b&1) ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans % mod;}
LL a[N], b[N];
LL c[N];
int main() {
    LL n;
    cin >> n;
    rep(i, n + 1) cin >> a[i];
    rep(i,n) cin >> b[i];
    LL ans = 0;
    rep(i,n + 1)
    {
        LL cnt = a[i] + a[i + 1];
        if(cnt >= b[i]) 
        {
            if(b[i] >= a[i]) 
            {
                LL _ = b[i] - a[i];
                a[i] = 0;
                a[i + 1] -= _;
                ans += b[i];
            }
            else 
            {
                a[i] -= b[i];
                ans += b[i];
            }
        }
        else 
        {
            ans += cnt;
            b[i] -= cnt;
            a[i] = 0;
            a[i + 1] = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2816
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
// clang-format on

void prime_factors(int n, map<int, int> &res) {
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  map<int, int> mp;
  for (int i = 1; i <= N; i++) {
    prime_factors(i, mp);
  }

  ll ans = 1;
  for (auto m : mp) {
    ans = (ans * (m.second + 1)) % MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int linearSearch(int* ,int);

int n;

int main(){
  int q,i,j;
  int s[10000],t[500];
  int cnt=0;

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

  for(i=0;i<q;i++){
    j=linearSearch(s,t[i]);
    if(j!=0){
      cnt++;
    }
  }

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


  return 0;
}

int linearSearch(int *s,int t){
  int i;
  for(i=0;i<n;i++){
    if(t==s[i])
      return 1;
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define rep(i,x) for(int i = 0;i<x;i++)
#define REP(i,x) for(ll i = 1;i<=x;i++)
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; 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 nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> vec(N);
    vecin(vec);
    sort(all(vec));
    ll ans = 0,rem = N - 1;
    for(ll i = N - 1;rem > 0;i--){
        if(i == N - 1){
            ans += vec[i];
            rem--;
        }
        else if(rem == 1){
            ans += vec[i];
            rem--;
        }
        else{
            ans += vec[i] * 2;
            rem -= 2;
        }
    }
    cout << ans << endl;
}

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

 int main() {

int N ;
cin >> N ;
vector<int>A(200);
int res = 0;
for(int i=0; i<N; i++) cin >> A.at(i) ;

while(true){
        bool fl = false ;
        for(int i=0; i<N; i++){
               if(A.at(i)%2 != 0) fl = true;
        }
 
        if(fl) break;
       
        for(int i = 0; i<N; i++){
                  A.at(i) /= 2;
         }
         ++res ;
}
cout << res << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
//vectorの中身を表示する
void DV(const vector<int>& v);
//vectorを作り、代入する
vector<int> makeV(int &num);


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

    cout << 2*A*M_PI;


    return 0;
}






















//display vector
void DV(const vector<int>& v)
{
    for(auto i: v)
    {
        cout << i << " ";
    }
    cout << endl;

}

//make vector
vector<int> makeV(int &num)
{
    vector<int> v(num);
    int i=0;
    rep(i,num)
    {
        cin >> v[i];
    }

    return v;
}

Measured memory_bytes: 3724
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  ll k;
  int q;
  cin >> n >> k >> q;
  VI gain(n, 0);
  REP(i,0,q) {
    int a;
    cin >> a;
    a--;
    gain[a] += 1;
  }
  FOR(a, gain) {
    if (k - (q - a) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


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

int main () {
  int N;
  cin >> N;
  
  //bool zero = true;
  int leastTry = 0;
  

    for (int i = 0; i < N; i++) {
      int num;
      cin >> num;
      int count = 0;
      while (num % 2 == 0) {
        num /= 2;
        count++;
      }
      if (count > 0) {
        if (i == 1) {
          leastTry = count;
        } else if (count < leastTry) {
          leastTry = count;
        }
      } else {
        leastTry = 0;
        break;
      }
    }
    cout << leastTry << endl;
        
        
  
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
#ifdef BOOST_RANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
  boost::for_each(vc, [&os](T value) {
#else
  std::for_each(vc.begin(), vc.end(), [&os](T value) {
#endif
    os << value << ' ';
    });
  return os;
}

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

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  string S{}; std::cin >> S;
  //ui N{}; cin >> N;
  ui N = S.size();
  vector<ull> ans(N, 0);

  pair<uc, ui> it{'R', 0};
  rep(1, N)
  {
    ++it.second;
    if (it.first == S[i]) continue;

    if (S[i] == 'L')
    {
      ans[i] += it.second / 2ULL;
      ans[i - 1] += (it.second - 1ULL) / 2ULL + 1;
    }
    else if(S[i] == 'R')
    {
      ans[i - it.second] += ((ull)it.second + it.second % 2ULL ) / 2ULL;
      ans[i - it.second - 1] += (it.second - 1ULL + (it.second - 1ULL) % 2) / 2ULL;
    }
    it.first = S[i];
    it.second = 0;
  }
  if (S[N - 2] == 'L')
  {
    ans[N - 1 - it.second] += ((ull)it.second + 1 + (it.second + 1ULL) % 2ULL) / 2ULL;
    ans[N - 1 - it.second - 1] += (it.second + it.second % 2ULL) / 2ULL;
  }
  else
  {
    ans[N - 1] += 1;
  }
  using std::cout;
  cout << ans << '\n';
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

int main() {
    ll a, b;
    cin >> a >> b;
    if (0 < a) {
        puts("Positive");
    } else if (a <= 0 && 0 <= b) {
        puts("Zero");
    } else {
        if (abs(b - a) & 1) {
            puts("Positive");
        } else {
            puts("Negative");
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int k;
  cin >> k;
  int ans=-1;
  if(7%k==0) cout << 1 << endl;
  else if(77%k==0) cout << 2 << endl;
  else{
    ll x=77%k;
    for(int i=3;i<=k;i++){
      x*=10;
      x+=7;
      x%=k;
      if(x==0){
        ans=i;
        break;
      }
    }
    cout<<ans<<endl;
  }
}


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

using ll = long long;
#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)

// const

// input

// valiable

// func

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

  int l,r,d;cin >> l >> r >> d;
  int ans = 0;
  for(int k = l;k <= r;k++){
    if(k % d == 0)ans++;
  } 
  cout << ans << '\n';
}


Measured memory_bytes: 3608
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int H,W,h,w;
  cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
ll a,b;
string s;
int main(){
    cin>>a>>s;
    b=(s[0]-'0')*100+(s[2]-'0')*10+s[3]-'0';
    cout<<a*b/100;
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>

#define rep(index,num) for(int index=0;index<num;++index)

using namespace std;

int main(){
  int X,A;
  std::cin >> X >> A;
  if(X<A) cout << 0 << endl;
  else    cout << 10 << endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    sup = {}
    for i in range(n-1):
        if a[i] in sup:
            sup[a[i]] += 1
        else:
            sup[a[i]] = 1
    for j in range(1, n+1):
        if j in sup:
            print(sup[j])
        else:
            print(0)
resolve()

Measured memory_bytes: 111828
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  int K, S;
  cin >> K >> S;
  int count = 0;
  for (int i = 0; i < K+1; i++) {
    for (int j = 0; j < K+1; j++) {
      if (0 <= (S-i-j) && (S-i-j) <= K) {
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
module.exports=function(r){var t={};function e(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return r[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var i in r)e.d(n,i,function(t){return r[t]}.bind(null,i));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=0)}([function(r,t,e){"use strict";var n=e(1);e(2)(n.readFileSync("/dev/stdin","utf8"))},function(r,t){r.exports=require("fs")},function(r,t,e){"use strict";var n=e(3),i=e(5);r.exports=function(r){var t=new n(r);i(t)}},function(r,t,e){"use strict";var n=e(4);r.exports=class{constructor(r){var t=r.trim().split(/\s+/g);this.inp=new n(t)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(r,t,e){"use strict";r.exports=class{constructor(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=r.length,this.items=r,this.ind=0}enq(r){this.size+=1,this.items.push(r)}deq(){var r=this.items[this.ind];return this.size-=1,this.ind+=1,r}clear(){this.items=[],this.size=0,this.ind=0}}},function(r,t,e){"use strict";r.exports=function(r){for(var t=r.in(),e=r.in(),n=(r.in(),new Array(t)),i=0;i<t;i++)n[i]=r.inr().split("");for(var o=0,s=new Array(t).fill(1),u=0;u<t;u++){for(var f=!1,a=0;a<e;a++)"."==n[u][a]?f&&(n[u][a]=o):(f=!0,o+=1,n[u][a]=o);f||(s[u]=0)}for(var c=t-1;c>=0;c--)for(var l=!1,p=e-1;p>=0;p--)"."==n[c][p]?l&&(n[c][p]=o):(l=!0,o=n[c][p]);for(var d=1;d<t;d++)if(1!=s[d]&&0!=s[d-1]){for(var v=0;v<e;v++)n[d][v]=n[d-1][v];s[d]=1}for(var h=t-2;h>=0;h--)if(1!=s[h]&&0!=s[h+1]){for(var y=0;y<e;y++)n[h][y]=n[h+1][y];s[h]=1}for(var b=0;b<t;b++)console.log(n[b].join(" "))}}]);

Measured memory_bytes: 23020
use std::cmp::Reverse;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, m: usize);
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        parse!(it, a: usize, b: usize);
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
    }
    let mut q = std::collections::BinaryHeap::new();
    let mut froms = vec![n; n];
    q.push(Reverse((0, 0, 0)));
    while let Some(Reverse((l, u, from))) = q.pop() {
        if froms[u] != n {
            continue;
        }
        froms[u] = from;
        for &v in g[u].iter() {
            if froms[v] != n {
                continue;
            }
            q.push(Reverse((l + 1, v, u)));
        }
    }
    if froms.iter().any(|&x| x == n) {
        println!("{}", "No");
    } else {
        println!("{}", "Yes");
        for i in 1..n {
            println!("{}", froms[i] + 1);
        }
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 15932
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define RT fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define INF 1LL<<61
#define inf 1<<30
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 1e9+7;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(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;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];
    cout << ceil(double(n-1)/(k-1));
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(){
    int n, i;
    double x[1001] = {}, y[1001] = {}, p1, p2, p3, pinf, p2c, p3c;

    scanf("%d", &n);
    for( i = 0; i < n; i++ ){
        scanf("%lf", &x[i]);
    }
    for( i = 0; i < n; i++ ){
        scanf("%lf", &y[i]);
    }
    for( i = 0, p1 = 0; i < n; i++ ){
        p1 += fabs( x[i] - y[i] );
    }
    for( i = 0, p2 = 0; i < n; i++ ){
        p2 += pow( fabs( x[i] - y[i] ), 2 );
    }
    p2c = sqrt( p2 );
    for( i = 0, p3 = 0; i < n; i++ ){
            p3 += pow( fabs( x[i] - y[i] ), 3 );
    }
    p3c = pow( p3, 1.0 / 3.0 );
    for( i = 0, pinf = 0; i < n; i++ ){
        if( pinf < fabs( x[i] - y[i] ) ){
            pinf = fabs( x[i] - y[i] );
        }
    }
    printf("%f\n%f\n%f\n%f\n", p1, p2c, p3c, pinf);
    return 0;
}

Measured memory_bytes: 728
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N,K;
	cin >> N >> K;
	vector<int> l(N);
	for(int i = 0; i < N; i++){
		cin >> l[i];
	}
	sort(l.begin(),l.end());
	reverse(l.begin(),l.end());
	int ans = 0;
	for(int i = 0; i < K; i++){
		ans += l[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import math
# お気楽ロジックが思い浮かばないので真っ当に解く
N, M = (int(x) for x in input().split(' '))
A = [int(x) for x in input().split(' ')]
# 基準となる閾値を求める
limen = math.ceil(sum(A) / ( M * 4))
# 閾値越えの値を全探索
ans = 0
for row in A:
  if row >= limen:
    ans += 1
# 回答
print( 'Yes' if ans >= M else 'No' )

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
  int s,k;
  cin >> k >> s;
  long long int sum=0;
  for(int x=0; x <= k; x++){
    if(s-x <= 2*k && s-x >= 0){
      if(s-x-k >= 0)
        sum += k-(s-x-k) + 1;
      else
	sum += s-x + 1;
    }
  }
  if(s == 0) sum = 1;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv) 
{
	int x, a, b;

	scanf("%d %d %d", &x, &a, &b);

	if (abs(x - a) < abs(x - b) ) {
		printf("A\n");
	} else {
		printf("B\n");
	}
	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  rep(i,n){
    cin >> s;
    string ans ="";
    auto it = find(all(s),'-');
    while(it != s.end()){
      s.erase(find(all(s),'-'),it+1);
      it = find(all(s),'-');
    }
    ans += s[0];
    int dir = 0;
    set<char> cs;
    cs.insert(s[0]);
    REP(i,1,s.size()){
      if(s[i] == '<'){
        dir = -1;
      }
      else if(s[i] == '>'){
        dir = 1;
      }
      else{
        if(dir == 1 && cs.find(s[i]) == cs.end()){
          ans += s[i];
          cs.insert(s[i]);
        }
        else if(dir == -1 && cs.find(s[i]) == cs.end()){
          ans = s[i] + ans;
          cs.insert(s[i]);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3084
S = input()

N = len(S)
table = [-1] * N
T = [-1] * N
prev = 0
for i, s in enumerate(reversed(S)):
    prev += (int(s) * pow(10, i, 2019)) % 2019
    prev %= 2019
    T[i] = prev

DP = [0] * 2019
for t in T:
    DP[t] += 1

ans = DP[0]
for num in DP:
    ans += num * (num - 1) // 2

print(ans)

Measured memory_bytes: 71272
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;

int f[105][15], p[105][15];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 10; j++){
            cin >> f[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 11; j++){
            cin >> p[i][j];
        }
    }
    ll mx = -2e9;
    for(int i = 1; i < (1 << 10); i++){
        int cnt[100]{};
        for(int j = 0; j < 10; j++){
            if(i >> j & 1){
                for(int k = 0; k < n; k++){
                    if(f[k][j]) cnt[k]++;
                }
            }
        }
        ll sum = 0;
        for(int j = 0; j < n; j++){
            sum += p[j][cnt[j]];
        }
        mx = max(sum, mx);
    }
    cout << mx;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

n_cnt = {}
for n in a:
    if n not in n_cnt:
        n_cnt[n] = -n+1
    else:
        n_cnt[n] += 1

print(sum([val if val >=0 else key+val for key, val in n_cnt.items()]))

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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);
const int  MAX= 1005;
int h,w;
int dp[MAX][MAX];
string grid[MAX];

bool valid(int x , int y) {
    return x>=0 && x<h && y>=0 && y<w && grid[x][y]=='.';
}

inline void add(int &x , int y) {
   x += y;
   if ( x >= MOD) {
       x -= MOD;
   }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin >> h >> w;
    for(int i = 0; i < h ; i++) {
        cin >> grid[i];
    }
    dp[0][0]=1;    
    for(int i = 0; i < h ; i++) {
        for(int j = 0; j < w ; j++) {
            if(grid[i][j] != '.') {
                continue;
            }
            if(valid(i-1,j)) {
                add(dp[i][j], dp[i-1][j]);
            }
            if(valid(i,j-1)) {
                add(dp[i][j], dp[i][j-1]);
            }
        }
    }
    cout << dp[h-1][w-1];
    return 0;
}



Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}}; ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
int main() {
    string S;
    cin >> S;
    for(char &c : S) {
        if(c == '?') c = 'D';
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 3728
n = int(input())
x_bin = input()
x = int(x_bin, 2)

pc = x_bin.count('1')
pc_p = pc + 1
pc_m = pc - 1

if pc == 1:
    for i, v in enumerate(x_bin):
        if v == '1':
            print(0)
        else:
            if i != n-1:
                if x_bin[-1] == '0':
                    print(1)
                else:
                    print(2)
            else:
                print(2)
    exit()

p = {0: 1}
m = {0: 1}
for i in range(1, n):
    p[i] = p[i-1]*2 % pc_p
    m[i] = m[i-1]*2 % pc_m

rest = {0: 0}
for i in range(1, pc + 1):
    rest[i] = rest[i % bin(i).count('1')] + 1

x_p = x % pc_p
x_m = x % pc_m

for i in range(n, 0, -1):
    if x_bin[n-i] == '1':
        a = (x_m - m[i-1]) % pc_m
        print(rest[a] + 1)
    else:
        a = (x_p + p[i-1]) % pc_p
        print(rest[a] + 1)


Measured memory_bytes: 62204
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n=3,i=1;
    int a[4];
    for(i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    cout<<a[1]+a[2]<<endl;
    return 0;
}

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

int a[100][100],z[100][100],j = 0;

int solve(int x,int y){
  a[x][y]=0;

  for(int i=1;i<=3;i++){
    if(a[x+i][y] == 1 && x+i <= 8) solve(x+i,y);
    if(a[x][y+i] == 1 && y+i <= 8) solve(x,y+i);
    if(a[x-i][y] == 1 && x-i >= 1) solve(x-i,y);
    if(a[x][y-i] == 1 && y-i >= 1) solve(x,y-i);
  }
  return 0;
}
int main(){

  int n,x,y;
  char k;

  cin >> n;

  for(int p=1;p<=n;p++){

    for(int i=1;i<=8;i++){
      for(int j=1;j<=8;j++){
	cin >> k;
	int t = k -'0';
	a[i][j] = t;
      }
    }
    cin >> y >> x;

    solve(x,y);

    cout << "Data " << p << ":" << endl;

    for(int i=1;i<=8;i++){
      for(int j=1;j<=8;j++) cout << a[i][j];
      cout << endl;
    }
  }
}

Measured memory_bytes: 1164
def main():
    A, B, C, D = map(int, input().split())
    num_C_div = B // C - (A - 1) // C
    num_D_div = B // D - (A - 1) // D
    CD_lcm = lcm(C, D)
    num_CandD_div = B // (CD_lcm) - (A - 1) // (CD_lcm)
    num_CorD_div = num_C_div + num_D_div - num_CandD_div
    print((B - A + 1) - num_CorD_div)


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import math


A, B, C, D = map(int, input().split())

if C == 1 or D == 1:
    print(0)
    exit()

count_all = B - A + 1
count_c = (B // C) - math.ceil(A / C) + 1
count_d = (B // D) - math.ceil(A / D) + 1
lcm_cd = C * D // math.gcd(C, D)
count_cd = (B // lcm_cd) - math.ceil(A / lcm_cd) + 1

ans = count_all - (count_c + count_d - count_cd)
print(ans)


Measured memory_bytes: 8968
// author: Saman Mahdanian
#include <iostream>

using namespace std;

int main() {
	long long n, p;
	cin >> n >> p;

	if (n == 1) {
		cout << p << endl;
		return 0;
	}

	int ans = 1;
	for (long long i = 2; i * i <= p; i++) {
		int cnt = 0;
		while (p % i == 0) {
			p /= i;
			cnt++;
		}
		for (int j = 0; j < cnt / n; j++)
			ans *= i;
		//ans = max(ans * 1LL, cnt / n);
	}
	cout << ans << endl;
}

// SamMHD :: Mar5-2019 :: Another Ez Pz...


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>



int main()
{
	int i,p,b,count=0,j;
	
	scanf("%d", &p);
	int *linear = (int*)malloc(sizeof(int)*p);

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

    scanf("%d", &b);
	int *linear2 = (int*)malloc(sizeof(int)*b);

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

	for (i = 0; i < b; i++)
	{
		for (j = 0; j < p; j++)
		{
			if (linear[j] == linear2[i])
			{
				count++;
				break;
			}
		}
	}

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


	return 0;
}

// 

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

ll MOD = 1000000007;

ll modpow(ll x, ll y, ll n) {
    ll res = 1;
    x%=n;
    while (y>0) {
        if (y%2==1) {
            res*=x;
            res%=n;
        }
        y/=2;
        x*=x;
        x%=n;
    }
    return res;
}

int main() {
    vector<ll> facts(200001), invs(200001);
    facts[0] = 1;
    invs[0] = 1;
    for (ll i=1; i<=200000; i++) {
        facts[i] = facts[i-1]*i%MOD;
        invs[i] = modpow(facts[i],MOD-2,MOD);
    }
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    ll res = 0;
    ll mult = 1;
    for (ll i=0; i<h-a; i++) {
        mult = facts[b-1+i]*invs[i]%MOD;
        mult*=invs[b-1];
        mult%=MOD;
        mult*=facts[h-i+w-b-2];
        mult%=MOD;
        mult*=invs[h-1-i];
        mult%=MOD;
        mult*=invs[w-b-1];
        mult%=MOD;
        res+=mult;
        res%=MOD;
    }
    cout << res;
    return 0;
}

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

#define MAX 2000
#define WHITE 0
#define BLACK 1
int N, X, Y;

// グラフの隣接リスト表現
vector<int> G[MAX + 1];
// A[i][k]は頂点iからの最短距離がちょうどkである頂点の個数
int A[MAX + 1][MAX + 1];

// 幅優先探索。sは探索の始点。各呼び出しでA[s]を更新していく。
void bfs(int s) {
	queue<int> Q;
	int d[MAX];
	int col[MAX + 1];
	for (int i = 1; i <= N; i++) {
		col[i] = WHITE;
	}
	Q.push(s);
	d[s] = 0;
	col[s] = BLACK;
	while (!Q.empty()) {
		int u = Q.front();
		Q.pop();
		for (int i = 0; i < G[u].size(); i++) {
			if (col[G[u][i]] == WHITE) {
				Q.push(G[u][i]);
				d[G[u][i]] = d[u] + 1;
				col[G[u][i]] = BLACK;
			}
		}
	}
	for (int i = 0; i <= N; i++) {
		A[s][i] = 0;
	}
	for (int i = 1; i <= N; i++) {
		A[s][d[i]]++;
	}
}

int main() {
	cin >> N >> X >> Y;
	for (int i = 1; i < N; i++) {
		G[i].push_back(i + 1);
		G[i + 1].push_back(i);
	}
	G[X].push_back(Y);
	G[Y].push_back(X);
	for (int i = 1; i <= N; i++) {
		bfs(i);
	}
	int ans[MAX];
	for (int k = 1; k < N; k++) {
		ans[k] = 0;
	}
	for (int i = 1; i <= N; i++) {
		for (int k = 1; k < N; k++) {
			ans[k] += A[i][k];
		}
	}
	for (int k = 1; k < N; k++) {
		cout << ans[k] / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;


int N,M,K;


signed main(){
  string S,T;
  cin>>T;
  N=(int)T.at(T.size()-1)-'0';
  if(N==2||N==4||N==5||N==7||N==9)S="hon";
  else if(N==0||N==1||N==6||N==8)S="pon";
  else S="bon";
  print(S);

}


Measured memory_bytes: 3640
package main

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

const maxBuf = 200100

var buf []byte = make([]byte, maxBuf)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

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

func readFloat64() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

/* #### main #### */
func main() {
	s := readString()
	t := readString()

	ans := 0

	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2384
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
comf = a[0]
counter = n-2
for i in range(1,n):
  if counter>1:
    comf += 2*a[i]
    counter -= 2
  elif counter == 1:
    comf += a[i]
    counter -= 1
  else:
    break
print(comf)

Measured memory_bytes: 31536
import sys

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, a = na()
x = na()
x = [0] + x
dp = [[[0] * (50 * n + 1) for i in range(n+1)] for j in range(n+1)]

for j in range(n + 1):
    for k in range(j + 1):
        for s in range(50 * n + 1):
            if j == 0 and k == 0 and s == 0:
                dp[j][k][s] = 1
            elif j >= 1 and s < x[j]:
                dp[j][k][s] = dp[j - 1][k][s]
            elif j >= 1 and k >= 1 and s >= x[j]:
                dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - x[j]]
            else:
                dp[j][k][s] = 0
print(sum([dp[n][k][k * a] for k in range(1, n+1)]))



Measured memory_bytes: 92636
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 M = sc.nextInt();
		long[][] sum = new long[8][N];

		long[] xyz = new long[3*N];
		for(int i=0; i<3*N; i++) {
			xyz[i] = sc.nextLong();
		}

		for(int j=0; j<N; j++) {
			sum[0][j] = xyz[j*3] + xyz[j*3+1] +xyz[j*3+2];
			sum[1][j] = xyz[j*3] + xyz[j*3+1] -xyz[j*3+2];
			sum[2][j] = xyz[j*3] - xyz[j*3+1] +xyz[j*3+2];
			sum[3][j] = xyz[j*3] - xyz[j*3+1] -xyz[j*3+2];
			sum[4][j] = -xyz[j*3] + xyz[j*3+1] +xyz[j*3+2];
			sum[5][j] = -xyz[j*3] + xyz[j*3+1] -xyz[j*3+2];
			sum[6][j] = -xyz[j*3] - xyz[j*3+1] +xyz[j*3+2];
			sum[7][j] = -xyz[j*3] - xyz[j*3+1] -xyz[j*3+2];
		}for(int m=0; m<8; m++) {
			Arrays.sort(sum[m]);
		}//System.out.println(sum[0][N-1]); //ここまで合ってるはず

		long[] P = new long[8];
		for(int k=0; k<8; k++) {
			for(int l=0; l<M; l++) {
				P[k] += sum[k][N-1-l];
			}
		}Arrays.sort(P);

		System.out.println(P[7]);

	}

}


Measured memory_bytes: 27396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int K; cin >> K;
	int ans = 0;
	rep1(i,K+1) {
		rep1(j,K+1) {
			rep1(k,K+1){
				int tmp = __gcd(i,j);
				ans += __gcd(tmp, k);
			}
 		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n,r;
  while(cin >> n >> r,n+r){
    int buff1[n];
    int buff2[n];
    int *cards=buff1,*next=buff2;

    /* initialize */
    for(int i=0;i<n;i++){
      cards[i]=n-i;
    }

    /* operation */
    while(r --> 0){
      int p,c,m;
      cin >> p >> c;
      m=c;

      for(int i=0;i<n;i++){
        if(i>=p-1 && i<p+c-1){
          /* to the top */
          next[i-p+1]=cards[i];
        }else{
          /* not to the top */
          next[m++]=cards[i];
        }
      }
      swap(cards,next);
    }

    cout << cards[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  for(int i=0;i<5;i++){
    int tmp;
    cin >> tmp;
    if(tmp==0) cout << i+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3584
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a*b//gcd(a, b)


def solve(a, b, c, d):
    lcm_c_and_d = lcm(c, d)
    a -= 1
    p = a - a//c - a//d + a//lcm_c_and_d
    q = b - b//c - b//d + b//lcm_c_and_d

    return q-p


if __name__ == '__main__':
    a, b, c, d = map(int, input().split())

    print(solve(a, b, c, d))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

int main()
{
    int N, Q;
    cin >> N >> Q;
    dsu disjoint(N);
    for (int i = 0; i < Q; ++i) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) 
            disjoint.merge(u, v);
        if (t == 1)
            cout << (disjoint.same(u, v) ? 1 : 0) << endl;
    }
}




Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
#define mx 200005

long long n, k, t, aa[mx], ans;
pair<long long, int> a[mx] = {make_pair(0, 0)};
int bit[mx*2];

int main(){
  scanf("%d%d", &n, &k);
  for(int i = 1; i <= n; i++){
    scanf("%d", &t);
    a[i] = make_pair(a[i-1].first + t - k, i);
  }
  sort(a, a+n+1);
  for(int i = 0; i <= n; i++) aa[a[i].second] = i;
  for(int i = 0; i <= n; i++){
    int tmp = aa[i] + 1, tmp2 = aa[i] + 1;
    while(tmp){
      ans += bit[tmp];
      tmp -= tmp & - tmp;
    }
    while(tmp2 <= n*2){
      bit[tmp2]++;
      tmp2 += tmp2 & -tmp2;
    }
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int v, E;
vector<vector<int>> g; // adjacency list
vector<int> vis;       // stores visit status
void dfs(int cur)
{
    // int p = cur;
    for (int j = 0; j < g[cur].size(); j++)
    {
        int k = g[cur][j];
        if (vis[k] == 0)
        {
            vis[k] = 1;
            dfs(k);
        }
    }
    // cout << cur << " ";
    // return 0;
}
int call_dfs()
{
    int x = 0;
    for (int i = 1; i <= v; i++)
    {
        if (vis[i] == 0)
        {
            vis[i] = 1;
            dfs(i);
            x += 1;
        }
    }
    return x - 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // lli n, m;
    cin >> v >> E;
    g.resize(v + 1);
    vis.resize(v + 1);
    for (int i = 1; i <= v; i++)
    {
        vis[i] = 0;
    }
    for (int i = 0; i < E; i++)
    {
        int v1, v2;
        cin >> v1 >> v2;
        g[v1].push_back(v2);
        g[v2].push_back(v1);
    }
    cout << call_dfs() << endl;
}

Measured memory_bytes: 10040
#include<iostream>
using namespace std;
int n,m,p;
int map[9][9][9];
int x[400],y[400];
bool check(int a)
{
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)for(int k=0;k<=n-m;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i][j][k+l]==a;
		if(f)return 1;
	}
	for(int i=0;i<n;i++)for(int j=0;j<=n-m;j++)for(int k=0;k<n;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i][j+l][k]==a;
		if(f)return 1;
	}
	for(int i=0;i<=n-m;i++)for(int j=0;j<n;j++)for(int k=0;k<n;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i+l][j][k]==a;
		if(f)return 1;
	}
	for(int i=0;i<n;i++)for(int j=0;j<=n-m;j++)for(int k=0;k<=n-m;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i][j+l][k+l]==a;
		if(f)return 1;
	}
	for(int i=0;i<n;i++)for(int j=0;j<=n-m;j++)for(int k=0;k<=n-m;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i][j+l][n-k-l-1]==a;
		if(f)return 1;
	}
	for(int i=0;i<=n-m;i++)for(int j=0;j<=n-m;j++)for(int k=0;k<n;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i+l][j+l][k]==a;
		if(f)return 1;
	}
	for(int i=0;i<=n-m;i++)for(int j=0;j<=n-m;j++)for(int k=0;k<n;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i+l][n-j-l-1][k]==a;
		if(f)return 1;
	}
	for(int i=0;i<=n-m;i++)for(int j=0;j<n;j++)for(int k=0;k<=n-m;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i+l][j][k+l]==a;
		if(f)return 1;
	}
	for(int i=0;i<=n-m;i++)for(int j=0;j<n;j++)for(int k=0;k<=n-m;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[n-i-l-1][j][k+l]==a;
		if(f)return 1;
	}
	for(int i=0;i<=n-m;i++)for(int j=0;j<=n-m;j++)for(int k=0;k<=n-m;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i+l][j+l][k+l]==a;
		if(f)return 1;
	}
	for(int i=0;i<=n-m;i++)for(int j=0;j<=n-m;j++)for(int k=0;k<=n-m;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i+l][j+l][n-k-l-1]==a;
		if(f)return 1;
	}
	for(int i=0;i<=n-m;i++)for(int j=0;j<=n-m;j++)for(int k=0;k<=n-m;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[i+l][n-j-l-1][n-k-l-1]==a;
		if(f)return 1;
	}
	for(int i=0;i<=n-m;i++)for(int j=0;j<=n-m;j++)for(int k=0;k<=n-m;k++)
	{
		bool f=1;
		for(int l=0;l<m;l++)f&=map[n-i-l-1][j+l][n-k-l-1]==a;
		if(f)return 1;
	}
	return 0;
}
main()
{
	while(cin>>n>>m>>p,n)
	{
		for(int i=0;i<p;i++)
		{
			cin>>x[i]>>y[i];
			x[i]--,y[i]--;
		}
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)for(int k=0;k<n;k++)
			map[i][j][k]=0;
		int f=1;
		for(int i=0;i<p;i++)
		{
			int j=0;
			for(;map[x[i]][y[i]][j];j++);
			map[x[i]][y[i]][j]=2-i%2;
			if(check(2-i%2))
			{
				cout<<(i%2?"White":"Black")<<" "<<i+1<<endl;
				f=0;
				break;
			}
		}
		if(f)cout<<"Draw"<<endl;
	}
}



Measured memory_bytes: 3048
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    A,B = LI()
    print(A*B if len(str(A))==1 and len(str(B))==1 else -1)

main()



Measured memory_bytes: 27196
S = list(input())

A = []
r = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        r += 1
    else:
        A.append(r)
        r = 1
A.append(r)

ans = []

for i in range(len(A)//2):
    B = []
    m = (A[2*i]+1)//2 + A[2*i+1]//2
    n = A[2*i]//2 + (A[2*i+1]+1)//2
    for j in range(m+n):
        if j == A[2*i]-1:
            B.append(m)
        elif j == A[2*i]:
            B.append(n)
        else:
            B.append(0)
    ans += B

print(*ans)

Measured memory_bytes: 57608