akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

// ax+b -> c(ax+b) + d = acx + bc + d

const int MOD = 998244353;

template<typename T>
class LazySegTree {
public:
    explicit LazySegTree(int n, vector<T> init, T def) : N(calcN_(n)), def(def) {
        mVal.assign(2*N-1, 0);
        for(int i=0;i<init.size();i++) mVal[N-1+i] = init[i];
        for(int i=N-2;i>=0;i--) mVal[i] = operate_(mVal[2*i+1], mVal[2*i+2]);
        mLazy.assign(2*N-1, make_pair(1, 0));
        mDirty.assign(2*N-1, 0);
    }
    void update(int l, int r, pair<long long, long long> value){
        updateImpl_(l, r, value, 0, 0, N);
    }
    T get(int l, int r){
        return getImpl_(l, r, 0, 0, N);
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    void updateImpl_(int l, int r, pair<long long, long long> value, int idx, int rangeL, int rangeR){
        eval_(idx, rangeL, rangeR);
        if(r <= rangeL || rangeR <= l) return;
        if(l <= rangeL && rangeR <= r){
            setLazy_(idx, value);
            eval_(idx, rangeL, rangeR);
        } else {
            int rangeM = (rangeL+rangeR)/2;
            updateImpl_(l, r, value, 2*idx+1, rangeL, rangeM);
            updateImpl_(l, r, value, 2*idx+2, rangeM, rangeR);
            mVal[idx] = operate_(mVal[2*idx+1], mVal[2*idx+2]);
        }
    }
    void setLazy_(int idx, pair<long long, long long> value){
        auto cur = mLazy[idx];
        mLazy[idx].first = (cur.first * value.first) % MOD;
        mLazy[idx].second = (cur.second * value.first + value.second) % MOD;
        mDirty[idx] = 1;
    }
    T getImpl_(int l, int r, int idx, int rangeL, int rangeR){
        if(r <= rangeL || rangeR <= l) return def;
        eval_(idx, rangeL, rangeR);
        if(l <= rangeL && rangeR <= r) return mVal[idx];
        int rangeM = (rangeL+rangeR)/2;
        T a = getImpl_(l, r, 2*idx+1, rangeL, rangeM);
        T b = getImpl_(l, r, 2*idx+2, rangeM, rangeR);
        return operate_(a, b);
    }
    void eval_(int idx, int rangeL, int rangeR){
        if(!mDirty[idx]) return;
        mVal[idx] = (mLazy[idx].first * mVal[idx] + (rangeR - rangeL) * mLazy[idx].second) % MOD;
        if(idx < N-1){
            setLazy_(2*idx+1, mLazy[idx]);
            setLazy_(2*idx+2, mLazy[idx]);
        }
        mLazy[idx] = make_pair(1, 0);
        mDirty[idx] = 0;
    }
    T operate_(T a, T b) const { return (a + b) % MOD; }
    const int N;
    const T def;
    vector<T> mVal;
    vector<pair<long long, long long>> mLazy;
    vector<int> mDirty;
};

int main(){
    int N, Q; cin >> N >> Q;
    vector<long long> a(N);
    for(auto& t : a) cin >> t;
    LazySegTree<long long> seg(N, a, 0);
    for(int i=0;i<Q;i++){
        int t; cin >> t;
        if(t == 0){
            int l, r, b, c; cin >> l >> r >> b >> c;
            seg.update(l, r, make_pair(b, c));
        } else {
            int l, r; cin >> l >> r;
            cout << seg.get(l, r) << endl;
        }
    }
}

Measured memory_bytes: 39692
#include <stdio.h>
 
int main(void){

	int A[3][10],B[3][10],C[3][10],D[3][10],i,ii,n,b[300],f[300],r[300],v[300];

	for(i=0;i<3;i++){
		for(ii=0;ii<10;ii++){
			A[i][ii]=0;
		}
	}
	for(i=0;i<3;i++){
		for(ii=0;ii<10;ii++){
			B[i][ii]=0;
		}
	}
	for(i=0;i<3;i++){
		for(ii=0;ii<10;ii++){
			C[i][ii]=0;
		}
	}
	for(i=0;i<3;i++){
		for(ii=0;ii<10;ii++){
			D[i][ii]=0;
		}
	}

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&b[i],&f[i],&r[i],&v[i]);
	}

	for(i=0;i<n;i++){
		if(b[i]==1){
			A[f[i]-1][r[i]-1]+=v[i];
		}
		if(b[i]==2){
			B[f[i]-1][r[i]-1]+=v[i];
		}
		if(b[i]==3){
			C[f[i]-1][r[i]-1]+=v[i];
		}
		if(b[i]==4){
			D[f[i]-1][r[i]-1]+=v[i];
		}
	}

	for(i=0;i<3;i++){
		for(ii=0;ii<10;ii++){
			printf(" %d",A[i][ii]);
		}
		printf("\n");
	}
	printf("####################\n");
	for(i=0;i<3;i++){
		for(ii=0;ii<10;ii++){
			printf(" %d",B[i][ii]);
		}
		printf("\n");
	}
	printf("####################\n");
	for(i=0;i<3;i++){
		for(ii=0;ii<10;ii++){
			printf(" %d",C[i][ii]);
		}
		printf("\n");
	}
	printf("####################\n");
	for(i=0;i<3;i++){
		for(ii=0;ii<10;ii++){
			printf(" %d",D[i][ii]);
		}
		printf("\n");
	}

	return 0;

}

Measured memory_bytes: 616
m, d = map(int, input().split())
ans = 0

for month in range(1, m+1):
	for day in range(1, d+1):
		if len(str(day)) >= 2:
			if int(str(day)[0]) >= 2 and int(str(day)[1]) >= 2 and int(str(day)[0]) * int(str(day)[1]) == month:
				ans += 1

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

int a,b,o,ab,n;
char x[5];

int main(){
    a=b=o=ab=0;
    while(scanf("%d,%s",&n,x)!=EOF){
        if(strcmp(x, "A")==0) a++;
        if(strcmp(x, "B")==0) b++;
        if(strcmp(x, "O")==0) o++;
        if(strcmp(x,"AB")==0)ab++;
    }
    printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
    
    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,sum=0;
    cin>>n;
    ll a[n],b[n],c[n-1];
    for(i=0;i<n;i++)
    {
    cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
        sum+=b[i];
    }
    for(i=0;i<(n-1);i++)
    {
        cin>>c[i];
    }
    for(i=1;i<n;i++)
    {
        if(a[i]-a[i-1]==1)
        {
            sum+=c[a[i]-2];
        }
    }
    cout<<sum;


     

  return 0;
    
}
    


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
 
int a[N*N];
int G[N][N];
int main() {
    int h,w,n;
    scanf("%d%d",&h,&w);
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
 
    int cnt=1;
    for(int i=1; i<=h; i++) {
        if(i%2) {
            for(int j=1; j<=w; j++) {
                if(a[cnt]==0) {
                    cnt++;
                    G[i][j]=cnt;
                    a[cnt]--;
                }
                else if(a[cnt]>0) {
                    G[i][j]=cnt;
                    a[cnt]--;
                }
            }
        }
        else {
            for(int j=w; j>=1; j--) {
                if(a[cnt]==0) {
                    cnt++;
                    G[i][j]=cnt;
                    a[cnt]--;
                }
                else if(a[cnt]>0) {
                    G[i][j]=cnt;
                    a[cnt]--;
                }
            }
        }
    }
 
    for(int i=1; i<=h; i++) {
        for(int j=1; j<=w; j++)
            printf("%d ",G[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    while(1)
    {
        int n,m;
        cin>>n>>m;if(!n)return 0;
        bool fl[1000][1000]={{false}};
        for(int i=0;i<m;++i){
            int a,b;
            cin>>a>>b;
            fl[a][b]=true;
            fl[b][a]=true;
        }
        bool df[1000]={false};
        for(int i=1;i<=n;++i){
            if(fl[1][i])df[i]=true;
        }
        bool f[1000]={false};
        for(int i=1;i<=n;++i){
            if(df[i]){
                for(int j=1;j<=n;++j){
                    if(fl[i][j]&&df[j]==false)f[j]=true;
                }
            }
        }
        int res=0;
        for(int i=2;i<=n;++i){
            if(df[i])res++;
            if(f[i])res++;
        }
        cout<<res<<endl;
    }
    return 0;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
int n, rt = 1, a[nsz + 5];
int pr[nsz + 5], dfn[nsz + 5], siz[nsz + 5];
vector<int> p[nsz + 5];

struct fenwick_tree {
	int t, tm[nsz + 5], tr[nsz + 5];
	
	void inline clear() { ++t; }
	
	void inline upd(int u, int w) {
		for (; u <= n; u += u & -u) {
			if (tm[u] != t)  tr[u] = w, tm[u] = t;
			else  tr[u] += w;
		}
	}
	
	int inline qry(int u) {
		int res = 0;
		for (; u > 0; res += (tm[u] == t) * tr[u], u -= u & -u);
		return res;
	}
	
	int inline qry(int l, int r) { return qry(r) - qry(l - 1); }
};
fenwick_tree tr;

struct graph {
	int sz, hd[nsz + 5];
	
	struct edge {
		int nxt, to;
		
		edge(int nxt = 0, int to = 0) {
			this->nxt = nxt, this->to = to;
		}
	} e[2 * nsz + 5];
	
	inline edge& operator [] (int id) { return e[id]; }
	
	void inline link(int u, int v) {
		e[++sz] = edge(hd[u], v), hd[u] = sz;
		e[++sz] = edge(hd[v], u), hd[v] = sz;
	}
};
graph g;

void dfs(int u = rt) {
	static int t = 0;
	dfn[u] = ++t;
	siz[u] = 1;
	for (int i = g.hd[u]; i; i = g[i].nxt) {
		int v = g[i].to;
		if (v == pr[u])  continue;
		pr[v] = u;
		dfs(v);
		siz[u] += siz[v];
	}
}

void bfs() {
	static int q[nsz + 5];
	int ql = 0, qr = 0;
	q[qr++] = rt;
	for (; ql != qr;) {
		int u = q[ql++];
		p[a[u]].push_back(u);
		for (int i = g.hd[u]; i; i = g[i].nxt) {
			int v = g[i].to;
			if (v == pr[u])  continue;
			q[qr++] = v;
		}
	}
}

int inline qry_subtree(int u) { return tr.qry(dfn[u], dfn[u] + siz[u] - 1); }

num inline solve(int c) {
	num res = (num) n * (n + 1) / 2;
	reverse(all(p[c]));
	loop (i, p[c].size()) {
		int u = p[c][i], s = siz[u];
		for (int i = g.hd[u]; i; i = g[i].nxt) {
			int v = g[i].to;
			if (v == pr[u])  continue;
			int k = qry_subtree(v), kk = siz[v] - k;
			res -= (num) kk * (kk + 1) / 2;
			s -= k;
		}
		tr.upd(dfn[u], s);
	}
	int k = siz[rt] - qry_subtree(rt);
	res -= (num) k * (k + 1) / 2;
	tr.clear();
	return res;
}

int main() {
	scanf("%d", &n);
	cont (i, n) {
		scanf("%d", &a[i]);
	}
	cont (i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		g.link(u, v);
	}
	dfs(), bfs();
	cont (c, n) {
		printf("%lld\n", solve(c));
	}
}

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

#define long long long

using namespace std;

const int N = 1e5+5;
const int M = 1e9+7;

long modpow(long a, long b) {
    long ret = 1;
    for( ; b; b >>= 1) {
        if(b & 1) ret = (ret * a) % M;
        a = (a * a) % M;
    }
    return ret;
}

int n, k;
int A[N], pos[N];
long fac[N], inv[N];

long ncr(int a, int b) {
    if(a < b || a < 0 || b < 0) return 0;
    return fac[a] * inv[b] % M * inv[a - b] % M;
}

int main() {
    fac[0] = inv[0] = 1;
    for(int i = 1; i < N; i++) {
        fac[i] = (fac[i-1] * i) % M;
        inv[i] = modpow(fac[i], M-2);
    }

    scanf("%d", &n);
    for(int i = 1; i <= n + 1; i++) {
        scanf("%d", A + i);
        if(!pos[A[i]]) pos[A[i]] = i;
        else k = pos[A[i]] + n - i;
    }
    for(int i = 1; i <= n + 1; i++) {
        if(i == 1) printf("%d\n", n);
        else {
            long now = ncr(n - 1, i); //Not include any dup
            now = (now + ncr(k, i - 1)) % M; //Include one dup but same
            now = (now + ncr(n - 1, i - 2)) % M; //Include both dup
            now = (now + (ncr(n - 1, i - 1) - ncr(k, i - 1) + M) % M) % M; //Include one dup but different
            now = (now + (ncr(n - 1, i - 1) - ncr(k, i - 1) + M) % M) % M; //Include one dup but different
            printf("%lld\n", now);
        }
    }

    return 0;
}

Measured memory_bytes: 3584
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c := nextInt(), nextInt(), nextInt()
	var count int
	for i := a; i <= b; i++ {
		if c%i == 0 {
			count++
		}
	}
	fmt.Println(count)
}

func nextInt() int {
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	return num
}



Measured memory_bytes: 1096
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define int long long  
signed main(){
    int A,B,C;
    int Ans;
    cin >> A >> B >> C;
    Ans=min((A%2)*B*C,A*(B%2)*C);
    Ans=min(Ans,A*B*(C%2));
    cout << Ans << endl;
    
    
	return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())

def check(n, k):
    if k == 1:
        return ((n + 1) // 2) % 2
    else:
        return max(0, (n + 1) % (k * 2) - k) % 2

k = 1
ans = 0

while k <= b:
    # print(k, check(b, k), check(a, k))
    ans += abs(check(b, k) - check(a-1, k)) % 2 * k
    k *= 2

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7;
using namespace std;
ll t;
ll arr[200005];
int main()
{
    ll a,b,c,d,e,f,i,j;
    cin>>a>>b;
    c=a/b;
    if(a%b)c++;
    cout<<c<<endl;
}



Measured memory_bytes: 256
class Problem
  attr_accessor :a, :b, :n, :m, :h, :w, :x, :y, :s ,:t

  def initialize
    @s = gets.chomp
    @t = gets.chomp
  end

  def solve
    @s = s.chars.sort.join
    @t = t.chars.sort.reverse.join
    s < t
  end

  def show(ans)
    puts ans ? "Yes" : "No"
  end
end

Problem.new.instance_eval do
  show(solve)
end


Measured memory_bytes: 14224
#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 int N = 1000006;

int n;
string a[N];

int z;
int t[N][26];
bool c[N];

bool p[N][26];

void solv()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; ++i)
    {
        int m = a[i].size();
        int pos = 0;
        for (int j = m - 1; j >= 0; --j)
        {
            if (!t[pos][a[i][j] - 'a'])
                t[pos][a[i][j] - 'a'] = ++z;
            pos = t[pos][a[i][j] - 'a'];
        }
        c[pos] = true;
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        int m = a[i].size();
        for (int j = 0; j < m; ++j)
        {
            if (!j)
            {
                for (int k = 0; k < 26; ++k)
                    p[j][k] = false;
            }
            else
            {
                for (int k = 0; k < 26; ++k)
                    p[j][k] = p[j - 1][k];
            }
            p[j][a[i][j] - 'a'] = true;
        }
        int pos = 0;
        for (int j = m - 1; j >= 0; --j)
        {
            for (int k = 0; k < 26; ++k)
            {
                if (k == a[i][j] - 'a')
                    continue;
                if (t[pos][k])
                {
                    if (c[t[pos][k]])
                    {
                        if (j && p[j - 1][k])
                            ++ans;
                    }
                }
            }
            pos = t[pos][a[i][j] - 'a'];
            if (c[pos])
                ++ans;
        }
    }
    ans -= n;
    printf("%d\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

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


Measured memory_bytes: 160680
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;
#define mod 1e+9
int main(){
    lli n,k;
    cin>>n>>k;
    lli count = 0;
    for(lli i = k; i<=n+1; i++){
        lli mini = (i*(i-1))/2;
        lli maxi = n*i;
        count += maxi - 2*mini + 1;
    }
    cout<<count % (int)(mod+7);
    
    return 0;
}


Measured memory_bytes: 3580
#include <stdio.h>
int main(void){
	int a,b,n,ans;
	scanf("%d",&n);
	if(n==1){
		printf("Hello World\n");
		return 0;
	}else{
		scanf("%d %d",&a,&b);
		ans=a+b;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
# define PI  3.14159265358979323846
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
int main() 
{
	
 	 ll h,w;
 	 cin>>h>>w;
 	 ll dp[h+1][w+1];
 	 char a[h+1][w+1];
 	 memset(dp,0,sizeof dp);
 	 for (int i = 1; i <= h; ++i)
 	  {
 	  	for (int j = 1; j <= w; ++j)
 	  	{
 	  		cin>>a[i][j];
 	  	}
 	  }		
 	 for (int i = 0; i <= h; ++i)
 	  {
 	  	for (int j = 0; j <= w; ++j)
 	  	{
 	  		if (i==0||j==0)
 	  		{
 	  			dp[i][j]=0;
 	  		}
 	  		else if(i==1&&j==1)
 	  		{
 	  			dp[i][j]=1;
 	  		}
 	  		else if(a[i][j]=='#')
 	  		{
 	  			dp[i][j]=0;
 	  		}
 	  		else if(a[i][j]=='.')
 	  		{
 	  			dp[i][j]=((dp[i][j-1]%MOD)+(dp[i-1][j]%MOD))%MOD;
 	  		}
 	  	}
 	  } 
 	  // for (int i = 0; i <= h; ++i)
 	  // {
 	  // 	for (int j = 0; j <= w; ++j)
 	  // 	{
 	  // 		cout<<dp[i][j]<<" ";
 	  // 	}
 	  // 	cout<<endl;
 	  // }	
 	   ll ans;
 	   ans=dp[h][w];
 	   //ans%=MOD;
 	   cout<<ans;
 	return 0;
 }

Measured memory_bytes: 9088
#include <stdio.h>

int main(void) {
	char str[20];
	
	scanf("%s", str);
	
	int i,end;
	for(i=0;i<=20;i++){
		if(str[i] == '\0'){
			end = i;
			break;
		}
	}
	
	for(i=end-1; i>=0; i--)
		printf("%c", str[i]);
	printf("\n");
	
	return 0;
	
}

Measured memory_bytes: 524
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
int32_t main() 
{
    fio
	ll j,i,n,t,l,w,r,h,k,m,maxi,d,x;
	cin>>n>>w;
	ll a[n],v[n];
	fo(i,n){
		cin>>a[i]>>v[i];
	}
	ll dp[n+1][w+1];
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=w;j++)
		{
			if(i==0||j==0)
				dp[i][j]=0;
			else if(a[i-1]<=j)
				dp[i][j]=max(v[i-1]+dp[i-1][j-a[i-1]],dp[i-1][j]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][w];
	
	
}



	

		

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

using namespace std;

int main() {
  int x,y,z;
  cin >> x >> y >> z;
  int ans = 0;
  int id  = 0;
  if(x >= y + 2 * z) {
    ans++;
    id = y + 2 * z;
  }
  while(1) {
    if(id + y + z > x) break;
    id += y + z;
    ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector

int main(void)
{
	int n;
	cin >> n;
	vec<int> p(n);
	rep(i, n) {
		int get;
		cin >> get;
		p[get - 1] = i;
	}

	vec<int> a(n), b(n);

	vec<int> c(n - 1);
	rep(i, n - 1) c[i] = max(1, p[i + 1] - p[i] + 1);
	a[0] = 1;
	rep(i, n - 1) a[i + 1] = a[i] + c[i];
	b[n - 1] = 1;
	rep(i, n - 1) {
		b[n - 2 - i] = b[n - 1] + a[n - 1] - a[n - 2 - i] + p[n - 2 - i] - p[n - 1];
	}
	rep(i, n - 1) cout << a[i] << " ";
	cout << a[n - 1] << endl;
	rep(i, n - 1) cout << b[i] << " ";
	cout << b[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

int main(){
    ll n;scanf("%lld",&n);
    ll ans=1e18;
    for(int i=1;i<=sqrt(n);i++){
        if(n%i==0){
            ll x=n/i;
            ans=ans>i+x?i+x:ans;
        }
    }

    printf("%lld\n",ans-2);
}

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

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

    int n;
    cin >> n;
    vector<int> ws(n + 1);
    for (int i = 1; i <= n; i++) cin >> ws[i];
    int ans = 1e9;
    for (int t = 1; t < n; t++) {
        int li = 0, he = 0;
        for (int j = 1; j <= n; j++) {
            if (j <= t) {
                li += ws[j];
            } else {
                he += ws[j];
            }
        }
        ans = min(ans, abs(li - he));
    }
    cout << ans << endl;
}

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

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

    int a,b;
    // 引数の受け取り
    //
    cin >> a >> b;

   if(a!=2&&b!=2){
       if(a==4||a==6||a==9||a==11){
        if(b==4||b==6||b==9||b==11){
            cout << "Yes" << endl;
    return 0;
        }
       }else{
        if(b==4||b==6||b==9||b==11){}else{
            cout << "Yes" << endl;
    return 0;
        }
       
       }
   }
            cout << "No" << endl;
    // 出力
    return 0;
}



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

using namespace std;

bool ok(string &expr, int &idx){
	int val[256];
	memset(val, -1, sizeof(val));
	int v = 0;
	bool res = true;
	while(expr[idx]!=')'){
		if(expr[idx]=='&'){ idx++; continue; }
		if(expr[idx]=='~') v = 0, idx++;
		else               v = 1;
		if(val[expr[idx]] != -1 && val[expr[idx]] != v) res = false;
		val[expr[idx]] = v;
		idx++;
	}
	idx++;
	return res;
}

int main(){
	string expr;
	while(cin >> expr){
		if(expr == "#") break;
		bool flg = false;
		for(int i=0;i<expr.size();i++){
			flg |= ok(expr, i);
		}
		cout << (flg ? "yes" : "no") << endl;
	}
	return 0;
}

Measured memory_bytes: 0
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void){
    ll n;scanf("%lld",&n);
    vector<ll> a(n);
    for(int i = 0;i < n;i++)scanf("%lld",&a[i]);

    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    int i = 0;
    int L = 0,R = 0;
    while(i < n){
        if(a[i] == a[i+1]){
            if(!L)L = a[i];
            else if(!R)R = a[i];

            i += 2;
        }else i++;
    }
    cout << (ll)L*(ll)R << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#define SIZE 100005
using namespace std;

struct Queue
{
  int list[SIZE];
  int head,tail;
  void init(){ head=tail=0; }
  bool isEmpty(){ return head==tail; }
  bool isFull(){ return head==(tail+1)%SIZE; }
  void enqueue(int x)
  {
    if(isFull()){
      cout << "ERROR(Over flow)" << endl;
      //exit(1);
    }
    list[tail] = x;
    tail++;
    tail %= SIZE;
  }
  int dequeue()
  {
    if(isEmpty()){
      cout << "ERROR(Under flow)" << endl;
      //exit(1);
    }
    int x = list[head];
    head++;
    head%=SIZE;
    return x;
  }
  int top()
  {
    return list[head];
  }
};
struct Node
{
  int parent,depth;
  string type;
  vector<int> childs;

  void init(){
    parent=-1;
  }
};

Queue q;

void print(vector<Node>& nodes)
{
  int i,j;
  for(i=0;i<nodes.size();i++){
    cout<<"node "<<i<<": parent = "<<nodes[i].parent<<", depth = "<<nodes[i].depth<<", "<<nodes[i].type<<", [";
    if(nodes[i].childs.size()>0){
      for(j=0;j<nodes[i].childs.size()-1;j++){
	cout<<nodes[i].childs[j]<<", ";
      }
      cout<<nodes[i].childs[ nodes[i].childs.size()-1 ];
    }
    cout<<"]"<<endl;
  }
}
void bfs(vector<Node>& nodes)
{
  int i,now=q.dequeue();
   nodes[now].depth=(nodes[now].parent>=0 ? nodes[ nodes[now].parent ].depth+1 : 0);
  if(nodes[now].parent<0) nodes[now].type="root";
  else if(nodes[now].childs.size()>0) nodes[now].type="internal node";
  else nodes[now].type="leaf";
  for(i=0;i<nodes[now].childs.size();i++){
    nodes[ nodes[now].childs[i] ].depth=nodes[now].depth+1;
    q.enqueue(nodes[now].childs[i]);
  }
  if(!q.isEmpty()) bfs(nodes);
}
int main()
{
  int i,j,n,m,cld,num;
  vector<Node> nodes;
  cin>>n; nodes.resize(n);
  for(i=0;i<n;i++) nodes[i].init();
  for(i=0;i<n;i++){
    cin>>num>>m;
    nodes[num].childs.resize(m);
    for(j=0;j<m;j++){
      cin>>cld; nodes[num].childs[j]=cld; nodes[cld].parent=num;
    }
  }
  for(i=0;i<n;i++) if(nodes[i].parent==-1) num=i;
  q.init(); q.enqueue(num);
  bfs(nodes);
  print(nodes);
  return 0;
}


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

int main(){
    int a[8];
    char c[8];
    int n;
    cin >> n;
    for(int i=0; i<n; ++i){
        while(scanf("%s", c) != EOF){
            for(int j=0; j<8; ++j) a[j] = c[j] - '0';
            for(int j=1; j<8; ++j){
                int tmp = a[j];
                if(a[j-1] > tmp){
                    int k = j;
                    do{
                        a[k] = a[k-1];
                        --k;
                    }while(k > 0 && a[k-1] > tmp);
                    a[k] = tmp;
                }
            }
            int max = 0;
            int min = 0;
            for(int d=10000000, j=0; d>=1; d/=10,++j){
                min += d*a[j];
                max += d*a[7-j];
            }
            cout << max-min << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
   string s;
   int nc[26]={};
     
   while(getline(cin,s)){
       for(int i=0;i<(int)s.length();i++){
           if('a'<=s[i]&&s[i]<='z') nc[s[i]-'a']++;
           if('A'<=s[i]&&s[i]<='Z') nc[s[i]-'A']++;
       }
   }
   for(int i=0; i<26 ;i++){
       cout<<(char)('a'+i)<<" : "<<nc[i]<<endl;
   }
     
}


Measured memory_bytes: 3188
ABC = list(map(int, input().split()))

odd_num = []
for i in range(len(ABC)):
    if ABC[i] % 2 != 0:
        odd_num.append(i)
        
if len(odd_num) == 0 or len(odd_num) == 3:
    count = 0
elif len(odd_num) == 1:
    for i in range(len(ABC)):
        if i not in odd_num:
            ABC[i] += 1
    count = 1
elif len(odd_num) == 2:
    for i in range(len(ABC)):
        if i in odd_num:
            ABC[i] += 1
    count = 1
    
max_ABC = max(ABC)
for i in range(len(ABC)):
    if ABC[i] != max_ABC:
        count += (max_ABC - ABC[i]) // 2

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Jul  5 21:31:45 JST 2020
 **/

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n), b;
    REP(i, n) std::cin >> a[i];
    std::sort(a.rbegin(), a.rend());
    REP(i, n) {
        b.push_back(a[i]);
        if (i) b.push_back(a[i]);
    }
    std::cout << std::accumulate(b.begin(), b.begin() + n - 1, 0LL) << std::endl;
}


Measured memory_bytes: 8984
c=[list(map(int,input().split())) for _ in range(3)]
for a0 in range(-100,201):
    for a1 in range(-100,201):
        for a2 in range(-100,201):
            if c[0][0]-a0==c[1][0]-a1==c[2][0]-a2:
                if c[0][1]-a0==c[1][1]-a1==c[2][1]-a2:
                    if c[0][2]-a0==c[1][2]-a1==c[2][2]-a2:
                        print("Yes")
                        exit()
print("No")

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

using namespace std;

typedef long long ll;
typedef long double ld;

int arr[3005];
ll dp[3005][3005][2];

ll solve(int i, int j, int turn)
{
    if(i > j)
      return 0;
    ll &ans = dp[i][j][turn];
    if(~ans)
      return ans;
    if(!turn)
      return ans = max(arr[i] + solve(i + 1, j, 1), arr[j] + solve(i, j - 1, 1));
    else
      return ans = min(solve(i + 1, j, 0) - arr[i], solve(i, j - 1, 0) - arr[j]);
}

int main()
{
  int n;
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> arr[i];
  memset(dp, -1, sizeof dp);
  cout << solve(0, n - 1, 0);
  return 0;
}


Measured memory_bytes: 141568
# 解説AC
N,K = map(int, input().split())

cnt = 0
for b in range(1, N+1):
    p,r = divmod(N, b)
    cnt += p * max(0, b - K)
    cnt += max(0, r - K + 1)

# a = 0のとき
if K == 0:
    cnt -= N

print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using State = string::const_iterator;
class ParseError{};

long long expr(State& begin,const long long& a,const long long& b,const long long& c);
long long term(State& begin,const long long& a,const long long& b,const long long& c);
long long term2(State& begin,const long long& a,const long long& b,const long long& c);
long long fact(State& begin,const long long& a,const long long& b,const long long& c);
long long number(State& begin,const long long& a,const long long& b,const long long& c);

long long expr(State& begin,const long long& a,const long long& b,const long long& c){
    long long res = term(begin,a,b,c);
    while(true){
        if(*begin == '+' && a == 1){
            begin++;
            res += term(begin,a,b,c);
        }else if(*begin == '-' && b == 1){
            begin++;
            res -= term(begin,a,b,c);
        }else if(*begin == '*' && c == 1){
            begin++;
            res *= term(begin,a,b,c);
        }else{
            break;
        }
    }
    return res;
}

long long term(State& begin,const long long& a,const long long& b,const long long& c){
    long long res = term2(begin,a,b,c);
    while(true){
        if(*begin == '+' && a == 2){
            begin++;
            res += term2(begin,a,b,c);
        }else if(*begin == '-' && b == 2){
            begin++;
            res -= term2(begin,a,b,c);
        }else if(*begin == '*' && c == 2){
            begin++;
            res *= term2(begin,a,b,c);
        }else{
            break;
        }
    }
    return res;
}

long long term2(State& begin,const long long& a,const long long& b,const long long& c){
    long long res = fact(begin,a,b,c);
    while(true){
        if(*begin == '+' && a == 3){
            begin++;
            res += fact(begin,a,b,c);
        }else if(*begin == '-' && b == 3){
            begin++;
            res -= fact(begin,a,b,c);
        }else if(*begin == '*' && c == 3){
            begin++;
            res *= fact(begin,a,b,c);
        }else{
            break;
        }
    }
    return res;
}

long long fact(State& begin,const long long& a,const long long& b,const long long& c){
    if(*begin == '('){
        begin++;
        long long res = expr(begin,a,b,c);
        begin++;
        return res;
    }
    return number(begin,a,b,c);
}

long long number(State& begin,const long long& a,const long long& b,const long long& c){
    long long res = 0;
    while(isdigit(*begin)){
        res *= 10;
        res += *begin - '0';
        begin++;
    }
    return res;
}

int main(){
    string S;
    cin >> S;
    State begin = S.begin();
    long long ans = expr(begin,1,1,1);
    long long v[] = {1,2,3};
    for(auto a:v)for(auto b:v)for(auto c:v){
        begin = S.begin();
        ans = max(ans,expr(begin,a,b,c));
    }
    cout << ans << endl;
}


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

int gcd(ll a,ll b){
  ll x = max(a,b);
  ll y = min(a,b);

  ll r;
  do{
    r = x % y;
    x = y;
    y = r;
  }while(r!= 0);

  return x;
}

int main()
{
  ll A,B,C,D;
  cin >> A >> B >> C >> D;

  ll ans=0;
  ll g = C*D/gcd(C,D);
  ll x = (A-1) / g;
  ll s = (A-1) / C;
  ll t = (A-1) / D;
  ll y = B /g;
  ll u = B /C;
  ll v = B /D;
  ans = B-(A-1) -(u-s) - (v-t)+(y-x);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "stdio.h"
#include "string.h"
int main()
{
	char a[1000],b[1000];
	while(gets(a)&&gets(b))
	{
		int i;
		char str[1000];
		int q=0;
		for(i=0;i<strlen(a);i++)
		{
			str[q++]=a[i];
			str[q]='\0';
			if(b[i]!='\0')
			{
				str[q++]=b[i];
				str[q]='\0';
			}
		}
		puts(str);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,i,j;
  cin>>n;
  if(n%2) k=n;
  else k=n+1;
  
  vector<pair<int,int>> pi;
  for(i=1;i<n;i++)
  {
    for(j=i+1;j<=n;j++)
    {
      if(i+j != k) pi.push_back({i,j});
    }
  }
  cout<<pi.size()<<endl;
  for(auto u:pi)
  {
    cout<<u.first<<" "<<u.second<<endl; 
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int N;
    cin >> N;
    map<string,int> mp;
    mp["AC"] = 0;
    mp["WA"] = 0;
    mp["TLE"] = 0;
    mp["RE"] = 0;
    REP(i,N) {
        string s;
        cin >> s;
        mp[s]++;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}

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

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int mod = 1000000007;

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

int main() {
        int n;
        vector<Pi> vec;
        cin >> n;
        for (int i = 0; i < n; i++) {
                int a;
                cin >> a;
                vec.emplace_back(a, 0);
        }
        for (int i = 0; i < n; i++) {
                int b;
                cin >> b;
                vec.emplace_back(b, 1);
        }
        
        sort(begin(vec), end(vec));
        int ans = 1;
        int acnt = 0, bcnt = 0;
        for (int i = 0; i < 2 * n; i++) {
                if (vec[i].second == 0) {
                        if (bcnt > 0) ans = ((ll)ans * bcnt--) % mod;
                        else acnt++;
                } else {
                        if (acnt > 0) ans = ((ll)ans * acnt--) % mod;
                        else bcnt++;
                }
        }

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

Measured memory_bytes: 2420
#include<stdio.h>
int main(void){
  char string[1800];
  int i=0;
  scanf("%[^\r\n]",string);
  while(string[i]!='\0'){
    if(string[i]>=65&&string[i]<=90)
      string[i++]+=32;
    else if(string[i]>=97&&string[i]<=122)
      string[i++]-=32;
    else
      i++;
  }
  printf("%s\n",string);
  return 0;
}

Measured memory_bytes: 524
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> al = new ArrayList<Integer>();
        for (int i = 0; i < 3; i++) {
            int a = sc.nextInt();
            al.add(a);
        }
        Collections.sort(al);
        for (int i = 0; i < 3; i++) {
            System.out.print(al.get(i));
            if (i==2) System.out.println();
            else System.out.print(" ");
        }
    }
}


Measured memory_bytes: 26392
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int HourA = sc.nextInt();
        int MinuteA = sc.nextInt();
        int HourB = sc.nextInt();
    	int MinuteB = sc.nextInt();
		int K   = sc.nextInt();
		int minute = 0;
		
		minute += MinuteB;
		
		if(MinuteA < 60){
		    minute += 60 - MinuteA;
		    HourA++;
		}
		
		minute += (HourB-HourA) * 60;
		

        System.out.println(minute-K);
    }
}

Measured memory_bytes: 35768
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

const int INF = 1 << 30;

int solve(int n, vector<int> x, vector<int> y, vector<string> dir) {
	int ans = INF;
	map<int, set<int>> d, v;
	for (int i = 0; i < n; ++i) {
		if (dir[i] == "R") {
			d[x[i] + y[i]].insert(y[i]);
		}
		if (dir[i] == "D") {
			v[x[i]].insert(y[i]);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (dir[i] == "U") {
			int key = x[i] + y[i];
			if (d.find(key) != d.end()) {
				set<int>& s = d[key];
				auto it = s.lower_bound(y[i]);
				if (it != s.end()) {
					ans = min(ans, (*it - y[i]) * 10);
				}
			}
			if (v.find(x[i]) != v.end()) {
				set<int>& s = v[x[i]];
				auto it = s.lower_bound(y[i]);
				if (it != s.end()) {
					ans = min(ans, (*it - y[i]) * 5);
				}
			}
		}
	}
	return ans;
}

void rotate(int n, vector<int> &x, vector<int> &y, vector<string> &dir) {
	map<string, string> t;
	t["D"] = "R", t["U"] = "L", t["L"] = "D", t["R"] = "U";
	for (int i = 0; i < n; ++i) {
		int nx = -y[i];
		y[i] = x[i], x[i] = nx;
		dir[i] = t[dir[i]];
	}
}

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int ans = INF;
		int n = -1;
		cin >> n;
		if (n < 0) return 0;
		vector<int> x(n), y(n);
		vector<string> dir(n);
		for (int i = 0; i < n; ++i) {
			cin >> x[i] >> y[i] >> dir[i];
		}
		for (int i = 0; i < 4; ++i) {
			ans = min(ans, solve(n, x, y, dir));
			rotate(n, x, y, dir);
		}
		if (ans == INF) {
			cout << "SAFE" << endl;
		} else {
			cout << ans << endl;
		}
	}
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    string w;
    cin >> w;

    map<char, ll> mp;

    for(ll i = 0; i < w.length(); i++){
        mp[w[i]]++;
    }

    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        if(iter->second % 2 == 1){
            cout << "No" << endl;
            return 0;
        }
    }    

    cout << "Yes" << endl;

}

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

const int INF = 1e9 + 9;

int dx1[] = {-1, 0, 1};
int dy1[] = {-1, 0, 1};
int dx2[] = {-2, -1, 0, 1, 2};
int dy2[] = {-2, -1, 0, 1, 2};

using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  
  int Ch, Cw, Dh, Dw;
  cin >> Ch >> Cw >> Dh >> Dw;
  --Ch; --Cw; --Dh; --Dw;
  
  vector<string> S(H);
  for(int i = 0; i < H; i++) cin >> S[i];
  
  deque<pair<int, pair<int, int>>> dq;
  dq.push_front({0, {Ch, Cw}});
  
  vector<vector<int>> dist(H, vector<int>(W, INF));
  dist[Ch][Cw] = 0;
  while(dq.size()){
    int cost = dq.front().first;
    int node_h = dq.front().second.first;
    int node_w = dq.front().second.second;
    dq.pop_front();
    
    if(dist[node_h][node_w] < cost) continue;
    
    for(int x : dx1){
      for(int y : dy1){
        if(x == 0 && y == 0) continue;
        if(x != 0 && y != 0) continue;
        
        if(0 <= node_h + y && node_h + y < H && 0 <= node_w + x && node_w + x < W && S[node_h + y][node_w + x] == '.'){
          if(dist[node_h + y][node_w + x] <= cost) continue;
          
          dist[node_h + y][node_w + x] = cost;
          dq.push_front({cost, {node_h + y, node_w + x}});
        }
      }
    }
    
    for(int x : dx2){
      for(int y : dy2){
        if(x == 0 && y == 0) continue;
        if(0 <= node_h + y && node_h + y < H && 0 <= node_w + x && node_w + x < W && S[node_h + y][node_w + x] == '.'){
          if(dist[node_h + y][node_w + x] <= cost + 1) continue;
          
          dist[node_h + y][node_w + x] = cost + 1;
          dq.push_back({cost + 1, {node_h + y, node_w + x}});
        }
      }
    }
  }
  
  if(dist[Dh][Dw] < INF) cout << dist[Dh][Dw] << endl;
  else cout << -1 << endl;
  
  return 0;
}

Measured memory_bytes: 9488
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6;
int d()
{
    int ret;
    scanf("%d", &ret);
    return ret;
}
long long lld()
{
    long long ret;
    scanf("%lld", &ret);
    return ret;
}
bool cmp(pair<int, int> s, pair<int, int> f)
{
    if (f.first > s.first)
        return true;
    else if (f.first == f.second && f.second < s.second)
        return true;
    else
        return false;
}
/*
long long arr[N],n;
bool IsCover(long long d){
    long long lastcover=-1,used=0;
    for(int i=0;i<n;i++){
        if(arr[i]>lastcover){
        lastcover=arr[i]+(2*d);
        used++;
        }

    }
    return used<=3;
}
long long PS(){
    long long hi=1e5,lo=0,mid;
    while(hi-lo > 0){
        mid=(lo+hi)/2;
        if(IsCover(mid))hi=mid;
        else lo=mid+1;
    }
    return lo;
}
*/
char arr[N];
int main(){
     int a=d(),b=d();
     scanf("%s",arr);
     int n=strlen(arr);
     int cnt=0;
     for(int i=0;i<n;i++){
        if(i==a){

            if(arr[i]=='-')
            continue;
            else{
            printf("No\n");
            return 0;
            }
        }
        else{
            if(arr[i]>='0' && arr[i]<='9'){

            }
            else{
                printf("No\n");
                return 0;
            }
        }
     }

     printf("Yes\n");


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.begin(), c.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
#define Sort(a) sort(Range(a));
#define DeSort(a) sort(RevRange(a));

using namespace std;
using ll = long long;

int main(void){
    Cin(string, a);
    Cin(int, b);
    Cin(int, c);
    Cin(int, d);
    //Cout();
    //Cout(() ? "Yes" : "No");
    Cout((a == "a" || a == "i" || a == "u" || a == "e" || a == "o") ? "vowel" : "consonant");
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int a;

  scanf("%d", &a);
  if (a == 25)
    puts("Christmas");
  if (a == 24)
    puts("Christmas Eve");
  if (a == 23)
    puts("Christmas Eve Eve");
  if (a == 22)
    puts("Christmas Eve Eve Eve");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
constexpr int inf = 1001001001;
#define chmin(x, y) x = min(x, y)
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    string s;
    cin >> n >> s;
    vector<int> S1(n + 1, 0), S2(n + 1, 0);
    for(int i = 0; i < n; ++i){
        if(s[i] == 'W'){
            S1[i + 1] += S1[i] + 1;
            S2[i + 1] += S2[i];
        }
        else{
            S1[i + 1] += S1[i];
            S2[i + 1] += S2[i] + 1;
        }
    }
    // for(int i = 0; i <= n; ++i) cerr << S1[i] << " ";
    // cerr << endl;
    // for(int i = 0; i <= n; ++i) cerr << S2[i] << " ";
    // cerr << endl;
    int ans = inf;
    for(int i = 0; i < n; ++i){
        int foo = S1[i] + S2[n] - S2[i + 1];
        // cerr << S1[i] << " " << S2[n] - S2[i + 1] << endl;
        chmin(ans, foo);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2964
import fractions
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass #sortされていない
a,b,k = map(int,input().split())
gcd = fractions.gcd(a,b)
yaku = list(reversed(sorted(list(set(divisor(gcd))))))
print(yaku[k-1])

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,X,T,a;
  cin >> N >> X >> T;
  if(N % X != 0){
    a = N / X + 1;
  }
  else{
    a = N / X;
  }
  cout << a * T << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;

int main() {
  int N;
  cin >> N;
  vector<int> V(N,0);
  int A;
  for (int i=1; i<N; i++) {
    cin >> A;
    V[A-1]++;
  }
  for (int i=0; i<N; i++) {
    cout << V[i] << endl;
  }
}

Measured memory_bytes: 4048
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define LL long long 
#define LD long double
int n,ans,a[30005][10];
string s;
int main()
{
	cin>>n>>s;
	for(int j=0;j<10;j++)
		a[n+1][j]=a[n][j]=n+1;
	for(int i=n-1;i>=0;i--)
	{
		for(int j=0;j<10;j++)
			a[i][j]=a[i+1][j];
		a[i][s[i]-'0']=i+1;
	}			
	/*for(int i=0;i<=n;i++)
	{
		for(int j=0;j<10;j++)
			cout<<a[i][j]<<" ";
		cout<<endl;
	}*/
	for(int i=0;i<10;i++)
		for(int j=0;j<10;j++)
			for(int k=0;k<10;k++)
			{
				int now=0;
				now=a[now][i];
				//cout<<now<<" ";
				now=a[now][j];
				//cout<<now<<" ";
				now=a[now][k];
				//cout<<now<<endl;
				if(now<=n)ans++;
			}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1536
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string s = Console.ReadLine();
    int n = s.Length;
    long mod = 1000000007;
    long[,] dp = new long[n+1,13];//a桁見て13で割った余りはbの方法の個数
    dp[0,0] = 1;
    long multiple = 1;

    for(int i = 1; i <= n; i++)
    {
      for(int j = 0; j < 13; j++)
      {
        long x = (long)(s[n-i]-'0');
        if(x >= 0 && x <= 9)
        {
          x *= multiple;
          x %= 13;
          dp[i,j] += dp[i-1,(j+13-x)%13];
          dp[i,j] %= mod;
        }else//?の時
        {
          for(long k = 0; k <= 9; k++)
          {
            long kk = k;
            kk *= multiple;
            kk %= 13;
            dp[i,j] += dp[i-1,(j+13-kk)%13];
            dp[i,j] %= mod;
            //Console.WriteLine(i+" "+j+" "+k+" "+dp[i,j]);
          }
        }
        //Console.WriteLine(i+" "+j+" "+dp[i,j]);
      }
      multiple *= 10;
      multiple %= 13;
    }
    

		Console.WriteLine(dp[n,5]);
	}
}

Measured memory_bytes: 21472
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j==n){
        cout <<"Yes\n";
        return 0;
      }
    }
  }
  cout <<"No\n";
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

signed main() {
    int a;
    string s;
    cin >> a >> s;
    if (a < 3200)cout << "red" << endl;
    else cout << s << endl;
}


Measured memory_bytes: 256
from math import floor
N = int(input())
a = list(map(int,input().split()))
a.append(0)
s = 0
S = 0
ans = 0
for i in range(N+1):
    if a[i] != s:
        s = a[i]
        ans += floor((S+1)/2)
        S = 0
    else:
        S += 1
print(ans)

Measured memory_bytes: 3060
i,j,k;long s[444],p[444][444],S,P;main(a){for(scanf("%*d");~scanf("%d",&a);i=j)for(s[++j]=S+=a;k=i--;p[i][j]=P)for(P=9e18;k<j;)P=fmin(P,p[i][k]+p[k++][j]+S-s[i]);printf("%ld",P);}

Measured memory_bytes: 1536