akhauriyash/Code-Regression huggingface dataset:
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,m,p;
  std::cin>>n>>m>>p;
  
  struct Edge{ll from,to,cost;};

  std::vector<Edge> check(m),es;

  std::vector<bool> flag1(n,false),flag2(n,false);

  std::vector<ll> d(n);

  rep(i,0,m){
    ll a,b,c;
    std::cin>>a>>b>>c;
    a--;b--;
    check[i]=Edge{a,b,p-c};
  } 

  std::queue<ll> point;
  point.push(0);
  flag1[0]=true;

  while(point.size()){
    ll now=point.front();point.pop();
    rep(i,0,m){
      if(check[i].from==now&&!flag1[check[i].to]){
        point.push(check[i].to);
        flag1[check[i].to]=true;
      }
    }
  }

  point.push(n-1);
  flag2[n-1]=true;

  while(point.size()){
    ll now=point.front();point.pop();
    rep(i,0,m){
      if(check[i].to==now&&!flag2[check[i].from]){
        point.push(check[i].from);
        flag2[check[i].from]=true;
      }
    }
  }

  rep(i,0,n){
    flag1[i]=(flag1[i]&flag2[i]);
  }

  rep(i,0,m){
    Edge e=check[i];
    if(flag1[e.from]&&flag1[e.to])es.push_back(e);
  }

  m=es.size();

  rep(i,0,n)d[i]=LLONG_MAX;

  ll ans=0;

  d[0]=0;
  ll count=0;
  ll temp=0;
  while(1){
    count++;
    bool update=false;
    rep(i,0,m){
      Edge e=es[i];
      if(d[e.from]!= LLONG_MAX&&d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
        update=true;
      }
    }

    if(!update){
      break;
    }else if(count>=n){
      ans=-1;
      break;
    }
  }

  if(ans!=-1){
    std::cout<<std::max((ll)0,-d[n-1]);
  }else{
    std::cout<<-1;
  }

  return 0;
}

Measured memory_bytes: 708
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
int n,q,k;
vector<P>g[100005];
ll d[100005];
void dfs(int v,int p,ll w){
    d[v]=w;
    for(int i=0;i<g[v].size();i++){
        if(g[v][i].F!=p)dfs(g[v][i].F,v,w+g[v][i].S);
    }
}
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        int a,b;
        ll c;
        scanf("%d%d%lld",&a,&b,&c);
        g[a].push_back(P(b,c));
        g[b].push_back(P(a,c));
    }
    scanf("%d%d",&q,&k);
    dfs(k,-1,0);
    for(int i=0;i<q;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        printf("%lld\n",d[a]+d[b]);
    }
}

Measured memory_bytes: 15872
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int X;
    if(A>=B){
        X=A;
    }else{
        X=B;
        }
    if(X>=C){

    }else{
        X=C;
    }
    cout << A+B+C-X << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int a[310][310];
int dist[310][310];
bool no_need[310][310];

int main() {
  // 入力
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a[i][j];
    }
  }

  // ワーシャルフロイド法
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dist[i][j] = a[i][j];
    }
  }
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  bool flag = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (a[i][j] != dist[i][j]) flag = false;
    }
  }

  ll ans = -1;
  if (flag) {
    for (int i = 0; i < N; i++) { // 始点
      for (int j = i + 1; j < N; j++) { // 終点
        for (int k = 0; k < N; k++) { // 中継点
          if (i == k || j == k) continue;
          if (a[i][j] == a[i][k] + a[k][j]) no_need[i][j] = true;
        }
      }
    }

    ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (no_need[i][j]) continue;
        ans += a[i][j];
      }
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IREP(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define IMAX INT_MAX
#define IMIN INT_MIN
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
template<typename T> inline void chmin(T &a, T b){ if(a > b) a = b; }
template<typename T> inline void chmax(T &a, T b){ if(a < b) a = b; }
template<typename T> inline void xch(T &a, T &b){ T w = a; a = b; b = w; }

int main() {
    vector<int> a;
    REP(i, 10){
        int n;
        cin >> n;
        a.push_back(n);
    }
    sort(ALL(a));
    cout << a[9] << endl << a[8] << endl << a[7] << endl;
    
    return 0;
}



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

void CountingSort(int*, int*, int);
int n;
main() {
  int i,*A,*B;
  scanf("%d",&n);
  A = (int *)malloc(sizeof(int) * n+1);
  B = (int *)malloc(sizeof(int) * n+1);
  if(A == NULL) {
    printf("メモリが確保できません\n");
    exit(EXIT_FAILURE);
  }
  if(B == NULL) {
    printf("メモリが確保できません\n");
    exit(EXIT_FAILURE);
  }

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

  CountingSort(A, B,10000);

  for(i = 1; i <= n; i++) {
    if(i > 1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  free(A);
  free(B);

  return 0;
}

void CountingSort(int *A,int *B, int k) {
  int i,j;
  int C[10001];
  for(i = 0; i < k; i++) {
    C[i] = 0;
  }

/* C[i]にiの出現数を記録する。 */
  for(j = 1; j < n+1; j++) {
    C[A[j]]++;
  }

/* C[i]にi以下の数の出現数を記録する */
  for(i = 1; i < k; i++) {
    C[i] = C[i] + C[i-1];
  }

  for(j = n; j > 0; j--) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

Measured memory_bytes: 16124
#include "bits/stdc++.h"
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif
bool check(string s){
    string t = s;
    reverse(t.begin(),t.end());
    return t == s;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int n = s.length();
    string one,two;
    one = "";
    two = "";
    int x = (n - 1) / 2;
    int y = (n + 3) / 2;
    for(int i=0;i<x;i++){
        one += s[i];
    }
    for(int i=y-1;i<n;i++){
        two += s[i];
    }
    cerr<<one<<" "<<two<<endl;
    if(check(s) and check(one) and check(two)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
    
}



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

using namespace std;

int n,m,x,a[300000],b[300000],ans,cnt;

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){scanf("%d",&x); a[x]++;}
	for (int i=1;i<=n;i++)
		if (a[i]>0) b[a[i]]++,cnt++;
	for (int i=1;i<=n;i++)
		while (cnt>m && b[i]>0) b[i]--,ans+=i,cnt--;
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<int64_t>> vec(N,vector<int64_t>(2));
  for(int i=0; i<N; i++){
    for(int j=0 ;j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  int64_t ans_a = vec.at(0).at(0);
  int64_t ans_b = vec.at(0).at(1);
  for(int i=0; i<N; i++){
      if(vec.at(i).at(0) < ans_a || vec.at(i).at(1) < ans_b){
        int64_t a = (ans_a + vec.at(i).at(0) - 1) / vec.at(i).at(0);
        int64_t b = (ans_b + vec.at(i).at(1) - 1) / vec.at(i).at(1);
        vec.at(i).at(0) *= max(a,b);
        vec.at(i).at(1) *= max(a,b);
      }
    ans_a = vec.at(i).at(0);
    ans_b = vec.at(i).at(1);
  }
  cout << ans_a + ans_b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();

    int i, j, H, W, A, B;
    cin>>H>>W>>A>>B;

    ll ans = 0;
    int br = min(W - B, H - A);
    rep(i, min(W - B, H - A)) {
        ans = (ans + (COM(B + 1 + i + H - A - i - 2, H - A - i - 1) * COM(W - B - i + A + 1 + i - 2, A + 1 + i - 1)) % MOD) % MOD;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n=1):n(n), f(n+1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i]) continue;
primes.push_back(i);
f[i] = i;
for (ll j = i*i; j <= n; j += i) {
if (!f[j]) f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x;}
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0) return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
ll countF(ll x){
    ll res=0;
    ll five=10;
    while(x/five>0){
        res+=x/five;
        five=five*5;
    }
    return res;
}
int main(){
    ll n;cin >> n;
    if(n%2!=0){
        cout << 0 << endl;
        return 0;
    }
    ll ans=countF(n);
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// tree<key, mapped = null_type, cmp = less<key>, rb_tree_tag, tree_order_statistics_node_update> name; order_of_key find_by_order

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fs first
#define sc second
#define abs(a) ((a) < 0 ? -(a) : (a))
#define sqr(a) ((a) * (a))

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

inline pair<pair<bool, bool>, pair<string, bool> > useinout();

#ifdef SOL
double starttime;
#endif

void initialization() {
#ifdef SOL
	starttime = 1000. * clock() / CLOCKS_PER_SEC;
	if (useinout().fs.fs)
		freopen("input.txt", "r", stdin);
	if (useinout().fs.sc)
		freopen("output.txt", "w", stdout);
#else
	srand(__rdtsc());
	const string file = useinout().sc.fs;
	if (!file.empty()) {
		freopen((file + ".in").c_str(), "r", stdin);
		freopen((file + ".out").c_str(), "w", stdout);
	} else
	if(useinout().sc.sc) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
}

int solution();

void finish(int exitval) {
	fflush(stdout);
#ifdef SOL
	fprintf(stderr, "\n-----------------\nexit value: %d\ntime: %.3lf ms\n-----------------\n", exitval, 1000. * clock() / CLOCKS_PER_SEC - starttime);
#endif
}

int main() {
	initialization();
	finish(solution());
	return (0);
}

const double eps = 1e-9;
const int mod = (int) 1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;

int c[maxn];

int solution() {

	string s;
	getline(cin, s);
	ll ans = 1;
	for(int i = 0; i < s.length(); i++) {
		ans += i + 1 - ++c[s[i]];
	}
	printf("%lld", ans);

	return (0);
}

inline pair<pair<bool, bool>, pair<string, bool> > useinout() {
	return (mp(mp(0, 0), mp("", 0)));
}

//by Andrey Kim


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;

    while(n > 0) {
        n -= 1000;
    }
    cout << -n << en;
}

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

    solve();
    /*
    ll t;
    cin >> t;
    REP(i, t)
    solve();
    */

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int H,W,i,j,n=0;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if(i%2==0){
                    if(j%2==0){
                        cout<<"#";
                    }else{
                        cout<<".";
                    }
                }else{
                    if(j%2==1){
                        cout<<"#";
                    }else{
                        cout<<".";
                    }
                    
                }
            }
            cout<<endl;
        }
        cout<<endl;
        
    }
    
    return 0;
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5 + 100;
const int mo = 1e9 + 7;
int inverse(int v) {
	int ans = 1;
	for(int p = mo - 2; p; p >>= 1) {
		if(p & 1) ans = ans * v % mo;
		v = v * v % mo;
	}
	return ans;
}
int inv[MX];
main () {
	int n; cin >> n;
	int p = 1;
	for(int i = 1; i <= n; i ++) {
		p = p * i % mo;
		inv[i] = (inv[i - 1] + inverse(i)) % mo;
	}
	int ans = 0;
	for(int i = 1; i <= n; i ++) {
		int in; cin >> in;
		ans = (ans + in * p % mo * (mo + inv[i] + inv[n - i + 1] - inv[1])) % mo;
	}
	cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>
#include <string>
#include <bits/stdc++.h>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;

static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;
using pint = pair<int,int>;

using Edge = pair<int, long long>;
using Graph = vector<vector<Edge> >;

Graph G;

vector <int> dir;
void dfs(int v, int p, int c)
{
  dir[v] = c;
  for(auto e: G[v])
  {
    if(e.first == p)continue;
    //グラフのコストが奇数なら異なる値にする
    if(e.second & 1)dfs(e.first, v, 1-c);
    else dfs(e.first, v, c);
  }
}


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

  G.assign(n, vector<Edge>());

  REP(i, n-1)
  {
    int u,v;
    ll w;
    cin >> u >> v >> w;
    --u, --v;
    G[u].push_back(Edge(v, w));
    G[v].push_back(Edge(u, w));
  }

  dir.assign(n,0);
  dfs(0,-1,1);

  for(auto v:dir)
  {
    cout << v << endl;
  }

  return 0;
}



Measured memory_bytes: 10496
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n;
pair<pair<string, int>, int> a[114];
vector<pair<int, int>> ta;

signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i].F.F >> a[i].first.second;
		a[i].second = i + 1;
	}
	sort(a, a + n);
	rep(i, n) {
		if (i < n - 1 && a[i].first.first == a[i + 1].first.first)ta.push_back({ a[i].first.second,a[i].second });
		else {
			ta.push_back({ a[i].first.second,a[i].second });
			sort(all(ta));
			reverse(all(ta));
			rep(j, ta.size()) {
				cout << ta[j].second << endl;
			}
			ta.clear();
		}
	}
}

Measured memory_bytes: 256
def main():
    n = int(input())
    indic = {}
    for _ in range(n):
        s = input()
        if s in indic:
            indic[s] += 1
        else:
            indic[s] = 1
    #print(indic)
    max_v = max(indic.values())

    ans = []
    for key in indic:
        if indic[key] == max_v:
            ans.append(key)

    ans.sort()
    for value in ans:
        print(value)
            
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 94424
using namespace std;

#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <numeric>
#include <map>
using namespace std;


int main(void){
	int N,M;

	cin >> N >> M;
  
  vector<int> D(N);
  
  int now = 0, r = 1;
  for (auto& i : D) {
    cin >> i;
    now += i;
    if (now <= M)
      r++;
  }

	cout << r << endl;

	return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    int ans = 0;
    for(int i=1; i<=k; i++){
        ans += l[n-i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (a, b, c, d) = listOfInt()
    println(when{
        Math.abs(c-a) <= d -> "Yes"
        Math.abs(b-a) <= d && Math.abs(c-b) <= d -> "Yes"
        else -> "No"
    })
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt()= listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37944
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}


const int MAX_N = 2010;
const int MOD = 1e9 + 7;
int128_t N, M;
int128_t S[MAX_N], T[MAX_N];

int128_t dp[MAX_N][MAX_N] = {};
int128_t dp_sum[MAX_N][MAX_N] = {};


int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= N; i++) {
        std::cin >> S[i];
    }

    for (int i = 1; i <= M; i++) {
        std::cin >> T[i];
    }

    int128_t ret = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            if (S[i] == T[j]) {
                dp[i][j] = (dp_sum[i-1][j-1] + 1) % MOD;
            } else {
                dp[i][j] = 0;
            }
            dp_sum[i][j] = (dp_sum[i-1][j] + dp_sum[i][j-1] - dp_sum[i-1][j-1] + dp[i][j] + MOD) % MOD;
            ret = (ret + dp[i][j]) % MOD;
        }
    }

    std::cout << ret << std::endl;
    
    return 0;
}

Measured memory_bytes: 126208
#include<iostream>
using ll = long long;
using namespace std;
int main(){
    ll n;
    cin >> n;
    string str;
    if(n==0)    str="0";
    while(n!=0){
        if(n%2==0){
            str="0"+str;
        }
        else{
            str="1"+str;
            n--;
        }
        n/=(-2);
    }
    cout << str << endl;
    return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(b+c-a < 0) cout << 0 << endl;
  else cout << b+c-a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <climits>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cfloat>
using namespace std;

const double INF = DBL_MAX / 2;

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

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

	int m = a[n-1] * 2;
	vector<double> dp(m, INF);
	dp[1] = 0;
	for(int i=0; i<n; ++i){
		vector<double> nextDp(m, INF);
		for(int j=1; j<m; ++j){
			for(int k=j; k<m; k+=j){
				nextDp[k] = min(nextDp[k], max(dp[j], abs(a[i]-k)/(double)a[i]));
			}
		}
		dp.swap(nextDp);
	}

	double ret = INF;
	for(int i=0; i<m; ++i)
		ret = min(ret, dp[i]);
	printf("%.10f\n", ret);

	return 0;
}

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

l = [ 0, abs( H[ 1 ] - H[ 0 ] ) ] + [ 0 ] * ( N - 2 )
for i in range( 2 , N ):
  l[ i ] = min( l[ i - 1 ] + abs( H[ i ] - H[ i - 1 ]), l[ i - 2 ] + abs( H[ i ] - H[ i - 2 ])) 
print( l[ N - 1 ] )

Measured memory_bytes: 13980
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
    do {                                                                       \
    } while (0)
#define dump(x)                                                                \
    do {                                                                       \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

struct S {
    int s, t, c;
};

void solve() {
    int n, c;
    cin >> n >> c;
    vector<S> cs(n);
    REP(i, 0, n) cin >> cs[i].s >> cs[i].t >> cs[i].c;
    sort(all(cs), [](auto &l, auto &r) { return l.t < r.t; });
    vector<vector<S>> css(c);
    REP(i, 0, n) {
        int tc = cs[i].c;
        --tc;
        if (css[tc].size() > 0 && cs[i].s == css[tc].back().t) {
            css[tc].back().t = cs[i].t;
        } else {
            css[tc].push_back(cs[i]);
        }
    }
    VI imos(100000 + 1);
    REP(i, 0, c) {
        for (auto &s : css[i]) {
            imos[s.s]++;
            imos[s.t + 1]--;
        }
    }
    REP(i, 0, 100000) imos[i + 1] += imos[i];
    cout << *max_element(all(imos)) << endl;
}

signed main() {
    solve();

    return 0;
}

Measured memory_bytes: 3712
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}

use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::BTreeMap;


use std::fmt::Display;
pub fn print_vec<T: Display>(v: &Vec<T>, prefix: &str, suffix: &str) {
    if v.is_empty() {
        println!("[]");
        return;
    }
    print!("{}", prefix);
    print!("{}", v[0]);
    for i in 1..v.len() {
        print!(" {}", v[i]);
    }
    println!("{}", suffix);
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (s,) = input!(String);
    let (t,) = input!(String);

    let slen = s.len();

    let mut ss = s.clone();

    ss.push_str(&s);

    let mut next_char: HashMap<(usize, char, char), usize> = HashMap::new();
    // let chs = HashMap::new();

    let mut cindex = HashMap::new();

    for (i, c) in ss.char_indices() {
        let v = cindex.entry(c).or_insert(vec![]);
        (*v).push(i);
    }

    for (i, c) in s.char_indices() {
        for &key in cindex.keys() {
            if let Some(v) = cindex.get(&key) {
                match v.binary_search(&i) {
                    Ok(next) => {
                        next_char.insert((i, c, key), v[next + 1]);
                    },
                    Err(next) => {
                        next_char.insert((i, c, key), v[next]);
                    }
                    //     if i <= next {
                    //         next_char.insert((i, c, key), next - i);
                    //     } else {
                    //         next_char.insert((i, c, key), i + slen - next);
                    //     }
                    // }
                }
            }
        }
    }

    let first = t.chars().nth(0).unwrap();
    if let None =  s.find(first) {
        println!("-1");
        return;
    }
    let mut index = s.find(first).unwrap();
    let mut current = first;
    let mut ans = index;

    for (i, c) in t.char_indices().skip(1) {
        if let Some(&ind) = next_char.get(&(index % slen, current, c)) {
            if index < ind {
                ans += ind - index;
            } else {
                ans += slen + ind - index;
            }
            index = ind;
            current = c;
        } else {
            println!("-1");
            return;
        }
    }

    println!("{}", ans + 1);
}

fn main() {
    solve();
}


Measured memory_bytes: 204712
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int arr[] = {a, b, c};

    std::sort(arr, arr + 3);

    printf("%d %d %d\n", arr[0], arr[1], arr[2]);

    return 0;
}


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

  int main() {
LL N,X,T;
cin>>N>>X>>T;
if(N%X==0){
  cout<<N/X*T<<endl;
}
else{
  cout<<(N/X+1)*T<<endl;
}
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

int n;

int main()
{
	n=ty();
	if(!(n&(n-1))){puts("No");return 0;}
	puts("Yes");

	printf("%d %d\n%d %d\n%d %d\n%d %d\n%d %d\n",3,1,1,2,2,n+3,n+3,n+1,n+1,n+2);
	for(int i=4;i+1<=n;i+=2)printf("%d %d\n%d %d\n%d %d\n%d %d\n",i,i+1,i+1,1,1,n+i,n+i,n+i+1);
	if(!(n&1))
	{
		int temp=1;
		while(temp<<1<=n)temp<<=1;
		printf("%d %d\n%d %d\n",temp+1,n,n+n-temp,n+n);
	}
	
	return 0;
}


Measured memory_bytes: 2304
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define INFTY (1<<21)
using namespace std;

static const int N = 100;

int main() {
	int p[N + 1], m[N + 1][N + 1];
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i - 1] >> p[i];
	}
	for (int i = 1; i <= n; i++) m[i][i] = 0;
	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = INFTY;
			for (int k = i; k <= j - 1; k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl

using namespace std;

typedef long long ll;
typedef string str;

const ll MAXN = 1e5 + 10;
const ll MOD = 1000000000000037;

ll n, a[MAXN], ps[MAXN];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	cout << 180 * (n - 2);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
lowerかな
2 4 2だとして
1.5-3.5がだめ
0,1 NG 2 OK
X開始、4-2=2秒間だめ

1 3 2
-1と0が2地点でNG
距離近い順に探索せな
うーん、密ケースでTLE,
IT1~IT2のfor回しはたしかに重くなると思った
eraseにする。なんかだめそうだけど。

うーん、密ケースは改善したけどKillerで1TLE
あっちをたてればこっちがたたず
1個ずつ消す、とかになるとめっちゃ重いよねえ。

もう答え見る･･･。
multiset?ってなんだ
setの重複許可か。sortだけするのかな
微妙だけど、結局Q人効率よく調べるとなるとこうか
ああ、一部改良できるかも
いや、結局NQ倍？
multisetだと何が効率いいんだ。
毎回N処理してるんじゃないの。
ああああ、意味わかった。
開始時間でsortしておいて、出発時間が上回ったらinsert中断してるのか。
*/
int main(){
  ll N,Q; cin>>N>>Q;
  vector<vector<ll>> Z(N*2,vector<ll>(3,0));
  vector<ll> D(Q,0);
  for(ll i=0; i<N; i++){
    ll s,t,x; cin>>s>>t>>x;
    Z[i*2][0]=s-x;//開始時間
    Z[i*2][1]=1;//insert
    Z[i*2][2]=x;//value
    Z[i*2+1][0]=t-x;//開始時間
    Z[i*2+1][1]=-1;//erase
    Z[i*2+1][2]=x;//value
  }
  //処理時間順にする
  sort(Z.begin(), Z.end(), [](auto& x, auto& y){return x[0] < y[0];});
  for(ll i=0; i<Q; i++) cin>>D[i];
  //人ごとに探索。
  ll Zsz=Z.size(), k=0;
  multiset<ll> S;
  for(ll i=0; i<Q; i++){
    //multisetにその時間までの道路の開閉情報いれる
    while(k<Zsz && Z[k][0]<=D[i]){
      ll flag=Z[k][1];
      ll val=Z[k][2];
      if(flag==1) S.insert(val);
      else if(flag==-1) S.erase(S.find(val));
      k++;
    }
    if(S.empty()) cout<<-1<<endl;
    else cout<<*S.begin()<<endl;
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a, b;
  cin >> a >> b;
  
  int n = a + b;
  
  if(a <= b){
    cout << "Impossible" << endl;
    return 0;
  }
  
  vector<int> x;
  x.emplace_back(0);
  for(int i = 1; i < n; i++){
    cout << "? " << x.back() << " " << i << endl;
    char c;
    cin >> c;
    if(c == 'Y') x.emplace_back(i);
    else{
      x.pop_back();
      if(x.size() == 0){
        x.emplace_back(i + 1);
        i++;
      }
    }
  }
  
  vector<int> ans(n, 0);
  ans.at(x.back()) = 1;
  
  for(int i = 0; i < n; i++){
    cout << "? " << x.back() << " " << i << endl;
    char c;
    cin >> c;
    if(c == 'Y') ans.at(i) = 1;
  }
  
  cout << "! ";
  for(int i = 0; i < n; i++){
    cout << ans.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 776
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
#include<ctime>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;

#define ll long long
#define MP make_pair

ll n,ans=0;

void cnt(ll num,ll ins,ll a,ll b,ll c){
    num=num*10+ins;
    if(num<=n){
        if(a+b+c==0)ans++;
        cnt(num,7,0,b,c);
        cnt(num,5,a,0,c);
        cnt(num,3,a,b,0);
        return;
    }
    return;
}

int main(void) {
    cin>>n;
    cnt(0,0,1,1,1);

    cout<<ans<<"\n";

    
    
    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) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()
 
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}
 
typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;

int main(){
   int w,h,n;
   cin >> w >> h >> n;
   vector<pair<int,int>> xy(n);
   vector<int> a(n);
   rep(i,n)cin >> xy[i].first >> xy[i].second >> a[i];

   int x1=0,y1=0,x2=w,y2=h;
   rep(i,n){
         if(a[i]==1)x1 = max(x1,xy[i].first);
         else if(a[i]==2)x2 = min(x2,xy[i].first);
         else if(a[i]==3)y1 = max(y1,xy[i].second);
         else if(a[i]==4)y2 = min(y2,xy[i].second);
   }
   int ans = (x2-x1)*(y2-y1);
   if(x1 >= x2 || y1 >= y2)cout << 0 << endl;
   else cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
ll cnt(ll x){
	int res=0;
	while(x!=0)res++,x/=10;
	return res;
}
int main() {
	ll n,res=1e18;cin>>n;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			res=min(res,max(cnt(n/i),cnt(i)));
		}
	}
	cout<<res<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int _=1e6+20;
int a[_],b[_],c[_],d[_];
int main(){
	ios::sync_with_stdio(false);
	int n;cin>>n;
	for(int i=1;i<=n;++i){
		int x;cin>>x;
		if(i&1)c[x]++;
		else d[x]++;
	}
	int s1=0,s2=0,t1,s3=0,s4=0,t2;
	for(int i=1;i<=1e5;++i){
		int x=c[i],y=d[i];
		if(x>s1)swap(x,s1),t1=i;
		if(x>s2)s2=x;
		if(y>s3)swap(y,s3),t2=i;
		if(y>s4)s4=y;
	}
	if(t1!=t2)cout<<n-s1-s3<<endl;
	else cout<<n-s1-s3+min(s1-s2,s3-s4)<<endl;
	return 0;
}


Measured memory_bytes: 4736
import java.util.*;
import java.util.ArrayDeque;
import java.util.Arrays;

class Point{
    int h;
    int w;
    Point(int h, int w){
        this.h = h;
        this.w = w;
    }
}

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
 
        int H = sc.nextInt();
        int W = sc.nextInt();
        char[][] S = new char[H][W];
        int[] dh = {1, 0, -1, 0};
        int[] dw = {0, 1, 0, -1};

        for(int i=0; i<H; i++){
            S[i] = sc.next().toCharArray();
        }
        int max = 0;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(S[i][j]=='#'){
                    continue;
                }
                ArrayDeque<Point> que = new ArrayDeque<Point>();
                que.add(new Point(i, j));
                boolean[][] memo = new boolean[H][W];
                memo[i][j] = true;
                int[][] dist = new int[H][W];
                for(int[] x:dist){
                    Arrays.fill(x, 0);
                }
                while(!que.isEmpty()){
                    Point p = que.pop();
                    for(int k=0; k<4; k++){
                        int h = p.h + dh[k];
                        int w = p.w + dw[k];
                        if(h>=0 && h<H && w>=0 && w<W){
                            if(S[h][w]!='#' && !memo[h][w]){
                                que.add(new Point(h, w));
                                memo[h][w] = true;
                                dist[h][w] = dist[p.h][p.w] + 1;
                                max = Math.max(max, dist[h][w]);
                            }
                        }
                    }
                }
            }
        }
        System.out.println(max);
    }
}

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


int main(void){
  int N, W;
  cin >> N >> W;

  const int MOD = (1e9) + 7;
  
  vector<int> w(N + 1);
  w[0] = 1e9;
  for(int i = 1; i <= N; i++){ cin >> w[i]; }
  sort(w.begin(), w.end());
  reverse(w.begin(), w.end());
  
  vector<vector<long long int> > dp(N + 1, vector<long long int>(W + 2, 0));
  dp[0][0] = 1;
  for(int i = 1; i <= N; i++){
    for(int j = 0; j <= W + 1; j++){
      // dp[i][j]: i???????????§?????¢?????????????????£?????????j??\??????????????????????????????????????°
      // = i-1???????????§?????¢?????????????????£?????????j??\??????????????????????????????????????° * 2
      // + i-1???????????§?????¢?????????????????£?????????[j - w[i], j)???????????????????????????????????°
      // = i-1???????????§?????¢?????????????????£?????????j??\??????????????????????????????????????° * 2
      // + (i-1???????????§?????¢?????????????????£?????????j - w[i]??\??????????????????????????????????????° - j??\??????????????????????????????????????°)
      // = i-1???????????§?????¢?????????????????£?????????j??\??????????????????????????????????????°
      // + (i-1???????????§?????¢?????????????????£?????????j - w[i]??\??????????????????????????????????????°
      int r = max(j - w[i], 0);
      dp[i][j] = (dp[i - 1][j] + dp[i - 1][r]) % MOD;
    }
  }

  /*
  for(int i = 0; i <= N; i++){
    printf("%d: ", i);
    for(int j = 0; j <= W + 1; j++){
      printf("[%2d]", dp[i][j]);
    }
    printf("\n");
  }
  */
  
  // j????????????(j, i]???????????????(i, N]????¢??????§????????????????????°
  long long int sum = 0, ans = 0;
  for(int i = N; i >= 0; i--){
    long long int total = W - sum;
    //printf("sum: %d\n", sum);
    if(sum > W){ break; }
    if(sum + w[i] > W){
      ++ans;
      ans %= MOD;
      //printf("%lld + %d >= %d, %lld is maximal\n", sum, w[i], W, sum);
    }
    for(int j = 1; j < i; j++){
      int low = max(total - w[j] - w[i] + 1, 0LL);
      int up = max(total - w[j] + 1, 0LL);
      //printf("<%d>: [%d, %d) (+ %d < %lld) = %lld %lld\n", j - 1, low, up, w[j], total, dp[j - 1][low] - dp[j - 1][up] + MOD, ans);
      ans += dp[j - 1][low] - dp[j - 1][up] + MOD;
      ans %= MOD;
    }

    // ?¢??????§?????????????????????
    sum += w[i];
  }

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

Measured memory_bytes: 18652
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,x;
	scanf("%lld%lld%lld",&a,&b,&x);
	if(a>0)
printf("%lld",(b/x)-(a-1)/x);
else
printf("%lld",(b/x)+1);
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    int R, G;
    cin >> R >> G;
    cout << 2 * G - R;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       Map<String,Integer>map=new HashMap<>();
       map.put("SUN",1);
       map.put("MON",2);
       map.put("TUE",3);
       map.put("WED",4);
       map.put("THU",5);
       map.put("FRI",6);
       map.put("SAT",7);
     String ss=s.nextLine();

        System.out.println(8-map.get(ss));
        }
    }


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

int main(){
    int a, b;
    string s;
    cin >> a >> b >> s;
    bool flag = true;
    for(int i=0; i<a; i++){
        if(!isalnum(s[i])) flag = false;
    }
    if(s[a] != '-') flag = false;
    for(int i=a+1; i<s.size(); i++){
        if(!isalnum(s[i])) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int N;
vector<long long> a;

int main() {
    cin >> N;
    long long black = 0, white = 0;
    a.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        if (i % 2 == 0) black += a[i];
        else white += a[i];
    }
    if (N % 2 == 0) cout << max(black, white) << " " << min(black, white) << endl;
    else {
        long long low = 0, high = 1<<30;
        while (high - low > 1) {
            long long mid = (low + high) / 2;
			vector<long long> dp; dp.assign(N + 1, -(1LL << 60));
			dp[1] = a[0];
			for (int i = 3; i <= N; i += 2) {
				// 直前をカットする場合
				if (dp[i - 2] >= mid) dp[i] = max(dp[i], a[i - 1]);
				
				// 直前をカットしない場合
				dp[i] = max(dp[i], dp[i - 2] - a[i - 2] + a[i - 1]);
			}

			//cout << "----------------" << endl << "mid = " << mid << endl;
			//for (int i = 1; i <= N; ++i) cout << i << ": " << dp[i] << endl;

			if (dp[N] >= mid) low = mid;
			else high = mid;
        }
        cout << white + low << " " << black - low << endl;
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
int MOD = 1000000007; //10^9 + 7


int main() {
	int n;
	string s;
	cin >> n >> s;

	if (n % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	n /= 2;
	rep(i, n) {
		if (s.at(i) != s.at(i + n)) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
D = dict()
TF = []
for _ in range(n):
  s = input()
  if "." not in s:
    s += "."
  a, b = s.split(".")
  k = len(b)
  c = int(a+b)
  t = 0
  while c%2 == 0:
    c //= 2
    t += 1
  f = 0
  while c%5 == 0:
    c //= 5
    f += 1
  t -= k
  f -= k
  TF.append((t, f))
D = Counter(TF)
ans = 0
for t1, f1 in D.keys():
  for t2, f2 in D.keys():
    if t1+t2 >= 0 and f1+f2 >= 0:
      ans += D[(t1, f1)] * D[(t2, f2)]
for t, f in TF:
  if t >= 0 and f >= 0:
    ans -= 1
ans //= 2
print(ans)

Measured memory_bytes: 88664
Q,H,S,D=list(map(int,input().split()))
N=int(input())
ans=0
min_tea=min(Q*8,H*4,S*2,D)
ans+= (N//2) * min_tea
N-=(N//2)*2
min_tea=min(Q*4,H*2,S*1)
ans+= (N//1) * min_tea
print(ans)

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

int main()
{
    int n, k, ans = 0, s;
    cin >> n;
    int tmp[10][10] = {0};

    for (int i = 1; i <= n; i++) {
        int x = i;
        while (x) {
            s = x%10;
            x /= 10;
        }
        tmp[s][i%10]++;
    }
    
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            ans += tmp[i][j] * tmp[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> x(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    int ans = (int)1e29;
    for (int i = 0; i < 2007; i++) {
        int cur_max = 0;
        for (int j = 0; j < n; j++) {
            cur_max = max(cur_max, abs(x[j] - i));
        }
        ans = min(ans, cur_max);
    }
    cout << ans << '\n';
    return 0;
}




Measured memory_bytes: 3180
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.Set;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            long N = in.Long();

            int n = (int) Math.sqrt(N);
            boolean[] prime = new boolean[n + 1];
            Arrays.fill(prime, true);
            prime[0] = false;
            prime[1] = false;
            for (int i = 2; i <= n; i++) {
                if (prime[i]) {
                    for (int j = i * 2; j <= n; j += i) {
                        prime[j] = false;
                    }
                }
            }
            Set<Long> set = new HashSet<>();
            for (int i = 2; i <= n; i++) {
                if (prime[i]) {
                    for (int j = i; j <= n; j *= i) {
                        if (N % j == 0) {
                            set.add((long) j);
                            N /= j;
                        }
                    }
                }
            }
            if (N > n) set.add(N);
            out.println(set.size());
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public long Long() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 34600