akhauriyash/Code-Regression huggingface dataset:
alphabet=[chr(i+97) for i in range(0,26)]
S=input()
if S=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    for i in S:
        alphabet.remove(i)
    if alphabet:
        print(S+alphabet[0])
    else:
        motoS=S
        S=list(S)
        poplist=[]
        stringlist=[]
        while len(S)>=2:
            poplist.append(S[-1])
            S.pop()
            for s in poplist:
                _S=[i for i in S]
                _S[-1]=s
                string=""
                for ss in _S:
                    string+=ss
                stringlist.append(string)
        stringlist.append(motoS)
        stringlist.sort()
        try:print(stringlist[stringlist.index(motoS)+1])
        except:print(stringlist[stringlist.index(motoS)])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
map<pii, int> M;
ll ans;
inline int firstd(int x)
{
	while(x >= 10) x /= 10;
	return x;
}
inline int lastd(int x)
{
	return x % 10;
}
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		++M[mp(lastd(i), firstd(i))];
	for(int i = 1; i <= n; ++i)
		ans += M[mp(firstd(i), lastd(i))];
	printf("%I64d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  string C;
  cin >> C;

  printf("%c", (C[0]+1));

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
int main()
{
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    rep2(b, 1, N + 1)
    {
        ll M = max(b - K, 0LL);

        ans += (N / b) * M + max(0LL, (N % b) - K + 1);
    }
    if (K == 0)
        ans -= N;
    cout << ans;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  map<int, int> A;
  rep(i, N){
    int a;
    cin >> a;
    A[a] += 1;
  }
  
  int count = 0;
  for (auto p: A){
    if (p.second % 2 == 1) count++;
  }
  
  cout << count << endl;
    
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

i64 com(int a, int b) {
  i64 ret = 1;
  for (int i = 1; i <= b; i++) {
    i64 j = a - i + 1;
    ret *= j;
    ret /= i;
  }
  return ret;
}

void solve() {
  int N, A, B; cin >> N >> A >> B;
  vi64 v(N); cin >> v;

  sort(all(v)), reverse(all(v));
  f80 average = 0;
  rep(i, A) average += v[i];
  average /= A;
  cout << average << '\n';

  i64 ans = 0;
  if (v[0] == v[A - 1]) {
    int cnt = 0;
    rep(i, N) if (v[i] == v[0]) cnt++;
    for (int i = A; i <= min(cnt, B); i++) {
      ans += com(cnt, i);
    }
  } else {
    int cnt = 0, cnt2 = 0;
    rep(i, N) {
      if (v[i] == v[A - 1]) cnt++;
      if (v[i] > v[A - 1]) cnt2++;
    }
    ans += com(cnt, A - cnt2);
  }
  cout << ans << '\n';
}


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

int main()
{
    int N;
    cin>>N;
    vector<long long> X(N), Y(N);
    for (int i=0; i<N; i++)
        cin>>X[i]>>Y[i];

    long long answer = 0;

    for (int r=0; r<10; r++)
    {
        for (int i=0; i<N*10; i++)
        {
            long long tx = X[i];
            long long ty = Y[i];
            for (int j=0; j<N; j++)
            {
                long long sx = 0;
                long long sy = 0;
                for (int k=0; k<N; k++)
                    if (tx*X[k]+ty*Y[k] >= 0)
                        sx += X[k],
                        sy += Y[k];
                tx = sx;
                ty = sy;
            }
            answer = max(answer, tx*tx+ty*ty);
        }
    }
    printf("%.16f\n", sqrt((double)answer));
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string X = Console.ReadLine();
        int stack = 0;
        int count = 0;
        foreach (char c in X)
        {
            switch (c)
            {
            case 'S':
                ++stack;
                break;
            case 'T':
                if (stack > 0)
                {
                    --stack;
                    count += 2;
                }
                break;
            }
        }
        Console.WriteLine(X.Length - count);
    }
}


Measured memory_bytes: 3544
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

bool cmp(pii a, pii b) { return a.first == b.first ? a.second > b.second:a.first < b.first; }

signed main() {
	for (int n, m; cin >> n >> m&&n;) {
		vector<pii> a(m, pii(0, 0));
		rep(j, 0, m)a[j].second = j + 1;
		rep(i, 0, n)rep(j, 0, m) {
			bool b; cin >> b;
			if (b)a[j].first++;
		}
		sort(all(a), cmp);
		rrep(j, 1, m)cout << a[j].second << " ";
		cout << a[0].second << endl;
	}
	return 0;
}

Measured memory_bytes: 2996
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,m,i,ans=0;cin>>n>>m;
	vector<int>wa(n);
	for(i=0;i<n;i++){wa[i]=n;}
	for(i=0;i<m;i++){int a,b;cin>>a>>b;a--;b--;mineq(wa[a],b);}
	int mg=n;
	for(i=0;i<n;i++){
		if(mg<=i){mg=n;ans++;}
		mineq(mg,wa[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    int N;
    int m1000=-1, m5000=-1, m10000=-1;
    long long Y;
    cin>> N >> Y;

    for(int i=0; i<=N; i++){
        for(int j=0; j<=N-i; j++){
            if(1000*i+5000*j+10000*(N-i-j)==Y){
                m1000=i;
                m5000=j;
                m10000=N-i-j;
            }
        }
    }

    printf("%d %d %d\n", m10000, m5000, m1000);
    return 0;
}



Measured memory_bytes: 256
import math

def calcConbination(n):
  if n == 0:
    return 0
  if n == 1:
    return 1
  else:
    return n + calcConbination(n-1)

N, M = map(int, input().split())
ans = 0
if N > 1 :
  ans += calcConbination(N-1)

if M > 1 :
  ans += calcConbination(M-1)

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    sort(all(a));
    sort(all(b));
    sort(all(c));
    // bc[i]:b[i]の下に置けるcの数
    vector<lint> bc(n);
    for (int i = 0; i < n; i++) {
        bc[i] = c.end() - upper_bound(all(c), b[i]);
    }
    // sum_b[i]:=bc[i]~bc[n-1]の和
    vector<lint> sum_b(n);
    sum_b[n - 1] = bc[n - 1];
    for (int i = n - 2; i >= 0; i--) {
        sum_b[i] = sum_b[i + 1] + bc[i];
    }
    lint ans = 0;
    for (int i = 0; i < n; i++) {
        if (upper_bound(all(b), a[i]) != b.end()) {
            ans += sum_b[upper_bound(all(b), a[i]) - b.begin()];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2944
n,m= map(int,input().split())
le = list(map(int, input().split()))

f = False
if m==1:f=True
if n>=m:f=True
#m==1だったら例外？
#n>=mのときは0
#n<mのときのみ考える
arr = [0]*(m-1)
le.sort()

if f==False:
    for i in range(0,m-1):
        arr[i]=abs(le[i]-le[i+1])
    arr.sort()
    u = n-1
    i=0
    while(u>0):
        del(arr[-1])
        u-=1

if f==False:
    print(sum(arr))

if f==True:
    print(0)


Measured memory_bytes: 13968
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const ll inf = 1LL << 60;

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

    ll n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;

    vector<vector<tuple<ll, ll, ll>>> graph(n);
    Rep (i, m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        graph[u].push_back(make_tuple(v, a, b));
        graph[v].push_back(make_tuple(u, a, b));
    }

    vector<ll> disty(n, inf);
    disty[s] = 0;

    priority_queue<pair<ll, ll>> q;
    q.push(make_pair(0, s));

    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        ll v = p.second;
        if (disty[v] < -p.first) continue;
        for (auto e : graph[v]) {
            ll next = get<0>(e);
            ll yen = get<1>(e);
            if (disty[next] > disty[v] + yen) {
                disty[next] = disty[v] + yen;
                q.push(make_pair(-disty[next], next));
            }
        }
    }

    vector<ll> dists(n, inf);
    dists[t] = 0;
    q.push(make_pair(0, t));
    while (!q.empty()) {
        auto p = q.top(); q.pop();
        ll v = p.second;
        if (dists[v] < -p.first) continue;
        for (auto e : graph[v]) {
            ll next = get<0>(e);
            ll snuke = get<2>(e);
            if (dists[next] > dists[v] + snuke) {
                dists[next] = dists[v] + snuke;
                q.push(make_pair(-dists[next], next));
            }
        }
    }

    vector<ll> dist(n);
    Rep (i, n) {
        dist[i] = disty[i] + dists[i];
    }

    // for (ll e : disty) {
    //     cout << e << endl;
    // }

    vector<ll> ans;
    reverse(dist.begin(), dist.end());
    priority_queue<ll> town;
    Rep (i, n) {
        town.push(-dist[i]);
        ll fee = town.top();
        ans.push_back(1e15 + fee);
    }

    reverse(ans.begin(), ans.end());

    for (ll e : ans) {
        cout << e << "\n";
    }
}

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

using namespace std;

int main()
{
	// 入力
	string S;
	cin >> S;
	int N = S.size();
	vector<string> S_Char(N);
	
	for (int i = 0; i < N; i++)
	{
		S_Char[i] = S.substr(i, 1);
	}
	
	
	int answer = 0;
	int strCount = 0;
	for (int i = 0; i < N; i++)
	{
		if (S_Char[i] == "A" || S_Char[i] == "C" || S_Char[i] == "G" || S_Char[i] == "T")
		{
			strCount++;
		}
		else {
			strCount = 0;
		}
		answer = max(strCount, answer);
	}
	
	// 出力
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define il inline
#define rg register
#define ldb double
#define lst long long
#define rgt register int
#define N 100050
using namespace std;
const int Inf=1e9;
il int MAX(rgt x,rgt y){return x>y?x:y;}
il int MIN(rgt x,rgt y){return x<y?x:y;}
il int read()
{
	int s=0,m=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')m=1;ch=getchar();}
	while( isdigit(ch))s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return m?-s:s;
}

int n;
lst Ans;
int v[N];
int L,R,le,ri;

int main()
{
	n=read();
	for(rgt i=1;i<=n;++i)v[i]=read();
	sort(v+1,v+n+1);
	L=v[n],R=v[n],le=1,ri=n-1;
	for(rgt i=2;i<=n;++i)
	{
		if(abs(v[le]-L)>abs(v[le]-R))
		{
			if(abs(v[ri]-L)>abs(v[ri]-R))
			{
				if(abs(v[le]-L)>abs(v[ri]-L))
					Ans+=abs(v[le]-L),L=v[le],++le;
				else Ans+=abs(v[ri]-L),L=v[ri],--ri;
			}else
			{
				if(abs(v[le]-L)>abs(v[ri]-R))
					Ans+=abs(v[le]-L),L=v[le],++le;
				else Ans+=abs(v[ri]-R),R=v[ri],--ri;
			}
		}else
		{
			if(abs(v[ri]-L)>abs(v[ri]-R))
			{
				if(abs(v[le]-R)>abs(v[ri]-L))
					Ans+=abs(v[le]-R),R=v[le],++le;
				else Ans+=abs(v[ri]-L),L=v[ri],--ri;
			}else
			{
				if(abs(v[le]-R)>abs(v[ri]-R))
					Ans+=abs(v[le]-R),R=v[le],++le;
				else Ans+=abs(v[ri]-R),R=v[ri],--ri;
			}
		}
	}printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 640
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;

ll N, A, B, C;
string str;
ll M = 0, m = 0;
ll temp = 0;
ll ans = 0;
char now;

int main()
{
	cin >> str;
	pair<ll, ll> p;
	vector<ll> v(str.length() + 1);
	now = str[0];
	for (int i = 0; i < str.length(); i++)
	{
		if (str[i] == '<')
		{
			temp++;
			v[i + 1] = max(v[i + 1], temp);
		}
		else
		{
			temp = 0;
		}
	}
	temp = 0;
	for (int i = str.length() - 1; i >= 0; i--)
	{
		if (str[i] == '>')
		{
			temp++;
			v[i] = max(v[i], temp);
		}
		else
		{
			temp = 0;
		}
	}
	for (int i = 0; i <= str.length(); i++)
	{
		ans += v[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4868
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
long long Q;
long long H;
long long S;
long long D;
long long N;
int main(){
  rd(Q);
  rd(H);
  rd(S);
  rd(D);
  rd(N);
  chmin(H, 2*Q);
  chmin(S, 2*H);
  chmin(D, 2*S);
  wt_L((N/2)*D + (N%2)*S);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// ll Q, H, S, D, N;
// {
//   rd(Q,H,S,D,N);
//   H <?= 2*Q;
//   S <?= 2*H;
//   D <?= 2*S;
//   wt((N/2)*D + (N%2)*S);
// }


Measured memory_bytes: 256
#include<iostream>
#include<deque>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<P> VP;
typedef vector<VP> VVP;
int mincost;


void NoJump(VVP &G,VVI &dp)
{
  int n= dp.size();
  rep(i,dp[0].size())dp[0][i] = 0;
  rep(i,n-1)
    {
      int m = dp[i].size();
      int o = dp[i+1].size();
      rep(j,m)
	{
	  rep(k,o)
	    {
	      int cost = (G[i+1][k].S+G[i][j].S)*abs(G[i+1][k].F-G[i][j].F);
	      dp[i+1][k] = min(dp[i+1][k],cost+dp[i][j]);
	    }	
	}
    }
  rep(i,G[n-1].size())mincost = min(mincost,dp[n-1][i]);
}

int main()
{
  int n,m;
  while(cin >> n >> m,n|m)
    {
      mincost = (1<<29);
      VVP G(n);
      rep(i,n)
	{
	  int k;
	  cin >> k;
	  rep(j,k)
	    {
	      int x,d;
	      cin >> x >> d;
	      G[i].push_back(P(x,d));
	    }
	}
    
      VVI dp(n);
      rep(i,n)dp[i].resize(G[i].size(),(1<<29));
      NoJump(G,dp);

      //First jump
      VVI prev = dp;
      if(m != 0){
	
	rep(i,G[1].size())prev[1][i] = 0;    
	rep(i,n)	
	  {
	    if(i+2 >= n)
	      {
		rep(k,G[i].size())mincost = min(mincost,dp[i][k]);
		break;
	      }
	  rep(j,G[i].size())
	    {
	      rep(k,G[i+2].size())
		{
		  int cost = (G[i][j].S+G[i+2][k].S)*abs(G[i][j].F-G[i+2][k].F);
		  prev[i+2][k] = min(prev[i+2][k],cost+dp[i][j]); 
		}
	    }
	  }
	dp = prev;
	NoJump(G,dp);
      }
      
      if(m == 1 || m == 0)goto Next;

      for(int i=1,cnt=1;cnt<m;cnt++,i+=2)
	{
	  prev = dp;
	  REP(j,i,n)
	    {
	      if(j+2 >= n)
		{
		  rep(k,G[j].size())mincost = min(mincost,dp[j][k]);
		  break;
		}
	      rep(k,G[j].size())
		{
		  rep(l,G[j+2].size())
		    {	  
		      int cost = (G[j][k].S+G[j+2][l].S)*abs(G[j][k].F-G[j+2][l].F);
		      prev[j+2][l] = min(prev[j+2][l],cost+dp[j][k]);
		    }
		}
	    }
	  dp = prev;
	  NoJump(G,dp);
	}      
     
    Next:;
    
      NoJump(G,dp);

      if(!G[n-1].empty())
	rep(i,G[n-1].size())mincost = min(mincost,dp[n-1][i]);
      else
	rep(i,G[n-2].size())mincost = min(mincost,dp[n-2][i]);
      
      cout << mincost << endl;
    }
  return 0;
}

Measured memory_bytes: 1268
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        n: usize,
        map: [(usize1, usize1, i64); n-1]
    }
    let mut graph = vec![vec![]; n];
    for &(a, b, l) in &map {
        graph[a].push((b, l));
        graph[b].push((a, l));
    }
    let mut queue = VecDeque::new();
    let mut p = vec![-1; n];
    p[0] = 0;
    queue.push_back(0);
    while let Some(x) = queue.pop_front() {
        let c = p[x];
        for &(m, l) in &graph[x] {
            if p[m] != -1 {continue;}
            let next = ((l % 2) + c) % 2;
            p[m] = next;
            queue.push_back(m);
        }
    }
    for i in p {
        println!("{}", i);
    }
}


Measured memory_bytes: 18812
#include<bits/stdc++.h>
#define MAX 100000
using namespace std;
int n,q;
int data[MAX+1];
void add(int i,int v){
  while(i<=n){
    data[i]+=v;
    i+=i&-i;
  }
}
int sum(int i){
  int res=0;
  while(i>0){
    res+=data[i];
    i-=i&-i;
  }
  return res;
}
int main(){
  int c,x,y;
  cin>>n>>q;
  for(int i=0;i<q;i++){
    scanf("%d%d%d",&c,&x,&y);
    if(c)printf("%d\n",sum(y)-sum(x-1));
    else add(x,y);
  }
}


Measured memory_bytes: 3560
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int mat[n][3];
    cin >> mat[0][0] >> mat[0][1] >> mat[0][2];
    for(int i = 1; i < n; i++){
        int a, b, c;
        cin >> a >> b >> c;
        mat[i][0] = a + max(mat[i-1][1], mat[i-1][2]);
        mat[i][1] = b + max(mat[i-1][0], mat[i-1][2]);
        mat[i][2] = c + max(mat[i-1][0], mat[i-1][1]);
    }
    cout << max(mat[n-1][0], max(mat[n-1][1], mat[n-1][2]));
    
    return 0;
}

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

using namespace std;

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

int main() {
	int T, g;
	long long s = 0;
	cin >> T;
	for (int i = 1; i <= T; i++)
		for (int j = 1; j <= T; j++){
			g = gcd(i,j);
			for (int k = 1; k <= T; k++)
				s += gcd(g,k);
		}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = br.readLine();
		
		int[] table = makeCharTable(input);
		char result = getUnexistNumber(table);
		
		if(result == 0){
			System.out.println("None");
		}
		else {
			System.out.println(result);
		}
	}
	
	public static int[] makeCharTable(String str){
		char[] carray = str.toCharArray();
		int[] result = new int[26];
		
		for(int i = 0; i < carray.length ; i++){
			result[carray[i] - 'a']++;
		}
		
		return result;
	}
	
	public static char getUnexistNumber(int[] table){
		for(int i = 0; i < table.length ; i++){
			if(table[i] == 0){
				return (char)(i + 'a');
			}
		}
		
		return (char)0;
	}

}


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

using namespace std;

const int mod = 1e9 + 7;

int add(int a, int b) {
  return a + b - mod * (a + b >= mod);
}

int mul(int a, int b) {
  return int(1ll * a * b % mod);
}

int pwr(int a, int x) {
  if (x == 0) {
    return 1;
  }
  return mul(pwr(mul(a, a), x >> 1), (x & 1 ? a : 1));
}

int dvd(int a, int b) {
  return mul(a, pwr(b, mod - 2));
}

int sub(int a, int b) {
  return a - b + mod * (a < b);
}

void inc(int& a, int b) {
  a = add(a, b);
}

void dec(int& a, int b) {
  a = sub(a, b);
}

const int N = 1010;
int t[N][N], dp[N][N];

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

  dp[1][1] = 1;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      char c;
      cin >> c;
      t[i][j] = (c == '.');
      if (i > 1 or j > 1) {
        dp[i][j] = add(t[i - 1][j] * dp[i - 1][j], t[i][j - 1] * dp[i][j - 1]);
      }
    }
  }
  cout << dp[n][m];

  return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 200000000
#define N 51




int32_t main()
{
    IOS;

    int n;
    cin >> n;
    vector<int> v(n),lf(n),rf(n),ls(n),rs(n);
    stack<int> s;
    for(int i = 0;i < n;i++)
    {
        cin >> v[i];
    }
    for(int i = 0;i < n;i++)
    {
        while(!s.empty() and v[s.top()] < v[i])
        {

            rf[s.top()] = i - 1;
            s.pop();
        }
        s.push(i);
    }
    while(!s.empty())
    {
        rf[s.top()] = n - 1;
        s.pop();
    }
    cerr << rf[1] << endl;
    for(int i = n - 1;i >= 0;i--)
    {
        while(!s.empty() and v[s.top()] < v[i])
        {
            lf[s.top()] = i + 1;
            s.pop();
        }
        s.push(i);
    }
    while(!s.empty())
    {
        lf[s.top()] = 0;
        s.pop();
    }
    deque<int> dq;
    vector<int> pt(n,0);
    for(int i = 0;i < n;i++)
    {
        
        vector<int> reinsert;
        while(!dq.empty() and v[dq.back()] < v[i])
        {
            if(pt[dq.back()])
                rs[dq.back()] = i - 1;
            else
            {
                pt[dq.back()] = 1;
                reinsert.push_back(dq.back());
            }
            dq.pop_back();
        }
        dq.push_back(i);
        int sz = reinsert.size();
        for(int i = sz - 1;i >= 0;i--)
        {
            dq.push_back(reinsert[i]);
        }
    }
    while(!dq.empty())
    {
        rs[dq.back()] = n - 1;
        dq.pop_back();
    }
    for(int i = 0;i < n;i++)
        pt[i] = 0;
    for(int i = n - 1;i >= 0;i--)
    {
        
        vector<int> reinsert;
        while(!dq.empty() and v[dq.back()] < v[i])
        {
            if(pt[dq.back()])
                ls[dq.back()] = i + 1;
            else
            {
                pt[dq.back()] = 1;
                reinsert.push_back(dq.back());
            }
            dq.pop_back();
        }
        dq.push_back(i);
        int sz = reinsert.size();
        for(int i = sz - 1 ;i >= 0;i--)
        {
            dq.push_back(reinsert[i]);
        }
    }
    while(!dq.empty())
    {
        ls[dq.back()] = 0;  
        dq.pop_back();
    }
    int ans = 0;
    for(int i = 0;i < n;i++)
    {

        int a1 = (i - ls[i] + 1) * (rf[i] - i + 1);
        a1 += (rs[i] - i + 1) * (i - lf[i] + 1);
        int a2 = 2 * (i - lf[i] + 1) * (rf[i] - i + 1);
        // cerr << lf[i] << " " << rf[i] << " " << ls[i] << " " << rs[i] << " " << a1 << " " << a2 << endl;
        ans += v[i] * (a1 - a2);
    }
    cout << ans;

}   

 
 


Measured memory_bytes: 5676
#include <stdio.h>

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int l, r, min = 1, max = n;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &l, &r);
    if (min < l) {
      min = l;
    }
    if (max > r) {
      max = r;
    }
  }
  int ans = max - min + 1;
  if (ans < 0) {
    ans = 0;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#空リスト作成と標準入力
s = set()
for _ in range(int(input())):
    a,b = map(int,input().split())
    try:
        #セットbを入れセットの長さを出力する
        if a == 0:
            s.add(b)
            print(len(s))
            
        #セットの中にbがあるなら1ないなら0を出力する
        elif a == 1:print(1 if b in s else 0)
        
        #セットからbを消す
        elif a == 2:s.remove(b)
    except KeyError:
        pass


Measured memory_bytes: 23372
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=b-1;i>=a;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

string  S,T;

int main(){
  cin >>  S >> T;
  if(S.size()+1==T.size()){
    T.pop_back();
    if(S==T){
      cYes;
      return 0;
    }
  }
  cNo;
}

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

int n, a[200];
long long sum[200];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i), sum[i] = sum[i - 1] + a[i];
    long long ans = 0x3f3f3f3f;
    for (int T = 1; T <= n; ++T)
        ans = min(ans, abs(sum[T] - (sum[n] - sum[T])));
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
const int MAX = 1005;
int N, M;
ll X[MAX], Y[MAX], Z[MAX];
ll cache[MAX][MAX];
int MASK = 0;
// 000: XYZ
// 001: XY-Z
// 010: X-YZ
// ...
// 111: -X-Y-Z

const int arr[2] = {1, -1};
const ll MIN = LONG_LONG_MIN / 4;
ll dp(int n, int m) {
  if (n == N) {
    return m == 0 ? 0 : MIN;
  }
  if (cache[n][m] != -1) return cache[n][m];
  int xmul = arr[bool(MASK&1)];
  int ymul = arr[bool(MASK&2)];
  int zmul = arr[bool(MASK&4)];
  ll mm = dp(n + 1, m);
  if (m > 0 && dp(n + 1, m - 1) != MIN) {
    mm = max(mm, dp(n + 1, m - 1) + xmul * X[n] + ymul * Y[n] + zmul * Z[n]);
  }
  cache[n][m] =mm;
  return mm;
}

int main() {
  scanf("%d %d", &N, &M);
  for (int i=0; i<N; i++) {
    scanf("%lld %lld %lld", &X[i], &Y[i], &Z[i]);
  }
  ll mm = 0;
  for (MASK = 0; MASK < (1 << 4); ++MASK) {
    memset(cache, -1, sizeof(cache));
    mm = max(mm, dp(0, M));
  }
  printf("%lld\n", mm);
  return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
vector<int> abcd(string a){
    vector<int> alp;
    int p;
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    for(int i = 0;i<26;i++){
        p = 0;
        for(int j = 0;j<a.size();j++){
            if(a[j] == alpha[i]){
                p++;
            }
        }
        alp.push_back(p);
    }
    return alp;
}
int main(){
    string s,t;
    cin >> s >> t;
    vector<int> sal = abcd(s);
    vector<int> tal = abcd(t);
    sort(sal.begin(),sal.end());
    sort(tal.begin(),tal.end());
    string ans = "Yes";
    for(int i = 0;i<26;i++){
        if(sal[i] != tal[i]){
            ans = "No";
            break;
        } 
    }
    cout << ans << endl;
}

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

queue<ll> q;

ll a[200010],b[200010],n;

inline ll rd()
{
	ll x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd();
	for (ll i=0;i<n;i++) a[i]=rd();
	for (ll i=0;i<n;i++) b[i]=rd();
	for (ll i=0;i<n;i++) if (b[i]<a[i]) { puts("-1");return 0; }
	ll ans=0;
	for (ll i=0;i<n;i++) q.push(i);
	while (!q.empty())
	{
		ll i=q.front();q.pop();
		ll h1=(i-1+n)%n,h2=(i+1)%n;
		if (b[i]<=b[h1]||b[i]<=b[h2]||b[i]==a[i]) continue;
		if (a[i]>b[h1]&&a[i]>b[h2])
		{
			ll hh=b[i]-a[i];
			if (hh%(b[h1]+b[h2])!=0) { puts("-1");return 0; }
			b[i]=a[i];ans+=hh/(b[h1]+b[h2]);
			continue;
		}
		ll hh=(b[i]-max(b[h1],b[h2])+(b[h1]+b[h2])-1)/(b[h1]+b[h2]);
		b[i]-=hh*(b[h1]+b[h2]);ans+=hh;
		if (b[i]<a[i]) { puts("-1");return 0; }
		q.push(h1);q.push(h2);
	}
	bool flag=true;
	for (ll i=0;i<n;i++) if (b[i]!=a[i]) flag=false;
	if (flag) printf("%lld\n",ans);
	else puts("-1");
	return 0;
}

Measured memory_bytes: 5120
a = int(input())
y = a//100
m = a%100
if 1 <= y <= 12 and 1 <= m <= 12:
	print('AMBIGUOUS')
elif 1 <= y <= 12:
	print('MMYY')
elif 1 <= m <= 12:
	print('YYMM')
else:
	print('NA')


Measured memory_bytes: 38404
#include<bits/stdc++.h>
using namespace std;
 
long long calc(int n, int c1, int c2, int s1, int s2, const vector<int>& options,
               int d, int nt, int ot) {
  int b1(d-1), a1(d+1), b2(d-1), a2(d+1);
  while (b1 >= 0 && options[b1] != nt) b1--;
  while (b2 >= 0 && options[b2] != ot) b2--;
  while (a1 < n && options[a1] != nt) a1++;
  while (a2 < n && options[a2] != ot) a2++;
  int x1(d-b1-1), y1(a1-d-1), z1(a1-b1-1), x2(d-b2-1), y2(a2-d-1), z2(a2-b2-1);
  int diff1 = z1*(z1+1)/2-x1*(x1+1)/2-y1*(y1+1)/2;
  int diff2 = z2*(z2+1)/2-x2*(x2+1)/2-y2*(y2+1)/2;
  return (long long) diff1 * c1 - (long long) diff2 * c2 + s1 - s2;
}

bool check(int diff, int time) {
  return diff >= 0 || rand() >= (-diff) * (clock()-time) * 1.4;
}

int main() {
  int n;
  cin >> n;
  vector<int> c(26), last(26, -1);
  vector<array<int, 26>> s(n);
  
  for (int i = 0; i < 26; ++i) cin >> c[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 26; ++j)
      cin >> s[i][j];
  
  long long total(0);
  vector<int> options(n);
  
  for (int i = 0; i < n; ++i) {
    int neg(0), test(-1), max_score(-1e9);
    for (int j = 0; j < 26; ++j) neg -= c[j] * (i - last[j]);
    for (int j = 0; j < 26; ++j) {
      int ss = s[i][j] + neg + c[j] * (i - last[j]);
      if (ss > max_score) {
        max_score = ss;
        test = j;
      }
    }
    total += max_score;
    options[i] = test;
    last[test] = i;
  }
  //cout << total << endl;
  // stochastic
  time_t time = clock();
  while ((clock()-time)<=1.9*CLOCKS_PER_SEC) {
    if (rand() & 1) {
      int dd(rand() % n), ot(options[dd]), tt;
      do { tt = rand() % 26; } while (ot == tt);
      
      options[dd] = tt;
      long long ns = calc(n, c[tt], c[ot], s[dd][tt], s[dd][ot],
                          options, dd, tt, ot);
      
      if (check(ns,time)) {
        total += ns;
      } else {
        options[dd] = ot;
      }
    } else {
      int dd1 = rand() % n;
      int ot1 = options[dd1];
      int dd2, ot2;
      do { dd2 = rand() % n; ot2 = options[dd2]; } while (ot1 == ot2);
      
      options[dd1] = ot2;
      long long ns1 = calc(n, c[ot2], c[ot1], s[dd1][ot2], s[dd1][ot1],
                          options, dd1, ot2, ot1);
      options[dd2] = ot1;
      long long ns2 = calc(n, c[ot1], c[ot2], s[dd2][ot1], s[dd2][ot2],
                          options, dd2, ot1, ot2);
      
      if (check(ns1+ns2,time)) {
        total += ns1 + ns2;
      } else {
        options[dd1] = ot1;
        options[dd2] = ot2;
      }
    }
  }
  
  for (const int& i: options) cout << i + 1 << endl;
  
  return 0;
}

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

int main()
{
    int h,w,i,j,s;
    char a[55][55];
    for(i=0;i<55;i++)
    {
        for(j=0;j<55;j++)
            a[i][j]='0';
    }
    cin>>h;cin>>w;
    for(i=1;i<=h;++i)
    {
        for(j=1;j<=w;++j)
        {
            cin>>a[i][j];
        }
        getchar();
    }
    for(i=1;i<=h;++i)
    {
        for(j=1;j<=w;++j)
        {
            s=0;
            if(a[i][j]=='#'){cout<<"#";continue;}
            else
            {
                if(a[i-1][j-1]=='#')s++;
                if(a[i-1][j]=='#')s++;
                if(a[i-1][j+1]=='#')s++;
                if(a[i][j-1]=='#')s++;
                if(a[i][j+1]=='#')s++;
                if(a[i+1][j-1]=='#')s++;
                if(a[i+1][j]=='#')s++;
                if(a[i+1][j+1]=='#')s++;
            }
            cout<<s;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (20000010)
#define P (998244353)
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c){
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int n,A,B,ans=0,jc[N],inv[N];
int C(int n,int m){
	return 1ll*jc[n]*inv[m]%P*inv[n-m]%P;
}
int catalan(int x,int y){
	return (C(x+y,y)-C(x+y,y-1)+P)%P;
}
int ksm(int a,int p){
	int res=1;
	while(p){
		if(p&1)res=1ll*res*a%P;
		a=1ll*a*a%P,p>>=1;
	}
	return res;
}
int main(){
	read(n),read(A),read(B);
	jc[0]=inv[0]=1;
	for(int i=1;i<=n*2;i++)jc[i]=1ll*jc[i-1]*i%P; inv[n*2]=ksm(jc[n*2],P-2);
	for(int i=n*2-1;i;i--)inv[i]=1ll*inv[i+1]*(i+1)%P;
	if(!B){puts("1"),exit(0);}
	//终点(B,B-A) 
	if(A+B==n)ans+=catalan(B-1,A);
//	cout<<ans<<endl;
	for(int i=0;i<=min(min(A,B-1),n-B);i++){
		int s=catalan(B-1,i);
		if(i+B!=n){
			int x=n-B-i-1,y=A-i+1;
			(ans+=1ll*s*C(x+y-1,x)%P)%=P;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 157952
Imports System

Module Program
    Sub Main(args As String())

        Dim NMX() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()
        Dim tbl(NMX(0), NMX(1)) As Integer
        For i As Integer = 1 To NMX(0)
            Dim tmp() As Integer = Console.ReadLine().Split(" ").Select(Function(x) Integer.Parse(x)).ToArray()
            For j = 0 To NMX(1)
                tbl(i, j) = tmp(j)
            Next
        Next

        Dim ans As Integer = Integer.MaxValue
        For i = 1 To 2 ^ NMX(0)
            Dim kingaku As Integer = CheckBooks(NMX, tbl, i)
            If kingaku < ans Then
                ans = kingaku
            End If
        Next

        If ans = Integer.MaxValue Then ans = -1

        Console.WriteLine(ans)

    End Sub

    Private Function CheckBooks(NMX() As Integer, tbl(,) As Integer, ptn As Integer) As Integer

        CheckBooks = Integer.MaxValue
        Dim rikaido(NMX(1)) As Integer
        Dim tassei As New List(Of Integer)
        Dim gokei As Integer

        For i As Integer = 1 To NMX(0)
            If ptn \ (2 ^ (i - 1)) Mod 2 = 1 Then
                For j As Integer = 1 To NMX(1)
                    rikaido(j) += tbl(i, j)
                    If rikaido(j) >= NMX(2) Then
                        If Not tassei.Contains(j) Then
                            tassei.Add(j)
                        End If
                    End If
                Next
                gokei += tbl(i, 0)
            End If
        Next

        If tassei.Count = NMX(1) Then
            CheckBooks = gokei
        End If

    End Function

End Module


Measured memory_bytes: 29552
from collections import defaultdict
from collections import deque
from collections import Counter
import math
import itertools

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()
lr = [readInts() for i in range(k)]

dp = [-1]*(n+2)
dp[n]=1
dp[n+1]=0
i=n
ruiseki = [0]*(k)
for j in range(k):
	ruiseki[j] = dp[min(i+lr[j][0],n+1)]-dp[min(i+lr[j][1],n+1)]
#print(ruiseki)
ans = 0
for i in range(n-1,0,-1):
	t = 0
	for j in range(k):
		ll = dp[min(i+lr[j][0],n+1)]
		rr = dp[min(i+lr[j][1]+1,n+1)]
		#print(ll,rr)
		ruiseki[j] += ll-rr
	t+=sum(ruiseki)
	dp[i]=t%998244353
	#print(i,ruiseki,dp)

print(dp[1])

Measured memory_bytes: 80900
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int N, K;
    long long ans = 0;
    cin >> N >> K;
    vector<int> H(N);
    
    for(int i = 0; i < N; i++){
        cin >> H.at(i);
    }
    
    sort(H.rbegin(), H.rend());
    
    for(int i = K; i < N; i++){
        ans += H.at(i);
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 1024
#include <stdio.h>
#define min(a, b) ((a) < (b)) ? (a) : (b)
#define max(a, b) ((a) > (b)) ? (a) : (b)

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif
void arrdump(int *arr, int len) {
  for (int i = 0; i < len; i++) {
    printf("[%d] = %d\n", i, arr[i]);
  }
}

int main(int argc, const char *argv[])
{
  int a, b, k;
  int c[101] = {0};
  scanf("%d%d%d", &a, &b, &k);
  int m =  min(a, b);
  for (int i = 1; i <= m; i++) {
    if (a % i == 0 && b % i == 0)
      c[i]++;
  }
  // arrdump(c, m + 1);
  for (int i = m; i > 0; i--) {
    if (c[i] == 1) {
      k--;
      eprintf("c[%d] = %d, k = %d\n", i, c[i], k);
    }
    if (k == 0) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 128
H,W = map(int,input().split())
maps = [input().rstrip() for x in range(H)]
for i in range(H):
  for j in range(W):
    if maps[i][j] == '#':
      count = 0
      if 0 <= i-1 and maps[i-1][j] == '#':
        count += 1
      if i+1 < H and maps[i+1][j] == '#':
        count += 1
      if 0 <= j-1 and maps[i][j-1] == '#':
        count += 1
      if j+1 < W and maps[i][j+1] == '#':
        count += 1
      if count == 0:
        print('No')
        exit()
print('Yes')  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;//でかい整数



int main(){
  ll  n;
  cin >> n;
  ll a_i, m;
  a_i=0;
  m= sqrt(n);
 

  rep(i,m){
    ll k=i+1;
    if(n/k *k==n) {
      a_i=k;
    }
  }

  ll j = n/a_i;
  ll ans = a_i+j-2;

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



Measured memory_bytes: 256