akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n); i >= 0; i--)
#define rloop(i, n, a) for(int i = (n); i >= (a); i--)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define dd(x) cout << #x << " : " << x << endl
using namespace std;
using ll = int64_t;

struct Comb {
    const ll mod;
    vector<ll> fact, ifact;
    ll mod_pow(ll x, ll n, const ll mod){
        ll ans = 1;
        while(n){
            if(n & 1) ans = ans*x%mod;
            x = x*x%mod;
            n >>= 1;
        }
        return ans;
    }
    Comb(int n, ll mod) : fact(n+1), ifact(n+1), mod(mod) {
        fact[0] = 1;
        loop(i, 1, n+1) fact[i] = fact[i-1] * i % mod;
        ifact[n] = mod_pow(fact[n], mod-2, mod);
        rloop(i, n, 1) ifact[i-1] = ifact[i] * i % mod;
    }
    ll operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
    }
};

ll mod_pow(ll x, ll n, const ll mod){
    ll ans = 1;
    while(n){
        if(n & 1) ans = ans*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return ans;
}

ll mod_mul(ll a, ll b, const ll mod){
    return (a%mod * b%mod)%mod;
}
ll mod_add(ll a, ll b, const ll mod){
    return ((a%mod) + (b%mod))%mod;
}

int main(){
    const ll mod = 998244353;
    int n, m, k; cin >> n >> m >> k;

    ll def = m * mod_pow(m-1, n-1, mod);

    Comb comb = Comb(n, mod);

    ll ans = 0;
    ll col = m;
    rrep(i, n-1){
        ll now = col;
        now = mod_mul(now, comb(n-1, i), mod);
        if(i <= k) ans = mod_add(ans, now, mod);
        col = mod_mul(col, m-1, mod);
    }
    cout << ans%mod << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
const ll MOD = 998244353;

int main() {
  string s;
  int k;
  cin >> s >> k;
  int one = 0, tot = 0;
  vector<int> cups;
  for (char c : s) {
    tot += c == '1';
    if (c == '0') {
      cups.emplace_back(one);
      one = 0;
    } else
      one++;
  }
  cups.emplace_back(one);
  int n = cups.size();
  k = min(k, tot);
  vector<vector<ll>> dp(tot + 1, vector<ll>(k + 1, -1));
  for (int i = 0; i <= k; ++i)
    dp[0][i] = 1;
  int acc = 0;
  for (int i = n - 1; i >= 0; --i) {
    acc += cups[i];
    vector<vector<ll>> ndp(tot + 1, vector<ll>(k + 1, -1));
    for (int j = 0; j <= acc; ++j) {
      if (j < cups[i]) {
        int delta = cups[i] - j;
        for (int p = 0; p + delta <= k; ++p) {
          for (int q = p; q + delta <= k; ++q) {
            if (dp[p][q] == -1)
              continue;
            if (ndp[p + delta][q + delta] == -1)
              ndp[p + delta][q + delta] = 0;
            ndp[p + delta][q + delta] += dp[p][q];
            ndp[p + delta][q + delta] %= MOD;
          }
        }
      } else {
        int delta = j - cups[i];
        for (int p = delta; p <= k; ++p) {
          for (int q = p; q <= k; ++q) {
            if (dp[p][q] == -1)
              continue;
            if (ndp[p - delta][q] == -1)
              ndp[p - delta][q] = 0;
            ndp[p - delta][q] += dp[p][q];
            ndp[p - delta][q] %= MOD;
          }
        }
      }
    }
    swap(dp, ndp);
  }
  cout << dp[0][k];
}

Measured memory_bytes: 4412
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                boolean ok = false;
                String stringN = String.valueOf(N);
                
                for(int i= 0; i< 3; i++){
                        if('7' == stringN.charAt(i)){
                        ok = true;
                        }
                }

                if(ok){
                        System.out.println("Yes");
                } else {
                        System.out.println("No");

                }
        }
}

        
        

Measured memory_bytes: 35744
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]

for i in range(n):
    for sum_w in range(w + 1):
        if sum_w - wv[i][0] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i]
                                 [sum_w - wv[i][0]] + wv[i][1])
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
print(dp[n][w])


Measured memory_bytes: 173832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=32e4;

char s[N];

int main(){
	ios::sync_with_stdio(0);
	cin>>s;
	int l=strlen(s);
	int ans=0,c=0;
	for(int i=0;i<l;i++){
		if(s[i]=='S')c++;
		else c--;
		if(c<0)ans++,c=0;
	}
	cout<<ans+c<<'\n';
	return 0;
}

Measured memory_bytes: 512
# ABC 053
s = input()
#print(s,len(s))#
for i in range(len(s)):
    if s[i]=='A': break
start = i
#print(start)#
for i in range(len(s)-1,0, -1):
    #print(i)#
    if s[i]=='Z': break
end = i
#print(end)#
print(end-start+1)

Measured memory_bytes: 3516
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

struct Node{
    int key;
    Node *right,*left,*parent;
};

Node *root,*NIL;



void insert(int k){
    Node *y=NIL;
    Node *x=root;
    Node *z;
    z=(Node *)malloc(sizeof(Node));
    
    z->key=k;
    z->left=NIL;
    z->right=NIL;
    
    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }
    
    z->parent=y;
    
    if(y==NIL){
        root=z;
    }else{
        if(z->key<y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
    
}

void inorder(Node *u){
    if(u==NIL){
        return;
    }
    inorder(u->left);
    cout<<" "<<u->key;
    inorder(u->right);
}

void preorder(Node *u){
    if(u==NIL){
        return;
    }
    cout<<" "<<u->key;
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n,x;
    string com;
    
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>com;
        if(com=="insert"){
            cin>>x;
            insert(x);
        }else if(com=="print"){
            inorder(root);
            cout<<endl;
            preorder(root);
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 26492
max, m = gets.split(" ").map(&:to_i)
min=1
m.times do
  l, r = gets.split(" ").map(&:to_i)
  min = l if min < l
  max = r if max > r
  if max < min
    max = min - 1
    break
  end
end

puts max - min + 1


Measured memory_bytes: 1788
import math

n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        ans = 0
        for k in range(d):
            ans += (x[i][k] - x[j][k])**2
        if math.sqrt(ans).is_integer():
            count += 1

print(count)


Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back

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

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const ll mod = 1e9 + 7;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//



int cnt_digits(ll n){
        int digits = 0;

        while(n > 0){
                n /= 10;
                digits++;
        }

        return digits;
}

int main(void){
        ll N;
        cin >> N;

        int ans = cnt_digits(N);

        for(ll A=1LL; A*A <= N; A++){
                if(N%A != 0) continue;
                const ll B = N/A;

                const int cur = max(cnt_digits(A), cnt_digits(B));

                ans = min(ans,cur);
        }

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









Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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 dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll h,w,d;
  cin>>h>>w>>d;
  map<ll,pll> p;
  rep(i,h)rep(j,w){
    ll a;
    cin>>a;
    p[a]=pll(i,j);
  }
  vll dp(h*w+1);
  rep(i,h*w+1){
    if(i==0) continue;
    if(i+d<=h*w){
      dp[i+d]+=dp[i]+abs(p[i].F-p[i+d].F)+abs(p[i].S-p[i+d].S);
    }
  }
  ll q;
  cin>>q;
  rep(i,q){
    ll l,r;
    cin>>l>>r;
    COUT(dp[r]-dp[l]);
  }
}

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

  
int main(){
  int n,m;
  cin >> n >> m;
  VI count(m);
 
  rep(i,n){
    int k;    
    cin >> k;
    rep(j,k){
      int a;
      cin >> a;
      rep(h,m){
        if(h+1==a)count.at(h)++;
    }
  }
  }
 
  int counnt=0;
  rep(i,m){
    if(count.at(i)==n){
      counnt++;
    }
  }
  cout << counnt <<endl;  
  
  
 
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
m, d = readInts()
cnt = 0
for i in range(1,m+1):
    for j in range(20,d+1):
        #print(j)
        if int(str(j)[0]) >= 2 and int(str(j)[1]) >= 2 and (int(str(j)[0]) * int(str(j)[1])) == i:
            #print(i,j)
            cnt += 1
print(cnt)


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

int main() {
  int n, k;
  int ans = 0;
  cin >> n >> k;
  vector<int> l(n);
  
  for(int i = 0; i < n; i++){
    cin >> l.at(i);
  }
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  for(int i = 0; i < k; i++){
    ans += l.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
a=[]
for i in range(28):
    n=int(input())
    a.append(n)
a.sort()
b=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
c=list(set(b)-set(a))
print(min(c))
print(max(c))


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
 
  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }
  
  int cnt = 1;
  int ans = 0;
  for (int i = 1; i < N; i++) {
    if (a[i] != a[i - 1]) {
    	ans += cnt % 2;
      	cnt = 1;
    } else {
    	cnt++;
   	}
  }
  ans += cnt % 2;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 640
n,m=map(int,input().split())
k=[0]*(n+1)
wa_count=0
ac_count=0
for i in range(m):
    p,s=map(str,input().split())
    if s== "AC":
        if k[int(p)]!=-1:
            wa_count=wa_count+k[int(p)]
            k[int(p)]=-1
            ac_count += 1
    else:
        if k[int(p)]!=-1:
            k[int(p)]+= 1
            
ac=str(ac_count)
wa=str(wa_count)
print(ac+" "+wa)

Measured memory_bytes: 9560
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)  文字列からllに変換　stoll(number)*/
 
 
 int main(){
	 int n; cin >> n;
	 vector<int> a(n,0);
	 rep(i,n){
		int A ;
		cin >> A;
		a[A] ++;//a[A]は絶対値の差がAですと言った人の人数が入っている。
	 }
	 //その報告で人間が並べるかどうかを判定する できるならjudge  1
	 int judge = 1;
	 for(int i = n - 1; i >= 0 ; i-=2 ){
		 if(i != 0){//この時は絶対2じゃないとダメ
			 if(a[i] != 2){
				 judge = 0;
				 break;
			 }
		 }
		 else{//iが0 のときはa[i]は1じゃないといけない
			 if(a[i]!=1){
				 judge = 0;
				 break;
			 }
		 }
	 }
	 ll ans = 1;
	 int r = n/2;
	 if (judge==0) {
		 cout<<0<<endl;
		 //cout<<"koko"<<endl;
	 }
	 else if(judge == 1){ //並びがあるなら何通りあるかを出力
		 ll mod = 1000000007;
		 //cout << mod << endl;
		 rep(i,r){
			ans *= 2;
			ans %= mod;
		 }
		 cout<<ans<<endl;
	 }
 }


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

//read question carefully!

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int a, b, c, k;
        cin >> a >> b >> c >> k;
        if (a < b && b < c)
        {
            cout << "Yes"
                 << "\n";
        }
        else if (a < b && b > c)
        {
            c = k * 2 * c;
            if (c > b)
                cout << "Yes"
                     << "\n";
            else
            {
                cout << "No"
                     << "\n";
            }
        }

        else
        {
            int ct = 0;
            bool f = 0;
            while (a >= b)
            {

                b = 2 * b;
                if (ct == k)
                {
                    f = 1;
                    break;
                }
                ct++;
            }
            if (f)
            {
                cout << "No"
                     << "\n";
            }
            else
            {
                k = k - ct;
                ct = 0;
                while (b >= c)
                {

                    c = 2 * c;
                    if (ct == k)
                    {
                        f = 1;
                        break;
                    }
                    ct++;
                }
                if (f)
                {
                    cout << "No"
                         << "\n";
                }
                else
                {
                    cout << "Yes"
                         << "\n";
                }
            }
        }
    }
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long x = scanner.nextLong();

        long[] a = new long[N];

        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextLong();
        }

        long eaten = 0;

        for (int i = 0; i < N - 1; i++) {
            long a_left = a[i];
            long a_right = a[i + 1];
            if (a_left + a_right <= x) {
                // ok
            } else {
                // 食べないといけない
                long diff = (a_left + a_right) - x;
                if (diff > a_right) {
                    long leftEat = diff - a_right;
                    a[i] = a[i] - leftEat;
                    a[i + 1] = 0;
                } else {
                    a[i + 1] = a[i + 1] - diff;
                }
                eaten += diff;
            }
        }

        System.out.print(eaten);
    }
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A[3];
	rep(i, 0, 3)
	{
		cin >> A[i];
	}

	sort(A, A + 3);

	int d1 = A[2] - A[0];
	int d2 = A[2] - A[1];

	if ((d1 + d2) % 2 == 0)
	{
		cout << (d1 + d2) / 2 << endl;
	}
	else
	{
		cout << 1 + (d1 + d2 + 1) / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
# yahoo-procon2019-qualC - When I hit my pocket...
def main():
    k, a, b = list(map(int, input().rstrip().split()))
    if b - a <= 2 or k < a - 1:
        print(k + 1)
        return

    ans, k = a, k - (a - 1)
    if k % 2 == 1:
        k -= 1
        ans += 1
    ans += (b - a) * k // 2
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    bool f = false;
    if (a == b && a != c) f = true;
    if (b == c && b != a) f = true;
    if (c == a && c != b) f = true;
    cout << (f ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int s1=0;
    for(int i=0;i<s.length();i++)
    {
        s1=s1+int(s[i])-48;
    }
    if(s1%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
using vs= vector<string>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n,ans=0,amin;
  cin >> n;
  vi a(n);
  rep(i,0,n)cin >> a[i];

  amin=INT_MAX;
  rep(i,0,n){
    if(amin>a[i]){
      ans++;
      amin=a[i];
    }
  }

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


Measured memory_bytes: 1024
n, m = gets.chomp.split(' ').map(&:to_i)
x = []
y = []
z = []
n.times do |i|
  x[i], y[i], z[i] = gets.chomp.split(' ').map(&:to_i)
end

w = 0
[
  [+1, +1, +1],
  [+1, +1, -1],
  [+1, -1, +1],
  [+1, -1, -1],
  [-1, +1, +1],
  [-1, +1, -1],
  [-1, -1, +1],
  [-1, -1, -1]
].each do |v|
  a = []
  
  n.times do |i|
    s = x[i] * v[0] + y[i] * v[1] + z[i] * v[2]
    a.push([i, s])
  end
  
  w = [w, a.sort{|p, q| p[1] <=> q[1]}[(n-m)..n].reduce(0){|p, q| p + q[1]}].max
end

puts w.to_s

Measured memory_bytes: 2168
program main
      implicit none
      integer(16) :: n, k, cnt, roop, i, cnt2, waru
      integer, allocatable :: a(:)
      integer :: str, next, str2, str3
      logical, allocatable :: used(:)

      read *, n, k
      allocate( a(n) )
      read *, a

      allocate( used(n) )
      used = .false.
      cnt = 0
      str = 1
      do
        if ( used(str) ) exit
        used(str) = .true.
        next = a(str)
        str = next
        cnt = cnt + 1
      end do

      str2 = 1
      cnt2 = 1
      do
        next = a(str2)
        str2 = next
        if ( next == str ) exit
        cnt2 = cnt2 + 1
      end do

      if ( (cnt+cnt2) >= k ) then
        str3 = 1
        do i = 1, k
          next = a(str3)
          str3 = next
        end do
        print *, next
      else

        waru = cnt-cnt2
        if ( waru == 0 ) then
          waru = cnt
        end if
  
        roop = mod( k-cnt,waru )
  
        do i = 1, roop
          next = a(str)
          str = next
        end do
        print *, next
      end if

end program main



Measured memory_bytes: 4532
#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 n,k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	ll h=1ll;
	rep(i,k) h *= a[i];
	rep(i,n-k) {
		if (a[i] < a[k+i])
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
  return 0;
}


Measured memory_bytes: 4028
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i) 
const long long INF = 10e9 + 7;
typedef long long ll;
using namespace std;
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; }
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	/
	/
	/
	*/
	ll n;
	cin >> n;
	map<ll, ll>a;
	ll temp = 0;
	ll ans = 0;
	rep0(i, n) {
		cin >> temp;
		a[temp]++;
	}
	for (auto& j : a) {
		if (j.second % 2 != 0) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
		int[] nums = new int[5];
		for (int i = 0; i < 5; i++) {
			nums[i] = Integer.parseInt(tokenizer.nextToken());
		}
		Arrays.sort(nums);
		for (int i = 4; i >= 0; i--) {
			if (i != 4) {
				builder.append(' ');
			}
			builder.append(nums[i]);
		}
		System.out.println(builder);
	}
}

Measured memory_bytes: 17024
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;

struct DAG {
private:
    struct Edge {
        int to;
    };
    std::vector<std::vector<Edge>> graph;
    bool is_dag = false;
    std::vector<int> sorted; // トポロジカルソート
    int V; // 頂点数
public:

    DAG(int v) {
        assert(v > 0);
        V = v;
        graph.resize(v);
    }

    // from から to への有向辺を張る
    void add_edge(int from, int to) {
        graph[from].push_back({to});
    }

    // トポロジカルソート O(V + E)
    // DAG じゃないなら size 0 の vectorを返す
    std::vector<int> topological_sort() {
        std::stack<int> sta;
        //std::vector<int> dist(V, 0);//その頂点までの最長路
        std::vector<int> in(V, 0);// 入次数
        int used_cnt = 0;//使用した頂点の数
        for (int i = 0; i < V; i++) {
            for (Edge e : graph[i]) {
                in[e.to]++;
            }
        }
        for (int i = 0; i < V; i++) if (in[i] == 0) {
            sta.push(i);
            used_cnt++;
        }
        while (!sta.empty()) {
            int p = sta.top(); sta.pop();
            sorted.push_back(p);
            for (Edge e : graph[p]) {
                int v = e.to;
                in[v]--;
                //dist[v] = std::max(dist[v], dist[p] + 1);
                if (in[v] == 0) {
                    sta.push(v);
                    used_cnt++;
                }
            }
        }
        if (used_cnt == V) {
            return sorted;
        }
        else {
            return std::vector<int>(0);
        }
    }

    vector<Edge>& operator[](int x) {
        return graph[x];
    }
};

int main() {
    int n, m; scanf("%d %d", &n, &m);
    m += n - 1;
    DAG dag(n);
    vector<vector<int>> g(n);
    REP(i, m) {
        int a, b; scanf("%d %d", &a, &b);
        a--; b--;
        dag.add_edge(a, b);
        g[b].push_back(a);
    }
    auto vec = dag.topological_sort();
    vector<int> rvec(n); // 頂点iは何番目
    REP(i, n) rvec[vec[i]] = i;
    vector<int> ans(n);
    REP(i, vec.size()) {
        int par = -1;
        REP(j, g[vec[i]].size()) {
            par = max(par, rvec[g[vec[i]][j]]);
        }
        ans[vec[i]] = par < 0 ? -1 : vec[par];
    }
    REP(i, n) {
        printf("%d\n", ans[i] + 1);
    }
    return 0;
}

Measured memory_bytes: 13300
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 200100;
int a[maxn], f[maxn];

ll check(int n, ll t) {
    ll ret = 0;
    for (int i=1;i<=n;i++) {
        ret += max(0ll, a[i]-t/f[n-i+1]);
    }
    return ret;
}


int main(void) {
    int n; ll k; scanf("%d%lld",&n,&k);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    for (int i=1;i<=n;i++) scanf("%d",&f[i]);
    sort(a+1,a+n+1);
    sort(f+1,f+n+1);
    ll l=0, r=1e12, ans=r;
    while (l <= r) {
        ll mid=(l+r)/2;
        if (check(n,mid) <= k) {
            ans=min(ans, mid), r=mid-1;
        } else l=mid+1;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <cmath>
typedef long long LL;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  LL dp[100005][13]={};
  string S;
  cin>>S;
  LL s_len = S.length();
  reverse(S.begin(),S.end());
  
  dp[0][0] = 1;
  LL mul = 1;
  LL mod = 1000000007;
  for(int i=0;i<s_len;i++){
    int digit=-1;
    if(S[i]=='?'){
      digit=-1;
    }else{
      digit=S[i]-'0';
    }
    
    if(digit==-1){
      for(int j=0;j<10;j++){
        for(int k=0;k<13;k++){
          dp[i+1][(j*mul+k)%13]+=dp[i][k];
          dp[i+1][(j*mul+k)%13]%=mod;
        }
      }
    }else{
      for(int k=0;k<13;k++){
        dp[i+1][(digit*mul+k)%13]+=dp[i][k];
        dp[i+1][(digit*mul+k)%13]%=mod;
      }
    }
    mul*=10;
    mul%=13;
  }

  cout << dp[s_len][5];
  
  return 0;
}

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

using namespace std;

int main ()
{
	int N, K = 3, i, j, g;
	scanf ("%d", &N);
	int h[N][K], dd[N][K];
	for (i = 0; i < N; i++)
	{
		for (j = 0; j < K; j++)
		{
			scanf ("%d", &(h[i][j]));
			//printf ("%d ", h[i][j]);
		}
		//printf ("\n");
	}
	memset (dd, -1, sizeof (dd[0][0])*N*K);
	for (j = 0; j < K; j++)
	{
		dd[0][j] = h[0][j];
	}
	for (i = 1; i < N; i++)
	{
		for (j = 0; j < K; j++)
		{
			for (g = 0; g < K; g++)
			{
				if (j == g) continue;
				dd[i][j] = max (dd[i][j], dd[i - 1][g] + h[i][j]);
			}
		}
	}
	int M = -1;
	for (j = 0; j < K; j++)
		M = max (M, dd[N - 1][j]);
	printf ("%d\n", M);
	return 0;
}


Measured memory_bytes: 2560
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    let n: i64 = read();
    let x: i64 = read();

    let mut a: Vec<i64> = vec![];
    for _ in 0..n {
        a.push(read());
    }

    let mut tmp = (a[0] - x).abs();
    for i in 0..a.len() {
        let b = (a[i] - x).abs();
        tmp = gcd(tmp, b);
    }
    println!("{}", tmp);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define min3(a, b, c) min(a, min(b, c))

int INF = 1e18;
int mod = 1e9 + 7;

void solve()
{
    int a, b, c, d;cin>>a>>b>>c>>d;
    cout<<max(max(a*c, b*d), max(a*d, b*c))<<endl;
}

signed main()
{

 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


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

typedef long long ll;

const ll mod = 1e9 + 7;
int n, k, fp;
vector<int> e;

vector<int> D(int z) {
	if(z == 1) return e;
	vector<int> l, r;
	if(z & 1) {
		l = D(z - 1);
		r = D(1);
	} else {
		l = r = D(z / 2);
	}
	vector<int> v;
	v.resize(k + 1, 0);
	for(int i = k; i >= 1; --i) {
		ll lj = 0, rj = 0;
		for(int j = i; j <= k; j += i) {
			lj += l[j];
			rj += r[j];
			v[i] -= v[j];
			if(v[i] < 0) v[i] += mod;
		}
		(v[i] += (lj % mod) * (rj % mod) % mod) %= mod;
	}
	return v;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	e.resize(k + 1, 1);
	vector<int> v = D(n);
	for(int i = 1; i <= k; ++i) {
		(fp += ((long long)i * v[i]) % mod) %= mod;
	}
	cout << fp << endl;
	return 0;
}


Measured memory_bytes: 4740
N = int(input())
txy = [[0, 0, 0]]
for i in range(N):
  txy.append(list(map(int, input().split())))

for i in range(N):
  dt = txy[i+1][0] - txy[i][0]
  dx = txy[i+1][1] - txy[i][1]
  dy = txy[i+1][2] - txy[i][2]
  
  if dt < abs(dx + dy):
    print('No')
    break
  else:
    if (dt - (dx + dy)) % 2 != 0:
      print('No')
      break
else:
  print('Yes')

Measured memory_bytes: 27024
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<" ----------------------------------- "<<endl
#define LL long long
#define DB double
#define LDB long double
#define ULL unsigned long long
using namespace std;
namespace IO{
	const int BS=(1<<23)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout),OS=OT;}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush();}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	inline LL read(){
		LL nm=0; bool fh=true; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) fh^=(cw=='-');
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return fh?nm:-nm;
	}
} using namespace IO;
#define mod 998244353
namespace  CALC{
	inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
	inline int mns(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
	inline int mul(int x,int y){return (LL)x*(LL)y%mod;}
	inline void upd(int &x,int y){x+=y;(x>=mod)?(x-=mod):0;}
	inline void dec(int &x,int y){x-=y;(x<0)?(x+=mod):0;}
	inline int qpow(int x,int sq){int res=1;for(;sq;sq>>=1,x=mul(x,x))if(sq&1)res=mul(res,x);return res;}
}using namespace CALC;
#define M 510
int n,t[M],ans=-1,dis[M],hd,tl,q[M];
char ch[M][M];
inline int solve(int x,int res=0){
	memset(dis,-1,sizeof(dis)),dis[x]=1; hd=tl=0,q[tl++]=x;
	for(x=q[hd];hd<tl;x=q[++hd]){
		for(int y=1;y<=n;y++) if(ch[x][y]=='1'){
			if(dis[y]==-1) dis[y]=dis[x]+1,q[tl++]=y;
			else if(dis[y]!=dis[x]-1&&dis[y]!=dis[x]+1) return -1;
		}
	}
	for(int i=1;i<=n;i++) res=max(res,dis[i]); return res;
}
int main(){
	ans=-1,n=read();
	for(int i=1;i<=n;i++) scanf("%s",ch[i]+1);
	for(int i=1;i<=n;i++) ans=max(ans,solve(i));
	printf("%d\n",ans); return 0;
}

Measured memory_bytes: 384
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }

  getChildrenNumber() {return Number(this.left !== null) + Number(this.right !== null);}

  isLeftChild() {
    if (this.parent === null) return null;
    return this.parent.left === this;
  }

  getLeftOrRight() {return this.isLeftChild() ? 'left' : 'right';}

  getSuccessor() {
    let n;
    if (this.right !== null) {
      n = this.right;
      while (n.left !== null) n = n.left;
    } else {
      n = this.parent;
      while (!n.isLeftChild && n.parent != null) n = n.parent;
    }
    return n;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    if (this.root === null) {
      this.root = new BinaryTree.Node(key);
      return;
    }
    let x = this.root, y;
    let newNode = new BinaryTree.Node(key);
    while (x !== null) {
      y = x;
      x = x[key < x.key ? 'left' : 'right'];
    }
    newNode.parent = y;
    y[key < y.key ? 'left' : 'right'] = newNode;
  }

  find(key, n = this.root) {
    if (n === null || n.key === key) return n;
    return this.find(key, n[key < n.key ? 'left' : 'right']);
  }

  delete(key) {
    const n = this.find(key);
    const leftOrRight = n.getLeftOrRight();
    switch (n.getChildrenNumber()) {
    case 0:
      n.parent[leftOrRight] = null;
      break;
    case 1:
      n.parent[leftOrRight] = n.left || n.right;
      n.parent[leftOrRight].parent = n.parent;
      break;
    default:
      const skey = n.getSuccessor().key;
      this.delete(skey);
      n.key = skey;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    console.log(innerFunc(this.root) || str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    console.log(innerFunc(this.root) || str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch (cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    case 'f': console.log(tree.find(Number(cmd.split(' ')[1])) ? 'yes' : 'no'); break;
    case 'd': tree.delete(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



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

int main() {
	for( ;; ) {
		int n;
		cin >> n;

		if( n == 0 ) { break; }

		vector<int> a( n );
		for( auto& v: a ) { cin >> v; }

		int result = 1000000;

		for( int i = 0; i < n; ++i ) {
			for( int j = i+1; j < n; ++j ) {
				result = min( result, abs( a.at(i) - a.at(j) ) );
			}
		}

		cout << result << endl;
	}
}



Measured memory_bytes: 3036
N,H=map(int,input().split())

a=[0]*N
b=[0]*N
for i in range(N):
  a[i],b[i]=map(int,input().split())

amax=max(a)
n=0
total=0
b.sort(reverse=True)
for i in range(N):
  if b[i] > amax:
    n+=1
    total+=b[i]
  else:
    break

if H <= total:
  for i in range(n):
    H-=b[i]
    if H <= 0:
      print(i+1)
      break
else:
  print(n+int((H-total-1)/amax)+1)

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);
	cout.tie(nullptr);
	char c;
	cin>>c;
	if(isupper(c))cout<<"A"<<endl;
	else cout<<"a"<<endl;
	return 0;
}


Measured memory_bytes: 3556
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		while ((s = stdIn.readLine()) != null) {
			int cnt = Integer.valueOf(s);
			Domi aUniv = new Domi();
			aUniv.init();
			for (int i = 0; i < cnt; i++) {
				aUniv.moving(stdIn.readLine());
			}
			aUniv.printAll();
		}
		System.exit(0);
	}
}

class Domi {
	private int bc = 4;
	private int fc = 3;
	private int rc = 10;
	private int[][][] psn = new int[bc][fc][rc];

	public void init() {
		for (int b = 0; b < bc; b++)
			for (int f = 0; f < fc; f++)
				for (int r = 0; r < rc; r++)
					psn[b][f][r] = 0;

	}

	public void printAll() {
		for (int b = 0; b < bc; b++) {
			if (b > 0)
				System.out.println("####################");
			for (int f = 0; f < fc; f++) {
				for (int r = 0; r < rc; r++)
					System.out.print(" " + psn[b][f][r]);
				System.out.println("");
			}
		}
	}

	public void moving(String log) {
		String[] logs = log.split(" ");
		int b = Integer.valueOf(logs[0]);
		int f = Integer.valueOf(logs[1]);
		int r = Integer.valueOf(logs[2]);
		int v = Integer.valueOf(logs[3]);
		psn[b - 1][f - 1][r - 1] += v;
	}

}

Measured memory_bytes: 24620
#include <bits/stdc++.h>
using namespace std;
int x, a, b, c, cnt;
int main(){
    scanf("%d%d%d%d", &a, &b, &c, &x);
    for(int i=0; i<=a; i++)
        for(int j=0; j<=b; j++)
            for(int k=0; k<=c; k++)
                if (500*i + 100*j + 50*k == x)
                    cnt++;

    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

using int64 = long long;

class Combination {
 public:
  constexpr Combination() { Build(); }
  static constexpr int mod_ = 1000000007;
  static constexpr int n_ = 800000;
  class LookupTable {
   public:
    int64 factorial_[n_];
    int64 inverse_[n_];
    int64 finverse_[n_];
  };
  LookupTable lt{};
  // return nCk
  constexpr int64 Get(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return lt.factorial_[n] * (lt.finverse_[k] * lt.finverse_[n - k] % mod_) %
           mod_;
  }

 private:
  constexpr void Build() noexcept {
    lt.factorial_[0] = 1;
    lt.factorial_[1] = 1;
    lt.finverse_[0] = 1;
    lt.finverse_[1] = 1;
    lt.inverse_[1] = 1;
    for (int i = 2; i < n_; ++i) {
      lt.factorial_[i] = lt.factorial_[i - 1] * i % mod_;
      lt.inverse_[i] = mod_ - lt.inverse_[mod_ % i] * (mod_ / i) % mod_;
      lt.finverse_[i] = lt.finverse_[i - 1] * lt.inverse_[i] % mod_;
    }
  }
};

template<typename T> void fastin(T &num) {
  T c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

Combination com;

int main() {
 int x, y; fastin(x); fastin(y);
  auto ok = [](int xx, int yy) -> bool {
    if (xx * 2 < yy || xx > yy * 2) return false;
    return (xx + yy) % 3 == 0;
  };
 
  if (!ok(x, y)) {
    printf("%d\n", 0);
    return 0;
  }
 
  int nn = (x + y) / 3;
  int r = x - nn;
 
  int64 ans = com.Get(nn, r);
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 



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

i64 N, M; cin >> N >> M;
vector<VP> G(N+1); // 入力の記録。
VVI d(N+1, VI(N+1, INF));  //隣接行列。最短経路記録。無向グラフで記録。
rep(i, 0, N+1) d[i][i] = 0;
rep(_, 0, M){
    int a, b, c; cin >> a >> b >> c;
    G[a].emplace_back(b, c);
    d[a][b] = d[b][a] = c;
}
// warshall-floyd
rep(k, 1, N+1) rep(i, 1, N+1) if (d[i][k] < INF) 
    rep(j, 1, N+1) if (d[k][j] < INF)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

int cnt = 0;
rep(i, 1, N+1) for(PII p: G[i]){
    if (d[i][p.first] < p.second) ++cnt;
}
cout << cnt <<  "\n";

return 0;
}
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int main() {
ll n,c,k;
cin>>n>>c>>k;
ll t[n]={};
ll bas=0;
ll a=0;
ll b=0;
for(ll i=0; i<n; i++){
cin>>t[i];}
sort(t,t+n);
for(ll i=0; i<n; i++){
ll r=t[i]+k;
bas++;
a=i;
while(t[a]<=r&&b<c){
b++;
a++;
if(a==n)break;}
i=a-1;
b=0;}
cout<<bas<<endl;}

Measured memory_bytes: 4356
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}

int main(void){
    int A,B,C,D; cin >> A >> B >> C >> D;
    int ans = min(B,D) - max(A,C);
    cout << max(ans,0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	ll N, A[5];
	cin >> N;
	ll ans = 1e17;
	for (int i = 0; i < 5; ++i) {
		cin >> A[i];
		if (ans > A[i]) {
			ans = A[i];
		}
	}
	if (N%ans == 0) {
		cout << 4 + N / ans << endl;
	}
	else {
		cout << 5 + N / ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from itertools import chain
n = int(input())
a = [input().split() + [i+1] for i in range(n)]
d = defaultdict(list)
for k,v,i in a:
    d[k].append((int(v), i))


sk = sorted(d.keys())
sd = [sorted(d[ski], reverse=True) for ski in sk]
[print(i) for v,i in chain.from_iterable(sd)]

Measured memory_bytes: 3316
#include<cstdio>
#define LL long long
#define N 100010
LL n,m,a[N],b[N];
signed main()
{
	scanf("%lld%lld",&n,&m);LL x(0),y(0),mod(1e9+7);
	for(register int i(1);i<=n;i++)
		scanf("%lld",&a[i]);
	for(register int i(1);i<=m;i++)
		scanf("%lld",&b[i]);
	for(register int i(1),j(n);i<j;i++,j--)
		x=(x+(a[j]-a[i])*(j-i)%mod)%mod;
	for(register int i(1),j(m);i<j;i++,j--)
		y=(y+(b[j]-b[i])*(j-i)%mod)%mod;
	return printf("%lld\n",x*y%mod),0;
}

Measured memory_bytes: 1664
from collections import *

n = int(input())
A = list(map(int, input().split()))
q = int(input())

A_dic = Counter(A)
A_sum = sum(A)

for _ in range(q):
    b, c = map(int, input().split())
    tmp = A_dic[b]
    A_dic[c] += tmp
    A_dic[b] = 0
    A_sum += tmp * (c - b)
    print(A_sum)


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

using namespace std;
#define int long long
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define vin(vec) for(auto &elem:vec)cin>>elem
#define vi vector<int>
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.first<<','<< P.second<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
#define show(x) cout<<#x<<" : "<<x<<'\n';


signed main(){
	fio;
	int t=1;
	// cin>>t;
	while(t--){
		int n, cap;
		cin>>n>>cap;
		vector<int> w(n); 		
		vector<int> v(n);
		for(int i=0; i<n; i++){
			cin>>w[i]>>v[i];
		}
		vector<vector<int>> dp(n+1, vector<int>(cap+1, 0));

		for(int i=n-1; i>=0; i--){
			for(int j=1; j<=cap; j++){
				dp[i][j]=dp[i+1][j];
				if(j-w[i]>=0)
					dp[i][j]=max(dp[i+1][j-w[i]]+v[i], dp[i][j]);
			}
		}
		cout<<dp[0][cap]<<'\n';
	}
}

Measured memory_bytes: 83128