akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
const int M = 100000;
const double pi = 3.141592653589;

int main(){
	int m[M], f[M], r[M];
	int i = 0;
	while (1) {
		cin >> m[i] >> f[i] >> r[i];
		if (m[i] == -1 && f[i] == -1 && r[i] == -1) {
			break;
		}
		i++;
	}
	for (int k = 0; k < i; k++) {
		if (m[k] != -1 && f[k] != -1) {
			if (m[k] + f[k] >= 80) cout << "A" << endl;
			else if (m[k] + f[k] >= 65 && m[k] + f[k] < 80) cout << "B" << endl;
			else if (m[k] + f[k] >= 50 && m[k] + f[k] < 65) cout << "C" << endl;
			else if (m[k] + f[k] >= 30 && m[k] + f[k] < 50) {
				if (r[k] >= 50) {
					cout << "C" << endl;
				}
				else {
					cout << "D" << endl;
				}
			}
		}
		if (m[k] + f[k] < 30 || m[k] == -1 || f[k] == -1) cout << "F" << endl;
	}

	return 0;
}

Measured memory_bytes: 3124
n,m,c=map(int,input().split())
B=list(map(int,input().split()))
count=0
for i in range(n):
  total=0
  A=list(map(int,input().split()))
  for j in range(m):
    total+=A[j]*B[j]
  if total>-c:
    count+=1
print(count)

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

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

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

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int n;
vector<vector<int>> G(100005);
vector<int> col(100005, -1);

void solve(int deep){
    set<int> st;

    for (auto& p : G[deep]) {
        if(col[p] != -1){
            st.insert(col[p]);
        }
    }

    int cnt = 1;
    for (auto& p : G[deep]) {
        if(col[p] == -1){
            while(st.count(cnt)) cnt++;
            st.insert(cnt);
            col[p] = cnt++;
            //cnt++;
        }
    }
}


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

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

        G[a].push_back(i);
        G[b].push_back(i);
    }

    int ans = 0;
    rep(i, n){
        ans = max(ans, (int)G[i].size());
    }
    cout << ans << "\n";

    rep(i, n){
        solve(i);
    }


    rep(i, n-1){
        cout << col[i] << "\n";
    }


    return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  vector<char> a(s.size());
  vector<char> b(t.size());
  for (int i = 0; i < s.size(); i++) {
    a.at(i) = s.at(i);
  }
  for (int i = 0; i < t.size(); i++) {
    b.at(i) = t.at(i);
  }
  
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  
  bool x = false;
  if (a.size() < b.size()) {
    bool y = true;
    for (int i = 0; i < a.size(); i++) {
      if (a.at(i) != b.at(i)) y = false;
    }
    x = y;
  }
  for (int i = 0; i < min(a.size(), b.size()); i++) {
    if (a.at(i) != b.at(i)) {
      if (a.at(i) < b.at(i)) x = true;
      break;
    }
  }
  
  if (x) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<vector<int>> x(m, vector<int>(2));
  for(int i = 0; i < m; i++) cin >> x.at(i).at(1) >> x.at(i).at(0);
  
  sort(x.begin(), x.end());
  
  int now = 0, ans = 0;
  for(int i = 0; i < m; i++){
    if(x.at(i).at(1) > now){
      now = x.at(i).at(0) - 1;
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
#define hell 1000000007
#define PI acos(-1.0)
#define S second
#define F first
#define lli long long int
#define li long int
#define ld long double
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
 
#define run(j, n) for(auto ii=j;ii!=n;ii++)
#define out(j, n) for(auto ii=j;ii!=n;ii++) cout<<(*ii)<<" ";


int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << showpoint;
cout << setprecision(11);

int h, w, k;cin>>h>>w>>k;
vector<vector<char>>ar(h, vector<char>(w));
int count=0;
for(int i=0;i<h;i++)
{
  for(int j=0;j<w;j++) {cin>>ar[i][j]; if(ar[i][j]=='#') count+=1;}
}
//cout<<count;
lli ans = 0;
for(int i=0;i<1ll<<h;i++)
{
  for(int j=0;j<1ll<<w;j++)
  {

    //cout<<i<<" "<<j<<endl; 
      vector<vector<char>>tmp=ar;
      int ct = 0;
      for(int k=0;k<h;k++)
      {
        if((1ll<<k)&i)
        {
           for(int p=0;p<w;p++)
           {
            if(tmp[k][p]=='#'){ct+=1;tmp[k][p]='.';}
           }
        }
      }
      for(int k=0;k<w;k++)
      {
        if((1ll<<k)&j)
        {
           for(int p=0;p<h;p++)
           {
            if(tmp[p][k]=='#'){ct+=1;tmp[p][k]='.';}
           }
        }
      }

    if(count-ct==k) ans+=1;
    //cout<<ct<<" "; 
  }
}

cout<<ans;
return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll N;
    cin >> N;

    string ans;
    while (N) {
        N--;
        ans += 'a' + N % 26;
        N /= 26;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;

}

Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, K;
ll V[100];
ll ans;

int main()
{
  std::cin >> N >> K;

  rep( i, N )
    std::cin >> V[i];

  rep( l, N+1 ) rep( r, N+1 )
  {
    if( l+r > N )
      continue;

    if( l+r > K )
      continue;

    ll rest = K-(l+r);

    std::vector<ll> vs;

    rep( i, l )
      vs.emplace_back( V[i] );
    for( ll i = N-1; i >= N-r; --i )
      vs.emplace_back( V[i] );

    std::sort( rall(vs) );

    rep( i, rest ) if( !vs.empty() && vs.back() < 0 )
      vs.pop_back();

    ll sum = 0;
    rep( i, vs.size() )
      sum += vs[i];

    chmax( ans, sum );
  }

  std::cout << ans << std::endl;

  return 0;
}

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

using namespace std;

int a[110][110];
int b[110];
int main()
{
    int n,m;
    cin >> n >> m;
    int ans = 0;
    for(int i = 1;i<=n;i++){
        for(int j =1;j<=m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(int  i = 1;i<=m;i++){
        scanf("%d",&b[i]);
    }
    for(int i = 1;i<=n;i++){
        for(int k = 1;k<=m;k++){
            ans += a[i][k] * b[k];
        }
        printf("%d\n",ans);
        ans = 0;
    }
 
    return 0;
}



Measured memory_bytes: 3228
from itertools import accumulate

def calc(n,A):
    Imos=[0]*(n+1)
    for i,a in enumerate(A):
        Imos[max(0,i-a)]+=1
        Imos[min(n,i+a+1)]-=1
    Ret=list(accumulate(Imos))
    return Ret[:n]

def main():
    n,k=map(int,input().split())
    A=tuple(map(int,input().split()))
    if k>=42:
        A=[n]*n
    else:
        for _ in range(k):
            A=calc(n,A)
    print(*A)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 180604
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<random>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 1e9;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
#define VMAX 500+10
    int N,K,ans=0;
    int A[1001];
int main(){
    cin>>N>>K;
    REP(i,N)cin>>A[i];
    REP(i,N){
        ans+=min(A[i]*2,abs(A[i]-K)*2);
    }
    cout<<ans;
}


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

int a, x=0, c=1;
int main(void)
{
    cin >> a;

    while(a != 0)
    {
        x = a%10;
        if(x == 7)
        {
            cout << "Yes\n";
            c = 0;
            break;
        }
        a /= 10;
    }
    if(c != 0) cout << "No\n";
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>

using namespace std;

int main(){

    string s;
    int front_num;
    int back_num;

    cin >> s;

    front_num = s.find_first_of('A');

    back_num =  s.find_last_of('Z');

    cout << (back_num - front_num + 1) << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

using lap_time_t = int64_t;

int main() {
  lap_time_t ret;
  std::cin >> ret;
  std::cin >> ret;
  lap_time_t t;
  while (std::cin >> t) {
    ret = boost::math::lcm(t, ret);
  }
  std::cout << ret << std::endl;
  return 0;
}

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

int main(){
    int n,ans=0;
    cin>>n;
    vector<int>b(1000000);


    for(int i=0;i<n-1;i++){
        cin>>b[i];
    }
    ans=b[0]+b[n-2];
     for(int i=0;i<n-2;i++){
         ans+=min(b[i],b[i+1]);
    }
    cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 4096
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)

n = I()
a = LI()
l = [0]*n
r = [0]*n
l[0] = a[0]
for i in range(1,n):
    l[i] = gcd(l[i-1],a[i])
r[-1] = a[-1]
for i in range(n-1)[::-1]:
    r[i] = gcd(r[i+1],a[i])

ans = 0
for i in range(n):
    if i == 0:
        ans = max(ans,r[i+1])
    elif i == n-1:
        ans = max(ans,l[-2])
    else:
        ans = max(ans,gcd(l[i-1],r[i+1]))
print(ans)



Measured memory_bytes: 59632
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<int,int> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
	string s;
	cin>>s;
	int flag=1;
	if(s[0]==s[1])flag=0;
	if(s[1]==s[2])flag=0;
	if(s[2]==s[3])flag=0;
	if(flag)cout<<"Good"<<endl;
	else cout<<"Bad"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> w(n);
    set<string> used;
    char last;
    bool fail = false;
    for (int i = 0; i < n; i++) {
        string w;
        cin >> w;
        if (i != 0) {
            if (last != w.front() || used.count(w)) {
                fail = true;
            }
        }
        last = w.back();
        used.insert(w);
    }

    cout << (fail ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){
  std::string N;
  long long int K, nbits;
  
  std::cin >> N >> K;
  nbits = N.length();

  std::vector<long long int> N_vec;
  for(long long int i = 0; i < nbits; i++){
    N_vec.push_back((long long int)N[i] - '0');
  }

  std::cerr << "N: " << N << std::endl << "K: " << K << std::endl;
  std::cerr << "N_vec:" << std::endl;
  for(long long int i = 0; i < nbits; i++){
    std::cerr << N_vec[i];
  }std::cerr << std::endl;

  // solve problem
  std::vector<std::vector<long long int> > dp(nbits, std::vector<long long int>(K+2));

  dp[0][0] = 1;
  dp[0][1] = N_vec[0]-1;
  dp[0][K+1] = 1;

  for(long long int i = 1; i < nbits; i++){
    // update dp[i][0]
    dp[i][0] = dp[i-1][0];
    // update dp[i][j] 1<=j<=K
    for(long long int j = 1; j <= K; j++){
      dp[i][j] = dp[i-1][j] + dp[i-1][j-1]*9;
    }
    if(dp[i-1][K+1] <= K && N_vec[i] != 0){
      dp[i][dp[i-1][K+1]]++;
    }
    if(dp[i-1][K+1] < K && N_vec[i] != 0){
      dp[i][dp[i-1][K+1]+1] += N_vec[i]-1;
    }
    // update dp[i][K+1]
    if(N_vec[i] != 0){
      dp[i][K+1] = dp[i-1][K+1] + 1;
    }
    else{
      dp[i][K+1] = dp[i-1][K+1];
    }
  }

  if(dp[nbits-1][K+1] == K){
    dp[nbits-1][K]++;
  }

  std::cerr << "Answer: " << std::endl;
  std::cout << dp[nbits-1][K] << std::endl;

  return 0;
}


Measured memory_bytes: 256
//If your experiment needs statistics, 
//you ought to have done a better experiment.
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=1e5+10;
int a[mx];
int main(){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",a+i);
    --a[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int j=a[i];
    if(a[j]==i)ans++;
  }
  assert(ans%2==0);
  printf("%d\n",ans/2);
  return 0;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main() {
  int n;
  cin >> n;
  int b[7][5];
  rep(i, 0, 7) {
    rep(j, 0, 5) {
      b[i][j] = i * 5 + j + 1;
    }
  }
  rep(i, 0, n) {
    int r, t;
    bool rd = false, td = false;
    cin >> r >> t;
    if(r % 100 == 0) rd = true;
    if(t % 30 == 0) td = true;
    if(r < 200) r = 0;
    else if(r < 300) r = 1;
    else if(r < 400) r = 2;
    else if(r < 500) r = 3;
    else r = 4;
    if(t < 30) t = 0;
    else if(t < 60) t = 1;
    else if(t < 90) t = 2;
    else if(t < 120) t = 3;
    else if(t < 150) t = 4;
    else if(t < 180) t = 5;
    else t = 6;

    if(rd && td) cout << b[t][r] << endl;
    if(rd && !td) {
      cout << b[t][r] << " " << b[t + 1][r] << endl;
    }
    if(!rd && td) {
      cout << b[t][r] << " " << b[t][r + 1] << endl;
    }
    if(!rd && !td) {
      cout << b[t][r] << " " << b[t][r + 1] << " ";
      cout << b[t + 1][r] << " " << b[t + 1][r + 1] << endl;
    }
  }
}

Measured memory_bytes: 3096
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がline1, 2行目がline2, …に入る
  var tmp = input.split("\n");
  //var line0 = tmp[0].split(" ");
  //var line1 = tmp[1].split(" ");
  //var line2 = tmp[2].split(" ");
  //var line3 = tmp[3].split(" ");

  var N = Number(tmp[0]);
  //var A = Number(line0[1]);
  //var B = Number(line0[2]);
  
  var pow = 1;
  for(var i=1; i<=N; i++){
    pow *= i;
    pow %= 1000000007;
  }
  
  console.log(pow);

  
  //入出力確認コード
  // A.forEach( function(value) console.log(value); );


}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;



int main(){
  long long x,k,d;
  cin >> x >>k >> d;
  long long a;
  a = abs(x)/d;
  if(k<=a){
    cout << abs(x)-k*d << endl;
  }
  else{
    if((k-a)%2==0){
      cout << abs(x)-a*d << endl;
    }
    else{
      cout << (a+1)*d-abs(x) << endl;
    }
  }
  
    
  
  
  
 
}

Measured memory_bytes: 3604
#include <cstring>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
int mmap[3][3];

int main()
{
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
			scanf("%d",&mmap[i][j]);
	}
	int sum1,sum2,sum3,sum4;
	sum1=mmap[0][0]+mmap[1][1]+mmap[2][2];
//	sum2=mmap[2][0]+mmap[1][1]+mmap[0][2];
	sum2=mmap[0][1]+mmap[1][2]+mmap[2][0];
	sum3=mmap[1][0]+mmap[2][1]+mmap[0][2];
	if(sum1==sum2&&sum2==sum3)
		printf("Yes\n");
	else printf("No\n");
}

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

int main() {
  ll n; cin >> n;
  vector<ll> a(n), b(1e7), c(1e7);
  rep(i, n) cin >> a[i];
  map<ll, ll> mp;
  rep(i, n) mp[a[i]]++;
  ll s = 0;
  for (auto p : mp) {
    ll t  = p.second;
    if (2 <= t) {
      b[p.first] += t * (t-1) / 2;
      s += b[p.first];
    }
    t--;
    if (2 <= t) c[p.first] += t * (t-1) / 2;
  }
  rep(i, n) {
    ll ans = s - b[a[i]] + c[a[i]];
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 168960
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define Rep1(i,k,n) for(int i=k ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

int main(){
    
    while(true){
        
        int n,x; cin >> n >> x;
        

        if(n + x == 0) break;
        /*

        int dp[n+10][x+10][4];
        rep(i,n+10) rep(j,x+10) rep(k,4) dp[i][j][k] = 0;
        rep(i,3) dp[0][0][i] = 1;

        rep(i,n+1){
            rep(j,x+1){
                rep(k,4){
                    if(j-i >= 0 and k >= 1) dp[i+1][j][k] = dp[i][j-i][k-1] + dp[i][j][k];
                    else dp[i+1][j][k] = dp[i][j][k];
                }
                
            }
        }

        cout << dp[n][x][3] << endl;
        */

       int ans = 0;
       rep1(i,n-2){
           Rep1(j,i+1,n-1){
               Rep1(k,j+1,n){
                   if(i+j+k == x) ans++;
               }
           }
       }
       cout << ans << endl;

    }


}


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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

const int MAXN = 405;
const int MAXC = 405;
int N;
int C;
int A[MAXN];
int B[MAXN];

const int MAXB = 405;
num sump[MAXC][MAXB];

num dp[MAXN][MAXC];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	for (int v = 1; v < MAXB; v++) {
		sump[0][v] = 1;
	}
	for (int a = 0; a+1 < MAXC; a++) {
		for (int v = 0; v < MAXB; v++) {
			sump[a+1][v] = sump[a][v] * v;
		}
	}
	for (int a = 0; a < MAXC; a++) {
		for (int v = 1; v < MAXB; v++) {
			sump[a][v] += sump[a][v-1];
		}
	}

	cin >> N >> C;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];

	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		int a = A[i]-1;
		int b = B[i];
		for (int c = 0; c <= C; c++) {
			for (int x = 0; c+x <= C; x++) {
				dp[i+1][c+x] += dp[i][c] * (sump[x][b] - sump[x][a]);
			}
		}
	}

	cout << dp[N][C] << '\n';

	return 0;
}


Measured memory_bytes: 1664
#include<cstdio>
int main(){
	char a[10003];

	while(true){
		int io=0,jo=0;
		int b=0,f=0;
		if(scanf("%s",a)==EOF) break;
		for(int i=0;a[i];i++){
			if(a[i]=='J') f=1;
			if(a[i]=='I') f=2;
			if(f){
				b=0;
				while(a[i]){
					if(a[++i]!='O'){
						i--;
						if(f==2)io+=b;
						else if(b>0){
							jo++;
							io+=b-1;
							}
						b=f=0;
						break;
						}
					if(a[++i]!='I'){
						i--;
						if(f==2)io+=b;
						else if(b>0){
							jo++;
							io+=b-1;
							}
						b=f=0;
						break;
						}
					b++;
					}
				}
			}

		if(f==2)io+=b;
		if(f==1&&b>0){jo++;io+=b-1;}
		printf("%d\n%d\n",jo,io);
		}
	return 0;
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(a,b) << " ";
  if(a+b<=n)cout << 0 << endl;
  else cout << a+b-n << endl;
}

Measured memory_bytes: 3604
using System;

class A_B_problem {
    public static void Main()
    {
        String[] s = Console.ReadLine().Split();

        int a = int.Parse(s[0]);
        int b = int.Parse(s[1]);

        int result1 = a / b;
        double result2 = a % b;
        double result3 = Convert.ToDouble(a)/ Convert.ToDouble(b);

        Console.WriteLine("{0} {1} {2,0:####.00000}",result1,result2,result3);
    }

}


Measured memory_bytes: 9336
#include <iostream>

using namespace std;

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 60 / 60;
   m = i / 60 - h*60;
   s = i % 60;
   
   cout << h << ":" << m << ":" << s << endl;
   
   return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <map>
#include <math.h>
using namespace std;

#define ll long long

int main(){
    int N,K;
    string S;
    cin >> N >> S >> K;
    for(int i = 0;i < N;i++){
        if(S[i] != S[K - 1])S[i] = '*';
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    typedef vector<pair<int , int>> vpii;
    typedef pair<int , int> pii;
    typedef pair<long long  , long long> pll;
    typedef pair<double , double> pdd;
    #define eb emplace_back;
    #define mp make_pair;
     
    int main(){
        ll n , a , b;
        cin>>n>>a>>b;
        if(a == 0){
            cout<<"0";
        }
        else{
            if(a+b<n){
                ll ans = (n / (a+b)) * a;
                if(n%(a+b)>a){
                    ans+=a;
                }
                else{
                    ans+=n%(a+b);
                }
                cout<<ans;
            }
            else if(a+b == n){
                cout<<a;
            }
            else if(a+b > n){
                if(a>n){
                    cout<<n;
                }
                else{
                    cout<<a;
                }
            }
        }
        return 0;
    }

Measured memory_bytes: 256
def foo(S,W):
    kosu=0
    S = S.lower()
    S = S.split()
    for i in range(len(S)):
        if S[i] == W:
            kosu+=1
    return kosu

x=0
W=input()
S=input()
while S != "END_OF_TEXT":
    x += foo(S,W)
    S = input()

print(x)


Measured memory_bytes: 5560
#include <iostream>
#include <string>

int main(void){
    char a,b;
    std::cin >> a >> b;

    std::string str;
    if(a < b){
        for(int i = 0; i < b-'0'; ++i){
            str += a;
        }
    }
    else {
        for(int i = 0; i < a-'0'; ++i){
            str += b;
        }        
    }

    std::cout << str << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long; 
int main(){
	int n, x, y;	cin >> n >> x >> y;
  	x--;	y--;
  	vector<int> cnt(n,0);
  	for(int i = 0; i < n-1; i++){
    	for(int j = i+1; j < n; j++){
        	int mn = min(abs(x-i)+abs(y-j)+1,abs(j-i));
          	cnt.at(mn)++;
        }
    }
  	for(int i = 1; i < n; i++) cout << cnt.at(i) << endl;
}

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

long long gcd(int a,int b){
    if(b==0)return a;
    else return gcd(b,a%b);
}

int main(){
    long long i,j;
    while(scanf("%lld %lld",&i,&j)==2){
    printf("%lld %lld\n",gcd(i,j),(i*j)/gcd(i,j));
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main () {
    int N ;
    cin >> N ;
    int ans ;
    ans = N/2 ;
    if (N%2 == 1){
        ans++ ;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = input()
scores = list(map(int, input().split()))

scores.sort()
scores.reverse()
alice_flag = True
alice_score = 0
bob_score = 0

for score in scores:
    if alice_flag:
        alice_score += score
        alice_flag = False
    else:
        bob_score += score
        alice_flag = True

print(alice_score - bob_score)


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

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

#define MOD 1000000007

using namespace std;

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

	ans = n/max(h,w);
	if( n%max(h,w) != 0 )	ans++;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include<math.h>
using namespace std;
typedef long long ll;
ll n, m;
vector<ll> yaku;
int main(void){
    // Your code here!
    cin >> n >> m;
    for (ll i = 1; i <= sqrt(m); i++){
        if (m % i) continue;
        if (i >= n) yaku.push_back(i);
        if (m / i >= n) yaku.push_back(m / i);
    }
    sort(yaku.begin(), yaku.end());
    cout << m / yaku[0] << endl;
}


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

int main() {
  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> p(n), c(n), period(n), score(n);
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
    p.at(i)--;
  }
  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
  }
  for (int i = 0; i < n; i++) {
    int64_t x = p.at(i), r = 1;
    score.at(i) = c.at(x);
    while (x != i) {
      x = p.at(x);
      score.at(i) += c.at(x);
      r++;
    }
    period.at(i) = r;
  }
  int64_t ans = -(1L << 60);
  for (int i = 0; i < n; i++) {
    int64_t x = p.at(i);
    vector<int64_t> s(period.at(i));
    for (int j = 0; j < period.at(i) - 1; j++) {
      x = p.at(x);
      s.at(j + 1) = s.at(j) + c.at(x);
    }
    for (int j = 1; j < min(k + 1, period.at(i)); j++) {
      ans = max(ans, s.at(j));
    }
    if (score.at(i) > 0) {
      for (int j = max(1L, k - period.at(i) + 1); j <= k; j++) {
        ans = max(ans, s.at(j % period.at(i)) + score.at(i) * (j / period.at(i)));
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  int N, M, Ai, x;
  int i = 0;
  x = 0;
  cin >> N >> M;
  while (i < M) {
  i++;
    cin >> Ai;
    x = x + Ai;
  }
  if (x <= N) {
  cout << N - x << endl;
  }
  else {
  cout << "-1" << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  int b[n-1];
  for (int i = 0; i < n-1; i++) {
    cin >> b[i];
  }
  long long ans = b[0];
  for (int i = 1; i < n-1; i++) {
    ans += min(b[i-1], b[i]);
  }
  ans += b[n-2];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
arr = list(map(int,input().split()))

ans = 11000
for i in range(len(arr)):
    for j in range(i+1,len(arr)):
        num = arr[i]+arr[j]
        ans = min(ans,num)

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 2940
/*** ????????¨?????? ***/

#include <bits/stdc++.h>
using namespace std;

int main(){
	int w, h, i, j, size, count;
	int in[1740];
	int maze[61][61];
	int hist[61][61];
	
	int dx[4]={0, 1, 0, -1}; // ????????????
	int dy[4]={-1, 0, 1, 0};
	
	cin >> w >> h;
	
	while(w||h){
		size=(w-1)*h+w*(h-1);
		for(i=0; i<size; ++i) cin >> in[i];
		for(j=0; j<2*h+1; ++j){
			for(i=0; i<2*w+1; ++i){
				hist[j][i]=-1;
			}
		}
		
		count=0;
		for(j=0; j<2*h+1; ++j){
			for(i=0; i<2*w+1; ++i){
				if(j==0 || j==2*h || i==0 || i==2*w) maze[j][i]=1;
				else if(j%2==0 && i%2==0) maze[j][i]=1;
				else if(j%2==1 && i%2==1) maze[j][i]=0;
				else{
					maze[j][i]=in[count];
					++count;
				}
			}
		}
		
		queue<pair<int, int>> qu;
		qu.push(make_pair(1, 1));
		hist[1][1]=1;
		while(!qu.empty()){
			pair<int, int> q=qu.front();
			qu.pop();
			int y=q.first, x=q.second;
			for(int k=0; k<4; ++k){
				int yy=y+dy[k], xx=x+dx[k];
				if(maze[yy][xx]==1) continue;
				yy+=dy[k];
				xx+=dx[k];
				if(hist[yy][xx]!=-1) continue;
				hist[yy][xx]=hist[y][x]+1;
				qu.push(make_pair(yy, xx));
			}
		}
		
		if(hist[2*h-1][2*w-1]==-1) cout << 0 << endl;
		else cout<< hist[2*h-1][2*w-1] << endl;
		
		cin >> w >> h;
	}
	return 0;
}

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

using namespace std;

int main()
{
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d >> e >> f;
	
	vector<int> x;
	vector<int> y;
	for(int i = 0; i <= f/(a*100); i++)
	{
		x.push_back(i*100*a);
	}
	for(int i = 0; i <= f/(b*100); i++)
	{
		y.push_back(i*100*b);
	}
	
	vector<int> water;
	for(auto itr_x = x.begin(); itr_x != x.end(); itr_x++)
	{
		for(auto itr_y = y.begin(); itr_y != y.end(); itr_y++)
		{
			if(*itr_x + *itr_y <= f)
			{
				water.push_back(*itr_x + *itr_y);
			}
		}
	}

	vector<int> p;
	vector<int> q;
	for(int i = 0; i <= f/c; i++)
	{
		p.push_back(i*c);
	}
	for(int i = 0; i <= f/d; i++)
	{
		q.push_back(i*d);
	}
	
	vector<int> suger;
	for(auto itr_x = p.begin(); itr_x != p.end(); itr_x++)
	{
		for(auto itr_y = q.begin(); itr_y != q.end(); itr_y++)
		{
			if((*itr_x + *itr_y) <= (f - (a > b ? b : a)*100))
			{
				suger.push_back(*itr_x + *itr_y);
			}
		}
	}
	
	int all_sum = 100*a;
	int water_sum = 100*a;
	int suger_sum = 0;
	
	for(auto itr_x = water.begin(); itr_x != water.end(); itr_x++)
	{
		for(auto itr_y = suger.begin(); itr_y != suger.end(); itr_y++)
		{
			if(*itr_x + *itr_y == 0)
			{
				continue;
			}
			
			if(*itr_x + *itr_y <= f && (*itr_x/100)*e >= *itr_y)
			{
				if((100.0*(*itr_y))/(*itr_x + *itr_y) >= 100.0*suger_sum/(water_sum + suger_sum))
				{
					all_sum = *itr_x + *itr_y;
					water_sum = *itr_x;
					suger_sum = *itr_y;
				}
			}
		}
	}
	
	cout << all_sum << " " << suger_sum << endl;
	return 0;
}

Measured memory_bytes: 1404
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		
		int min = 1001;
		for (int i = 0; i <= s.length - t.length; i++) {
			int cnt = 0;
			for (int j = 0; j < t.length; j++) {
				if (s[i + j] != t[j]) cnt++;
			}
			min = Math.min(min, cnt);
		}
		
		System.out.println(min);

		sc.close();
	}
}




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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)


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

  vector<ll> a[3];//(x,y,z)を配列のベクトルで管理
  rep(i,n){
    rep(j,3){
      ll num;
      cin >> num;
      a[j].push_back(num);
    }
  }

  ll ans=0;
  rep(bit,1<<3){//1000
    vector<ll> b;//8通りの足し方を入れる
    rep(i,n){
      ll tmp=0;
      rep(j,3){
        if(bit & 1<<j) tmp += a[j][i];
        else tmp -= a[j][i];
        //xは0番目、yは1番目、zは2番目のビットが立っていたら足す　そうでなければ引く
      }
      b.push_back(tmp);
    }
    sort(all(b));
    reverse(all(b));
    ll sum=0;
    rep(i,m){
      sum += b[i];
    }
    ans = max(ans,sum);
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
	int n; scanf("%d", &n);
	vector<pair<int, int>> acts;
	for (int i = 0; i < n; ++i) {
		int a, b; scanf("%d %d", &a, &b);
		acts.emplace_back(b, a);
	}
	sort(begin(acts), end(acts));
	reverse(begin(acts), end(acts));
	int lastDoTime = acts[0].first;
	for (int i = 0; i < n; ++i) {
		int jobDoneAt = min(lastDoTime, acts[i].first);
		lastDoTime = jobDoneAt - acts[i].second;
	}
	if (lastDoTime >= 0) printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

signed main(){

  vector<int> v(3);
  for(int i = 0; i < 3; i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  int n; cin >> n;

  vector<int> dp(n+1,0);
  dp[0] = 1;
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < n; j++){
      if(j + v[i] > n) continue;
      dp[j + v[i]] += dp[j];
    }
  }
  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 256
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

void solve(int k, vector<vector<int> > &ans, int r)
{
    if (k == 2)
    {
        ans[0].push_back(1);
        ans[1].push_back(1);
        return;
    }
    for (int j = r; j > r - k + 1; j--) ans[k - 1].push_back(j);
    for (int j = r; j > r - k + 1; j--) ans[k - 2 - (r - j)].push_back(j);
    solve(k - 1, ans, r - k + 1);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int k = 1; k <= 4000; k++)
    {
        if (k * (k + 1) == 2 * n)
        {
            cout << "Yes\n";
            cout << k + 1 << "\n";
            vector<vector<int> > ans(k + 1);
            solve(k + 1, ans, n);
            forn(i, ans.size())
            {
                cout << ans[i].size() << " ";
                forn(j, ans[i].size())
                {
                    cout << ans[i][j] << " ";
                }
                cout << "\n";
            }
            return 0;
        }
    }
    cout << "No";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> S(H);
  for(auto& v: S) {
    string s;
    cin >> s;
    for(auto c: s) v.emplace_back((c=='#') ? 0 : 1);
  }

  auto h = S, v = S;
  for(auto i=0; i<H; ++i) {
    for(auto j=1; j<W; ++j)   if(S[i][j]) h[i][j] += h[i][j-1];
    for(auto j=W-1; 0<j; --j) if(S[i][j]) h[i][j-1] = h[i][j];
  }
  for(auto j=0; j<W; ++j) {
    for(auto i=1; i<H; ++i)   if(S[i][j]) v[i][j] += v[i-1][j];
    for(auto i=H-1; 0<i; --i) if(S[i][j]) v[i-1][j] = v[i][j];
  }

  auto ans = 0;
  for(auto j=0; j<W; ++j) for(auto i=0; i<H; ++i) if(S[i][j]) ans = max(ans, v[i][j]+h[i][j]-1);
  cout << ans << endl;
}


Measured memory_bytes: 47744
(defun read-list (x &optional ret)
  (if (< x 1)
    (reverse ret)
    (read-list (1- x) (cons (read) ret))))

(defun cal-min (lst p &optional (ans 0))
  (if (null lst)
    (* ans 2)
    (cal-min (cdr lst) p (+ (min (abs (- (car lst) p)) (car lst)) ans))))


(let* ((n (read))
       (k (read))
       (l (read-list n)))

    (format t "~A~%"
          (cal-min l k)))


Measured memory_bytes: 24280
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	for i := 0; i < m; i++ {
		n -= getNextInt(scanner)
	}
	if n < 0 {
		n = -1
	}
	fmt.Fprintln(writer, n)
}


Measured memory_bytes: 1888
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll N;
	cin >> N;
	ll a,b,a_1,b_1;
	ll ans = LINF;
	for (ll i = 1;i*i <= N;i++){
		if (N % i == 0){
			a = N / i;
			ans = min(ans,a- 1+i- 1);
		}
	}
	cout  << ans <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int x,y,z,total;
	scanf("%d %d %d",&x, &y, &z);
	total = x+y+z;
	if (total>=22){
		printf("bust\n");
	}
	else if (total<22){
		printf("win\n");
	}
}

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

#include <iostream>
#include <vector>
// #include <map>
// #include <string>
// #include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (r <= x and x <= W - r and r <= y and y <= H - r) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 3100
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<ll> par;
//     vector<ll> siz;
    
//     UnionFind(ll N): par(N), siz(N,1LL) {
//         for (ll i=0;i<N;i++) par[i] = i;
//     }

//     ll root(ll x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//         siz[ry] += siz[rx];
//     }

//     bool same(ll x, ll y) {
//         ll rx = root(x);
//         ll ry = root(y);
//         return rx == ry;
//     }

//     ll size(ll x) {
//         return siz[root(x)];
//     }
// };

int main(void) {
    string S;
    cin >> S;
    for (int i=0;i<S.size();i++) cout << 'x';
    cout << endl;

    return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m, d;
	cin >> n >> m >> d;

	ll l = n - d, r = d;
	ll dif = max(0, r - l), dif2 = max(l - r, 0);
	if (d == 0) cout << fixed << setprecision(20) << (long double)(m - 1) / n << endl;
	else cout << fixed << setprecision(20) << (long double)(m - 1) / n * (n - dif + dif2) / n << endl;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: i64,
    }

    for a in -130..130 {
        let mut a5 = 1;
        a5 *= a * a * a * a * a;
        for b in -130..130 {
            let mut b5 = 1;
            b5 *= b * b * b * b * b;
            if a5 - b5 == x {
                println!("{} {}", a, b);
                return;
            }
        }
    }
}


Measured memory_bytes: 2188
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000000+10;
int a[maxn];
int main()
{
    int k,s;
    scanf("%d%d",&k,&s);
    for(int i=0; i<=k; i++)
        for(int j=0; j<=k; j++)
            a[5000+i+j]++;
    int sum=0;
    for(int i=0; i<=k; i++)
    {
        int pos=s-i;
        if(pos<0)continue;
        sum+=a[5000+pos];
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
/**
*    created: 12.05.2020 09:13:58
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, x; cin >> n >> x;
    int cnt = 1; //残りn回
    int d = 0;
    rep(i,n) {
        int l; cin >> l;
        d += l;
        if (d <= x) cnt++;
        else break;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
N, C, K = map(int, input().split())
t = [int(input()) for _ in range(N)]
t.sort()

a = 0

c = 0
l = t[0]
for i in range(N):
    if c == C or t[i] - l > K:
        a += 1
        c = 0
        l = t[i]
    
    c += 1

if c > 0:
    a += 1

print(a)

Measured memory_bytes: 7384