akhauriyash/Code-Regression huggingface dataset:
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;cin>>a>>b;
  string s;cin>>s;
  
  for(int i=0;i<a;i++){
    if(s[i]=='-'){
      cout<< "No" <<endl;
      return 0;
    }
  }
  if(s[a]!='-'){
      cout<< "No" <<endl;
      return 0;
    }
  
  for(int i=a+1;i<a+b+1;i++){
    if(s[i]=='-'){
      cout<< "No" <<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
// #include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <sstream>
#include <iomanip>
using namespace std;


#define int int64_t
#define vi vector<int>
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define all(x) (x).begin(), (x).end()
#define vii vector< vector<int> >
#define rip(dp, n, m) vector< vector<int> > dp(n, vector<int>(m,0))
#define ff first
#define ss second
#define pii pair<int64_t, int64_t>
#define miv map<int, vector<int> >
#define mp make_pair
#define pb push_back
#define prr(x) cout << (#x) <<'	' << (x) << endl
#define pr(x) cout  << (x) << endl
#define f(i,n) for(i=0;i<n;i++)
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x)  __builtin_popcountll(x)
#define zrobits(x)  __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define FIO  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
  FIO;
  int i, n, j, m, k, l, t;
  cin >> n >> k;
  vector<pii> v(n);
  f(i,n)
    cin >> v[i].ff >> v[i].ss;
  
  rip(dp,n+1,k+1);
  f(i,n+1) f(j,k+1) dp[i][j]=0;

  for(i=1;i<=n;i++)
  {
    for(j=1;j<=k;j++)
    {
      if(j>=v[i-1].ff)
        dp[i][j] = max((v[i-1].ss+dp[i-1][j-v[i-1].ff]), dp[i-1][j]);
      
      else 
        dp[i][j] = dp[i-1][j];
    }
  }

  // f(i,n+1)
  // {
  //   f(j,k+1) cout << dp[i][j] << " ";
  //   cout << endl;
  // }

  cout << dp[n][k];

}

Measured memory_bytes: 83192
import java.util.*;

public class Main {
    public static void main(String args[] ) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        	if (a < b){
        	System.out.println("a < b");
        	}else if(a > b){
        	System.out.println("a > b");
        	}else{
        	System.out.println("a == b");
        	}
    }
}



Measured memory_bytes: 26224
#include<iostream>
using namespace std;
int main(){
  int i,k,cnt;
  string s;
  cin>>s;
  int ans=1e6;
  for(k=0;k<2;k++){
    cnt=0;
    for(i=0;i<s.size();i++){
      if(s[i]!='0'+(i+k)%2)
        cnt++;
    }
    ans=min(ans,cnt);
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 512
n = int(input())
cnt = 0
ans = 0
for i in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
        if cnt == 3:
            ans = 1
    else:
        cnt = 0
if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62208
n,k = map(int,input().split())
num =0
count = 0
for i in reversed(range(1,n+1)):
    #count = 0
    i1 = i
    if k > i*(2**count):
        i = i*(2**count)
        while k > i:
            i *= 2
            count += 1
    num += ((1/2)**count)*(1/n)
print(num)

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

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll h,n;
    cin>>h>>n;
    ll a[n];
    string ans = "No";
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    bool flag = false;
    for(int i = 0; i<n;i++){
        h -= a[i];
        if(h <= 0){
            flag = true;
            break;
        }
    }
    if(flag) ans = "Yes";
    cout<< ans <<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int ans = 0;
	string s; cin >> s;
	rep(i, s.size()){
		ans += i % 2 - (s[i] == 'p');
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end())

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using vstr = std::vector<std::string>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int n, m;
    cin >> n >> m;
    vint a(n);
    rep(i, n)cin >> a[i];

    /*
    a.resize(100000);
    rep(i, 100000)a[i] = 1000000000;
    m = 100000;
    */

    priority_queue<int> q;
    rep(i, n) {
        q.push(a[i]);
    }

    rep(i, m) {
        ll val = q.top();
        q.pop();
        val /= 2;
        q.push(val);
    }
    
    ll ans = 0;
    rep(i, n) {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}

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



Measured memory_bytes: 1276
s = input()
sset = set(s)
slist = list(sset)
slist.sort()
char = "abcdefghijklmnopqrstuvwxyz"
flg = False

for i in range(26):
  if len(slist) <= i:
    print(char[i])
    flg = True
    break
  if slist[i] != char[i]:
    print(char[i])
    flg = True
    break

  
if flg == False:
  print("None")
  


Measured memory_bytes: 3188
# -*- coding: utf-8 -*-

def main():
    n,k = map(int, input().split())
    l = list(map(mean, input().split()))
    out = sum(l[:k])
    result = out

    for i in range(1, len(l)-(k-1)):
        result = result - l[i-1] + l[i+k-1]

        if out < result:
            out = result

    print(out)

def mean(x):
    x = int(x)
    return x * (x+1) / (2 * x)

if __name__ == "__main__":
    main()


Measured memory_bytes: 23588
#include <iostream>
#include <cstdio>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
const int MAX = 100100; 

vector<int> L[MAX];
pair<int, int> K[MAX];
int isvisit[MAX];
int pnum;
bool finish;
set<int> m;
deque<int> path;


int main(){
    int N,M;
    cin >> N >> M;
    REP(i,M){
        int a,b;
        cin >> a >> b;
        a--, b--;
        L[a].push_back(b);
        L[b].push_back(a);
        //int ka = K[a].first;
        //int kb = K[b].first;
    }
    
    int front = 0;
    int back = L[0][0];
    m.insert(front);
    m.insert(back);
    path.push_front(front);
    path.push_back(back);
    pnum += 2;
    while(1){
        bool update = false;
        for(int i = 0; i < L[front].size(); i++){
            int next = L[front][i];
            if(m.find(next) == m.end()){
                m.insert(next);
                front = next;
                path.push_front(front);
                pnum++;
                update = true;
                break;
            }
        }
        for(int i = 0; i < L[back].size(); i++){
            int next = L[back][i];
            if(m.find(next) == m.end()){
                m.insert(next);
                back = next;
                path.push_back(back);
                pnum++;
                update = true;
                break;
            }
        }
        if(update == false) break;
    }



    printf("%d\n", pnum);
    REP(i,pnum){
        printf("%d ", path.front()+1);
        path.pop_front();
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 11392
#include<iostream>
using namespace std;
int main()
{
	long long s=0,n,k,m;
	cin>>n>>k;
	if(k%2==1)
	{
		if(n<k) cout<<0;
		else
		{
			m=n/k;
			s=m*m*m;
			cout<<s;
		}
	}
	else
	{
		if(n<k/2) cout<<0;
		else
		{
			m=(n-k/2)/k+1;
			s=m*m*m;
			if(n>=k)
			{
				m=n/k;
				s+=m*m*m;
			}
			cout<<s;
		}
	}
 } 

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

SP = [list(input().split()) for _ in range(N)]

sp=[]
count=1
for s,p in SP:
    sp.append([s,int(p),count])
    count+=1
    
#sp.sort(key=lambda x:x[1],reverse=True)
sp.sort(key=lambda x:(x[0],-x[1]))

for i,j,k in sp:
    print(k)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long 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 long long INF = 1LL << 60;

int n;
ll cnt;
int a[1000100];
vector<int> G;

void insertionSort(int a[], int n, int g)
{
  REP(i, g, n-1){
    int j = i-g;
    while(j >= 0 && a[j] > a[j+g]){
      swap(a[j], a[j+g]);
      cnt++;
      j -= g;
    }
  }
}

// void insertionSort(int a[], int n, int g)
// {
//   REP(i, g, n-1){
//     int v = a[i];
//     int j = i-g;
//     while(j>=0 && a[j] > v){
//       a[j+g] = a[j];
//       j -= g;
//       cnt++;
//     }
//     a[j+g] = v;
//   }
//
// }

void shellSort(int a[], int n)
{
  for(int g=1; g<=n; g=3*g+1){
    G.push_back(g);
  }
  repr(i, G.size()-1){
    insertionSort(a, n, G[i]);
  }
}

int main(){
  cin >> n;
  rep(i, n) scanf("%d", &a[i]);

  cnt = 0;
  shellSort(a, n);

  cout << G.size() << endl;
  repr(i, G.size()-1){
    if(i==0) printf("%d\n", G[i]);
    else printf("%d ", G[i]);
  }
  printf("%lld\n", cnt);
  rep(i, n) printf("%d\n", a[i]);

  return 0;
}




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

int main(){
  int N, X;
  cin >> N >> X;
  int s=0;
  int a=1000;
  for (int i=0; i<N; i++){
    int m;
    cin >> m;
    s+=m;
    a=min(m,a);
  }
  cout << N+(X-s)/a << endl;
}



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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	map<int, int> amap;
	int N;
	cin >> N;
	int A;
	rep(i, 0, N)
	{
		cin >> A;
		amap[A]++;
	}
	int ma[2] = { 0 };

	for (auto p : amap)
	{
		if (p.second >= 2)
		{
			chmax(ma[1], p.first);
			if (ma[0] < ma[1])
			{
				swap(ma[0], ma[1]);
			}
		}
		if (p.second >= 4)
		{
			chmax(ma[1], p.first);
			if (ma[0] < ma[1])
			{
				swap(ma[0], ma[1]);
			}
		}
	}

	cout << ma[0] * ma[1] << endl;

	return 0;
}

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

int main(){
    int H, W;
    cin >> H >> W;
    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++){
            string s;
            cin >> s;
            if(s == "snuke"){
                string t = "";
                t.push_back('A' + j);
                t += to_string(i+1);
                cout << t << endl;
            }
        }

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc059/tasks/abc059_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    if (a.length() > b.length() || (a.length() == b.length() && a > b)) {
        cout << "GREATER\n";
    } else if (a.length() < b.length() || (a.length() == b.length() && a < b)) {
        cout << "LESS\n";
    } else {
        cout << "EQUAL\n";
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author acesine
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        private long maxOfThree(long A, long B, long C) {
            return Math.max(Math.max(A, B), C);
        }

        private long minOfThree(long A, long B, long C) {
            return Math.min(Math.min(A, B), C);
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long H = in.nextInt(), W = in.nextInt();
            long minDiff = H * W;
            for (long h = 0; h <= H; h++) {
                long A = h * W;
                long B = ((H - h) / 2) * W;
                long C = H * W - A - B;
                minDiff = Math.min(minDiff, maxOfThree(A, B, C) - minOfThree(A, B, C));
                B = (H - h) * (W / 2);
                C = H * W - A - B;
                minDiff = Math.min(minDiff, maxOfThree(A, B, C) - minOfThree(A, B, C));
            }
            for (int w = 0; w < W; w++) {
                long A = w * H;
                long B = ((W - w) / 2) * H;
                long C = H * W - A - B;
                minDiff = Math.min(minDiff, maxOfThree(A, B, C) - minOfThree(A, B, C));
                B = (W - w) * (H / 2);
                C = H * W - A - B;
                minDiff = Math.min(minDiff, maxOfThree(A, B, C) - minOfThree(A, B, C));
            }
            out.println(minDiff);
        }

    }
}



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

stack<char> st;

int main(){
  string S;
  cin >> S;
  int count=0;
  st.push(S[0]);
  for(int i=1; i<S.size(); i++){
    if(st.empty()){
      st.push(S[i]);
      continue;
    }
    if(st.top()!=S[i]){
      st.pop();
      count+=2;
    }
    else{
      st.push(S[i]);
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int n,s,ans;
void F(depth,t,sum)
{
    if(depth==10)
    {
        if(t==n&&sum==s)
        {
            ans++;
        }
        return;
    }
    F(depth+1,t+1,sum+depth);
    F(depth+1,t,sum);
}
int main(void)
{
    while(1)
    {
        scanf("%d %d",&n,&s);
        if(n==0&&s==0)break;
        F(0,0,0);
        printf("%d\n",ans);
        ans=0;
    }
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[100010],l[100010],r[100010];
ll gcd(ll A,ll B){
	if(B==0){
		return A;
	}
	return gcd(B,A%B);
}
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	l[0]=a[0];
	r[n-1]=a[n-1];
	for(ll i=1;i<n;i++){
		ll now=gcd(max(a[i],l[i-1]),min(a[i],l[i-1]));
		l[i]=now;
	}
	for(ll i=n-2;i>=0;i--){
		ll now=gcd(max(a[i],r[i+1]),min(a[i],r[i+1]));
		r[i]=now;
		//cout << now<<endl;
	}
	ll ans=max(l[n-2],r[1]);
	for(ll i=0;i+2<n;i++){
		ll now=l[i];
		ll nex=r[i+2];
		ans=max(ans,gcd(max(now,nex),min(now,nex)));
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int min_num = 10000;
    for (int i=0;i+2 < s.length(); i++ ) {
        int tmp_num = (s[i]-'0') * 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');
        min_num = min(min_num, abs(753 - tmp_num));
        // cout << "tmp_num: " << tmp_num << " min_num: " << min_num << endl;
    }
    cout << min_num << endl; 
}


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

using namespace std;

#define ll long long

int main(void){
    vector<int> p(100008, 1);

    int root = 100;
    int max = 100008;

    for(int i = 2;i*i < max;++i){
        if(p[i] == 1){
            int j = 2;
            while(i*j < max){
                p[i*j] = 0;
                ++j;
            }
        }
    }

    int x;
    cin >> x;
    
    while(p[x] == 0){
        ++x;
    }

    cout << x << endl;

    return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10000000)

V, M = map(int,input().split())
L = [[] for _ in range(V+1)]
DP = [-1 for _ in range (V + 2)]
for _ in range(M):
    x,y = map(int,input().split())
    L[x-1].append(y-1)

def rec(v):
    if DP[v] != -1: return DP[v]
    ret = 0
    for x in L[v]:
        ret = max(ret,rec(x)+1)
    DP[v] = ret
    return DP[v]
ans = 0
for i in range(V):
    ans = max(ans, rec(i))
print(ans)


Measured memory_bytes: 152796
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int r;
    cin >> r;
    cout <<r * r << endl;
}


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

#define ll long long
#define F(i,m,n) for(ll i=m;i<n;i++)
#define Fr(j,n,m) for(ll j=n;j>=m;j--)
#define vll vector<ll>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpll vector< pll >
#define tlll tuple < ll ,ll,ll >
/*-------------------------------------*---------------------------------------*/

#define godspeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl
#define cout_array(a) cout<<#a<<"=";for(auto x: a){ cout<<x<<" ";}cout<<endl

ll gcd(ll a,ll b){
    return (b?gcd(b,a%b):a);
}
const ll MAX_PRIME = 1e9+7;
const ll INF = 1e18;


/*I NEED YOU TO WORK FOR TWO HOURS ON THIS NO MATTER WHAT....THE RESULT DOESN'T MATTER.....ITS ALL ABOUT YOUR EFFORTS.
---------------------------------------------------------------------------------------------------------------------*/

ll fast_pow(ll x,ll y,ll z){
    if(y==0)return 1%z;
    else if(y==1)return x%z;
    if(y%2==0){
        ll res = fast_pow(x,y/2,z);
        return (res*res)%z;
    }
    else{
        ll res = fast_pow(x,y/2,z);
        ll temp = (res*res)%z;
        return ((x%z)*temp)%z;
    }
}

int main() {
    godspeed

    string string1;
    string string2;
    cin>>string1;
    cin>>string2;
    ll n = string1.length();
    ll t = string2.length();
    ll ans = 10000;
    F(i,0,n-t+1){
        string temp = string1.substr(i,t);
        ll count = 0;
        F(j,0,t){
           if(temp[j] != string2[j])count+=1;
        }
        ans = min(count,ans);
    }
    cout<<ans<<endl;

    return 0;
}


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

int main() {
	int a, b, c;
	int x;
	int counter = 0;
	cin >> a >> b >> c;
	cin >> x;

	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				int sum = i * 500 + j * 100 + k * 50;
				//cout << sum << endl;
				if (sum == x) {
					counter++;
				}
			}
		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int row = input.nextInt();
        int cow = input.nextInt();
        int[][] A = new int[row][cow];
        int[] b = new int[cow];
        for(int i = 0; i < row; i ++)
            for(int j = 0; j < cow; j ++)
                A[i][j] = input.nextInt();
        for(int k = 0; k < cow; k ++)
            b[k] = input.nextInt();
        calculate(A, b);    
    }
    
    public static void calculate(int[][] A, int[] b){
        int sum = 0;
        for(int i = 0; i < A.length; i ++){
            for(int j = 0; j < A[0].length; j ++)
                sum += (A[i][j] * b[j]);
            System.out.println(sum);
            sum = 0;
        }
    }
}


Measured memory_bytes: 40708
#include<iostream>

using namespace std;

int main(){

    int64_t N;
    cin >> N;
    int two = 0, four = 0;
    int a[N];

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

        if(a[N]%4==0){
            four++;
        }

        if(a[N]%2==0){
            two++;
        }

    }

    two = two - four;
  	

    if(four >= N/2|| two == N || two + four == N){
        cout << "Yes" << endl;
        return 0;
    }
    
    if ((four - 1) >= (N-two-1)/2){
        cout << "Yes" <<endl;
    }else
    {
        cout << "No" << endl;
    }
    


    return 0;
}

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

#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

const int N = 2e5 + 77;
int A[N], D[N];

int32_t main()
{
    fast;
    int n , k ; cin >> n >> k;
    for(int i = 0 ;i < n ; ++i) cin >> A[i];
    int ans = 1e18;
    
    for(int i = 0 ; i < n-k+1 ; ++i){
        int l = i , r = i + k - 1;
        int a = min(abs(A[l]) , abs(A[r]));
        int b = A[r] - A[l];
        int s = a+b;
        ans = min(s,ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4428
# coding: utf-8
# Your code here!

import collections
n = int(input())

sl = []
for _ in range(n):
    s = sorted(list(input()))
    sl.append(s)

before_s = ""
ans = 0
point = 1
for i in sorted(sl):
    if i == before_s:
        point += 1
    else:
        before_s = i
        ans += int(point * (point - 1) / 2)
        point = 1
ans += int(point * (point - 1) / 2)
print(ans)
    


Measured memory_bytes: 101848
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    s = list(input())
    if n % 2 == 1:
        print('No')
    else:
        if s[:n//2] == s[n//2:]:
            print('Yes')
        else:
            print('No')
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const ll INF = 1000000009000000009;

ll n, a, b, c, d;

map<ll, ll> mp;

ll rec(ll n)
{
    if (mp.find(n) != mp.end())
        return mp[n];
    if (n == 0)
        return 0;
    ll ans = INF;
    if (n < (long double)ans / d)
        ans = n * d;
    ll u = (n / 2) * 2;
    if (u / 2 != n)
        ans = min(ans, abs(n - u) * d + a + rec(u / 2));
    u += 2;
    if (u / 2 != n)
        ans = min(ans, abs(n - u) * d + a + rec(u / 2));
    u = (n / 3) * 3;
    if (u / 3 != n)
        ans = min(ans, abs(n - u) * d + b + rec(u / 3));
    u += 3;
    if (u / 3 != n)
        ans = min(ans, abs(n - u) * d + b + rec(u / 3));
    u = (n / 5) * 5;
    if (u / 5 != n)
        ans = min(ans, abs(n - u) * d + c + rec(u / 5));
    u += 5;
    if (u / 5 != n)
        ans = min(ans, abs(n - u) * d + c + rec(u / 5));
    return mp[n] = ans;
}

void solv()
{
    mp.clear();
    scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
    printf("%lld\n", rec(n));
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    int tt;
    scanf("%d", &tt);
    while (tt--)
        solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Measured memory_bytes: 5000
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int a,b,c;
  cin >> a >> b >> c;

  if(c <= b/a){
    cout << c << endl;
  } else {
    cout << b/a << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>

#define rep(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
using namespace std;

typedef struct{
	int wrong[11];
	int correct;
	int p_time;
	int num;
}Team;

int T, P, R;

void sswap(Team *a, Team *b){
	Team temp = *a;
	*a = *b;
	*b = temp;
}
void solve(Team team[]){
	rep(i, 0, T - 1)
	for (int j = T - 1; j > i; j--)
	{
		if (team[j].correct > team[j - 1].correct)
			sswap(team + j, team + j - 1);
		else if (team[j].correct == team[j - 1].correct){
			if (team[j].p_time < team[j - 1].p_time)
				sswap(team + j, team + j - 1);
			else if (team[j].p_time == team[j - 1].p_time&&team[j].num < team[j - 1].num)
				sswap(team + j, team + j - 1);
		}



	}
}

int main(){

	cin >> T >> P >> R;
	while (T != 0){
		Team team[51] = { { 0 }, 0, 0 };
		rep(i, 0, T)team[i].num = i + 1;
		rep(i, 0, R){
			int t, p, time;
			char str[20];
			cin >> t >> p >> time >> str;
			t--;
			if (strcmp(str, "WRONG")){
				team[t].correct++;
				team[t].p_time += time + team[t].wrong[p] * 1200;
			}
			else{
				team[t].wrong[p]++;
			}

		}
		solve(team);
		rep(i, 0, T){
			cout << team[i].num << " " << team[i].correct << " " << team[i].p_time << endl;
		}
		cin >> T >> P >> R;
	}
	return(0);
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
#define ls x<<1,l,mid
#define rs x<<1|1,mid+1,r
#define N 500005
#define M 2000005
using namespace std;
int n;
int head[N],ver[M],nxt[M],tot;
void add(int a,int b)
{
    tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;return ;
}
int low[N],in[N],top,st[N],dfn[N],be[N],num,tim;
void trjan(int x)
{
    low[x]=dfn[x]=++tim;
    st[++top]=x;
    in[x]=1;
    for(int i=head[x];i;i=nxt[i])
    {
        if(!dfn[ver[i]])
        {
            trjan(ver[i]);
            low[x]=min(low[x],low[ver[i]]);
        }
        else if(in[ver[i]])low[x]=min(low[x],dfn[ver[i]]);
    }
    if(low[x]==dfn[x])
    {
        int y;num++;
        do
        {
            y=st[top--];
            in[y]=0;
            be[y]=num;
        }while(y!=x);
    }
    return ;
}
struct nd
{
    int x,id;
    friend bool operator < (const nd &aa,const nd &bb)
    {
        return aa.x<bb.x;
    }
}a[N];
int tt,mx;
int fan[N];
void build(int x,int l,int r)
{
    mx=max(mx,x);
    if(l==r)
    {
        add(x+tt,fan[a[l].id]);
        return ;
    }
    int mid=(l+r)>>1;
    add(x+tt,x*2+tt);
    add(x+tt,x*2+1+tt);
    build(ls);build(rs);
}
void add(int x,int l,int r,int ll,int rr,int ps)
{
    if(l>=ll&&r<=rr)
    {
        add(ps,x+tt);
        return ;
    }
    int mid=(l+r)>>1;
    if(ll<=mid)add(ls,ll,rr,ps);
    if(rr>mid)add(rs,ll,rr,ps);
}
bool pan(int x)
{
    memset(dfn,0,sizeof(dfn));
    memset(head,0,sizeof(head));
    tot=tim=num=0;
    build(1,1,tt);
    int l=1,r=1;
    for(int i=1;i<=tt;i++)
    {
        while(l<i&&a[i].x-a[l].x>=x)l++;
        while(r<=tt&&a[r+1].x-a[i].x<x)r++;
        //cout<<l<<' '<<r<<endl;
        if(l!=i)add(1,1,tt,l,i-1,a[i].id);
        if(r!=i)add(1,1,tt,i+1,r,a[i].id);
    }
    for(int i=1;i<=tt+mx;i++)if(!dfn[i])trjan(i);
    for(int i=1;i<=tt;i++)if(be[i]==be[fan[i]])return 0;
    return 1;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int t1,t2;cin>>t1>>t2;
        a[++tt].x=t1;a[tt].id=tt;
        a[++tt].x=t2;a[tt].id=tt;
        fan[tt-1]=tt;fan[tt]=tt-1;
    }
    sort(a+1,a+tt+1);
    int l=0,r=1000000000;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(pan(mid))l=mid+1;
        else r=mid-1;
    }
    //cout<<pan(0);
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 26752
// TOPSIC001_0

#include <bits/stdc++.h>

using namespace std;

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

typedef int _loop_int;
#define REP(i, n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i, a, b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i, a, b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a, b) a=min((a),(b))
#define CHMAX(a, b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a, b) (abs(a-b)<EPS)
typedef complex<Real> P;


int main() {
//    int N ,L; cin >> N >> L;
    int N; cin >> N;
    vi d(N); REP(i, N) cin >> d.at(i);
    sort(d.begin(), d.end());
    d.erase(unique(ALL(d)), d.end());



    cout << d.size();

//    vector<string> vs(N);
//    REP(i, N) cin >> vs.at(i);
//    string O, E; cin >> O >> E;


    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		Point p1=new Point(0,0);
		Point p2=new Point(100,0);
		System.out.println("0.00000000 0.00000000");
		koch(n,p1,p2);
		System.out.println("100.00000000 0.00000000");
	}
	public static void koch(int n,Point p1,Point p2){
		if(n==0) return;
		Point s=new Point(0,0);
		Point t=new Point(0,0);
		Point u=new Point(0,0);
		s.x=(2*p1.x+1*p2.x)/3;
		s.y=(2*p1.y+1*p2.y)/3;
		t.x=(1*p1.x+2*p2.x)/3;
		t.y=(1*p1.y+2*p2.y)/3;
		u.x=(t.x-s.x)/2-(t.y-s.y)*Math.sqrt(3)/2+s.x;
		u.y=(t.x-s.x)*Math.sqrt(3)/2+(t.y-s.y)/2+s.y;

		koch(n-1,p1,s);
		//System.out.println(s.x+" "+s.y);
		System.out.printf("%.8f %.8f",s.x,s.y);
		System.out.println("");
		koch(n-1,s,u);
		//System.out.println(u.x+" "+u.y);
		System.out.printf("%.8f %.8f",u.x,u.y);
		System.out.println("");
		koch(n-1,u,t);
		//System.out.println(t.x+" "+t.y);
		System.out.printf("%.8f %.8f",t.x,t.y);
		System.out.println("");
		koch(n-1,t,p2);
	}
}
class Point{
	double x,y;
	public Point(double x,double y){
		this.x=x;
		this.y=y;
	}
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// aのb乗(MODした)を返す。
ll modpow(ll a, ll b, ll mod = 1000000007) {
  ll res = 1;
  for (a %= mod; b; a = a * a % mod, b >>= 1)
    if (b & 1) res = res * a % mod;
  return res;
}

// mを法としたaの逆元を返します
long long modinv(long long a, long long m = 1000000007) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll gcd(ll a, ll b) {
  return (!a || !b) ? 0 : ((a % b == 0) ? b : gcd(b, a % b));
}

// 結果を入れたmapを返します
map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i <= sqrt(n); i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  // 2以上で割り切れなかったら
  if (n != 1) ret[n] = 1;
  return ret;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) { cin >> v[i]; }

  map<ll, int> lc;
  for (int i = 0; i < n; i++) {
    map<ll, int> res = prime_factor(v[i]);
    for (auto x : res) {
      if (lc[x.first] < x.second) lc[x.first] = x.second;
    }
  }
  ll sa = 1;
  for (auto x : lc) {
    sa = sa * modpow(x.first, x.second) % MOD;
  }

  vector<ll> rui(n + 1), rrui(n + 1);

  rui[0] = rrui[n] = 1;
  for (int i = 0; i < n; i++)
    rui[i + 1] = rui[i] * v[i] % MOD;
  for (int i = n; i > 0; i--)
    rrui[i - 1] = rrui[i] * v[i - 1] % MOD;

  ll sowa = 0;
  for (int i = 0; i < n; i++) {
    sowa = (sowa + rui[i] * rrui[i + 1] % MOD) % MOD;
  }

  ll hoge = 1;
  for (int i = 0; i < n; i++) {
    hoge = hoge * v[i] % MOD;
  }

  cout << sowa * sa % MOD * modinv(hoge) % MOD << endl;
}


Measured memory_bytes: 1152
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;
typedef pair<int, int> P;

/** Problem 1130 : Red and Black **/
int main()
{
	bool field[20][20];
	bool vis[20][20];
	int W, H, sx, sy; char c;
	
	while (cin >> W >> H, W||H) {
		int ans = 0;
		
		rep(y, H) {
			rep(x, W) {
				cin >> c;
				if (c=='.') {
					field[x][y]=true;
				} else if (c=='@') {
					field[x][y]=true;
					sx = x; sy = y;
				} else {
					field[x][y] = false;
				}
				vis[x][y] = false;
			}
		}
		
		queue<P> Q;
		Q.push(P(sx, sy));
		
		while (Q.size()!= 0) {
			P p = Q.front(); Q.pop();
			if (!vis[p.first][p.second]) {
				ans++;
				vis[p.first][p.second]=true;
			}
			
			rep(i, 4) {
				int nx = p.first+dx[i], ny=p.second+dy[i];
				if (0<= nx && nx < W && 0 <= ny && ny < H && field[nx][ny] && !vis[nx][ny])
					Q.push(P(nx, ny));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4244
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
signed main() {
	int n,ans=0;
	cin>>n;
	f(i,n){
		int a;
		cin>>a;
		if(a!=i+1)ans++;
	}
	if(ans<=2)puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;

int main(){
  int n; cin >> n;
  int graph[n][n] = {};
  int k,f;
  rep(i,n){
    cin >> f >> k;
    rep(j,k){
      int ai; cin >> ai;
      graph[i][ai-1] = 1;
    }
  }
  rep(i,n){
    rep(j,n){
      cout << graph[i][j];
      if(j != n-1) cout << " ";
    }
    cout << "\n";
  }
}


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

using namespace std;
const int LIMIT = 1e6;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), count(LIMIT + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        count[a[i]]++;
    }
    sort(a.begin(), a.end());

    vector<bool> divisible(LIMIT + 1);
    for (int i = 1; i <= LIMIT; i++) {
        if (count[i] > 0) {
            if (count[i] >= 2)divisible[i] = true;
            for (int j = i * 2; j <= LIMIT; j += i)divisible[j] = true;
        }
    }

    int ret = 0;
    for (auto x:a) {
        if (!divisible[x])ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 7912
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
 
// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
using namespace __gnu_pbds;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const int INF = 1e16;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 1e9 + 7;

const int maxn = 1e4 + 7;

int dp[maxn][105][2];

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    string s;
    cin >> s;
    int d, n;
    cin >> d;
    int x = s[0] - '0';
    x %= d;
    dp[0][0][0] = 1;
    n = s.size();
    for(int i = 1; i <= n; i++)
    {
        int x = s[i-1] - '0';
        for(int j = 0; j < d; j++)
        {
            int prev = (j - x + 10 * d) % d;
            dp[i][j][0] += dp[i-1][prev][0];
            dp[i][j][0] %= mod;
            for(int k = 0; k < 10; k++)
            {
                prev = (j - k + 10 * d) % d;
                dp[i][j][1] += dp[i-1][prev][1];
                if(k < x)
                    dp[i][j][1] += dp[i-1][prev][0];
                dp[i][j][1] %= mod;
            }
        }
    }
    int ans = dp[n][0][0] + dp[n][0][1] - 1 + mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}

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

#define _LL long long
#define rep(i, n) for(_LL i = 0; i < (_LL)(n); i++)


template <class T> class MultiArray2
{
    public:
        T* _a;
        int _w;
        int _h;
        MultiArray2(int w, int h, bool clr = false)
        {
            _w = w; _h = h;
            _a = new T[_w * _h];
            if(clr) memzero();
        }

        void memzero()
        {
            memset(_a, 0, _w * _h * sizeof(T));
        }

        ~MultiArray2()
        {
            delete _a;
        }

        T* operator[](int i)
        {
            return _a + (i * _h);
        }
};


#define INF (1UL << 60)

int main()
{
    _LL n, k;
    cin >> n >> k;
    _LL *h = new _LL[n];

    MultiArray2<_LL> dp(n, k + 1, true);
    rep(i, n) cin >> h[i];

    if( n == k )
    {
        cout << 0 << endl;
        return 0;
    }
    rep(i, n)
    {
        if( i == 0 )
        {
            rep(j, k + 1) dp[i][j] = INF;
            dp[i][0] = h[i];
            continue;
        }
        rep(j, k + 1)
        {
            dp[i][j] = INF;
            rep(m, j + 1)
            {
                if( i - 1 - m < 0 )
                {
                    dp[i][j] = min(dp[i][j], h[i]);
                    break;
                }
                _LL tmp = dp[i - 1 - m][j - m];
                if( h[i] > h[i - 1 - m] ) tmp += h[i] - h[i - 1 - m];
                dp[i][j] = min(dp[i][j], tmp);
            }
        }
    }

    _LL ans = INF;
    
    rep(m, k + 1)
    {
        ans = min(ans, dp[n - 1 - m][k - m]);
    }
//    rep(i, n)
//        rep(j, k + 1) cout << i << "," << j << "," << ":" << dp[i][j] << endl;
    cout << ans << endl;
}

Measured memory_bytes: 3908
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	printf("%d",(c-a)*60+d-b-e);
}

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

const int N=2e3+5,K=1e4+5,S=1e6+5,C=26;

#define bs bitset<S> 

int n,k,len[N],st[N];
bitset<K> f[N];
char s[N][K];

bs tr[C<<2],pos[C];

#define lk k<<1
#define rk k<<1|1
#define mid (l+r>>1)

inline void mdy(int pos,int val,int k=1,int l=0,int r=C-1){
  tr[k][val]=1;
  if(l==r)return;
  if(pos<=mid)mdy(pos,val,lk,l,mid);
  else mdy(pos,val,rk,mid+1,r);
}

bs state;

inline int qry(int k=1,int l=0,int r=C-1){
  if(l==r)return l;
  if((state&tr[lk]).none())return qry(rk,mid+1,r);
  return qry(lk,l,mid);
}

int main(){
  scanf("%d%d",&n,&k);
  for(int i=1;i<=n;i++)scanf("%s",s[i]+1),len[i]=strlen(s[i]+1);
  f[n+1][0]=1;
  for(int i=n;i;i--)for(int j=k;~j;j--)f[i][j]=f[i+1][j]|(j>=len[i]?f[i+1][j-len[i]]:0);
  for(int t=0,i=1;i<=n;i++){
    st[i]=t+1;
    for(int j=1;j<=len[i];j++){
      t++;
      mdy(s[i][j]-'a',t);
      pos[s[i][j]-'a'][t]=1;
    }
    if(i==n)st[n+1]=t+1;
  }

  state[1]=1;

  for(int i=1;i<=k;i++){
    for(int j=1;j<=n;j++)if(state[st[j]])state[st[j+1]]=1;
    for(int j=1;j<=n;j++)if(k-i+1<len[j]||!f[j+1][k-i+1-len[j]])state[st[j]]=0;
    int x=qry();
    putchar(x+'a');
    (state&=pos[x])<<=1;
  }

  return 0;
}


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

int n;
vector<int> v;
vector<int> p1(100001, 0);
vector<int> p2(100001, 0);

int main() {
	cin >> n;
	v.resize(n);
	for (int i = 0; i < n; ++i) cin >> v.at(i);


	for (int i = 0; i < n; ++i)
	{
		if (i%2==0)
		{
			p1.at(v.at(i))++;
		} else {
			p2.at(v.at(i))++;
		}
	}

	int a=0, b=0, ac=0, bc=0;

	for (int i = 0; i < 100001; ++i)
	{
		if (p1.at(i) > ac)
		{
			a = i;
			ac = p1.at(i);
		}

		if (p2.at(i) > bc)
		{
			b = i;
			bc = p2.at(i);
		}
	}

	int a2=0, b2=0, ac2=0, bc2=0;

	for (int i = 0; i < 100001; ++i)
	{
		if (p1.at(i) > ac2 && i != a)
		{
			a2 = i;
			ac2 = p1.at(i);
		}

		if (p2.at(i) > bc2 && i != b)
		{
			b2 = i;
			bc2 = p2.at(i);
		}
	}

	if (a==b)
	{
		if (ac-ac2 > bc-bc2)
		{
			b = b2;
		} else {
			a = a2;
		}
	}

	int ans = 0;

	for (int i = 0; i < n; ++i)
	{
		if (i%2==0)
		{
			if (v.at(i)!=a) ans++;
		} else {
			if (v.at(i)!=b) ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    string T; cin >> T;
    REP(i, T.size()) {
        char c;
        if (T[i] == '?') {
            c = 'D';
        } else {
            c = T[i];
        }
        cout << c;
    }
    cout << "\n";
}


Measured memory_bytes: 3784
N,K = map(int,input().split())

okasi = [0] * (N + 1)
for i in range(K):
	d = int(input())
	A = list(map(int,input().split()))
	for j in range(d):
		okasi[A[j]] = 1
#print(okasi)

count = 0
for i in range(1,N +1,1):
	if okasi[i] != 1:
		count = count + 1
print(count)

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,sum=0;
  cin>>a>>b;
  for(int i=0; i<2; i++){
    if(a>b){
      sum+=a;
      a--;
    }else{
      sum+=b;
      b--;
    }
  }
  cout<<sum<<'\n';
  return 0;
}


Measured memory_bytes: 256