akhauriyash/Code-Regression huggingface dataset:
def main():
    N,M,K = map(int,input().split())
    MOD = 998244353
    
    if M == 1:
        if K == N-1:
            print(1)
        else:
            print(0)
        exit()
    
    fac = [0]*(N+1)
    fac[0],fac[1] = 1,1
    
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    def comb(x,y):
        return (fac[x]*pow(fac[y],MOD-2,MOD)*pow(fac[x-y],MOD-2,MOD))%MOD
    
    ans = 0
    base = [1,pow(M-1,N-K-1,MOD)]
    for i in range(K+1):
        base.append((base[-1]*(M-1))%MOD)

    for i in range(K+1):
        ret = comb(N-1,i)*(M*base[-i-2])
        ans += ret
    
    print(ans%MOD)
    
if __name__ == "__main__":
    main()


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

const int MAXN = 1000 + 10;

string s;
char mp[MAXN];

int main() {
  	cin >> s;

  	for (int i = 0; i < s.size(); i++)
    	mp[s[i]] = true;
	
	if (!(mp['S'] ^ mp['N']) && !(mp['E'] ^ mp['W'])) 
		cout << "Yes" << '\n';
	else
		cout << "No" << '\n';
	return 0;
}


Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int n,A,B;
int dp[50][500][500];
int a[50],b[50],c[50];
int main(void){
    cin >> n >> A >> B;
    rep(i,n)cin >> a[i] >> b[i] >> c[i];
    const int INF = 1001001001;
    rep(i,50)rep(j,500)rep(k,500)dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    rep(i,n)rep(j,500)rep(k,500){
        dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
        if(j - a[i] >= 0 and k - b[i] >= 0){
            mins(dp[i+1][j][k],dp[i][j - a[i]][k - b[i]] + c[i]);
        }
    }
    int ans = INF;
    rep(i,500)rep(j,500){
        if(!i or !j)continue;
        if(i * B == j * A){
            mins(ans,dp[n][i][j]);
        }
    }
    if(ans == INF)ans = -1;
    cout << ans << endl;
    return 0 ;
}

Measured memory_bytes: 49024
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	string st;
	cin >> n >> st;
	stack<char> stc;
	for(ll i=0; st[i]; i++){
		if(stc.empty())
			stc.push(st[i]);
		else if(stc.top() != st[i])
			stc.push(st[i]);
	}
	cout << stc.size();
	return 0;
}

Measured memory_bytes: 3804
using System.Collections.Generic;
using System.Linq;
public class PictureMatching
    {
        private static int[] Item;

        public static void Main(string[] args)
        {
            Input();
            Method();
            System.Console.ReadLine();
        }

        private static void Input()
        {
            System.Console.ReadLine();
            Item = ToIntArray(System.Console.ReadLine().Split(' '));
        }

        private static void Method()
        {
            int cnt = 0;
            for (int i = 0; i < Item.Length - 1; i++)
            {
                int mini = i;
                for (int j = i; j < Item.Length; j++)
                {
                    if (Item[j] < Item[mini])
                    {
                        mini = j;
                    }
                }
                if (mini != i)
                {
                    var temp = Item[mini];
                    Item[mini] = Item[i];
                    Item[i] = temp;
                    cnt++;
                }
            }
            ConsoleWrite();
            System.Console.WriteLine(cnt);
        }

        private static void ConsoleWrite()
        {
            for (int i = 0; i < Item.Length; i++)
            {
                System.Console.Write(Item[i]);
                if (i != Item.Length - 1)
                {
                    System.Console.Write(" ");
                }
            }
            System.Console.WriteLine("");
        }

        private static int[] ToIntArray(string[] str)
        {
            IEnumerable<int> intArray = str.Select(x => int.Parse(x));
            return intArray.ToArray();
        }
}

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

int main(){
  int x[6];
  for(int i=1;i<6;i++){
    cin>>x[i];
  }
  for(int i=1;i<6;i++){
    if(x[i]==0){
      cout<<i<<"\n";
      return 0;
    }
  }
}

Measured memory_bytes: 3548
#include <iostream>

using namespace std;

int main(){

	int n = 0;
	int num[1000] = { 0 };

	cin >> n;

	for (int i = 0; i <= n; i++) {

		cin >> num[i];

	}

	for (int i = n - 1; i > 0; i--) {

		cout << num[i] << " ";

	}

	cout << num[0] << endl;
	

	return 0;

}



Measured memory_bytes: 3088
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, D = MI()
    X = [0]*N
    Y = [0]*N
    ans = 0
    for i in range(N):
        X[i], Y[i] = MI()
        if X[i]**2 + Y[i]**2 <= D **2:
            ans += 1



    
    print(ans)

if __name__ == "__main__":
	main()

Measured memory_bytes: 24660
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>

using namespace std;

typedef complex<double> P;

const int N = 20;
const double INF = -1.0;

int n;
double r, s, e[N][N][N], d[N][N][10005], t, dist;
P a, b;
vector<P> in;

main(){
  cin >> n >> r >> s;
  s *= M_PI / 180.0;
  for(int i=0;i<n;i++){
    cin >> a.real() >> a.imag();
    in.push_back(a);
  }
  fill(e[0][0], e[N][0], INF);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i == j) continue;
      for(int k=0;k<n;k++){
        if(j == k) continue;
        a = in[i] - in[j];
        b = in[k] - in[j];
        t = acos(real(conj(a) * b) / (abs(a) * abs(b)));
        if(M_PI - t <= s) e[i][j][k] = abs(b);
      }
    }
  }
  fill(d[0][0], d[N][0], -1.0);
  int ans = 0;
  for(int i=1;i<n;i++){
    if(abs(in[0] - in[1]) <= r){
      d[0][i][1] = abs(in[0] - in[i]);
      ans = 1;
    }
  }
  for(int k=1;(double)k<r+1;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(d[i][j][k] < 0.0) continue;
        ans = max(ans, k);
        for(int l=0;l<n;l++){
          if(e[i][j][l] < 0.0) continue;
          dist = d[i][j][k] + e[i][j][l];
          if(dist > r) continue;
          if(d[j][l][k+1] < 0.0) d[j][l][k+1] = dist;
          else if(d[j][l][k+1] > dist) d[j][l][k+1] = dist;
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll l = 4*a * b;
    if (c-b-a < 0) {
        cout << "No" << endl;
        return 0;
    }
    else {
        ll r = (c-b-a)*(c-b-a);
        if (l < r) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

  int n,y1,y3,mb,ms,y1000;
  int i,j,k;
  int a,b,c,e;
  int y[102] = {0};
  int m[102] = {0};
  int d[102] = {0};
  int sum[102] = {0};

  scanf("%d",&n);

  y1 = 20 + 19 + 20 + 19 + 20+ 19 + 20 + 19 + 20 +19;
  y3 = 20 * 10;
  a  = 1000 /3;
  b = 1000 - a -1;

  y1000 = a * y3 + b*y1;
  // printf("y1000 = %d\n" ,y1000); 


  for(i=0;i<n;i++) {
    a = b = c= e= 0;

    scanf("%d %d %d" ,&y[i],&m[i],&d[i]);

    a = y[i] / 3;
    b = y[i] - a - 1;

    sum[i] = a * y3 + b * y1;
    //   printf("sumy = %d\n",sum[i]);

    c = m[i] / 2;
    e = m[i] - c-1;

    if(y[i] % 3 != 0) {
    sum[i] = sum[i] + 20*c + 19 * e;

    } else sum[i] = sum[i] + 20 *(m[i] - 1)-5;

    //    printf("summ = %d\n",sum[i]);

    sum[i] = sum[i] + d[i]- 1;
   

    printf("%d\n",y1000 - sum[i]);

  }

  return 0;

}

Measured memory_bytes: 596
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int D,N;
    cin>>D>>N;
    double ret=pow(100,D);
    if(N!=100){
        ret*=N;
    }else{
        ret*=101;
    }
    cout<<int(ret)<<endl;
}

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

using namespace std;

long long a,b,c,d,n,m,i,j,t[200005];
string s,q;

bool prim(int a)
{
    for (int i=2; i<=sqrt(a); i++)
        if (a%i==0) return 0;
    return 1;
}

int main() 
{
    cin>>a;
    while (!prim(a)) a++;
    cout<<a;
}

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

using namespace std;

string s;

int k;

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

    cin >> s >> k;

    vector <string> v;

    for(int i = 0; i < s.size(); ++i)
    {
        string a;
        for(int j = i; j < s.size(); ++j)
        {
            a.push_back(s[j]);
            v.push_back(a);
            if(a.size() == 5)
                break;
        }
    }

    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());

    cout << v[k - 1] << '\n';

    return 0;
}


Measured memory_bytes: 1660
from collections import Counter


def cmb(a):
    return a * (a - 1) // 2


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    s = sum([cmb(x) for x in c.values()])
    for i in a:
        print(s - c[i] + 1)


if __name__ == '__main__':
    resolve()


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

int bubble_sort(int n,int A[]){
    int sum=0;int x;
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            if(A[j]<A[j-1]){
                x=A[j];
                A[j]=A[j-1];
                A[j-1]=x;
                sum++;
            }
        }
    }
    return sum;
}

int main(){
    int n;
    cin>>n;
    int A[n];
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    int sum=bubble_sort(n,A);
    for(int i=0;i<n;i++){
        if(i!=0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",sum);
}


Measured memory_bytes: 3224
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

signed main()
{
    int h, w;
    cin >> h >> w;
    
    vvi miyage(h, vi(w));
    
    rep(i, h) rep(j, w){
        cin >> miyage[i][j];
    }
    
    vector<vvi> dp(h+w-1, vvi(h, vi(h)));
    dp[0][0][0] = miyage[0][0];
    
    reps(k, 1, h+w-1){
        rep(i1, h) rep(i2, h){
            int j1 = k - i1;
            int j2 = k - i2;
            if(j1<0 || w<=j1 || j2<0 || w<=j2) continue;
            
            int a1 = miyage[i1][j1];
            int a2 = miyage[i2][j2];
            int sum = i1 == i2 ? a1 : a1 + a2;
            
            int di1[] = {0, -1, 0, -1};
            int di2[] = {0, 0, -1, -1};
            rep(m, 4){
                int pi1 = i1 + di1[m];
                int pi2 = i2 + di2[m];
                if(pi1 >= 0 && pi2 >= 0){
                    dp[k][i1][i2] = max(dp[k][i1][i2], dp[k-1][pi1][pi2] + sum);
                }
            }
        }
    }
    
    cout << dp[h+w-2][h-1][h-1] << endl;
}


Measured memory_bytes: 66048
/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>
 
#define rep(i, n) for(int i = 0; i < n; i++)
 
//const long long INF = 1LL << 60;
const long long MOD = 1000000007;
using ll = long long;


int main()
{
    int N;
    std::cin >> N;
    std::vector<ll> A(N);

    long long plus = 0;
    rep(i, N)
    {
        int tmp;
        std::cin >> tmp;
        plus += tmp;
        plus = plus % MOD;
        A[i] = tmp;
    }

    ll ans = 0;
    rep(i, N-1)
    {
        plus -= A[i];

        // 10億7で割っているので底につくことがある 
        if(plus < 0)
        {
            plus += MOD;
        }
        ans += ( plus * A[i] ) % MOD;
        ans = ans % MOD;
    }
    
    std::cout << ans << std::endl;

    return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b,k; cin>>a>>b>>k;
  rep(i,k){
    if(i%2==0){
      if(a%2) a--;
      b+=a/2;
      a/=2;
    }else{
      if(b%2) b--;
      a+=b/2;
      b/=2;
    }
  }
  cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
tree = [[] for _ in range(n)]
for _i in range(n-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

visit = [-1 for _ in range(n)]
f, s = 0, 0
f_q = deque([0])
s_q = deque([n-1])

while f_q or s_q:
    g = []
    while f_q:
        p = f_q.popleft()
        for i in tree[p]:
            if visit[i] < 0:
                f += 1
                g.append(i)
                visit[i] = 0
    f_q = deque(g)

    g = []
    while s_q:
        p = s_q.popleft()
        for i in tree[p]:
            if visit[i] < 0:
                s += 1
                g.append(i)
                visit[i] = 0
    s_q = deque(g)
if f > s:
    print("Fennec")
else:
    print("Snuke")

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MAX3(a, b, c) ((a) > (MAX(b, c)) ? (a) : (MAX(b, c)))
#define MIN3(a, b, c) ((a) < (MIN(b, c)) ? (a) : (MIN(b, c)))

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

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    int forward = 0, backward = 0;
    rep(i, m) {
        int p;
        cin >> p;
        if (p <= x)
            forward++;
        else
            backward++;
    }
    cout << min(forward, backward) << endl;

    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int res = 0;
    for (int i = a; i <= b; i++) {
        if (i / 10000 == i % 10 && (i % 10000) / 1000 == (i % 100) / 10) res++;
    }
    cout << res << endl;
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> road(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    road[a].push_back(b);
    road[b].push_back(a);
  }
  vector<int> orient(n, -1);
  queue<int> bfs;
  bfs.push(0);
  while (!bfs.empty()) {
    int cur = bfs.front();
    bfs.pop();
    for (int s : road[cur]) {
      if (orient[s] != -1) continue;
      orient[s] = cur;
      bfs.push(s);
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++)
    cout << orient[i] + 1 << endl;
  return 0;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	ll n;
	cin >> n;
	set<ll>s;
	ll cur = n;
	s.insert(cur);
	for(int i=2; i<=sqrt(n); i++){
		cur = n;
		while(cur%i==0){
			cur/=i;
		}
		if(cur%i==1)s.insert(i);
	}
	cur = n-1;
	if(cur>1){
		s.insert(cur);
		for(int i=2; i<=sqrt(cur); i++){
			if(cur%i==0){
				if(!s.count(i))s.insert(i);
				ll cur2 = cur/i;
				if(!s.count(cur2))s.insert(cur2);
			}
		}
	}
	//for(auto x:s)cout << x << endl;
	cout << s.size() << endl;
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define REP(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define REPS(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define RREP(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define RREPS(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define BIT(n) ((int)(1) << (n))
#define ALL(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n, w;
    cin >> n >> w;
    std::vector<int> wei(n);
    std::vector<int> val(n);
    for (int i = 0; i < n; i++) {
        cin >> wei[i] >> val[i];
    }
    std::vector<int> dp(w + 1, 0);
    for (int i = 0; i < n; i++) {
        for (int j = w; j >= 0; j--) {
            if (j == 0) {
                chmax(dp[wei[i]], val[i]);
            } else if (dp[j] == 0) {
                continue;
            } else {
                if (j + wei[i] <= w) {
                    chmax(dp[j + wei[i]], dp[j] + val[i]);
                }
            }
        }
    }
    int out = 0;
    for (int i = 0; i <= w; i++) {
        chmax(out, dp[i]);
    }
    cout << out << endl;
    return 0;
}

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

using namespace std;

int main()
{int N,K; cin >> N >> K;
 vector<long long> h(N);
 for (long long i = 0; i < N; i++)
 { cin >> h[i];}
 sort(h.begin(),h.end());
 long long active = h[K-1] - h[0];
 
 for(int i = 0; i <= N - K ; i++)
  {if(active > h[i - 1 + K] - h[i])
   {active = h[i - 1 + K] - h[i];}}
 cout << active << endl;}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long x=sc.nextLong(),t=100,count=0;;
    while(t<x) {
    	t+=t*0.01;
    	//System.out.println(t);
    	count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 35748
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static string ReadLine() { return Console.ReadLine().Trim(); }
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    static void Main() {
        int n = ReadInt();
        var xs = new int[n];
        var min = new int[n]; // min[i] = 0..i ???????°????
        var max = new int[n]; // max[i] = i..n-1 ????????§???
        for (int i = 0; i < n; i++) {
            xs[i] = ReadInt();

            if (i == 0) {
                min[i] = xs[i];
            }
            else {
                min[i] = Math.Min(min[i-1], xs[i]);
            }
        }

        max[n-1] = xs[n-1];
        for (int i = n-2; i >= 0; i--) {
            max[i] = Math.Max(max[i+1], xs[i]);
        }

        int ans = max[1] - min[0];
        for (int i = 1; i < n; i++) {
            ans = Math.Max(ans, max[i] - min[i-1]);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 19932
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
#include <numeric>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	for (;;) {
		int N;
		cin >> N;
		if (cin.fail()) break;

		vector<int> A(N);
		for (int i = 0; i < N; i++) {
			cin >> A[i];
		}
		int B;
		for (int i = 0; i < N; i++) {
			cin >> B;
			A[i] -= B;
		}
		sort(A.begin(), A.end());

		int result = 0;
		ll sum = 0;
		for (int i = 0; i < N && A[i] < 0; i++) {
			sum += A[i];
			result++;
		}
		for (int i = N - 1; sum < 0 && i >= 0 && A[i] > 0; i--) {
			sum += A[i];
			result++;
		}
		cout << (sum < 0 ? -1 : result) << endl;
	}

	return 0;
}


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

int main() {
	int n, k;
	while ( cin >> n >> k ) {
		int hei[ n+k+5 ]; memset( hei, 0, sizeof (hei) );
		
		for (int i = 0; i < n; ++i) cin >> hei[i];
		
		int cost[ n+k+5 ]; fill( cost, cost+n+k+5, 1 << 30 );
		cost[0] = 0;
		
		for (int i = 0; i < n-1; ++i) {
			for (int j = 1; j <= k; ++j) {
				cost[ i+j ] = min( cost[ i+j ], cost[i] + abs( hei[i] - hei[ i+j ] ) );
			}
		}
		
		cout << cost[ n-1 ] << '\n';
	}
	return 0;
}


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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int N = 7E2 + 10;

int n, m;
int a[N][N];
int vis[N];
int sum;

bitset<N> f;

void DFS(int u){
	eput(u, vis[u]);
	sum += vis[u];
	for (int i = 1; i <= a[u][0]; ++i){
		int v = a[u][i];
		if (vis[v] == 0){
			vis[v] = -vis[u];
			DFS(v);
		}
		else if (vis[u] == vis[v]){
			puts("-1");
			exit(0);
		}
	}
}

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i){
		int u, v;
		scanf("%d%d", &u, &v);
		a[u][v] = a[v][u] = 1;
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (i != j && a[i][j] == 0)
				a[i][++a[i][0]] = j;

	f.set(0);
	eput(f.to_string().substr(f.size() - (n + 1)));
	int ssum = 0;
	for (int i = 1; i <= n; ++i)
		if (vis[i] == 0){
			sum = 0;
			vis[i] = 1;
			DFS(i);

			sum = abs(sum);
			ssum += sum;
			f |= f << sum;

			eput(sum);
			eput(f.to_string().substr(f.size() - (n + 1)));
		}
	int n1 = n - ssum >> 1;
	for (int i = ssum / 2; i >= 0; --i)
		if (f[i]){
			n1 += i;
			break;
		}
	int n2 = n - n1;
	eput(n1, n2);
	printf("%d\n", n1 * (n1 - 1) / 2 + n2 * (n2 - 1) / 2);
	return 0;
}


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

int main() {
int n;
cin >>n;
vector<int>A(n);
for(int &x : A) cin>>x;
int min = *min_element(A.begin(), A.end());
int max = *max_element(A.begin(), A.end());
int64_t ttl=accumulate(A.begin(), A.end(), 0LL);
printf("%d %d %ld",min,max,ttl);
cout << endl;
  return 0;
}


Measured memory_bytes: 3268
#include <iostream>
using namespace std;
int main(void){
  int a=0,b=0,n;
  string A,B;
  cin>>n;
  for(int i=0;i<n;i++){
      cin>>A>>B;
      if(A==B){
          a++;
          b++;
      }
      else if(A>B) a+=3;
      else b+=3;
  }
  cout<<a<<" "<<b<<endl;
  return 0;
  }



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  vector<int> a(5);
  rep(i,5){
    cin >> a.at(i);
  }
  int mintime = 100000000;
  rep(i,5){
    int hoge = 0;
    rep(j,5){
      if(i != j){
        hoge += ((a.at(j)+9)/10)*10;
      }
    }
    mintime = min(mintime,hoge+a.at(i));
  }
  cout << mintime << endl;
  
  
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define N 300000
 
int n,m,x,y,xb,p[N],q[N],dep[N];
bool vis[N];
vector<int> g[N];
 
bool dfs(int u,int fa){
	int s=0; vis[u]=1; dep[u]=dep[fa]+1;
	for (auto v:g[u])
		if (!vis[v]){
			s^=dfs(v,u);
		}
		else
			if (dep[v]>dep[u]){
				p[++xb]=u; q[xb]=v;
				s^=1;
			}
	if (s){p[++xb]=u; q[xb]=fa;}
	else{p[++xb]=fa; q[xb]=u;}
	return s^1;
}
 
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;++i){
		scanf("%d%d",&x,&y);
		g[x].push_back(y); g[y].push_back(x);
	}
	if (!dfs(1,0)){puts("-1"); return 0;}
	for (int i=1;i<=m;++i) printf("%d %d\n",p[i],q[i]);
	
	return 0;
}


Measured memory_bytes: 20992
def solve():
    N = int(input())
    S = input()
    white = [0] * (N+2)
    black = [0] * (N+2)
    for i in range(1,N+1):
        if S[i-1] == '.':
            white[i] = white[i-1] + 1
            black[i] = black[i-1]
        else:
            black[i] = black[i-1] + 1
            white[i] = white[i-1]
    
    ans = float('inf')
    for i in range(N+1):
        tmp = black[i] + white[-2] - white[i]
        ans = min(ans, tmp)
    
    print(ans)
    
if __name__ == '__main__':
    solve()

Measured memory_bytes: 43248
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


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

    int A, B;
    cin >> A >> B;

    string S;
    cin >> S;

    bool f = true;
    REP(i, S.size()) {
        if (i == A) {
            if (S[i] != '-') {
                f = false;
                break;
            }
        } else {
            if (S[i] - '0' > 9 || S[i] - '0' < 0) {
                f = false;
                break;
            }
        }
    }

    if (f) print("Yes");
    else print("No");


}


Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    int x;
    cin>>x;
    vector<ll> a;
    a.push_back(0);
    for(ll i=1;i<=100000;i++){
        ll k=i/2.0*(i+1);
        a.push_back(k);
    }
    cout<<lower_bound(a.begin(),a.end(),x)-a.begin()<<endl;
}

Measured memory_bytes: 4324
#include<bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define F(i,n) for(i=0; i<n; i++)

using namespace std;

typedef long long int ll;
const int N = 3e5 + 2;

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

    int t;
    cin >> t;
    string s = "ACL";
    while(t--)
        cout << s ;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];


int main () {
    vector<vector<int>>bingo(3,vector<int>(3));
    rep(i,3){
        rep(j,3){
            cin >> bingo.at(i).at(j); 
        }
    }

    int N;
    cin >>N;

    rep(i,N){
        int b;
        cin >> b;

        rep(i,3){
            rep(j,3){
                if(bingo.at(i).at(j) == b){
                    bingo.at(i).at(j) = -1;
                }
            }
        }
    }

    int naname1=0;
    int naname2=0;
    rep(i,3){
        int tate =0;
        int yoko =0;
        rep(j,3){
            tate += bingo.at(i).at(j);
            yoko += bingo.at(j).at(i);
        }
        if(tate == -3 || yoko == -3){
            cout <<"Yes" << endl;
            return 0;
        }
        naname1 += bingo.at(i).at(i);
        naname2 += bingo.at(2-i).at(i);
    }
    
    if(naname1 == -3 || naname2 == -3){
            cout <<"Yes" << endl;
            return 0;
    }else cout << "No" << endl;

    


}

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

namespace _0339
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            HashSet<string> a = new HashSet<string> { };
            for (int i = 0; i < n; i++)
            {
                int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
                Array.Sort(s);
                a.Add(s[0].ToString() + " " + s[1].ToString() + " " + s[2].ToString());
            }
            Console.WriteLine(n-a.Count());
        }
    }
}

Measured memory_bytes: 10136
#include<cstdio>
#include<string>
#include<utility>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,string> p;
typedef pair<string,string>c;
vector<c>change;
int N;
string E;
int main()
{
	for(;scanf("%d",&N),N;)
	{
		priority_queue<p,vector<p>,greater<p> >Q;
		change.clear();
		char a[12],b[12];
		for(int i=0;i<N;i++)
		{
			scanf("%s%s",a,b);
			change.push_back(make_pair(string(a),string(b)));
		}
		scanf("%s%s",a,b);
		E=string(b);
		Q.push(make_pair(0,string(a)));
		int f;
		for(f=0;!Q.empty();)
		{
			p tmp=Q.top();Q.pop();
			if(tmp.first>10||tmp.second.length()>10)continue;
			if(tmp.second==E)
			{
				printf("%d\n",tmp.first);
				f=1;
				break;
			}
			for(int i=0;i<change.size();i++)
			{
				string tag=change[i].first;
				string now=tmp.second;
				int idx=now.find(tag);
				for(;idx!=std::string::npos;)
				{
					now.replace(idx,tag.length(),change[i].second);
					idx=now.find(tag,idx+change[i].second.length());
				}
				if(now!=tmp.second)
					Q.push(make_pair(tmp.first+1,now));
			}
		}
		if(!f)
			puts("-1");
	
	}
	return 0;
}

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

int main() {
	int N,M;
	cin >> N>>M;
	vector<int>X(M);
	for (int n = 0; n < N; ++n) {
		int K;
		cin >> K;
		for (int m = 0;m<K;++m) {
			int num;
			cin >> num;
			num--;
			X[num]++;
		}
	}
	int ans = 0;
	for (int m = 0;m<M;++m) {
		if (N == X[m]) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps=1e-8;
int main() {
	int a, b, c;
	while (cin >> a >> b >> c, a) {
		int mi = (int)MOD; int mi2; P chk;
		for (int i = 0; i <= a*b||i<=c; i += a) {
			int s = i - c;
			if (s >= 0 && s%b == 0&&i/a+s/b<=mi) {
				if (i / a + s / b < mi) {
					mi2 = i + s; chk = { i / a,s / b };
				}
				mi = i / a + s / b;
				if (mi2 > i + s) {
					chk = { i / a,s / b };
				}
			}
			s = i + c;
			if (s >= 0 && s%b == 0 && i / a + s / b <= mi) {
				if (i / a + s / b < mi) {
					mi2 = i + s; chk = { i / a,s / b };
				}
				mi = i / a + s / b;
				if (mi2 > i + s) {
					chk = { i / a,s / b };
				}
			}
			s = c - i;
			if (s >= 0 && s%b == 0 && i / a + s / b <= mi) {
				if (i / a + s / b < mi) {
					mi2 = i + s; chk = { i / a,s / b };
				}
				mi = i / a + s / b;
				if (mi2 > i + s) {
					chk = { i / a,s / b };
				}
			}
		}
		cout << chk.first << " " << chk.second << endl;
	}
	return 0;
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int mod = 1000000007;
const int N = 1e6+10;
int a[2600], b[2600];
int fa[55];
int find(int u)
{
    return u == fa[u]?u :(fa[u] = find(fa[u]));
}
void init(int n)
{
    for (int i = 1; i <= n; i++)
        fa[i] = i;
}
int main() 
{
 //   freopen("in.txt", "r", stdin);
    int n, m;
    while (~scanf("%d%d", &n, &m))
    {
        for (int i = 0; i < m; i++)
            scanf("%d%d", a + i, b + i);
        int ans = 0;
        for (int i = 0; i < m; i++)
        {
            init(n);
            for (int j = 0; j < m; j++) if (i != j)
            {
                int x = find(a[j]);
                int y = find(b[j]);
                if (x != y)
                    fa[x] = y;
            }
            int t = fa[1], flag = 0;
            while (t != fa[t])
            {
                t = fa[t];
            }
            for (int j = 1; j <= n; j++)
            {
                int x = fa[j];
                while (x != fa[x])
                {
                    x = fa[x];
                }
                if (x != t)
                {
                    flag = 1;
                    break;
                }
            }
            ans += flag;
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

int main() {
    string S,T;
    string ans = "Yes";
    cin >> S >> T;

    for(int i = 0 ; i < S.size() ; i++){
        if(S.at(i)!=T.at(i)){
            ans = "No";
        }          
    }
    cout << ans << endl;
}


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

using namespace std;

int main(void) {
    int N;
    cin >> N;

    vector<int> B(N - 1);
    for (int i = 0; i < N - 1; i++) {
        cin >> B[i];
    }

    vector<int> A(N, 0);
    A[0]     = B[0];
    A[N - 1] = B[N - 2];

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

    long long ans = 0;
    for (int a : A) {
        ans += a;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int A, B; 
    char op;
    cin >> A >> op >> B;

    int ans;
    if (op == '+') {
        ans = A+B;
    }else {
        ans = A-B;
    }

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int a[10];
    int ans = MOD;
    int p[5];

    for (int i = 0; i < 5; i++)
    {
        cin >> a[i];
        p[i] = i;
    }

    do
    {
        int res = 0;

        for (int i = 0; i < 5; i++)
        {
            res = (res + 9) / 10;
            res *= 10;
            res += a[p[i]];
        }

        ans = min(ans, res);

    } while (next_permutation(p, p + 5));

    cout << ans << endl;
}

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

#define int long long

int n;
int a;
int f[100002]={0};

int cnt=0;

main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    f[a]++;
    if(f[a]>1)cnt++;
  }

  cout<<n-cnt-(cnt%2)<<endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll N,M;
ll A[305][305];
int main(){
  cin>>N>>M;
  for(ll i=0;i<N;i++)
    for(ll j=0;j<M;j++)
      cin>>A[i][j];
  ll left=0;ll right=N;
  while(1<right-left){
  ll mid=left+(right-left)/2;
    vector<ll>a(N);
    vector<bool>c(M+1,true);
    bool judge=false;
    for(ll x=0;x<M-1;x++){
      vector<ll>b(1+M);ll Max=0;ll I=0;
    for(ll i=0;i<N;i++){
    b[A[i][a[i]]]++;
      if(Max<b[A[i][a[i]]]){Max=b[A[i][a[i]]];I=A[i][a[i]];}
    }if(Max<=mid){judge=true;break;}
             c[I]=false;
          for(ll i=0;i<N;i++)
             while(!c[A[i][a[i]]])a[i]++;
       }if(judge)
            right=mid;
          else
            left=mid;
               }cout<<right<<endl;
  return 0;
}

Measured memory_bytes: 4328
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli ans = 6;
    lli a, b;
    cin >> a >> b;
    ans /= (a * b);
    out(ans);
}

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

#define ll long long int
#define mp make_pair
#define pb push_back
#define fi first
#define si second
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define AS 200001
#define mod 1000000007
string lcs(string a, string b) {
	int n = a.size();
	int m = b.size();
	int dp[n + 1][m + 1];
	for (int i = 0; i < n + 1; i++) {
		for (int j = 0; j < m + 1; j++) {
			if (i == 0 || j == 0) {
				dp[i][j] = 0;
			}
		}
	}
	for (int i = 1; i < n + 1; i++) {
		for (int j = 1; j < m + 1; j++) {
			if (a[i - 1] == b[j - 1]) {
				dp[i][j] = 1 + dp[i - 1][j - 1];
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	int i = n;
	int j = m;
	string ans = "";
	while (i > 0 and j > 0) {
		if (a[i - 1] == b[j - 1]) {
			ans.push_back(a[i - 1]);
			i--;
			j--;
		}
		else {
			if (dp[i][j - 1] > dp[i - 1][j]) {
				j--;
			}
			else {
				i--;
			}
		}
	}
	reverse(ans.begin(), ans.end());
	return ans;
}

int main() {
	fastIO
	string a, b;
	cin >> a >> b;
	cout << lcs(a, b);
}

Measured memory_bytes: 35456
# include <iostream>
# include <cstdio>
# include <cmath>
# include <cstring>
# include <string>
# include <cstdlib>
# include <algorithm>
# include <stack>
# include <queue>
# include <vector>
# define maxx (103)
# define Pi (3.14159265358979)
# define inf (2147483647)
using namespace std;
int read() {
	int x=0,f=1;
	char ch;
	while(ch<'0'||ch>'9')  {
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f*x;
}
int main() {

	int a,b;
	
	a=read();
	b=read();
	
	cout << max(a-b,0);

	return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  while (getline(cin, s), s != "0") {
    istringstream ss(s);
    int x;
    int t = 0, one = 0;
    while (ss >> x) {
      if (x == 1) one++;
      if (2 <= x && x <= 9) t += x;
      if (10 <= x && x <= 13) t += 10;
    }
    while (t + 11 + one - 1 <= 21 && one) {
      t += 11;
      one--;
    }
    t += one;
    cout << (t > 21 ? 0 : t) << endl;
  }
}

Measured memory_bytes: 3112