akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<int, int> pi;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    cout << (n+1)/2;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a,b,c,sum = 0;
		int[] d = new int[100];
		a = scan.nextInt();
		b = scan.nextInt();
		
		for(int i = 0; i < b; i++) {
			sum += scan.nextInt();
		}
		if(sum % (a + 1) == 0) c = sum / (a + 1);
		else c = sum / (a + 1) + 1;
		
		System.out.println(c);
	}
}


Measured memory_bytes: 26164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template <typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template <typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}

int N,M;
ve<vi> G;
vi A;
int root = 0;
vi D;

int dfs(int n){
    
    if(D[n] >= 0) return D[n];
    
    if(A[n] == n) return D[n] = 0;
    if(A[n] != -1) return D[n] = dfs(A[n])+1;
    int res = 0;
    for (int p : G[n]) {
        int aa = dfs(p)+1;
        //cout << n csp p csp aa << endl;
        if(chmax(res,aa)){
            A[n] = p;
        }
    }
    
    return D[n] = res;
}


int main()
{
    cin >> N >> M;
    G.resize(N);
    D.assign(N,-1);
    rep(i,N+M-1){
        int a,b;
        cin >> a >> b;
        a--,b--;
        G[b].pb(a);
    }
    A.assign(N,-1);
    rep(i,N){
        if(G[i].size() == 1){
            A[i] = G[i][0];
        }else if(G[i].size() == 0){
            A[i] = i;
            root = i;
        }
    }
    
    
    rep(i,N){
        if(A[i] == -1){
            dfs(i);
        }
    }
    
    
    rep(i,N) {
        if(A[i] == i) cout << 0 << endl;
        else cout << A[i]+1 << endl;
    }
    
    
    

    
    
    
    

    return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int, int> tupl;
typedef pair<int, pair<int, int>> tripl;

vi horses;

int main() {
    int k, n; scanf("%i %i", &k, &n);
    for (int i = 0; i < n; i++)
    {
        int t; scanf("%i", &t);
        horses.push_back(t);
    }

    vi dists;
    for (int i = 0; i < n; i++)
    {
        if (i == 0) continue;
        dists.push_back(horses[i]- horses[i-1]);
    }
    dists.push_back(k-horses[n-1]+horses[0]);

    sort(dists.begin(), dists.end());
    reverse(dists.begin(), dists.end());
    printf("%i", k - dists[0]);
    
}


Measured memory_bytes: 2548
#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()
#define endl "\n"

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

const int MOD = 1e9 + 7;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(abs(a - c) <= d || (abs(a-b) <= d && abs(b-c) <= d)) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

const int N = 1e3 + 11;
int a[N];

int32_t main() {                                                                                                                        
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    sort(a, a + n);
    int sum = 0;
    for (int i = 0; i < k; i++)
      sum += a[i];
    cout << sum << endl;
}   


Measured memory_bytes: 3624
import java.util.*;

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

        int k = sc.nextInt();
        int n = sc.nextInt();

        int[] a = new int [n];

        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }

        int max = k - a[n - 1] + a[0];

        for(int i = 0; i < n - 1; i++){
            int sub = a[i + 1] - a[i];

            if(max < sub){
                max = sub;
            }
        }

        System.out.println(k - max);
    }
}


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

int main(){
    int n,m;
    cin >> n >> m;
    int sum = 0;
    for(int i=0;i<m;i++){
        int a;
        cin >> a;
        sum += a;
    }
    if(sum > n)cout << -1 << endl;
    else cout << n-sum << endl;
}

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

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll S; cin >> S;
	ll BASE = ll(1e9);
	cout << 0 << ' ' << 0 << ' ' << (S + BASE - 1) / BASE << ' ' << ((S + BASE - 1) / BASE * BASE - S) << ' ' << 1 << ' ' << BASE << '\n';

	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,n;
    cin >> h >> n;
    int sum = 0;
    REP(i,n){
        int a;
        cin >> a;
        sum+=a;
    }
    if(sum>=h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

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

const ll MOD = 1e9+7;

// Combinationの使い方
// vector<vector<ll>> v(N+1, vector<ll>(N+1, 0));
// comb(v);
void comb(vector<vector<ll>> &v){
    for(int i = 0; i < v.size(); i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(int k = 1; k < v.size(); k++){
        for(int j = 1; j < k; j++){
            v[k][j] = (v[k-1][j-1] + v[k-1][j]);
            //余りを求める問題は毎回計算ごとにやる
            // v[k][j] = (v[k-1][j-1] + v[k-1][j]) % MOD;
        }
    }
}

// Union Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : int "3" change to bit "100"
// rep(pattern, 1 << N) if (pattern & (1 << x)) cnt++

// 過去問第3問ABC113Bまでdone

string S;
vector<string> memo;

ll calc(string s){
    ll tmp = 0;
    ll ans = 0;
    rep(i, s.size()){
        if(s[i]!='+'){
            tmp = tmp*10 + (s[i]-'0');
        }else{
            ans += tmp;
            tmp = 0;
        }
    }
    ans += tmp;
    return ans;
}

ll search(string s, int i, int flag){
    ll sum = 0;
    if(s[i]==S[S.size()]){
        return 0;
    }

    if(flag==0) s.insert(i,"+");

    bool find_flag = true;
    rep(j,memo.size()){
        if(memo[j]==s){
            find_flag = false;
            break;
        }
    }

    if(find_flag){
        memo.push_back(s);
        sum += calc(s);
        // cout << s << " " << calc(s) << endl;
    }

    if(flag==0){
        sum += search(s, i+2, 0);
        sum += search(s, i+2, 1);
    }else{
        sum += search(s, i+1, 0);
        sum += search(s, i+1, 1);
    }
  
    return sum;
}

int main(){
    cin >> S;

    // cout << search(S, 1, 0) << endl;
    // cout << search(S, 1, 1) << endl;

    if(S.size()==1) cout << S << endl;
    else cout << search(S, 1, 0) + search(S, 1, 1) << endl;
    
    return 0;
}

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

#define real() cout<<"\n";

#define debug(arguments...) {string pri=#arguments;replace(pri.begin(),pri.end(),',',' ');stringstream prii(pri);istream_iterator<string> _iterat(prii);error(_iterat,arguments);}
void error(istream_iterator<string> _iterat) {}
template<typename T,typename...args>
void error(istream_iterator<string> _iterat,T a,args...arguments)
{
    cerr<<*_iterat<<"="<<a<<"\n";
    error(++_iterat,arguments...);
}

#define debugmp(z) {string pri=#z;error(pri,z);}
template<typename T,typename V>
void error(string pri,const pair<T,V> &z)
{
    cerr<<pri<<"="<<"{"<<z.first<<","<<z.second<<"}"<<"\n";
}
template<typename T,typename V>
void error(string pri,const map<T,V> &z)
{
    cerr<<pri<<" is={";
    for(auto it=z.begin();it!=z.end();++it)
    {
        cerr<<it->first<<":"<<it->second;
        auto _it=z.end();
        _it--;
        if(it!=_it) cerr<<",";
    }
    cerr<<"}";
    cerr<<"\n";
}

#define debugc(z,st,ed) {string pri=#z;error(pri,z,st,ed);}
template<typename T>
void error(string pri,const vector<T> &z,long long st,long long ed)
{
    cerr<<pri<<" in range["<<st<<","<<ed<<")=[";
    for(long long i=st;i<ed;++i)
    {
        cerr<<z[i];
        if(i!=ed-1) cerr<<" ";
    }
    cerr<<"]";
    cerr<<"\n";
}
template<typename T>
void error(string pri,const set<T> &z,long long st,long long ed)
{
    cerr<<pri<<" in range["<<st<<","<<ed<<")=[";
    long long tempcount=0;
    for(auto it=z.begin();it!=z.end();++it)
    {
        if(tempcount>=st and tempcount<ed)
        {
            cerr<<*it;
            if(tempcount!=ed-1) cerr<<" ";
        }
        tempcount++;
    }
    cerr<<"]";
    cerr<<"\n";
}
template<typename T>
void error(string pri,const T z[],long long st,long long ed)
{
    cerr<<pri<<" in range["<<st<<","<<ed<<")=[";
    for(long long i=st;i<ed;++i)
    {
        cerr<<z[i];
        if(i!=ed-1) cerr<<" ";
    }
    cerr<<"]";
    cerr<<"\n";
}

void logic()
{
    string s;
    cin>>s;
    if(s[s.length()-1]=='s') 
    {
        s.push_back('e');
        s.push_back('s');
    }
    else s.push_back('s');
    cout<<s;
    cout<<"\n";
    //incase of wrong answer...stress test your code...do not stress test yourself
    //overflow,bounds,size,constraints
    //sample tests,corner case/special case(n==0 or n==1 or negative numbers...),some hand written tests
    //read statement carefully
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    long long t;
    //cin>>t;
    //while(t--)
    {
        logic();
    }
}


Measured memory_bytes: 3652
#include<stdio.h>

int main(){
  int i,p,r,n,q=0,x,s=0,u=0,j;

  scanf("%d",&n);
  int A[n+1];
  A[0]=0;
  r=n;
  for(i=1;i<n+1;i++){
    scanf("%d",&A[i]);
  }
  p=1;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      s=A[i];
      A[i]=A[j];
      A[j]=s;
    }
  }
  u=A[i+1];
  A[i+1]=A[r];
  A[r]=u;
  q=i+1;
  for(i=1;i<q;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[q]);
  for(i=q+1;i<n+1;i++){
  if(i<n){
    printf("%d ",A[i]);
  }
  else printf("%d",A[i]);
  }
  printf("\n");
  return 0;
  
}






Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
#define T tuple<int,int,int>

int main(){
	int a,b;
	cin>>a>>b;
	if(a+b>=10){
		cout<<"error"<<endl;
	}else{
		cout<<a+b<<endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a;
	int h, m, s;

	scanf("%d", &a);
	
	h = a / 3600;
	m = (a - h * 3600) / 60;
	s = a - h * 3600 - m * 60;

	printf("%d:%d:%d\n", h, m, s);

	return 0;
}

Measured memory_bytes: 592
#include<stdio.h>
#include<string.h>
int main(){
  int i,flag=0,ct=0;
  char a[3];
  scanf("%s",a);
  for(i=0;i<3;i++){
    if(flag){
      if(a[i]=='R'){
        ct++;
      }else{

          printf("%d",ct);
          return 0;

        
      }
    }else{
      if(a[i]=='R'){
        ct++;
        flag=1;
      }
    }
  }
  printf("%d",ct);
  return 0;
}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> H(N);
    rep(i, 0, N) cin >> H[i];
    VVL G(N);
    rep(i, 0, M){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    ll ans = 0;
    rep(i, 0, N){
        bool f = true;
        for(auto g : G[i]){
            if(H[g] >= H[i]) f = false;
        }
        if(f) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9856
#include <stdio.h>
int main(){
  int n,m,l,i,j,k;
  int A[101][101]={};
  int B[101][101]={};
  double C[101][101]={};

  scanf("%d %d %d",&n,&m,&l);

  for(i=1;i<=n;i++){
    for(j=1;j<=m;j++){
      scanf("%d",&A[i][j]);
    }
  }
  for(i=1;i<=m;i++){
    for(j=1;j<=l;j++){
      scanf("%d",&B[i][j]);
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=m;j++){
      for(k=1;k<=l;k++){
	C[i][k]+=A[i][j]*B[j][k];
      }
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=l;j++){
      if(j==l){
	printf("%.0f",C[i][j]);
      }else{
	printf("%.0f ",C[i][j]);
      }
    }
    printf("\n");
  }
  return 0;
}

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

#define fast ios::sync_with_stdio(0); cin.tie(NULL); 
#define fi first
#define se second
#define mp make_pair
#define pi 3.14159265359
#define MOD 1000000007
#define inf 1e18
#define setbits(x) __builtin_popcountll(x)
typedef long long ll;
#define mp make_pair
#define ALL(v) v.begin(), v.end() 
#define F(i,s,n) for(i=s;i<n;++i)
#define pb push_back
#define eb emplace_back
#define tin freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pll pair<ll,ll>
ll max(ll a,ll b)
{
    return a*(a>=b)+b*(b>a);
}
string smax(string a,string b)
{
    if(a.size()>b.size())return a;
    return b;
}
/*----------------------------------------------------------*/
string a,b;

void solve()
{
    cin>>a>>b;
    ll n=a.size(),m=b.size();
    ll dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(ll i=1;i<n+1;++i)
    {
        for(ll j=1;j<m+1;++j)
        {
            if(a[i-1]==b[j-1])dp[i][j]=1+dp[i-1][j-1];
            dp[i][j]=max(dp[i][j],dp[i][j-1]);
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            //cout<<dp[i][j]<<" ";
        }//cout<<endl;
    }
    ll i=n,j=m;
    string s=" ";
    while(i!=0&&j!=0)
    {
        if(dp[i][j]==dp[i][j-1])--j;
        else if(dp[i][j]==dp[i-1][j])--i;
        else {--i;--j;s=a[i]+s;}
    }cout<<s;
}

int main()
{
    //tin
    fast
    ll tc=1;//cin>>tc;
   for(ll i=1;i<=tc;++i)
   {
    //cout<<"Case #"<<i<<": ";
    solve();
    if(i!=tc)cout<<"\n";
   }
return 0;
}
//End-Cases 
//Precomputation
//Segmentation Fault
//Complexity
//Break it up
//Sub Problems


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

int T[200000000];
int size = 0;

void maxHeapify(int i)
{
    int l = i * 2;
    int r = i * 2 + 1;
    int largest;
    if (l <= size && T[l] > T[i])
    {
        largest = l;
    }
    else
    {
        largest = i;
    }
    if (r <= size && T[r] > T[largest])
    {
        largest = r;
    }

    if (largest != i)
    {
        swap(T[i], T[largest]);
        maxHeapify(largest);
    }
}

void Insert(int key)
{
    int i;
    size++;
    T[size] = key;
    i = size;
    while (i > 1 && T[i / 2] < T[i])
    {
        swap(T[i / 2], T[i]);
        i = i / 2;
    }
}

int Delete()
{
    int key = T[1];
    T[1] = T[size];

    size--;
    maxHeapify(1);
    return key;
}

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

    int key;
    string com;

    cin >> com;
    while (com[2] != 'd')
    {
        if (com[0] == 'i')
        {
            cin >> key;
            Insert(key);
        }
        else if (com[1] == 'x')
        {
            cout << Delete() << endl;
        }

        cin >> com;
    }

    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i<N; i++) {
    cin >> H.at(i);
  }
  sort(H.begin(), H.end());
  reverse(H.begin(), H.end());
  int64_t count = 0;
  for (int i = 0; i<N-K; i++) {
    count += H.at(N-1-i);
  }
  cout << count << endl;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int n, k; cin >> n >> k;
    cout << (n+k-1)/k - n/k << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll l = -1, r = 1e18;
  while(l + 1 < r) {
    ll x = (l + r) / 2;
    vl b(n + 1);
    b[0] = x * 2;
    rep(i, n) b[i + 1] = 2 * a[i] - b[i];
    if(b[n] < b[0])
      r = x;
    else if(b[n] > b[0])
      l = x;
    else {
      rep(i, n) cout << b[i] << '\n';
      return 0;
    }
  }
}

Measured memory_bytes: 4920
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long c7 = calc(7 * M);
		long c14 = calc(14 * M);
		long joint = c7 * 2 - c14;
		long crest = calc((int) ((N * 7) % (M * 7)));
		long ans = ((7 * N) / (7 * M)) * c7 + crest - ((7 * N) / (7 * M) - 1) * joint - ((N * 7) % (M * 7) != 0 ? 1 : 0) * joint;
		Console.WriteLine(ans);
	}
	
	long calc(int hw){
		if(hw == 0) return 0;
		int w = 7;
		int h = hw / w;
		
		int[][] m = new int[h][];
		for(int i=0;i<h;i++) m[i] = new int[w];
		
		foreach(var r in A){
			for(int j=r;j<hw;j+=M){
				m[j/w][j%w] = 1;
			}
		}
		
		int[] dx = {0, 1, 0, -1};
		int[] dy = {1, 0, -1, 0};
		var UF = new UnionFind(hw);
		for(int i=0;i<hw;i++){
			int y = i / w;
			int x = i % w;
			for(int t=0;t<4;t++){
				int ny = y + dy[t];
				int nx = x + dx[t];
				if(!InRange(ny, 0, h) || !InRange(nx, 0, w)) continue;
				if(m[ny][nx] == m[y][x]) UF.Unite(i, ny * w + nx);
			}
		}
		
		long ret = 0;
		for(int i=0;i<hw;i++) if(UF.IsRoot(i) && m[i / w][i % w] == 0) ret++;
		return ret;
		
	}
	bool InRange(int t, int l, int r){
		return l <= t && t < r;
	}
	
	int M,Q;
	long N;
	int[] A;
	public Sol(){
		var d = rla();
		N = d[0]; M = (int) d[1]; Q = (int) d[2];
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
class UnionFind{
	
	int[] parent;
	int[] mem;
	int compo;
	int N;
	public UnionFind(int n_){
		Initialize(n_);
	}
	
	public void Initialize(int n_){
		N=n_;
		parent=new int[N];
		mem=new int[N];
		for(int i=0;i<N;i++){
			parent[i]=i;
			mem[i]=1;
		}
		compo=N;
	}
	
	public int Parent(int a){
		if(parent[a]==a)return a;
		return parent[a]=Parent(parent[a]);
	}
	
	public bool IsUnited(int a,int b){
		return Parent(a)==Parent(b);
	}
	
	public void Unite(int a,int b){
		a=Parent(a);b=Parent(b);//Parent()を呼ぶことでa以上のノードは全てparentがrootになる
		if(a==b)return;
		parent[a]=b;
		mem[b]+=mem[a];
		compo-=1;
	}
	
	public bool IsRoot(int x){
		return x==parent[x];
	}
	public int MemCnt(int x){
		return mem[Parent(x)];
	}
	
	public void Dump(){
		for(int i=0;i<parent.Length;i++){
			Console.Write(i==0?"{0}":" {0}",parent[i]);
		}
		Console.WriteLine("");
	}
	
	public int Compo{
		get{
			return compo;
		}
	}
	
}


Measured memory_bytes: 49496
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const int N=1e6+10;
typedef long long ll;
const ll mod=1e9+7;
#define per(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define inf 0x3f3f3f3f
#define qwq puts("QWQ");
#define qaq puts("QAQ");
#define mem(a,b) memset(a,b,sizeof(a))
#define mid ((l+r)>>1)
#define l(x) x<<1
#define r(x) x<<1|1
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
void read(int &x)
{
	int f=1;x=0;
	char s=getchar();
	while(s<'0'||s>'9')
    {
    	if(s=='-')f=-1;
    	s=getchar();
	}
	while(s>='0'&&s<='9')x=x*10+s-'0',s=getchar();
	x*=f;
}
char s[maxn];
int n;
int main()
{
	read(n);
	scanf("%s",s+1);
	int k=0;
	rep(i,1,n)
	{
		if(s[i]!=s[i-1])k++;
	}
	printf("%d\n",k);
}

Measured memory_bytes: 384
import Control.Applicative
import Control.Monad

f :: (Int, Int, Int) -> IO Bool
f (p, q, r)= do
  b <- forM [0..(q-1)] $ \i -> do
    if p*i `mod` q == r then return True
                        else return False
  return $ foldl (||) False b

main = do
  nums <- (\[x, y, z] -> (x, y, z)) . map read . words <$> getLine :: IO (Int, Int, Int)
  (f nums) >>= (\x -> if x then return "YES" else return "NO") >>= putStrLn


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1),b(n);
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];
  ll ans = 0;
  rep(i,n){
    ans += min(a[i]+a[i+1],b[i]);
    a[i+1] = clamp(a[i]+a[i+1]-b[i],0,a[i+1]);
  }
  cout << ans << endl;
}

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

int main() {
    int N, A[200];
    cin >> N;

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

    int count = 0;
    // 各要素が割り切れる限りループを続ける。
    // ループの回数（全要素を割った回数）は count で表す。

    bool exist_odd = false;
    while (true) {
        for (int i=0; i<N; i++) {
            if (A[i] % 2 != 0) {
                exist_odd = true;
            }
        }

        if (exist_odd) break;

        for (int i=0; i<N; i++) {
            A[i] /= 2;
        }

        count++;
    }

    cout << count << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const long long MOD = 1000000007;

ll N, M;
ll S[100010], T[100010];
ll dp[2010][2010];
ll mp[100010];

ll solve(){
    dp[0][0] = 1;
    REP(i, N) dp[i + 1][0] = 1;
    REP(j, M) dp[0][j + 1] = 1;
    REP(i, N){
        REP(j, 100010) mp[j] = 0;
        REP(j, M){
            mp[T[j]] = (mp[T[j]] + dp[i][j]) % MOD;
            dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j + 1] + mp[S[i]]) % MOD;
        }
    }
    return dp[N][M];
}

signed main(){
    cin >> N >> M;
    REP(i, N) cin >> S[i];
    REP(i, M) cin >> T[i];
    PRINT(solve());
    return 0;
}

Measured memory_bytes: 35848
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n;
  ll k;
  cin>>n>>k;

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

//————————————————二分探索——————————————————————————

  ll ng = 0;
  ll ok = 1e9;
  while (abs(ok - ng) > 1) {
    ll mid = (ng + ok) / 2;

    ll cnt=0;
    rep(i,n){
      cnt+=(p[i]+mid-1)/mid-1;
    }
    (cnt<=k? ok : ng) = mid;
  }

  cout << ok << endl;

//——————————————————————————————————————————



}

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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP				make_pair
#define X				first.first
#define Y				first.second

typedef pair<int, int> P;

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

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

int ans;

void dfs( int n, int s, int i ) {
	if( i > 9 ) {
		if( n == 0 && s == 0 ) ans++;
		return;
	}

	dfs( n - 1, s - i, i + 1 );
	dfs( n, s, i + 1 );
	
}

signed main() {
	int n, s;
	while( cin >> n >> s, n ) {
		ans = 0;
		dfs( n, s, 0 );
		cout << ans << endl;
	}
}


Measured memory_bytes: 3092
N = int(input())
Rt = []

for _ in range(N):

    # 価格
    Rt.append(int(input()))

minR = 10**9
profit = Rt[1]-Rt[0]

for i in range(0,N-1):
    minR = min(minR, Rt[i])
    profit = max(profit, Rt[i+1] - minR)

print(profit)


Measured memory_bytes: 13596
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
x = [int(item) for item in list(input().rstrip())]
x.reverse()

ones = x.count(1)
aug = ones + 1
dim = ones - 1

modaug = 0
moddim = 0
for i, item in enumerate(x):
    if item == 1:
        modaug += pow(2, i, aug)
        modaug %= aug
        if dim != 0:
            moddim += pow(2, i, dim)
            moddim %= dim

cnt = [-1] * (2*10**5 + 10)
cnt[0] = 0; cnt[1] = 1
for i in range(1, 2*10**5 + 10):
    val = i
    num = bin(val).count("1")
    cnt[i] = cnt[val % num] + 1

ans = []
for i, item in enumerate(x):
    if item == 0:
        tmp = modaug + pow(2, i, aug)
        tmp %= aug
    else:
        if dim == 0:
            ans.append(0)
            continue
        else:
            tmp = moddim - pow(2, i, dim)
            tmp %= dim
    ans.append(cnt[tmp] + 1)

ans.reverse()
for item in ans:
    print(item)

Measured memory_bytes: 96800
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var x = new double[N];
            var y = new double[N];
            var list = new List<double>();

            for (int i =0; i < N; i++)
            {
                var A = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
                x[i] = A[0];
                y[i] = A[1];
            }

            for(int i =0; i <N-1; i++)
            {
                for(int j= i+1; j < N; j++)
                {
                    var a = Math.Sqrt(Math.Pow(x[i] - x[j], 2) + Math.Pow(y[i] - y[j], 2));
                    list.Add(a);
                }
            }

            var b = list.Sum();

            if(N == 2)
            {
                Console.WriteLine(b);
            }
            else
            {
                for (int i = 3; i <= N; i++)
                {
                    b = b * (i - 1) / i;
                }

                Console.WriteLine(b);
            }

        }
        
    }

}


Measured memory_bytes: 13268
require "complex"

def distance(p,q)
  Math.sqrt(p*p + q*q)
end

results = []

n, d = gets.split(" ").map(&:to_i)
lines = readlines.map(&:chomp)

lines.each do |line|
  p, q = line.split(" ").map(&:to_i)
  result = distance(p, q)
  if result <= d
    results << result
  end
end

puts results.count

Measured memory_bytes: 46552
import java.util.*;
import static java.lang.System.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		long A = 0, B = 0;
		long[] scores = new long[n];
		scores[0] = sc.nextLong();
		A = scores[0];
		for(int i = 1; i < n; i++) {
			scores[i] = sc.nextLong();
			B += scores[i];
		}
		long ans = Math.abs(A - B);
		for(int i = 1; i < n - 1; i++) {
			A += scores[i];
			B -= scores[i];
			ans = Math.min(ans, Math.abs(A - B));
		}
		out.println(ans);
		
		out.close();
	}

	

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}


Measured memory_bytes: 24976
#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(){
    int a, b, x;
    cin >> a >> b >> x;
    if(x < a) cout << "NO" << endl;
    else if(a+b < x) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 3600
#include<stdio.h>
int main(){
  int m, f, r;

  while(1){
    scanf("%d%d%d",&m,&f,&r);

    if(m == -1 && f == -1 && r == -1)break;
    if(m == -1||f == -1){
      printf("F\n");
    }
    else if(m + f >= 80){
      printf("A\n");
    }
    else if(m + f >= 65 && m + f < 80){
      printf("B\n");
    }
    else if(m + f >= 50 && m + f < 65){
      printf("C\n");
    }
    else if(r >= 50){
      printf("C\n");
    }
    else if(m + f >= 30 && m + f < 50){
      printf("D\n");
    }
    else if(m + f < 30){
      printf("F\n");
    }
  }
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

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

constexpr ll MOD = 1e9 + 7;

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

    int n;
    ll a[410];

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    ll dp[410][410];
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            dp[i][j] = 1e17;

    for (int i = 0; i < n; i++)
        dp[i][i] = 0;

    ll sum[410];
    sum[0] = 0;
    for (int i = 0; i < n; i++)
        sum[i + 1] = sum[i] + a[i];

    for (int r = 2; r <= n; r++)
    {
        for (int i = 0; i + r - 1 < n; i++)
        {
            int j = i + r - 1;

            for (int k = i; k < j; k++)
            {
                dp[i][j] = min(dp[i][j], sum[j + 1] - sum[i] + dp[i][k] + dp[k + 1][j]);
            }
        }
    }

    cout << dp[0][n - 1] << endl;

    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
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;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N,K;
    cin >> N >> K;
    ll ans = 0;
    for(ll i = K;i < N + 2;i++){
        ll n = ((N - i + 1) * i + 1) % mod;
        ans += n;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

namespace Printer{
    void print(vector<int> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    void print(vector<vector<int> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void print(pair<int, int> p){
        cout << "(" << p.first << ", " << p.second << ")" << endl;
    }
};

//--global--//



//----------//

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    bool hasE[3001];
    bool hasF[3001];
    fill(hasE,hasE+3001, false);
    fill(hasF, hasF+3001, false);
    hasE[0] = true;
    hasF[0] = true;
    for(int i=f; i>=0; i--){
        if(hasF[i]){
            for(int j=i; j<=f; j+=a*100){
                hasF[j] = true;
            }
        }
    }
    for(int i=f; i>=0; i--){
        if(hasF[i]){
            for(int j=i; j<=f; j+=b*100){
                hasF[j] = true;
            }
        }
    }

    for(int i=f; i>=0; i--){
        if(hasE[i]){
            for(int j=i; j<=f; j+=c){
                hasE[j] = true;
            }
        }
    }
    for(int i=f; i>=0; i--){
        if(hasE[i]){
            for(int j=i; j<=f; j+=d){
                hasE[j] = true;
            }
        }
    }
    // rep(i, f+1){
    //     if(hasE[i]){
    //         cout << i << endl;
    //     }
    // }

    // rep(i, f+1){
    //     if(hasF[i]){
    //         cout << i << endl;
    //     }
    // }
    double ma = 0;
    int sumg = 0;
    int sugarg = 0;
    rep2(i, 1, 3001){
        if(hasF[i]){
            rep(j, 3001){
                if(hasE[j]){
                    int sum = i + j;
                    if(sum <= f && j <= (i/100) * e){
                        if(ma < (double)(100 * j) / (double)(sum) || sumg == 0){
                            ma = (double)(100 * j) / (double)(sum);
                            sumg = sum;
                            sugarg = j;
                        }
                    }
                }
            }
        }
    }

    cout << sumg << " " << sugarg << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pii pair<ll, ll> 
#define pb push_back
#define debug(x) cerr<< #x << " is " <<x<<endl;
#define debug2(x) cerr<<#x<< " is\n"; for (auto &i:x) {cout<<i<<' '; } cout<<endl;
#define f first
#define s second
using namespace std;

const ll mod = 1e9+7;

char grid[1005][1005];
int dp[1005][1005];

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n, m; cin>>n>>m;
    for (int i=0; i<n; i++){
    	for (int j=0; j<m; j++){
    		cin>>grid[i][j];
    	}
    }
    dp[0][0]=1;
    for (int i=0; i<n; i++){
    	for (int j=0; j<m; j++){
    		dp[i][j]%=mod;
    		if (grid[i][j]!='#'){
    			dp[i+1][j]+=dp[i][j];
    			dp[i][j+1]+=dp[i][j];
    		}
    	}
    }
    cout<<dp[n-1][m-1]%mod<<'\n';
}

Measured memory_bytes: 5248
n, k = map(int, input().split())
kmax = (n - 1) * (n - 2) // 2
if k > kmax:
    print(-1)
else:
    rest = kmax - k
    print(n - 1 + rest)
    for i in range(1, n):
        print(i, n)
    i, j = 1, 2
    while rest:
        print(i, j)
        j += 1
        if j == n:
            i += 1
            j = i + 1
        rest -= 1

Measured memory_bytes: 3616
//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pii pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;
    
    int D[N];bool vis[N];int tg[N],cc[N];
    pii e[N];int w[N];
    map<int,int> id[N];
    vc<int> to[N];
    void dfs(int x,int col)
    {
		vis[x]=1;cc[x]=col;
    	for(auto y:to[x]) if(!vis[y])
    	{
    		dfs(y,col^1);
			w[id[x][y]]=D[x];//=D[y]
    		tg[x]++;tg[y]++;
		}return;
	}
	void brush(int x,int col)
	{
		cc[x]=col;vis[x]=1;
		for(auto t:id[x])
		{
			int y=t.FR;
			if(vis[y] or D[y]<=D[x]) continue;
			w[t.SE]=D[y]-D[x];
			brush(y,col);
		}
	}
	bool st[N];
	void main()
	{
		int n=qread(),m=qread();fo(i,1,n) D[i]=qread();
		fo(i,1,m)
		{
			int x=qread(),y=qread();e[i]={x,y};
			id[x][y]=id[y][x]=i;w[i]=1e9;
			if(D[x]==D[y]) to[x].PB(y),to[y].PB(x);//配色边，两边异色 
		}
		fo(x,1,n)
		{
			st[x]=1;
			for(auto t:id[x]) if(D[t.FR]<D[x]) st[x]=0;
		}
		fo(x,1,n) if(!vis[x] and st[x])
		{
			dfs(x,0);//分配颜色，不能有孤立点 
			if(!tg[x]) {printf("-1");return;}
		}
		fo(x,1,n) if(vis[x]) brush(x,cc[x]);
		fo(x,1,n) putchar(cc[x]?'B':'W');puts("");
		fo(i,1,m) write2(w[i]);
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 109568
from collections import Counter
N=int(input())
cnt=sorted(Counter(list(map(int, input().split()))).items(), reverse=True)
b=[]
for k, v in cnt:
    if v>=4 and b==[]:
        print(k*k)
        exit()
    elif v>=2:
        b.append(k)
        if len(b)==2:
            print(b[0]*b[1])
            exit()
print(0)


Measured memory_bytes: 21412