akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vp es;
    rep(_,n-1) {
        int u,v;
        cin >> u >> v;
        u--; v--;
        es.eb(u,v);
    }
    ll ans = 0;
    rep2(i,1,n+1) ans += (ll)i*(n-i+1);
    for(auto [u,v] : es) {
        if(u > v) swap(u,v);
        ans -= (ll)(u+1)*(n-v);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5320
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		String q = in.next();

		int i;
		int ret = -1;
		for (i = 0; i < s.length(); i++) {
			if (s.indexOf(q) == -1) {
				s = s.substring(1, s.length()) + s.substring(0, 1);
			} else {
				ret = s.indexOf(q);
				break;
			}
		}
		if (ret == -1) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 18064
#include <stdio.h>
int main(void){
	int n,m,i=0,j=0,a=1,b=a+1,c=b+1,count=0;

	while(1){
		scanf("%d %d",&n,&m);
		if(n == 0 && m == 0)
			break;
    		for(a=1; a<=n; a++){
        		for(b=a+1; b<=n; b++){
           			for(c=b+1; c<=n; c++){
                			if(a+b+c==m)
                  				count++;
            			}
			}
		}
		printf("%d\n",count);
		count=0;		
	}
	return 0;
}

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

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

  int cnt = 0;
  rep(i,n) {
    int a; cin >> a;
    if(a % 2 == 0) cnt++;
  }
  cout << (cnt == n ? "second" : "first") << '\n';
}



Measured memory_bytes: 3636
n = gets.to_i
a_array = gets.split(" ").map(&:to_i)

rate = Array.new(8, 0)
wild = 0
a_array.each do |a|
  if a > 0 && a < 400
    rate[0] += 1
  elsif a < 800
    rate[1] += 1
  elsif a < 1200
    rate[2] += 1
  elsif a < 1600
    rate[3] += 1
  elsif a < 2000
    rate[4] += 1
  elsif a < 2400
    rate[5] += 1
  elsif a < 2800
    rate[6] += 1
  elsif a < 3200
    rate[7] += 1
  else
    wild += 1
  end
end

min = rate.select{|r| r != 0 }.count
max = min + wild
min = 1 if min == 0
puts "#{min} #{max}"

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

int f[200];

int main(){
	int ans = 0;
	int n, k; cin >> n >> k;
	for(int i = 0; i < k; i++){
		int d; cin >> d;
		for(int j = 0; j < d; j++){
			int a; cin >> a;
			if(f[a - 1] == 0)f[a - 1] = 1;
		}
	}
	for(int i = 0; i < n; i++)if(f[i] == 0)ans++;
	cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdint.h>
#include <math.h>
using namespace std;

int main()
{
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    int result = 0;
    if( n >= k ){
        result = k * x + (n - k) * y;
    }
    else{
        result = n * x;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // int n;
    // cin >> n;
    set<int> s;
    int q, a, b, c;
    cin >> q;
    rep(i, q) {
        cin >> a >> b;
        if(a == 0) {
            s.insert(b);
            cout << s.size() << "\n";
        } else if(a == 1) {
            cout << (s.find(b) != s.end()) << "\n";
        } else if(a == 2) {
            s.erase(b);
        } else {
            cin >> c;
            auto p1 = s.equal_range(b);
            auto p2 = s.equal_range(c);

            while(p1.first != p2.second) {
                cout << *p1.first++ << "\n";
            }
        }
    }
}



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

using namespace std;

int main (void){
  int n;
  cin >> n;
  cin.ignore();

  vector <int> a;
  int tmp;

  int ni = n;
  while (ni--){
    cin >> tmp;
    a.push_back(tmp);
  }
  sort(a.begin(), a.end());
  cout << a.back() - a.front() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <array>
#include <set>
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
int main() {
    array<int, 3> a;
    scanf("%d", &a[0]);
    scanf("%d", &a[1]);
    scanf("%d", &a[2]);
    whole(sort, a);
    set<array<int, 3> > used;
    while (     a[0] % 2 == 0
            and a[1] % 2 == 0
            and a[2] % 2 == 0) {
        used.insert(a);
        ll sum = a[0] +(ll) a[1] + a[2];
        a[0] = (sum - a[0]) / 2;
        a[1] = (sum - a[1]) / 2;
        a[2] = (sum - a[2]) / 2;
        whole(sort, a);
        if (used.count(a)) break;
    }
    if (used.count(a)) {
        printf("-1\n");
    } else {
        printf("%d\n", int(used.size()));
    }
    return 0;
}


Measured memory_bytes: 256
#pragma region Include/Defines
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <queue>
#include <time.h>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef vector<pii> vpii;
typedef vector <pll> vpll;
typedef long double ld;
#define all(a) std::begin(a), std::end(a)

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

template<typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); }
template<typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); }

#ifdef _DEBUG
#define epr(...) fprintf(stderr,__VA_ARGS__)
#else
#define epr(...) 
#endif
#pragma endregion

const int MAX = 2e5 + 100;
int n, m;
set<int> g[MAX];

void clear() {
	for (int i = 0; i < MAX; i++) g[i].clear();
}

void read() {
	for (int i = 0; i < m; i++) {
		int f, t;
		scanf("%d%d", &f, &t);
		f--, t--;
		g[f].insert(t);
		g[t].insert(f);
	}
}

void solve() {
	for (int v = 1; v < n - 1; v++) {
		if (g[0].count(v) && g[n - 1].count(v)) return void(printf("POSSIBLE\n"));
	}
	printf("IMPOSSIBLE\n");
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d%d", &n, &m) == 2) {
		clear();
		read();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}

Measured memory_bytes: 28416
#undef NDEBUG
#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;
using ld = long double;

void solve(bool);

int main() {
#ifdef YA
    auto s = clock();
    assert(freopen("input.txt", "r", stdin));
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    cout << fixed << setprecision(20);

    solve(true);

#ifdef YA1
    while (true) solve(false);
#endif

#ifdef YA
    cout << endl << endl << "time = " << (clock() - s) / (double)CLOCKS_PER_SEC << endl;
#endif

    return 0;
}

void solve(bool __attribute__((unused)) read) {
    li k, a, b;
    cin >> k >> a >> b;
    li s = 1;
    li t = min(k, a - s);
    s += t;
    k -= t;
    if (b >= a + 2 && s >= a) {
        t = k / 2;
        s += (b - a) * t;
        k -= 2 * t;
    }
    s += k;
    cout << s << endl;
}

// IDI OBRATNO KOD SMOTRET, RANO POKA SUBMITIT


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define MAXN 200005
#define INT_SIZE 32
#define debug cout<<"we are debugging"<<endl;
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
const ll MAX = 2000000;
ll fac[MAX], finv[MAX], inv[MAX];
void cmbinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i=2;i<MAX;i++) {
		fac[i] = fac[i-1]*i%MOD;
		inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i] = finv[i-1]*inv[i]%MOD;
	}
}
ll cmb(ll n, ll 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()
{
     int n;
     cin>>n;
     ll x[n],y[n];
     for(int i=0;i<n;i++)
     cin>>x[i]>>y[i];
     ll val=-1e10,val2=-1e10;
     ll val1=1e10,val3=1e10;
     for(int i=0;i<n;i++)
     {
         val=max(x[i]+y[i],val);
         val1=min(x[i]+y[i],val1);
         val2=max(x[i]-y[i],val2);
         val3=min(x[i]-y[i],val3);
     }
     cout<<max(val-val1,val2-val3);

}



Measured memory_bytes: 6736
n, w = map(int, input().split())

weight = [0]*n
value = [0]*n

for i in range(n):
    weight[i], value[i] = map(int, input().split())

v_sum = sum(value)

dp = [[10**12 for _ in range(v_sum+1)] for i in range(n)]

for i in range(n):
    if i == 0:
        dp[i][0] = 0
        dp[i][value[0]] = weight[0]
    else:
        for k in range(v_sum+1):
            if k < value[i]:
                dp[i][k] = dp[i-1][k]
            else:
                dp[i][k] = min(dp[i-1][k], dp[i-1][k-value[i]]+weight[i])

for i in range(v_sum, -1, -1):
    if dp[n-1][i] <= w:
        print(i)
        exit()


Measured memory_bytes: 171528
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

int main(void)
{
	int n;
	cin >> n;
	vec<int> a(200000, 0);
	rep(i, n) {
		int get;
		cin >> get;
		a[get]++;
	}
	int ans = n;
	int i = 1;
	while(i <= 100000) {
		if (a[i] <= 1) {
			i++;
			continue;
		} else if (a[i] > 2) {
			ans -= 2;
			a[i] -= 2;
		} else {
			a[i]--;
			ans -= 2;
			i++;
			while(a[i] < 2 && i <= 100000) i++;
			a[i]--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
import itertools
#標準出力
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

#ソートした
Psotred  = sorted(P)
Qsotred  = sorted(Q)

#順列造った。
A = list(itertools.permutations(Psotred, N))
B = list(itertools.permutations(Qsotred, N))

#taple型に変更した
P_tap = tuple(P)
Q_tap = tuple(Q)

ans_P = 1
ans_Q = 1

for i in A:
    if i != P_tap:
        ans_P = ans_P +1
    elif i == P_tap:
        break

for i in B:
    if i != Q_tap:
        ans_Q = ans_Q +1
    elif i == Q_tap:
        break
        
print(abs((ans_Q)-(ans_P)))

Measured memory_bytes: 12788
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset> 
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
// RAJJI KI MEHER 
#define fio ios_base::sync_with_stdio(false)
//#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll int
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%lld",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 100000000000000005
#define MINN -10000000000000000
#define INTMAX 1000001000
#define pii pair<li,li>
#define pdd pair<double,double>
#define pic pair<int,char>
//#define N 5005
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
using namespace std;
li a[25][25];li n,n1=0,n2=0,n3=0,k,mod=1000000007;string s;
li AA[3002][3002];
li ff(li i1,li i2){if(i2<0 || i2>(n-i1)) return(0);
    if(i1==n) {//cout<<n<<" "<<i2<<endl;
        return(1);}
    if((s[i1-1]=='<' && i2==0) || (s[i1-1]=='>' && i2==(n-i1))) return(0);
    if(AA[i1][i2]!=-1) return(AA[i1][i2]);    
    li ans=0;//cout<<i2<<" "<<i<<" "<<(i2|(1<<i))<<endl;
if(s[i1-1]=='<')    ans=(ff(i1+1,i2-1)+ff(i1,i2-1))%mod;
else ans=(ff(i1,i2+1)+ff(i1+1,i2))%mod;
AA[i1][i2]=ans;return(ans);
}
int main(){readl(n);cin>>s;memset(AA,-1,sizeof(AA));li i,j;li ans=0;
for(i=0;i<n;i++){ans=(ans+ff(1,i))%mod;}
cout<<ans;
}

Measured memory_bytes: 74528
#include<bits/stdc++.h>
#define N 20
using namespace std;
int n,A[N],q,m;
bool ans;

void dfs(int x,int s){
  if(x==n||ans){
    if(s==m)ans=true;
    return;
  }
  dfs(x+1,s+A[x]);
  dfs(x+1,s);
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];
  cin>>q;
  while(q--){
    cin>>m;
    ans=0;
    dfs(0,0);
    if(ans)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
/**
 * Title:
 * Url:
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    string s; cin >> s;
    int q; cin >> q;
    bool flag = false;
    for(int i=0; i<q; i++) {
        int ti; cin >> ti;
        if(ti==1) {
            flag = !flag;
        } else {
            int fi;
            string ci;
            cin >> fi >> ci;
            if(fi==1) {
                if(flag) {
                    s.append(ci);
                } else {
                    s.insert(0, ci);
                }
            } else {
                if(flag) {
                    s.insert(0, ci);
                } else {
                    s.append(ci);
                }
            }
        }
    }
    if(flag) {
        // reverse(s.begin(), s.end());
        for(int i=s.length()-1; i>=0; i--) {
            cout << s[i];
        }
        cout << endl;
        return 0;
    }
    cout << s << endl;

    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n, r;
	int card[55];
	int a[55], b[55];
	while(cin >> n >> r, n+r){
		rep(i, n) card[i] = n-i;
		int p, c;
		for(int i=0; i< r; i++){
			rep(i, 55){ a[i] = 0; b[i] = 0;}
			cin >> p >> c;

			rep(i, p-1) a[i] = card[i];
			rep(i, c) b[i] = card[p+i-1];
			rep(i, c) card[i] = b[i];
			rep(i, p-1) card[i+c] = a[i];

		}
		cout << card[0] << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

long comb[100][100] = {};

void init_comb(){
  comb[0][0] = 1;
  comb[1][0] = 1;
  comb[1][1] = 1;
  for(int i=2;i<100;i++){
    for(int j=0;j<=i;j++){
      if(j==0 || j==i) comb[i][j] = 1;
      else comb[i][j] = comb[i-1][j-1]+comb[i-1][j];
    }
  }
}

int main(){
  init_comb();
  fix20;
  int n;
  int a,b;
  cin >> n >> a >> b;
  vector<long> data(n);
  rep(i,n) cin >> data.at(i);
  sort(data.begin(),data.end(),greater<long>());
  long comp = data.at(0);
  int id = 0;
  vector<int> cnt(n,0);
  rep(i,n){
    if(data.at(i) == comp){
      cnt.at(id)++;
    }else{
      comp = data.at(i);
      id++;
      cnt.at(id)++;
    }
  }
  double sum = 0;
  rep(i,a){
    sum += (double)data.at(i);
  }
  cout << sum / ((double)a) << endl;
  long ans = 0;
  if(cnt.at(0) > a){
    for(int i=a;i<=min(cnt.at(0),b);i++){
      ans += comb[cnt.at(0)][i];
    }
  }else{
    int tmp = a;
    rep(i,n){
      tmp -= cnt.at(i);
      if(tmp <= 0){
        cout << comb[cnt.at(i)][tmp+cnt.at(i)] << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String key = "AKIHABARA";
    int s = 0;
    int k = 0;
    boolean ans = true;
    while (k < key.length()) {
      if( s >= S.length()
         || (S.charAt(s) != key.charAt(k))) {
        if (key.charAt(k) != 'A') {
          ans = false;
          break;
        }
      } else {
        s++;
      }
      k++;
    }
    System.out.println(s == S.length() && ans ? "YES" : "NO");
  }
}

Measured memory_bytes: 21844
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: joisino&#039;s travel
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200;
const int MAX_R = 8;
const int RBITS = 1 << MAX_R;
const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

int rs[MAX_R], ds[MAX_R][MAX_R], dists[MAX_N], dp[RBITS][MAX_R];
vpii nbrs[MAX_N];

/* subroutines */

inline void setmin(int &a, int b) { if (a > b) a = b; }

/* main */

int main() {
  int n, m, r;
  scanf("%d%d%d", &n, &m, &r);
  int rbits = 1 << r;

  for (int i = 0; i < r; i++) scanf("%d", &rs[i]), rs[i]--;

  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--;
    nbrs[a].push_back(pii(b, c));
    nbrs[b].push_back(pii(a, c));
  }

  for (int st = 0; st < r; st++) {
    fill(dists, dists + n, INF);
    dists[rs[st]] = 0;
    priority_queue<pii> q;
    q.push(pii(0, rs[st]));

    while (! q.empty()) {
      pii u = q.top(); q.pop();
      int ud = -u.first, &ui = u.second;
      if (ud != dists[ui]) continue;

      vpii &nbru = nbrs[ui];
      for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
	int &vi = vit->first, vd = ud + vit->second;
	if (dists[vi] > vd) {
	  dists[vi] = vd;
	  q.push(pii(-vd, vi));
	}
      }
    }

    for (int gl = 0; gl < r; gl++) ds[st][gl] = dists[rs[gl]];
  }

  /*
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < r; j++) printf("%d ", ds[i][j]); putchar('\n');
  }
  */
  
  for (int bits = 0; bits < rbits; bits++) fill(dp[bits], dp[bits] + r, INF);
  for (int i = 0; i < r; i++) dp[1 << i][i] = 0;
  
  for (int bits = 0; bits < rbits; bits++)
    for (int i = 0; i < r; i++)
      if (dp[bits][i] < INF)
	for (int j = 0, bj = 1; j < r; j++, bj <<= 1)
	  if (! (bits & bj))
	    setmin(dp[bits | bj][j], dp[bits][i] + ds[i][j]);

  int mind = INF;
  for (int i = 0; i < r; i++) setmin(mind, dp[rbits - 1][i]);
  printf("%d\n", mind);
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
struct edge{int to,cost;};
edge e;
vector<edge>v[100001];
double ans,t,p,c;
int dis[100001],a,b,n;
bool used[100001];
void dfs(int x,int d){
	used[x]=1;
	dis[d]++;
	r(i,v[x].size())
	  if(!used[v[x][i].to]){
	  	t+=v[x][i].cost*pow(p,(double)d+1);
	  	dfs(v[x][i].to,d+1);
	  }
	 if(!d){
	 	ans=t;
	    r(i,n)ans+=t*pow(p,(double)(i))*dis[i];
	    printf("%.9f\n",ans);
	 }
}
main(){
	cin>>p>>n;
	r(i,n-1){
		cin>>a>>b>>c;
		a--;b--;
		e.to=b,e.cost=c;
		v[a].push_back(e);
		e.to=a;
		v[b].push_back(e);
	}
	dfs(0,0);
}

Measured memory_bytes: 15668
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=2005;

int n,cst;
int val[N],now[N];

inline int Ri(){
	register int r=0,c=getchar();
	while(c<'0' || '9'<c) c=getchar();
	while('0'<=c && c<='9') r=(r<<1)+(r<<3)+c-'0',c=getchar();
	return r;
}
int main(){
	n=Ri(),cst=Ri();
	for(int i=1;i<=n;i++) now[i]=val[i]=Ri();
	long long ans=-1;
	for(int r=0;r<n;r++){
		long long tot=1ll*r*cst;
		for(int i=1;i<=n;i++)
			tot+=(now[i]=min(now[i],val[i+r>n? i+r-n:i+r]));
		if(ans==-1) ans=tot;
		else ans=min(ans,tot);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int func (int n) {
    if (n == 0) {
        return 0;
    }
    return func(n-1) + n;
}

int main() 
{
    int N, K;
    cin >> N >> K;
    vector<double>P(N);
    for (int i = 0; i < N; i++) {
        cin >> P.at(i);
        double DDD = (double)func(P.at(i)) / P.at(i);
        P.at(i) = DDD;
    }
    
    queue<double> q;
    double sum = 0;
    double ans = 0;
    for (int i = 0; i < N; i++) {
        sum += P.at(i);
        q.push(P.at(i));
        if(q.size() > K){
            sum -= q.front();
            q.pop();
        }
        if (q.size() == K) {
            ans = max(ans, sum);
        }
    }
    
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

Measured memory_bytes: 3456
import scala.io.StdIn

object Main {
	def main(args: Array[String]){
		val num = StdIn.readLine.toCharArray
		val hundred = num(0)
		val ten = num(1)
		val one = num(2)

		val result =   convert(hundred).toString + convert(ten).toString + convert(one).toString
		println(result)
	}

	def convert(charNum: Char): Char ={
		if(charNum == '9') '1' else '9'
	}

}


Measured memory_bytes: 27344
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
void solve(){
	ll a, b;
	cin>>a>>b;
	int ans = 0;
	while(a<=b){
		a*=2;
		ans++;
	}
	cout<<ans<<endl;
}
	
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
  t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int l;
const int n = 20;
int m = 0;
vector<int> et[n];
vector<int> ec[n];

int main() {
	int i, j;
	
	cin >> l;
	
	int mul = 1;
	for (i = n - 2; i >= 1; i--) {
		et[i].push_back(i + 1);
		ec[i].push_back(mul);
		et[i].push_back(i + 1);
		ec[i].push_back(0);
		mul *= 2;
		m += 2;
	}
	
	int offset = 0;
	for (i = 1; i < n; i++) {
		mul = (1 << (n - 1 - i));
		while (offset + mul <= l) {
			et[0].push_back(i);
			ec[0].push_back(offset);
			offset += mul;
			m++;
		}
	}
	
	cout << n << " " << m << endl;
	for (i = 0; i < n; i++) {
		for (j = 0; j < et[i].size(); j++) {
			cout << i + 1 << " " << et[i][j] + 1 << " " << ec[i][j] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <cmath>
#include <queue>
#include <ctime>
#include <utility> // std::pair
#include <functional> // std::greater <int> ()
#define int long long
#define MAXN 500000 // check
#define inf 1000000000000000001
#define BASE 29 // hashings mod, can be rand'd
#define mod 998244353 // can be 1000000007
#define pi 3.1415926535897
#define pii pair <int, int>
#define fii first
#define see second

typedef long long ll;
typedef long double ld;
using namespace std;

int n;
int ans=0;

// functions
void input(){
	cin >> n;
	for(int i=1; i<=n; i++) ans+=i*(n-i+1);
	int u, v;
	for(int i=1; i<n; i++)
	{
		cin >> u >> v;
		if(u>v)
		{
			int tmp=u;
			u=v;
			v=tmp;
		}
		ans-=u*(n-v+1);
	}
	return;
}

void solve(){
	cout << ans;
	return;
}

void output(){
	return;
}

signed main(){
/*
//  REMEMBER TO TURN OFF IFDEF IN PROBLEMS WITH FILE I/O
*/
//#ifdef sheeep
//	freopen("forces.inp", "r", stdin);
//	freopen("forces.out", "w", stdout);
//#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
//	int t;
//	cin >> t;
//	for(int i=1; i<=t; i++){
		input();
		solve();
		output();
//	}
	return 0;
}
// Author: NamSPro

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

int main(){
	int n;
	cin>>n;
	vector<int> open(n,0);
	vector<vector<int>> price(n,vector<int>(11));
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			int p; cin>>p;
			open[i]=open[i]*2+p;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<11;j++){
			cin>>price[i][j];
		}
	}
	int ans=-1e9;
	for(int i=1;i<1024;i++){
		int val=0;
		for(int j=0;j<n;j++){
			val+=price[j][__builtin_popcount( i&open[j] )];
		}
		ans=max(val,ans);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
 
int main() {
    ios::sync_with_stdio(false);
	string s;
	cin >> s;
	for (int i = 0 ; i < s.length() ; i++) {
		if (s[i] == '9') {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}

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

int main(){

  int N,M;
  vector<int> A;
  cin >> N >> M;
  A.resize(M);
  for(int i = 0; i < M; i++){
    cin >> A[i];
    N -= A[i];
  }
  if(N < 0) N = -1;
  cout << N << endl;
  
  return 0;
}


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

int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int count=0;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(i*10+j*2+k==X/50){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a=0,b=0,c=0,d=0;
    int num;
    while(cin>>num)
    {
        int n=0;
       // int min=num/4;
        for(a=0;a<10&&a<=num;a++){
            for(b=0;b<10&&a<=num;b++){
                for(c=0;c<10&&a<=num;c++){
                    for(d=0;d<10&&a<=num;d++){
                        if(a+b+c+d==num){
                            n++;
                        }
                    }
                }
            }
        }
        cout<<n<<endl;
    }
    return 0;
}


Measured memory_bytes: 3000
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
"""
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
max_A = max(A)
bit = bin(K)
if max_A > K:
    bit = bin(max_A)"""
max_f = 0
#for d in range(1,len(bit))[::-1]:
for d in range(41,-2,-1):
    #d=d-2
    if (d != -1 and not (K & 1 << d)):
        continue
    f=0
    #for e in range(2,len(bit))[::-1]:
    for e in range(41,-1,-1):
        #e=e-2
        mask = 1<<e
        num=0
        for a in A:
            if a&mask:
                num+=1
        n_num = N - num
        if e>d:
            if K&mask:
                f += mask*n_num
            else:
                f += mask*num
        elif e==d:
            f += mask*num
        else:
            f += mask*max(n_num,num)
    max_f = max(f,max_f)
print(max_f)

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

typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> la(n);
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> la[i];
    if (la[i] > 0) ans += la[i];
  }
  ll s1 = 0, s2 = 0;
  ll b1 = -1e17, b2 = 1e17;
  for (int i = 0; i < n; ++i) {
    if (la[i] < 0) s1 += la[i];
    else s2 += la[i];
    if (i >= k) {
      if (la[i-k] < 0) s1 -= la[i-k];
      else s2 -= la[i-k];
    }
    if (i >= k-1) {
      b1 = max(b1, s1);
      b2 = min(b2, s2);
    }
    // cout << i << " " << b1 << " " << b2 << endl;
  }
  // cout << b1 << " " << b2 << endl;
  ll b = min(-b1, b2);
  ans -= b;
  cout << ans << endl;
}

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    string s;cin>>s;
    int k;cin>>k;
    set<string> st;
    for(int i=1;i<=min((int)s.length(),50);i++){
        for(int j=0;j<(int)s.length()+1-i;j++){
            st.insert(s.substr(j,i));
        }
    }
    auto itr=st.begin();
    for(int i=0;i<k-1;i++) itr++;
    cout<<*itr<<endl;
}


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

int main() {
  int x, a, b;
  cin >> x;
  
  a = x / 10; b = x % 1000;
  if(a%111 == 0 || b%111 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {


    public Main(FastScanner in, PrintWriter out) {
        long a = in.nextLong();
        long b = in.nextLong();
        long n = in.nextLong();
        long k = a / b, z = a % b;
        long y = Math.min(n, b - 1) % b;
        long res = k * y + y * z / b; 
        out.println(res);
    }

    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        // Scanner in = new Scanner(
                // new BufferedReader(new InputStreamReader(System.in)));
        FastScanner in = new FastScanner(System.in);

        Main sol = new Main(in, out);

        out.close();
    }
}


class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner(InputStream stream)
    {
        this.stream = stream;
    }

    int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

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

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}


Measured memory_bytes: 32344
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef long double ld;
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define pb push_back
#define pf push_front
#define mp map<ll,ll>
#define INF 1000000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else
    {
        return gcd(b%a,a);   
    }
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int f(char c)
{
    return (int)c-96;
}
/**********************************************************************
***********************************************************************
*********************ACTUAL CODE BEGINS HERE***************************/
int main()
{   
    fast;
    int n,x,t;
    cin>>n>>x>>t;
    if(n%x==0)
    {
        cout<<n/x*t;
    }
    else
    {
        cout<<(n/x+1)*t;   
    }
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main(){
  int a[100][100];
  int b[100][100];
  long long int c[100][100]={0};

  int n,m,l;
  cin >> n >> m >> l;
  int i;
  int j;
  for(i = 0;i < n ;i++){
    for(j = 0; j < m;j++){
      cin >> a[i][j];
    }   
  }
  for(i = 0;i < m;i++){
    for(j = 0;j < l;j++){
      cin >> b[i][j];
    }   
  }

  for(i = 0;i < n;i++){
    for( j = 0;j < l;j++){
      for(int k = 0;k < m;k++){
        c[i][j] += a[i][k]*b[k][j];
      }   
    }   
  }

  for(i = 0;i < n;i++){
    for(j = 0;j < l;j++){
      cout << c[i][j];
      if(j!=l-1){
        cout << " ";
      }   
    }   
    cout << endl;
  }
}

Measured memory_bytes: 3196
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let[a,b,c]=nrin(3)
  out(a==b&&b==c?1:a==b||a==c||b==c?2:3)
}
main()

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  int ans = 0;
  rep(i, 1, n) {
    if (a[i] == a[i - 1]) {
      a[i] = 101;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(x) begin(x),end(x)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const int inf = 2e9+9;
const int mod = 1e9+7;
ll n,ans;
ll mp[4009][9];
string s;
map < char , ll > id;
ll X(int x,int y){
    set < ll > se;
    se.insert(0);
    se.insert(1);
    se.insert(2);
    se.erase(id[s[x]]);
    se.erase(id[s[y]]);
    return *se.begin();
}
int main(){
    fast,cin>>n>>s;
    id['R'] = 0,id['G'] = 1,id['B'] = 2;
    for(int i=n-1;i>=0;i--){
        mp[i][0] = mp[i+1][0]+(id[s[i]]==0);
        mp[i][1] = mp[i+1][1]+(id[s[i]]==1);
        mp[i][2] = mp[i+1][2]+(id[s[i]]==2);
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i] == s[j]) continue;
            ans += mp[j+1][X(i,j)];
            int indx = j + (j-i);
            ans -= (indx < n && id[s[indx]] == X(i,j));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3856
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int H, W;
    scan(H, W);

    auto s = iota(H).map!(i => readln.chomp).array;

    auto dp = new int[][](H, W);
    dp[0][0] = s[0][0] == '#';

    foreach (i ; 0 .. H) {
        foreach (j ; 0 .. W) {
            if (i == 0 && j == 0) continue;
            dp[i][j] = inf;
            if (i - 1 >= 0) {
                if (s[i][j] == '#') {
                    chmin(dp[i][j], dp[i-1][j] + (s[i-1][j] == '.'));
                }
                else {
                    chmin(dp[i][j], dp[i-1][j]);
                }
            }
            if (j - 1 >= 0) {
                if (s[i][j] == '#') {
                    chmin(dp[i][j], dp[i][j-1] + (s[i][j-1] == '.'));
                }
                else {
                    chmin(dp[i][j], dp[i][j-1]);
                }
            }
        }
    }

    auto ans = dp[H-1][W-1];
    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int x = ri(), y = ri();
	int res = std::max(0, 100000 * (4 - x)) + std::max(0, 100000 * (4 - y));
	if (x == 1 && y == 1) res += 400000;
	std::cout << res << std::endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long ll;
typedef vector<long long int> vi;
typedef vector<long long int>::iterator vit;

int main(){
	int m, d, c = 0;
	bool f = 0;
	int a[13] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	while (cin >> m >> d){
		if (m == 0)break;
		for (int i = 0; i < m; i++){
			for (int j = 0; j < a[i]; j++){
				c++;
				if (i == m - 1 && j == d - 1){
					f = 1;
					break;
				}
			}
			if (f)break;
		}
		c = c % 7;
		if (c == 1){
			cout << "Thursday\n";
		}
		else if (c == 2){
			cout << "Friday\n";
		}
		else if (c == 3){
			cout << "Saturday\n";
		}
		else if (c == 4){
			cout << "Sunday\n";
		}
		else if (c == 5){
			cout << "Monday\n";
		}
		else if (c == 6){
			cout << "Tuesday\n";
		}
		else {
			cout << "Wednesday\n";
		}
		c = 0;
		f = 0;
	}
}

Measured memory_bytes: 1124
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

template <typename T, int COUNT>
class BinaryIndexedTree {
private:
	T m_data[COUNT + 1];
public:
	BinaryIndexedTree(){
		fill(m_data, m_data + COUNT + 1, T());
	}
	T sum(int i){
		T s = T();
		while(i > 0){
			s += m_data[i];
			i -= i & -i;
		}
		return s;
	}
	void add(int i, const T &x){
		while(i <= COUNT){
			m_data[i] += x;
			i += i & -i;
		}
	}
};


struct LexicalCompare {
	bool operator()(int a, int b) const {
		char abuf[16] = { 0 }, bbuf[16] = { 0 };
		int alen = 0, blen = 0;
		while(a > 0){ abuf[alen++] = '0' + (a % 10); a /= 10; }
		while(b > 0){ bbuf[blen++] = '0' + (b % 10); b /= 10; }
		reverse(abuf, abuf + alen);
		reverse(bbuf, bbuf + blen);
		for(int i = 0; i < 16; ++i){
			if(abuf[i] < bbuf[i]){ return true; }
			if(abuf[i] > bbuf[i]){ return false; }
		}
		return false;
	}
};

int main(){
	while(true){
		ll A, B, P;
		cin >> A >> B >> P;
		if(A == 0 && B == 0 && P == 0){ break; }
		vector<int> lexical_order(B - A + 1);
		for(int i = A; i <= B; ++i){ lexical_order[i - A] = i; }
		sort(lexical_order.begin(), lexical_order.end(), LexicalCompare());
		int N = lexical_order.size();
		BinaryIndexedTree<ll, 100001> bit;
		vector<ll> dp(N);
		for(int i = 0; i < N; ++i){
			dp[i] = (bit.sum(lexical_order[i] - A) + 1) % P;
			bit.add(lexical_order[i] - A + 1, dp[i]);
		}
		ll answer = accumulate(dp.begin(), dp.end(), 0ll) % P;
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 2876
// 簡易競プロテンプレ
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b, ans;
int main(void){
 cin >> a >> b;
 if ((a<0 && 0<b) || (b<0 && 0<a)){
  ans = abs(abs(a)-abs(b)) + 1;
 }else if (a==0){
  ans = abs(b) + (b<0);
 }else if (b==0){
  ans = abs(a) + (a>0);
 }else if (0<a && 0<b){
  ans = abs(a-b) + 2 * (a>b);
 }else{
  ans = abs(a-b) + 2 * (a>b);
 }
 cout << ans << endl;
 
 return 0;
}

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

ans   = 0
count = 0


for j in range(N):
    if N == 1:
       break
 
    if H[j] >= H[j+1]:
        count += 1
    else:
        ans   = max(count, ans)
        count = 0
 
    if j == N-2:
        if count > ans:
            ans   = count
        break

print(ans)


Measured memory_bytes: 14252
#include<stdio.h>
#include<string.h>

#define M 2000000
#define L 14

char H[M][L];

int getChar(char ch){
  if(ch == 'A')return 1;
  if(ch == 'C')return 2;
  if(ch == 'G')return 3;
  if(ch == 'T')return 4;
  else return 0;
}

long long getkey(char str[]){
  long long sum=0,p=1,i;
  for(i=0;i<strlen(str);i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
  return key % M;
}
int h2(int key){
  return 1 + (key % (M -1));
}

int find(char str[]){
  long long key,i,h;
  key = getkey(str);
  for(i=0;;i++){
    h = (h1(key) + i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;
}
int insert(char str[]){
  long long key,i,h;
  key=getkey(str);
  for(i=0;;i++) {
    h = (h1(key) + i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i,n,h;
  char str[L],com[9];
  for(i=0;i<M;i++)H[i][0]='\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%s",com,str);
    if(com[0]=='i'){
      insert(str);
    }
    else{
      if(find(str)){
	/*printf("\n");*/
	printf("yes\n");
      }
      else{
	/*printf("\n");*/
	printf("no\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 29100
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
multiset<int>ms;
int n, l, a[1200000];
signed main() {
	cin >> n >> l; for1(i, n) { cin >> a[i]; if (i <= l)ms.insert(a[i]); }
	cout << *(ms.begin());
	for1(i, n - l) {
		ms.insert(a[i + l]);
		ms.erase(ms.find(a[i]));
		cout << ' ' << *(ms.begin());
	}cout << endl;
}


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

using namespace std;

int n, W;
int w[110], v[110];
long long dp[110000];

int main() {
	cin >> n >> W;
	for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
	
	for (int i = 0; i < n; i++) {
		for (int j = W; j >= w[i]; j--) {
			dp[j] = max(dp[j], dp[j - w[i]] + 1ll * v[i]);
		}
	}
	
	long long ans = 0;
	for (int i = 0; i <= W; i++) ans = max(ans, dp[i]);
	cout << ans << '\n';
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&a!=c||a==c&&a!=b||b==c&&a!=b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int w, h, x, y, r;
cin >> w >> h >> x >> y >> r;
if (x-r >= 0 && x+r <= w && y+r <=h && y-r >= 0)
       cout << "Yes" << endl;
    else
       cout << "No" << endl;

return 0;
}


Measured memory_bytes: 3116