akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		TreeMap<String, ArrayList<Integer>> paged = new TreeMap<String, ArrayList<Integer>>();
		while (sc.hasNext()) {
			String line = sc.nextLine();
			String[] data = line.split(" ");
			
			if (paged.containsKey(data[0])) {
				paged.get(data[0]).add(Integer.parseInt(data[1]));
			} else {
				ArrayList<Integer> al = new ArrayList<Integer>();
				al.add(Integer.parseInt(data[1]));
				
				paged.put(data[0], al);
			}
		}
		
		for (String key : paged.keySet()) {
			System.out.println(key);
			
			ArrayList<Integer> al = paged.get(key);
			Collections.sort(al);
			for (int i = 0; i < al.size(); i++) {
				System.out.print(al.get(i));
				if (i < (al.size() - 1)) System.out.print(" ");
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26144
S = input()

L = [0] * 4

for s in S:
  if s == "N":
    L[0] = 1
  elif s == "S":
    L[1] = 1
  elif s == "E":
    L[2] = 1
  elif s == "W":
    L[3] = 1

if L[0] == L[1] and L[2] == L[3]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 61740
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long fac[200020], finv[200020], inv[200020];
long long mod = 1000000007;
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 200020; 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(long long n, long long 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() {
    COMinit();
    long long s;
    cin >> s;
    long long ans = 0;
    for (long long i = 1; i <= s / 3; i++) {
        long long m = s - i * 3;
        ans += COM(i + m - 1, m);
        ans %= 1000000007;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n;cin>>n;
	ll b[n-1];
	for(int i=0;i<n-1;i++){cin>>b[i];}
	if(n==2){cout<<2*b[0];return;}
	int ans=b[0];
	for(int i=1;i<n-1;i++){
		ans+=min(b[i],b[i-1]);
	}
	ans+=b[n-2];
	cout<<ans;
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}

Measured memory_bytes: 3668
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int H,W; cin >> H >> W;
    int dist[1005][1005];
    Fill(dist, -1);
    char field[1005][1005];
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};

    queue<pair<int,int>> que;

    rep(i,0,H){
        rep(j,0,W){
            cin >> field[i][j];
            if(field[i][j] == '#'){
                dist[i][j] = 0;
                que.push({i,j});
            }
        }
    }

    while(!que.empty()){
        auto v = que.front();
        que.pop();
        rep(t,0,4){
            int nx = v.first + dx[t];
            int ny = v.second + dy[t];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W){
                if(field[nx][ny] == '.'){
                    field[nx][ny] = '#';
                    dist[nx][ny] = dist[v.first][v.second] + 1;
                    que.push({nx,ny});
                }
            }
        }
    }

    int ans = 0;
    rep(i,0,H){
        rep(j,0,W){
            chmax(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long n,m;
int main()
{
    cin>>n>>m;
    if (n<m)
        swap(n,m);
    if (n-m>=2)
        return 0*puts("0");
    long long res=1;
    for (long long i=1;i<=n;++i)
        res=res*i%mod;
    for (long long i=1;i<=m;++i)
        res=res*i%mod;
    if (n==m)
        res=res*2%mod;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*"lcm"   MIN*/                      int lcm(ll a,ll b){return a*b/gcd(a,b);}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >>a.at(i);
    }
    ll ans = 10e17;
    for(int i=0;i<101;i++){
        ll che = 0;
        for(int j=0;j<n;j++){
            che+=pow(a.at(j)-i,2);
        }
        ans = min(ans,che);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    string n; ll k; cin >> n >> k;
    set<char> digit = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    rep(i, k){
        char a; cin >> a;
        digit.erase(a);
    }

    ll n_max = -1, d_max = (*digit.rbegin())-'0';
    rep(i, n.size()) chmax(n_max, (ll)(n[i]-'0'));

    // nと同じ桁数で表せる
    if(n_max <= d_max){
        bool exceed = false;
        rep(i, n.size()){
            if(!exceed){
                auto it = digit.lower_bound(n[i]);
                cout << *it;
                if(*it-'0' > n[i]-'0') exceed = true;
            }
            else cout << *digit.begin();
        }
        cout << endl;
    }
    // nと同じ桁数で表せない
    else{
        // 0を除く最も小さな数字1つと0を含む最も小さな数字n個を出力
        auto it = digit.begin();
        if(*it == '0'){ it++; cout << *it << string(n.size(), *digit.begin()) << endl; }
        else cout << string(n.size()+1, *digit.begin()) << endl;
    }
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    double ans = 0;
    int n;cin >> n;
    inc(i, 0, n){
        double x;string u;
        cin >> x >> u;
        if(u == "JPY"){
            ans += x;
        }else{
            ans += x*380000.;
        }
    }
    printf("%.8lf\n", ans);
    return 0;
}


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

long long mod_inv(long long a, long long m){
    long long b = m, u = 1, v = 0;
    while(b){
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll ans;

    ll sum1 = 0;
    rep(i, N){
        sum1 = (sum1 + A[i]) % MOD;
    }

    ll sum2 = 0;
    rep(i, N){
        sum2 = (sum2 + A[i] * A[i]) % MOD;
    }

    ans = (sum1 * sum1 - sum2) % MOD;
    ans = ans * mod_inv(2, MOD);
    ans = ans % MOD;

    if(ans < 0) ans += MOD;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4840
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) x.size()
#define int ll
 
using namespace std;
 
const int N = (int)2e6 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
int a[N], b[N], n;
bool prime[N];
ll binpow (int x, int y) {
	if (y == 0) return 1;
	if (y % 2 == 0) {
		int o = binpow (x, y / 2);
		return (o * o) % mod;
	}
	else {       	
		int o = binpow (x, y - 1) * x;
		o %= mod;
		return o;
	}
}
void solve () {
	cin >> n;
	for (int i = 2; i <= (int)1e6; i ++) {
		if (!prime[i]) {
			for (int j = i * i; j <= (int)1e6; j += i) {
				prime[j] = 1;
			}	
		}
	}
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];	
		int x = a[i];
		for (int j = 2; j <= sqrt (x); j ++) {
			if (!prime[j]) {
		        int kol = 0;
				while (x % j == 0) {
					kol ++;
					x /= j;			
				}
				if (kol > b[j]) b[j] = kol;
			}	
		}        
		if (x > 1) {
			if (b[x] == 0) b[x] = 1;
		}
	}
	ll ans = 0;
	ll sum = 1;
	for (int i = 2; i <= (int)1e6; i ++) {
		sum *= binpow (i, b[i]);
		sum %= mod;
	}         
	ll just = sum;
	for (int i = 1; i <= n; i ++) {
		int x = a[i];
		sum = just;
		for (int j = 2; j <= sqrt (x); j ++) {
			if (!prime[j]) {
		        int kol = 0;
				while (x % j == 0) {
					kol ++;
					x /= j;			
				}
				sum *= binpow (binpow (j, kol), mod - 2);
				sum %= mod;
			}	                 
		}
		if (x > 1) {
			sum *= binpow (x, mod - 2);
			sum %= mod;
		}    
		ans += sum;
		ans %= mod;
	}		
	cout << ans;
}

 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//  cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 11520
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
        return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
        return readInts()[0];
}
auto readLongs() {
        return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
        return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

long next(long s) {
    return (s*s/100)%10000;
}

void main(){
    auto d = readLong();
    foreach(i; iota(d)) {
        auto s = readLong();
        writeln("Case ", i+1, ":");
        foreach(h; iota(10)) {
            s = next(s);
            writeln(s);
        }
    }
}

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

int main(){
    int n;
    cin >> n;
    int tmp = n;
    int sum = 0;
    for(int i = 1; i < 11; i++){
        sum += n % 10;
        n = n / 10;
    }
    if(tmp % sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from collections import deque

N,C,K = map(int,input().split())
T = [0 for i in range(N)]

for i in range(N):
  T[i] = int(input())

T = sorted(T)
con = 0
bus = deque()

for i in range(N):
  t = T[i]
  #バスに乗れるなら乗せる
  ##乗客が0人の時は問答無用で乗れる
  ##乗客がいる場合、最初の乗客が乗った時間から経過時間がK未満
  ##なおかつ、乗客がC人未満なら乗れる
  if len(bus) == 0 or (t - bus[0] <= K and len(bus) < C):
    bus.append(t)
  else:
    bus = deque()
    con += 1
    bus.append(t)
    
if len(bus) > 0:
  con += 1
  
print(con)

Measured memory_bytes: 8500
#include <iostream>

using namespace std;

int main(int argc, const char *argv[])
{
  unsigned long long h;
  cin >> h;

  unsigned long long cnt = 0;
  while (h != 0) {
    h /= 2;
    cnt++;
  }

  unsigned long long pow2 = 1;
  unsigned long long ans = 0;
  for (int i = 0; i < cnt; i++) {
    ans += pow2;
    pow2 *= 2;
  }
  

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<pair<int, int> > a(n);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a[i] = {x, i + 1};
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		cout << a[i].second << " ";
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll a[7];
    for(int i = 0; i < 7; i++) cin >> a[i];
    ll ans = (a[0] / 2) * 2 + a[1] + (a[3] / 2) * 2 + (a[4] / 2) * 2;
    if(a[0] % 2 == 1 && a[3] % 2 == 1 && a[4] % 2 == 1) ans += 3;
    else if(a[0] % 2 == 1 && a[3] % 2 == 1 && a[4] >= 2) ans++;
    else if(a[0] % 2 == 1 && a[4] % 2 == 1 && a[3] >= 2) ans++;
    else if(a[4] % 2 == 1 && a[3] % 2 == 1 && a[0] >= 2) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define ll long long
#define umap unordered_map
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up
ll M=1e9+7;
int quick_pow(int x,int p){
    int a=1,po=x;
    while(p){
        if(p&1)  a=1ll*a*po%M;
        po=1ll*po*po%M;p>>=1;
    }
    return a;
}
//Start from Here
int main(){
    int N, Q;
    cin>>N;
    string S;
    cin>>S;
    set<int> T[26];
    rep(i, N){
        T[S.at(i)-'a'].insert(i);
    }
    rep(i, 26){
        T[i].insert(1e9);
    }
    cin>>Q;
    int t, i, l, r;
    char c;
    int cnt;
    rep(k, Q){
        cin>>t;
        if(t==1){
            cin>>i>>c;
            i--;
            T[S.at(i)-'a'].erase(i);
            T[c-'a'].insert(i);
            S.at(i)=c;
        }else{
            cin>>l>>r;
            cnt=0;
            rep(j, 26){
                auto itr1=T[j].lower_bound(l-1);
                if(*itr1<=r-1){
                    cnt++;
                }

            }
            cout<<cnt<<endl;
        }
    }
}


Measured memory_bytes: 24196
#include <iostream>
#include <string>
#include <vector>

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

int main(){
    string s;
    cin >> s;
    REP(c, 28){
        vector<ll> p;
        REP(j, s.size()){
            if(s.at(j) == (char)c + 'a'){
                p.push_back(j);
            }
        }
        for(ll j = 0; j + 1 < p.size(); ++j){
            if(p.at(j + 1) - p.at(j) < 3){
                cout << p.at(j) + 1 << ' ' << p.at(j + 1) + 1 << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << endl;
    return 0;
}


Measured memory_bytes: 1192
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int N;
int A[MAX_N];
int B[MAX_N];

int main(void)
{
  cin >> N;
  REP(i, N - 1) cin >> B[i];

  A[0] = B[0];
  for (int i = 1; i < N - 1; i++) {
    A[i] = min(B[i], B[i - 1]);
  }
  A[N - 1] = B[N - 2];
  int ans = 0;
  for (int i = 0; i < N; i++) ans += A[i];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

char T[200001] = {0};
char ans[200001] = {0};
int main()
{
	scanf("%s", T);
	int i = 0;
	int len = strlen(T);
	strncpy(ans, T, len);
	for (i = len-1; i >= 0; i--) {
		if (ans[i] == 'P') {
			//
		} else if (ans[i] == 'D') {
			//
		} else {
			ans[i] = 'D';
		}
	}


	printf("%s\n", ans);
	//yesno(ans);
	//okng(ans);
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

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

	int N;
	cin >> N;

	int p[N];
	rep(i, N)
		cin >> p[i];

	string ans = "YES";
	int cnt = 0;
	rep(i, N) {
		if (i+1 != p[i]) {
			cnt++;
			if (i+1 != p[p[i]-1] || cnt > 2) {
				ans = "NO";
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef pair<string,int> psi;
typedef queue<psi> qpsi;

int main() {

    
    int n, qt;
    cin >> n >> qt;
    
    qpsi q;
    
    for (int i = 0; i < n; i++) {
        string nmi;
        int ti;
        cin >> nmi >> ti;
        q.push(psi(nmi, ti));
    }
    
    int t = 0;
    
    while (! q.empty()) {
        psi u = q.front(); q.pop();//先頭を取り出す
        
        string &un = u.first;
        int &ut = u.second;
        
        if (ut <= qt) {
            t += ut;
            cout << un << ' ' << t << endl;
        }
        else {
            t += qt;
            ut -= qt;
            q.push(u);//制限時間に収まらなかった場合、処理した時間を引いた上で、一番後ろに戻す
        }
    }
    
    return 0;
}



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

int main() {
    int N, M;
    cin >> N >> M;
    vector <string> A(N);
    vector <string> B(M);
    bool isMatch;
    for (int i=0; i<N; i++) cin >> A.at(i);
    for (int i=0; i<M; i++) cin >> B.at(i);
    for (int i=0; i<=N-M; i++) {
        for (int j=0; j<=N-M; j++) {
            isMatch = true;
            for (int k=0; k<M; k++) {
                for (int l=0; l<M; l++) {
                    if (A.at(i+k).at(j+l) != B.at(k).at(l)) {
                        isMatch = false;
                    }
                }
            }
            if (isMatch) {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define ll long long
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}


ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

bool cnt[30];
int main(){
  string S; cin >> S;
  for(int i = 0; i < S.size(); i++){
    cnt[S[i] - 'a'] ^= 1;
  }
  bool l = 1;
  for(int i = 0; i < 30; i++) l &= !cnt[i];
  if(l) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
	int n,a,b,c;
	cin>>n>>a>>b>>c;
	cout<<(n-(a+b-c))<<endl;
}


Measured memory_bytes: 3108
import java.util.*;
public class Main {
	int[] use;
	int[][][] go,back;
	int hh,mm,ss,n,count;
	String str1,str2;
	String[] t1,t2;
	Scanner stdin=new Scanner (System.in);
	
	
	void Solve(){
		while(true){
			n=stdin.nextInt();
			if(n==0) break;
			
			use=new int[3600*24];
			go=new int[24][60][60];
			back=new int[24][60][60];
			
			for(int i=0;i<n;i++){
				str1=stdin.next();
				t1=str1.split(":");
				str2=stdin.next();
				t2=str2.split(":");
				
	
				go[Integer.parseInt(t1[0])][Integer.parseInt(t1[1])][Integer.parseInt(t1[2])]++;
				back[Integer.parseInt(t2[0])][Integer.parseInt(t2[1])][Integer.parseInt(t2[2])]++;				
				
			}
			
			for(int i=0;i<24;i++){
				for(int j=0;j<60;j++){
					for(int k=0;k<60;k++){
						int r=3600*i+60*j+k;
						if(r==0) use[r]=go[i][j][k];
						else use[r]=use[r-1]+go[i][j][k]-back[i][j][k];
						
					}
				}
			}
			
			Arrays.sort(use);
			System.out.println(use[use.length-1]);
			
		}
		
		
		
		
		
	}
	public static void main(String args[]){
		
		Main m=new Main();
		m.Solve();
	}
	
	
	
}

Measured memory_bytes: 113804
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  int sum = accumulate(A.begin(), A.end(), 0);
  int num = 0; // 選べる商品の個数
  for (int i=0; i<N; i++) {
    if ((double)sum/(4*M)<=A[i]) num++;
  }
  if (M<=num) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,k;cin>>n>>k;
  int l[n];for(int i=0;i<n;i++)cin>>l[i];
  sort(l, l+n, greater<int>());
  int sum =0;
  for(int i=0; i<k; i++){
    sum+=l[i];
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
# coding: utf-8

l = (("A","T"),("G","C"))
i = input()
if i in l[0]:
    if i == l[0][0]:
        print(l[0][1])
    else: print(l[0][0])
else:
    if i == l[1][0]:
        print(l[1][1])
    else: print(l[1][0])


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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;
  vector<ll> v(N);
  for(int i = 0; i < N; i++){
    cin >> v.at(i);
  }

  vector<ll> left(N), right(N);
  left[0] = abs(v[0]);
  right[N-1] = abs(v[N-1]);

  for(int i = 1; i < N; i++){
    left[i] = abs(v[i] - v[i-1]) + left[i-1];
  }
  for(int i = N-2; i >= 0; i--){
    right[i] = abs(v[i] - v[i+1]) + right[i+1];
  }

  ll ans = 0;
  for(int i = 0; i < N; i++){
    if(i == 0){
      ans = right[1] + abs(v[1]);
    } else if(i == N-1){
      ans = left[N-2] + abs(v[N-2]);
    } else { 
      ans = left[i-1] + abs(v[i+1] - v[i-1]) + right[i+1];
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3584
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let () =
  let n = Scanf.scanf "%d\n" (fun x -> x) in
  let lst = Array.to_list
      (Array.init n (fun _ -> Scanf.scanf "%d " (fun x -> x))) in
  let head = List.hd lst in
  let tail = List.tl lst in
  Printf.printf "%d\n" (List.fold_left gcd head tail)

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> sum(100010,0);
	rep(i,n){
		int l,r;
		cin>>l>>r;
		r++;
		sum[l]++;
		sum[r]--;
	}
	int ans=0;
	rep(i,100010){
		sum[i+1]+=sum[i];
		if(sum[i+1]) ans++;
	}
	cout<<ans<<endl;
}

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

typedef vector<int> vi;

vi pset;

void init(int n)
{
    pset = vi(n, 0);
    iota(pset.begin(), pset.end(), 0);
}

int findSet(int i) { return pset[i] == i? i : (pset[i] = findSet(pset[i])); }

int isSameSet(int i, int j) { return findSet(i) == findSet(j); }

void unionSet(int i, int j) 
{ 
    if(!isSameSet(i,j)) 
    {
        int pi = findSet(i);
        int pj = findSet(j);
        pset[pi] = pj;
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n,m,x,y;
    vi v;
    while(cin >> n >> m)
    {
        v = vi(n+1);
        for(int i = 1; i <= n; i++)
            cin >> v[i];
        init(n+1);
        for(int i = 0; i < m; i++)
        {
            cin >> x >> y; 
            unionSet(x,y);
        }
        int ans = 0;
        for(int i = 1; i <= n; i++)
            if(i == v[i] || findSet(v[i]) == findSet(i))
                ans++;
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200005;
int n,a[N],to[N],b[N],c[N];
int cmp(int x,int y){
	return a[x]<a[y];
}
signed main(){
	scanf("%lld",&n);
	int sum1=0,sum2=0;
	for (int i=0;i<n;i++)scanf("%lld%lld",&a[i],&a[i+n]),sum1+=a[i],sum2+=a[i+n];
	if (n==2){
		printf("%lld\n",min(a[0],a[3])+min(a[1],a[2]));
		return 0; 
	}
	int ans=min(sum1,sum2);
	for (int i=0;i<2*n;i++)b[i]=i;
	sort(b,b+2*n,cmp);
	c[0]=a[b[0]];
	for (int i=1;i<2*n;i++)c[i]=a[b[i]]+c[i-1];
	for (int i=0;i<2*n;i++)to[b[i]]=i;
	for (int i=0;i<n;i++){
		int now=n-3,v=a[i]+a[i+n];
		if (to[i]<=now|to[i+n]<=now){
			if (to[i]<=now+1)now++,v-=a[i];
			if (to[i+n]<=now+1)now++,v-=a[i+n];
		}
		ans=min(ans,c[now]+v);
	}
	printf("%lld\n",ans);
}

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

int a[100001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	a[0]=1;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	long long int L=2,R=2;
	if(2%a[n]!=0){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=n;i>=1;i--){
		R+=a[i]-1;
		L=(L%a[i-1]==0?L:((L/a[i-1]+1)*a[i-1]));
		R=R/a[i-1]*a[i-1];
		if(L>R){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<L<<' '<<R<<endl;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int s, hour, min, sec, rest1,rest2;
	
	scanf("%d", &s);

	if (0<=s&&0<=86400)
	{

		rest1 = s % 3600;
		hour = (s - rest1) / 3600;

		rest2 = rest1 % 60;

		min = (rest1 - rest2) / 60;

		sec = rest2;

		printf("%d:%d:%d\n", hour, min, sec);

	}
	
	return 0;
}

Measured memory_bytes: 2716
#include<iostream>
#include<algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m], v[n];
  rep (i, n) cin >> a[i];
  rep (i, m) cin >> b[i];
  rep (i, n) v[i] = 0;
  rep (i, m) rep (j, n) if (a[j] <= b[i]) {
    ++v[j];
    break;
  }
  cout << max_element(v, v + n) - v + 1 << endl;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll INF = 1LL << 60;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

vector<i_i> edges[1005][1005];
int memo[1005][1005];
bool visited[1005][1005];

int dfs(int i, int j) {
  if (memo[i][j] >= 0) return memo[i][j];
  visited[i][j] = true;

  int ret = 1;
  for (i_i p : edges[i][j]) {
    if (visited[p.first][p.second] && memo[p.first][p.second] < 0) return memo[i][j] = 999999999;
    chmax(ret, dfs(p.first, p.second) + 1);
  }

  return memo[i][j] = ret;
}

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  rep(i, 0, n) {
    i_i prev{-1, -1};
    rep(j, 0, n - 1) {
      int to;
      cin >> to;
      to--;

      if (prev.first != -1) {
        edges[prev.first][prev.second].pb({min(i, to), max(i, to)});
      }
      prev.first = min(i, to);
      prev.second = max(i, to);
    }
  }

  Fill(memo, int(-1));
  rep(i, 0, n) rep(j, 0, n) {
    if (i >= j) continue;
    dfs(i, j);
  }

  int ans = 0;
  rep(i, 0, n) rep(j, 0, n) {
    if (i >= j) continue;
    chmax(ans, memo[i][j]);
  }

  cout << (ans >= 999999999 ? -1 : ans) << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 44544
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    int ans = 0;
    for (int p = 0; p <= A; p++){
      for (int q = 0; q <= B; q++){
        for (int r = 0; r <= C; r++){
          int total = 500*p + 100*q + 50*r;
          if (total == X) ans++;
        }
      }
    }
    System.out.println(ans);
  }
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> v(N,0);
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        v[a]++;
        v[b]++;
    }

    for(int i = 0; i < N; i++) {
        cout << v[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
oruegg19 - Arundhati Bhattacharya
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mp make_pair
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const unsigned ll l=1e9+7;
const int MAX_=1005;
const ll q = 1e9;
int T;

void solve(int x)
{
  string s,t;
  cin >> s >> t;

  int n=s.size(), m = t.size();

  vector< vector<int> > dp (n, vector<int>(m));
  // int dp[n+5][m+5];

  // memset(dp,0,sizeof dp);


  for(int i=0; i<n; i++)
  {
    for(int j=0; j<m; j++)
    {
      if(!(i||j))
      {
        dp[i][j] = s[i] == t[j];
      }
      else if(i && !j)
      {
        dp[i][j] = max(int(s[i]==t[j]),dp[i-1][j]);
      }
      else if(!i && j)
      {
        dp[i][j] = max(int(s[i]==t[j]),dp[i][j-1]);
      }
      else
      {
        dp[i][j] = max((s[i] == t[j])+dp[i-1][j-1], max(dp[i-1][j],dp[i][j-1]));
      }
      // cout << dp[i][j] << " ";
    }
    // cout << endl;
  }

  int i=n-1,j=m-1;
  string ans="";

  // cout << dp[i][j] << endl;

  while(i >= 0 && j >= 0)
  {
    // cout << i << " " << j << endl;
    if(s[i] == t[j])
    {
      ans += s[i];
      i--,j--;
    }
    else
    {
      if(!(i||j))
      {
        break;
      }
      else if(i && !j)
      {
        i--;
      }
      else if(!i && j)
      {
        j--;
      }
      else
      {
        if(dp[i-1][j] > dp[i][j-1])
        {
          i--;
        }
        else
          j--;
      }
    }
  }

  reverse(ans.begin(),ans.end());
  cout << ans << endl;
  // cout << "Case #" << T-t << ": " << s << endl;

}

int main()
{
  IOS
  int t,testCases;
  testCases=1;

  while(testCases--)
  {
    t=1;
    // cin >> t; //comment this in case of singular test case
    T = t;
    while(t--)
    {
      // cout << "HERE" << endl;
      solve(t);
    }
  }
  return 0;

}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 20

ll D, G;
ll P[MAX_N] = {};
ll C[MAX_N] = {};

ll solve(ll& cur, ll ind) {
    ll ret = 0;
    if(cur >= G) { return ret; }
    if(cur + (ind+1) * 100 * P[ind] + C[ind] < G) {
        cur += (ind+1) * 100 * P[ind] + C[ind];
        return P[ind];
    }
    else {
        REP(i, P[ind]) {
            cur += (ind+1) * 100;
            ret++;
            if(cur >= G) { return ret; }
        }
        cur += C[ind];
    }
    return ret;
}

signed main()
{
    cin >> D >> G;
    REP(i, D) { cin >> P[i] >> C[i]; }

    // 解く順番
    vector<int> problems;
    REP(i, D) {
        problems.push_back(i);
    }

    ll ans = LLINF;
    do {
        ll cur = 0;
        ll cand = 0;
        REP(i, problems.size()) {
            cand += solve(cur, problems[i]);
            if(cand >= G) { break; }
        }
        ans = min(ans, cand);
    } while( next_permutation(problems.begin(), problems.end()) );

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n)-1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a)-1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using Vec = vector<T>;
template<class T> using VVec = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i-1)*10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}

struct IoSetup {
	IoSetup() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} iosetup;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

int H, W;
string S[50];

const int INF = 100000000;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

void solve() {
	queue<P> Q;
	Q.emplace(0, 0);
	VVec<int> dist(H, Vec<int>(W, INF));
	dist[0][0] = 0;
	while (!Q.empty()) {
		auto [ny, nx] = Q.front();
		Q.pop();
		rep (i, 4) {
			int y = ny + dy[i];
			int x = nx + dx[i];
			if (y < 0 || y >= H || x < 0 || x >= W || S[y][x] == '#' || dist[y][x] != INF) {
				continue;
			}
			dist[y][x] = dist[ny][nx] + 1;
			Q.emplace(y, x);
		}
	}
	int cnt = 0;
	rep (i, H) rep (j, W) if (S[i][j] == '#') cnt++;
	if (dist[H - 1][W - 1] == INF) {
		cout << -1 << endl;
	}
	else cout << H * W - cnt - dist[H - 1][W - 1] - 1 << endl;
	
	
}

int main() {
	cin >> H >> W;
	rep (i, H) cin >> S[i];
	solve();

	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <map>

using namespace std;

typedef pair<string, int> elem;

int main()
{
    map<string, int> cnt;
    map<string, int> len;

    string word;
    while (cin >> word) {
        if (cnt.count(word)) {
            cnt.at(word)++;
        } else {
            cnt.insert(elem(word, 1));
            len.insert(elem(word, word.size()));
        }
    }

    pair<string, int> mode("", 0);
    for (auto it = cnt.begin(); it != cnt.end(); it++) {
        if (it->second > mode.second) {
            mode = *it;
        }
    }

    pair<string, int> max_len("", 0);
    for (auto it = len.begin(); it != len.end(); it++) {
        if (it->second > max_len.second) {
            max_len = *it;
        }
    }

    cout << mode.first << " " << max_len.first << endl;

    return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 210000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long C(int a,int b){
	if(a<b||b<0)return 0;
	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	int f=0;
	for(int i=1;i<=a;i*=2){
		f=i;
		if(a==i){
			printf("No\n");return 0;
		}
	}
	printf("Yes\n");
	for(int i=2;i<=a-((a+1)%2);i++){
		printf("%d %d\n",1,i);
		printf("%d %d\n",i^1,a+i);
	}
	printf("%d %d\n",a+1,a+2);
	if(a%2==0){
		int t=a+1-f;
		printf("%d %d\n",f,a);
		printf("%d %d\n",t,2*a);
	}
}

Measured memory_bytes: 2176
import heapq

def dijkstra(s,g,n):
    d=[float('inf')]*n
    d[s]=0
    pq=[]
    heapq.heappush(pq,[0,s])
    while len(pq)!=0:
        t,u=heapq.heappop(pq)
        if d[u]<t:
            continue
        for v,c in g[u]:
            if d[u]+c<d[v]:
                d[v]=d[u]+c
                heapq.heappush(pq,[d[v],v])
    return d

n = int(raw_input())
g = [[] for _ in xrange(n)]
for i in xrange(n - 1):
    a, b, c = map(int, raw_input().split())
    a -= 1; b -= 1
    g[a].append([b, c])
    g[b].append([a, c])
q, k = map(int, raw_input().split())
k -= 1
dist = dijkstra(k, g, n)
for i in xrange(q):
    x, y = map(int, raw_input().split())
    x -= 1; y -= 1
    print dist[x] + dist[y]


Measured memory_bytes: 82844
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	ans := 0
	c := [19][19]int{}

	for i := 0; i < n; i++ {
		a := int(scanFloat64()*1e9 + 0.5)

		c2, c5 := 0, 0
		for a%2 == 0 && c2 < 18 {
			a /= 2
			c2++
		}
		for a%5 == 0 && c5 < 18 {
			a /= 5
			c5++
		}
		for i := 0; i < 19; i++ {
			if c2+i < 18 {
				continue
			}
			for j := 0; j < 19; j++ {
				if c5+j < 18 {
					continue
				}
				ans += c[i][j]
			}
		}

		c[c2][c5]++
	}
	fmt.Fprintln(wr, ans)

}


Measured memory_bytes: 5072