akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int lately[40][200000];
string s,t;
signed main() {
	memset(lately,-1,sizeof(lately));
	cin >> s >> t;
	for (char i = 'a';i <= 'z';i++) {
		size_t pos = 0;
		for (size_t j = 0;j < s.size();j++)
			if (s[j] == i)
				for (;pos <= j;pos++) lately[1*i-'a'][pos] = j;
	}
	bool flag = true;
	size_t pos = 0;
	int cnt = 1;
	for (size_t i = 0;i < t.size();i++) {
		if (lately[1*t[i]-'a'][0] == -1) {
			flag = false;
			break;
		}
		if (lately[1*t[i]-'a'][pos] == -1 || pos >= s.size()) {
			pos = 0;
			cnt++;
		}
		pos = lately[1*t[i]-'a'][pos]+1;
	}
	if (flag == false) printf("-1");
	else printf("%lld\n",1ll*cnt*s.size()-(1ll*s.size()-pos));
	return 0;
}

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

signed main(){
  int K,S;
  cin>>K>>S;
  int ans=0;
  rep(x,K){
    rep(y,K){
      int z=S-x-y;
      if(0<=z&&z<=K)ans+=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
using namespace std;
int main(){
    int d;
    cin >> d;
    if(d == 25){
        cout << "Christmas" << endl;
    }else if(d == 24){
        cout << "Christmas Eve" << endl;
    }else if(d == 23){
        cout << "Christmas Eve Eve" << endl;
    }else if(d == 22){
        cout << "Christmas Eve Eve Eve" << endl;
    }else{

    }



}

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

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb(x) push_back(x)

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 1000000009


using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n >> k)
    {
        ll md = (n % k);

        ans = min(md, k - md);

        cout << ans << endl;
    }


}




Measured memory_bytes: 256
n = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):      
      if L[i]+L[j] > L[k] and (L[i]!=L[j] and L[j]!=L[k]):
        ans += 1        
print(ans)        

Measured memory_bytes: 9096
using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{

    int n, a, b, c, d;
    string s;

    public void AtCoder()
    {
        string[] input;
        input = Console.ReadLine().Split(' ');
        n = int.Parse(input[0]);
        a = int.Parse(input[1]) - 1;
        b = int.Parse(input[2]) - 1;
        c = int.Parse(input[3]) - 1;
        d = int.Parse(input[4]) - 1;
        s = Console.ReadLine();
        bool f = true;
        bool g = false;

        for(int i=a; i<c; i++)
        {
            if (s[i] == '#' && s[i + 1] == '#') f = false;
        }
        for(int i=b; i<d; i++)
        {
            if (s[i] == '#' && s[i + 1] == '#') f = false;
        }
        if(d < c)
        {
            for(int i=b-1; i<d; i++)
            {
                if (i >= 0 && i + 2 < n)
                {
                    if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.')
                        g = true;
                }
            }
            f = g;
        }

        if (f) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}


Measured memory_bytes: 13152
sx,sy,tx,ty = map(int,input().split())
ans = ''

#内廻り(S->T)
ans += 'U'
ans += 'U'*(ty-sy-1)
ans += 'R'*(tx-sx-1)
ans += 'R'
#内廻り(T->S)
ans += 'D'
ans += 'D'*(ty-sy-1)
ans += 'L'*(tx-sx-1)
ans += 'L'
#外廻り(S->T)
ans += 'L'
ans += 'U'*(ty-sy+1)
ans += 'R'*(tx-sx+1)
ans += 'D'
#外廻り(T->S)
ans += 'R'
ans += 'D'*(ty-sy+1)
ans += 'L'*(tx-sx+1)
ans += 'U'

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 200001;

string s;
int cur[MX], dp[MX];
map<int,int> mindp;

int test(int x) {
    if (!mindp.count(x)) return MOD;
    return mindp[x]+1;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> s;
    int ind = 0;
    for (char c: s) {
        ind ++;
        cur[ind] = cur[ind-1]^(1<<(c-'a'));
    }
    dp[sz(s)] = 0;
    mindp[cur[sz(s)]] = 0;
    F0Rd(i,sz(s)) {
        dp[i] = MOD;
        F0R(j,26) dp[i] = min(dp[i],test(cur[i]^(1<<j)));
        F0R(j,26) dp[i] = min(dp[i],test(cur[i]));
        if (!mindp.count(cur[i])) mindp[cur[i]] = MOD;
        mindp[cur[i]] = min(mindp[cur[i]],dp[i]);
    }
    cout << dp[0];
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 11472
#include<iostream>
using namespace std;
int n, a, b, c, d, i, ok, ok2;
char s[200005];
int main(){
    cin>> n >> a >> b >> c >> d;
    cin>> s + 1;
    ok = 1;
    for(i = a + 1; i <= c; i++){
        if(s[i] == '#' && s[i - 1] == '#'){
            ok = 0;
            break;
        }
    }
     for(i = b + 1; i <= d; i++){
        if(s[i] == '#' && s[i - 1] == '#'){
            ok = 0;
            break;
        }
    }
    if(c < d){
        ok2 = 1;
    }
    else{
        for(i = b; i <= d; i++){
            if(s[i - 1] == '.' && s[i + 1] == '.' && s[i] == '.'){
                ok2 = 1;
            }
        }
    }
    if(ok == 1 && ok2 == 1){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 384
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const inf = 1001001001001001

func main() {
	sc.Split(bufio.ScanWords)
	N, M := getInt(), getInt()
	a := make([]int, M)
	c := make([]int, M)
	for i := 0; i < M; i++ {
		a[i] = getInt()
		b := getInt()
		for j := 0; j < b; j++ {
			n := getInt() - 1
			c[i] |= (1 << n)
		}
	}

	dp := make([]int, 1<<N)
	for j := 0; j < 1<<N; j++ {
		dp[j] = inf
	}
	dp[0] = 0

	for i := 1; i <= M; i++ {
		for j := 0; j < 1<<N; j++ {
			dp[j|c[i-1]] = min(dp[j|c[i-1]], dp[j]+a[i-1])
		}
	}

	ans := dp[1<<N-1]
	if ans == inf {
		out(-1)
		return
	}
	out(ans)
}


Measured memory_bytes: 1852
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a >> b >> c >> k;
  tmp = min(a, k);
  ans += tmp;
  k -= tmp;
  tmp = min(b, k);
  k -= tmp;
  tmp = min(c, k);
  ans -= tmp;
  Cout(ans);
  return 0;
}

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

using namespace std;

int main(){
    int N,X,Y;
    cin >> N>>X>>Y;
    X--;Y--;
    
    vector<vector<int>> d;
    d.resize(N);
    for(int i=0;i<d.size();i++) d[i].resize(i);
    
    for(int i=0;i<N;i++){
        for(int j=0;j<d[i].size();j++){
            //j<i
            if(j<=X && Y<=i){
                d[i][j]=X-j+i-Y+1;
            }
            else if(j<=X && i<Y){
                int a=i-j;
                int b=X-j+1+Y-i;
                d[i][j]=min(a,b);
            }
            else if(X<j && Y<=i){
                int a=i-j;
                int b=j-X+1+i-Y;
                d[i][j]=min(a,b);
            }
            else{//X<j<i<Y
                int a=i-j;
                int b=j-X+1+Y-i;
                d[i][j]=min(a,b);
            }
            //printf("d[%d][%d]=%d\n",i,j,d[i][j]);
        }
    }
    
    vector<int> sum;
    sum.resize(N-1);
    for(int i=0;i<N;i++){
        for(int j=0;j<d[i].size();j++){
            sum[d[i][j]-1]++;
        }
    }
    
    for(int i=0;i<sum.size();i++) cout << sum[i] << endl;
    
    return 0;
}



Measured memory_bytes: 8192
import java.util.Scanner;

public class Main {

	/** 100 */
	private static final int HUNDRED = 100;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int d = scanner.nextInt(), n = scanner.nextInt();
			int pow = 1;
			for (int i = 0; i < d; i++) {
				pow *= HUNDRED;
			}
			// 解説通りの式で計算
			System.out.println((n + (n - 1) / (HUNDRED - 1)) * pow);
		}
	}
}


Measured memory_bytes: 35648
#include <iostream>

 

using namespace std;

 

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   s = i % 60;
   m = (i % 3600) / 60;
   cout << h << ":" << m << ":" <<  s << endl; 
   
   return 0;
}



Measured memory_bytes: 3080
x, y, a, b, c = map(int, input().split())
Lista = sorted(list(map(int, input().split())), reverse = True)
Listb = sorted(list(map(int, input().split())), reverse = True)
Listc = sorted(list(map(int, input().split())), reverse = True)
if x < a:
    del Lista[x : a]
if y < b:
    del Listb[y : b]
List = sorted(Lista + Listb, reverse = True)
i = -1
for n in range(min(x + y, c)):
    if List[-n-1] < Listc[n]:
        i = n
    else:
        break
del List[x + y - i -1 : x + y]
del Listc[i + 1 : c]
print(sum(List) + sum(Listc))

Measured memory_bytes: 23200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct score
{
    int p, s;
};
bool cmp(score g1, score g2)
{
    return g1.p < g2.p;
}
int main ()
{
    score sc;
    int n;
    cin >> n;
    vector <score>v;
    for (int i = 0; i<n; i++){
        cin >> sc.p >> sc.s;
        v.push_back(sc);
    }
    sort (v.begin(), v.end(), cmp);
    int ans = 0;
    ans = v[0].p - 1;
    for (int i = 0; i<n-1; i++){
        ans+= v[i+1].p-v[i].p-1;
    }
    if (v[n-1].s!= 0){
        ans+= v[n-1].s;
    }
    cout << ans+n << endl;
    return 0;
}



Measured memory_bytes: 1400
#優先度付きキュー
import heapq
n,m=map(int,input().split())
#入力時に全ての数に-1をかける
a=list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a) #aを優先度付きキューにする

for _ in range(m):
  #最小値(最大値)を取り出す
  tmp_min = heapq.heappop(a)
  #負数の剰余演算を避けるため一時的に正の整数にしている
  heapq.heappush(a, (-1)*(-tmp_min//2))
print(-sum(a))

Measured memory_bytes: 14180
n=int(input())
a,b,c=[list(map(int,input().split())) for _ in range(3)]
s=0
before= n
for i in range(n):
      s+=b[a[i]-1]
      if a[i]==before+1:
            s+=c[a[i-1]-1]
      before=a[i]
print(s)


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

#define int         long long
#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 sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int M=1e9 + 7;
const int N=1e5 + 5;

int a[N];
int n,m;
mi mp;

int32_t main()
{
	IOS;
	cin >> n >> m;
	rep(i,1,m)
	{
		int x;
		cin >> x;
		mp[x]++;
	}
	if(mp[1]==0)
	{
		a[1]=1;
	}
	a[0]=1;
	rep(i,2,n)
	{
		if(mp[i]==1)
		{
			a[i]=0;
		}
		else
		{
			a[i] = (a[i-1] + a[i-2])%M;
		}
	}
	cout << a[n] << endl;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[105];
	cin>>a;
	int n=strlen(a);
	for(int i=0;i<n;i++){
		if(i%2==0&&a[i]!='h'){
			cout<<"No";
			return 0;
		}
		if(i%2==1&&a[i]!='i'){
			cout<<"No";
			return 0;
		}
	}
	if(n%2==0){cout<<"Yes";return 0;}
  else cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	printf("%lld",(a-c)/(b+c));
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++){
    cin >> d.at(i); 
  }

  set<int> mochi;
  for(int n : d){
    mochi.insert(n);
  }
  
  cout << mochi.size() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    REP(i, 0, n) {
        cin >> a[i];
        sum += a[i];
        if (i % 2) {
            sum -= a[i] * 2;
        }
    }
    cout << sum;
    REP(i, 0, n - 1) {
        sum = a[i] * 2 - sum;
        cout << " " << sum;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(){
    int S;
    int h,m,s;
    scanf("%d", &S);
    h = S/3600;
    S %= 3600;
    m = S/60;
    S %= 60;
    s = S;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


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

const int maxn = 2e5 + 5;
const ll Inf = 1e18;
ll dp[maxn];

ll tree[4 * maxn];

ll query(int pos, int tl, int tr, int l, int r){
    if (tl > tr || tr < l || tl > r)
        return -Inf;
    if (tl >= l && tr <= r){
        return tree[pos];
    }
    int tm = (tl + tr) / 2;
    return max(query(2 * pos, tl, tm, l, r), query(2 * pos + 1, tm + 1, tr, l, r));
}

void update(int pos, int tl, int tr, int idx, ll val){
    if (tl == tr){
        tree[pos] = max(tree[pos], val);
        return;
    }
    int tm = (tl + tr) / 2;
    if (idx <= tm){
        update(2 * pos, tl, tm, idx, val);
    } else {
        update(2 * pos + 1, tm + 1, tr, idx, val);
    }
    tree[pos] = max(tree[2 * pos], tree[2 * pos + 1]);
}

int main()
{
    int n;
    cin >> n;
    vector<ll> h(n), a(n);
    for (int i = 0; i < n; i++){
        cin >> h[i];
    }
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = 0; i < n; i++){
        dp[h[i]] = a[i] + query(1, 0, maxn - 1, 0, h[i] - 1);
        update(1, 0, maxn - 1, h[i], dp[h[i]]);
        /*for (int j = 0; j < h[i]; j++){
            dp[h[i]] = max(dp[h[i]], a[i] + dp[j]);
        }*/
    }
    ll ans = *max_element(dp, dp + maxn);
    cout << ans;
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int solve() {
    int a,b,c,d; cin >> a >> b >> c >> d;
    ll s = min(a, d) - min(c, max(0, d - a - b));
    cout << s << endl;
    return 0;
}

int main() {
    int T = 1; 
    // cin >> T;
    for (int t = 1; t <= T; t++)
        // cout << "Case #" << t << ": " << solve() << "\n";
        solve();
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e16;

/*
	S = { A, B, C};
	2^|S|
	{} 000
	{A} 100
	{B} 010
	{C} 001
	{A, B} 110
	{B, C} 011
	{A, C} 101
	{A, B, C} 111
*/
lint N, M, X;
lint cost[12];
lint understand[12][12];
int main() {
	cin >> N >> M >> X;
	REP(i, N) {
		cin >> cost[i];
		REP(j, M) {
			cin >> understand[i][j];
		}
	}

	lint minv = INF;
	REP(bit_array, 1ll << N) {
		lint got_skill[12];
		lint cost_sum = 0;
		REP(k, M) got_skill[k] = 0;
		REP(j, N) {
			if ((bit_array >> j) % 2 == 1) {
				cost_sum += cost[j];
				REP(k, M) {
					got_skill[k] += understand[j][k];
				}
			}
		}
		bool flag = true;
		REP(k, M) {
			if (got_skill[k] < X) {
				flag = false;
			}
		}
		if (flag) {
			if (minv > cost_sum) {
				minv = cost_sum;
			}
		}
	}

	if (minv == INF) {
		cout << -1 << endl;
	}
	else {
		cout << minv << endl;
	}
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;


int main()
{
	string S = "", S1 = "", S2 = "";
	std::cin >> S;
	for (int j = S.size(); j > 0; j--) {
		S.pop_back();
		S1 = "";
		S2 = "";
		if (S.size() >= 0) {
			for (int i = 0; i < S.size() / 2; i++)
				S1.push_back(S[i]);
			for (int i = S.size() / 2; i<S.size(); i++)
				S2.push_back(S[i]);
			if (S1 == S2) {
				printf("%d", S.size());
				cin >> S;
				return 0;
			}
		}
		else {
			cout << "-1";
			return 1;
		}
	}
}



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

int w,h;
char t[102][102];

int dx[128];
int dy[128];

int main(void){
	dx['>'] = 1;
	dx['<'] = -1;
	dy['v'] = 1;
	dy['^'] = -1;

	while(cin>>h>>w && (h||w)){
		for(int i=0;i<h;i++){
			cin>>t[i];
		}

		int x = 0, y = 0;
		while(t[y][x] != '?' && t[y][x] != '.'){
			int nx = x + dx[t[y][x]];
			int ny = y + dy[t[y][x]];
			t[y][x] = '?';
			x = nx;
			y = ny;
		}
		if(t[y][x] == '?'){
			cout<<"LOOP\n";
		}
		else{
			cout<<x<<" "<<y<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
using System;
using System.Text;

namespace Main
{
  class Program
  {
    static void Main(string[] args)
    {
      var lines = Console.ReadLine().Split(' ');
      var a = int.Parse(lines[0]);
      var b = int.Parse(lines[1]);
      var k = int.Parse(lines[2]);

      StringBuilder buf = new StringBuilder();
      if (b - a < k * 2)
      {
        for (var i = a; i <= b; i++)
          if (a <= i && i < a + k || b - k < i && i <= b)
            buf.Append(i).Append('\n');
      }
      else
      {
        for (var i = a; i < a + k; i++)
          Console.WriteLine(i);
        for (var i = b - k + 1; i <= b; i++)
          buf.Append(i).Append('\n');
      }

      Console.Write(buf);
    }
  }
}


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

int main(void){
	int i;
	int count = 0;
	char S[100];
	scanf("%s", S);
	int len = strlen(S);
	for (i = 0; i < len / 2; i++){
		if (S[i] != S[len - i - 1]) {
			count++;
		}
	}
	printf("%d", count);
}

Measured memory_bytes: 128
import re

n=int(input())

def A(snake):
    r=re.match("^>\'(\=+)\#(\=+)\~$",snake)
    if r:
        if len(r.group(1))==len(r.group(2)):
            return True
    return False
def B(snake):
    r=re.match("^\>\^(Q=)+\~\~$",snake)
    if r:
        return True
    return False

for i in range(n):
    S=input()
    if A(S):
        print("A")
    elif B(S):
        print("B")
    else:
        print("NA")



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

int main() {
    int N, M, L; cin >> N;
    if (N % 2 == 0){
        M = N / 2;
        L = (N + 1);
    } else {
        M = (N + 1) / 2;
        L = N;
    }

    vector<vector<int> > group(M, {0});
    for (int i = N; 1 <= i; i--) {
        int j = 0;
        while (true) {
            if (group[j][0] + i > L) {
                j++;
            } else {
                break;
            }
        }
        group[j].push_back(i);
        group[j][0] += i;
    }
    vector<pair<int ,int> > ans;

    for (int i = 0; i < M; i++) {
        for (int j = i + 1; j < M; j++) {
            for (int k = 1; k < group[i].size(); k++){
                for (int l = 1; l < group[j].size(); l++) {
                    ans.push_back({group[i][k], group[j][l]});
                }
            }
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i].first << ' ' << ans[i].second << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
 
string low(string w){
    string w_ = "";
    for(int i=0;i<w.size();i++){
        if(w[i] >= 'A' && w[i] <= 'Z'){
            w_ += w[i]+32;
        }else{
            w_ += w[i];
        }
    }
    return w_;
}

int main(){
    string w; cin >> w;
    w = low(w);

    string t;
    int cnt=0;
    
    string tango = "";

    while(true){
        cin >> t;
        if(t=="END_OF_TEXT") break;
        t = low(t);
        if(t == w) cnt++;
    }

    cout << cnt<< endl;
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
int n,h,a[100001],b[100001],ma,ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>h;
	for (int i=0;i<n;++i) cin>>a[i]>>b[i];
	sort(a,a+n);
	ma=a[n-1];
	sort(b,b+n);
	for (int i=n-1;i>=0;--i)
		if (b[i]>ma && h>0) h-=b[i],++ans;
	if (h>0) ans+=(h+ma-1)/ma;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
    int x,y;
    while(1){
        cin >> x >> y;
        if (x == 0&&y == 0)break;
        else if (x > y){
            cout << y << " " << x << endl;
        }
        else{
            cout << x << " " << y << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3060
#include<cstdio>
using namespace std;
int n,m,a[110],sum;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    scanf("%d",&m);
    while(m--){
        int p,x;
        scanf("%d%d",&p,&x);
        printf("%d\n",sum-a[p]+x);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
string s,t;
int main(){
        int a,b,c;
        while(cin>>a>>b){
                int ans=a*3+b;
                cout<<ans/2<<"\n";
        }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<queue>
#define ll long long
using namespace std;
const int mod=1e9+7;
inline int read()
{
    int kkk=0,x=1;
    char c=getchar();
    while((c<'0' || c>'9') && c!='-')
        c=getchar();
    if(c=='-')
        c=getchar(),x=-1;
    while(c>='0' && c<='9')
        kkk=(kkk<<3)+(kkk<<1)+(c-'0'),c=getchar();
    return kkk*x;
}
ll n,K,dp[2001][2001],sum[4000001];
inline ll ksm(int a,int b)
{
	a%=mod;
	ll c=1;
	while(b)
	{
		if(b%2)
			c=1ll*c*a%mod;
		a=1ll*a*a%mod;
		b/=2;
	}
	//cout<<c<<endl;
	return c;
}
inline ll C(int N,int M)
{
	if(N==0)
		return 1;
	return 1ll*sum[M]*ksm(sum[N],mod-2)%mod*ksm(sum[M-N],mod-2)%mod;
}
inline void format()
{
	sum[0]=1;
	for(register int i=1;i<=4000000;++i)
		sum[i]=1ll*sum[i-1]*i%mod;
}
int main()
{
	format();
	n=read(),K=read();
	if(K==1)
	{
		puts("1");
		return 0;
	}
	for(register int i=0;i<=n;++i)
		dp[i][0]=1;
	for(register int i=1;i<=n;++i)
		for(register int j=1;j<=i;++j)
			dp[i][j]=(dp[i-1][j]+1ll*dp[i][j-1]*(n-j+1)%mod*C(K-2,n*K-i-(j-1)*(K-1)-1)%mod)%mod;
	printf("%lld\n",dp[n][n]);
	return 0;
}

Measured memory_bytes: 62720
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int input [3];
    int x = 0;
    int n = 0;
    int m = 0;

    int a, b;

    //expired
    cin>> x>> a>> b;
    n = 0;
    n = n-a+b;
    if (n<=0){
        cout << "delicious";
    }
    else if (n>0 && n<=x){
        cout << "safe";
    }
    else if (n>x){
        cout << "dangerous";
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.Math.*;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if( n == 0 ) break;
			
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = sc.nextInt();
			
			int min = n;
			for(int i=0;i<n;i++) for(int c=1;c<=3;c++){
				int tmp = a[i];
				a[i] = c;
				int l = i, r = i, cnt = 0;
				while(l>=0) {
					int cc = a[l];
					while( l > 0 && cc == a[l-1] ) l--;
					while( r < n-1 && cc == a[r+1] ) r++;
					if( r-l-cnt+1 < 4 ) break;
					cnt += r-l-cnt+1;
					l--;
				}
				a[i] = tmp;
				min = min(n - cnt, min);
			}
			
			System.out.println(min);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;

bool check(vector<int> &cnt) {
    for (int &x : cnt) {
        if (x > 1)
            return true;
    }
    return false;
}

void mark(int x, vector<int> &cnt, int val) {
    int i = 0;
    while (x) {
        if (x & 1)
            cnt[i] += val;
        x /= 2;
        ++i;
    }
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    vector<int> arr(n);
    for (int &x : arr)
        cin >> x;

    long long ans = 0;
    vector<int> cnt(20, 0);
    int l = 0, r = 0;
    while (l < n && r < n) {
        mark(arr[r], cnt, 1);
        while (l < r && check(cnt)) {
            mark(arr[l], cnt, -1);
            ++l;
        }
        ans += r - l + 1;
        ++r;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n, q;
	scanf("%d%d", &n, &q);
	vector<ll> a(q + 1);
	a[0] = n;
	for (int i = 1; i <= q; ++i) {
		scanf("%lld", &a[i]);
	}
	map<ll, ll> cnt; // [0,r] -> c
	cnt[a[q] - 1] = 1;
	for (int i = q - 1; i >= 0; --i) {
		auto it = cnt.lower_bound(a[i]);
		while (it != cnt.end()) {
			ll x = it->first;
			ll c = it->second;
			assert(x >= a[i]);
			if ((x + 1) % a[i]) cnt[x % a[i]] += c;
			cnt[a[i] - 1] += (x + 1) / a[i] * c;
			cnt.erase(it++);
		}
	}
	vector<ll> ans(n);
	for (auto& x : cnt) {
		assert(x.first < n);
		ans[x.first] += x.second;
	}
	for (int i = n - 2; i >= 0; --i) {
		ans[i] += ans[i + 1];
	}
	for (ll x : ans) printf("%lld\n", x);
}


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


int main()
{
	int N,C,K;
	cin>>N>>C>>K;
	vector<int> T(N);
	rep(i,N) cin>>T[i];
	sort(T.begin(),T.end());
	int prev=T[0];
	int cnt=1;
	int i=1;
	int ans=0;
	while (i<N)
	{
		if(prev+K>=T[i]&&cnt<C)
		{
			cnt++;
		}
		else
		{
			ans++;
			cnt=1;
			prev=T[i];
		}
		i++;
	}
	cout<<ans+1<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int A[100], N, i, j, minj, sw = 0;
	
	scanf("%d", &N);
	
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	
	for(i = 0; i <= N - 1; i++){
		minj = i;
		for(j = i; j <= N - 1; j++){
			if(A[j] < A[minj]){
				minj = j;
			}
		}
		int temp = A[i];
		A[i] = A[minj];
		A[minj] = temp;
		if(i < minj){
			sw++;
		}
	}
	
	for(i = 0; i <= N - 1; i++){
		if(i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
	printf("%d\n", sw);
	
	return 0;
}



Measured memory_bytes: 2096
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define LL long long
int N;
std::vector<LL> a;
std::vector<LL> b;
int main() {
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		LL tmp;
		std::cin >> tmp;
		a.push_back(tmp);
	}
	for (int i = 0; i < N; i++) {
		LL tmp;
		std::cin >> tmp;
		b.push_back(tmp);
	}
	LL adda = 0;
	LL addb = 0;
	for (int i = 0; i < N - 1; i++) {
		if (a[i] - b[i] < 0) {
			LL ne = ((b[i] - a[i] + 1) / 2) * 2;

			if (adda >= ne) {
				adda -= ne;
				ne = 0;
			}
			else{
				ne -= adda;
				adda = 0;
			}
			addb += ne / 2;
			if ((b[i] - a[i]) % 2 != 0) {
				if (addb != 0)addb--;
				else adda += 2;
			}
		}
		if (b[i] - a[i] < 0) {
			LL  ne = a[i] - b[i];
			if (addb >= ne) {
				addb -= ne;
				ne = 0;
			}
			else {
				ne -= addb;
				addb = 0;
			}
			adda += ne * 2;
		}
	}
	if (a[N - 1] + adda <= b[N - 1] + addb)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int r = sc.nextInt();
    
		// 出力
		System.out.println(r < 1200 ? "ABC" : r < 2800 ? "ARC" : "AGC" );
	}
}


Measured memory_bytes: 22612
N = int(input())

restaurants = {}
for i in range(1, N+1):
    s, p = input().split()
    restaurants[i] = (s, int(p) * -1)

key = lambda x: (x[1][0], x[1][1])
restaurants_sorted = sorted(restaurants.items(), key=key)

for k in restaurants_sorted:
    print(k[0])

Measured memory_bytes: 9188
import heapq

n, m = map(int, input().split())
item = [-1 * int(a) for a in input().split()]
heapq.heapify(item)
ans = 0

for _ in range(m):
    item_max = heapq.heappop(item)
    item_max = item_max / 2
    heapq.heappush(item, item_max)

for i in item:
    ans += int(i)

print(- ans)

Measured memory_bytes: 14180
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
bool prime[50000005];
map<llint, llint> mp;

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

//ax+by = gcd(a, b)を満たす(x, y)を求めgcd(a, b)を返す
llint extgcd(llint a, llint b, llint &x, llint &y)
{
	if(b == 0){
		x = 1, y = 0;
		return a;
	}
	llint xx, yy;
	llint d = extgcd(b, a%b, xx, yy);
	x = yy, y = xx-(a/b)*yy;
	return d;
}

//a^{-1} (mod m)を求める。存在しない場合(gcd(a, m)!=1)は-1を返す
llint mod_inverse(llint a, llint m)
{
	llint x, y;
	if(extgcd(a, m, x, y) != 1) return -1;
	return (x%m + m) % m;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	n *= 2;
	
	for(int i = 2; i < 8005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 50000005; j+=i) prime[j] = true;
	}
	
	for(int i = 2; i < 50000005; i++){
		if(prime[i]) continue;
		while(n % i == 0){
			mp[i]++;
			n /= i;
		}
	}
	if(n > 1) mp[n]++;
	
	vector<llint> vec;
	for(auto it = mp.begin(); it != mp.end(); it++){
		llint mul = 1;
		for(int i = 0; i < it->second; i++) mul *= it->first;
		vec.push_back(mul);
	}
	
	llint ans = inf, m = vec.size(), M = 1<<m;
	for(int i = 0; i < M; i++){
		llint mul = 1, mul2 = 1;
		for(int j = 0; j < m; j++){
			if(i & (1<<j)) mul *= vec[j];
			else mul2 *= vec[j];
		}
		llint res = mod_inverse(mul, mul2);
		llint y = (mul*res-1)/mul2;
		if(y <= 0) res +=((-y+1)+mul*mul2-1)/(mul*mul2) * mul2;
		//cout << mul << " " << mul2 << " " << res << endl;
		ans = min(ans, mul*res-1);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 52432
import sys
def input():
	return sys.stdin.readline()[:-1]

class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def Sum(self, i):#1からiまでの和
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def PointAdd(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

s = input()
n = len(s)
a = [-1 for _ in range(n)]
ch = [[] for _ in range(26)]
for i in range(n):
	ch[ord(s[i])-97].append(i)
if sum([len(x)%2 == 1 for x in ch]) > 1:
	print(-1)
	sys.exit()

for i, c in enumerate(ch):
	tmp = i
	l = len(c)
	for j in range(l//2):
		a[c[j]] = tmp
		a[c[l-j-1]] = tmp
		tmp += 26
#print(a)

former, latter = 0, 0
half = False
d = dict()
cur = 0
bubble = []

ans = 0

for x in a:
	if x >= 0:
		if x not in d:
			d[x] = cur
			cur += 1
			former += 1
			ans += latter + half
		else:
			bubble.append(d[x])
			latter += 1
			if n%2 == 1 and not half:
				ans += 1
	else:
		half = True

bit = BIT(n//2+2)
for b in bubble:
	ans += bit.Sum(b+1)
	bit.PointAdd(b+1, 1)

print(ans)

Measured memory_bytes: 28716
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<18;
	int dp[1<<19];
	int lazy[1<<19];
	segtree(){
		memset(dp,0,sizeof(dp));
		for(int i=0;i<N*2;i++){
			dp[i]=11451419;
			lazy[i]=11451419;
		}
	}

	void lazy_eval(int k){
		dp[k]=min(dp[k],lazy[k]);
		if(k<N-1){
			lazy[k*2+1]=min(lazy[k*2+1],lazy[k]);
			lazy[k*2+2]=min(lazy[k*2+2],lazy[k]);
		}
	}

	void lazy_upd(int k){
		dp[k]=min(dp[k*2+1],dp[k*2+2]);
	}
	void update(int a,int b,int v,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return;
		if(a<=l && r<=b){
			lazy[k]=min(lazy[k],v);
			lazy_eval(k);
			return;
		}
		int mid=(l+r)/2;
		update(a,b,v,k*2+1,l,mid);
		update(a,b,v,k*2+2,mid,r);
		lazy_upd(k);
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return 11451419;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,mid);
		int vr=query(a,b,k*2+2,mid,r);
		lazy_upd(k);
		return min(vl,vr);
	}
};

int n;
set<int> g[100005];
set<int> gg[100005];
segtree seg;
bool self[100005];

int main(void){
	scanf("%d",&n);
	int selfc=0;
	int pr=0;
	for(int i=0;i<n;i++){
		int m;
		scanf("%d",&m);
		bool flag=false;
		for(int j=0;j<m;j++){
			int x;
			scanf("%d",&x);
			x--;
			if(x==i){
				self[i]=true;
				g[i].insert(x);
			}else if(x==i+1){
				flag=true;
			}else if(x>=pr && !self[i]){
				g[i].insert(x);
			}
		}
		if(!flag){
			pr=i+1;
		}
	}
	for(int i=0;i<n;i++){
		for(set<int>::iterator it=g[i].begin();it!=g[i].end();it++){
			int v=*it;
			gg[v].insert(i);
		}
	}
	int mini_m=11451419;
	for(int i=n-1;i>=0;i--){
		for(set<int>::iterator it=gg[i].begin();it!=gg[i].end();it++){
			int v=*it;
			mini_m=min(v,mini_m);
		}
		if(*(gg[i].begin())>mini_m){
			gg[i].insert(mini_m);
		}
	}
	seg.update(0,1,0);
	int prv=0;
	int cnt=0;
	for(int i=0;i<n;i++){
		if(gg[i].size()==0)continue;
		int v=seg.query(prv,prv+1);
		int nxt=*(gg[i].begin());
		//printf("%d %d %d\n",i,nxt,v);
		seg.update(i+1,nxt+2,v+1);
		prv=i+1;
	}
	printf("%d\n",seg.query(prv,prv+1));
	return 0;
} 


Measured memory_bytes: 16804
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const int inf = (int)1e10;
const int mod = (int)1e9 + 7;

int n;
int a[2*(int)1e5 + 1];
int main(){
    cin >> n;
    rep(i, n) cin >> a[i];

    ll sum_a = 0, res = 0;
    rep(i, n) sum_a += a[i];
    rep(i, n - 1){
        sum_a -= a[i];
        res = (res + (a[i] %mod) * (sum_a %mod)) %mod;
    }
    cout << res << endl;
}

Measured memory_bytes: 4284
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	n := scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
	}

	ans := math.MaxInt64
	for i := -100; i <= 100; i++ {
		sum := 0
		for _, v := range a {
			sum += (v - i) * (v - i)
		}
		ans = min(ans, sum)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

ll dp[3009][3009];

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

    string s, t;
    cin >> s >> t;

    int a = s.size(), b = t.size();
    FOR(i, 1, a + 1) FOR(j, 1, b + 1) {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        if(s[i - 1] == t[j - 1]) chmax(dp[i][j], dp[i - 1][j - 1] + 1);
    }
    string ans;
    while(a && b) {
        if(dp[a][b] == dp[a - 1][b])
            a--;
        else if(dp[a][b] == dp[a][b - 1])
            b--;
        else {
            --a;
            --b;
            ans.push_back(s[a]);
        }
    }
    reverse(ALL(ans));
    cout << ans << endl;
    return 0;
}

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

int main(){
  int a1,a2,a3;

  cin >> a1 >> a2 >> a3;

  if (a1 + a2 + a3 >= 22) {
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }

  return 0;
}


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

public class Main {
    public static void main(String[] args) {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        Scanner sc = new Scanner(is);
        int w[] = new int[5];

        for (int i = 0; i < w.length; i++) {
            w[i] = sc.nextInt();
        }

        int lastIndex = 0;

        int lastIndexDigit = 10;

        for (int i = 0; i < w.length; i++) {
            int digit = w[i] % 10;
            if (digit != 0 && digit < lastIndexDigit) {
                lastIndex = i;
                lastIndexDigit = digit;
            }
        }

        int count = 0;

        for (int i = 0; i < w.length; i++) {
            if (i == lastIndex) {
                count += w[i];
            } else {
                if (w[i] % 10 == 0) {
                    count += w[i];
                } else {
                    count += (w[i] / 10 + 1) * 10;
                }
            }
        }

        os.println(count);
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <string>
typedef long long ll;
using namespace std;





int main(){
    int N;
    cin >> N;
    bool ans = false;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            int A = i*j;
            if(N==A)ans = true;
        }
    }
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
R = lambda: map(int, input().split())
input()
a, b = list(R()), R()
r = 0
for i, u in enumerate(b):
    x = min(a[i], u)
    y = min(a[i + 1], u - x)
    a[i + 1] -= y
    r += x + y
print(r)


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

int main(void){
	int N, W;
	cin >> N >> W;
	vector<int> w(N), v(N);
	for(int i = 0; i < N; ++i){
		cin >> w[i] >> v[i];
	}
	ll dp[N+1][W+1] = {};
	for(int i = 0; i < N; ++i){
		for(int j = 0; j <= W; ++j){
			dp[i+1][j] = dp[i][j];
			if(j-w[i]>=0){
				dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i+1][j]);
			}
		}
	}

	cout << dp[N][W] << endl;
	return 0;
}

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

int main(){
    char s;
    cin >> s;
    if(isupper(s)){
        s='A';
    }else{
        s='a';
    }
    cout << s << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<cmath>

using namespace std;
int main(void)
{
    int a, b;
    cin >> a >> b;
    for (int i = 1; i <= 1250;i++)
        if (floor(i*0.08)==a&&floor(i*0.1)==b){
            cout << i << endl;
            return 0;
        }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#define M_PI 3.14159265358979323846
#include <vector>
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s == "ABC"){
      cout << "ARC";
    }else{
      cout << "ABC";
    }
}

  


Measured memory_bytes: 3120
'use strict';

function main(input) {
  const i = input.split(' ').map((x) => x | 0);

  if (i[0] == 1 || i[1] == 1) {
    console.log(1);
    return;
  }

  if (i[0] * i[1] % 2 == 0) {
    console.log(i[0] * i[1] / 2);
  } else {
    console.log(Math.floor(i[0] * i[1] / 2) + 1)
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include<stdio.h>

int main(void){
	
	int m,f,r,k;
	
	while(1){
		
		scanf("%d %d %d",&m, &f, &r);
		
		if(m==-1 && f==-1 && r==-1){
			break;
		}
		
		k = m + f;
		
		if(m==-1 || f==-1){
			printf("F\n");
		}
		if(m != -1 && f != -1){
			if(k>=80){
				printf("A\n");
			}else if(k>=65 && k<80){
				printf("B\n");
			}else if(k>=50 && k<65){
				printf("C\n");
			}else if(k>=30 && k<50){
				if(r>=50){
					printf("C\n");
				}else{
					printf("D\n");
				}
			}else{
				printf("F\n");
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 2104