akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

void print(const list<char>& lst, bool f)
{
    string s;
    for (char ch : lst) s += ch;
    if (not f) reverse(s.begin(), s.end());
    cout << s << endl;    
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    string S; cin >> S;
    list<char> lst(S.begin(), S.end());
    bool normal = true;

    int Q; cin >> Q;
    while(Q--) {
        int T;
        cin >> T;
        switch(T) {
            case 1: {
                normal = !normal;
                break;
            }
            case 2: {
                int f; char c; cin >> f >> c;
                if (f == 1) {
                    if (normal) lst.push_front(c);
                    else lst.push_back(c);
                }
                if (f == 2) {
                    if (normal) lst.push_back(c);
                    else lst.push_front(c);
                }
                break;
            }
        }
        //print(lst, normal); 
    }
    print(lst, normal); 
}


Measured memory_bytes: 10452
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

const int NMAX = 100005;

vector<int> G[NMAX];
int ans = 0;

int dp[NMAX];
int k;

void dfs(int node) {
    dp[node] = 1;
    for (int to: G[node]) {
        dfs(to);
        dp[node] = max(dp[node], dp[to] + 1);
    }
    if (dp[node] == k) {
        dp[node] = -1;
        ans++;
    }
}

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n >> k;

    vector<int> A(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
    }
    if (A[1] != 1) {
        ans++;
    }

    for (int i = 2; i <= n; ++i) {
        G[A[i]].push_back(i);
    }
    for (int root: G[1]) {
        dfs(root);
        ans -= dp[root] == -1;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 11136
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        PriorityQueue<Integer> q=new PriorityQueue<>(Comparator.reverseOrder());
        Job[] a = new Job[n];
        for(int i = 0; i < n; i++){
            a[i] = new Job(scanner.nextInt()-1,scanner.nextInt());
        }
        Arrays.sort(a);
        long ans=0;
		int ain=0;
        for(int i = 0; i < m; i++){
            while(ain < n && a[ain].day == i){
                q.add(a[ain].salary);
                ain++;
            }
            if(!q.isEmpty()){
                ans += q.poll();
            }
        }
        System.out.println(ans);
    }
    static class Job implements Comparable<Job>{
		int salary,day;
		public Job(int day,int salary){
			this.salary=salary;
			this.day=day;
		}
		@Override
		public int compareTo(Job j){
			return this.day-j.day;
		}
	}
}

Measured memory_bytes: 89704
n = int(input())
import math
num = math.factorial(n)
dic={}
i = 2
ans = 1
while num != 1:
  cnt = 1
  while num%i == 0:
    num = num//i
    cnt+=1
  ans = ans*cnt
  i +=1
print(ans%(10**9+7))

Measured memory_bytes: 8964
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n;
ll ans;

int main()
{
    cin>>n;
    if(n % 2 == 1)
    {
        printf("0\n");
        return 0;
    }
    n /= 2;
    for(ll i = 5; i <= n; i *= 5)
    {
        ans += n / i;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
int n,m,a[1001];
typedef pair <int,int> P;
typedef pair<P,int> PP;

int solve(){
  PP t[1001];
  t[0]=PP(P((m/a[0])*a[0],a[0]),0);
  for(int i=1;i<n;i++){
    sort(t,t+i);
    P ima=t[0].f;
    int nx=((ima.f-1)/a[i])*a[i]+a[i];
    if(ima.f==nx&&ima.s>a[i]) nx+=a[i];
    if(m<nx)nx-=a[i];
    t[i]=PP(P(nx,a[i]),i);
  }
  sort(t,t+n);
  if(t[0].f==t[1].f)return n;
  return t[0].s+1;
 }

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<n;i++) cin>>a[i];
    cout<<solve()<<endl;      
  }
  return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
typedef long long int ll;
using namespace std;
int main(){
	ll N;
	ll K;
	ll x;
	vector<ll> h;
	cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>x;
		h.push_back(x);
	}
	sort(h.begin(),h.end());
	x=1000000000;
	for(int i=0;i<N-K+1;i++){
		if(h[i+K-1]-h[i]<x){
			x=h[i+K-1]-h[i];
		}
	}
	cout << x << endl;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 5005
int n, ans;
char a[N];
int main(){
	scanf("%d%s", &n, a + 1);
	for (register int i = 1; i <= n; ++i){
		int s = 0;
		for (register int j = 1; j <= n - i; ++j)
			a[j] == a[j + i] && s < i ? ++s, ans = std :: max(ans, s) : s = 0;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
import itertools
n, m = map(int, input().split())
path = [[False] * n for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True
ans = 0
for i in itertools.permutations(range(n), n):
    if i[0] == 0:
        for j in range(n):
            if j == n - 1:
                ans += 1
                break
            if not path[i[j]][i[j+1]]:
                break
print(ans)


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, k;
  cin >> n >> k;
  
  cout << (k>1 ? n-k : (ll)0) << newl;
  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = int64_t;

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

void solve(){
    string s;
    int res = 0;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '+'){
            res++;
        }else{
            res--;
        }
    }
    cout << res << endl;
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
using namespace std;
int N,M,s,c;
int main(){
    cin>>N>>M;
    unordered_map<int,int>m;
    for(int i=0;i<M;i++){
        cin>>s>>c;
        if(m.count(s)!=0&&m[s]!=c){cout<<-1<<endl;return 0;}
        m[s]=c;
    }
    for(int i=0;i<1000;i++){
        string num=to_string(i);
        if(num.size()!=N)continue;
        bool f=true;
        for(auto x:m)f&=(num[x.first-1]=='0'+x.second);
        if(f){cout<<num<<endl;return 0;}
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 384
N, K = map(int, input().split())
x = list(map(int, input().split()))

tmin = float('inf')

for i in range(N - K + 1):
    d = x[i + K - 1] - x[i]
    tmin = min(tmin, d + abs(x[i]), d + abs(x[i + K - 1]))

print(tmin)


Measured memory_bytes: 14384
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	int N,K;
	cin>>N>>K;
	ll V[N];
	ll reV[N];
	ll ans=0;
	rep(i,N) cin>>V[i];
	rep(i,N) reV[i]=V[N-1-i];
	for(int i=0;i<=K; i++){
		for(int j=0; j<=K-i; j++){
			ll as=0;
			int tmp[i+j]={};
			if(i+j>min(N,K)) break;
			int drop=K-i-j;
			rep(k,i){
				tmp[k]=V[k];
			}
			rep(k,j)
				tmp[k+i]=reV[k];
			
			sort(tmp,tmp+(i+j));
			//cout << i <<" "<<j<<" "<< drop <<" ";
			rep(k,min(drop,i+j)){
				if(tmp[k]<0){
					tmp[k]=0;
				}
			}
			rep(k,i+j){
				as+=tmp[k];
			}
			//cout << as << endl;
			ans=max(as,ans);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
// AOJ Volume 0 Problem 0034

#include <stdio.h>

int main(void)
{
	int l[10];
	int sum_l;
	float l1;
	int l12;
	int v1, v2;
	int i;

	while (scanf("%d,", &l[0]) != EOF){
		for (i = 1; i < 10; i++){
			scanf("%d,", &l[i]);
		}
		scanf("%d,%d", &v1, &v2);

		sum_l = 0;
		for (i = 0; i < 10; i++){
			sum_l += l[i];
		}
		
		l1 = ((float)v1 * sum_l / (v1 + v2) + 0.9999);
		l12 = ((float)v1 * sum_l / (v1 + v2) + 0.9999);
		
//		printf("l1=%f, %d\n", l1, l12);

		i = 0;
		while (l12 > 0){
			l12 -= l[i];
			i++;
		}
//		printf("l1=%f, %d\n", l1, l12);
		printf("%d\n", i);
		

	}
	
	return (0);
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

void solve() {
  int n;
  cin >> n;
  map<int, int> dp;
  while(n--) {
    int t;
    cin >> t;
    dp[t]++;
  }
  int m;
  cin >> m;
  int bad = 0;
  while(m--) {
    int t;
    cin >> t;
    if(--dp[t] < 0) {
      bad++;
      break;
    }
  }
  if(bad) cout << "NO\n";
  else cout << "YES\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 9600
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc(v: usize, bit: usize) -> usize {
    if bit == 0 {
        if v % 4 == 0 || v % 4 == 3 {
            return 0;
        }
        return 1;
    }
    if ((v >> bit) & 1) == 0 {
        return 0;
    }
    if v % 2 == 1 {
        return 0;
    }
    return 1 << bit;
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    let mut ans = 0;
    for bit in 0..60 {
        ans |= calc(b, bit) ^ calc(a - 1, bit);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
=begin
N
S1
S2
...
Sn
=end

n = gets.chomp.to_i
ss = n.times.map do
  gets.chomp
end

h = {}

ss.each do |s|
  h[s] ||= 0
  h[s] += 1
end

max = h.values.max
s_list = []

h.each do |k,v|
  if v == max
    s_list << k
  end
end

s_list.sort.each do |s|
  puts s
end


Measured memory_bytes: 41432
import sys
p = [[int(c) for c in r.split()] for r in sys.stdin.read().split('\n') if r != '']
n = p[0][0]
a = p[1]
b = p[2]
c = 0
k = 0
for i in range(n):
    v = min(a[i], k)
    w = min(b[i], a[i] - v)
    c += v + w
    k = b[i] - w
v = min(a[-1], k)
print(c+v)

Measured memory_bytes: 20132
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long mod = 1000000007;

namespace mp = boost::multiprecision;

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

	mp::int128_t n;
	cin >> n;

	if (n & 1) {
		cout << 0 << "\n";
		return 0;
	}

	mp::int128_t five_index = 0, two_index = 0;
	
	mp::int128_t t = n;
	while (t > 1) {
		t = t >> 1;
		two_index += t;
	}

	mp::int128_t s = n/2;
	while (s > 4) {
		s /= 5;
		five_index += s;
	}

	cout << min(two_index, five_index) << "\n";

	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define test int t; cin >> t; while (t--)
#define fast ios::sync_with_stdio(NULL); cin.tie(NULL)
#define mod 1000000007
#define endl "\n"
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/GCD(m,n))
#define all(v) v.begin(),v.end()
#define ll long long
typedef vector<ll> vecll;
typedef vector<int> veci;
typedef vector<char> vecc;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define time 1.0 * clock() / CLOCKS_PER_SEC


int main(){
    fast;
    // test{
    //     ll n,s=0;cin>>n;
    //     vecll a(n);
    //     set <ll> se;
    //     for(auto &x:a){cin>>x;s+=x;se.insert(x);}
    //     vecll pra,prb;
    //     pra.pb(a[0]),prb.pb(s);
    //     for(int i=1;i<n;i++){
    //         pra.pb(a[i]+pra[i-1]);
    //         prb.pb(prb[i-1]-a[i-1]);
    //     }
    //     ll c=0,z=1;
    //     for(auto x:se){
    //         if(x!=z){c=1;break;}
    //         z++;
    //     }
    //     if(c)cout<<0<<endl;
    //     else{
    //         vecll ans;
    //         for(int i=0;i<n-1;i++){
    //             if(s-pra[i] == ((n-i)*(n-i-1))/2 and pra[i]==((i+1)*(i+2))/2){ans.pb(i+1);}
    //         }   
    //         for(int i=n-1;i>=0;i--){
    //             if(s-prb[i] == ((n-i)*(n-i-1))/2 and prb[i]==((i+1)*(i+2))/2){ans.pb(i+1);}
    //         }
    //         cout<<ans.size()<<endl;
    //         for(auto x:ans)cout<<x<<" "<<n-x<<endl;
    //     }


    // }
    ll n,r=0,g=0,b=0;
    cin>>n;
    string s;
    cin>>s;
    for(auto x:s){
        if(x=='R')r++;
        if(x=='G')g++;
        if(x=='B')b++;
    }

    ll i=0,ans=r*g*b;
    while(i<n){
        for(int j=i+2;j<n;j+=2){
            ll k=s[(i+j)/2];
            if(s[i] != s[j] && s[i] != k && s[j]!=k)ans--;
        }
        i++;
    }
    cout<<ans;
    return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		//Console.WriteLine(Cnt(B, C, D));
		//Console.WriteLine(Cnt(A - 1, C, D));
		Console.WriteLine(Cnt(B, C, D) - Cnt(A - 1, C, D));
		
		
		
		
	}
	
	long Cnt(long x, long mod1, long mod2){
		long a = x / mod1;
		long b = x / mod2;
		long lcm = mod1 / gcd(mod1, mod2) * mod2;
		long ab = x / lcm;
		return x - a - b + ab;
	}
	long gcd(long a, long b){
		return a == 0 ? b: gcd(b % a, a);
	}
	
	long A, B, C, D;
	public Sol(){
		var d = rla();
		A = d[0]; B = d[1]; C = d[2]; D = d[3];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

using namespace std;

int main(void)
{
  uint64_t N, M;
  cin >> N >> M;

  uint64_t a = (N<=M/2) ? N : M / 2;
  
  M -= 2*a;
  uint64_t b = M / 4;

  cout << a + b << endl;

  return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long int llint;
llint dp[1005][10005],n;
vector <pair<pair<int,llint>,llint> > v;
bool f(pair <pair<int,llint>,llint> p1,pair <pair<int,llint>,llint> p2) {
	return p1.first.second-p2.first.first>p2.first.second-p1.first.first;
}
llint rek(int x,llint y) {
	if(x==n) return 0;
	if(dp[x][y]!=-1) return dp[x][y];
	llint ret=0;
	ret=max(ret,rek(x+1,y));
	if(y>=v[x].first.first) ret=max(ret,rek(x+1,min(v[x].first.second,y-v[x].first.first+llint(1e5*(y==1e4+1))))+v[x].second);
	dp[x][y]=ret;
	//cout << x << " " << y << " " << ret << "\n";
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i=0;i<n;i++) {
		llint w,s,v1;
		cin >> w >> s >> v1;
		v.push_back(make_pair(make_pair(w,s),v1));
	}
	sort(v.begin(),v.end(),f);
	/*for(int i=0;i<n;i++) {
		cout << v[i].first.first << " " << v[i].first.second << " " << v[i].second << "\n";
	}
	cout << "\n";*/
	memset(dp,-1,sizeof(dp));
	cout << rek(0,1e4+1);
	return 0;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<int,int> p;

int H,W;
int h,w;

int main(){
  cin >> H >> W;
  cin >>h >>w;
  cout << (H-h)*(W-w) << endl;
}


Measured memory_bytes: 256
while true
    b, r, g, c, s, t = gets.chomp.split.map(&:to_i)
    break if [b, r, g, c, s, t] == [0, 0, 0, 0, 0, 0]
    puts 95*b + 63*r + 7*g + 2*c + 3*(s-t) + 100
end


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

int INF = 100000000;

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

  int ans = INF;
  for (int i = 1; i <= n / 2; i++) {
    vector<int> id(6);
    vector<int> jd(6);
    int k = i, j = n - i;

    rep (m, 6) {
      id[m] = k % 10;
      k /= 10;
      jd[m] = j % 10;
      j /= 10;
    }

    int sum = 0;
    rep (m, 6) sum += id[m] + jd[m];

    if (sum < ans) ans = sum;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
const int maxn=1e4+7;
const int N=1e6+7;
const int mod=1e9+7;
int f[maxn],p[maxn],cnt = 0;
int b[N],a[maxn];
map<int,int> ma;
void prime()
{
    LL i,j;
    f[1] = 1;
    for(i=2;i<maxn;i++)
    {
        if(f[i])
            continue;
        p[cnt++] = i;
        for(j=i*i;j<maxn;j+=i)
        {
            f[j] = 1;
        }
    }
}

void fun(int x) //分解质因数
{
    int i = 0;
    while(p[i]*p[i] <= x && i < cnt)
    {
        int t = 0;
        while(x % p[i] == 0)
        {
            x /= p[i];
            t++;
        }
        if(t > b[p[i]])
            b[p[i]] = t;
        i++;
    }
    if(x > 1)
        b[x] = max(b[x],1);
}

LL qpow(LL x,int k)
{
    LL ans = 1;
    while(k)
    {
        if(k&1)
            ans = ans*x%mod;
        x = x*x%mod;
        k /= 2;
    }
    return ans;
}

int main()
{
    int n;
    prime();
    scanf("%d",&n);
    memset(b,0,sizeof(f));
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        fun(a[i]);
    LL ans = 1,ss=0;
    for(int i=1;i<=1000000;i++)
        ans = ans*qpow(i,b[i])%mod;
    for(int i=1;i<=n;i++){
        ss=(ss+ans*qpow(a[i],mod-2))%mod;
    }
    printf("%lld\n",ss);
    return 0;
}


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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n, m;

vvi v;

bitset <11> p;

void read() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    vector <int> temp;
    for(int j = 0; j < k; ++j) {
      int s;
      cin >> s;
      temp.pb(s);
    }
    v.pb(temp);
  }
  for(int i = 0; i < m; ++i) {
    bool x;
    cin >> x;
    if (x)
      p[i] = 1;
    else p[i] = 0;
  }
}

void solve() {
  int sol = 0, l = (1 << n);
  for(int i = 0; i < l; ++i) {
    bitset <11> activated;
    for(int j = 0; j < n; ++j)
      if ((1 << j) & i) {
        //bulb[j] = !bulb[j];
        activated[j] = true;
      }
    vector <int> bulb(m);
    for(int j = 0; j < n; ++j)
      if (activated[j])
        for(int k = 0; k < m; ++k)
          for(auto x : v[k])
            if (x == j + 1)
              ++bulb[k];
    bool good = 1;
    for(int j = 0; j < m && good; ++j)
      if (bulb[j] % 2 != p[j])
        good = 0;
    if (good)
      ++sol;
  }
  cout << sol;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  read();
  solve();
  return 0;
}


Measured memory_bytes: 256
def main():
    a, b = input().split()
    f = 0
    if a == "H":
        f = 1
        if b == "D":
            f = 0
    else:
        if b == "D":
            f = 1
    
    if f == 0:
        print("D")
    else:
        print("H")



if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	int n, ans = 1;
    queue<string> s;
	s.push("a");
	cin >> n;
	if (n == 1) {
		cout << "a" << endl;
		return 0;
	}
	for (;;) {
		if (ans == n) {
			break;
		}
		int n1 = s.size();
		for (int l = 0; l < n1; l++) {
			string n2 = s.front();
			char max = 'a';
			for (int o = 0; o < n2.size(); o++) {
				if (max < n2[o]) {
					max = n2[o];
				}
			}
			for (int i = 0; i < int(max-'a'+2); i++) {
				s.push(s.front() + (char)('a' + i));
			}
			s.pop();
		}
		for (int j = 0; j < s.size(); j++) {
			string str = s.front();
			if (str.size() != ans + 1) {
				s.pop();
			}
		}
		if (ans + 1 == n) {
			for (int k = 0; k < s.size(); k++) {
				cout << s.front() << endl;
				s.push(s.front());
				s.pop();
			}
		}
		ans++;
		
	}
   
}

Measured memory_bytes: 7936
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
n=h*w
INF=1<<20
d = [[float("inf") for i in range(n)] for i in range(n)]
#d[u][v] : 辺uvのコスト(存在しないときはinf)
dyx=[(1,0),(-1,0),(0,1),(0,-1)]
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            continue
        for dy,dx in dyx:
            if 0<=i+dy<h and 0<=j+dx<w and s[i+dy][j+dx]==".":
                d[i*w+j][(i+dy)*w+j+dx]=1
                d[(i+dy)*w+j+dx][i*w+j]=1



for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０

x=warshall_floyd(d)
for i in range(n):
    for j in range(n):
        if x[i][j]==float("inf"):
            x[i][j]=-1

ans=0
for i in range(n):
    ans=max(ans,max(x[i]))
print(ans)


Measured memory_bytes: 136200
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
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 T> inline T gcd(T a, T b) {if(a==0) return b; return gcd(b%a,a);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd(a,b);}
template <class T> inline T sum(vector<T> &vec) {T res=0; for (int i = 0; i < vec.size(); i++) res += vec[i]; return res;}
template <class T> inline T mpow(T a, T b) {if(b==0)return 1; T c = mpow(a,b/2);if(b%2==1)return c*c*a; return c*c;}
const int INF = 1 << 30;
const long long INFLL = 1LL << 60;
typedef pair<int, int> P;

#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define FOR(i,n) for (int (i)=0;(i)<(n);(i)++)
#define REPB(i,n) for (int (i)=((n)-1);(i)>=0;(i)--)
#define FORB(i,n) for (int (i)=((n)-1);(i)>=0;(i)--)
#define SORT(A) sort((A).begin(),(A).end())

bool isprime[1000001];

int main() {
    /*
    string S, T;
    cin >> S >> T;
    cout << T + S << endl;
*//*
    ll A, B, K; cin >> A >> B >> K;
    if (K > A) {
        cout << 0 << " " << max(0LL,B - (K-A)) << endl;
    } else {
        cout << A-K << " " << B << endl;
    }*/
    ll N = 1e6;
    ll X; cin >> X;
    for (int i = 0; i <= N; i++) isprime[i] = true;
    for (int i = 2; i <= N; i++) {
        if (isprime[i]) {
            for (int j = 2*i; j <= N; j += i) isprime[j] = false;
        }
    }
    for (ll x = X; x <= N; x++) {
        if (isprime[x]) {
            cout << x << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1280
#include <iostream>
using namespace std;
int main(void){
    int x, y, z, w;
    while(true){
        cin >> x;
        z = 0, w = 0;
        if (x == 0){
            break;
        }
        for(int i = 0; i < x; i++){
            cin >> y;
            if(y >= 2){
                z += 1;
            } 
            if(y >= 1){
                w += 1;
            }
        }
        if (z == 0){
            cout << "NA" << endl;
        }
        else {
            cout << w+1 << endl;
        }
    }
}



Measured memory_bytes: 3032
import Data.List
import Control.Applicative
import Control.Monad
import Data.Monoid
import qualified Data.Foldable as F

data Card = Card { suit :: Char, num :: Int } deriving (Eq)

instance Show Card where
    show (Card suit num) = suit:show num

newtype CardNum = CardNum { getCard :: Card } deriving (Show)

instance Eq CardNum where
    CardNum (Card _ x) == CardNum (Card _ y) = x == y

instance Ord CardNum where
    CardNum (Card _ x) `compare` CardNum (Card _ y) = x `compare` y

myread :: String -> Card
myread (x:xs) = Card x (read xs)


main :: IO ()
main = do
    getLine
    input <- map myread . words <$> getContents
    let bsorted = bubbleSort $ map CardNum input
        ssorted = selectionSort $ map CardNum input
    putStrLn $ intercalate " " $ map (show . getCard) bsorted
    putStrLn $ if isStable input bsorted then "Stable" else "Not stable"
    putStrLn $ intercalate " " $ map (show . getCard) ssorted
    putStrLn $ if isStable input ssorted then "Stable" else "Not stable"


bubbleSort :: (Ord a) => [a] -> [a]
bubbleSort [] = []
bubbleSort xs = let (m, others) = minOthers xs
                in m:bubbleSort others
    where changeOrThrough x (y, ys)
              | x <= y    = (x, y:ys)
              | otherwise = (y, x:ys)
          minOthers xs = foldr changeOrThrough (last xs, []) (init xs)

selectionSort :: (Ord a) => [a] -> [a]
selectionSort [] = []
selectionSort all@(x:_) = let m = minimum all
                          in m:(selectionSort . tail $ firstReplace m x all)
    where firstReplace a b (x:xs)
              | x == a    = b:xs
              | otherwise = x:firstReplace a b xs

isStable :: [Card] -> [CardNum] -> Bool
isStable xs ys = getAll $ F.foldMap (\ys' -> All $ isPartStable xs ys') (group ys)
    where isPartStable xs ys' = map getCard ys' == filter (\x -> num x == (num . getCard $ head ys')) xs



Measured memory_bytes: 4124
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll X[n];
    ll ans = 0;
    rep(i,n) cin >> X[i];
    for(int i=1; i<n; i++){
        ll tmp =(X[i]-X[i-1])*a;
        if(tmp<b){
            ans += tmp;
        }else{
            ans += b;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int dp[100010];
int main(void)
{
	string x;
	cin>>x;
	dp[0]=1;
	string y;
	for(int i=0;i<x.length();i++)
	{
		if(dp[i]==0)
		{
			continue;
		}
		y=x.substr(i,5);
		if(y=="dream")
		{
			if(dp[i]==1)
			{
				dp[i+5]=1;
			}
		}	
		y=x.substr(i,7);
		if(y=="dreamer")
		{
			if(dp[i]==1)
			{
				dp[i+7]=1;
			}
		}
		y=x.substr(i,5);
		if(y=="erase")
		{
			if(dp[i]==1)
			{
				dp[i+5]=1;
			}
		}
		y=x.substr(i,6);
		if(y=="eraser")
		{
			if(dp[i]==1)
			{
				dp[i+6]=1;
			}
		}	
	}	
	if(dp[x.size()]==1)
	{
		cout <<"YES"<<endl;
	}
	else
	{
		cout <<"NO"<<endl; 
	}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  for(int i = 0;i < n;i++){
    cin >> p[i];
  }
  for(int i = 0;i < n;i++){
    q[p[i]-1] = i;
  }
  int max,k;
  max = 1;
  k = 1;
  for(int i = 1;i < n;i++){
    if(q[i] > q[i-1]) k++;
    else k = 1;
    if(max < k) max = k;
  }
  cout << n - max << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int a[15];
int main(){
	for(int i=0;i<10;i++)
		scanf("%d",a+i);
	sort(a,a+10);
	printf("%d\n%d\n%d\n",a[9],a[8],a[7]);
	return 0;
}


Measured memory_bytes: 3268
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cctype>
#include<string>
using namespace std;

int main(){
    int n; // カードの枚数
    cin >> n;
    // cout << n << endl;

    int point1 = 0, point2 = 0;

    for(int i = 0; i < n; i++){
        string card1, card2;
        cin >> card1;
        cin >> card2;
        // cout << card1 << " " << card2 << endl;

        // １の勝利
        if(card1 > card2){
            point1 += 3;
        }
        // ２の勝利
        if(card1 < card2){
            point2 += 3;
        }
        // 引き分け
        if(card1 == card2){
            point1 += 1;
            point2 += 1;
        }
    }

    cout << point1 << " " << point2 << endl;


    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int Q,H,S,D;
    int N;
    cin >> Q >> H >> S >> D >> N;
    int L1 = min({Q*4,Q*2+H,H*2,S});
    cout << min(L1*N,N/2*D+N%2*L1) << endl;
}

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

typedef long long ll;

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

    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    for(int i=0;i<n;i++) cin >> x[i];
    int ans = 0;
    for(int i=0;i<n;i++){
        ans += min(x[i],abs(x[i]-k));
    }
    ans *= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
 
    long long ans = 0;
    int MaxNum = 0;
    for (int i = 0; i < N; i++)
    {
        //MaxNumを使い回すことで計算を抑える
        MaxNum = max(MaxNum, A[i]);
   
        ans += MaxNum - A[i];
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}

struct Tuple {
    LL a, b;
};

int main() {
    LL N;
    cin >> N;
    vector<Tuple> T(N);
    REP(i, N) {
        LL a, b;
        cin >> a >> b;
        T[i] = Tuple{a, b};
    }

    sort(ALL(T), [] (auto& x, auto& y) {return x.b < y.b;});

    LL t = 0, s = 0;
    REP(i, N) {
        t += T[i].a;
        if (t > T[i].b) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
	
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  string s, t;
  cin >> s >> t;
  int ans = 0;
  rep(i, 0, 3) {
    if (s[i] == t[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define pld pair <ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
#define cld complex <double>

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 1e6 + 100;
const ll base = 239;
const ll mod = 1e9 + 7;
const ll maxc = 26;

ll n, m, k, t;

ll stbase[maxn];

vector <ll> hsh[maxn];

string S[maxn];

ll gethsh(ll i, ll l, ll r) {
    if (l > r) {
        return 0;
    }
    ll hsh0 = (hsh[i][r + 1] - hsh[i][l] + mod) % mod;
    hsh0 = (hsh0 * stbase[maxn - l - 1]) % mod;
    return hsh0;
}

int main() {
    pyshnapyshnakaa
    ll q, w, e, a, b, c;
    stbase[0] = 1;
    for (q = 1; q < maxn; q++) {
        stbase[q] = stbase[q - 1] * base % mod;
    }
    map <pll, vector <ll> > st; // len, hsh
    cin >> n;
    for (q = 0; q < n; q++) {
        cin >> S[q];
        hsh[q].resize(S[q].size() + 1);
        for (w = 0; w < S[q].size(); w++) {
            hsh[q][w + 1] = (hsh[q][w] + S[q][w] * stbase[w] % mod) % mod;
        }
    }
    for (q = 0; q < n; q++) {
        ll hsh = gethsh(q, 1, S[q].size() - 1);
        st[mp(S[q].size() - 1, hsh)].pb(S[q][0] - 'a');
        // st.insert(mp(S[q].size(), gethsh(q, 0, S[q].size() - 1)));
    }
    ll ans = 0;
    // cout << gethsh(0, 4, 5) << " " << gethsh(1, 1, 2) << endl;
    for (q = 0; q < n; q++) {
        vector <ll> F(maxc);
        for (w = 0; w < S[q].size(); w++) {
            F[S[q][w] - 'a']++;
        }
        for (w = S[q].size(); w >= 0; w--) {
            ll hsh = gethsh(q, w, S[q].size() - 1);
            pll p = mp(S[q].size() - w, hsh);
            for (auto i : st[p]) {
                // cout << "I " << i << endl;
                if (F[i] != 0) {
                    // cout << F[i] << endl;
                    ans++;
                }
            }
            // for (e = 0; e < maxc; e++) {
            //     if (F[e] != 0) {
            //     }
            // }
            if (w > 0) {
                F[S[q][w - 1] - 'a']--;
            }
        }
    }
    // cout << "HERE" << endl;
    cout << ans - n;
    return 0;
}

Measured memory_bytes: 152544
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

void inverse(ll n,vector<ll> &inv){
    //要素数:n+1 (0~n)
    inv[0]=1;
    inv[1]=1;
    for(ll i=2;i<=n;i++){
        inv[i]=(MOD-inv[MOD%i]*(MOD/i))%MOD;
    }
}

void inverse_u(ll n,vector<ll> &inv){
    //要素数:n+1 (0~n)
    for(ll i=2;i<=n;i++){
        inv[i]=(inv[i]*inv[i-1])%MOD;
    }
}

void factorial(ll n,vector<ll> &fac){
    //要素数:n+1 (0~n)
    fac[0]=1;
    fac[1]=1;
    for(ll i=2;i<=n;i++){
        fac[i]=(fac[i-1]*i)%MOD;
    }
}

ll nCr(ll n,ll r,vector<ll> &inv,vector<ll> &fac){
    return fac[n]*inv[r]%MOD*inv[n-r]%MOD;
}

int main(){
    ll n,k; cin>>n>>k;
    vector<ll> inv(n+1,0),fac(n+1,0);
    inverse(n,inv); inverse_u(n,inv);
    factorial(n,fac);
    for(ll i=1;i<=k;i++){
        if(n-k+1<i){
            cout<<0<<endl;
            continue;
        }
        ll ans=1;
        ans=(ans*nCr(k-1,i-1,inv,fac))%MOD;
        ans=(ans*nCr(n-k+1,i,inv,fac))%MOD;
        cout<<(ans+MOD)%MOD<<endl;
    }
}

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

typedef long long ll;
typedef pair<int,int> P;

int nextInt() {
  int x; scanf("%d", &x); return x;
}

int main() {
  ll H = nextInt(), W = nextInt();;
  int N = nextInt();

  map< P, int > mp;
  for (int i = 0; i < N; i++) {
    int a = nextInt(), b = nextInt();
    for (int dx = -1; dx <= 1; dx++) {
      for (int dy = -1; dy <= 1; dy++) {
        int na = a + dx;
        int nb = b + dy;
        if (2 <= na && na <= H-1 && 2 <= nb && nb <= W-1) 
          ++mp[ P(na, nb) ];
      }
    }
  }
  vector<ll> ans(10);
  ans[0] += (H-2) * (W-2) - mp.size();
  for (auto p = mp.begin(); p != mp.end(); ++p) {
    ++ans[p->second];
  }
  for (int i = 0; i < 10; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
ll ans=0,k;
int main()
{
	cin>>k;
	rep2(i,1,k+1) if(i%3!=0&&i%5!=0) ans+=i;
	cout<<ans<<endl;
	return 0;}

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

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

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

  vector<ll> a[3];
  rep(i, N) {
    rep(j, 3) {
      ll tmp; cin >> tmp;
      a[j].push_back(tmp);
    }
  }

  ll ans = -1;

  for(int bit = 0; bit < (1<<3); bit++) {
    vector<ll> b(N);
    rep(i, N) {
      ll tmp = 0;
      rep(j, 3) {
        if((bit >> j) & 1) tmp += a[j][i];
        else tmp -= a[j][i];
      }
      b[i] = tmp;
    }
    sort(b.begin(), b.end(), greater<ll>());
    ll sum = 0;
    rep(i, M) sum += b[i];
    ans = max(ans, sum);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

signed main()
{
	int N, K;
	cin >> N >> K;

	int b = N / K;

	int a = N - (K * b);
	cout << (a) << endl;
}









Measured memory_bytes: 256
// 問題名: Never Wait for Weights
// URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1330&lang=jp
// 所要時間: 30分
// --感想--
// Disjoint Setはネットから拾ったものをほぼそのまま使っていたが、この問題を特にあたって一から書き直す必要が
// あったため、構造体への理解が深まって良かった。

#include <bits/stdc++.h>
using namespace std;

// root: 代表元を取得
// unite: 重い代表元を軽い代表元の下につける
// distance: 重さの差を取得
struct UnionFind
{
    vector<int> par, dist;

    UnionFind(int sz)
    {
        par.assign(sz, -1);
        dist.assign(sz, 0); 
    }

    int root(int k)
    {
        if (par[k] == -1)
            return (k);
        int r = root(par[k]);
        dist[k] += dist[par[k]];
        return (par[k] = r);
    }

    void unite(int x, int y, int w)
    {
        int rx = root(x), ry = root(y);
        if (rx == ry)
            return;
        if(dist[x] + w > dist[y]){
            par[ry] = rx;
            dist[ry] = dist[x] + w - dist[y];
        }
        else{
            par[rx] = ry;
            dist[rx] = dist[y] - dist[x] - w;
        }
    }    

    int distance(int x, int y)
    {
        if(root(x) == root(y))
            return (dist[y] - dist[x]);
        else
            return 10000000;
    }

};

int main(){
    while(1){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            break;
        UnionFind uf(n + 1);
        for (int i = 0; i < m; i++){
            char s; 
            cin >> s;
            if(s=='!'){
                int a, b, w;
                cin >> a >> b >> w;
                uf.unite(a, b, w);
            }
            else{
                int a, b;
                cin >> a >> b;
                int d = uf.distance(a, b);
                if(d > 1000000)
                    cout << "UNKNOWN" << endl;
                else
                    cout << d << endl;
            }
        }
    }
}


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

int main(){
	ll n;
	cin>>n;
	ll x=n;
	int r=0;
	int sum=0;
	while(x!=0){
		r=x%10;
		x/=10;
		sum+=r;
	}
	if(n%sum==0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 4e3 + 3;
const int mod = 1e9 + 7;
int pascal[N][N];
int prefix[N][N];
int preprefix[N][N];
void pre(){
	for(int i = 0 ; i < N ; ++i){
		pascal[i][0] = 1;
		prefix[i][0] = 1;
		for(int j = 1 ; j <= i ; ++j){
			pascal[i][j] = pascal[i - 1][j - 1] + pascal[i - 1][j];
			pascal[i][j] -= (pascal[i][j] >= mod) * mod;
			prefix[i][j] = prefix[i][j - 1] + pascal[i][j];
			prefix[i][j] -= (prefix[i][j] >= mod) * mod;
		}
		for(int j = i + 1 ; j < N ; ++j){
			prefix[i][j] = prefix[i][j - 1];
		}
		preprefix[i][0] = 1;
		for(int j = 1 ; j < N ; ++j){
			preprefix[i][j] = preprefix[i][j - 1] + prefix[i][j];
			preprefix[i][j] -= (preprefix[i][j] >= mod) * mod;
		}
	}
}
int n , m;
int ans;
int solve(int red , int blue){
	if(red == 0 || blue == 0){
		return 1;
	}
	int res = 0;
	for(int row = red - min(red , blue) ; row <= red ; ++row){
		int col = red - row;
		res = (res + 1LL * pascal[red - row + blue - col][red - row] * (col ? preprefix[col - 1][row] : 1)) % mod;
	}
	return res;
}
int main(){
	pre();
	scanf("%d %d" , &n , &m);
	ans = 0;
	for(int i = 1 ; i <= n + 1 ; ++i){
		ans += solve(n - i + 1 , m - 1);
		ans %= mod;
	}
	printf("%d\n" , ans);
}

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

#include <math.h>

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

  priority_queue<ll> a;

  rep(i,n){
      ll price;
      cin >> price;
      a.push(price);
  }

  rep(i,m){
      ll discount;
      discount = a.top()/2.0;
      a.pop();
      a.push(discount);
  }

  ll ans = 0;
  rep(i,n){
      ans += int(floor(a.top()));
      a.pop();
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){
    os << st[i];
    if(i!=st.size()-1) os << endl;
  }
  return os;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n,n){
    vi a(n);
    cin >> a;
    sort(ALL(a));
    int diff = INT_MAX;
    REP(i,n-1){
      mins(diff,abs(a[i]-a[i+1]));
    }
    cout << diff << endl;
  }
}



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

int main(){
  int a,b;
  cin>>a>>b;
  a=(a+11)%13;
  b=(b+11)%13;
  if(a==b) cout<<"Draw"<<endl;
  else if(a>b) cout<<"Alice"<<endl;
  else cout<<"Bob"<<endl;
}

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Numeric

main :: IO ()
main = loop

loop :: IO ()
loop = do
  { [n, x] <- getInts
  ; if n == 0 && x == 0 then return ()
    else print (length (filter (( x == ) . sum) (comb [1 .. n] 3))) >> loop
  }

comb :: [Int] -> Int -> [[Int]]
comb ns 0 = [[]]
comb ns k = if length ns == k then [ns]
            else map (head ns :) (comb (tail ns) (k - 1)) ++ comb (tail ns) k  
--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn  .  unwords .  map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 5644
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N = inp()
S = []
f = "Yes"
for i in range(N):
    s = input()
    if i > 0:
        prev = S[i-1]
        if s in S or s[0] != prev[-1]:
            f = "No"
    S.append(s)
print(f)


Measured memory_bytes: 3064