akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <set>

using namespace std;

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

const ll mod = 1000000007;

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

  int N;
  cin >> N;
  vector<ll> x(N), y(N);
  for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

  vector<pair<ll, int> > xi(N), yi(N);
  for (int i = 0; i < N; i++) {
    xi[i] = make_pair(x[i], i);
    yi[i] = make_pair(y[i], i);
  }
  sort(xi.begin(), xi.end());
  sort(yi.begin(), yi.end());

  vector<set<Pii> > edge(2*N);
  for (int i = 0; i < N; i++) {
    edge[i].emplace(N+i, 0);
    edge[N+i].emplace(i, 0);
  }

  for (int i = 0; i < N-1; i++) {
    edge[xi[i].second].emplace(xi[i+1].second, xi[i+1].first - xi[i].first);
    edge[xi[i+1].second].emplace(xi[i].second, xi[i+1].first - xi[i].first);
    edge[N+yi[i].second].emplace(N+yi[i+1].second, yi[i+1].first - yi[i].first);
    edge[N+yi[i+1].second].emplace(N+yi[i].second, yi[i+1].first - yi[i].first);
  }

  priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > pque;
  pque.emplace(0, 0);
  vector<bool> visited(2*N);
  int nodeToVisit = 2*N;
  ll ans = 0;
  while (!pque.empty()) {
    auto now = pque.top();
    pque.pop();
    auto &cost = now.first;
    auto &node = now.second;
    if (visited[node]) continue;
    visited[node] = true;
    nodeToVisit--;
    ans += cost;
    if (nodeToVisit <= 0) break;
    for (auto &x: edge[node]) {
      pque.emplace(x.second, x.first);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 48752
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n; cin>>n;
	map<ll,ll> a,b;
	rep(i,1,n+1){
		ll m; cin>>m;
		if(i%2==0){//偶数
			a[m]++;
		}
		else{
			b[m]++;
		}
	}
	vector<pair<ll,ll>> q(n),p(n);
	// q=even p=odd
	for(auto c:a) q.push_back(make_pair(c.second,c.first));
	for(auto c:b) p.push_back(make_pair(c.second,c.first));
	sort(all(p)); reverse(all(p));
	sort(all(q)); reverse(all(q));
	ll x,y;
	ll ans=n;
	rep(i,0,q.size()){
		if(i==2)break;
		rep(j,0,p.size()){
			if(j==2)break;
			if(q[i].second!=p[j].second){
				chmin(ans,n-q[i].first-p[j].first);
			}
		}
	}
	if(ans==n)ans/=2;
	cout<<ans<<endl;
	
	
	
	return 0;
}

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

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
struct edge{
    ll u,v,d,c;
    edge(){}
    edge(ll u,ll v,ll d,ll c):u(u),v(v),d(d),c(c){}
    bool operator < (const edge& o) const{
        return c < o.c;
    }
    bool operator > (const edge& o) const{
        return c > o.c;
    }
};
ll solve(ll N,ll M){
    ll res = 0;
    vector<vector<edge>> G(N);
    for(int i = 0;i <M;i++){
        ll u,v,d,c; cin >> u >> v >> d >> c;
        u--; v--;
        G[u].push_back(edge(u,v,d,c));
        G[v].push_back(edge(v,u,d,c));
    }
    
    vector<ll> dist(N,LINF);
    dist[0] = 0;
    queue<ll> q;
    q.push(0);
    while(q.size()){
        ll n = q.front(); q.pop();
        for(auto e:G[n]){
            if(dist[e.v] > dist[e.u] + e.d){
                dist[e.v] = dist[e.u] + e.d;
                q.push(e.v);
            }
        }
    }
    
    for(int i = 1; i < N;i++){
        ll Min = LINF;
        for(edge e:G[i]){
            if(dist[e.u] == dist[e.v] + e.d) Min = min(Min,e.c);
        }
        res += Min;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N,M;
    while(cin >> N >> M,N|M){
        cout << solve(N,M) << endl;
    }
    return 0;
}



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

struct BipMatch{
  int n;
  vector<vector<int> > G;
  vector<int> match,used;
  
  BipMatch(){}
  BipMatch(int sz):n(sz),G(sz),match(sz),used(sz){}
  
  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(int i=0;i<(int)G[v].size();i++){
      int u=G[v][i],w=match[u];
      if(w<0||(!used[w]&&dfs(w))){
        match[v]=u;
        match[u]=v;
        return true;
      }
    }
    return false;
  }

  int build(){
    int res=0;
    fill(match.begin(),match.end(),-1);
    for(int v=0;v<n;v++){
      if(match[v]<0){
        fill(used.begin(),used.end(),0);
        if(dfs(v)){
          res++;
        }
      }
    }
    return res;
  }
};

int n,a[101][101],a1,a2,a3,p[1001],t[1001],m,m2;

int main(){
while(1){
  r(i,101)r(j,101)a[i][j]=(i==j?0:1e8);
  cin>>n>>m>>m2;
  if(n==0)return 0;
  r(i,m){
    cin>>a1>>a2>>a3;
    a[a2][a1]=a[a1][a2]=a3;
  }
  r(i,m2)cin>>p[i]>>t[i];
  r(k,n)r(i,n)r(j,n)a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
  BipMatch D(m2*2);
  r(i,m2){
    r(j,m2)if(i!=j){
      if(a[p[i]][p[j]]+t[i]<=t[j]){
        D.add_edge(i,j+m2);
      }
    }
  }
  cout<<m2-D.build()<<endl;
}
}


Measured memory_bytes: 8464
#include <bits/stdc++.h>
using namespace std;
 
int read() {
    int f = 1, x = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f; return x;
}
 
/*============ Header Template ============*/

const int N = 100005;
int n, L, q;
int x[N], r[N][20];
int idx[N];
int main() {
	// freopen("A.in", "r", stdin);
	// freopen("A.out", "w", stdout);
	n = read(); x[n + 1] = 1E9 + 7; x[0] = - 1E9 - 7;
	for (int i = 2; i <= n; i ++) idx[i] = idx[i >> 1] + 1;
	for (int i = 1; i <= n; i ++) x[i] = read();
	L = read(); q = read();
	for (int i = 1; i <= n; i ++) {
		int le = i, ri = n + 1;
		while (ri - le > 1) {
			int mid = (le + ri) >> 1;
			if (x[mid] - x[i] <= L) le = mid;
			else ri = mid;
		}
		r[i][0] = le;
	}
	for (int j = 1; j < 18; j ++)
		for (int i = 1; i <= n; i ++) {
			r[i][j] = r[r[i][j - 1]][j - 1];
	}
	for (int i = 1; i <= q; i ++) {
		int a = read(), b = read();
		if (b < a) swap(a, b);
		int ans = 0;
		for (int j = 17; j >= 0; j --) {
			if (r[a][j] < b) {
				a = r[a][j];
				ans += (1 << j);
			}
		}
		printf("%d\n", ans + 1);
	}
	return 0;
}
/*
9
1 3 6 13 15 18 19 29 31
10
4
1 8
7 3
6 7
8 5
*/

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

using namespace std;

const int N = 2 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

long long n, a, b, mod;

bool read() {
    if (!(cin >> n >> a >> b >> mod))
        return false;

    return true;
}

int getlen(long long num) {
    auto res = 0;
    for (; num > 0; num /= 10, ++res) { }
    return res;
}

long long bpow(long long a, long long n, long long mod) {
    auto res = 1ll;
    a %= mod;

    for (; n > 0; n /= 2, a = a * a % mod)
        if (n & 1)
            res = res * a % mod;

    return res;
}

long long series1(long long x, long long n) {
    if (n == 0)
        return 1ll;

    auto nn = (n - 1) / 2;
    auto res = series1(x, nn) * (1 + bpow(x, nn + 1, mod)) % mod;

    if (n % 2 == 0)
        res += bpow(x, n, mod);

    return res % mod;
}

long long series2(long long x, long long n) {
    if (n == 0)
        return 0ll;

    auto nn = (n - 1) / 2;
    auto piv = bpow(x, nn + 1, mod);
    auto res = (series2(x, nn) * (1 + piv) + (nn + 1) % mod * series1(x, nn) % mod * piv) % mod;

    if (n % 2 == 0)
        res += n % mod * bpow(x, n, mod) % mod;

    return res % mod;
}

long long calc(long long a, long long b, long long n) {
    long long x = bpow(10ll, getlen(a), mod);
    return (mod + (a % mod * series1(x, n) - b % mod * series2(x, n)) % mod) % mod;
}

void solve() {
    auto ans = 0ll;

    for (long long len = getlen(a), i = 0; i < n; ++len) {
        if (len < getlen(a + i * b))
            continue;

        auto l = i;
        auto r = n - 1;

        for (; l < r; ) {
            auto m = (l + r + 1) / 2;

            if (getlen(a + b * m) > len)
                r = m - 1;
            else
                l = m;
        }

        ans = bpow(bpow(10ll, len, mod), r + 1 - i, mod) * ans % mod;
        ans = (ans + calc(a + r * b, b, r - i)) % mod;
        i = r + 1;
    }

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int y = scan.nextInt();
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= n; j++){
                int z = (y - i * 10000 - j * 5000) / 1000;
                if(z == n - i - j && 0 <= z && z <= n){
                    System.out.println(i + " " + j + " " + z);
                    return;
                }
            }
        }
        System.out.println(-1 + " " + -1 + " " + -1);
        scan.close();
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 27236
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] p = new int[N];
        for(int i = 0; i < N; i++){
            p[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(p);
        int sum = 0;
        for(int i = 0; i < K; i++){
            sum += p[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 39456
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////
string s;
 
ll cal1(){
    ll n=s.size();
    ll dp[n+1][2];memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    rep(i,0,n-1){
        ll c=s[i]-'0';
        if(c==0){
            dp[i+1][0]=dp[i][0];
            dp[i+1][1]=mod(3*dp[i][1]);
        }else{
            dp[i+1][0]=mod(2*dp[i][0]);
            dp[i+1][1]=mod(dp[i][0]+3*dp[i][1]);
        }
    }
    /*
    rep(i,0,n){
        rep(j,0,1)cout<<dp[i][j]<<" ";cout<<endl;
    }*/
    ll ans=0;
    rep(j,0,1)Add(ans,dp[n][j]);
    return mod(ans);
}
ll rev(string s){
    ll res=0;
    reverse(s.begin(),s.end());
    rep(i,0,s.size()-1){
        if(s[i]=='1')res+=1ll<<i;
    }
    return res;
}
ll cal2(){
    ll l=rev(s);
    ll res=0;
    rep(a,0,l){
        rep(b,0,l-a){
            if((a+b)==(a^b))res++;
        }
    }
    return res;
}
string exc(ll n){
    string res;
    while(n>=1){
        if(n&1)res+='1';
        else res+='0';
        n/=2;
    }
    reverse(res.begin(),res.end());
    return res;
}
 
int main(){fastio
    cin>>s;
    cout<<cal1()<<endl;
    /*
    rep(i,1,10){
        s=exc(i);
        cout<<s<<":"<<cal1()<<" "<<cal2()<<endl;
    }*/
    
    return 0;
}


Measured memory_bytes: 2000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 1;i<=n;++i)
typedef long long ll;
 int f(int i){
   int count = 0;
   while(i > 0){
     count += i%10;
     i /= 10;
   }
   return count;
 }
 
int main(){
  int n,a,b;
  int ans = 0;
  cin >> n >> a >> b;
  rep(i,n){
    if(a <= f(i) && f(i) <= b){
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
times = [A,B,C,D,E]
remains = []
for t in times:
    remains.append(t%10)
last_item_i = -1
rmin = 1e8
for i in range(len(remains)):
    if remains[i] != 0 and remains[i] < rmin:
        rmin = remains[i]
        last_item_i = i
if last_item_i == -1:
    last_item_i = 0

ans = 0
for i in range(len(times)):
    if i != last_item_i:
        t = ((times[i] + 10 - 1)//10)*10
        ans += t

ans += times[last_item_i]

print(ans)


Measured memory_bytes: 62048
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    if S == T[:-1]:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
#define endl '\n'
 
int main()
{
    fastio;
    lli a,b,c,k;
    cin>>a>>b>>c>>k;
    lli ans = 0;

    lli t = min(a,k);
    ans += t;
    a -= t;
    k -= t;

    t = min(b,k);
    b -= t;
    k -= t;

    t = min(c,k);
    ans -= t;
    c -= t;
    c -= t;

    cout<<ans<<endl;
}

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }

    sort(h.rbegin(), h.rend());

    int move_count = 0;

    for (int i = 0; i < n; i++)
    {
        if (i < k)
            continue;
        move_count += h[i];
    }

    cout << move_count << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
    int N;
    cin >> N;

    long long sum = 0;
    for (int i = 1; i <= N; i++) {
        string s = "";
        if (i % 3 == 0 && i % 5 == 0) {
            s = "FizzBuzz";
        }
        else if (i % 3 == 0) {
            s = "Fizz";
        }
        else if (i % 5 == 0) {
            s = "Buzz";
        }
        else {
            sum += i;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();

    String p[] = new String[10000000];
    int w[] = new int[10000000];

    int setsumon[] = new int[10000000];
    String answer[] = new String[10000000];

    for (int i = 0; i < m; i++) {
      setsumon[i] = sc.nextInt();
      answer[i] = sc.next();
    }

    int seikai = 0;
    int wrong = 0;
    for (int i = 0; i < m; i++) {
      if ("AC".equals(p[setsumon[i] - 1])) {
        continue;
      }
      if (answer[i].equals("AC")) {
        p[setsumon[i] - 1] = "AC";
        seikai++;
        if (w[setsumon[i] - 1] > 0) {
          wrong += w[setsumon[i] - 1];
        }

      } else {
        w[setsumon[i] - 1]++;
      }
    }

    System.out.println(seikai + " " + wrong);
  }
}


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

int main() {
  int N;
  cin >> N;
  int ans=0;
  for (int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    ans += r-l+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    int a, b;
    
    scanf("%d %d", &a, &b);
    
    if (a <= 0 && b >= 0) {
        puts("Zero");
    } else if (a < 0 && (b - a) % 2 == 0) {
        puts("Negative");
    } else {
        puts("Positive");
    }
    
    return 0;
}


Measured memory_bytes: 128
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    string s; cin >> s;
    if(s.substr(0, 4) == "YAKI") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 768
#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 g(a, b) __gcd((a), (b))
#define l(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, class U>T rem(T a, U b) { return a - b*floor(a/b); }
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; }
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()
{
        string S;
        cin >> S;

        ll ans = 0;
        rep(bit, 0, 1<<(len(S)-1)) {
                vll choice;
                rep(i, 0, len(S)-1) {
                        if (bit & 1<<i) {
                                choice.push_back(i);
                        }
                }

                vector<string> nums;
                string tmp;
                rep(i, 0, len(S)) {
                        tmp += S[i];
                        if (isin(i, choice)) {
                                nums.push_back(tmp);
                                tmp.clear();
                        }
                }      
                nums.push_back(tmp);

                rep(i, 0, len(nums)) {
                        ans += stoll(nums[i]);
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
typedef long long ll;

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

const double PI=3.14159265358979323846; // or M_PI


void Main() {
    ll n, k, d, count=0, roop=0, roop_start=0, in_a;

    // ifstream in("sub1_22.txt");
    // cin.rdbuf(in.rdbuf());

    cin >> n >> k;
    vector<ll> a;
    vector<ll> dest;
    vector<ll> ikeru_check(n + 1, -1);

    a.push_back(0);
    REP(i, n) {
        cin >> in_a;
        a.push_back(in_a);
    }
    //COUTA(i, a);

    d = 1;
    REP(i, k) {
        if (ikeru_check[d] != -1) {
            roop_start = ikeru_check[d];
            roop = count - ikeru_check[d];
            // COUT(roop);
            break;
        }
        ikeru_check[d] = count;
        dest.push_back(d);
        d = a[d];
        count++;
    }
    dest.push_back(d);
    // COUT(count);
    // COUT(k);
    // COUT(dest.size());

    vector<ll> l(dest.begin() + roop_start, dest.end());
    //COUTA(i, dest);
    //COUTA(i, l);

    if (k <= count) {
        COUT(dest[k]);
    }
    else {
        COUT(l[((k - roop_start) % roop)]);
    }

    //COUT(count);
    // COUTA(i, a);
    // COUTA(i, dest);
    // COUTA(i, ikeru_check);
    // COUT(roop);
    // COUT(roop_start);
    // COUT(k % roop);
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 9460
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int N, M, Q, a[55], b[55], c[55], d[55], sp = 0;

std::vector<int> A;


void dfs(int i)
{
  if (A.size() == N) {
    int s = 0;
    
    for (int j = 0; j < Q; j ++)
      if (A[b[j]] - A[a[j]] == c[j])
        s += d[j];

    sp = std::max(s, sp);

    return;
  }

  assert(! A.empty());
  
  int s = A.back();

  for (int i = s; i <= M; i ++) {
    A.push_back(i);

    dfs(i + 1);

    A.pop_back();
  }
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::cin >> N >> M >> Q;

  for (int i = 0; i < Q; i ++) {
    std::cin >> a[i] >> b[i] >> c[i] >> d[i];

    a[i] --;
    b[i] --;
  }

  A.push_back(1);

  dfs(1);

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


Measured memory_bytes: 3656
#include <stdio.h>
#include<string.h>
int main()
{
    long long int n;
    scanf("%lld",&n);
    int a[n];
    long long int count[n+1],sum=0,count1[n+1];
    for(int i=0;i<n+1;i++)
    {
        count[i]=0;
        count1[i]=0;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        count[a[i]]++;
    }
    for(int i=0;i<n+1;i++)
    {
        if(count[i]>1)
        {
            count1[i]=((count[i]-1)*(count[i]-2))/2;
            count[i]=(count[i]*(count[i]-1))/2;
            sum+=count[i];
        }
        else
        count[i]=0;
    }
    for(int i=0;i<n;i++)
    {
        printf("%lld\n",(sum-count[a[i]]+count1[a[i]]));
    }
}


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

int main() {
  long long k;
  cin>>k;
  long long ans=0;
  for(long long a=1;a<=k;a++){
    for(long long b=1;b<=k;b++){
      for(long long c=1;c<=k;c++){
        long long x=gcd(a,b);
        ans+=gcd(x,c);
      }
    }
  }
  cout<<ans<<endl;
}
  


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    int mn = inf;
    rep(i, n) {
        int s;
        cin >> s;
        ans += s;
        if(s %10 != 0) chmin(mn, s);
    }
    if(ans % 10 == 0) ans -= mn;
    cout << max(ans, 0) << endl;
}

Measured memory_bytes: 256
N=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(N):
    s=input()
    if s=="AC":
        ac+=1
    elif s=="WA":
        wa+=1
    elif s=="TLE":
        tle+=1
    else:
        re+=1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

Measured memory_bytes: 9204
#include<iostream>
#include<map>
#include<vector>
#include<string>

using namespace std;

int p[101];
vector<int> e[101];
const int INF=1<<29;

void dfs(int x,int i){
  if(p[x]!=INF)return;
  p[x]=i;
  for(auto f:e[x]){
    dfs(f,i);
  }
}

int main(){
  int N;
  cin>>N;
  string l[101];
  map<string,vector<int> > m;
  for(int i=0;i<N;i++){
    string s;
    cin>>s;
    if(s=="goto"){
      string t;
      cin>>t;
      t.resize(t.size()-1);
      m[t].push_back(i);
    }else{
      s.resize(s.size()-1);
      l[i]=s;
    }
  }
  for(int i=0;i<N+1;i++){
    if(!l[i].empty()){
      e[i]=m[l[i]];
    }
    if(i&&!l[i-1].empty()){
      e[i].push_back(i-1);
    }
    p[i]=INF;
  }
  dfs(N,0);
  for(int i=1;p[0]==INF;i++){
    for(int j=0;j<N;j++){
      if(p[j+1]==i-1&&p[j]==INF){
	dfs(j,i);
      }
    }
  }
  cout<<p[0]<<endl;
}

Measured memory_bytes: 1256
S=gets.chomp.chars
N=S.size
ps=S.reverse

s2=S[0, (N-1)/2]
ps2=s2.reverse

s3=S[(N+3)/2-1, N-(N+3)/2+1]
ps3=s3.reverse

if S===ps && s2===ps2 && s3===ps3
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 3836
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    x = list(map(int,input().split()))

    for i in range(5):
        if x[i] == 0:
            res = i + 1

    print(res)



main()


Measured memory_bytes: 9160
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    if ((a+b)%2==0) {
      System.out.println((a+b)/2);
    }else{
      System.out.println((a+b+1)/2);
    }
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int main()
{
#ifdef wxh010910
	freopen("input.txt", "r", stdin);
#endif
	int n;
	cin >> n;
	vector<int> a(n);
	vector<bool> b(n);
	int prefix = -1, q = 0;
	for(int i = 0; i < n; ++i)
	{
		cin >> a[i];
		--a[i];
		if(a[i] > prefix)
		{
			prefix = a[i];
			b[i] = true;
			++q;
		}
	}
	vector<int> fenw_even(n, 0), fenw_odd(n, -inf);
	stack< pair<int *, int> > memory;
	auto modify = [&](vector<int> & fenw, int x, int value)
	{
		while(x < n)
		{
			if(fenw[x] < value)
			{
				memory.emplace(& fenw[x], fenw[x]);
				fenw[x] = value;
			}
			x |= x + 1;
		}
	};
	auto query = [&](vector<int> & fenw, int x)
	{
		int result = - inf;
		while(x >= 0)
		{
			result = max(result, fenw[x]);
			x = (x & (x + 1)) - 1;
		}
		return result;
	};
	vector<int> size(n);
	for(int i = n - 1; ~ i; --i)
	{
		int even = -inf, odd = -inf;
		size[i] = memory.size();
		if(b[i])
		{
			even = query(fenw_even, n - a[i] - 1) + 2;
			odd = query(fenw_odd, n - a[i] - 1) + 2;
		}
		else
		{
			even = query(fenw_odd, n - a[i] - 1) + 1;
			odd = query(fenw_even, n - a[i] - 1) + 1;
		}
		if(even >= 0)
		{
			modify(fenw_even, n - a[i] - 1, even);
		}
		if(odd >= 0)
		{
			modify(fenw_odd, n - a[i] - 1, odd);
		}
	}
	auto check = [&](int x, int need)
	{
		if(need < 0) return false;
		if(need & 1)
		{
			return query(fenw_odd, n - x - 1) >= need;
		}
		else
		{
			return query(fenw_even, n - x - 1) >= need;
		}
	};
	auto valid = [&](int max0, int max1, int diff, int q)
	{
		return check(max0, q - diff) || check(max1, q + diff);
	};
	int max0 = 0, max1 = 0;
	if(!check(0, q))
	{
		puts("-1");
		return 0;
	}
	int diff = 0;
	for(int i = 0; i < n; ++i)
	{
		if(b[i]) --q;
		while(memory.size() > size[i])
		{
			* memory.top().first = memory.top().second;
			memory.pop();
		}
		if(max0 <= a[i])
		{
			if(valid(a[i], max1, diff + 1, q))
			{
				cout << 0;
				max0 = a[i];
				++diff;
			}
			else
			{
				cout << 1;
				if(max1 <= a[i])
				{
					max1 = a[i];
					--diff;
				}
			}
		}
		else
		{
			if(valid(max0, max1, diff, q))
			{
				cout << 0;
			}
			else
			{
				cout << 1;
				if(max1 <= a[i])
				{
					max1 = a[i];
					--diff;
				}
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 33796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807
//https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_D
//区間加算　区間和クエリ
//演算の定義
auto query = [](ll x, ll y) { return x+y; };
//単位元
const ll unit = 0;
struct LazySegTree
{
private:
  ll n;
  vector<ll> node,lazy;

public:
  LazySegTree(vector<ll> v)
  {
    node.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1, unit); 
    lazy.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1,-1); 
    n = 1LL << 64 - __builtin_clzll(v.size());
    for (ll i = 0; i < v.size(); i++)
      node[i + n - 1] = v[i]; //最下段から構築
    for (ll i = n - 2; i >= 0; i--)
      node[i] = query(node[2 * i + 1], node[2 * i + 2]);
  }
  
  // k 番目のノードについて遅延評価を行う
  void eval(int k, int l, int r){ 
    // 遅延配列が空でない場合、自ノード及び子ノードへの
    // 値の伝播が起こる
    if (lazy[k] != -1){
      node[k] = lazy[k];
      // 最下段かどうかのチェックをしよう
      // 子ノードは親ノードの 1/2 の範囲であるため、
      // 伝播させるときは半分にする
      if (r - l > 1){
        lazy[2 * k + 1] = lazy[k] / 2;
        lazy[2 * k + 2] = lazy[k] / 2;
      }
      // 伝播が終わったので、自ノードの遅延配列を空にする
      lazy[k] = -1;
    }
  }

  void update(int a, int b, ll x, int k = 0, int l = 0, int r = -1){
    if (r < 0)
      r = n;
    // k 番目のノードに対して遅延評価を行う
    eval(k, l, r);
    // 範囲外なら何もしない
    if (b <= l || r <= a)
      return;
    // 完全に被覆しているならば、遅延配列に値を入れた後に評価
    if (a <= l && r <= b){
      lazy[k]= (r - l) * x;
      eval(k, l, r);
    }
    // そうでないならば、子ノードの値を再帰的に計算して、
    // 計算済みの値をもらってくる
    else{
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = node[2 * k + 1] + node[2 * k + 2];
    }
  }

  // 要求区間 [a, b) 中の要素の和を答える k := 自分がいるノードのインデックス 対象区間は [l, r) にあたる
  ll get(ll a, ll b, ll k = 0, ll l = 0, ll r = -1)
  {
    // 最初に呼び出されたときの対象区間は [0, n)
    if (r < 0)
      r = n;
    // 要求区間と対象区間が交わらない -> 適当に返す
    if (r <= a || b <= l)
      return unit;
    // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
    // 関数が呼び出されたら評価！
    eval(k, l, r);
    if (a <= l && r <= b)
      return node[k];
    // 要求区間が対象区間の一部を被覆 -> 子について探索を行う
    // 左側の子を vl ・ 右側の子を vr としている
    // 新しい対象区間は、現在の対象区間を半分に割ったもの
    ll vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
    return query(vl, vr);
  }
};

int main()
{
ll n , q ;
cin >> n >> q ;

vector<ll> t(n,(1LL<<31)-1);
LazySegTree s(t);
vector<ll> ans;
rep(i,q){
  ll a  ;
  cin >> a  ;
  if(!a){
    ll b , c , d ;
    cin >> b >> c >> d ;
    s.update(b, c+1, d);
  }
  else {
    ll b ;
    cin >> b ;
    ans.push_back(s.get(b, b+1));
  }
}

rep(i,ans.size())cout<<ans[i]<<"\n";

return 0;
}



Measured memory_bytes: 9372
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
 
int main()
{
long double A;
  cin >> A;
  long double B;
  cin >> B;
  if(A>B){
  cout << "GREATER" ;
  }
    if(A==B){
  cout << "EQUAL" ;
  }
    if(A<B){
  cout << "LESS" ;
  }
    return 0;
}

Measured memory_bytes: 256
N, C, K =map(int, input().split())
T = [int(input()) for i in range(N)]
T.sort()

Bus, Cap = 1, 1
Lim = T[0]+K
for i in range(N-1):
    if T[i+1] <= Lim:
        if Cap < C:
            Cap += 1
        else:
            Bus += 1
            Cap = 1
            Lim = T[i+1] + K
    else:
        Bus += 1
        Cap = 1
        Lim = T[i+1] + K
print(Bus)

Measured memory_bytes: 7384
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    for a in A:
        if a % 2 == 0 and (a % 3 != 0 and a % 5 != 0):
            print("DENIED")
            return
    print("APPROVED")

if __name__ == '__main__':
    main()

Measured memory_bytes: 66028
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/foreach.hpp>
using namespace std;

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

	int tmp,i=0;
	vector<int> cards;
	while(cin >> tmp){
		cards.push_back(tmp);
		i++;
		if(i>=n){
			break;
		}
	}
	i=1;
	int a=0,b=0;
	sort(cards.begin(),cards.end());
	BOOST_FOREACH(int card,cards){
		if(i%2 == 0){
			a += card;
		}
		else {
			b += card;
		}
		i++;
	}
	cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Control.Monad (replicateM)

main :: IO ()
main = do
  n <- readLn
  [d, x] <- map read <$> words <$> getLine
  solve d x <$> replicateM n (read <$> getLine) >>= print

solve :: Int -> Int -> [Int] -> Int
solve d x as = x + (sum $ map f as)
  where
    f a = (d - 1) `div` a + 1


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
string str,str1;
int n,ans;
int main(){

    cin >> str >> n;
    for(int i=0;i<n;i++){
        cin >> str1;
        str1=str1+str1;
        if(str1.find(str)!=-1)ans++;
    }
    cout << ans << endl;

return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u==s)cout<<a-1<<" "<<b;
    else if(u==t)cout<<a<<" "<<b-1;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    string s="",p="";
    for(int i=0;i<n;i++)
    s+=m+'0';
    for(int i=0;i<m;i++)
    p+=n+'0';
    if(s<p)
    cout<<s;
    else
    cout<<p;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class E
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (H, N) = Scanner.Scan<int, int>();
            var A = new int[N];
            var B = new int[N];
            for (var i = 0; i < N; i++)
            {
                (A[i], B[i]) = Scanner.Scan<int, int>();
            }

            var dp = Enumerable.Repeat((int)1e9, H + 1).ToArray();
            dp[0] = 0;
            for (var i = 0; i < H; i++)
            {
                for (var j = 0; j < N; j++)
                {
                    var h = Math.Min(H, i + A[j]);
                    dp[h] = Math.Min(dp[h], dp[i] + B[j]);
                }
            }
            Console.WriteLine(dp[H]);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 28276
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int S = intArray[0];
            int W = intArray[1];
            if(S <= W)
            {
                Console.WriteLine("unsafe");
            }
            else
            {
                Console.WriteLine("safe");
            }
        }
    }
}

//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 28108
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define lb(x) (x & -x)
#define N (500005)

using namespace std;

struct data{ int l,r,len; }q[N];

int c[N],n,m;

il int gi(){
  RG int x=0,q=1; RG char ch=getchar();
  while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
  if (ch=='-') q=-1,ch=getchar();
  while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
  return q*x;
}

il int cmp(const data &a,const data &b){ return a.len<b.len; }

il void add(RG int x,RG int v){
  for (;x<=m;x+=lb(x)) c[x]+=v; return;
}

il int query(RG int x){
  RG int res=0; for (;x;x^=lb(x)) res+=c[x]; return res;
}

int main(){
  n=gi(),m=gi();
  for (RG int i=1;i<=n;++i) q[i].l=gi(),q[i].r=gi(),q[i].len=q[i].r-q[i].l+1;
  sort(q+1,q+n+1,cmp);
  for (RG int i=1,pos=0,ans;i<=m;++i){
    while (pos<n && q[pos+1].len<i) add(q[++pos].l,1),add(q[pos].r+1,-1);
    ans=n-pos; for (RG int j=i;j<=m;j+=i) ans+=query(j); printf("%d\n",ans);
  }
  return 0;
}


Measured memory_bytes: 5504
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int a[111];
int main()
{
	int sum=0;
	int n; cin>>n;
	for (int i=1; i<=n; i++) 
	{
		cin>>a[i]; sum+=a[i];
	}
	
	int ans=sum;
	int res=0;
	for (int i=1; i<=n; i++)
	{
		res+=a[i];
		ans=min(ans,abs(sum-2*res));
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yn(int o){
    if (o == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int main() {
    int a, b, c; cin >> a >> b >> c;
    vector<bool> ar(1000,false);
    int ans = 0;
    ar[a] = true;
    ar[b] = true;
    ar[c] = true;
    rep(i,1000) if (ar[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;


int main(){
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n) {
        cin >> a.at(i);
        if (i==0) b.at(i)=a.at(i);
        else b.at(i)=b.at(i-1)+a.at(i);
        }
    int k=1,kk=1;
    ll ans=INF;
    ll t,tt;
    for (int i=1;i<n-2;i++){
        while (true){
           t=abs(b.at(k-1)-(b.at(i)-b.at(k-1)));
           if (t<abs(b.at(k)-(b.at(i)-b.at(k)))) break;
           k++;   
        }
        while (true){
            tt=abs(b.at(i+kk)-b.at(i)-(b.at(n-1)-b.at(i+kk)));
            if (tt<abs(b.at(i+kk+1)-b.at(i)-(b.at(n-1)-b.at(i+kk+1)))) break;
            kk++;
        }
        ll p=max(b.at(k-1),(b.at(i)-b.at(k-1)));
        p=max(p,b.at(i+kk)-b.at(i));
        p=max(p,b.at(n-1)-b.at(i+kk));
        ll q=min(b.at(k-1),(b.at(i)-b.at(k-1)));
        q=min(q,b.at(i+kk)-b.at(i));
        q=min(q,b.at(n-1)-b.at(i+kk));
        ans=min(ans,p-q);
        //cout << k << " " << kk << " " << ans << endl;
        kk--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}

#[allow(unused_imports)]
use std::io::{stdout, Write};
#[allow(unused_imports)]
use std::collections::HashMap;
fn gcd(mut x: u64, mut y: u64) -> u64 {
    let mut z = x;
    let mut gcd_num = x;
    while z != 0 {
        gcd_num = z;
        z = y % x;
        y = x;
        x = z;
    }
    gcd_num
}
fn main() {
    let (a, b, n) = read_three::<i64>();
    if n >= b - 1 {
        println!("{}", (a * (b - 1) / b) as i64 - a * ((b - 1) / b) as i64);
    } else {
        println!("{}", (a * n / b) as i64 - a * (n / b) as i64);
    }

}


Measured memory_bytes: 2152
#include<bits/stdc++.h>
using namespace std;
long gcd(long a,long b){
    if(a < b)swap(a,b);
    if(a%b == 0)return b;
    else return gcd(b,a%b);
}

long lcm(long a,long b){
    return a*b/gcd(a,b);
}

int main(){
    long n,m;
    cin >> n >> m;
    string s,t;
    cin >> s >> t;
    long lcmm = lcm(n,m);
    long gcdd = gcd(n,m);
    bool chk = true;
    long a = lcmm/n;
    long b = lcmm/m;
    
    for(int i=0;i<gcdd;i++){
        if(s[i*b] != t[i*a])chk = false;
    }

    if(!chk)lcmm = -1;
    cout << lcmm << endl;
    
}


Measured memory_bytes: 512