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

int main() {
    lint n;
    cin >> n;
    
    for(lint i=1; i<=9; i++)
    for(lint j=1; j<=9; j++) {
        if(i * j == n) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin>>N;
    if(N>=195)
        cout<<5<<endl;
    else if(N>=189)
        cout<<4<<endl;
    else if(N>=165)
        cout<<3<<endl;
    else if(N>=135)
        cout<<2<<endl;
    else if(N>=105)
        cout<<1<<endl;
    else 
        cout<<0<<endl;
    }

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

int main() {
	int x, n;
    cin >> x >> n;
    vector<int> p(n);
    rep(i, n) {
        cin >> p.at(i);
    }
    int answer;
    bool finish = false; 
    int i = 0;
    while (!finish) {
        if (!(find(p.begin(), p.end(), x-i)!=p.end())) {
            answer = x-i;
            finish = true;
        } else if (!(find(p.begin(), p.end(), x+i)!=p.end())) {
            answer = x+i;
            finish = true;
        } else {
            i++;
        }
    }
    cout << answer << endl;
}

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

int main() 
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    bool flag = true;
    while (A > 0 && C > 0) {
        if (flag) {
            C -= B;
        }else{
            A -= D;
        }
        flag = !flag;
    }
    
    if (C <= 0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3628
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	d := iSScan(n)
	ans := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			ans += d[i] * d[j]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1780
#include <stdio.h>

int main(void)
{
	int ball[10];
	int n;
	int i, j, k;
	int l, r;
	int flag;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		for (j = 0; j < 10; j++){
			scanf("%d", &ball[j]);
		}
		
		
		l = r = flag = 0;
		for (j = 0; j < 10; j++){
			if (l < ball[j]){
				l = ball[j];
			}
			else if (r < ball[j]){
				r = ball[j];
			}
			else {
				flag = 1;
				break;
			}
		}
		
		if (flag == 0){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}
/* 0022.cがTLEなんだよなぁ… */

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main(){

  vector< pair<ll, ll> > v;
  int N, M;
  cin >> N >> M;
  int a;
  pair<ll, ll> p;
  REP(i, 0, N){
    cin >> a;
    p = make_pair(a, 1);
    v.push_back(p);
  }
  int b, c;
  REP(i, 0, M){
    cin >> b >> c;
    p = make_pair(c, b);
    v.push_back(p);
  }

  sort(v.begin(), v.end(), greater< pair<ll, ll> >());

  ll ans = 0;
  int num = 0;
  int count = 0;
  while(num <= N){
    ans += v[count].first * v[count].second;
    num += v[count].second;
    count++;
  }
  count--;
  num -= v[count].second;
  ans -= v[count].first * v[count].second;
  ans += v[count].first * (N - num);

  cout << ans << endl;

  return 0;
}


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

void give(int &x, int &y){
	if(x % 2 == 1)
		x--;
	y += x/2;
	x /= 2;
	return;
}

int main(){
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 0; i < k/2; i++){
		give(a, b);
		give(b, a);
	}
	if (k % 2 == 1)
		give(a, b);
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
t =0 
for s in s:
  if s == "h":
    t=1
  elif s =="i":
    if t == 0:
      t = 0
      print("No")
      quit()
    t = 0
  else:
    print("No")
    quit()
if t == 1:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ld long double
const ll MOD = 998244353;
const ll INF = 1e18;
using namespace std;
    const int N = 10000000;
ll lp[N+100];

ll dp[N + 100], raw[N + 100];

main(){    
    #ifdef XOX
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\Input.txt", "r", stdin);
        freopen("D:\\V S Code\\cpp\\competitiveProgramming\\OPT.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(!cin.tie(NULL));
    
vector<int> pr;

for (int i=2; i<=N; ++i) {
    if (lp[i] == 0) {
        lp[i] = i;
        pr.push_back (i);
    }
    for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
        lp[i * pr[j]] = pr[j];
}


    ll n;
    cin >> n;

    raw[1] = 1, dp[1] = 1;

    ll ans = 1;

    for(ll i = 2; i <= n; i++) {
        if((i / lp[i]) % lp[i] == 0)    raw[i] = raw[i / lp[i]];
        else    raw[i] = (i / (lp[i]));
        dp[i] = dp[i / lp[i]] + dp[raw[i]];
        ans += (ll)dp[i] * i;
        //cerr << ans << " "; 
    }

    cout << ans;
}

Measured memory_bytes: 240144
def MaximumProfit():
    N = int(input())
    num = int(input())
    _min = num

    num2 = int(input())
    if num2 < num : _min = num2
    _maxn2n = num2 - num
    
    for i in range(2, N):
        num = int(input())
        if _maxn2n < num - _min : _maxn2n = num - _min
        if _min > num : _min = num

    return _maxn2n

print(MaximumProfit())


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

int main(){
    int r,D,x2000;
    cin >> r >> D >> x2000;

    int x = x2000;
    for(int i = 1; i <= 10; i++) {
        x = r*x - D;
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
T = [int(i) for i in input().split()]
M = int(input())
P = []
for i in range(M):
    array = list(map(int, input().strip().split()))
    P.append(array)

for i in range(M):
    a = int(P[i][0])
    b = T[a-1] - P[i][1]
    print(sum(T) - b)

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


int min(int a, int b)
{
	return (a < b ? a : b);
}
int abso(int x)
{
	return (x >= 0 ? x : -x);
}
static const int INF = 1e9;
int main()
{
	int n;
	cin >> n;
	vector<int> h(n+1);
	vector<int> dp(n + 1);
	for (int i = 0; i < n; i++)cin >> h[i+1], dp[i]=INF;
	dp[n] = INF;
	dp[1] = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i + 1 <= n)dp[i + 1] = min(dp[i + 1], dp[i] + abso(h[i] - h[i + 1]));
		if (i + 2 <= n)dp[i + 2] = min(dp[i + 2], dp[i] + abso(h[i] - h[i + 2]));
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;

namespace ForAtcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long a = long.Parse(Console.ReadLine());
            if (a == 0)
                Console.WriteLine("1");
            else
                Console.WriteLine("0");
        }
    }
}

Measured memory_bytes: 27512
s = input()
k = int(input())
split_s = []
counter = 1
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        split_s.append(counter)
        counter = 1
    else:
        counter += 1
split_s.append(counter)

ans = 0
if len(split_s) == 1:
    print(len(s)*k//2)
elif s[0] != s[-1]:
    # 繋がらないのでそれぞれの変換回数を求める
    for i in range(len(split_s)):
        ans += split_s[i]//2
    print(ans*k)
else:
    # 端がつながるので分割
    for i in range(1, len(split_s)-1):
        ans += split_s[i]//2
    ans += (split_s[-1]+split_s[0])//2
    ans *= k-1
    for i in range(len(split_s)):
        ans += split_s[i]//2
    print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long L[] = new long[N + 1];
		L[0] = 2;
		L[1] = 1;
		for (int i = 2; i <= N; i++) {
			L[i] = L[i - 1] + L[i - 2];
		}
		sc.close();
		System.out.println(L[N]);
	}
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  N = 1e6 + 5;

ll mx1=-1e18,mx2=-1e18,mx3=-1e18,mx4=-1e18,mi1=1e18,mi2=1e18,mi3=1e18,mi4=1e18;
int n;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        ll x,y;cin>>x>>y;
        ll u=x+y,v=x-y,p=-x+y;
        mx1=max(mx1,u);
        mi1=min(mi1,u);
        mx2=max(mx2,v);
        mi2=min(mi2,v);
        mx3=max(mx3,p);
        mi3=min(mi3,p);
    }
    cout<<max({mx1-mi1,mx2-mi2,mx3-mi3})<<'\n';
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;
 
int main() {
    vector<vector<int>> a(3,vector<int>(3));
    rep(i,3) {
        rep(j,3) cin >> a[i][j];
    }
    int n;
    cin >> n;
    int b;
    rep(k,n) {
        cin >> b;
        rep(i,3) {
            rep(j,3) {
                if (b==a[i][j]) a[i][j]=-1;
            }
        }
    }
    bool flag=0;
    bool flag3=1;
    bool flag4=1;
    rep(i,3) {
        bool flag1=1;
        bool flag2=1;
        rep(j,3) {
            if (a[i][j]!=-1) flag1=0;
            if (a[j][i]!=-1) flag2=0;
            if (i==j && a[i][j]!=-1) flag3=0;
            if (i+j==2 && a[i][j]!=-1) flag4=0;
        }
        if (!flag) flag=(flag1 || flag2);
    }
    if (!flag) flag=(flag3 || flag4);
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import numpy as np
n, k = map(int, input().split())
arr = np.array([0] + list(map(int, input().split())) + [0] * 100)

INF = 1 << 60
dp = np.full(arr.shape[0] + 100, INF, dtype=int)

dp[1] = 0

for i in range(n):
    dp[i + 1: i + k + 1] = np.minimum(dp[i + 1: i + k + 1], dp[i] + np.abs(arr[i + 1: i + k + 1] - arr[i]))

print(dp[n])

Measured memory_bytes: 22920
#include<bits/stdc++.h>
#define ww while
#define loop(i,l,r) for(int i=l;i<r;i++)
#define ci cin>>
#define co cout<<
#define ll long long
using namespace std;
//ll int dp[1000001][101]={};
ll int max(ll int a,ll int b ){
  if(a>b)
  return a;
  else
  return b;
}
ll int min(ll int a,ll int b ){
  if(a<b)
  return a;
  else
  return b;
}
int main()
 {    ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      ll int n,cap;
      cin>>n>>cap;
    ll int w[n],v[n];
      loop(i,0,n){
    ll int a,b;
      cin>>a>>b;
      w[i]=a,v[i]=b;
      }
    vector<ll int>dp(cap+1);
    for(int i=0;i<n;i++){
        for(ll int k = cap-w[i] ;k>=0;k--){
          dp[w[i]+k]=max(dp[w[i]+k],v[i]+dp[k]);
        }
     } ll int ans=0;
      loop(i,0,cap+1){
      ans=max(ans,dp[i]);
    }
     cout<<ans;
  }


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 数値
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int d = c - (a - b);
		if (d < 0) {
			d = 0;
		}

		System.out.println(d);

	}
}


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

int main( int argc, char *argv[] )
{
int A;
int B;
int C;
int D;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;
	if( A + B < C + D )
		cout << "Right" << endl;
	else if( A + B > C + D )
		cout << "Left" << endl;
	else
		cout << "Balanced" << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    vector<int> a(5);
    REP(i,5) cin >> a[i];
    REP(i,5){
        if(a[i]==0){
            cout << i+1<< endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3628
S = list(input())

def search(now, i, S):
    cnt = 1
    while True:
            if now == "L":
                if S[i-cnt] == "R":
                    if cnt %2 == 0:
                        return i-cnt, i-cnt+1
                    else:
                        return i-cnt+1, i-cnt
                else:
                    cnt += 1
            elif now == "R":
                if S[i+cnt] == "L":
                    if cnt %2 == 0:
                        return i+cnt, i+cnt-1
                    else:
                        return i+cnt-1, i+cnt
                else:
                    cnt += 1
        
l = len(S)
ans = [0 for _ in range(l)]
before = 0
for i in range(l):
    now = S[i]
    if before == now:
        tmp = index
        index = nex
        nex = tmp
    else:
        index, nex = search(now, i, S)
    ans[index] += 1
    before = now

print(" ".join([str(s) for s in ans]))

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	// your code goes here
	int H=read(),W=read();
	vector<string> C(2*H);
	REP(i,H){
		string tmp;
		cin >> tmp;
		C[2*i]=tmp;
		C[2*i+1]=tmp;
	}
	REP(i,C.size()) cout << C[i] << endl;
	
}

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

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    int cnt0 = 0, cnt1 = 0;
    for (int i = 1; i <= n; ++ i) {
        cnt0 += i % m == 0;
        cnt1 += m % 2 == 0 && i % m == (m / 2);
    }
    std::cout << 1LL * cnt0 * cnt0 * cnt0 + 1LL * cnt1 * cnt1 * cnt1 << std::endl;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  string s;
  cin >> n >> s;
  
  vector<int> x[10];
  for(int i = 0; i < n; i++){
    x[(int)s.at(i) - 48].push_back(i);
  }
  
  int ans = 0, a, b, c;
  for(int i = 0; i <= 9; i++){
    if(x[i].size() == 0) continue;
    a = x[i].at(0);
    for(int j = 0; j <= 9; j++){
      if(x[j].size() == 0) continue;
      auto bb = upper_bound(x[j].begin(), x[j].end(), a);
      if(bb == x[j].end()) continue;
      b = *upper_bound(x[j].begin(), x[j].end(), a);
      for(int k = 0; k <= 9; k++){
        if(x[k].size() == 0) continue;
        if(x[k].at(x[k].size() - 1) > b) ans++;
      }
    }
  }
  
  cout << ans << "\n";
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
int main(){
    int k=in(),x=in();
    rep(i,2*k-1){
        cout<<x-k+i+1<<" ";
    }
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int n;
    double *a;
    scanf("%d", &n);
    a = malloc(sizeof(double) * n);
    int i;
    for (i = 0; i < n; i++){
        scanf("%lf", &a[i]);
    }
    double ans = 0;
    for (i = 0; i < n; i++)
        ans += 1.0/a[i];
    ans = 1.0 / ans;

    printf("%f", ans);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int a[m];
    for(int i=0;i<m;i++)cin >> a[i];
    for(int i=0;i<m;i++){
        n-=a[i];
        if(n<0)break;
    }
    if(n>=0)cout << n;
    else cout << -1;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    int n,W;
    cin >> n >> W;
    long long dp[102][100005];
    long long w,v;
    for(int i=0; i<=n; i++){
    	for(int j=0; j<=W; j++){
        dp[i][j]=0;
        }
    }
    for(int i=1; i<=n; i++){
        cin >> w >> v;
        dp[i][w]=max(dp[i-1][w],v);
        for(int j=0; j<=W; j++){
          	dp[i][j]=max(dp[i-1][j],dp[i][j]);
        }
      	for(int j=1; j+w<=W; j++){
            if(dp[i-1][j]!=0)dp[i][j+w]=max(dp[i-1][j+w],dp[i-1][j]+v);
        }
    }
    long long ans=0;
    for(int i=0; i<=W; i++){
      ans=max(ans,dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 79616
#include<bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N,A[1000][1000],cnt,B[1000][1000],p;
vector<pair<int,int>>v[1000][1000];
queue<pair<int,int>>q;
int main(){
	cin>>N;
	for(int i=0;i<N;++i){
		for(int j=0;j<N-1;++j){
			cin>>A[i][j];
			--A[i][j];
		}
	}
	for(int i=0;i<N;++i){
		for(int j=1;j<N-1;++j){
			++B[min(i,A[i][j])][max(i,A[i][j])];
		}
	}
	for(int i=0;i<N;++i){
		for(int j=0;j<N-2;++j){
			v[min(i,A[i][j])][max(i,A[i][j])].push_back(mkp(min(i,A[i][j+1]),max(i,A[i][j+1])));
		}
	}
	for(int i=0;i<N;++i){
		for(int j=i+1;j<N;++j){
			if(B[i][j]==0){
				q.push(mkp(i,j));
			}
		}
	}
	p=N*(N-1)/2;
	while(p){
		if(q.empty()){
			cout<<-1<<endl;
			return 0;
		}
		queue<pair<int,int>>que;
		++cnt;
		while(!q.empty()){
			--p;
			int x=q.front().first;
			int y=q.front().second;
			q.pop();
			for(pair<int,int>p:v[x][y]){
				--B[p.first][p.second];
				if(!B[p.first][p.second]){
					que.push(mkp(p.first,p.second));
				}
			}
		}
		q=que;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 47104
/*
    2020.6.11
    Ве№И 1379
    LTC
*/
#include <bits/stdc++.h>
#define mem(f, x) memset( f, x, sizeof(f) )
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mk(x, y) make_pair(x, y)
#define fi first
#define se second
#define pk push_back
typedef long long LL;
using namespace std;
const int M = 1e5+50;
const int N = 1e5+50;
LL n;
int bt[N];

int main( ){
    while( scanf( "%lld", &n ) != EOF ){
        int cnt = 0;
        while( n ){
            bt[cnt++] = (n-1)%26;
            n = (n-1)/26;
        }
        for( int i = cnt-1; i >= 0; i-- )
            printf( "%c", 'a'+bt[i] );
        printf( "\n" );
    }
    return 0;
}


Measured memory_bytes: 3732
#include <stdio.h>
int main () {
  int n;
  int input;
  int arr[100];
  int i;
  int j;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&input);
    arr[i] = input;
    }
  for(j = i - 1; j >= 0; j--){
    printf("%d",arr[j]);
    if(j != 0){
      printf(" ");
    }
  }
  printf("\n");

  return 0;
}


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

void InsertionSort(int* a, int n){
    int i, v, j, k;

    for (i=1; i<n; i++){
        for (k=0; k<n; k++){
            if (k == n-1){ cout << a[k] <<endl; }
            else { cout << a[k] << " "; }
        }

        v = a[i];
        j = i - 1;

        while (j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }

        a[j+1] = v;
    }
}

int main(){
    int n;

    cin >> n;

    int a[n];
    int* ap;

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

    ap = a;

    InsertionSort(ap, n);
    for (int k=0; k<n; k++){
        if (k == n-1){ cout << a[k] << endl; }
        else { cout << a[k] << " "; }
    }

    return 0;
}



Measured memory_bytes: 3124
import math

a, b, c = [int(x) for x in input().split() ]

s = a * b * math.sin( math.radians(c)) / 2
l = a + b + math.sqrt(
    (b*math.sin(math.radians(c)))**2 + (a - b * math.cos(math.radians(c)))**2)

h = b * math.sin( math.radians(c))
print(s)
print(l)
print(h)


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	string s;
	cin >> s;

	int ans = 0;
	for (int i = sz(s) - 1; i > 0; i--) {
		if (i % 2 != 0) continue;
		if (s.substr(0, i / 2) == s.substr(i / 2, i / 2)) {
			ans = i;
			break;
		}
	}

	out(ans);

	return 0;
}

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

#define FIO                     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod                     1000000007
#define eps                     1e-9
#define setbits                 __builtin_popcount
#define gcd                     __gcd
#define rep(i,a,b)              for(int i=a;i<=b;i++)
#define repr(i,b,a)             for(int i=b;i>=a;i--)
#define forn(i,n)               for(int i=0;i<n;i++)
#define all(a)                  a.begin(), a.end()
#define in(a,b)                 ( (b).find(a) != (b).end())
#define pb                      push_back
#define fill(a,v)               memset(a, v, sizeof a)
#define endl                    "\n"
#define ff                      first
#define ss                      second
#define mp                      make_pair
#define minin(a)                *min_element (all(a))
#define maxin(a)                *max_element(all(a))
#define asort(c)                sort(all(c))
#define dsort(c)                sort(all(c), greater<int>()) 
#define PI                      3.14159265358979323846
typedef  unsigned long long          ll;
typedef  vector<int>                 vi;
typedef  pair<int, int>              ii;
typedef  vector<ii>                 vii;
typedef  set<int>                    si;
typedef  unordered_map<int, int>    mii;
typedef  vector<ll>                 vll;
typedef  long double                 ld;

const int N=505;
int c[N][N],a[N][N];

int main()
{
  
  
  
  int  n,m,q,l,r;

  
  cin>>n>>m>>q;

  while(m--)
  {
  	cin>>l>>r;
  	c[l][r]++;
  }
  repr(i,n,1)
  {
  	rep(j,1,n)
  	{
  		a[i][j]=c[i][j]+a[i][j-1]+a[i+1][j]-a[i+1][j-1];
  	}
  }
  while(q--)
  {
  	cin>>l>>r;
  	cout<<a[l][r]<<endl;
  }
  
  return 0;
}  

Measured memory_bytes: 2944
P = [1 for _ in range(10**6)]
P[0]=0
P[1]=0
for i in range(2,10**3+1):
    for j in range(i*i,10**6,i):
        P[j]=0
Q = []
for i in range(2,10**6):
    if P[i]==1:
        Q.append(i)
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
A = list(map(int,input().split()))
a = A[0]
for i in range(1,N):
    a = gcd(a,A[i])
if a>1:
    print("not coprime")
else:
    hist = [0 for _ in range(10**6)]
    flag = 0
    for i in range(N):
        a = A[i]
        if P[a]==1:
            if hist[a]==0:
                hist[a]=1
            else:
                flag=1
                break
        else:
            for q in Q:
                if a%q==0:
                    if hist[q]==0:
                        hist[q]=1
                    else:
                        flag = 1
                        break
                    while a%q==0:
                        a = a//q
                if a==1:break
            if flag==1:break
    if flag==0:
        print("pairwise coprime")
    else:
        print("setwise coprime")

Measured memory_bytes: 204004
# https://atcoder.jp/contests/abc106/tasks/abc106_d
# どうやったら高速に区間[p,q]に完全に入っている区間の数を取得できるか？
# p,qを二次元座標として捉えると電車1本の線は二次元平面上の1点として表せる
# このときp,qの区間に完全に入っている電車の本数というのは、x軸、y軸の両方において[p,q]となる四角形内にある電車の本数
# queryに高速に答えるために二次元累積和を構築する
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


import numpy as np

N, M, Q = read_ints()
LR = read_tuple(M)
pq = read_tuple(Q)

# # 二次元座標上へのプロット
# LR2d = np.zeros((N + 1, N + 1), np.int64)
# for L, R in LR:
#     LR2d[L, R] += 1 #ここがボトルネック


# numpy使わずに再実装
LR2d = [[0] * (N + 1) for _ in range(N + 1)]
for L, R in LR:
    LR2d[L][R] += 1
LR2d = np.array(LR2d)

# LR2d_accum = np.zeros((N + 2, N + 2), np.int64)
LR2d_accum = LR2d.cumsum(axis=0).cumsum(axis=1)  # 1次元累積和同様半開区間で考える
# つまりインデックスi,jとはもとの配列においてi,jを含まない四角形の領域の合計を出す

# queryに答えていく
for p, q in pq:
    print(LR2d_accum[q, q] - LR2d_accum[q, p - 1] -
          LR2d_accum[p - 1, q] + LR2d_accum[p - 1, p - 1])



Measured memory_bytes: 48892
n,c,k=map(int,input().split())
t=[]
for i in range(n):
  t.append(int(input()))
t.sort()

bus=0
arr=0
que=0
for i in range(n):
  tt=t[i]
  if que==0:
    #print('que=0,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
    arr=tt
    que+=1
    bus+=1
  else:
    if que==c:
      #print('q==c,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
      bus+=1
      arr=tt
      que=1
    else:
      if arr+k<tt:
        #print('dep,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
        bus+=1
        arr=tt
        que=1
      else:
        #print('waiting,i,bus,arr,que,t[i]',i,bus,arr,que,t[i])
        que+=1

print(bus)


Measured memory_bytes: 50392
#pragma GCC optimize "03"
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int N = 505;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int n, a[N], b[N];

int func(int d){
	int z = 0;
	for(int i = 1; i <= n; i++){
		b[i] = a[i] % d;
		z += b[i];
	}
	z /= d;
	sort(b + 1, b + n + 1);
	int s = 0;
	for(int i = 1; i <= n-z; i++)
		s += b[i];
	return s;
}

signed main() {
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	IOS;
	int k, s = 0;
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		s += a[i];
	}
	int ans = 0;
	for(int d = 1; d*d <= s; d++){
		if(s%d == 0 && func(d) <= k)
			ans = max(ans, d);
		if(s%d == 0 && func(s/d) <= k)
			ans = max(ans, s/d);
	}
	cout << ans;
	return 0;
}

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

void solve(long long N, std::string s, std::string t)
{
    long dup = 0;

    for (long i = 0; i < N; i++)
    {
        if (s.at(i) == t.at(0))
        {
            if(s.substr(i,N-i) == t.substr(0,N-i)){
                dup = N-i;
                break;
            }
        }
    }
    cout << 2 * N - dup << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::string s;
    std::cin >> s;
    std::string t;
    std::cin >> t;
    solve(N, s, t);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
long long A, B;
long long H[210000];

int main() {
  while (cin >> N >> A >> B) {
	for (int i = 0; i < N; ++i) cin >> H[i];
	sort(H, H+N);
	long long lo = 0, hi = 1LL<<30;
	while (hi - lo > 1) {
	  long long mid = (lo + hi) / 2;
	  long long need = 0;
	  for (int i = 0; i < N; ++i) {
		long long rem = H[i] - mid * B;
		if (rem > 0) need += (rem + (A-B-1)) / (A-B);
	  }
	  if (need <= mid) hi = mid;
	  else lo = mid;
	}
	cout << hi << endl;
  }
}









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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int h, w;
  cin >> h >> w;
  int d[10][10];
  for(int i = 0; i < 10; ++i) for(int j = 0; j < 10; ++j)
  {
    cin >> d[i][j];
  }

  for (int k = 0; k < 10; k++){			// 経由する頂点
    for (int i = 0; i < 10; i++) {		// 始点
      for (int j = 0; j < 10; j++) {	// 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  int num;
  ll ans = 0;
  for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j)
  {
    cin >> num;
    num = abs(num);
    ans += d[num][1];
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	
	int ans=1;
	
	int now=0;
	for(int i=1;i<=n;i++)
	{
		int ddd;
		cin>>ddd;
		now+=ddd;
		if(now<=m)
		{
			ans++;
		}
	}
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}


int main(){
  int n,m;
  cin >> n >> m;
  if(n%2==1)rep(i,m)cout << i+1 << ' ' << n-i << endl;
  else{
    rep(i,min(n/4,m))cout << i+1 << ' ' << n/2-i << endl;
    if(m<=n/4)return 0;
    int cnt=m-n/4;
    rep(i,(n-2)/4){
      cout << i+n/2+1 << ' ' << n-i-1 << endl;
      cnt--;
      if(cnt==0)return 0;
    }
  }
}

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

using namespace std;

typedef long long ll;

signed main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    vector<vector<pair<int, pair<int,int>>>> dp(n + 1, vector<pair<int, pair<int, int>>>(m + 1, make_pair(0, make_pair(-1, -1))));
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= m; ++j){
            if(i != n)
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if(j != m)
                dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
            if(i != n && j != m && s[i] == t[j] && dp[i][j].first + 1 > dp[i + 1][j + 1].first){
                dp[i + 1][j + 1] = make_pair(dp[i][j].first + 1, make_pair(i, j));
            }
        }
    }
    int x = dp[n][m].second.first;
    int y = dp[n][m].second.second;
    string ans;
    while(x != -1){
        ans += s[x];
        tie(x, y) = dp[x][y].second;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 105984
while True:
    ans = []
    data = {}
    r = input()
    if r == 0:
        break
    for i in xrange(r):
        tmp = map(int, raw_input().split())
        
        if tmp[0] in data.keys():
            data[tmp[0]] += tmp[1] * tmp[2]
        else:
            data.update({tmp[0]:tmp[1]*tmp[2]})
    
        if data[tmp[0]] >= 1000000 and tmp[0] not in ans:
            ans.append(tmp[0])
    if len(ans) == 0:
        print "NA"
    else:
        print "\n".join(map(str, ans))

Measured memory_bytes: 4324
X,N = list(map(int,input().split()))
if N == 0:
    print(X)
    exit()
p = list(map(int,input().split()))
sorted_p = sorted(p)
minDelta = 1000
minI = 0
for i in range(102):
    if not (i in sorted_p):
        delta = abs(X - i)
        if minDelta > delta:
            minDelta = delta
            minI = i
print(minI)

Measured memory_bytes: 9132
#include<stdio.h>
int main(void)
{
int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r>=0 && y-r>=0 && x+r<=W && y+r<=H){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

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

int main(){

    int N,D;
    cin >> N >> D;

    int X[N][D];
    for(int i=0;i<N;i++){
        for(int j=0;j<D;j++){
            cin >> X[i][j];
        }
    }

    double d;
    int ans=0;


    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            double sum=0;
            for(int k=0;k<D;k++){
                sum += pow(X[i][k]-X[j][k],2);
            }
            d=sqrt(sum);
            if(d==floor(d))ans++;
        }
    }

    cout << ans << endl;


    return 0;
}

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

int main() {
	int N;
	cin >> N;
  N = N%10;
	
      if ( N == 3) {
        cout << "bon" << endl;
      }
      else if ( N == 0 || N == 1 || N == 6 || N == 8 ) {
        cout << "pon" << endl;
      }
      else {
        cout << "hon" << endl;
      }
    }
 


Measured memory_bytes: 3624
def ten_to_n(X, n):
    i = X // n
    s = str(X % n)
    if (i):
        return ten_to_n(i, n) + s
    return s

def solve():
    N, M = map(int, input().split())
    n = ten_to_n(N, M)
    return len(n)
 
print(solve())


Measured memory_bytes: 2940
#!/usr/bin/env python3
# N = int(input())
S = input()
T = input()
# A, B = map(int, input().split())
# A = list(map(int, input().split()))
ans = 0
for i in range(len(S)):
    if S[i] == T[i]:
        ans += 1
print(ans)

Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>

int amari[1000000];

int main(void) {
	int x,y;
	int i;
	while(1) {
		scanf("%d%d",&x,&y);
		if(x==0 && y==0)break;
		memset(amari,0,sizeof(amari));
		amari[x]=1;
		for(i=2;;i++) {
			x=(x*10)%y;
			if(amari[x]>0) {
				printf("%d %d\n",amari[x]-1,i-amari[x]);
				break;
			} else if(x==0) {
				printf("%d 0\n",i-1);
				break;
			}
			amari[x]=i;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
        int n;
//	int flag=0;
	cin>>n;
	vector<unsigned long long> a(n);
	unsigned long long ans=1;
	
	for(auto &it : a) cin>>it;
        sort(a.begin(),a.end());
      	if(a[0]==0){
			cout<<0;
			return 0;
		}
        for(int i=0;i<(int)a.size();i++){
	
	       if(a[i]<=1000000000000000000/ans){
		       ans*=a[i];
	       }
	       else{
		       cout<<-1;
		       return 0; 
	       }

	}
	cout<<ans;

			
			
	return 0;
}

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

int N, A, B;

int enough(int T, const vector<int>& H) {
    int t = T;
    for (auto& h : H) {
        int tmp = h - B * T;
        t -= (tmp > 0) * (tmp + A - 1) / A;
    }

    return t >= 0;
}
signed main() {
    cin >> N >> A >> B;
    A -= B;

    vector<int> h(N);
    for (auto& x : h) cin >> x;

    int ok = *max_element(h.begin(), h.end());
    int ng = -1;

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (enough(mid, h)) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#define N 200001
#define K 10000
int main()
{
  int *A,*B;
  int i,j,n;
  int hi[K+1];
  scanf ("%d",&n);
  
  A=malloc(sizeof(int)*n+1);
  B=malloc(sizeof(int)*n+1); 

  for (i=0;i<=K;i++)
    hi[i]=0;


  for(i=0;i<n;i++){
    scanf ("%d",&A[i+1]);
    hi[A[i+1]]++;
  }

  for(i=1;i<=K;i++)
    hi[i]=hi[i]+hi[i-1];
  
  for(j=1;j<=n;j++){
    B[hi[A[j]]]=A[j];
    hi[A[j]]--;
  }
    
  for(i=1;i<=n;i++){
    if(i>1)
      printf(" ");
      
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 17436
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            //ここから
            var str = IO.ReadLineToIntList();
            var ans = str[1] <= 500 * str[0] ? "Yes" : "No";

            //ここまで

            Console.WriteLine(ans);
            Console.ReadKey();
        }

    }

    static class Func
    {
        static public long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); }


        public static double ToAngle(this double radian)
        {
            return (double)(radian * 180 / Math.PI);
        }

        public static double ToRadian(this double angle)
        {
            return (double)(angle * Math.PI / 180);
        }

        static public long Conbination(long n, long m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * Conbination(n - 1, m - 1) / m;
        }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }

        static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }

        static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }

        static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }

        static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } }
    }
}

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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll mod = 1e9+7;

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

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

char S[2005][2005];
int l[2005][2005], r[2005][2005], u[2005][2005], d[2005][2005];

void solve(){
  int H, W;
  cin >> H >> W;

  rep(y, H){
    rep(x, W) cin >> S[x][y];
  }

  rep(y, H){
    REP(x, 1, W){
      if(S[x][y] == '#' || S[x-1][y] == '#'){
        l[x][y] = 0;
        continue;
      }
      l[x][y] = l[x-1][y] + 1;
    }
  }

  rep(y, H){
    RREP(x, 0, W-1){
      if(S[x][y] == '#' || S[x+1][y] == '#'){
        r[x][y] = 0;
        continue;
      }
      r[x][y] = r[x+1][y] + 1;
    }
  }

  rep(x, W){
    REP(y, 1, H){
      if(S[x][y] == '#' || S[x][y-1] == '#'){
        d[x][y] = 0;
        continue;
      }
      d[x][y] = d[x][y-1] + 1;
    }
  }


  rep(x, W){
    RREP(y, 0, H-1){
      if(S[x][y] == '#' || S[x][y+1] == '#'){
        u[x][y] = 0;
        continue;
      }
      u[x][y] = u[x][y+1] + 1;
    }
  }

  int ans = 0;
  rep(y, H) rep(x, W){
    if(S[x][y] != '#') ans = max(ans, l[x][y] + r[x][y] + u[x][y] + d[x][y] + 1);
  }

  cout << ans << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

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

using namespace std;

#define llong long long 
unsigned llong int n;
int memo[31][16][11];

unsigned llong int solve(int first, int second, int third, int sum){
	if(memo[first][second][third] != -1) return memo[first][second][third];
	if(sum == n){
		return memo[first][second][third] = 1;
	}
	if(sum > n) return memo[first][second][third] = 0;

	unsigned llong int ret = 0;
	for(int i = 1; i < 4; i++){
		if(i == 1) ret += solve(first + 1, second, third, sum + i);
		if(i == 2) ret += solve(first, second + 1, third, sum + i);
		if(i == 3) ret += solve(first, second, third + 1, sum + i);
	}

	return memo[first][second][third] = ret;
}

int main(){
	while(cin >> n, n){
		fill_n(**memo, 31 * 16 * 11, -1);
		unsigned llong int ans = solve(0,0,0,0);
		if(ans % 3650 == 0){
			cout << ans / 3650 << endl;
		}else{
			cout << ans / 3650 + 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3012
import bisect

def eratosthenes(n):
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
                
    return prime_list

primes = eratosthenes(10**5)
Primes = set(primes)
pp = []
for i in primes:
    if (i+1)//2 in Primes:
        pp.append(i)
q = int(input())
for _ in range(q):
    l,r = map(int,input().split())
    print(bisect.bisect_right(pp,r)-bisect.bisect_left(pp,l))

Measured memory_bytes: 4440
//0008 Sum of 4 Integers
//nツつェツ与ツつヲツづァツづェツつスツづつォツ、a+b+c+d=nツづづ按づゥツ組ツづ個古つ青板づーツ出ツ療債つケツづヲ
//ツづ按つィツ、n<=50ツ、0<=a,b,c,d<=9ツづつキツづゥ
//ツ禿シツ療債づ個終ツづュツづィツづ孔OFツづ与ツつヲツづァツづェツづゥ

#include<iostream>
#include<numeric>
using namespace std;

int main(void)
{
	const int N = 4;
	int a[N];
	int n;
	while( cin >> n)
	{
		int count = 0;
		for(int i = 0; i < 10*10*10*10; i++)
		{
			a[0] = i/10/10/10;
			a[1] = i/10/10%10;
			a[2] = i/10%10;
			a[3] = i%10;
			if(accumulate(a, a+N, 0) == n)
				count++;
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll  X,Y;
    cin >> X >> Y;
    ll A=X;
    int ans=0;
    while (A<=Y){
        A=A*2;
        ans+=1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256