akhauriyash/Code-Regression huggingface dataset:
while(True):
    try:
        ans = 0
        n = input()
        for i in range(10):
            for j in range(10):
                for k in range(10):
                    for l in range(10):
                        if(i + j + k + l == n):
                            ans += 1
        print(ans)
    except Exception:
        break
        

Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
//cout << fixed << setprecision(8) << a << endl;
#define Fast_Input ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define pb push_back
#define mem(a, b)     memset(a, b, sizeof(a))
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*sort(v.begin(), v.end(),
     [](const pair<int, int>& x, const pair<int, int>& y)
{
    if (x.first != y.first)
        return x.first < y.first;
    return x.second < y.second;
});
*/
int const fx[]= {+1,+0,-1,+1};
int const fy[]= {-1,+1,+0,+0};
const int inf = numeric_limits<int>::max();
const ll mx=1e3;
const ll mod=1e9+7;
int cost[15],arr[15][15];
int n,m,x;
int ans=inf;
void rec(int ind,int co,vector<int>v)
{
    int p=0,i;
    for(i=0;i<m;i++)
    {
        if(v[i]<x)
        {
            p=1;
            break;
        }
    }
    if(!p)
    {
        ans=min(ans,co);
        return;
    }
    if(ind>n)
        return;
    rec(ind+1,co,v);
    for(i=0;i<m;i++)
    {
       v[i]+=arr[ind][i];
    }
    rec(ind+1,co+cost[ind],v);
}
int main()
{
    int i,j,c;
    cin >> n >> m >> x;
    i=1;
    int no=n;
    while(no--)
    {
       cin >> c;
       cost[i]=c;
       for(j=0;j<m;j++)
       {
           cin >> arr[i][j];
       }
       i++;
    }
    vector<int>now;
    for(i=0;i<m;i++)now.pb(0);
    rec(1,0,now);
    if(ans==inf)cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n,a,b;
  cin>>n>>a>>b;

  ll x[n+1]={};
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  ll ans=0;
  for(int i=1;i<n;i++){
    ans+=min(a*(x[i]-x[i-1]),b);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main(){

    int N, M;
    cin >> N >> M;

    int like[M+1];
    for(int i = 0; i <=M; i++) like[i] = 0;

    for(int i = 0; i < N; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int ind;
            cin >> ind;
            like[ind] ++;
        }
    }

    int ans = 0;
    for(int i = 0; i <= M; i++){
        if(like[i] == N) ans ++;
    }
    cout << ans << endl;

}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/03  Problem: code-festival-2016-ex-final_a / Link: https://cf16-exhibition-final.contest.atcoder.jp/tasks/cf16_exhibition_final_a?lang=en  ----- */
/* ------問題------

一次元の世界に N 個のパソコンと N 個の電源があります。 i 番目のパソコンの座標は ai であり、 i 番目の電源の座標は bi です。 これらの 2N 個の座標は相異なることが保証されています。
すぬけ君は、それぞれのパソコンをケーブルで電源につなぎたいです。 それぞれの電源は一つのパソコンにのみつなぐことができます。
何通りの方法で、ケーブルの長さの合計を最小化できるでしょうか？ 答えを modulo 109+7 で求めてください。

-----問題ここまで----- */
/* -----解説等-----

座標順に並べるとなんとなく連結成分っぽいものが見える場所と見えない場所がある。
これについて考えると小さいものから選択していくのがよく、座標で並べたときにつなぐ対称は交差してはいけないことがわかる。(判例を証明で消す)
したがって先頭から見ていくときに、現在の連結成分っぽいもののサイズを乗算していけばよい

----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VL a(N), b(N);
	vector<PLL>v;
	FOR(i, 0, N) {
		cin >> a[i];
		v.push_back(PLL(a[i], 1));
	}
	FOR(i, 0, N) {
		cin >> b[i];
		v.push_back(PLL(b[i], -1));
	}
	SORT(v);
	ans = 1;
	int size = 0;
	FOR(i, 0, SZ(v)) {
		if (size != 0 && (size > 0) != (v[i].second > 0)) {
			ans = (ans * abs(size)) % MOD;
		}
		size += v[i].second;
	}


	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 8048
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <memory>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <string>
#include <unordered_map>
#include <iomanip>
#include <sstream>  
#include <deque>
#include <unordered_set>
#include <stack>
#include <functional>

using namespace std;


//#define int long long

vector <vector <int> > g;
int num[110000];
int gg = 1;

void dfs(int v) {
    num[v] = gg;
    for (auto it : g[v]) {
        if (!num[it]) {
            dfs(it);
        }
    }
}

signed main() {

    int n, m;
    cin >> n >> m;
    g.resize(n + 1);
    vector <int> v(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> v[i];
    }
    for (int i = 1; i <= m; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int i = 1; i <= n; ++i) {
        if (!num[i]) {
            dfs(i);
            ++gg;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (num[v[i]] == num[i]) ++ans;
    }
    cout << ans << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    set<int> a;
    REP(i,3){
        int b; cin >> b;
        a.insert(b);
    }

    cout << a.size() << endl;

    return 0;
}

Measured memory_bytes: 3632
using System;

namespace ALDS1_4_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ');
            var n = int.Parse(nk[0]);
            var k = int.Parse(nk[1]);
            var w = new int[n];
            int left = 1, right = 1000000000;
            for (int i = 0; i < n; i++)
            {
                w[i] = int.Parse(Console.ReadLine());
                if (w[i] > left) left = w[i];
            }
            while (left < right)
            {
                int mid = (left + right) / 2;
                if (Check(mid, w, k)) right = mid;
                else left = mid + 1;
            }
            Console.WriteLine(left);
        }

        static bool Check(int p, int[] w, int k)
        {
            for (int i = 0, t = 0; i < w.Length; i++)
            {
                if (w[i] > t)
                {
                    if (k > 0)
                    {
                        k--;
                        t = p - w[i];
                    }
                    else return false;
                }
                else t -= w[i];
            }
            return true;
        }
    }
}

Measured memory_bytes: 9940
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <tuple>
#include <utility>
using namespace std;

struct UnionFind {
    vector<int> node;
    int size_;
    UnionFind (int n) : node(n, -1), size_(n) {}
    int find(int k) { return node[k] < 0 ? k : find(node[k]); }
    bool same(int u, int v) { return find(u) == find(v); }
    bool unite(int u, int v) {
        if(same(u, v)) return false;
        u = find(u), v = find(v);
        size_--;
        node[u] += node[v];
        node[v] = u;
        return true;
    }
    size_t size() { return size_; }
    void reset() {
        size_ = node.size();
        fill(node.begin(), node.end(), -1);
    }
};

const int INF = 1 << 28;
int solve_testcase() {
    int N, M; cin >> N >> M;
    if(N == 0 and M == 0) return 1;
    
    vector< pair<int, int> > sink;
    for(int i=0; i<N; i++) {
        int h; cin >> h;
        sink.emplace_back(h, i);
    }
    sink.emplace_back(-INF, -1);

    sort(sink.rbegin(), sink.rend());
    vector< vector<int> > edges(N, vector<int>(N, INF));
    for(int i=0; i<M; i++) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        edges[a][b] = c;
        edges[b][a] = c;
    }

    UnionFind uf(N);
    vector<int> alive(N);
    int i = 0, ans = 0, cnt = 0;
    for(; i<N; i++) {
        int h = sink[i].first;
        vector<int> is;
        is.emplace_back(sink[i].second);
        while(i < N and sink[i].first == sink[i+1].first) {
            is.emplace_back(sink[++i].second);
        }

        for(auto k : is) alive[k] = true, cnt++;
        vector< tuple<int, int, int> > cand;
        for(int k=0; k<N; k++) {
            for(int j=k+1; j<N; j++) {
                if(edges[j][k] == INF or !alive[j] or !alive[k]) continue;
                cand.emplace_back(edges[j][k], j, k);
            }
        }

        int tmp = 0;
        UnionFind uf_(uf);

        sort(cand.begin(), cand.end());
        for(auto e : cand) {
            int c, u, v; tie(c, u, v) = e;
            if(uf_.same(u, v)) continue;
            // fprintf(stderr, "tmp edge (h = %d): (u, v) = (%d, %d), cost = %d\n", h, u, v, c);
            uf_.unite(u, v);
            tmp += c;
        }

        if(uf_.size() == (N - cnt) + 1) {
            for(auto e : cand) {
                int c, u, v; tie(c, u, v) = e;
                if(uf.same(u, v)) continue;
                // fprintf(stderr, "edge (h = %d): (u, v) = (%d, %d), cost = %d\n", h, u, v, c);
                uf.unite(u, v);
                ans += c;
            }

            /*
            uf = uf_;
            ans += tmp;
            */
        }
        else {
            uf.reset();
            ans = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



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

int main(){
    double ans=0;
    int n;
    int x[10];
    int y[10];
    cin >>n;
    vector<vector<double>> dist(n,vector<double>(n));
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i] ;
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        dist[i][j] = pow((pow(x[i]-x[j],2)+pow(y[i]-y[j],2)),0.5);
      }
    }

    vector <int> order(n);
    for(int i=0;i<n;i++) order[i] = i;

    do {
      for(int i=0;i<n-1;i++){
      ans += dist[order[i]][order[i+1]];
    }
  } while(next_permutation(order.begin(),order.end()));

double p=1.0;
    for(int i=1;i<=n;i++){
     p=p*i;
    }
    ans = ans /p;
    cout << fixed << setprecision(16) << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
  int X;
  int happy = 0;
  
  scanf("%d",&X);
  
  while(X>5){
    if(X>=500){
      X-=500;
      happy+=1000;
    }else if(X>5){
      X-=5;
      happy+=5;
    }
  }
  
  printf("%d\n",happy);
}

Measured memory_bytes: 128
a,b=map(int,input().split())
h=[int(i) for i in input().split()]
ansl=[]
dic={i:0 for i in range(a)}
aans=[]
for i in range(b):
    c,d=map(int,input().split())
    if True:
        ch=h[c-1]
        dh=h[d-1]
        if ch==dh:
            if dic[c-1]==0:
                ansl.append(c-1)
                dic[c-1]+=1
            if dic[d-1]==0:
                ansl.append(d-1)
                dic[d-1]+=1
        else:
            if ch<dh:
                if dic[c-1]==0:
                    ansl.append(c-1)
                    dic[c-1]+=1
            else:
                if dic[d-1]==0:
                    ansl.append(d-1)
                    dic[d-1]+=1
        aans.append([c,d])
print(a-len(ansl))

Measured memory_bytes: 39292
#include <iostream>
using namespace std;
const int INFTY=1000000001;

void marge(int A[],int left,int mid,int right){
	int n1=mid-left;
	int n2=right-mid;
	int* L=new int[n1+1];
	int* R=new int[n2+1];
	for(int i=0;i<n1;i++){
		L[i]=A[left+i];
	}
	for(int i=0;i<n2;i++){
		R[i]=A[mid+i];
	}
	L[n1]=INFTY;
	R[n2]=INFTY;

	for(int i=0,j=0,k=left;k<right;k++){
		if(L[i]<=R[j]){
			A[k]=L[i];
			i++;
		}
		else{
			A[k]=R[j];
			j++;
		}
	}
	delete[] R;
	delete[] L;
}

void margesort(int A[],int left,int right){
	if(left+1>=right)
		return;

	int mid=(left+right)/2;
	margesort(A,left,mid);
	margesort(A,mid,right);
	marge(A,left,mid,right);
}

int binarysearch(int x,int S[],int n){
	int B=0;
	int T=n-1;
	while(B<=T){
		int mid=(B+T)/2;
		if(S[mid]==x) return mid;
		else if(S[mid]<x) B=mid+1;
		else T=mid-1;
	}
	return -1;
}
	
int main(){
	int n;
	cin>>n;
	int A[n];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}

	int m;
	cin>>m;
	int B[m];
	for(int i=0;i<m;i++){
		cin>>B[i];
	}

	int c=0;
	margesort(A,0,n);
	for(int i=0;i<m;i++){
		if(binarysearch(B[i],A,n)!=-1) c++;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3788
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=[int(input()) for i in range(m)]

for i in range(n):
    c=0
    for j in range(m):
        
        c +=a[i][j]*b[j]
    print(c)


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


def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    L = [[0] * W for _ in range(H)]
    R = [[0] * W for _ in range(H)]
    T = [[0] * W for _ in range(H)]
    B = [[0] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if s[h][w] == "#":
                R[h][w] = 0
            elif w == 0:
                R[h][w] = 1
            else:
                R[h][w] = R[h][w - 1] + 1
    for h in range(H):
        for w in reversed(range(W)):
            if s[h][w] == "#":
                L[h][w] = 0
            elif w == W - 1:
                L[h][w] = 1
            else:
                L[h][w] = L[h][w + 1] + 1
    for w in range(W):
        for h in range(H):
            if s[h][w] == "#":
                B[h][w] = 0
            elif h == 0:
                B[h][w] = 1
            else:
                B[h][w] = B[h-1][w] + 1
    for w in range(W):
        for h in reversed(range(H)):
            if s[h][w] == "#":
                T[h][w] = 0
            elif h == H - 1:
                T[h][w] = 1
            else:
                T[h][w] = T[h + 1][w] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            res = R[h][w] + L[h][w] + B[h][w] + T[h][w] - 3
            ans = max(ans, res)
    print(int(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 307976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int D;
vector<int> C;
vector<vector<int>> S;

long long getTime() {
	timespec ts;
	clock_gettime(CLOCK_REALTIME_COARSE, &ts);
	long long r = ts.tv_sec;
	r *= 1000000000;
	r += ts.tv_nsec;
	return r;
}

ll calcScore(const vector<int>& T) {
	vector<int> last(26, -1);
	ll score = 0;
	for (int i = 0; i < D; ++ i) {
		int d = i - last[T[i]];
		score -= C[T[i]] * d * (d-1) / 2;
		last[T[i]] = i;
		score += S[i][T[i]];
	}
	for (int j = 0; j < 26; ++ j) {
		int d = D - last[j];
		score -= C[j] * d * (d-1) / 2;
	}
	return score;
}

int hoge(const vector<int>& T) {
	vector<int> last(26, -1);
	vector<ll> pena(26);
	for (int i = 0; i < D; ++ i) {
		last[T[i]] = i;
		for (int j = 0; j < 26; ++ j) {
			pena[j] += C[j] * (i - last[j]);
		}
	}
	int r = 0, cnt = 1;
	for (int j = 1; j < 26; ++ j) {
		if (pena[j] > pena[r]) {
			r = j; cnt = 1;
		} else if (pena[j] == pena[r]) {
			if (rand() % ++cnt == 0) { r = j; }
		}
	}
	return r;
}

int main() {
	auto startTime = getTime();

	cin >> D;
	C.resize(26);
	for (auto& x : C) cin >> x;
	S = vector<vector<int>>(D, vector<int>(26));
	for (auto& x : S) for (auto& y : x) cin >> y;

	vector<int> res(D);
	for (int i = 0; i < D; ++ i) {
		res[i] = 0;
		for (int j = 1; j < 26; ++ j) {
			if (S[i][j] > S[i][res[i]]) res[i] = j;
		}
	}

	for (int tt = 1; ; ++ tt) {
		int x = hoge(res);
		int ii = 0;
		ll m = -(1LL<<62);
		for (int i = 0; i < D; ++ i) {
			int tmp = res[i];
			res[i] = x;
			auto s1 = calcScore(res);
			if (s1 > m) {
				ii = i;
				m = s1;
			}
			res[i] = tmp;
		}
		if (res[ii] == x) break;
		res[ii] = x;
	}

	ll maxScore = calcScore(res);

	for (int tt = 1; ; ++ tt) {
		if (tt % 1024 == 0 && getTime() - startTime >= 1900000000) break;
		int i = rand() % D;
		int tmp = res[i];
		if (tt % 2 == 0) {
			res[i] = hoge(res);
		} else {
			res[i] = rand() % 26;
		}
		if (tmp == res[i]) continue;
		auto s1 = calcScore(res);
		if (s1 > maxScore) { maxScore = s1; }
		else { res[i] = tmp; }
	}

	for (auto x : res) cout << x + 1 << endl;
}


Measured memory_bytes: 3684
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

#define pi 3.141592653589
#define repeat(i,n) for(int i=0;i<n;i++)

int main()
{
	string str;	//最初の文字列
	string temp;	//シャッフルの時に使う文字列操作用変数
	int n;	//シャッフル回数
	int h;	//シャッフル枚数
	while (1)
	{
		cin >> str;
		if (str == "-") break;
		cin >> n;
		repeat(i, n)
		{
			cin >> h;
			temp = str.substr(0, h);
			str = str + temp;
			str.erase(0, h);
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <set>

using namespace std;

int main() {
    int n;
    cin >> n;
    bool yes = true;
    set<int> set;

    while (n--) {
        int a;
        cin >> a;
        if (set.find(a) != set.end()) {
            yes = false;
            break;
        }
        set.insert(a);
    }

    cout << (yes ? "YES" : "NO") << endl;

    return 0;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	int ans = 0;
	while (n > 0) {
		int x = n;
		int c = 0;
		while (x) {
			c++, x /= 10;
		}
		ans += c & 1;
		n--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

long long A, B, C, D, E, F;
typedef pair<long long, long long> pll; // 砂糖, 水

bool operator < (pll a, pll b) {
    return a.first * (b.first + b.second) < b.first * (a.first + a.second);
}


int main() {
    while (cin >> A >> B >> C >> D >> E >> F) {
        pll res = pll(0, A*100);
        for (long long a = 0; a <= F; a += A*100) {
            for (long long b = 0; a + b <= F; b += B*100) {
                long long water = a + b;
                long long maxsugar = min(F - a - b, E * (water / 100));
                
                for (long long c = 0; c <= maxsugar; c += C) {
                    for (long long d = 0; c + d <= maxsugar; d += D) {
                        long long sugar = c + d;

                        pll tmp = pll(sugar, water);
                        chmax(res, tmp);
                    }
                }
            }
        }
        cout << res.first + res.second << " " << res.first << endl;
    }
}











Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A=new int[N+1];
		int answer=0;
		for(int i=1;i<=N;i++) {
			A[i]=sc.nextInt();
			int d=1;
			while(A[i]%(int)Math.pow(2, d)==0) {
				d++;
			}
			answer=answer+d-1;
		}
		System.out.println(""+answer);

	}
}


Measured memory_bytes: 34292
import itertools
n, m = [int(i) for i in input().split()]
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = 0
for i, j in itertools.product(range(n - m + 1), repeat = 2):
    if b == [a[i + _][j:j + m] for _ in range(m)]:
        ans = 1
print(["No", "Yes"][ans])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	cin >> N;
	vector<int> C(N);
	vector<int> S(N);
	vector<int> F(N);
	vector<int> ans(N, 0);

	for (int i = 0; i < N - 1; i++)
	{
		cin >> C[i] >> S[i] >> F[i];
	}

	for (int i = 0; i < N; i++)
	{
		for (int j = i; j < N - 1; j++)
		{
			ans[i] = max(ans[i] + (F[j] - ans[i] % F[j]) % F[j], S[j]) + C[j];
		}
	}

	for (auto out : ans)
	{
		cout << out << endl;
	}
	return;
}

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

	int stop;
	cin >> stop;

	return 0;
}

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

#define int long long

using namespace std;
using pii = pair<int, int>;

const int maxn = 1e5 + 10;
int ps[maxn], sf[maxn], n;
vector<pii> seg;

signed main()
{
        ios::sync_with_stdio(false);
        cin >> n;

        int ans = -2e9, L = -2e9, R = 2e9;
        for (int i = 0, l, r; i < n; i++)
                cin >> l >> r, seg.push_back({ l, r }), ans = max(ans, r - l + 1), L = max(L, l), R = min(R, r);
        ans += max(0ll, R - L + 1);
        sort(seg.begin(), seg.end(),
            [](pii x, pii y) { return x.second < y.second; });

        int mn = seg.front().first, mx = seg.front().second;
        ps[0] = mx - mn + 1;
        for (int i = 1; i < n; i++) {
                mn = max(mn, seg[i].first);
                ps[i] = max(0ll, mx - mn + 1);
        }
        mn = seg.back().first, mx = seg.back().second;
        sf[n - 1] = mx - mn + 1;
        for (int i = n - 2; ~i; i--) {
                mx = min(mx, seg[i].second);
                sf[i] = max(0ll, mx - mn + 1);
        }

        for (int i = 0; i < n - 1; i++)
                ans = max(ans, ps[i] + sf[i + 1]);
        cout << ans;

        return 0;
}


Measured memory_bytes: 3568
import java.io.*;
import java.util.*;
import java.lang.*;

class Main {
	public static void main (String[] args) {
	    Scanner sc = new Scanner(System.in);
	    char ch = sc.next().charAt(0);
	    if(Character.isUpperCase(ch)){
	        System.out.println("A");
	    } else{
	        System.out.println("a");
	    }
	}
}

Measured memory_bytes: 35428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

char g[30][30];

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    int H,W;
    cin >> H >> W;

    vector<pair<int,int>> safe;
    rep(i,H){
        rep(j,W){
            cin >> g[i][j];
            if(g[i][j] == '.'){
                safe.PB(MP(i,j));
            }
        }
    }

    ll c_max = 0;

    rep(i,sz(safe)-1){
        for(int j = i+1;j < sz(safe);j++){
            pii st = safe[i];
            pii gl = safe[j];

            int cost[30][30];

            memset(cost,0,sizeof(cost));

            queue<pii> q;
            q.push(st);


            while(!q.empty()){
                pii tmp = q.front();
                q.pop();

                if(tmp.first > 0 && g[tmp.first-1][tmp.second] == '.' && !cost[tmp.first-1][tmp.second]){
                    q.push(MP(tmp.first-1,tmp.second));
                    cost[tmp.first-1][tmp.second] = cost[tmp.first][tmp.second] + 1;
                }

                if(tmp.first < H-1 && g[tmp.first+1][tmp.second] == '.' && !cost[tmp.first+1][tmp.second]){
                    q.push(MP(tmp.first+1,tmp.second));
                    cost[tmp.first+1][tmp.second] = cost[tmp.first][tmp.second] + 1;
                }

                if(tmp.second > 0 && g[tmp.first][tmp.second-1] == '.' && !cost[tmp.first][tmp.second-1]){
                    q.push(MP(tmp.first,tmp.second-1));
                    cost[tmp.first][tmp.second-1] = cost[tmp.first][tmp.second] + 1;
                }

                if(tmp.second < W-1 && g[tmp.first][tmp.second+1] == '.' && !cost[tmp.first][tmp.second+1]){
                    q.push(MP(tmp.first,tmp.second+1));
                    cost[tmp.first][tmp.second+1] = cost[tmp.first][tmp.second] + 1;
                }

            }

            chmax(c_max,cost[gl.first][gl.second]);
        }
    }

    cout << c_max << endl;



}

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

using namespace std;

int n=0;
int cnt=0;

int main()
{
	cin >> n;
	for (int i=1; i<=n; i++)
	{
		if (i%10==0)
			continue;
		int ii=i;
		int f=0,l=0;
		while (ii)
		{
			l = ii%10;
			ii/=10;
		}
		f = i%10;
		if (f==l && f<=n){
			cnt++;
		}
		int mx=0;
		for (int j=0; j<5; j++)
		{
			f*=10;
			int cc = n-f-l;
			if (cc<0)
				continue;
			if (min(cc/10, mx)>=0){
				cnt+=min(cc/10, mx)+1;
			}
			mx*=10;
			mx+=9;
		}	
	}
	cout << cnt;
	return 0;
}



Measured memory_bytes: 256
<?php
//error_reporting(0);
$s = trim(fgets(STDIN));
$Q = (int)trim(fgets(STDIN));
//list($A,$B) = explode(" ",trim(fgets(STDIN)));
//$a[] = array_map('intval',explode(" ",trim(fgets(STDIN))));

$f="";
$b="";
$status = false;
for($i=0;$i<$Q;$i++) {
  $q = explode(" ",trim(fgets(STDIN)));
  if ($q[0]==1) {
    $status = !$status;
  }
  else {
    if ((!$status && $q[1]==1) || ($status && $q[1]==2)) {
      $f = $q[2].$f;
    }
    else {
      $b .= $q[2];
    }
  }
}
$s = $f . $s . $b;
if ($status) $s = strrev($s);
printf("%s\n",$s);


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

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

    switch(n%10){
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    case 3:
        cout << "bon" << endl;
        break;
    default:
        cout << "hon" << endl;
        break;
    }

    return 0;
}



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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second

ll M,N;
vector<pair<ll,ll>> A;

int main(){
  cin >> N >> M;
  pair<ll,ll> a;
  for(int i=0;i<N;++i){
    cin >> a.first >> a.second;
    A.pb(a);
  }
  sort(A.begin(),A.end());
  ll ans = 0;
  ll rec = 0;
  ll key = 0;
  while(1){
    if(ans==M) break;
    if(A[key].second+ans<=M){
      ans+=A[key].second;
      rec+=A[key].first*A[key].second;
      key++;
    }else{
      rec+=A[key].first*(M-ans);
      break;
    }
  }
  cout << rec << endl;
  return 0;

}

Measured memory_bytes: 2420
//Rooted Trees

#include<stdio.h>
#define N 100005
#define NILL -1

struct Node{
  int a,b,c;
};

struct Node tree[N];
int n, dep[N];

void print(int u)
{
  int i,imp;
  printf("node %d: ",u);
  printf("parent = %d, ",tree[u].a);
  printf("depth = %d, ",dep[u]);

  if(tree[u].a == NILL)
    {
      printf("root, ");
    }else if(tree[u].b == NILL)
    {
      printf("leaf, ");
    }else printf("internal node, ");

  printf("[");
  for(i = 0,imp = tree[u].b; imp != NILL; i++, imp = tree[imp].c)
    {
      if(i == 0) printf("%d",imp);
      else printf(", %d",imp);
    }
  printf("]\n");
}

int work(int u, int a)
{
  dep[u] = a;
  if(tree[u].c != NILL) work(tree[u].c,a);
  if(tree[u].b != NILL) work(tree[u].b,a+1);
}

int main()
{
  int i,j,b,c,imp,k,x,rt;
  scanf("%d",&n);

  for(i = 0; i < n; i++)
    {
      tree[i].a = tree[i].b = tree[i].c = NILL;
    }

  for(i = 0; i < n; i++)
    {
      scanf("%d %d",&x,&k);
      for(j = 0; j < k; j++)
	{
	  scanf("%d",&imp);
	  if(j == 0) tree[x].b = imp;
	  else tree[b].c = imp;
	  b = imp;
	  tree[imp].a = x;
	}
    }

  for(i = 0; i < n; i++)
    {
      if(tree[i].a == NILL) c = i;
    }

  work(c,0);

  for(i = 0; i < n; i++)  print(i);
  
  return 0;
}



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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    long long res = 0;
    long long sum = 0;
    int r = 0;
    for (int l = 0; l < n; l++)
    {
        while ((r < n) && (sum ^ a[r]) == (sum + a[r]))
	{
		sum += a[r];
		r++;
	}
	res += r - l;
	if (l == r)
	{
		r++;
	}
	else
	{
		sum -= a[l];
	}
    }

    cout << res << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
typedef pair<int,int> pi;
template <typename T> void chmax(T& a, T b) {a = max(a,b);}
template <typename T> void chmin(T& a, T b) {a = min(a,b);}
//#define cerr if (0) cout

int s,w;

int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	cin >> s >> w;
	cout << (s>w?"safe":"unsafe");
	return 0;
}


Measured memory_bytes: 3624
n = gets.to_i
a = n.times.map{gets.to_i}
a.sort!
x1 = [-1]
x2 = [1]
y = [1]
if n.odd?
    for i in 1..n-1
        if i == n-1
            x1 << -1
        else
            if i.odd?
                x1 << 2
            else
                x1 << -2
            end
        end
        if i == n-1
            x2 << 1
        else
            if i.odd?
                x2 << -2
            else
                x2 << 2
            end
        end
    end
    m = []
    s = []
    t = []
    x1.sort!
    x2.sort!
    for i in 0..n-1
        s << x1[i]*a[i]
        t << x2[i]*a[i]
    end
    puts [s.inject(:+),t.inject(:+)].max
else
    for i in 1..n-1
        if i == n-1
            y << -1
        else
            if i.odd?
                y << -2
            else
                y << 2
            end
        end
    end
    m = []
    y.sort!
    for i in 0..n-1
    m << y[i]*a[i]
    end
    puts m.inject(:+)
end

Measured memory_bytes: 8048
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

mat mul(mat &A, mat &B){
    mat C(A.size(), vll(B[0].size()));
    rep(i,A.size()){
        rep(k,B.size()){
            rep(j,B[0].size()){
                C[i][j]=(C[i][j]^(A[i][k]&B[k][j]));
            }
        }
    }
    return C;
}

mat pow(mat A,ll n){
    mat B(A.size(), vll(A.size()));
    rep(i,A.size()){
        B[i][i]=(1ll<<32)-1;
    }
    while(n>0){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n>>=1;
    }
    return B;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin>>s;
    rep(i,s.size()-8){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define for(i,a,b) for(int i=a;i<b;i++)
#define all(a) a.begin(),a.end()
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
 
int main() {
  ll a;
  ci(a);
  vec b(a);
  for(i,0,a)
    ci(b[i]);
  string c="Yes";
  reverse(all(b));
  for(i,1,a){
    if(b[i]>b[i-1]+1){
      c="No";
      break;
    }
    if(b[i]==b[i-1]+1)
      b[i]--;
  }
  co(c);
}

Measured memory_bytes: 1024
import sys
n,m,X,Y=map(int,input().split())
z=0
x=list(map(int,input().split()))
y=list(map(int,input().split()))
for i in range(Y+1):
    if max(x)<i and min(y)>=i and X<i<=Y:
        print('No War')
        sys.exit()
print('War')


Measured memory_bytes: 3060
s = int(input())
ans = -999
ans_list = []
counter = 1
ans_list.append(s)
while   True:
    counter += 1
    if s%2 == 0:
        s = s//2
    else:
        s = 3*s +1

    if  s in ans_list:
        ans = counter
        break
    elif  counter > 1000000:
        break
    ans_list.append(s)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define itn int
#define vpii vector<pii>
#define pdd pair<double,double>
#define vll vector<ll>

typedef long long ll;

using namespace std;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vi a(n);
	vi ans(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) ans[a[i] - 1] = i + 1;
	for (int i = 0; i < n; i++) cout << ans[i] << " ";
	return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<functional>
using namespace std;

#define INF 1<<21
#define DIV 1000000007

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

int main() {
  int n, a[105];
  cin >> n;
  for (int i = 0; i < n; i++) {
	cin >> a[i];
  }
  sort(a, a + n);
  cout << a[n - 1] - a[0] << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <deque>
#include <math.h>
#include <cstring>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <stack>
#include<cassert>
#include <cfloat>
#include <list>
using namespace std ;
#define ll long long
#define submitStage int TCF = 1 ;
#define testStage int TCF = 1000 ;
#define testMyStupedCode TCF--
void FastInputOutput(){
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
void ReadFromFile( string name , string extention ){
    string fullPath = name + "." + extention ;
    freopen( fullPath.c_str() , "r" , stdin ) ;
}
inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}
inline char C(){
    char c ;
    scanf( "%c" , &c ) ;
    return c ;
}
inline ll power(ll x, ll p, ll m){
    ll res = 1;
    while(p){
        if(p & 1)
            res = (res * x) % m;
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}
long double ModLog(long double base, long double x) {
    return (logl(x) / logl(base));
}

const int N = 1e5 + 5;
ll dp[N];
int w[101], v[101];
ll inf = 1e13 + 5, n;
int main(){
     //freopen("//Users//Mr.X//Desktop//tests//tst.text", "r", stdin);
     n = D();
     int W = D();
     int V = 0;
     for(int i = 0; i < n; ++i){
          w[i] = D(), v[i] = D();
          V += v[i];
     }
     for(int i = 0; i <= V; ++i)
          dp[i] = inf;
     dp[0] = 0;
     int ans = 0;
     for(int i = 0; i < n; ++i)
         for(int j = V - v[i]; j >= 0; --j){
               dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
               ans = max(ans, (j + v[i]) * (dp[j + v[i]] <= W));
         }
     printf("%d", ans);
     return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <set>

using namespace std;

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

	string s;
	set<string> st;
	for (int i = 0; i < n; i++) {
		cin >> s;
		st.insert(s);
	}
	cout << st.size() << endl;
	
	return 0;
}

Measured memory_bytes: 19252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
template<typename T> T factorial(T n){
    if(n==1) return 1;
    else return n*factorial(n-1)%MOD;
}
template<typename T> T Pow(T x, T n, T m){
    if(n == 0) return 1;
    if(n % 2 == 0) return Pow(x * x % m, n / 2, m);
    else return x * Pow(x, n - 1, m) % m;
}
template<typename T> T combination(T n, T k, T m){
    return factorial<T>(n) * Pow<T>(factorial(k), m-2, m) % m * Pow<T>(factorial(n-k), m-2, m) % m;
}
struct edge{
    int to; // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using graph = vector<vector<edge>>;
using Graph = vector<vector<int>>;

int main(){
    ll x; cin >> x;
    ll ans = 0;
    ans += (x / 500) * 1000;
    ans += ((x%500)/5) * 5;
    cout << ans << endl;
    return 0;
}

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


int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int sum=0;
  for(auto& a : A){
    cin >> a;
    sum+=a;
    a *= 4 * M;
  }
  sort(A.begin(), A.end());
  int num_item = distance(lower_bound(A.begin(), A.end(), sum), A.end());
  cout << (num_item>=M?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
a,b,c,d = list(map(int, input().split()))
flag = 0
while a > 0 and c > 0:
    if flag == 0:
        c -= b
        flag = 1
    else:
        a -= d
        flag = 0
if a <= 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 9168
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int n,m;
    cin>>n>>m;
    
    cout<<(n-1)*(m-1)<<endl;
    
    
    return 0;
}






Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


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

  int A, B;
  cin >> A >> B;
  if (A == B) {
    cout << "Draw" << endl;
  } else if (A == 1 || (A > B && B > 1)) {
    cout << "Alice" << endl;
  } else {
    cout << "Bob" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    char a,b;
  string x;
  cin>>x;
  if(x.size()>=3){
      a = x.at(0);
      b = x.at(x.size() -1);
      cout<<a<<x.size()-2<<b<<endl;
  }
 else if(x.size()==1){
      cout<<x.at(0)<<endl;
  }
  else if(x.size() == 2){
      cout<<x.at(0)<<x.at(1)<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

constexpr int MOD = 100'000;

int S[100001];

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

    int s;
    for (int i = 1; i < n; i++) {
        cin >> s;
        S[i] = S[i - 1] + s;
    }

    int ans = 0;

    int a, pos = 0;
    for (int i = 0; i < m; i++) {
        cin >> a;
        ans += abs(S[pos] - S[pos + a]);
        ans %= MOD;
        pos += a;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3484
#include <bits/stdc++.h>  // ver2.2.0
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0 * 10^18 (MAXの1/3くらい)
#define MOD 1000000007  //  10^9 + 7
using namespace std;
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ
 
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}

Vi a(0);

bool ser(int n){
  int l = a.size();
  int L = 0,R = l,mid = (L+R)/2;
  
  while(L<R){
    if(a[mid]==n) return true;
    else if(a[mid]>n) R = mid;
    else if(a[mid]<n) L = mid+1;
    
    mid = (L+R)/2;
  }
  return false;
}

signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,m,er;
  cin >> n;
  
  rep(i,0,n) {
    cin >> er;
    a.pb(er);
  }

  cin >> m;
  int qw,ans=0;
  rep(i,0,m){
    cin >> qw;
    if(ser(qw)) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n,m;
  std::cin>>n>>m;
  int h[n+1];
  h[0]={0};
  for(int i=1; i<=n; ++i)
    std::cin>>h[i];

  int a,b;
  std::vector<int> vec[n+1];
  while(m--){
    std::cin>>a>>b;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }

  bool flag=true;
  int count = 0;
  for(int i=1; i<=n; ++i){
    flag = false;
    if(vec[i].begin() == vec[i].end()){
      ++count;
      flag=true;
    }
    for(auto j=vec[i].begin(); j<vec[i].end(); ++j){
      if(h[i] <= h[*j]){
        flag = true;
      }
    }
    if(!flag){
      ++count;
    }
  }
  std::cout<<count<<std::endl;
}


Measured memory_bytes: 9052
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

bool sortinrev(const pair<int,int> &a,  const pair<int,int> &b) { 
       return (a.sd > b.sd); 
}

//START OF CODE ->->->->->->->

void solve()
{
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    rep(i,0,a.size()){
        cin>>a[i];
    }
    vector< pair<int,int> > p;
    rep(i,0,m){
        int b,c;
        cin>>b>>c;
        p.pb(mp(b,c));
    }
    sort(all(p),sortinrev);
    sort(all(a));
    // rep(i,0,p.size()){
    //     out2(p[i].ft,p[i].sd);
    // }
    int j = 0;
    rep(i,0,p.size()){
        int cnt = 0;
        while( a[j] <= p[i].sd && cnt < p[i].ft ){
            a[j] = p[i].sd;
            j++;
            cnt++;
        }
    }
    int sum = 0;
    // rep(i,0,a.size()){
    //     out1(a[i]);
    // }
    rep(i,0,a.size()){
        sum += a[i];
    }
    cout<<sum<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 6096