akhauriyash/Code-Regression huggingface dataset:
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

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

int func(int N)
{
        if (N < 10)
                return N;
        return func(N / 10) + N % 10;
}

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

        vector<int> S(N + 1);

        rep(i, N) cin >> S[i];
        sort(S.begin(), S.begin() + N);
        int ans = 0;

        rep(i, N-1)
        {
                if (L >= S[i])
                {
                        L -= S[i];
                        ans++;
                }
        }
        if (L == S[N-1])
        {
                ans++;
        }
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();
        
        for(int i=1; i<=K; i++){
            if(i%2 == 1){
                if(A%2 == 1){
                    A--;
                }
                A = (A/2);
                B += A;
                continue;
            }else{
                if(B%2 == 1){
                    B--;
                }
                B = (B/2);
                A += B;
                continue;
            }
        }
        
        
        System.out.println(A+" "+B);
    }
}



Measured memory_bytes: 38852
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const double PI = 2 * asin(1);

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

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ma=max(a)
ma=ma//2
aaa=max(a)
ans=10**10
for i in range(n):
    if abs(ma-a[i])<ans and a[i]!=aaa:
        ans=abs(ma-a[i])
        aaaaaa=a[i]
print(max(a),aaaaaa)



Measured memory_bytes: 14428
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 998244353;

int main() {
	int n;
	cin >> n;
	vi a(n);
	double ave = 0;
	rep(i, n) {
		cin >> a[i];
		ave += a[i];
	}
	ave /= n;
	int x = ceil(ave);
	int y = floor(ave);
	int ans1 = 0;
	int ans2 = 0;
	rep(i, n) {
		ans1 += (a[i] - x) * (a[i] - x);
		ans2 += (a[i] - y) * (a[i] - y);
	}
	ans1 = min(ans1, ans2);
	cout << ans1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdlib>
#include <climits>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int N, K;
int A[100010];

vector<int> getDiffs(vector<int> ds) {
  set<int> temp;
  for (size_t i = 0; i+1 < ds.size(); i++) {
    auto d = ds[i+1] - ds[i];
    if(d) temp.insert(d);
  }
  vector<int> new_ds;
  int first = *(temp.begin());
  new_ds.push_back(first);
  for (auto &&d:temp) {
    if(d%first) new_ds.push_back(d);
  }
  sort(new_ds.begin(),new_ds.end());
  return new_ds;
}

int main (int argc, char const *argv[])
{
  cin >> N >> K;
  set<int> as;
  for(int i=0;i<N;++i) {
    cin >> A[i];
    as.insert(A[i]);
  }
  int maxA = *as.rbegin();
  sort(A,A+N);
  vector<int> diffs;
  diffs.assign(A,A+N);
  for (size_t i = 0; i < 1000; i++) {
    diffs = getDiffs(diffs);
    if(diffs.size()<2) break;
  }
  if(as.count(K)) {
    cout << "POSSIBLE" << endl;
    return 0;
  } else {
    if(K>maxA) {
      cout << "IMPOSSIBLE" << endl;
      return 0;
    } else {
      for(auto &&d:diffs) {
        if(K%d==0){
          cout << "POSSIBLE" << endl;
          return 0;
        }
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

ll mod(ll x){
    ll res=x%MOD;
    return res+(res<0?MOD:0);
}
ll inv(ll x){
    ll b=MOD,u=1,v=0;
    while(b){
        ll t=x/b;
        x-=t*b;swap(x,b);
        u-=t*v;swap(u,v);
    }
    return mod(u);
}
vector<ll> prods(int x){
    vector<ll> res(x+1);
    res[0]=1;
    for(int i=1; i<=x; i++)res[i]=mod(i*res[i-1]);
    return res;
}
vector<ll> pows(ll a,int x){
    vector<ll> res(x+1);
    res[0]=1;
    a=mod(a);
    for(ll i=1; i<=x; i++)res[i]=mod(a*res[i-1]);
    return res;
}
ll power(ll a, ll n){
    ll res=1;
    a=mod(a);
    for(;n>0;n>>=1){
        if(n&1)res=mod(res*a);
        a=mod(a*a);
    }
    return res;
}

vector<ll> p;//p=prods(MAX_n)
ll comb(ll a, ll b){
    if(b<0||b>a)return 0;
    return mod(mod(p[a]*inv(p[b]))*inv(p[a-b]));
}

//https://www.wolframalpha.com/input/?i=sum%5BC%28x%2By%2Cx%29%2C%7Bx%2Ca%2Cb%7D%2C%7By%2Cc%2Cd%7D%5D&lang=ja

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;
    p=prods(2000002);
    ll ans = comb(r1+c1,r1)-comb(r1+c2+1,r1)-comb(c1+r2+1,r2+1)+comb(r2+c2+2,r2+1);
    cout<<(ans+MOD)%MOD;
    return 0;
}

Measured memory_bytes: 15872
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://beta.atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_d>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
void solve(){
    ll n,m; cin >> n >> m;
    ll s,t; cin >> s >> t; s--; t--;
    vector<vector<pll>> G1(n),G2(n);
    for(int i = 0; i < m;i++){
        ll u,v,a,b; cin >> u >> v >> a >> b;
        u--; v--;
        G1[u].push_back({v,a});
        G2[u].push_back({v,b});
        G1[v].push_back({u,a});
        G2[v].push_back({u,b});
    }
    
    vector<ll> dist1(n,LINF),dist2(n,LINF);
    dist1[s] = 0; dist2[t] = 0;
    queue<ll> q;
    
    q.push(s);
    while(q.size()){
        ll n = q.front(); q.pop();
        for(auto e:G1[n]){
            ll next = e.first,cost = e.second;
            if(dist1[next] > dist1[n] + cost){
                dist1[next] = dist1[n] + cost;
                q.push(next);
            }
        }
    }
    q.push(t);
    while(q.size()){
        ll n = q.front(); q.pop();
        for(auto e:G2[n]){
            ll next = e.first,cost = e.second;
            if(dist2[next] > dist2[n] + cost){
                dist2[next] = dist2[n] + cost;
                q.push(next);
            }
        }
    }
    vector<ll> ans(n,1e15);
    ll minV = LINF;
    for(ll i = n-1;i>=0;i--){
        minV = min(minV,dist1[i]+dist2[i]);
        ans[i] -= minV;
    }
    for(int i = 0; i < n;i++){
        cout << ans[i] << endl;
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 20864
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int N, A, B, C;
int inf = 99999999;
int L[8];
int dfs(int v, int a, int b, int c)
{
    if (v == N)
    {
        if (a > 0 && b > 0 && c > 0)
        {
            return abs(a - A) + abs(b - B) + abs(c - C)-30;
        }
        else
        {
            return inf;
        }
    }
    int ret0 = dfs(v + 1, a, b, c);
    int retA = dfs(v + 1, a + L[v], b, c)+10;
    int retB = dfs(v + 1, a, b + L[v], c)+10;
    int retC = dfs(v + 1, a, b, c + L[v])+10;
    return min({ret0, retA, retB, retC});
}
int main()
{
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }

    cout << dfs(0, 0, 0, 0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    string fes = "FESTIVAL";
    string s; cin >> s;
    cout << s.substr(0, s.size() - fes.size()) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

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

  for(int i=1; i<=n; i++) {
    if(to_string(i).length() %2 != 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 888
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define pb(x)                       push_back(x)
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 1e18;
ll n, w;
ll wei[110],v[110];
ll dp[110][MAXN];


int main()
{
    fast_io;
    cin >> n >> w;
    for (int i = 1; i <= n;i++){
        cin >> wei[i] >> v[i];
    }
    for (int i = 0; i <= n;i++){
        for (int j = 1; j < MAXN;j++){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for (int i = 1; i <= n;i++){
        //cout << i << endl;
        for (int j = MAXN - 1;j >= 0;j--){
            if (j < v[i]){
                dp[i][j] = dp[i - 1][j];
            }
            else{
                dp[i][j] = min(dp[i-1][j - v[i]] + wei[i],dp[i - 1][j]);
            }
        }
    }
    ll ans = 0;

    for (int i = 0; i < MAXN;i++){
        if (dp[n][i] != INF and dp[n][i] <= w){
            ans = i;
        }
    }
    cout << ans << endl;
}


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


int main()
{
int A,B;
cin >> A >> B;
string s;
cin >> s;

bool ok = true;

rep(i,A+B+1) {
    if(i != A) {
        if(s[i] == '-') ok = false;
    }
    if(i == A) {
        if(s[i] != '-') ok = false;
    }
}

if(ok) cout << "Yes" << endl;
else cout << "No" << endl;


return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;
int main() {
    int i,j,n,b,c,x,y;
    int flag=0;
    int count10000=0;
    int count5000=0;
    int count1000=0;
    int sum=0;
    int souwa=0;
    int max=0;
    int temp;
    cin>>n>>y;
    for(i=0; i<=n; ++i){
        for(j=0; j<=n; ++j){
            temp=y-10000*i-5000*j;
            if(temp<0){continue;}
            if((10000*i+5000*j+temp==y)&&(i+j+temp/1000==n)){cout<<i<<" "<<j<<" "<<temp/1000;flag=1;break;}
        }
        if(flag==1)break;
    }
    if(flag==0){cout<<-1<<" "<<-1<<" "<<-1;}

    return 0;
}

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

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key)
    {
      return u;
    }
  if(k < u->key)
    {
      return treeSearch(u->left,k);
    }
  else
    {
      return treeSearch(u->right,k);
    }
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

 

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct 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) //tree is empty
    {
      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);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL)
    {
      return ;
    }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20452
import scala.io.StdIn._
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  var a,b,c,d = sc.nextInt
  var sum=0
  if(a<b){
    sum+=a
  }
  else{
    sum+=b 
  }
  if(c<d){
    println(sum+c)
  }
  else{
    println(sum+d)
  }
}

Measured memory_bytes: 27196
use std::io::BufRead;

pub struct StdinReader<R: BufRead> {
    pub buf_reader: R,
    pub buf: String,
}

impl<R: BufRead> StdinReader<R> {
    pub fn new(r: R) -> Self {
        StdinReader {
            buf_reader: r,
            buf: String::with_capacity(10000),
        }
    }
}

#[macro_export]
macro_rules! input {
    ($reader : expr, $t : ty) => { // one variable
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().parse().unwrap();
                reader.buf.clear();
                tmp_var
            },
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty) => { // 2 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone())
            }
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty, $t2 : ty) => { // 3 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone(), tmp_var[2].clone())
            }
        }
    };
    ($reader : expr, $t : ty; $size : expr) => { // Vector
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                tmp_var
            }
        }
    };
}

fn main() {
    let handle = std::io::stdin();
    let mut r = StdinReader::new(handle.lock());
    let (n, m) = input!(r, usize, usize);
    let mut meal_map: Vec<Vec<bool>> = vec![vec![false; n];m];
    for i in 0..n {
        let person = input!(r, Vec<usize>; m);
        person.into_iter().skip(1).map(|a| meal_map[a-1][i] = true).collect::<Vec<_>>();
    }
    println!("{}", meal_map.into_iter().filter(|a| a.iter().all(|a| *a) ).count());
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define INF 2000000000
using namespace std;
int main(){
  int v,n;
  cin>>v>>n;
  long long a[v][v];
  r(i,v)r(j,v)a[i][j]=i==j?0:INF;
  r(i,n){int x,y,w;
    cin>>x>>y>>w;
    a[x][y]=w;
  }
  r(k,v)r(i,v)r(j,v)if(a[i][k]!=INF&&a[k][j]!=INF)a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
  r(i,v)if(a[i][i]<0){cout<<"NEGATIVE CYCLE"<<endl;return 0;}
  r(i,v){r(j,v){
      if(j)cout<<' ';
      if(a[i][j]>=INF) cout<<"INF";
      else cout<<a[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const int N=1e5+10;

inline int read(){
	int ww=1,xx=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') ww=-ww;ch=getchar();}
	while(isdigit(ch)){xx=(xx<<1)+(xx<<3)+(ch^48);ch=getchar();}
	return ww*xx;
}

int n,m,fr,to,cnt;
int de[N],ans;
int q[N],l,r=-1;
int head[N];
int f[N];
vector<int> ed[N];

signed main(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
	n=read();
	m=read();
	for(int i=1;i<=m;i++){
		fr=read();
		to=read();
		de[to]++;
		ed[fr].pb(to);
	}
	r=-1;
	l=0;
//	for(int i=1;i<=n;i++) printf("%d ",de[i]);
	for(int i=1;i<=n;i++) if(de[i]==0) q[++r]=i;
	while(l<=r){
		int u=q[l++];
//		printf("%d ",u);
		for(int i=0;i<ed[u].size();i++) {
			int v=ed[u][i];
			de[v]--;
			if(de[v]==0) q[++r]=v;
		}
	}
//	puts("");
	for(int i=0;i<r;i++){
		int u=q[i];
//		printf("%d ",u);
		for(int j=0;j<ed[u].size();j++)
			f[ed[u][j]]=max(f[ed[u][j]],f[u]+1);
	}
	for(int i=1;i<=n;i++) ans=max(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}
/*
4 5
1 2
1 3
3 2
2 4
3 4
*/

Measured memory_bytes: 6912
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : September 10, 2020 4:47 PM
 *    Problem Name  : A - Remaining Balls
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc154/tasks/abc154_a
 *    @genarated by : ai-virtual-assistant
**/

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

int main(){
    ios_base::sync_with_stdio(false);

    string s,t,u;
    cin >> s >> t;

    int a,b;
    cin >> a >> b >> u;

    if(u == s){
        a--;
        cout << a << " " << b << endl;
    }

    else if(u == t) {
        b--;
        cout << a << " " << b << endl;
    }

    else{
        cout << a << " " << b << endl;
    }
    return 0 ;
}


Measured memory_bytes: 3628
N, M = map(int, input().split())
aList = sorted(list(map(int, input().split())), reverse=True)
bcList = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1], reverse=True)

bcs = []
for bc in bcList:
    bcs.extend([bc[1]] * bc[0])
    if len(bcs) >= N:
        break

aList.extend(bcs)
aList.sort(reverse=True)
ans = sum(aList[:N])
print(ans)


Measured memory_bytes: 35524
#!/usr/bin/env pypy3

#import numpy as np
#import scipy, scipy.special

# Python 3 modules: https://docs.python.org/3/library/

import math, itertools, operator
from math import *
from math import factorial as fact
from itertools import permutations, combinations
from functools import reduce
# Use scipy for stats: https://docs.scipy.org/doc/scipy/reference/stats.html
# Before Python 3.5
from fractions import gcd

inf = float('inf')

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

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(inp = input, sep = ' ', conv = int):
    return map(conv, inp().split(sep = sep))

################################################################################


N, K = input_ints()

P = .0
for n in range(1, N+1):
    i = 0
    c = 0
    while n < K:
        n *= 2
        c += 1
    P += pow(.5, c) / N
print(P)


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


int main() {
    
    int n, d, pos, nr;
    cin >> n >> d;
    pos = d + 1;
    nr = 1;
    while(pos + d < n) {
        nr++;
        pos += 2 * d + 1;
    }
    cout << nr;
    return 0;
}

Measured memory_bytes: 3556
<?php
$line = fgets(STDIN);
list($K, $X) = explode(' ', $line);

$min = $X - ($K - 1);
$max = $X + ($K - 1);
for ($i = $min; $i <= $max; $i++) {
    echo $i;
    if ($i < $max) {
        echo " ";
    }
}

Measured memory_bytes: 3828
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)
int H,A[MAX+1];


void maxHeapify(int i){
  int l,r,largest;
  l = 2*i;
  r = 2*i+1;

  if(l<=H && A[l] > A[i]) largest=l;
  else largest = i;
  if(r<=H && A[r] > A[largest]) largest=r;

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


int extract(){
  int maxv;
  if(H<1) return -INFTY;

  maxv=A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return maxv;
}


void increaseKey(int i,int key){
  if(key<A[i]) return;

  A[i] = key;
  while(i>1 && A[i/2]<A[i]){
    swap(A[i],A[i/2]);
    i=i/2;
  }
}

void insert(int key){
  H++;
  A[H] = -INFTY;
  increaseKey(H,key);
}


int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s",com);
    if(com[0] == 'e' && com[1] == 'n') break;
    if(com[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }else{
      printf("%d\n",extract());
    }
  }
  return 0;
}



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

int main(){
    int a=0;
    string s;
    cin>>s;

    for(int i=0;i<=2;i++){
        if(s.at(i)==s.at(i+1))a=1;
    }
    if(a==1)cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    int N;
    cin >> N;
    vector<vector<pair<int,bool>>> v(N);
    int ans=0;
    REP(i,N) {
        int n;
        cin >> n;
        REP(j,n) {
            int x,y;
            cin >> x >> y;
            auto p = make_pair(x,(bool)y);
            v[i].push_back(p);
        }
    }

    int end = 1 << N;

    for (int i=1; i<end ; ++i) {
        vector<bool> members(N,false);
        int shift=0;
        int memCount = 0;
        while (shift<=N){
            if ((1 << shift)&i) {
                // cout << shift << "i:" << i << endl;
                members[shift]=true;
                memCount++;
            }
            shift++;
        }
        bool is_mujyun = false;
        REP(j,N) {
            if (members[j]) {
                for(const auto &p:v[j]) {
                    // 矛盾ならフラグを立てる。
                    if (members[p.first-1]!=p.second) {
                        // cout << "member: " << j << "の発言: " << p.first <<"は"<< p.second <<"に矛盾" << endl;
                        is_mujyun=true;
                        break;
                    }
                }
            }
            if (is_mujyun) break;
        }
        if (!is_mujyun) chmax(ans,memCount);

    }

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


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main (){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	   
    int y,m,d;
	char c,e;
	cin >> y >> c >> m >> e >> d;

	if(m>4){
		cout << "TBD" << endl;
	}
	else cout << "Heisei" << endl;
}

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

using namespace std;

struct Range
{
	int l,r,sz;
	Range(){}
}R[300001];

bool operator < (const Range &a, const Range &b)
{
	return a.sz < b.sz;
}

int n,m;
int ans[100011];
int Tree[100011];

void update(int x,int val)
{
	for(;x<=100010;x+=x&(-x))
		Tree[x] += val;
}

int query(int x)
{
	int ans = 0;
	for(;x>0;x-=x&(-x))
		ans += Tree[x];
	return ans;	
}

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

	cin >> n >> m;
	for (int i=1;i<=n;i++)
	{
		cin >> R[i].l >> R[i].r;
		R[i].sz = (R[i].r - R[i].l + 1);
	}	
	sort(R+1,R+1+n);
	int pos = 1;
	for (int i=1;i<=m;i++)
	{
		while(pos <= n && R[pos].sz < i)
		{
			update(R[pos].l,1);
			update(R[pos].r+1,-1);
			pos++;
		}
		ans[i] = (n - pos + 1);
		for (int j=i;j<=m;j+=i)
			ans[i] += query(j);
	}	
	for (int i=1;i<=m;i++)
		cout << ans[i] << '\n';
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=3e5+10,inf=1e9+10,mod=1e9+7;
int a,n,b;
int ans[M];
vector<int>gp;
main()
{
	int n,a,b;
	cin>>n>>a>>b;
	if(n<a+b-1)return cout<<-1,0;
	if(a*b<n)return cout<<-1,0;
	for(int i=1;i<=n;i++)ans[i]=i;
	int cnt=0;
	for(int i=1;i<=n;i+=b)
	{
		gp.clear();
		cnt++;
		gp.pb(i);
		bool flag=0;
		for(int j=i+1;j<min(i+b,n+1);j++)
		{
			//int res=i+j-i;
			if(n-j==a-cnt){
				gp.pb(j);
				flag=1;
				break;
			}
			gp.pb(j);
		}
		reverse(gp.begin(),gp.end());
		for(int j=0;j<gp.size();j++)ans[i+j]=gp[j];
		if(flag)break;
	}
	for(int i=1;i<=n;i++)cout<<ans[i]<<" ";
}

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

int n, A;
int a[51];
long long ways[51][11000];

int main() {
	scanf("%d %d", &n, &A);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]); 
		a[i] -= A;
	}
	ways[0][5000] = 1;
	for (int i = 0; i < n; i++){
		for (int w = -2500; w <= 2500; w++) {
			ways[i + 1][w + 5000] += ways[i][w + 5000];
			ways[i + 1][w + 5000] += ways[i][w + 5000 - a[i]];
		}
	}
	printf("%lld\n", ways[n][5000] - 1);
}


Measured memory_bytes: 3456
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <math.h>
#include <bitset>
#include <vector>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

typedef long long ll;

const ll INF = 1e18, MOD = 1e9 + 7;
const int INT_MAX = 1e9;

ll n, mx, m;

char c[1000][2000];

ll d[1000][1000];

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

	for (int i = 0; i < n; i++)
		scanf ("%s", c[i]);

	if (c[0][0] == '.')
		d[0][0] = 1;

	for (int i = 1; i < m; i++)
		if (c[0][i] == '.')
			d[0][i] = d[0][i-1];

	for (int i = 1; i < n; i++)
		if (c[i][0] == '.')
			d[i][0] = d[i-1][0];

	for (int i = 1; i < n; i++)
		for (int j = 1; j < m; j++)
			if (c[i][j] == '.')
				d[i][j] = (d[i-1][j] + d[i][j-1]) % MOD;

	cout << d[n-1][m-1];
}

Measured memory_bytes: 9984
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define  inf 0x3fffffff 
int main()
{
	int i, n,x,a[110000];
	long long sum;
	while (~scanf("%d%d", &n, &x))
	{
		sum = 0;
		for (i = 1; i <= n; i++)
			scanf("%d", &a[i]);
		if (a[1] > x)
		{
			sum += a[1] - x;
			a[1] = x;
		}
		for (i = 2; i <= n; i++)
		{
			int flag = a[i] + a[i - 1] - x;
			if (flag > 0)
			{
				sum += flag;
				a[i] -= flag;
			}
		}
		printf("%lld\n",sum);
	}
	return 0;
}

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

#define int long long 
#define f(i,n) for(int i=1;i<=n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int N = 403;
const int inf = 1e15;

int dp[N][N];
int a[N];
int n;

int calc(int i,int j)
{
    if(i == j) return 0;
    
    if(dp[i][j] != -1) return dp[i][j];
    
    assert(i < j);
    
    dp[i][j] = inf;
    
    for(int k=i;k<j;k++) dp[i][j] = min(dp[i][j], calc(i,k) + calc(k+1,j) + a[j] - a[i-1]);
    
    return dp[i][j];
}

void solve()
{
    memset(dp,-1,sizeof(dp));
    
    cin >> n;
    
    f(i,n) cin >> a[i];
    
    f(i,n-1) a[i+1]+=a[i];
    
    cout << calc(1,n);
}

signed main()
{
    fast;
    solve();
}

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

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

#define fr first
#define sc second
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)

int main(){
	static ll n,m;
	cin>>n>>m;
	
	static ll dp[6005][2005][2]={};
	dp[1][0][0]=1;
	for(int i=1;i<=3*n;i++){
		for(int j=0;j<=n;j++){
			dp[i+1][j][0]+=dp[i][j][0]+dp[i][j][1];
			dp[i+1][j+1][1]+=dp[i][j][0]*i;
			dp[i+2][j+1][1]+=dp[i][j][0]*(i+1)*i;
			dp[i+1][j][0]%=m;
			dp[i+1][j+1][1]%=m;
			dp[i+2][j+1][1]%=m;
		}
	}
	
	/*for(int i=1;i<=3*n;i++){
		for(int j=0;j<=n;j++){
			cout<<"dp["<<i<<"]["<<j<<"][0]="<<dp[i][j][0]<<endl;
			cout<<"dp["<<i<<"]["<<j<<"][1]="<<dp[i][j][1]<<endl;
		}
	}*/
	
	ll ret=0;
	for(int i=0;i<=n;i++)ret+=dp[3*n][i][0]+dp[3*n][i][1];
	cout<<ret%m<<endl;
}

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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int a;
  cin>>a;
  int sum=a+pow(a,2)+pow(a,3);
  cout<<sum<<"\n";
}

Measured memory_bytes: 4028
n = int(input())
lst = [int(input()) for _ in range(n)]
lst.sort()
center = n // 2
if n % 2:
  higher = lst[center + 1:]
  lower = lst[:center]
  ans = (sum(higher) - sum(lower)) * 2 - higher[0] + lower[-1] + max(lst[center] - lower[-1], higher[0] - lst[center])
else:
  higher = lst[center:]
  lower = lst[:center]
  ans = (sum(higher) - sum(lower)) * 2 - higher[0] + lower[-1]

print(ans)


Measured memory_bytes: 52952
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> hisSnaks(n);
    int tmp;
    int totalSnacks = 0;
    for(int i = 0; i < hisSnaks.size();i++){
        hisSnaks[i] = 0;
    }
    while (totalSnacks < k)
    {
        cin >> tmp;
        totalSnacks++;
        for(int i = 0; i< tmp; i++){
            int ttmp;
            cin >> ttmp;
            hisSnaks[ttmp-1]++;
        }
    }
    int result = 0;
    for(int i = 0; i < hisSnaks.size();i++){
        if(hisSnaks[i]==0){
            result++;
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 3564
N,H = map(int, input().split())
L = [[int(x) for x in input().split()] for _ in range(N)]

from operator import itemgetter

L.sort(reverse=True)
Amax = L[0]
L.sort(reverse=True, key=itemgetter(1))

i = 0
while i < N and Amax[0] < L[i][1] and H > 0:
    H -= L[i][1]
    i += 1
if H <= 0:
    ans = i
else:
    ans = i + H//Amax[0]
    if H%Amax[0] != 0:
        ans += 1
    
print(ans)

Measured memory_bytes: 23020
#include<iostream>
using namespace std;
main(){
	int n;
	cin>>n;
	int data[6];
	for(int i=0;i<6;i++)
		data[i]=0;
	double h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
		h[i]-=160;
	}

	for(int i=0;i<n;i++){
		data[(int)(h[i]/5)]++;
	}

	for(int i=0;i<6;i++){
		cout<<i+1<<":";
		for(int j=0;j<data[i];j++)
			cout<<"*";
		cout<<endl;
	}
}

Measured memory_bytes: 1232
#include <iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a<=b&&b<=c)
    cout << a  <<' '<< b<<' '<< c <<'\n';
  else if(a<=c&&c<=b)
    cout << a<< ' '<<c<<' '<< b <<'\n';
  else if(b<=a&&a<=c)
    cout << b<< ' '<<a<< ' '<<c <<'\n';
  else if(b<=c&&c<=a)
    cout << b<< ' '<<c<< ' '<<a <<'\n';
  else if(c<=a&&a<=b)
    cout << c<< ' '<<a<< ' '<<b <<'\n';
  else if(c<=b&&b<=a)
    cout << c << ' '<<b << ' '<<a <<'\n';
  
  return 0;
}

Measured memory_bytes: 2956
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	private Set<String> set = new HashSet<String>();
	public static void main(String[] args) {
		int N,M;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		int a[][] = new int[N][N];
		for (int i=0;i<M;i++) {
			int x,y;
			x= sc.nextInt();
			y= sc.nextInt();
			a[x-1][y-1]=1;
			a[y-1][x-1]=1;
		}
		Main main = new Main();
		boolean status[] = new boolean[N];
		int b[] = new int[N];
		for (int i=0;i<N;i++) {
			status[i] = false;
		}
		for (int i=0;i<N;i++) {
			main.countPattern(a,1,status,b,i,N);
		}
		System.out.println(main.set.size());
	}
	public void countPattern(int a[][],int number,boolean[] status,int b[],int nowPoint,int N) {
		status[nowPoint]=true;
		b[number-1] =nowPoint;
		boolean temp[];
		if (number==N) {
			String s=new String();
			for (int i=N-1;i>=0;i--) {
				s+=b[i];
			}
			if (set.contains(s)) {
				return ;
			}
			s=new String();
			for (int i=0;i<N;i++) {
				s+=b[i];
			}
			set.add(s);
			return ;
		}
		number+=1;
		for (int i=0;i<N;i++) {
			temp = Arrays.copyOf(status, status.length);
			int c[] = Arrays.copyOf(b, b.length);
			if (a[nowPoint][i]==1&&temp[i]==false) {
				temp[i] =true;
				c[number-1]=i;
				countPattern(a,number,temp,c,i,N);
			}
		}
	}
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
const bool multiple_queries = false;
#define rep(i, n) for(ll i = 0; i < (n) ; ++i)
#define For(i, a, b) for(ll i = (a); i < (b) ; ++i)
#define revrep(i, n) for(ll i = (n) - 1; i >= 0 ; --i)
#define revFor(i, b, a) for(ll i = (b) - 1; i >= (a) ; --i)
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(i) __builtin_popcountl((i))
#define substring(s, start, end) s.substr((start), (end) - (start) + 1)

struct BinaryIndexedTree{
  ll n, ini, M; vl dat;
  BinaryIndexedTree(ll n, ll ini = 0):
    dat(n + 1, ini), n(n), ini(ini){M = 1; while (M <= n) M <<= 1;};

  //       x: 1001 1010  1100 1011 1101  1111
  // x & - x: 0001 0010  0100 0001 0001  0001
  //      ->: 1010 1100 10000 1100 1100 10000

  ll update_func(ll val, ll d){
    // if maximum -> max(val, dat)
    // return max(val, d);
    // if cumulative sum
    return val + d;
  }

  ll query(ll i){
    /*
    v[0] + v[1] + ... + v[i]
    e.g.) i = 10101
    itr1. 10101 -> 10100
    itr2. 10100 -> 10000
    itr3. 10000 -> 00000 (break)
    */

    if (i < 0) return ini;
    ll ret = 0;
    for (ll j = i; j >= 0; j = (j & (j + 1)) - 1){
      ret = update_func(ret, dat[j]);
    }
    return ret;
}

  ll query(ll l, ll r){
    // a[l] + a[l + 1] + ... + a[r - 1] + a[r]
    return query(r) - query(l - 1);
  }

  ll lower_bound(ll key){
    //v[0] + v[1] + ... + v[left - 1] < key <= v[0] + v[1] + ... + v[left]
    if (key <= 0) return 0;
    ll left = 0, right = 1;
    while(right <= n) right <<= 2;

    for (ll i = right; i > 0; i /= 2){
      if (left + i <= n && dat[left + i - 1] < key){
        key -= dat[left + i - 1];
        left += i;
      }
    }
    return left;
  }

  void update(ll i, ll val){
    /*
    e.g.) i = 10101, n = 11111
    itr1. i: 10101, i+1: 10110 -> 10111
    itr2. i: 10111, i+1: 11000 -> 11111 (break)
    */
    if (i < 0) return;
    for(ll j = i; j < n; j |= j + 1){
      dat[j] = update_func(val, dat[j]);
    }
  }
};

template<typename T>
void read_vector(ll n, vector<T>& v, ll offset = 0){
  v.resize(n);
  rep(i, n){
    cin >> v[i];
    if (offset) v[i] += offset;
  }
}

void solve(){
  ll n, Q;
  cin >> n >> Q;
  vl as;
  read_vector(n, as);
  BinaryIndexedTree bit(n);
  rep(i, n) bit.update(i, as[i]);
  rep(i, Q){
    ll mode; cin >> mode;
    if (mode){
      ll l, r; cin >> l >> r;
      cout << bit.query(l, r - 1) << endl;
    }else{
      ll p, x; cin >> p >> x;
      bit.update(p, x);
    }
  }
}

void test(ll num = 0, bool verbose = false){
  rep(i, max(1LL, num)){
    ll t = clock();
    if (verbose) cout << "\n#####" << " " << i + 1 << " " << "#####" << " " << "\n## Answer ##\n";
    solve();
    if (verbose) {cout << "\nElapsed Time:" << " " << 1000.0 * (clock() - t) / CLOCKS_PER_SEC << " " << "[ms]" << endl;}
  }
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  #ifdef _LOCAL
    test(6, true);
  #else
    ll t = 0;
    if (multiple_queries) cin >> t;
    test(t, false);
  #endif
  return 0;
}

Measured memory_bytes: 12152
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var nl = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var n = nl[0]; var l = nl[1];
        var tl = new List<int>();
        for (var i = 1; n >= i; i++)
        {
            var t = l + i - 1;
            tl.Add(t);
        }
        var atl = tl.OrderBy(x => Math.Abs(x)).ToList();
        var s = atl[0];
        tl.Remove(s);
        Console.WriteLine(tl.Sum());

    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.rbegin(), a.rend())
using namespace std;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll> A(a), B(b), C(c);
    loop(a) cin>>A[i];
    loop(b) cin>>B[i];
    loop(c) cin>>C[i];

    sort(A), sort(B), sort(C);
    priority_queue<ll, vector<ll>, greater<ll>> p;

    loop(x) p.push(A[i]);
    loop(y) p.push(B[i]);
    loop(c){
        if(p.top()<C[i]){
            p.pop();
            p.push(C[i]);
        }
    }

    ll ans = 0;
    while(!p.empty()) ans += p.top(), p.pop();
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4852
N = int(input())
schedules = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N - 1):
    sc, ss, sf = schedules[i]
    time = ss + sc
    for j in range(i + 1, N - 1):
        c, s, f = schedules[j]
        if time < s:
            time = s + c
        else:
            time = -(-time // f) * f + c
    print(time)
print(0)

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

long long power(long long x,long long n,long long m){
  long long res=1;
  if(n>0){
    res = power(x,n/2,m);
    if(n%2==0) res=(res*res)%m;
    else res=(((res*res)%m)*x)%m;
  }
  return res;
}
  
int main() {
  long long n,a,b,ans=0,minus=0;
  long long MOD = 1000000007;
  cin >> n >> a >> b;
  
  long long ocom[200000+1],com[200000+1],ucom[200000+1];
  ocom[0]=1,ocom[1]=n,com[1]=1,ucom[0]=1,ucom[1]=1;
  
  for(long long i=2;i<=200000;i++){
    ocom[i]=ocom[i-1]*(n-i+1);
    ocom[i]%=MOD;
    com[i] = MOD-com[MOD%i]*(MOD/i)%MOD;
    ucom[i] = ucom[i-1]*com[i]%MOD;
  }
  
  
  minus=((ocom[a]*ucom[a])%MOD+(ocom[b]*ucom[b])%MOD+1)%MOD;
  
  ans=power(2,n,MOD);
  ans=((ans+MOD)-minus)%MOD;

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


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> r,g,b;
		string s;
		cin>>s;
		for(int i=0;i<n;i++){
			if(s[i]=='R')
			r.push_back(i);
			else if(s[i]=='G')
			g.push_back(i);
			else
			b.push_back(i);
		}
		ll cnt=r.size();
		cnt*=g.size();
		cnt*=b.size();
		for(int i=0;i<r.size();i++){
			for(int j=0;j<g.size();j++){
				if((r[i]+g[j])%2!=0)
				continue;
				if(binary_search(b.begin(),b.end(),(r[i]+g[j])/2))
				cnt--;
			}
		}
		
		for(int i=0;i<g.size();i++){
			for(int j=0;j<b.size();j++){
				if((g[i]+b[j])%2!=0)
				continue;
				if(binary_search(r.begin(),r.end(),(g[i]+b[j])/2))
				cnt--;
			}
		}
		
		for(int i=0;i<r.size();i++){
			for(int j=0;j<b.size();j++){
				if((r[i]+b[j])%2!=0)
				continue;
				if(binary_search(g.begin(),g.end(),(r[i]+b[j])/2))
				cnt--;
			}
		}
		cout<<cnt;
	}
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public long getTotalHeightOfStools(int n, int[] arr) {
        long total = 0;
        int prevHeight = arr[0];
        for (int i = 1; i < n; i++) {
            if (prevHeight > arr[i]) {
                total += prevHeight - arr[i];
                arr[i] = prevHeight;
            }

            prevHeight = arr[i];
        }
        return total;
    }

    public static void main(String[] args) throws Exception {
        Main solution = new Main();

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        long answer = solution.getTotalHeightOfStools(n, arr);
        System.out.println(answer);
    }
}

Measured memory_bytes: 61316
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

LL N;
LL P;
LL ans = 1;

LL mypow(LL base, LL exp) {
  if (exp == 0) return 1;
  LL res = mypow(base*base, exp/2);
  if (exp%2) res *= base;
  return res;
}

int main() {
  scanf("%lld%lld", &N, &P);
  while (P > 1) {
    bool found = false;
    for (LL d=2; d*d <= P; d++) {
      if (P%d == 0) {
        found = true;
        int cnt = 0;
        while (P%d == 0) {
          cnt++;
          P /= d;
        }
        ans *= mypow(d, cnt/N);
        break;
      }
    }

    if (!found) {
      ans *= mypow(P, (1/N));
      break;
    }
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 256
n, a, b = map(int, raw_input().split())
mod = 10**9 + 7
ans = pow(2, n, mod) - 1
anum = 1
for i in range(n, n - a, -1):
	anum = (anum*i)%mod
aden = 1
for i in range(1, a + 1):
	aden = (aden*i)%mod
aden = pow(aden, mod - 2, mod)
anum *= aden
anum %= mod
ans -= anum
ans %= mod

if a != b:
	anum = 1
	for i in range(n, n - b, -1):
		anum = (anum*i)%mod
	aden = 1
	for i in range(1, b + 1):
		aden = (aden*i)%mod
	aden = pow(aden, mod - 2, mod)
	anum *= aden
	anum %= mod
	ans -= anum
	ans %= mod

print ans

Measured memory_bytes: 9348
#include <cstdio>

int main(){
    int c1,c2,c3;
    while(scanf("%d%d%d",&c1,&c2,&c3)!=-1){
        int ok=0;
        for(int i=1;i<=10;i++){
            if(i!=c1&&i!=c2&&i!=c3 && c1+c2+i<=20) ok++;
        }
        if(ok>=4) printf("YES\n");
        else printf("NO\n");
    }
}

Measured memory_bytes: 1008