akhauriyash/Code-Regression huggingface dataset:
from collections import deque

class MaxFlow:
    class Edge:
        def __init__(self,to,cap,rev):
            self.to = to
            self.cap = cap
            self.rev = rev

    def __init__(self,n,inf = 10**9+7):
        self.n = n
        self.inf = inf
        self.level = [-1]*n
        self.iter = [0]*n
        self.e = [[] for _ in range(n)]

    def add_edge(self, from_, to, cap):
        self.e[from_].append(self.Edge(to, cap, len(self.e[to])))
        self.e[to].append(self.Edge(from_, 0, len(self.e[from_])-1))

    def bfs(self, start):
        self.level = [-1]*self.n
        dq = deque()
        self.level[start] = 0
        dq.append(start)
        while dq:
            cur_vertex = dq.popleft()
            for edge in self.e[cur_vertex]:
                if edge.cap > 0 > self.level[edge.to]:
                    self.level[edge.to] = self.level[cur_vertex] + 1
                    dq.append(edge.to)

    def dfs(self, cur_vertex, end_vertex, flow):
        if cur_vertex == end_vertex:return flow
        while self.iter[cur_vertex] < len(self.e[cur_vertex]):
            edge = self.e[cur_vertex][self.iter[cur_vertex]]
            if edge.cap > 0 and self.level[cur_vertex] < self.level[edge.to]:
                flowed = self.dfs(edge.to, end_vertex, min(flow, edge.cap))
                if flowed > 0:
                    edge.cap -= flowed
                    self.e[edge.to][edge.rev].cap += flowed
                    return flowed
            self.iter[cur_vertex] += 1
        return 0

    def compute(self, source, sink):
        flow = 0
        while True:
            self.bfs(source)
            if self.level[sink] < 0:return flow
            self.iter = [0]*self.n
            while True:
                f = self.dfs(source, sink, self.inf)
                if f == 0:break
                flow += f

def main():
    x,y,e = map(int,input().split())
    mf = MaxFlow(x+y+2)
    s = x+y
    t = s+1
    for _ in range(e):
        a,b = map(int,input().split())
        mf.add_edge(a,b+x,1)
    for i in range(x):
        mf.add_edge(s,i,1)
    for i in range(y):
        mf.add_edge(i+x,t,1)
    print (mf.compute(s,t))


if __name__ == '__main__':
    main()




Measured memory_bytes: 9492
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		int ans[] = new int[10];
		ans[0] = r*x-d;

		for(int i= 1; i<10; i++) {
			ans[i] = r*ans[i-1]-d;
		}

		for(int j=0; j<ans.length; j++) {
			System.out.println(ans[j]);
		}
	}

}


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

int main()
{
	int h,n;
	cin >> h >> n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
	for(int i=0;i<n;i++)
		h -= arr[i];
	if(h<=0)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
int main(){
  string s; cin >> s;
  ll ans = 753;
  rep(i,s.size()-2){
    ll p = 100*(s[i]-'0') +10*(s[i+1]-'0') +(s[i+2]-'0');
    ans = min(ans, abs(753-p));
  }
  cout << ans;
  return 0;
}


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

using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<vector<int> > a(n+1);
    for(int i = 1; i <= n; i++){
        int id, size;
        cin >> id >> size;
        a[i].resize(size);
        for(int j = 0; j < size; j++){
            int temp;
            cin >> temp;
            a[i][j] = temp;
        }
    }
    vector<int> d(n+1);
    vector<bool> ok(n+1);
    queue<int> s;
    s.push(1);
    ok[1] = true;
    while(!s.empty()){
        int now = s.front();
        s.pop();
        for(int i = 0; i < a[now].size(); i++){
            int next = a[now][i];
            if(!ok[next]){
                d[next] = d[now] + 1;
                s.push(next);
                ok[next] = true;
            }
        }
    }
    for(int i = 2; i <= n; i++){
        if(d[i] == 0)d[i] = -1;
    }
    for(int i = 1; i <= n; i++){
        cout << i << " " << d[i] << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;


int main() {
  int h[10];

  for (int i = 0; i < 10; i++) {
    cin >> h[i];
  }

  sort(h, h+10);

  for (int i = 9; i > 9-3; i--) {
    std::cout << h[i] << std::endl;
  }

}

Measured memory_bytes: 3164
def main():
    N = int(input()) - 1
    digits = []

    while True:
        a, b = N // 26, N % 26
        digits.append(b)
        if a == 0:
            break
        N = a - 1

    digits.reverse()
    chars = map(to_alphabet, digits)
    print(''.join(chars))


def to_alphabet(x: int):
    return chr(65 + x).lower()


if __name__ == "__main__":
    main()


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

int main() {
    int X;
    cin >> X;
    int j = 8;
    for (int i = 600; i <= 2000; i = i + 200) {
        if (X < i) {
            cout << j << endl;
            return 0;
        }
        j--;
    }
}

Measured memory_bytes: 3632
object Main extends App {
  @scala.annotation.tailrec
  def loop(i: Int, ints: Seq[Int]): String = ints match {
    case Seq() => "Yes"
    case x :: xs if x - 1 == i => loop(x - 1, xs)
    case x :: xs if x <= i => loop(x, xs)
    case _ => "No"
  }

  val sc = new java.util.Scanner(System.in)
  val i :: ints = Seq.fill(sc.nextInt())(sc.nextInt()).reverse
  println(loop(i, ints))
}


Measured memory_bytes: 54652
// ABC158C - Tax Increase

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

int main() {
	int A, B;
	cin >> A >> B;

	int i;
	for (i = 1; i <= 1100; i++) {
		if ((i * 8 / 100 == A)&&(i * 10 / 100 == B)) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
sub = sum(a) - 2 * a[0]
asub = abs(sub)

for i in range(1, n - 1):
    sub -= 2 * a[i]
    if abs(sub) < asub:
        asub = abs(sub)
print(asub)


Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;

ll lcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }
  if (b == 0) {
    return a;
  } else {
    return lcd(b, a % b);
  }
}

int main() {
  vector<vector<int>> C(3, vector<int>(3));
  for (int i = 0; i < 3; ++i) {
    cin >> C[i][0] >> C[i][1] >> C[i][2];
  }
  int Sb = accumulate(C[0].begin(), C[0].end(), 0);
  int a2 = (accumulate(C[1].begin(), C[1].end(), 0) - Sb) / 3;
  int a3 = (accumulate(C[2].begin(), C[2].end(), 0) - Sb) / 3;
  int Sa = a2 + a3;
  int b1 = (C[0][0] + C[1][0] + C[2][0] - Sa) / 3;
  int b2 = (C[0][1] + C[1][1] + C[2][1] - Sa) / 3;
  int b3 = (C[0][2] + C[1][2] + C[2][2] - Sa) / 3;
  vector<int> A = {0, a2, a3};
  vector<int> B = {b1, b2, b3};
  bool flg = true;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      if (C[i][j] != A[i] + B[j]) {
        flg = false;
        break;
      }
    }
    if (!flg) {
      break;
    }
  }
  if (flg) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<bitset>
#include<functional>
#include<climits>
using namespace std;
typedef pair<int,int>pii;
const int INF=1e9;
const int dx[]={0,-1,0,1},dy[]={-1,0,1,0};



int main(){
    int n,q;
    while(cin>>n>>q,n||q){
        int cnt[100]={0};
        for(int i=0;i<n;i++){
            int m;
            cin>>m;
            while(m--){
                int date;
                cin>>date;
                cnt[date]++;
            }
        }
        int mav=-1,mac=0;
        for(int i=1;i<100;i++){
            if(cnt[i]<q)continue;
            if(mac<cnt[i]){
                mac=cnt[i];
                mav=i;
            }
        }
        if(mav==-1)cout<<0<<endl;
        else cout<<mav<<endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define MAX_N 100
#define INF 0x3f3f3f3f

int N;
ll DP[MAX_N];

ll solve(int n);

int main()
{
	memset(DP, -1, sizeof(DP));
	DP[0] = 2; DP[1] = 1;

	while (~scanf("%d", &N)) {
		printf("%lld\n", solve(N));
	}
    return 0;
}

ll solve(int n) {
	if (DP[n] != -1) return DP[n];

	return DP[n] = solve(n-1) + solve(n-2);
}


Measured memory_bytes: 256
import numpy as np

n, m = map(int, input().split())
xm =list(map(int, input().split()))

xm = np.array(xm)

if n>=m:
    print(0)
else:
    xm = np.sort(xm)
    diff = xm[1:] - xm[:-1]
    diff = np.abs(diff)
    diff = np.sort(diff)
    
    print(sum(diff[:(m-n)]))

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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int mod = 1e9 + 7;
const int MAX = 1e5 + 1;

void solve()
{
	string n;
	cin >> n;
	ll sum = 0;
	for(int i = 0; i < n.length(); ++i)
	{
		int dig = n[i] - '0';
		sum += dig;
	}
	if(sum % 9 == 0) cout << "Yes\n";
	else cout << "No\n";
}


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


Measured memory_bytes: 3780
import bisect
n, q = [ int(v) for v in input().split() ]

if n != 1:
    tree_list = [0] + [ (n**(i+1)-1) // (n-1) for i in range(100) if (n**(i+1)-1) // (n-1) <= 10**9 ]

def upward(a):
    d = bisect.bisect_left(tree_list,a) - 1
    outlist = []
    for i in range(d+1):
        outlist.append(a)
        if i < d:
            a -= tree_list[d-i] + 1
            a //= n
            a += tree_list[d-i-1] + 1
    return d, outlist

def lca(a,b):
    da, a_list = upward(a)
    db, b_list = upward(b)

    if da < db:
        da, db = db, da
        a_list, b_list = b_list, a_list
    s = da - db
    ans = None
    for i in range(db+1):
        if a_list[s+i] == b_list[i]:
            ans = a_list[s+i]
            break
    return ans



for i in range(q):
    v, w = [ int(v) for v in input().split() ]
    if n != 1:
        print(lca(v,w))
    else:
        print(min(v,w))


Measured memory_bytes: 58460
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int mex=2005;
#define ll long long 
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int> 
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++) 

int main()
{
    fast
  int n;
  cin>>n;
  ll int freq[10][10];
  fo(i,0,10)
  fo(j,0,10)
  freq[i][j]=0;
  fo(i,1,n+1)
  {
      int u=i;
      int k=u%10;
      int j=0;
      while(u)
      {
          j=u;
          u=u/10;
          
      }
      freq[j][k]++;
    
  }
  ll int ans=0,ans2=0;
  fo(i,1,n+1)
  {
      int u=i;
      int k=u%10;
      int j=0;
      while(u)
      {
          j=u;
          u=u/10;
          
      }
      ans+=freq[k][j];
  }
  cout<<ans;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
inline int read(){char c = getchar();int x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 1e3 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ull n,sum = 0;
    cin >> n;
    ull arr[n+5] = {0},ans[n+5] = {00};
    for(int i = 1;i <= n;i++) cin >> arr[i];
    for(int i = 1;i <= n;i++) ans[i] = (arr[i]+ans[i-1]);
    for(int i = 1;i <= n;i++) sum = ((sum + arr[i]*((ans[n]-ans[i])%mod))%mod)%mod;
    cout << sum << endl;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    ll n, k; cin >> n >> k;
    map<ll, ll> m;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        m[a]++;
    }
    vector<ll> v;
    for(auto p : m){
        v.push_back(p.second);
    }
    sort(all(v));
    ll ans = 0;
    int c = m.size();
    for(int i = 0; i < c - k; i++){
        ans += v[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 14964
import numpy as np
n,k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n, dtype = int)
for i in range(1,n):
    s = max(0,i-k)
    dp[i] = min(dp[s:i] + np.abs(h[i] -h[s:i]))
print(dp[-1])

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

int main() {
    ll N;
    string S;
    cin >> N >>S;
    vector<vector<ll>> numPlace(10);
    for(int i=0;i<N;i++){
        int num = S[i] -'0';
        numPlace[num].push_back(i);
    }
    ll ans =0;
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)for(int k=0;k<10;k++){
        if(numPlace[i].size() ==0 || numPlace[j].size()==0){
            continue;
        }
        ll l = numPlace[i][0];
        ll r = numPlace[j].back();
        auto itrm = upper_bound(numPlace[k].begin(),numPlace[k].end(),l);
        if(itrm == numPlace[k].end()){
            continue;
        }
        if(*itrm<r){
            ans ++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

int prime[1000] = {}, coeff[1000001] = {};
long long sum[1000001] = {};

int factorize(int n, int p[], int m[])
{
	int i, k;
	for (i = 0, k = 0; prime[i] * prime[i] <= n; i++) {
		if (n % prime[i] != 0) continue;
		p[k] = prime[i];
		for (m[k] = 0; n % p[k] == 0; m[k]++, n /= p[k]);
		k++;
	}
	if (n > 1) {
		p[k] = n;
		m[k++] = 1;
	}
	return k;
}

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	int i, N, A[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	int j, k;
	for (i = 2, k = 0; i <= 1010; i++) {
		for (j = 0; j < k; j++) if (i % prime[j] == 0) break;
		if (j == k) prime[k++] = i;
	}
	
	int h, l[100], m[100], p[100], n[2], q, appear[1000001] = {};
	for (i = 1, q = 0; i <= N; i++) {
		sum[0] += A[i];
		k = factorize(A[i], p, m);
		for (j = 1, l[0] = 1; j <= k; j++) l[j] = 0;
		n[0] = p[0];
		n[1] = 1 - p[0];
		while (l[k] == 0) {
			if (coeff[n[0]] == 0) {
				coeff[n[0]] = n[1];
				appear[q++] = n[0];
			}
			sum[n[0]] += A[i] / n[0];
			
			for (j = 0; j < k && l[j] == m[j]; j++);
			if (j < k) {
				n[0] *= p[j];
				if (l[j] == 0) n[1] *= 1 - p[j];
			}
			for (l[j--]++; j >= 0; l[j--] = 0) {
				for (h = 0; h < l[j]; h++) n[0] /= p[j];
				if (l[j] > 0) n[1] /= 1 - p[j];
			}
		}
	}
	
	long long ans = (sum[0] % 998244353) * ((sum[0] - 1) % 998244353) % 998244353;
	for (j = 0; j < q; j++) {
		i = appear[j];
		sum[i] %= 998244353;
		ans = (ans + ((sum[i] * sum[i] % 998244353) * i % 998244353) * coeff[i] % 998244353) % 998244353;
	}
	
	ans = (ans + 998244353) % 998244353;
	printf("%lld\n", div_mod(ans, 2, 998244353));
	fflush(stdout);
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  
  int n = s.size() -1;
  int t = s[0] - '0';
  long long sum = 0;
  
  for(int bit=0;bit<(1<<n);bit++){
    long long t = s[0] - '0';
    
    for(int i=0;i<n;i++){
      if(bit & (1<<i)){
        sum += t;
        t = s[i+1] - '0';
      }
      else{
        t *= 10;
        t += s[i+1] - '0';
      }
      
    }
    
    sum += t;
    
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

int main() {

	int N;
	cin >> N;

	vector<char> S(N);
	rep(i, N) {
		cin >> S.at(i);	
	}

	int p = 0, w = 0, g = 0, y = 0;
	rep(i, N) {
		if (S.at(i) == 'P') {
			p++;		
		} 
		else if (S.at(i) == 'W') {
			w++;
		}
		else if (S.at(i) == 'G') {
			g++;
		}
		else {
			y++;
		}
	}

	if (p > 0 && w > 0 && g > 0 && y > 0) {
		cout << "Four" << endl;	
	}
	else {
		cout << "Three" << endl;	
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
int main()
{
	sync;
	ll n;
	cin>>n;
	vector<pair<ll,ll> >v;
	for(ll i=1;i<=n;i++)
	{
		ll x;cin>>x;
		v.push_back({x,i});
	}
	sort(v.begin(),v.end());
	for(ll i=0;i<n;i++)
	cout<<v[i].S<<" ";
}

Measured memory_bytes: 2544
#include <stdio.h>

int main(void)
{
    int n;
    int a[100];
    int i;
    int min;
    int max;

    scanf("%d", &n);

    for (i = 0; i < n; i++) scanf("%d", &a[i]);

    max = a[0];
    min = a[0];
    for (i = 0; i < n; i++){
        if (min > a[i]){
            min = a[i];
        }
        if (max < a[i]){
            max = a[i];
        }

    }

    printf("%d\n", max - min);

    return (0);
}

Measured memory_bytes: 128
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var A = lines[1].split(" ").map((value, index) => {
        return (Number(value - (index + 1)));
    });

    var a = A.concat(); a.sort((a, b) => a - b)
    var b = a[Math.floor(N / 2)]
    var ans = 0;

    for (var i = 0; i < N; i++) {
        ans += Math.abs(A[i] - b)
    }

    console.log(ans);
});

Measured memory_bytes: 35828
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

int main(){
	int n;
	int m;
	vector< pair<int, int> > lr;

	// read inputs
	cin >> n;
	cin >> m;
	int min = 0;
	int max = n;
	for (size_t i = 0; i < m; ++i) {
		int l;
		int r;
		cin >> l;
		cin >> r;
		if (l > min) {
			min = l;
		}
		if (r < max) {
			max = r;
		}
	}

	if (max - min < 0) {
		cout << 0 << endl;
	} else {
		cout << max - min + 1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
<?php
$candidate=trim(fgets(STDIN));
list($temperature,$T)=explode(" ",trim(fgets(STDIN)));
$height=explode(" ",trim(fgets(STDIN)));
$subs=[];

for($i=0;$i<$candidate;$i++){
$sub=abs($T-($temperature-$height[$i]*0.006));
$subs[]=$sub;
}

$minKeys=array_keys($subs,min($subs));
echo $minKeys[0]+1;
?>

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

bool is_prime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = std::sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

int main() {
  int X;
  std::cin >> X;

  for(int x = X; x <= 2 * x; ++x) {
    if(is_prime(x)) {
      std::cout << x << '\n';
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
  
  int D;
  scanf("%d",&D);
  
  switch(D){
    case 22:
      printf("Christmas Eve Eve Eve");
      break;
      
    case 23:
      printf("Christmas Eve Eve");
      break;
 
    case 24:
      printf("Christmas Eve");
      break;
      
    case 25:
      printf("Christmas");
      break;
  }
  
  return 0;
}

Measured memory_bytes: 128
def main():
    n, a, b = map(int, input().split())

    ans = 0

    for i in range(1, n+1):
        sum_ = 0
        num = i
        while num > 0:
            sum_ += num % 10
            num //= 10
        if sum_ >= a and sum_ <= b:
            ans += i

    print(ans)


if __name__ == "__main__":
    main()


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n+1) cin>>a[i];
  rep(i,n) cin>>b[i];
  ll ans = 0;
  rep(i,n){
    int diff = 0;
    ans += min(a[i],b[i]);
    diff = b[i]-min(a[i],b[i]);
    ans += min(diff,a[i+1]);
    a[i+1]=max(0,a[i+1]-diff);
    }
    cout << ans<<endl;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()

ans = 0
num = 0
for a, b in AB:
    ans += a*b
    num += b
    if num>M:
        ans -= (a*(num-M))
        break

print(ans)

Measured memory_bytes: 27760
#include<iostream>
using namespace std;
int main()
{
    string str;
    int number,i,temp;
    cin >> number;
    cin >> str;
    for(i=0;i<str.length();i++)
    {
        if(str.at(i)<'Z'-number)
        {
            str.at(i)+=number;
        }
        else
        {
            temp=str.at(i)+number-'A';
            temp%=26;
            str.at(i)=temp+'A';
        }
    }
    cout << str;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    vector<int> A(3);
    rep(i,3) cin >> A[i];
    sort(all(A));

    cout << (A==vector<int>{5,5,7} ? "YES" : "NO") << ln;

}


Measured memory_bytes: 3620
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int D = Integer.parseInt(tokens[1]);
		int count = 0;
		for (int i = 0; i < N; ++i) {
			tokens = in.readLine().split(" ");
			long X = Integer.parseInt(tokens[0]);
			long Y = Integer.parseInt(tokens[1]);
			if ((double) D >= Math.sqrt((double) (X * X + Y * Y))) {
				++count;
			}
		}
		System.out.println(count);
	}

	void calc() {
	}

	void showResult() {
	}
}


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

int main() {
int h,w,d;cin>>h>>w;char s[h+2][w+2];int a[h+2][w+2];string ans="Yes";
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      if(i==0 || j==0 || i==h+1 || j==w+1)a[i][j]=0;
      else cin>>s[i][j];
      if(s[i][j]=='#')a[i][j]=1;
      else a[i][j]=0;
    }
  }
  
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
     if(a[i][j]==0)continue;
      else if(a[i+1][j]==0 && a[i-1][j]==0 && a[i][j+1]==0 && a[i][j-1]==0){
        ans="No";
      }
  }
}
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	int H, W;
	cin >> H >> W;
	int N = 10;
	vector<vector<int>>C(N, vector<int>(N));
	rep(i, N) {
		rep(j, N) {
			cin >> C[i][j];
		}
	}
	vector < vector<int>>A(H, vector<int>(W));
	rep(i, H) {
		rep(j, W) {
			cin >> A[i][j];
		}
	}
	rep(k, N) {
		rep(i, N) {
			rep(j, N) {
				C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
			}
		}
	}
	
	int ans = 0;
	rep(i, H) {
		rep(j, W) {
			if (A[i][j] != -1) {
				ans += C[A[i][j]][1];
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
//Catchharsh
#include<bits/stdc++.h>
#define ll long long int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define see(x) cout<<#x<<" = "<<x<<endl
const ll MOD = 1e9+7;
const ll INF = 1011111111;
const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
inline ll add(ll a,ll b){a+=b;if(a>=MOD)a-=MOD;return a;}
inline ll sub(ll a,ll b){a-=b;if(a<0)a+=MOD;return a;}
inline ll mul(ll a,ll b){return (a*1ll*b)%MOD;}
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}

int32_t main()
{   
     IOS;
     
     ll n,m,i,j,k,x;
     cin>>n>>m>>x;
     vector< vector<ll> > v(n);
     ll cost[n];
     for(i=0;i<n;i++)
     {
        cin>>cost[i];
        vector<ll> t(m);
        for(j=0;j<m;j++) cin>>t[j];
        v[i]=t;
     }
     ll ans=LLINF;
     for(ll set=1;set<(1ll<<n);set++)
     {
        ll val[m]={0};
        ll temp=0;
        for(i=0;i<n;i++)
        {
            if(set&(1ll<<i))
            {
                for(j=0;j<m;j++)
                    val[j]+=v[i][j];
                temp+=cost[i];
            }
        }
        for(i=0;i<m;i++)
        {
            if(val[i]<x) break;
        }
        if(i==m) ans=min(ans,temp);
     }
     if(ans==LLINF) cout<<-1;
     else
     cout<<ans;
     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  string S;
  cin >> S;

  ll N = S.size();
  ll cnt = 0;

  rep2(i, 1, N){
    if(S[i] != S[i - 1]) cnt++;
  }

  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 512
N = int(input())
dp = [0] * 100500

import math
dp[1] = 1
for i in range(2, N+1):
    dp[i] = dp[i-1] + 1
    for j in range(math.floor(math.log(i, 6)) + 1):
        dp[i] = min(dp[i], dp[i - 6 ** j] + 1)
    for k in range(math.floor(math.log(i, 9) + 0.00000001) + 1):
        dp[i] = min(dp[i], dp[i - 9 ** k] + 1)


print(dp[N])


Measured memory_bytes: 9664
#include <bits/stdc++.h>
using namespace std;
#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++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

//---------------------------

using PP = pair<string, int>;

int main(){
    int n;
    cin >> n;
    vector<vector<PP>> V(n);
    V[0].push_back(PP("a",0));
    rep(i,n-1){
        for(auto x : V[i]){
            string s = x.first;
            int t = x.second;
            rep(j,t+2){
                char c = 'a' + j;
                V[i+1].push_back(PP(s+c, max(t,j)));
            }
        }
    }

    for(auto x : V[n-1]){
        cout << x.first << endl;
    }    
    return 0;
}

Measured memory_bytes: 10736
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;

  vector<int> p(1e5 + 5), a(1e5 + 5), w(1e5 + 5);
  a = {0};
  w = {0};
  vector<string> s(1e5 + 5);
  for (int i = 0; i < m; i++)
  {
    cin >> p[i] >> s[i];
    if(s[i] == "AC"){
      a[p[i] - 1] = 1;
    }else if(s[i] == "WA" && a[p[i] - 1] == 0){
      w[p[i] - 1]++;
    }
  }
  int ac = 0, wa = 0;

  for (int i = 0; i < n; i++){
    if(a[i] == 1){
      ac++;
    }else {
      w[i] = 0;
    }
  }
  for (int i = 0; i < n; i++){
    wa += w[i];
  }
  cout << ac << " " << wa << endl;
  return 0;
}

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

// Binary Indexed Tree 蟻本
class Bit
{

public:
    Bit(int n): n(n) {
        dat.resize(n + 1);
    }

    int sum(int i)
    {
        int s = 0;
        while (i > 0){
            s += dat[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x)
    {
        int s = 0;
        while (i <= n){
            dat[i] += x;
            i += i & -i;
        }
    }

private:
    int n = 0;
    vector<int>  dat;
};

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

    Bit tree(n);
    vector<int> a(n);
    vector<int> sorted(n);

    for (size_t i = 0; i < n; ++i)
    {
        cin >> a[i];
        sorted[i] = a[i];
    }
    sort(sorted.begin(), sorted.end());

    ll answer = 0;
    for (ll i = 0; i < n; ++i)
    {
        // 数字をそのまま持つとメモリー不足
        int index = lower_bound(sorted.begin(), sorted.end(), a[i]) - sorted.begin() + 1;
        answer += i - tree.sum(index);
        tree.add(index, 1);
    }
    cout << answer << endl;

    return 0;
}


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

int n,x,H,T,q[400010];

int main()
{
#ifdef h10
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
#endif
	int i;
	scanf("%d",&n);
	H=n; T=n;
	while (n--)
	{
		scanf("%d",&x);
		if (n&1) q[T++]=x;
		else q[--H]=x;
	}
	for (i=H;i<T;i++)
		printf("%d ",q[i]);
}


Measured memory_bytes: 2944
N = gets.to_i
edges = (N - 1).times.map do
  u, v, w = gets.split.map(&:to_i)
  [u - 1, v - 1, w]
end
graph = Array.new(N) { [] }
edges.each do |u, v, w|
  graph[u].push([v, w])
  graph[v].push([u, w])
end

def bfs(graph, s, colors)
  colors[s] = 0
  # [[u, parent, color], ...]
  queue = [[s, nil, colors[s]]]
  while !queue.empty?
    u, parent, color = queue.shift
    graph[u].each do |v, w|
      next if v == parent
      new_color = w.even? ? color : (color + 1) % 2
      colors[v] = new_color
      queue.push([v, u, new_color])
    end
  end
end

colors = Array.new(N)
bfs(graph, 0, colors)
colors.each do |c|
  puts c
end

Measured memory_bytes: 28668
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, x, y;
    long long ans(0);
    cin >> a >> b >> c >> x >> y;
    if(2 * c < a + b)
    {
        ans += 2 * c * min(x, y);
        //cout << ans << " ";
        if(x > y)
        {
            if(2 * c < a)
                ans += 2 * c * (x - y);
            else
                ans += a * (x - y);
        }
        else
        {
            if(2 * c < b)
                ans += 2 * c * (y - x);
            else
                ans += b * (y - x);
        }
    }
    else
    {
        ans += a * x + b * y;
    }
    cout << ans;
}

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

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	ll res=0;
	for(ll a=1;a<=n;a++){
		for(ll b=a;a*b<n;b++){
			if(a==b)res++;
			else res+=2;
		}
	}
	cout << res << endl;
}

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

int main() {
	// your code goes here
	

int N;

cin >> N;

vector <char> s(N);

for (int i=0;i<N;i++){
cin >> s.at(i);
}
int j=0;
for(int i=0;i<N;i++){

if (s.at(i)=='Y'){
j++;
}

}

if (j>0){
cout << "Four" << endl;
}

else {
cout << "Three"<< endl;
}
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pii pair<int,int>
#define iiii pair<int,pii >
#define ld double 
#define MAXN 100100
#define inf 1000000000000000000ll
using namespace std;

ll Dp[MAXN],e,t,q=inf,a[MAXN];
int n,p;




int main()
{
	scanf("%d%lld%lld",&n,&e,&t);
	for(int i=1;i<=n;i++)scanf("%lld",a+i);

	for(int i=1;i<=n;i++)
	{
		while ((a[i]-a[p+1])*2>=t)
		{
			q=min(q,Dp[p]-a[p+1]*2-a[p]);
			p++;
		}
		Dp[i]=min(3ll*a[i]+q,Dp[p]+a[i]-a[p]+t);
	}
	
	 
	printf("%lld\n",Dp[n]-a[n]+e);

	
	return 0;
} 

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
using namespace std;
int main() {
    int N,T,A;
    cin >> N >> T >> A;
    int h;
    int min = 1<<30;
    int res = 0;
    for (int i=0; i<N; i++) {
        cin >> h;
        int temperature_1000 = 1000*T - 6 * h;

        if (min>abs(1000*A-temperature_1000)) {
            min = abs(1000*A - temperature_1000);
            res = i+1;
        }
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

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

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

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

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

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

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

int n;
vi g[125252];

int bef[125252];

void dfs(int p,int b){
  bef[p] = b;
  for(int to : g[p])if(to!=b){
    dfs(to,p);
  }
}

vi path;

int color[125252];
int ans[2];

void dfs2(int p,int b,int c){
  ans[c] ++;
  for(int to : g[p])if(to != b){
    if(color[to]==1-c)continue;
    dfs2(to,p,c);
  }
}

int main(){
  scanf("%d",&n);
  REP(i,n-1){
    int a,b;
    scanf("%d%d",&a,&b);
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  REP(i,n)bef[i]=-1;
  dfs(0,-1);
  int cur = n-1;
  while(true){
    cur = bef[cur];
    if(cur==0)break;
    path.push_back(cur);
  }
  reverse(ALL(path));
  int l = path.size();
  REP(i,n)color[i] = -1;
  color[0] = 0;
  color[n-1] = 1;
  REP(i,l)color[path[i]] = 1;
  REP(i,(l+1)/2)color[path[i]] = 0;
  dfs2(0,-1,0);
  dfs2(n-1,-1,1);
  puts(ans[0]<=ans[1] ? "Snuke" : "Fennec");
  return 0;
}


Measured memory_bytes: 12280
#include <stdio.h>
int main() {
	int n, m, A, B, pt[200000] = {0};
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &A, &B);
		if (A == 1) {
			pt[B - 1]++;
		} else if (B == n) {
			pt[A - 1]++;
		}
	}
	for (int i = 0; i < n; i++) {
		if (pt[i] >= 2) {
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 896
N = input()
ss = raw_input()
s=ss.split("()")

while len(s)>1:
    s="".join(s)
    #print(s)
    s=s.split("()")

a=""
b=""

s=s[0]
N=len(s)



for i in range(N):
    if s[i]=="(":
        a+=")"
    if s[i]==")":
        b+="("

print(b+ss+a)


Measured memory_bytes: 2568
def main():
    n=int(input())
    l = sorted(map(int, input().split()))
    ll=len(l)
    count = 0
    for x in range(ll-2):
        for y in range(x+1, ll-1):
            if l[x] == l[y]:
                continue
            for z in range(y+1, ll):
                if l[y] == l[z]:
                    continue
                if l[z] < l[x]+l[y]:
                    count += 1
                else:
                    break
    print(count)

if __name__ == '__main__':
    main()

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

int main(){
    int a[3][3],b;
    bool bingo[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
            bingo[i][j]=false;
        }
    }
    int n;cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        for(int j=0;j<3;j++){
            for(int h=0;h<3;h++){
                if(a[j][h]==b) bingo[j][h]=true;
            }
        }
    }

    bool isBingo=false;
    for(int i=0;i<3;i++){
        if(bingo[i][0]&&bingo[i][1]&&bingo[i][2]){
            isBingo=true;
        }
    }
    for(int i=0;i<3;i++){
        if(bingo[0][i]&&bingo[1][i]&&bingo[2][i]){
            isBingo=true;
        }
    }
    if((bingo[0][0]&&bingo[1][1]&&bingo[2][2])||(bingo[0][2]&&bingo[1][1]&&bingo[2][0])){
        isBingo=true;
    }

    if(isBingo) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int n;
	cin>>n;
	vector<P> x(n);
	vector<int> r(n*n, -1);
	bool ok = true;
	rep(i, n){
		int t;
		cin>>t;
		x[i] = P(t-1, i);
		if(r[t-1]!=-1) ok = false;
		r[t-1] = i;
	}
	sort(all(x));
	int p = 0;
	rep(i, n){
		int c = x[i].snd;
		while(c--){
			while(r[p]!=-1) p++;
			r[p] = x[i].snd;
		}
		if(p>x[i].fst) ok = false;
	}
	//rep(i, n*n) cerr<<r[i]<<endl;
	p = n*n-1;
	for(int i = n-1; i >= 0; i--){
		int c = n-x[i].snd-1;
		while(c--){
			while(r[p]!=-1) p--;
			r[p] = x[i].snd;
		}
		if(p<x[i].fst) ok = false;
	}
	if(!ok) cout<<"No"<<endl;
	else {
		cout<<"Yes"<<endl;
		rep(i, n*n) cout<<r[i]+1<<" ";
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=3005,mod=998244353;
int f[N][N],ipw[N],pw[N];
int A,B,C,D,ans;

int power(int x,int p){
	int res=1;
	for(;p;p>>=1,x=(ll)x*x%mod)
		if(p&1) res=(ll)res*x%mod;
	return res;
}

int main(){
	read(A),read(B);
	read(C),read(D);
	f[A][B]=1;
	rep(i,A+1,C){
		ipw[0]=1,ipw[1]=power(i-1,mod-2);
		pw[0]=1,pw[1]=i-1;
		rep(j,2,D){
			ipw[j]=(ll)ipw[j-1]*ipw[1]%mod;
			pw[j]=(ll)pw[j-1]*pw[1]%mod;
		}
		int sum=0;
		rep(j,B,D){
			f[i][j]=(ll)f[i-1][j]*j%mod;
			f[i][j]=(f[i][j]+(ll)sum*pw[j])%mod;
			sum=(sum+(ll)f[i-1][j]*ipw[j])%mod;
		}
	}
	rep(i,B,D){
		ans=(ans+(ll)f[C][i]*power(C,D-i))%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 38864
n,k = map(int, input().split())

mod = 10**9+7
cnts=[0]*(k+1)

for x in reversed(range(1,k+1)):
    num= k//x

    c = pow(num,n,mod)
    for j in range(2,num+1):
        c-= cnts[x*j]
    cnts[x]=c

ans=0
for i in range(1,k+1):
    ans+=(i*cnts[i])
print(ans%mod)

Measured memory_bytes: 74548
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) 

const int N=2e5+5;
const int INF=0x3f3f3f3f;
int dp[(1<<26)+5];
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>s;
	mem(dp,INF);
	dp[0]=0;
	int mark=0;
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		mark^=1<<(s[i]-'a');
		dp[mark]=dp[mark]+1;
		for(int j=0;j<26;j++)
		{
			dp[mark]=min(dp[mark^(1<<j)]+1,dp[mark]);
		}		
		ans=dp[mark];
		dp[0]=0;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 262736
#include<stdio.h>
#include<math.h>

int main(){
  long long s = 0;
  long long a = 0;
  long long b = 0;
  long long c = 0;
  long long d = 0;
  
  scanf("%lld",&s);
  //printf("%lld#\n",s);
  
  if(s <= 1000000000){
    a=s;
    b=0;
    c=0;
    d=1;
  }else if(s == 1000000000000000000){
    a=1000000000;
    b=0;
    c=0;
    d=1000000000;
  }else{
    a= 1000000000;
    d= s / 1000000000 + 1;
    b= (a*d) - s;
    c= 1;
  }
  printf("0 0 %llu %llu %llu %llu",a,b,c,d);
  return 0;
}
    
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int q, lc;
set<pll> s;
ll as=0, ls=0, bs=0;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> q;
  s.insert(mp(-LINF, -1ll));
  auto itr = s.begin();
  FOR(_, 0, q){
    int t;
    cin >> t;
    if(t==2){
      ll h = itr->fi;
      cout << h << " " << h * (lc*2-sz(s)+1) + as - ls*2 + bs << endl;
      continue;
    }
    ll a, b;
    cin >> a >> b;
    as += a;
    bs += b;
    pll p = mp(a, ll(_));
    s.insert(p);
    if(*itr < p){
      if(sz(s)&1){
      }else{
        itr++;
        lc++;
        ls += itr->fi;
      }
    }else{
      ls += a;
      if(sz(s)&1){
        ls -= itr->fi;
        itr--;
      }else{
        lc++;
      }
    }
  }
}

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

int main(){
int p[10000];
int j=3;
int a;
bool c;
p[0]=2;
for(int i=1;i<10000;i++){
for(;;j++){
c=true;
for(int k=2;k*k<=j;k++){
a=j;
a%=k;
if(a==0){c=false; break;}}
if(c){
p[i]=p[i-1]+j;
j++;
break;}
}}

int n;
while(cin>>n){
if(n==0)break;
cout<<p[n-1]<<endl;}}

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

// @author: pashka

int main() {
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
        cout << a[i] << b[i];
    }

    return 0;
}

Measured memory_bytes: 256
def ecount(X):
  c,ans=1,[]
  for i in range(len(X)-1):
    if X[i]==X[i+1]:c+=1
    else:
      ans.append(c);c=1
  ans.append(c)
  return ans
n,k=map(int,input().split())
a=sorted(ecount(sorted(list(map(int,input().split())))))
ans=0
for i in range(max(0,len(a)-k)):ans+=a[i]
print(ans)

Measured memory_bytes: 24748
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  string s;
  cin>>s;
  if(s[5]=='0'){
    if(s[6]<'5')cout<<"Heisei";
    else cout<<"TBD";
  }else{
    cout<<"TBD";
  }
}

Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
		int a;
		cin >> a;
		int b;
		cin >> b;
		//1 <= a <= b <= 12;

		if ((a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10) && (b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12))
		cout << "Yes" << endl;
		else if ((a == 4 || a == 6 || a == 9) && (b == 6 || b == 9 || b == 11))
		cout << "Yes" << endl;
		else
		cout << "No" << endl;
}

Measured memory_bytes: 256