akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int n,m;
vector<vector<pii> > g;
bool hako[111111];
int kyori[111111];
int iro[111111];

bool dfs(int x,int d,int iro_i){
  //printf(":::%x\n",x);
  if(iro[x]!=0 && iro_i!=iro[x]) return true;
  
  if(kyori[x]==-1) kyori[x]=d;
  else if(kyori[x]!=d) return false;
  else return true;
  iro[x]=iro_i;
  
  for(int i=0;i<g[x].size();i++){
    if(!dfs(g[x][i].first,d+g[x][i].second,iro_i)) return false;
  }
  return true;
}

int main(void){
  cin>>n>>m;
  int l,r,d;
  g.resize(n+1,vector<pii>());
  memset(kyori,-1,sizeof kyori);
  
  for(int i=0;i<m;i++){
    cin>>l>>r>>d;
    g[l].pb(pii(r,d));
    hako[r]=true;
  }
  
  bool f=true;
  int iro_i=1;
  for(int i=1;i<=n;i++){
    if(hako[i]||iro[i]!=0) continue;
    if(!dfs(i,0,iro_i)){
      f=false;
      break;
    }
    iro_i++;
  }
  for(int i=1;i<=n;i++){
    if(kyori[i]==-1) f=false;
  }
  if(f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  /*
  for(int i=1;i<=n;i++){
    printf("%d : iro=%d kyori=%d\n",i,iro[i],kyori[i]);
  }
  */
  return 0;
}



Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<sstream>
#include<stdio.h>
using namespace std;

int main(){
    int n; 
    cin >> n;
    int count = 0;
    for(int i = 1; i <= n; i++){
        ostringstream oss;
        oss << i;
        //printf("%s\n", oss.str().c_str());
        if(oss.str().size() % 2 != 0){
            count++;
            //printf("%s\n", oss.str().c_str());
        }

    }
    cout << count << endl;
}

Measured memory_bytes: 256
import sys

nn=int(input())
s_list=[]
for i in range(nn):
	s_list.append(str(input()))
mm=int(input())
t_list=[]
for j in range(mm):
	t_list.append(str(input()))

count_list=[]
for k in range(nn):
	name = s_list[k]
	count=0
	for l in range(nn):
		if name==s_list[l]:
			count+=1
	for m in range(mm):
		if name==t_list[m]:
			count-=1
	count_list.append(count)

for n in range(mm):
	name = t_list[n]
	count=0
	for o in range(nn):
		if name==s_list[o]:
			count+=1
	for p in range(mm):
		if name==t_list[p]:
			count-=1
	count_list.append(count)
max_value=max(count_list)
if max_value<=0:
	max_value=0
print(max_value)


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int count = 0;
  for(int i=a; i<=b; i++){
    if(c%i == 0)
      count++;
  }
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3120
/*
 * Created By : pash123
 * 2020-09-19-17.21
*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

const int M=1e9+7;

vector<pair<int,int> > inputs;

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        int x,y;
        cin>>x>>y;
        inputs.push_back(make_pair(x,y));
    }
    bool isOccur=false;
    for(int i=0;i<n;++i)
    {
        int j=i;
        if(inputs[j].first==inputs[j].second)
        {
            if(j+2<n)
            {
                if((inputs[j+1].first==inputs[j+1].second) && (inputs[j+2].first==inputs[j+2].second))
                {
                    isOccur=true;
                    break;
                }
            }
        }

    }
    isOccur?cout<<"Yes":cout<<"No";
    return 0;
}


Measured memory_bytes: 3632
import numpy as np

N, X = map(int, input().split())
L = list(map(int, input().split()))
# D = [np.array([])]
D = [0, 0]

for i in range(2, N + 2):
    D.append(D[i - 1] + L[i - 2])

D2 = np.array(D)

D3 = D2[D2 <= X]    # X以下の要素を抽出

print('{}'.format(D3.size - 1))    # 回数を出力










Measured memory_bytes: 12504
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

signed main()
{
	ios::sync_with_stdio(false);
	int n;cin>>n;
	if(n==0){
		cout<<0<<endl;
		return 0;
	} 
	string ans="";
	while(n!=0){
		if(n%2==0){
			ans+="0";
			n/=(-2);
		}
		else{
			ans+="1";
			if(n<0) n=(n-1)/(-2);
			else n/=(-2);
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 1e5+23;
int a[maxn];
const int mod = 1e9+7;
int n,k;
int fac[maxn],inv[maxn];

int qpow(int a,int b)
{
    int ans=1;
    while(b){
        if(b&1) ans=1ll*ans*a%mod;
        b>>=1;
        a=1ll*a*a%mod;
    }
    return ans;
}

int comb(int i,int j)
{
    if(i<j) return 0;
    return 1ll*fac[i]*inv[j]%mod*inv[i-j]%mod;
}


int main()
{
    cin>>n>>k;
    fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
    inv[n]=qpow(fac[n],mod-2);
    for(int i=n-1;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
    for(int i=0;i<n;i++) scanf("%d",a+i);
    sort(a,a+n);ll ans=0;
    for(int i=n-1;i>=0;i--){
        ans=(ans+1ll*a[i]*comb(i,k-1)%mod)%mod;
    }
    for(int i=0;i<n;i++){
        ans=(ans-1ll*a[i]*comb(n-i-1,k-1)%mod+mod)%mod;
    }
    cout<<ans;
}


Measured memory_bytes: 1408
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> cake(h);
    REP(i, h)
        cin >> cake[i];

    vector<bool> empty(h, true);
    REP(i, h){
        REP(j, w){
            if(cake[i][j] == '#')
                empty[i] = false;
        }
    }
    vector<vector<int>> ans(h, vector<int>(w, 0));
    int now = 1;
    REP(i, h){
        if(empty[i])
            continue;
        bool first = true;
        REP(j, w){
            if(cake[i][j] == '#'){
                if(!first)
                    now++;
                else
                    first = false;
            }
            ans[i][j] = now;
            int k = i+1;
            while(k < h && empty[k]){
                ans[k][j] = now;
                k++;
            }
            k = i - 1;
            while(k >= 0 && empty[k]){
                ans[k][j] = now;
                k--;
            }
        }
        now++;
    }

    for(auto line: ans){
        print_container(line);
    }
    return 0;
}

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

using namespace std;

int main(void){
    int k, a, b;
    cin >> k >> a >> b;
    bool ok = false;
    for(int i = 1; i <= b; i++){
        if(a <= k * i && k * i <= b)ok = true;
    }
    if(ok){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
}

Measured memory_bytes: 3624
/*
 * ----------------------------------------------------------------------------
 *  (: Bismillahir Rahmanir Rahim :) 
 * File: /home/grimfirefly/Programming/Atcoder/Today/A_Plural_Form.cpp
 * Project: /home/grimfirefly/Programming/Atcoder/Today
 * Created Date: Saturday, September 19th 2020, 6:00:55 pm
 * Author: Grim Firefly :)
 * Author Mail : GrimFirefly1@gmail.com
 * -----
 * Last Modified: Sat Sep 19 2020
 * Modified By: Grim Firefly :)
 * -----
 *   ________        .__           ___________.__                  _____ .__          
 *  /  _____/_______ |__|  _____   \_   _____/|__|_______   ____ _/ ____\|  |  ___.__.
 * /   \  ___\_  __ \|  | /     \   |    __)  |  |\_  __ \_/ __ \\   __\ |  | <   |  |
 * \    \_\  \|  | \/|  ||  Y Y  \  |     \   |  | |  | \/\  ___/ |  |   |  |__\___  |
 *  \______  /|__|   |__||__|_|  /  \___  /   |__| |__|    \___  >|__|   |____// ____|
 *         \/                  \/       \/                     \/              \/     
 * 
 *           |\_|\
 *           | a_a\
 *           | | "]
 *       ____| '-\___
 *      /.----.___.-'\
 *     //        _    \
 *    //   .-. (GF)  /|
 *   |'|  /\:  .--  / \
 *  // |-/  \_/____/\/~|
 * |/  \ |  []_|_|_] \ |
 * | \  | \ |___   _\ ]_}
 * | |  '-' /   '.'  |
 * | |     /    /|:  | 
 * | |     |   / |:  /\
 * | |     /  /  |  /  \
 * | |    |  /  /  |    \
 * \ |    |/\/  |/|/\    \
 *  \|\ |\|  |  | / /\/\__\
 *   \ \| | /   | |__
 *        / |   |____)
 *        |_/
 * ----------------------------------------------------------------------------
 */

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

//constant
#define PI acos(-1.0)
#define SZ 10000
#define mod 1000000007
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef unsigned un;
typedef pair<int, int> pii;
typedef vector<int> vi;

//Debug Setting up
#define watch(x) cout << (#x) << "=" << x << endl
#define watch2(x, y) cout << (#x) << "=" << x << " & " << (#y) << "=" << y << endl;
#define watchara(wow)     \
    for (auto x : wow)    \
    {                     \
        cout << x << " "; \
    }                     \
    cout << "\n"

//defining fast_io
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

//defining something
#define F first
#define S second

//Main Function Start From Here
void solve()
{
    string str;
    cin >> str;
    cout << str;
    if (*str.rbegin() == 's')
        cout << "es" << endl;
    else
        cout << 's' << endl;
}

int main()
{
    fast_io;

    solve();

    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
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; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  ll n,a,b; cin >> n >> a >> b;
  ll minnum = a * (n-1) + b;
  ll maxnum = a + b * (n-1);
  cout << max(0LL,maxnum - minnum + 1) << "\n";
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
const int Nmax=200010;
 
int main() {
	int K;
 	bool flag=true;
	ll A[Nmax];
	cin >> K;
	for(int i=0;i < K;i++) cin >> A[i];
	if(A[K-1] != 2){
		cout << "-1" << endl;
		return 0;
	}
	ll mina=2,mac=3; //最少人数
	for(int i=K-2;i >= 0;i--){
      	//ll a = A[i] % mina;
      	//ll b = mina;
	  	if(mina > mac) flag=false;
		if(A[i] >= mina) mina = A[i];
		else mina = ceil((double)mina/A[i]) * A[i];
      	//if(mina-b > a) flag = false; //あり得ない人数離脱したらfalse
	  	mac = (mac/A[i]+1) * A[i] -1;
	}
 	if(mina > mac) flag = false;
	if(flag) cout << mina << " " << mac << endl;
  	else cout << "-1" <<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define PI 3.14159265359

int main(){
  ll N, i;
  string ans = "pon";
  cin >> N;
  N = N%10;
  if(N == 2 || N == 4 || N == 5 || N == 7 || N == 9){
    ans = "hon";
  } else if(N == 3){
    ans = "bon";
  }

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

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
    int x, y, a, b, c;
    vector<int> p(100001,0), q(100001,0), r(100001,0);
    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i < a; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> q[i];
    }
    for (int i = 0; i < c; i++) {
        cin >> r[i];
    }
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());
    for (int i = x; i < a; i++) {
        p[i] = 0;
    }
    for (int i = y; i < b; i++) {
        q[i] = 0;
    }
    int ii = 0, jj = 0, kk = 0;
    long long res = 0;
    for (int sum = 0; sum < x+y; sum++) {
        if (r[kk] >= p[ii] && r[kk] >= q[jj]) {
            // cout << "r " << r[kk] << endl;
            res += r[kk]; kk++;
        } else if (p[ii] >= q[jj] && p[ii] >= r[kk]) {
            // cout << "p " << p[ii] << endl;
            res += p[ii]; ii++;
        } else if (q[jj] >= p[ii] && q[jj] >= r[kk]) {
            // cout << "q " << q[jj] << endl;
            res += q[jj]; jj++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1408
import sys

N, M = [int(_) for _ in input().split()]
a = [-1 for i in range(N+1)]
for i in range(M):
    s, c = [int(_) for _ in input().split()]
    if a[s] != -1:
        if c != a[s]:
            print(-1)
            sys.exit(0)
    else:
        a[s] = c
if a[1] == 0:
    if N == 1:
        print(0)
    else:
        print(-1)
    sys.exit(0)
for i in range(1, N+1):
    if a[i] == -1:
        if i == 1:
            if N == 1:
                a[i] = 0
            else:
                a[i] = 1
        else:
            a[i] = 0

print(*a[1:], sep='')


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define VI vector<int>
#define VII vector<pair<int, int>>
#define PII pair<int, int>
#define MP make_pair
// #define log(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define log(fmt, ...)
// #define check(...) assert(##__VA_ARGS__)
#define check(...)

int n;

void dfs(int index, string s, int max_till_now) {
    if (index > n) {
        cout << s << el;
        return;
    }
    rep(i, 'a', max_till_now + 1) {
        s.push_back(i);
        dfs(index + 1, s, max(i, max_till_now));
        s.pop_back();
    }
}

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

    cin >> n;

    string s = "a";
    dfs(2, s, 'a');
}


Measured memory_bytes: 1536
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <string>

int main() {
  char buf[128];
  scanf("%s", buf);
  std::string s = buf;

  size_t res = 0;
  size_t n = s.length();
  for (size_t i = 0; i < n; ++i) {
    if (s[i] != s[n-i-1]) {
      s[n-i-1] = s[i];
      ++res;
    }
  }
  printf("%zu\n", res);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e12;
using namespace std;

int main(){
    ll n; cin>>n;
    ll ans = INF;
    for(ll i=1; i*i<=n; i++){
        if(n%i == 0){
            ans = min(ans,i+n/i-2);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll N, M;
    in >> N>> M;
    ll ans = N*(N-1) / 2 + M*(M-1)/2;

    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef struct two{
	int num;
	int time;	
}Do;
bool cmp(Do x, Do y)
{
	if(x.num < y.num)
		return 1;
	return 0;
}
int main()
{
	Do a[100005];
	int n, i;
	long long k ;
	cin>>n>>k;
	for(i = 0; i < n; i++)
		cin>>a[i].num>>a[i].time;
	sort(a, a + n, cmp);
	//cout<<a[0].num<<endl;
	//cout<<a[9].num<<endl;
	for(i = 0; i < n;i++)
	{
		//cout<<k<<endl;
	//	cout<<a[i].num<<endl;
		if(k - a[i].time <= 0)
		{
			cout<<a[i].num;
			break;
		}
		k = k - a[i].time;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M; cin >> N >> M;
    string s, t; cin >> s >> t;
    ll lc = lcm(N, M);
    if(N < M){
        swap(s, t); swap(N, M);
    }
    
    ll gn = lc / N, gm = lc / M;
    REP(i, N){
        ll idx = i*gn;
        if(idx % gm != 0) continue;
        if(s[i] != t[idx/gm]){
            cout << -1 << endl; return 0;
        }
    }
    REP(i, M){
        ll idx = i*gm;
        if(idx % gn != 0) continue;
        if(t[i] != s[idx/gn]){
            cout << -1 << endl; return 0;
        }
    }
    cout << lc << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// union by size + path having
class UnionFind {
public:

    //素集合の要素の親（木構造の根）を配列*3で保持している．初期状態では頂点間の辺は存在せず，孤立した状態のため，自分自身を根として初期化している（par: parent の略）．
    vector <ll> par;

    // 各集合（木）の大きさ．根をたどるとその木の大きさが返されるように実装されている．この配列を用意しておくとある頂点の連結成分の大きさを簡単に求められる
    vector <ll> siz;

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    int N, M, x, y;
    cin >> N >> M;
    vector<int> p(N), correct(N);
    rep(i, N) {
        cin >> x;
        x--;
        p.at(i) = x; // p[i] に x が入っている
        correct.at(x) = i; // 現在 x が入っている座標は　i　である
    }
    UnionFind uf(N);
    rep(i, M){
        cin >> x >> y;
        x--;
        y--;
        uf.merge(x, y);
    }
    rep(i, N){
        if(p.at(i) == i) continue;
        else if(uf.issame(i, correct.at(i))) {
            p.at(correct.at(i)) = p.at(i); // p[i] は交換元の座標に入れる
            correct.at(p.at(i)) = correct.at(i);
            correct.at(i) = i;
            p.at(i) = i;
        }
    }
    int ans = 0;
    rep(i, N) {
        if(p.at(i) == i) ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 5560
#include<bits/stdc++.h>
using namespace std;
#define M 1e9 + 7
#define C 998244353
#define pi 3.14159265359
#define loop(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define rloop(i,a,b) for(ll i = ll(a); i >= ll(b); --i)
#define sloop(i,a) for (std::set<ll>::iterator i = a.begin(); i != a.end(); ++i)
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;

vector<ll>edges[1005];
bool visited[1005];
vector<ll> nodes;
ll ans=0;

void dfs(ll m){
    ans++;
    visited[m] = true;
    for (std::vector<ll>::iterator i = edges[m].begin(); i != edges[m].end(); ++i)
    {
        if(!visited[*i]){
            dfs(*i);
        }
    }

}
void solve(){
    ll n,m;
    cin >> n >> m;
    cout << n*m << "\n";
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    loop(f,0,t){    
        solve();
    }   
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<s.length();++i)
		if(s[i]!=',')cout<<s[i];
		else cout<<" ";
	cout<<endl;
	return 0;
} 

Measured memory_bytes: 256
N,*as=$<.read.split.map(&:to_i)

arr = Array.new(N+1,0)
as.each do |a|
  arr[a] += 1
end

sum = arr.map {|n| n * (n-1) / 2 }.inject(&:+)

as.each do |a|
  p sum - (arr[a]-1)
end



Measured memory_bytes: 34072
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String S = in.next();
            int score = 0;

            for (int i = 0; i < S.length(); i++) {
                char my = i % 2 == 0 ? 'g' : 'p';
                char his = S.charAt(i);

                if (my != his) {
                    score += my == 'p' ? 1 : -1;
                }
            }
            out.println(score);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}


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

#define pb push_back
#define mp make_pair
#define F(i, a, n, b) for(int i=a;i<n;i+=b)
#define REVF(i, a, b, c) for(int i=a;i>=b;i-=c)
#define REP(i, n) F(i, 0, n, 1)
#define REP1(i, n) F(i, 1, n+1, 1)
#define REV(i, n) REVF(i, n, 0, 1)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef long long ll;

const int MAX = 3e6 + 5;

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

	cin>>a>>b;
	if(a <= 9 && b <= 9)
		cout<<a*b;
	else
		cout<<-1;	
	return 0;
}

Measured memory_bytes: 256
import sys

N, M = (int(i) for i in input().split())
A = []
B = []
for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())

for i in range(N-M+1):
    if B[0] in A[i]:
        pos = A[i].find(B[0])
        flag = 0
        for j in range(M):
            if A[i+j][pos:pos+M] == B[j]:
                pass
            else:
                flag = -1
                break
        if flag == 0:
            print("Yes")
            sys.exit()

print("No")

Measured memory_bytes: 3064
"use strict";

var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );

readable.on( 'data', function( chunk ) {
		var data = chunk.split( ' ' );
		var a = parseInt( data[0] );
		var b = parseInt( data[1] );
		var c = parseInt( data[2] );
		if( a < b && b < c) {
			console.log( "Yes" );
		} else {
			console.log( "No" );
		}
});



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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll REM( ll a )
{
	a %= MOD;
	if ( a < 0 )
	   a += MOD;
	return a;
}

ll ADD( ll a, ll b )
{
	return REM( REM( a ) + REM( b ) );
}

ll SUB( ll a, ll b )
{
	return REM( REM( a ) - REM( b ) );
}

ll MUL( ll a, ll b )
{
	return REM( REM( a ) * REM( b ) );
}

ll POT( ll n, ll k )
{
	if ( k == 0 )
		return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 )
		return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
	return MUL( a, POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
	for ( ll i = 2;i <= sqrt( x ); i++ )
		if ( x % i == 0 )
			return false;
	return true;
}

ll x, y;

int main()
{
	cin >> x >> y;
	cout << x / __gcd( x, y ) * y << "\n";
	return 0;
}


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

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

int n;
string s, t;

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

  cin >> n;
  cin >> s >> t;
  string res;
  for (int i = 0; i < n; ++i) {
    res += s[i];
    res += t[i];
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}

bool IsPrime(int m){
    if(m<2) return false;
    if(m==2) return true;
    if(m%2==0) return false;

    double root_m = sqrt(m);

    for(int i=3; i<root_m; i+=2){
        if(m%i==0) return false;
    }

    return true;
}

int main(){
    int n;
    cin >> n;
    printf("%d:", n);
    if(IsPrime(n)){
        printf(" %d\n", n);
        return 0;
    }
    while(n%2==0){
        printf(" %d", 2);
        n/=2;
    }
    
    int divider = 3;

    while(divider<n){
        while(n%divider==0){
            printf(" %d", divider);
            n /= divider;
        }

        while(1){
            divider += 2;
            if(IsPrime(divider)) break;
        }
    }
    if(divider==n) {
        printf(" %d\n", divider);
    }else{
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 3224
k,t = map(int,input().split())
l = list(map(int,input().split()))

if len(l) == 0:
    print(l[0]-1)
    exit()

m = max(l)
s = sum(l)-m

if m-1 > s:
    print(m-s-1)
else:
    print(0)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int n, m;
vector<vector<bool>> graph;

void dfs(vector<bool> &visit, int v){
    if(visit[v]){
        return;
    }
    visit[v] = true;
    rep(i, n){
        if(graph[v][i]){
            dfs(visit, i);
        }
    }
}

int main() {

    cin >> n >> m;

    vector<int> a(m), b(m);
    graph.assign(n, vector<bool>(n));
    rep(i, m){
        int x, y;
        cin >> x >> y;
        a[i] = --x;
        b[i] = --y;
        graph[x][y] = true;
        graph[y][x] = true;
    }

    int ans = 0;
    rep(i, m){
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        vector<bool> visit(n);
        dfs(visit, 0);
        rep(k, n){
            if(!visit[k]){
                ans++;
                break;
            }
        }
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    cout << ans << endl;

    return 0;
}


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

int main(void){
    long long int x[2],y[2];
    cin >> x[0] >> y[0];
    
    x[1] = -x[0],y[1] = -y[0];
    
    long long int ans = -1;
    for(int i = 0;i < 2;i++){
        for(int j = 0;j < 2;j++){
            if(x[i] <= y[j]){
                long long int num = (i+j) + (y[j]-x[i]);
                
                if(ans == -1)ans = num;
                else ans = min(ans,num);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,m,ans=0;
  cin>>n>>m;
  vector<ll>v(n,0);
  multiset<ll> st;
  for(ll i=0;i<n;i++){
    cin>>v[i];
    st.insert(v[i]);
  }
  for(ll i=0;i<m;i++){
    auto it=st.end();
    it--;
    ll x=*it;
    x=x/2;
    st.erase(it);
    st.insert(x);
  }
  for(auto i=st.begin();i!=st.end();i++){
    ans+=*i;
  }
  cout<<ans<<endl;


}


Measured memory_bytes: 5760
def row(A):
  B = []
  for a in A:
    if "#" in a:
      B.append(a)
  return B

def trans(A):
  c = len(A[0])
  B = []
  for i in range(c):
    C = ""
    for j in range(len(A)):
      C += A[j][i]
    B.append(C)
  return B

def col(A):
  return trans(row(trans(A)))
        
      

H, W = map(int, input().split())
A = []
for i in range(H):
  A.append(input())

while col(A) != A or row(A) != A:
  A = col(A)
  A = row(A)

for i in A:
  print(i)

Measured memory_bytes: 39280
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A*C <= B)cout << C << endl;
	else cout << B / A << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s; cin >> s;
    int n = s.size();
    map<char,int> mp;
    rep(i,n) mp[s[i]]++;
    ll ans = (ll)n*(n-1)/2 + 1;
    for (P p : mp) ans -= (ll)p.second*(p.second-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 3760
void main()
{
    dchar[] c = rdDchar;
    dchar[] d = rdDchar;

    dchar[] e = c.dup;
    dchar[] f = d.dup;
    reverse(e);
    reverse(f);

    writeln(c == f && d == e ? "YES" : "NO");
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

int main() {
	int n;
	cin >> n;
	bool flag = false;
	int ans;
	int arrays[100000] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> arrays[i];
	}
	sort(arrays, arrays + n, greater<int>());//大きい順番 40 10 8 2
	for (int i =n-2; i >- 1; i--) {
		if (arrays[i] % arrays[n - 1] != 0) {
			flag = true;
			int a = arrays[i];
			int b = arrays[n - 1];
			int r = a % b;
			while (r != 0) {
				a = b;
				b = r;
				r = a % b;
			}
			ans = b;
		}
	}
	if (flag == true) {
		cout << ans;
	}
	else {
		cout << arrays[n - 1];//一番小さい数で割り切れてしまうなら単純
	}
}

Measured memory_bytes: 640
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int main(){
 ll h,w,d;
 cin>>h>>w>>d;
V<P> a(h*w+1);
for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
       int d;cin>>d;
       a[d]=P(i,j);
    }
}
V<ll> sum(h*w+1,0);
for(int i=1;i<=h*w-d;i++){
    sum[i+d]=sum[i]+(abs(a[i+d].fi-a[i].fi)+abs(a[i+d].se-a[i].se));
}
int q;
cin>>q;
while(q--){
    int l,r;
    cin>>l>>r;
    cout<<sum[r]-sum[l]<<endl;
}
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
bool judge(int n)
{
	int counter=0;
	while(n>=10)
	{
		n/=10;
		counter++;
	}
	if(counter%2) return false;
	    else return true;
}
int main()
{
	int N,cnt=0;
	cin >> N;
	for(int i=1;i<=N;i++)
	{
		if(judge(i)) cnt++;
	}
	cout << cnt;
	return 0;
}

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

using namespace std;

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl

const int maxn = (int)1e6+5;
typedef long long ll;

int cnt[maxn];
void solve(){

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

   int ans = 0;
   for(int i=1 ; i<=n ; i++){
      if(cnt[a[i]]){
         cnt[a[i]] = 2;
         continue;
      }
      int val = a[i];
      for(int j=val ; j<maxn ; j+=(val)){
         cnt[j]++;
      }
   }

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

      if(cnt[a[i]]<=1) ans++;
   }

   cout << ans << endl;

}


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

    //cout << "Fi Amanillah" << endl;

    int t=1;
    //cin >> t;
    while(t--){
      solve();
    }
    return 0;
}



Measured memory_bytes: 8264
from heapq import heappop, heappush
from collections import defaultdict
import sys
sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


class Dijkstra:
    """Graph input:
    {
    node:{node:cost,node:cost...},
    node:{node:cost,node:cost...},
    ...
    }
    """

    def __init__(self, graph: dict, N: int):
        self.graph = graph
        self.costs = [float("inf")] * N

    def calculate(self, start):
        queue = list()

        # step1: push the start point into the priority queue
        self.costs[start] = 0
        heappush(queue, (0, start))  # (cost,node)

        while queue:
            # step2: get the minimum cost node from unfixed node and fix the cost
            cost_from_start, min_node = heappop(queue)

            # step3: update the direct connected nodes
            for link, cost in self.graph[min_node].items():
                if cost_from_start + cost < self.costs[link]:
                    self.costs[link] = cost_from_start + cost
                    heappush(queue, (self.costs[link], link))

        return self.costs


def main():
    h, w = input_int_list()

    G = defaultdict(dict)
    for i in range(10):
        line = input_int_list()
        for j in range(10):
            G[j][i] = line[j]

    # 1へ変換するコストをダイクストラ法で求める
    dijkstra = Dijkstra(G, 10)
    costs = dijkstra.calculate(1)

    cnts = defaultdict(int)
    for _ in range(h):
        line = input_int_list()
        for n in line:
            cnts[n] += 1

    ans = 0
    for k, v in cnts.items():
        if k == -1 or k == 1:
            continue
        ans += costs[k] * v

    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 68136
#include<bits/stdc++.h>
#define long long long
using namespace std;
const long N=1e6,inf=1e9;
pair<long,long>pp[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  long n,d,a;cin>>n>>d>>a;

  for(long i=1;i<=n;i++)
    cin>>pp[i].first>>pp[i].second;
  sort(pp+1,pp+n+1);

  priority_queue<pair<long,long> >pq;long cnt=0;
  long ans=0;
  for(long i=1;i<=n;i++)
  {
    while(cnt)
    {
      if((-pq.top().first)<pp[i].first)
      {
        cnt-=pq.top().second;pq.pop();
      }
      else break;
    }
    long h=pp[i].second-cnt*a;
    if(h<=0)continue;
    long ad=(h+a-1)/a;pq.push({-(pp[i].first+2*d),ad});
    cnt+=ad;ans+=ad;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6516
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
void solve()
{
	int n,k;
	cin>>n>>k;
	int cnt=0;
	while(1){
		n/=k;
		cnt++;
		if(n==0){
			break;
		}
	}
	cout<<cnt<<endl;
}

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


Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
T = [0]*N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        T[i] = T[i-1] + 1
    else:
        T[i] = T[i-1]
for j in range(Q):
    left, right = map(int, input().split())
    print(T[right-1]-T[left-1])

Measured memory_bytes: 6140
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int k;
    cin >> k;
    vector<ll> a;
    for(int i=1; i<=9; i++) a.push_back(i);
    while(1){
        if(k <= a.size()){
            cout << a[k-1] << endl;
            return 0;
        }
        k -= a.size();
        vector<ll> old;
        swap(old, a); //配列a,oldを交換
        for(ll x : old){
            for(int i=-1; i<=1; i++){
                int d = x%10 + i;
                if(d<0 || d>9) continue;
                ll nx = x*10 + d;
                a.push_back(nx);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1840
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
  int m, n;
  
  while(cin >> n >> m){
    if(n == 0 && m == 0) break;
    
    vector<int> person(n+1);
    
    for(int i = 1 ; i <= n ; i++){
      person[i] = i;
    }
    int cnt = 1;
    
    for(vector<int>::iterator it = person.begin()+1 ; person.size() != 1 ;){
      if(it == person.end()) it = person.begin()+1;
      
      if(cnt % m == 0) it = person.erase(it);
      else it++;
      cnt++;
    }
    
    cout << person[1] << endl;
  }
  return 0;
}

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

int main() {
  int N, K, a = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    if (a < K) {
      a = a * 2;
    }else {
      a = a + K;
    }
  }
  cout << a << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
int main()
{
	ll mod = 1000000007;
	ll N,K;
	ll i,j,k;
	cin>>N>>K;
	k=0;
	for(i=1;i<=N;++i)
	{
		for(j=1;j<=K;++j)
		{
			if(i==((int)(j/10))*((int)(j%10))&&(j/10)>1&&(j%10)>1)
			{
				k++;
			}
		}
	}
	cout << k << endl;
	return 0;
}




















Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
#include <queue>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
//input
int main(void)
{
    int N;
    string s;
    cin >> N;
    if (N >= 30)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624