akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc175/tasks/abc175_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll R, C, K;
  cin >> R >> C >> K;

  VVV<ll> dp(R, VVL(C, VL(4)));
  VVL val_mat(R, VL(C));

  rep(i, K) {
    ll r, c, v;
    cin >> r >> c >> v;
    --r, --c;
    val_mat[r][c] = v;
  }

  rep(r, R) rep(c, C) rep(used, 4) rep(dir, 2) {
    ll nr = dir ? r + 1 : r;
    ll nc = dir ? c : c + 1;

    unless(nr < R && nc < C) continue;

    chmax(dp[nr][nc][r != nr ? 0 : used], dp[r][c][used]);

    if (used < 3) {
      chmax(dp[nr][nc][r != nr ? 0 : used + 1], dp[r][c][used] + val_mat[r][c]);
    }
  }

  ll res = 0;
  rep(i, 4)
      chmax(res, dp[R - 1][C - 1][i] + (i < 3 ? val_mat[R - 1][C - 1] : 0));

  cout << res << "\n";
}


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

using namespace std;

string s;

void solve(){
    bool ans=false;
    if(s.length()==2){
        if(s[0]==s[1]){
            cout << 1 << ' ' << 2 << endl;
            ans=true;
        }
        else{
            ans=false;
        }
    }
    else{
        for(int i=0;i<s.length()-3;i++){
            if(s[i]==s[i+1] || s[i+1]==s[i+2] || s[i+2] == s[i]){
                cout << i+1 << ' ' << i+3 << endl;
                ans = true;
                break;
            }
        }
    }
    if(!ans){
        cout << -1 << ' ' << -1 << endl;
    }
}

int main(){
    cin >> s;
    solve();
}

Measured memory_bytes: 512
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>

#define arrayLength(array) (size_t)((sizeof array) / (sizeof array[0]))

int main() {
  int a = 0, b = 0;
  char s[255], *r;

  scanf(" %d %d", &a, &b);
  scanf(" %[^\n]s", &s);

  s[b - 1] += 32;

  printf("%s", s);

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;
 
 
//debug func
template<typename T>
void vecprint(vector<T> v) {
    for(auto x : v) {
        cerr << x << " ";
    }
    cerr << endl;
}
 
template<typename T>
void vecvecprint(vector<vector<T>> v) {
    for(auto x :v) {
        REP(i, x.size()-1) {
            cerr << x[i] << " ";
        }
        cerr << x[x.size()-1] <<endl;
    }
}
 
template<typename T>
void pqprint(priority_queue<T> q) {
    while(!q.empty()) {
        cerr << q.top() << " ";
        q.pop();
    }
    cerr << endl;
}
 
template<typename T>
void qprint(queue<T> q) {
    while(!q.empty()) {
        cerr << q.front() << " ";
        q.pop();
    }
    cerr << endl;
}
 
template<typename T>
void vecqprint(vector<queue<T>> v) {
    for(int i = 0; i < v.size(); i++) {
        qprint(v[i]);
    }
}
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}

inline double get_time_sec(void){
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}

int n;
VLL va, vb;

int main(void) {
    cin >> n;
    va = VLL(n+1, 0);
    vb = VLL(n, 0);
    REP(i, n+1) cin >> va[i];
    REP(i, n) cin >> vb[i];
    
    LL res = 0;
    REP(i, n) {
        LL damage = min(va[i], vb[i]);
        res += damage;
        vb[i] -= damage;
        if(vb[i] > 0) {
            damage = min(va[i+1], vb[i]);
            res += damage;
            va[i+1] -= damage;
        }
    }

    cout << res << endl;
}

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

int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int hour = h2-h1;
    int minute = m2-m1;

    int time = hour*60 + minute - k;

    if(time < 0){
        time = 0;
    }

    cout << time << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>

using namespace std;
typedef long long int ll;

string s;
char c;
int mx=0;
bool r;

int main(){
    cin>>s;
    c=s[0];
    for(int i=1;i<s.size();i++){
        if(c==s[i])mx++;
        else mx=0;
        c=s[i];
        //printf("%d\n",mx);
        
        if(mx>=2)r=true;
        //c=s[i];
    }
    cout<<(r ? "Yes":"No")<<endl;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M = 1000001;
  int i,j,ct;
  int w=0,x;

  vector<int> c(M,0);
  cin >> N;
  for(i=0;i<N;i++){
    cin >> x;
    c[x] = 1;
    w = gcd(w,x);
  }

  if (w>1){
    cout << "not coprime" << endl;
    return 0;
  }
  
  for(i=2;i<M;i++){
    ct = 0;
    for(j=i;j<M;j+=i)
      ct += c[j];
    if (ct>1){
      cout << "setwise coprime" << endl;
      return 0;
    }
  }

  cout << "pairwise coprime" << endl;
  return 0;
}

Measured memory_bytes: 7096
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans ;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
    int a , b , c ;
    cin >> a >> b >> c;
    if(a>b){
        int t = a;
        a = b ;
        b = t ;
    }
    if(c>a && c<b) cout << "Yes";
    else cout << "No";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
   // cin >> q;
    while(q--)
        solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

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

using namespace std;

int main(){
    int a,b,k;
  cin>>a>>b>>k;
  int end,start;
  if(2*k>b-a){
    for(int i=a;i<=b;i++){
      cout<<i<<endl;
    }
  }else{
    for(int i=a;i<a+k;i++){
      cout<<i<<endl;
    }
    for(int i=b-k+1;i<=b;i++){
      cout<<i<<endl;
    }
  }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#define int long long
#define SIZE 21
#define VALUE 50001
const int infty = 99999;
//#define _DEBUG
using namespace std;
int N, M, Cs[SIZE], T[SIZE][VALUE];
int solve(){
    for(int i=0; i<=M; i++){
        for(int n=0; n<=N; n++){
            if(n==0){
                T[i][n] = 0;
            }else if(i==0){
                T[i][n] = infty;
            }else if(n<Cs[i-1]){
                T[i][n] = T[i-1][n]; 
            }else{
                T[i][n] = min(T[i-1][n], T[i][n-Cs[i-1]]+1);
            }
        }
    }
#ifdef _DEBUG
    for(int i=0; i<=M; i++){
        if(i>0)cout << Cs[i-1] << "\t";
        else cout << "i\\n\t";
        for(int n=0; n<=N; n++){
            cout << T[i][n] << "\t";
        }cout << endl;
    }
#endif
    return T[M][N];
}
signed main(){
    while(cin >> N >> M){
        for(int i=0; i<M; i++){
            cin >> Cs[i];
        }
        cout << solve() << endl;
    }
}


Measured memory_bytes: 7200
a1,b1=map(int,input().split())
a2,b2=map(int,input().split())
a3,b3=map(int,input().split())
a4,b4=map(int,input().split())
a5,b5=map(int,input().split())
a6,b6=map(int,input().split())
a7,b7=map(int,input().split())
print(a1-b1)
print(a2-b2)
print(a3-b3)
print(a4-b4)
print(a5-b5)
print(a6-b6)
print(a7-b7)


Measured memory_bytes: 5592
#include <iostream>
#include <vector>

using namespace std;

int N;
int a[201];
int b[201];
int c[201];
int d[201];

int V;
constexpr int MAX_V = 10000;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v){
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(int v){
    used[v] = true;
    for(auto& u : G[v]){
        int w = match[u];
        if(w < 0 || !used[w] && dfs(w)){
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching(){
    int res = 0;
    for(int i = 0; i < V; ++i) match[i] = -1;
    for(int v = 0; v < V; ++v){
        if(match[v] < 0){
            for(int i = 0; i < V; ++i) used[i] = false;
            if(dfs(v)){
                ++res;
            }
        }
    }
    return res;
}

int main(){
    cin >> N;
    V = 2 * N;

    for(int i = 0; i < N; ++i) cin >> a[i] >> b[i];
    for(int i = 0; i < N; ++i) cin >> c[i] >> d[i];

    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            if(a[i] < c[j] && b[i] < d[j]){
                add_edge(i, N + j);
            }
        }
    }

    cout << bipartite_matching() << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
P multi(P x, P y) {
	int a = x.first*(y.second / x.second)+y.first;
	int b = y.second;
	return make_pair(a, b);
}
int main() {
	string s;
	while (cin >> s) {
		if (s == "#")break;
		P now;
		int t = s.length();
		vector<string> v;
		while (t) {
			if (t - 5 >= 0 && s.substr(t - 5, 5) == "north") {
				t -= 5; v.push_back("north");
			}
			else if(s.substr(t-4,4)=="west"){
				t -= 4; v.push_back("west");
			}
		}
		int len = v.size();
		if (v[0] == "north")now = make_pair(0, 1);
		else now = make_pair(90, 1);
		for (int i = 1; i < len; i++) {
			if (v[i] == "north") {
				P z = make_pair(-90, (int)pow(2, i));
				while (z.first % 2 == 0 && z.second % 2 == 0) {
					z.first /= 2; z.second /= 2;
				}
				now = multi(now, z);
			}
			else {
				P z = make_pair(90, (int)pow(2, i));
				while (z.first % 2 == 0 && z.second % 2 == 0) {
					z.first /= 2; z.second /= 2;
				}
				now = multi(now, z);
			}
		}
		cout << now.first;
		if (now.second != 1) {
			cout << "/" << now.second;
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3320
#include <stdio.h>

int n,a[200200],x;
int main()
{
  scanf ("%d",&n);
  for (int i=0;i<n;i++) scanf ("%d",&a[i]), x ^= a[i];
  for (int i=0;i<n;i++) printf ("%d%c",a[i]^x,i+1<n?' ':'\n');
return 0;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
int main() {
  int n;
  ll ans=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    for(int j=1;i*j<=n;j++){
      ans+=i*j;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        vll nums(3);
        cin >> nums[0] >> nums[1] >> nums[2];
        ll K;
        cin >> K;
        rep(i, 0, K) {
                *max_element(all(nums)) *= 2;
        }
        cout << accumulate(all(nums), 0LL) << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
const int md=998244353;
struct Modint {
  int x;
  Modint() { x=0; }
  Modint operator+=(const Modint& oth) {
    x+=oth.x;
	if (x>=md) x-=md;
	return *this;
  }
} f[302][302][702][4],r;
int n,m,i,j,k1,lst,cur,s0,s1;
char s[302];
int main() {
  scanf("%s",s);  n=strlen(s);
  scanf("%d",&m); m=min(m,n);
  f[0][0][0][0].x=1;
  for (i=0; i<n; i++) {
    cur=s[i]-'0';
	for (j=0; j<=m; j++) for (k1=0; k1<=i+j; k1++) for (lst=0; lst<4; lst++) if (f[i][j][k1][lst].x) {
	  if (cur==0) {
	    f[i+1][j][k1][0]+=f[i][j][k1][lst];
		if (lst<2) f[i][j+1][k1+1][1]+=f[i][j][k1][lst];
	  } else {
	    f[i+1][j][k1][(lst/2)*2+1]+=f[i][j][k1][lst];
		if (k1>0 && lst%2==0) f[i+1][j][k1-1][2]+=f[i][j][k1][lst];
	  }
    }
  }
  for (j=0; j<=m; j++) for (lst=0; lst<4; lst++) r+=f[n][j][0][lst];
  printf("%d\n",r.x);
  return 0;
}


Measured memory_bytes: 1004128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;

int main (){
    int a,b,c;
    cin >> a >> b >> c;
    int maxi = max(max(a,b),c);
  	int maxu = 3 * maxi - a - b - c;
    if(maxu % 2 == 0){
        cout << maxu / 2 << endl;
    }else cout << (maxu + 3) / 2 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code

def resolve():
    N,M,P=pin()
    edge=[]#0-index
    for i in range(M):
        a,b,c=pin()
        edge.append((a-1,b-1,P-c))
    #print(edge)
    
    #Bellman–Ford algorithm?
    inf = float("inf")
    ans=[inf]*N#0-index
    ans[0]=0

    for i in range(N*2):
        for j in range(M):
            t,f,p=edge[j]
            ans[f]=min(ans[f],ans[t]+p)
            if  ans[f]>ans[t]+p:
                ans[f]=0-inf
    #    print(ans)
        if i==N:
            temp=ans[-1]
        if i==N*2-1:
            if ans[-1]<temp:
                ans[-1]=0-inf
    t=(0-ans[-1])
    



    if t==inf:s=-1
    elif t<0:s=0
    else:s=t
    print(s)
#%%submit!
resolve()

Measured memory_bytes: 45276
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int x;
	cin >> x;
	puts(x >= 30 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,a,x;
    cin>>n;
    x=n/2;
    x--;
    vector < int > v,t;
    set < int > st;
    while(n--)
    {
        cin>>a;
        v.push_back(a);
        t.push_back(a);
    }
    sort(v.rbegin(),v.rend());
    int ans=v[x];
    for(auto i : t)
    {
        if(i>=ans)
            cout<<v[x+1]<<endl;
        else
            cout<<v[x]<<endl;
    }
}


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

#define inf 1e18

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define tc ll t;cin >> t;while(t--)

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin >> n >> k;
	vector <ll> h(n);
	for0(i,n){
		cin >> h[i];
	}	
	vector <ll> ans(n,inf);
	ans[0] = 0;
	// ans[1] = abs(h[0]- h[1]);
	forc(i,1,n-1){
		for1(j,k){
			if(i-j >= 0){
				ans[i] = min(abs(h[i]-h[i-j]) + ans[i-j],ans[i]);
			}
		}
	}
	cout << ans[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1792
#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;
    int c = 0, d = 1;
    cin >> a >> b;
    while(d < b){
        d += a-1;
        c++;
    }
    cout << c << endl;
    return 0;
}

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

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;
const double PI = acos(-1);

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

lli gcd(lli a , lli b) {
    if(b == 0) return a;
    a %= b;
    return gcd(b,a);
}

int n, k, r, s, p;
int dp[MAXN][3];
string t;


int convert (char x) {
    if (x == 'r') return 0;
    if (x == 'p') return 1;
    if (x == 's') return 2;

    return -1;
}


int score (int player, int machine) {
    if (player == convert('r') and machine == convert('s')) return r;
    if (player == convert('s')  and machine == convert('p')) return s;
    if (player == convert('p') and machine == convert('r')) return p;

    return 0;
}

void solve() {

    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    lli ans = 0;

    for (int i = 0; i < n; i++) {
        int machine = convert (t[i]);

        if (i < k) {
            for (int j = 0; j < 3; j++) {
                dp[i][j] = max (dp[i][j], score(j, machine));
            }
        } else {
            for (int j = 0; j < 3; j++) {
                for (int l = 0; l < 3; l++) {
                    if (j == l) continue;

                    dp[i][j] = max(dp[i][j], dp[i - k][l] + score(j, machine));
                }
            }
        }

        if (i + k >=  n) ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
    }

    cout << ans << endl;
}

int main()
{
    IOS;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++) {
        //cout << "Case " << i << ": ";
        solve();
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){
  
  int k;
  cin >> k;
  ll dp[20][10];
  REP(i,10)dp[0][i] = 1;
  ll sum = 9;
  int digit = 0,gggg;
  bool flag = false;
  if(k < 10)flag = true;
  for(int i = 1;i < 20;i++){
    if(flag)break;
    dp[i][0] = dp[i-1][1] + dp[i-1][0];
    for(int j = 1;j < 10;j++){
      
      if(j != 9)dp[i][j] = dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1];
      else if(j == 9) dp[i][j] = dp[i-1][j] + dp[i-1][j-1];
      sum += dp[i][j];
      if(sum >= k){
        gggg = j;
        digit = i;
        sum -= dp[i][j];
        flag = true;
        break;
      }

    }
    
  }
  string res = "";
  res += (char)(gggg+'0');
  if(digit == 0){
    res = to_string(k);
  }else{
    
    for(int i = digit-1;i >= 0;i--){

      if(gggg != 0){
        for(int j = gggg-1;j <= gggg+1;j++){
          sum += dp[i][j];
          if(sum >= k){
            sum -= dp[i][j];
            res += (char)(j+'0');
            gggg = j;
            break;
          }
        }
      }else{
        for(int j = 0;j <= 1;j++){
          sum += dp[i][j];
          if(sum >= k){
            sum -= dp[i][j];
            res += (char)(j+'0');
            gggg = j;
            break;
          }
        }
      }
    }

    

  }
  cout << res << endl;







  return 0;
}

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

using namespace std;
int main(){
    string s;
    int k, a;
    cin>>s>>k;
    set<string> S;
    a=s.size();
    for (int i=1; i<=min(a, 5); i++)
    {
        for (int j=0; j<=a-i; j++)
        {
            S.insert(s.substr(j, i));
        }
    }
    auto u=S.begin();
    for (int i=0; i<k-1; i++) u++;
    cout<<*u<<'\n';
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		//Sccaner???????????????????????????????????????
		//System.in??§??\????????±?????????
		Scanner sc = new Scanner(System.in);
		int intA = sc.nextInt();

		//??????????¨?????????????????????????
		double dbAncer = Math.pow(intA, 3);
		int intAncer = (int)dbAncer;
		System.out.println(intAncer);
	}
}

Measured memory_bytes: 26076
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int> input;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		input.push_back(tmp);
	}

	int count = 0;
	for (int i = 1; i < n - 1; i++) {
		if (input[i - 1] < input[i] && input[i] < input[i + 1]) {
			count++;
		}
		else if (input[i - 1] > input[i] && input[i] > input[i + 1]) {
			count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input().strip())
a = list(map(int, input().split()))
s = [a[0]]
for i in range(0, (n - 1)):
    s.append(s[i] + a[i + 1])
mi = float('inf')
su = sum(a)
for i in range(n - 1):
    rep = abs(su - 2 * s[i])
    if rep < mi:
        mi = rep
print(mi)


Measured memory_bytes: 86992
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int shi[100005];
int main(){
    int a;
    while(~scanf("%d",&a)){
        int pan=0;
        for(int i=0;i<a;i++)scanf("%d",&shi[i]);
        sort(shi,shi+a);
        if(shi[0]>=a){
                if((shi[0]-a+1)%2==1)printf("Second\n");
                else printf("First\n");
                continue;
        }
        int ru=1;int s=a;s-=shi[0];
        while(shi[ru]-shi[ru-1]+1<s){
            s-=(shi[ru]-shi[ru-1]+1);
            if(shi[ru]==shi[ru-1]){
                if(pan==0)pan=1;else pan=0;
            }
            else pan=0;
            ru++;
        }
        int k=shi[ru]-shi[ru-1];
        if(k%2==1&&pan==1)pan=0;
        if(s==1){
            if(pan==0)printf("First\n");
            else printf("Second\n");
        }
        else{
            int l=shi[ru]-shi[ru-1]+1-s+1;
            if(l%2==1)printf("Second\n");
            else printf("First\n");
        }
    }
}
/*
1
0
6
5 5 5 4 4 3
6
5 4 4 4 4 3
6
3 4 3 1 2 0
*/



Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

last_value = -1
satisfied_points = 0

for i, v in enumerate(A):
  s = B[v - 1]
  satisfied_points += s
  if (last_value == (v - 1)):
    ss = C[last_value - 1]
    satisfied_points += ss
  last_value = v
  
print(satisfied_points)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
typedef pair<ll, ll> LP;

ll max(ll a, ll b){
	if (a>b) return a;
	else return b;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> h(n);
	REP(i, n){cin >> h[i];}
	ll ans = 1;
	if (n==1){cout << ans << endl; return 0;}
	ll m = h[0];
	FOR(i, 1, n){
		if (h[i]>=m){
			ans++;
			m = h[i];
		}
	}
	cout << ans << endl;
}

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

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

int main() {
		SINT32 ANS = 0;

	SINT32 N = 0;
	SINT32 K = 0;
	SINT32 count = 0;
	SINT32 han01 = 0;
	SINT32 Fhan01 = 0;
	SINT32 Lhan01 = 0;

	cin >> N;
	cin >> K;

	SINT8 S[1000000];
	for (SINT32 i = 0; i < 1000000; i++) {
		S[i] = 'A';
	}

	cin >> S;

	vector<SINT32> DATA(N);


	if (S[0] == '0') {
		han01 = 0;
		Fhan01 = 0;
	} else {
		han01 = 1;
		Fhan01 = 1;
	}
	if (S[N-1] == '0') {
		Lhan01 = 0;
	} else {
		Lhan01 = 1;
	}
	count = 0;

		
	for (SINT32 i = 0; i < N; i++) {
		if (S[i] == 'A') {
			break;
		}

		if (han01 == 0) {
			if (S[i] == '0') {
			} else {
				han01 = 1;
				count++;
			}
		} else {
			if (S[i] == '0') {
				han01 = 0;
				count++;
			} else {	
			}
		}
		DATA[count] = DATA[count]+1;			
	}

/*	for (SINT32 i = 0; i < count+4; i++) {
		cout << DATA[i] << " ";
 	}
	cout << endl;
	*/

	vector<SINT32> SA(count+5);

	SA[0] = 0;
	SA[1] = 0;
	
	for (SINT32 i = 2; i < count+3; i++) {
		SA[i] = DATA[i-2] + SA[i-1];
 	}
	SA[count+3] = SA[count+2];
	SA[count+4] = SA[count+3];


/*
	for (SINT32 i = 0; i < count+4; i++) {
		cout << SA[i] << " ";
 	}
	cout << endl;
	*/
if (2*K > count) {
	ANS = N;
} else {
	ANS = 0;


if (Fhan01 == 0) {
	for (SINT32 i = 2*K+1; i < count+5; i++) {
		ANS = MAX(ANS, SA[i] - SA[i - (2*K+1)]);
//		cout << SA[i] << " " <<SA[0] <<endl;
		i++;
 	}
} else {
	for (SINT32 i = 2*K; i < count+5; i++) {
		ANS = MAX(ANS, SA[i] - SA[i - (2*K+1)]);
//		cout << SA[i] << " " <<SA[0] <<endl;
		i++;
 	}

}
}



	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


Measured memory_bytes: 2048
#include<iostream>
using namespace ::std;
int main(){
    
    int s;
    cin>>s;
    int array[s],score,max=0,i,j;
  for(i=0;i<s;i++)
  {cin>>array[i];}
    for(i=0;i<s-1;i++){
        j=i;
      //cout<<j<<endl;
        while(array[j]>=array[j+1]&&j<s-1){
            score++;
            //cout<<j;
          	j++;
        }
      //cout<<endl;
      //cout<<score<<endl;
        if(score>max)
        max=score;
      if(max>=s-j)break;
        score=0;
    }

    cout<<max;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	string s;
	int k;
	cin>>k>>s;
	int n=s.length();
	if(n<=k)cout<<s<<endl;
	else
	{
		string ans="";
		for(int i=0;i<k;i++)
			ans+=s[i];
		ans+="...";
		cout<<ans<<endl;
	}

	return 0;
}



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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

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

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

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read();
	vi a(n);
	REP(i,n)a[i]=read();
	sort(ALL(a));
	int ans=0;
	REP(i,n-1){
		int s=min(i+1,n-1-i);
		s*=2;
		ans+=(a[i+1]-a[i])*s;
	}
	if(n%2==1){
		ans-=min(a[n/2]-a[n/2-1],a[n/2+1]-a[n/2]);
	}else{
		ans-=a[n/2]-a[n/2-1];
	}
	print(ans);
}


Measured memory_bytes: 1024
import fractions

A,B,C,D = map(int, input().split())
ans=B-A+1


E=D * C // fractions.gcd(C, D)

if A%C==0:
    nC_initial=A//C
else:
    nC_initial=A//C+1
    
if A%D==0:
    nD_initial=A//D
else:
    nD_initial=A//D+1

    
if A%E==0:
    nE_initial=A//E
else:
    nE_initial=A//E+1
    
nC_final=B//C
nD_final=B//D
nE_final=B//E
if nC_final<nC_initial:
    nC_final=nC_initial
if nD_final<nD_initial:
    nD_final=nD_initial
if nE_final<nE_initial:
    nE_final=nE_initial
nc=(nC_final-nC_initial+1)
nd=(nD_final-nD_initial+1)
ne=(nE_final-nE_initial+1)
if B<C:
    nc=0
    ne=0
if B<D:
    nd=0
    ne=0
if B<E:
    ne=0


#print(ans,nC_initial,nC_final,nD_initial,nD_final, nE_initial,nE_final)
#print(ans,nc,nd,ne)
print(ans-nc-nd+ne)

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

using namespace std;

long long v[1000] , w[1000];
const long long inf = 1e18 + 4;
int main() {
	long long s = 0;
	int n , W; cin>>n>>W;
	for(int i = 0 ; i < n; ++i){
		cin>>w[i]>>v[i];
		s += v[i];
	}
	vector<long long>dp(s + 1 , inf);
	dp[0] = 0;
	for(int i = 0 ; i < n ; ++i){
		for(int vl = s - v[i] ; vl >= 0 ; --vl){
			dp[vl + v[i]] = min(dp[vl + v[i]] , dp[vl] + w[i]);

		}
	}
	long long ans = 0; 
	for(int i = 0 ; i <= s; ++i){
		if(dp[i] <= W)ans = max(ans , (long long)i);
	}
	cout<<ans<<endl;

	
	
  
}

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


int main() {
    int N;

    cin >>N;

    vector<string> jisho(N);

    for(int i=0;i<N;i++){
        cin>>jisho.at(i);
    }

    sort(jisho.begin(), jisho.end());
    
    int sum=1;

    for(int i=1;i<N;i++){
        if(jisho.at(i-1)!=jisho.at(i)){
            sum++;
        }
    }

    cout <<sum<<endl;

}

Measured memory_bytes: 9596
from bisect import bisect_right
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
    for j in range(i):
        m = L[i]-L[j]
        k = bisect_right(L, m)
        n = max(0, j-k)
        ans+=n
print(ans)

Measured memory_bytes: 43692
from bisect import *
import sys
n = int(input())
dic = {}
dic2 = {}
box = []
for i in range(n):
    a, b, *c = sys.stdin.readline().split()
    if a == '0':
        insort_left(box, b)
        dic[b] = int(c[0])
    elif a == '1':
        print(dic[b] if b in dic else 0)
    elif a == '2':
        if b in dic:
            del dic[b]
    else:
        L = bisect_left(box,b)
        R = bisect_right(box, c[0])
        while L<R:
            if box[L] in dic:
                print(box[L], dic[box[L]])
            L = bisect_right(box, box[L])
        
        


Measured memory_bytes: 38788
#include <bits/stdc++.h>
#define rep(i, z, n) for(int64_t i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
//const int MODINF = 1000000007;
//const int64_t INF = 998244353;
using namespace std;
typedef pair<int64_t, int64_t> P;

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    map<string, int> mp;
    set<string> s;
    int count = 1;
    rep(i, 0, N){
        cin >> S.at(i);
        if(mp.count(S.at(i))){
            mp[S.at(i)]++;
            count = max(count, mp[S.at(i)]);
        }
        else{
            mp[S.at(i)] = 1;
        }
    }
    sort(all(S));
    rep(i, 0, N){
        if(mp[S.at(i)] == count && !s.count(S.at(i))){
            cout << S.at(i) << endl;
            s.insert(S.at(i));
        }
    }
}

Measured memory_bytes: 36096
#include<stdio.h>
#include<algorithm>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,m,ro[110000],ex[110000],now,x[110000],y[110000],lasy,t,r[110000],yt,f[110000],ans,g[110000],lx;
const int p=1e9+7;
inline bool cmp1(const int a,const int b){
	return y[a]<y[b];
}
inline bool cmp2(const int a,const int b){
	if (x[a]==x[b]) return y[a]<y[b];//!!!!
	return x[a]<x[b];
}
inline void add(int x,int v){
	while (x<=yt){
		f[x]+=v;
		if (f[x]>=p) f[x]-=p;
		x+=x&(-x);
	}
}
inline int ask(int x){
	int ans=0;
	while (x){
		ans+=f[x];
		if (ans>=p) ans-=p;
		x-=x&(-x);//!!!
	}
	return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,n) scanf("%d",&ro[i]);
	fo(i,1,m) scanf("%d",&ex[i]);
	now=2;
	fo(i,1,n){
		while (ro[i]>ex[now]&&now<m) now++;
		if (ex[now-1]<ro[i]&&ro[i]<ex[now]){
			x[++t]=ro[i]-ex[now-1];
			y[t]=ex[now]-ro[i];
		}
	}
	//fo(i,1,t) printf("%d %d\n",x[i],y[i]);
	fo(i,1,t) r[i]=i;
	sort(r+1,r+t+1,cmp1);
	yt=1;lasy=0;
	fo(i,1,t)
		if (y[r[i]]>lasy){
			lasy=y[r[i]];
			y[r[i]]=++yt;
		}else y[r[i]]=yt;
	sort(r+1,r+t+1,cmp2);
	lx=1;
	add(1,1);//!!!
	ans=1;//!!!
	fo(i,1,t){
		if (x[r[i]]>x[r[lx]]){
			fo(j,lx,i-1) add(y[r[j]],g[j]);//y[r[i]]
			lx=i;
		}
		if (x[r[i]]==x[r[i-1]]&&y[r[i]]==y[r[i-1]]) continue;
		g[i]=ask(y[r[i]]-1);
		ans+=g[i];
		if (ans>=p) ans-=p;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 2688
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define                   pi acos(-1)


int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    ll s=0;
    for(int i=1; i<=n; i++){
        if(i%3!=0 && i%5!=0)
            s+=i;
    }
    cout<<s<<endl;
    End
}
/* pray for me
Do before die
*/


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll N; cin >> N;
  ll A,B; cin >> A >> B;
  ll ans = 0;
  ans += N/(A+B)*A;
  ans += min(N%(A+B),A);
  cout << ans << endl;
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    map<string, int> mp;
    rep(i, N) {
        string s;
        cin >> s;
        mp[s]++;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int S[111111],T[111111];
int P[222222];

int sum[222222];
signed main(){
    cin>>N>>M;
    rep(i,N){
        cin>>S[i]>>T[i];
        if(S[i]>T[i])S[i]*=-1,T[i]*=-1;
    }
    rep(i,M)cin>>P[i],P[i+M]=-P[i];
    M*=2;
    sort(P,P+M);

    for(int i=1;i<M;i++){
        sum[i]=P[i]-P[i-1]+(i>1?sum[i-2]:0);
    }

    int ans=0;
    rep(i,N){
        if(T[i]<P[0]){
            ans+=T[i]-S[i];
            continue;
        }
        if(P[M-1]<S[i]){
            ans+=T[i]-S[i];
            continue;
        }
        int t=upper_bound(P,P+M,T[i])-P-1;
        int s=upper_bound(P,P+M,S[i])-P;
        if(s%2!=t%2){
            ans+=sum[t-1]-sum[s]+T[i]-P[t]+P[s]-S[i];
        }
        else{
            ans+=sum[t]-sum[s]+P[s]-S[i];
        }
    }

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

Measured memory_bytes: 6048
#include<cstdio>
#define ll long long
using namespace std;
ll n, m, k;
int main()
{
	scanf("%lld %lld %lld", &n, &m, &k);
	if (k - m <= 2)
	{
		printf("%lld\n", n + 1);
		return 0;
	}
	else
	{
		ll ch = m - 1;
		if (n <= m - 1)
		{
			printf("%lld\n", n + 1);
			return 0;
		}
		n -= (m - 1);
		ll dap = m;
		dap = dap + (k - m)*(n / 2);
		dap += (n % 2);
		printf("%lld\n", dap);
	}
}


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

class Program
{
    public static void Main()
    {
        string[] K = Console.ReadLine().Split(' ');
        double A = int.Parse(K[0]);
        double B = int.Parse(K[1]);

        double C = A;
        double D = B;
        while (true)
        {
           
            if (C > D)
            {
                C = C % D;
            }
            else if (D > C)
            {
                D = D % C;
            }

            if (C == 1|D==1)
            {

                break;
            }
            else if (C == 0 | D == 0)
            {
                break;
            }
        }
        double ans;
        if (C == 0)
        {
            ans = (A * B) / D;
        }
        else if (D == 0)
        {
            ans = (A * B) / C;
        }
        else
            ans = A * B;
        
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
from operator import itemgetter


n, k = map(int, input().split())

li_a = [i+k for i in range(n)]
li_b = [i+k+n for i in range(n)]
li_c = [i+k+2*n for i in range(n)]
ans = []

for i in range(n):
   ans.append((li_a[n//2-i], li_b[n-1-i], li_a[n//2-i] + li_b[n-1-i]))
ans = sorted(ans, key = itemgetter(2))

res = []
for i in range(n):
    if ans[i][0] + ans[i][1] <= li_c[i]:
        res.append((ans[i][0], ans[i][1], li_c[i]))
    else:
        print(-1)
        break
else:
    for i in res:
        print(*i)

Measured memory_bytes: 76064
#include <stdio.h>
#define N 100000
int partition(int*,int,int);
int main(){

  int i,n,q;
  int A[N];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  q = partition(A,0,i-1);

  for(i=0;i<n;i++){

    if(i==n-1)printf("%d",A[i]);
    else {
      if(i==q)printf("[%d] ",A[i]);
      else printf("%d ",A[i]);
    }
  }
  puts("");

  return 0;

}

int partition(int *A,int p,int r){

  int x,j,temp,i;

  x=A[r];

  i=p-1;

  for(j=p;j<r;j++){

    if(A[j]<=x){
      i++;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }

    temp=A[i+1];
    A[i+1]=A[r];
    A[r]=temp;
  
    return i+1;

}

Measured memory_bytes: 3076
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

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

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  int A, B, C, K;
  cin >> A >> B >> C;
  cin >> K;
  bool judge = false;
  for (int i = 0; i < K; i++) {
    if (B <= A) {
      B = B * 2;
    } else {
      C = C * 2;
    }
  }
  if (B > A && C > B) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

int main()
{
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  
  cout << (H2 - H1) * 60 + (M2 - M1) - K;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
double pi = 2*acos(0.0);
double third_side(double a, double b, double c) 
{ 
    double angle = cos(c); 
    return sqrt((a * a) + (b * b) - 2 * a * b * angle); 
}
int main(){
	int t=1;
	//cin >> t;
	while(t--){
		double a=0,b=0,h=0,m=0;
      	cin >> a >> b >> h >> m;
      	double angle=0,ans=0,hour=0,minu=0;
      	hour = (double)((h*60+m)/720);
      	minu = (double)(m/60);
      	if(hour >= minu){angle = hour -minu;}
      	else{
      		angle = minu - hour;
      	}	
      	//cout << hour <<" "<<minu<<" "<<angle <<endl;
      	angle = angle*pi*2;
      	//angle = pi - angle; 
        //cout << cos(pi/4)<<endl;
      	ans = third_side(a,b,angle);
      	if(ans==0){
      	std::cout << std::fixed;
	    cout<<std::setprecision(20)<<0<<endl;}
      	else{
        std::cout << std::fixed;
	    cout<<std::setprecision(20)<<ans<<endl;
        }
    }
}

Measured memory_bytes: 4172
# -*- coding: utf-8 -*-
N = int(input())
Flowers = list(map(int, input().split(' ')))

Count = 0

while( max(Flowers) > 0 ):
    maxList = [ i for i, x in enumerate(Flowers) if x == max(Flowers) ]

    idx = maxList.pop(0)
    Flowers[idx] -= 1
    Count += 1
    while(len(maxList) > 0):
        next_idx = maxList.pop(0)
        if idx + 1 != next_idx:
            Count += 1
        idx = next_idx
        Flowers[idx] -= 1

print(Count)

Measured memory_bytes: 3064