akhauriyash/Code-Regression huggingface dataset:
def main():
    def dijkstra_search(s):
        from heapq import heappush, heappop
        d = [INF] * n
        searched = [False] * n
        d[s] = 0
        searched[s] = True
        edge_list = []
        count = 1
        for i in edge[s]:
            heappush(edge_list,i)
        while edge_list:
            min_d,min_v = heappop(edge_list)
            if searched[min_v] or min_d > d[min_v]:
                continue
            v = min_v
            d[v] = min_d
            searched[v] = True
            count += 1
            for i,j in edge[v]:
                next_d = i+d[v]
                if not searched[j]:
                    heappush(edge_list,(next_d,j))
            if count == n:
                break
        return d
    
    h,w = map(int,input().split())
    n = 10
    route = []
    route = [list(map(int,input().split())) for _ in range(n)]
    INF = float('inf')
    edge = [[] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            edge[j].append((route[i][j],i))
    dist = dijkstra_search(1)
    hw = [list(map(int,input().split())) for _ in range(h)]
    ans = 0
    for i in hw:
        for j in i:
            if not j == -1:
                ans += dist[j]
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
N,K,Q = [int(i) for i in input().split()]
mem_point = [K-Q for i in range(N)]


for rounds in range(Q):
  temp = int(input())
  mem_point[temp-1] += 1 
  
for point in mem_point:
  if 0 < point:
    print("Yes")
  else:
    print("No")


Measured memory_bytes: 7900
#include <stdio.h>

int getBlock(int rating)
{
    if (rating < 400) return 1;
    else if (rating < 800) return 2;
    else if (rating < 1200) return 3;
    else if (rating < 1600) return 4;
    else if (rating < 2000) return 5;
    else if (rating < 2400) return 6;
    else if (rating < 2800) return 7;
    else if (rating < 3200) return 8;
    else return 0;
}

int min(int a, int b)
{
    if (a < b)
        return a;
    return b;
}

int max(int a, int b)
{
    if (a > b)
        return a;
    return b;
}

int main()
{
    int n, t, block[9] = {0};
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        block[getBlock(t)]++;
    }
    int res = 0;
    for (int i = 1; i <= 8; i++) {
        if (block[i] != 0) res++;
    }
    if (res != 0)
        printf("%d %d", res, res + block[0]);
    else 
        printf("%d %d", 1, block[0]);
}

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

int main() {
	int a;
	cin>>a;
	if(a<10){
	    cout<<a<<endl;
	}
	else if(a>=10&&a<100){
	    cout<<"9"<<endl;
	}
	else if(a>=100&&a<1000){
	    cout<<(9+a-99)<<endl;
	}
	else if(a>=1000&&a<10000){
	    cout<<"909"<<endl;
	}
	else if(a>=10000&&a<100000){
	    cout<<(909+a-9999)<<endl;
	}
	else {
	    cout<<"90909"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
        int N;
        cin >> N;
        int number[10000];
        for(int i=0 ; i<N ; i++ )
                cin >> number[i];
        long long int ans=0;
        for(int i=0 ; i<N ; i++ ){
                for(int j=i+1 ; j<N ; j++ ){
                        if(number[i]>number[j])
                                swap(number[i],number[j]);
                }
                ans+=number[i];
        }
        cout << number[0]<<" "<<number[N-1]<<" "<<ans<<endl;
        return 0;
}

Measured memory_bytes: 3116
x,y,a,b,c = gets.chomp.split(" ").map(&:to_i)
aryp = gets.chomp.split(" ").map(&:to_i)
aryq = gets.chomp.split(" ").map(&:to_i)
aryr = gets.chomp.split(" ").map(&:to_i)
if aryr.length <x+y
  rkouho = aryr.sort
else
  rkouho = aryr.sort[c-(x+y) .. c-1]
end

ary1 =[aryp.sort[a-x .. a-1],aryq.sort[b-y .. b-1],rkouho].flatten.sort
puts ary1[ary1.length-(x+y) .. ary1.length-1].inject(&:+)


Measured memory_bytes: 33596
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
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; }

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    llong N, HP;
    cin >> N >> HP;

    llong maxA = 0;

    vecllong b(N);
    FOR(i, N) {
        llong a;
        cin >> a >> b[i];
        maxA = max(maxA, a);
    }

    sort(b.begin(), b.end(), greater<llong>());

    auto ceil = [](llong a, llong b) {
        return (a + b - 1) / b;
    };

    llong ans = ceil(HP, maxA);
    FOR(i, N) {
        HP -= b[i];
        if(HP < 0) {
            ans = min(ans, i + 1);
            break;
        }
        llong a = (i + 1) + ceil(HP, maxA);
        ans = min(ans, a);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
object Main{
  def main(args: Array[String]){
    val sc = new java.util.Scanner(System.in)
    val num = sc.nextInt
    var list = List[Long]()

    for(i <- 1 to num){
      val in = sc.nextInt
      list = in :: list
    }

    println(list.min + " " + list.max + " " + list.sum)
  }
}

Measured memory_bytes: 60380
s = input()
table = [0 for _ in range(len(s))]
i = 0
j = 0
tmp = 'R'
while j != len(s) - 1:
    j += 1
    if s[j] != tmp:
        while i != j:
            if s[i] == 'R':
                table[i] = j - i
            i += 1
    tmp = s[j]

s_reversed = s[::-1]
table.reverse()
i = 0
j = 0
tmp = 'L'
while j != len(s) - 1:
    j += 1
    if s_reversed[j] != tmp:
        while i != j:
            if s_reversed[i] == 'L':
                table[i] = j - i
            i += 1
    tmp = s_reversed[j]

table.reverse()

ans = [0 for _ in range(len(s))]
for k in range(0, len(s)):
    if s[k] == 'R':
        if table[k] % 2 == 0:
            ans[k + table[k]] += 1
        else:
            ans[k + table[k] - 1] += 1
    else:
        if table[k] % 2 == 0:
            ans[k - table[k]] += 1
        else:
            ans[k - table[k] + 1] += 1
print(' '.join(map(str, ans)))


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    int ans = inf;

    rep(div, 1<<(h-1)) {
        int g = 0;
        vector<int> id(h);
        rep(i, h) {
            id[i] = g;
            if (div>>i&1) ++g;
        }
        ++g;
        vector<vector<int>> c(h, vector<int>(w, 0));
        // 縦でグループ分けした時の1の個数
        rep(i, h) rep(j, w) c[id[i]][j] += (s[i][j]-'0');
        int num = g - 1;
        vector<int> now(g);
        auto add = [&](int j) {
            // グループの個数を横も含めて足していく
            rep(i, g) now[i] += c[i][j];
            rep(i, g) if (now[i] > k) return false;
            return true;
        };
        rep(j, w) {
            if (!add(j)) {
                num++;
                now = vector<int>(g);
                if (!add(j)) {
                    num = inf;
                    break;
                }
            }
        }
        ans = min(ans, num);
    }

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

Measured memory_bytes: 384
// ABC149-B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    ll a,b,k;
    cin>>a>>b>>k;
    if(a<=k){
        k-=a,a=0;
        if(b<=k) b=0;
        else b-=k;
    }else{
        a-=k;
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

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

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define endl "\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

ll const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 1e9+7;

// code begins here

int main(){
    fast;
    
    ll x,n;
    cin>>x>>n;
    
    vector<ll> arr(n);
    for(auto &u: arr)
        cin>>u;
    
    set<ll> s;
    for(auto u: arr)
        s.insert(u);
    
    ll mx = inf, ans = inf;
    
    for(ll i=-200;i<=200;i++){
        if(s.count(i))
            continue;
        if(abs(i-x)<mx){
            mx = abs(i-x);
            ans = i;
        } 
        if(abs(i-x)==mx){
            ans = min(ans, i);
        }
    }
    
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3652
n = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))
ans = 0
def binary_search(lis,item):
    l = 0
    r = len(lis) - 1
    while l <= r:
        mid = (l+r)//2
        guess = lis[mid]
        if guess == item:
            return 1
        if guess > item:
            r = mid -1
        else:
            l = mid + 1
    return 0
for i in T:
    ans += binary_search(S,i)
print(ans)


Measured memory_bytes: 16708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int N,M,C;
 cin >> N >> M >> C;
 vector<int> B(M);
  int A[N][M];
  rep(i,M){
    cin >> B[i];
  }
  rep(i,N){
    rep(j,M){
      cin >> A[i][j];
    }
  }
  int ans = 0;
  for(int i= 0;i<N;i++){
    int kun = 0;
    for(int j = 0;j<M;j++){
        kun += A[i][j]*B[j];
    }
      if(kun+C>0){
        ++ans;
      }
    }
    cout << ans << endl;
 return 0;
}

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

int main() {	
	int n,a,b;
	const int AMAX=100000;
	long long k,num[AMAX];
	
	cin>>n>>k;
	for(int i=0;i<AMAX;i++)num[i]=0;
	for(int i=0;i<n;i++){
		cin>>a>>b;;
		num[a-1]+=b;
	}
	for(int i=0;i<AMAX;i++){
		if(num[i]>=k){
			cout<<i+1<<endl;
			break;
		}
		k-=num[i];
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));


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

	int N;
	cin >> N;
	int s[101] = { 0 };
	eFOR(i, 1,N) {
		int a = i;
		if (a == 1)continue;
		for (int k = 2; k <= a; k++) {
			int j = 0;
			while (a >= 1) {
				if (a%k == 0) {
					a = a / k;
					j++;
				}
				else {
					break;
				}
			}
			if (j == 0)
				continue;
			else
				s[k] += j;
		}
	}
	//REP(i, 101)cout << s[i] << endl;
	int a2=0,a4=0,a14=0,a24=0,a74 = 0;
	eFOR(i, 1, 100) {
		if (s[i] >= 2)a2++;
		if (s[i] >= 4)a4++;
		if (s[i] >= 14)a14++;
		if (s[i] >= 24)a24++;
		if (s[i] >= 74)a74++;
	}
	int ans = a74 + a24 * (a2 - 1) + a14 * (a4 - 1) + (a4*(a4 - 1)) / 2 *( a2 - 2);
	cout << ans << endl;
	return 0;
}




















Measured memory_bytes: 256
import sys
from functools import lru_cache
@lru_cache(maxsize=None)
def alg_memoization_recursion(n):
    if n==1:
        return 1
    else:
        return alg_memoization_recursion(n//2) + alg_memoization_recursion(n//2) + 1

def solve():
    H=int(input())
    print(alg_memoization_recursion(H))

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3572
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll r, D, x_prev;
  cin >> r >> D >> x_prev;
  ll gram;
  for (int i = 0; i < 10; i++) {
    gram = r * x_prev - D;
    cout << gram << endl;
    x_prev = gram;
  }
  return 0;
}

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

int main() {
  
  string a;
  int count;
  
  cin >> a;
  
  for ( int i = 0; i < 3; i++){
    if ( a.at(i) ==  '1' ){
      count++;
    }
  }
  
    cout << count << endl;
  
}



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

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> k(m), p(m);
	vector<vector<int>> s(m);
	int t;
	for (int i = 0; i < m; i++) {
		cin >> k[i];

		for (int j = 0; j < k[i]; j++) {
			cin >> t;
			s[i].push_back(t);
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}

	int ans = 0;
	int u = 0;
	for (int i = 0; i < (1 << n); i++) {
		t = 0;
		for (int j = 0; j < m; j++) {
			u = 0;
			for (int l = 0; l < k[j]; l++) {
				if (((i >> (s[j][l] - 1)) & 1) == 1) {
					u++;
				}
			}
			if (p[j] == u % 2) {
				t++;
			}
		}
		
		if (t == m) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main()
{
  ll n;
  cin>>n;
  ll a[n+1]={0},cc[n];
  for(ll i=0;i<n;i++)
  {
      cin>>cc[i];
      a[cc[i]]++;
  }
  ll sum=0;
  for(ll i=0;i<n+1;i++)
  {
      if(a[i]!=0)
      {
        sum+=((a[i]*(a[i]-1))/2);
      }
  }
  for(ll i=0;i<n;i++)
  {
      ll x=sum;
      x=x-((a[cc[i]]*(a[cc[i]]-1))/2);
      x=x+(((a[cc[i]]-1)*(a[cc[i]]-2))/2);
      cout<<x<<'\n';
      
  }
}

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

int main(){
  
  int n;
  map < int , char > mp;
  int ans = 0;
  cin >> n;
  
  for(int i = 0; i < n; i++){

    cin >> mp[i];
    
  }
  
  for(int i = 0; i < n; i++){
    
    if(mp[i] == mp[i + 1]){
    }else{
      ans++;
    }
    
    
  }
  cout << ans << endl;
  return 0;
  
}

  

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vector<pll> a(n);
  for(ll i=0;i<n;i++) {
    ll v;
    cin >> v;
    a[i]={v,i};
  }
  sort(a.rbegin(),a.rend());
  mat dp(n+1,vec(n+1));
  for(ll i=0;i<n;i++) {
    ll v=a[i].first;
    ll id=a[i].second;
    for(ll j=0;j<=i;j++) {
      dp[i+1][j+1]=max(dp[i+1][j+1],v*abs(id-j)+dp[i][j]);
      dp[i+1][j]=max(dp[i+1][j],v*abs(n-id-1-(i-j))+dp[i][j]);
    }
  }
  ll ans=0;
  for(ll i=0;i<=n;i++) {
    ans=max(ans,dp[n][i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 34664
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int K,A,B;
    cin >> K >> A >> B;
    bool X=false;
    for (int i=A;i<=B;i++) {
        if(i%K==0) {
            X=true;
            break;
        }
    }
    
    if(X==true) {
        cout << "OK" << endl;
    }
    else {
        cout << "NG" << endl;
    }
}


Measured memory_bytes: 3632
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
         int n = int.Parse(ReadLine());
         int[] x = ReadLine().Split(' ').Select(int.Parse).ToArray();
         int[] ans = new int[100];
         for(int i = 0;i < n; i++){
            for(int j = 1; j <= 100; j++){
               ans[j-1] += (int)Math.Pow(x[i]-j,2);
            }
         }
         WriteLine(ans.Min());
      }
   }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){
    
    ll n,m,d;
    cin >> n >> m >> d;
    
    if(d == 0){
        outset(10);
        cout << (ld)(m-1)/(ld)(n) << endl;
    }
    else{
        outset(10);
        cout << (ld)(m-1)*(ld)(n-d)*2/(ld)(n*n) << endl;
    }

    
    
    
    

    return 0;
}


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

int main()
{
	int n;//n種類のドーナツ
	int x;//g
	
	int m[100];
	int pay=0;
	int cnt = 0;
	cin >> n;
	cin >> x;
	for (int i = 0; i < n; i++) {
		cin >> m[i];
		pay += m[i];
		cnt++;
	}
	sort(m, m + n);

	while(1) {
		pay += m[0];
		if (pay <= x) {
			cnt++;
		}
		else break;
	}
	cout << cnt<< endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()


using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

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

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool upd_min (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool upd_max (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    n %= 10;
    if (n == 3) {
        cout << "bon\n";
    }
    else if (n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon\n";
    }
    else cout << "hon\n";
}


Measured memory_bytes: 3624
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var n = parseInt(input[0][0], 10);
    var line;
    arr_time = Array.from({length: n}, () => [0, 0, 0]);
    arr_v = [];
    for (var i = 0; i < n; i++){
        line = input[i + 1].map(e => parseInt(e, 10));
        arr_v.push([]);
        for (var j = 2; j < line.length; j++){
            arr_v[i].push(line[j]);
        }
    }
    var tmp = 0;
    time = 1;
    history = [];
    whole_loop:
    while (time < n * 2){
        for (var i = tmp; i < n; i++){
            if (arr_time[i][1] === 0) {
                arr_time[i] = [i + 1, time, 0];
                history = [i];
                time ++;
                finished = DFS(i);
                tmp = i;
                continue whole_loop;
            }
        }
    }
    for (var x of arr_time){
        console.log(x.join(" "))
    }
}

function DFS(tmpNode){
    for (let x of arr_v[tmpNode]){
        if (arr_time[x - 1][1] === 0) {
            arr_time[x - 1] = [x, time, 0];
            time ++;
            history.push(x);
            DFS(x - 1);
        } 
    }
    arr_time[tmpNode][2] = time;
    time ++;
    history.pop();
    return true;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 



Measured memory_bytes: 16624
#include <iostream>
#include <sstream>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int d;
    if (a > b){
        d = a;
        a = b;
        b = d;
    }

    if (b > c){
        d = b;
        b = c;
        c = d;
    }
    if (a > b){
        d = a;
        a = b;
        b = d;
    }
    cout << a << " "<<b<<" " << c << endl;
    return 0;
}


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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   int n,cnt=0;
   string s,t,c,v;
   cin>>n>>s>>t;

   rep(i,0,n){
      cnt = 0;
      while(s[i+cnt] == t[cnt] && i+cnt < n){
         ++cnt;
      }
      if(cnt >= n-i-1){
         cout<<2*n-cnt<<'\n';
         return 0;
      }
   }

   cout<<2*n<<'\n';
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n;    //n组数据
		int a,b,c;    //3条边的边长
		n = in.nextInt();
		for(int i=0;i<n;i++) {
			a = in.nextInt();
			b = in.nextInt();
			c = in.nextInt();
			if((a*a+b*b==c*c)||(a*a+c*c==b*b)||(b*b+c*c==a*a))
				System.out.println("YES");
			else
				System.out.println("NO");
		}
		in.close();
	}
}


Measured memory_bytes: 33032
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n, l;
  cin >> n >> l;
  vector<string> vec;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    vec.pb(s);
  }
  sort(vec.begin(), vec.end());
  for(int i = 0; i < n; i++){
    cout << vec[i];
  }
  cout << endl;
	return 0;
}


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

int main() {
  int A,B;
  int H,M;
  
  cin >> A >> B >> H >> M;
  
  cout << fixed << setprecision(20);
  
  double Mkakudo = (M * (M_PI / 30.0));
  double Hkakudo = (H + (M / 60.0)) * (M_PI / 6.0);
  
  double sa = 0;
  if(Mkakudo > Hkakudo){
    sa = Mkakudo - Hkakudo;
    if(sa == M_PI){
      cout << (double)(A + B) << endl;
      return 0;
    }else if(sa > M_PI){
      sa = (2 * M_PI) - sa;
    }
  }else if(Mkakudo < Hkakudo){
    sa = Hkakudo - Mkakudo;
    if(sa == M_PI){
      cout << (double)(A + B) << endl;
      return 0;
    }else if(sa > M_PI){
      sa = (2 * M_PI) - sa;
    }
  }else{
    double result;
    if(A > B){
      result = (double)(A - B);
    }else{
      result = (double)(B - A);
    }
    cout << result << endl;
    return 0;
  }
  
  double result = sqrt(A * A + B * B - 2.0 * A * B * cos(sa));
  cout << result << endl;
  
}

Measured memory_bytes: 4232
#include<stdio.h>
	int main()
	{
		long long n,input,max = 1e18,flag = 0,total = 1,zero = 0;
		scanf("%lld",&n);
		while(n--)
		{
			scanf("%lld",&input);
			zero = (input == 0) ? 1 : zero;
			flag = (input > max) ? 1 : flag;
			total *= input;
			if(input == 0) zero = 1; 
			else max /= input;
		}
		(zero == 1) ? printf("0\n") : (flag == 1) ? printf("-1\n") : printf("%lld\n",total);
	}

Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

vector<int> g[101];
bool used[101];
pint ans[101];
int cnt;
void dfs(int v){
    used[v]=true;
    ans[v].first=cnt++;
    rep(i,g[v].size()){
        if(!used[g[v][i]]){
            dfs(g[v][i]);
        }
    }
    ans[v].second=cnt++;
}
int main(){
    int n,u,k,v;
    cin>>n;
    rep(i,n){
        cin>>u>>k;
        --u;
        rep(j,k){
            cin>>v;
            --v;
            g[u].pb(v);
        }
    }
    cnt=1;
    rep(i,n){
        if(!used[i]) dfs(i);
    }
    rep(i,n) cout<<i+1<<" "<<ans[i].first<<" "<<ans[i].second<<endl;
    return 0;
}


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

def f(num):
    memo = [0] * 41
    if num % 4 == 1 or num % 4 == 2:
        memo[0] = 1
    for k in reversed(range(1, 41)):
        if (num >> k) & 1 == 1:
            num -= (1 << k)
            memo[k] = (num + 1) % 2
    return memo

memo1 = f(b)
memo2 = f(a-1)

ans = 0
for i in range(41):
    if (memo1[i] - memo2[i]) % 2 == 1:
        ans += (1 << i)

print(ans)

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

int main(){
  int n;
  int ans[1111]={0};
  for(int i=1;i<1001;i++){
    int sum = i;
    for(int j=i+1;j<1001;j++){
      sum += j;
      if(sum > 1000) break;
      ans[sum]++;
    }
  }
  while(cin >> n , n){
    cout << ans[n] << endl;
  } 
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

const int inf = 1e9;
int main(){
    int n,k,c;
    while(cin>>n>>k>>c){
        string s; cin>>s;
        vi l(k), r(k);
        
        int last = -inf;
        int pos = 0;
        for(int i=0; i<n && pos<k; ++i){
            if(s[i]=='o' && i>last+c){
                l[pos++] = i;
                last = i;
            }
        }

        assert(pos==k);

        last = inf;
        pos = k-1;
        for(int i=n-1; i>=0 && pos>=0; --i){
            if(s[i]=='o' && i<last-c){
                r[pos--] = i;
                last = i;
            }
        }
        
        assert(pos==-1);
        // print(l),print(r);
        
        forn(i,k){
            if(l[i]==r[i]){
                cout<<l[i]+1<<endl;
            }
        }

        // cout<<endl;
        
    }
    return 0;
}

Measured memory_bytes: 3332
import sys
import math
def Sieve_of_Eratosthenes(N):
    prime=set(i for i in range(2,N+1))
    for i in range(2,math.ceil(N**0.5)+1):
        tmp=set()
        for j in prime:
            if j>i and j%i==0: tmp.add(j)
        for j in tmp:
            prime.remove(j)

    return(prime)

N=int(input())
prime=Sieve_of_Eratosthenes(55555)
ans=[[] for i in range(5)]
for i in prime:
    ans[i%5].append(i)

for i in range(N):
    print(ans[1][i],end=" ")

Measured memory_bytes: 9452
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Set<String> S = new HashSet<>();
        int n = sc.nextInt();
        for (int i=0; i<n; i++) {
            S.add(sc.next());
        }

        Set<String> T = new HashSet<>();
        int q = sc.nextInt();
        for (int i=0; i<q; i++) {
            T.add(sc.next());
        }

        S.retainAll(T);
        System.out.println(S.size());
    }
}



Measured memory_bytes: 79856
function Main(input){
	input = input.split("\n");
	var mem = input[0].split(" ").map(Number);
	var arr = input[1].split(" ").map(Number);
	var max = 0;
	for(var i=1;i<arr.length;i++){
	    if(max<arr[i]-arr[i-1]) max = arr[i]-arr[i-1];
	}
	if(mem[0]-arr[arr.length-1]+arr[0]>max) max = mem[0]-arr[arr.length-1]+arr[0];
	console.log(mem[0]-max)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 35956
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)1e5 + 1;
const int INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

int n, a[N], b[N];
int main (){
  scanf ("%d", &n);
  forn (i, 1, n) scanf ("%d", a + i);
  forn (i, 1, n) scanf ("%d", b + i);
  int pos = n, ans = 0;
  while (pos > 0){
    int cur = 0;
    forn (i, 1, pos){
      cur += a[i];
    }
    forn (i, pos, n){
      cur += b[i];
    }
    ans = max(ans, cur);
    pos--;
  }
  printf ("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
#define FOr(i, a, b) for (int i=a; i<(b); i++)
#define For(i, a) for (int i=0; i<(a); i++)
#define FOrr(i,a,b) for (int i = (b)-1; i >= a; i--)
#define Forr(i,a) for (int i = (a)-1; i >= 0; i--)
/////////////////////////// ..... ///////////////////////////
#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args){
cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }
/////////////////////////// ..... ///////////////////////////
#define int ll
#define pb(x) push_back(x)
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////
const int N = 101;
const int M = 100010;
int w[N],v[N];
int dp[N][M];
/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	int n,W; cin >> n >> W;
	For(i,n)cin >> w[i] >> v[i];
	For(i,n)For(j,M)dp[i][j]=INF;
	dp[0][0]=0;
	dp[0][v[0]]=w[0];
	For(i,n){
		For(j,M){
			if(i+1 < n && j+v[i+1]<M)
				dp[i+1][j+v[i+1]]=min(dp[i+1][j+v[i+1]],w[i+1]+dp[i][j]);
			if(i+1<n)
				dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
		}
	}
	Forr(j,M){
		if(dp[n-1][j] <= W){
			cout << j << "\n";
			return;
		}
	}
}
int32_t main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("TC", "r", stdin);
		//freopen("output.txt","w",stdout);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	for(int tt=1;tt<=t;tt++){
		//cout << "Case #"<<tt<<": ";
		solve();
	}
	#ifndef ONLINE_JUDGE
    	cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
    #endif
}

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

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x*y/gcd(x,y);
}
 
signed main(){
	int n,m;
	string s,t;
	cin>>n>>m>>s>>t;
	int x=lcm(lcm(n,m)/n,lcm(n,m)/m);
	for(int i=0;i<lcm(n,m)/x;i++){
		if(s[lcm(n,m)/m*i]!=t[lcm(n,m)/n*i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<lcm(n,m)<<endl;
}

Measured memory_bytes: 512
n=int(input())
#n,m=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

def divnum(n):
    res=0
    for i in range(1,n+1):
        if n%i==0:
            res+=1
    if res==8:
        return True
    else:
        return False
count=0
for i in range(1,n+1):
    if i%2!=0 and divnum(i):
        count+=1
print(count)

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

int main() {
	int length, convert_number;
	string result;
	cin >> length >> convert_number >> result;

	int index = convert_number - 1;
	if (result[index] == 'A') {
		result[index] = 'a';
	} 
	if (result[index] == 'B') {
		result[index] = 'b';
	}
	if (result[index] == 'C') {
		result[index] = 'c';
	}

	cout << result;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
   ll n,i,j,a,b;
   cin>>n;
   for(i=1; i*i<=n; i++)
   {
     if(n%i==0)
     {
       a=i;
       b=n/i;
     }
   }
   
   a--; b--;
   cout<<a+b<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;

int score = 0;
int N, K;
int R, S, P;
string T;

vector<vector<int>> dp(3,vector<int>(100001, 0));
vector<char> used(100001,'x');

void dps(int idx){
    // 文字列の最終まで来ていたらreturn
    if(idx == N){
        return;
    }
    // 前回までの試行の最大値を計算する
    int before_maxi = max(dp[0][idx - 1], max(dp[1][idx - 1], dp[2][idx - 1]));

    // 今回の各ハンドについて処理する
    if(T[idx] == 's'){
        if(used[idx - K] == 's'){
            dp[0][idx] = -1;
        }else{
            dp[0][idx] = before_maxi + R;
            used[idx] = 's';
        }
    }else if(T[idx] == 'p'){
        if(used[idx - K] == 'p'){
            dp[1][idx] = -1;
        }else{
            dp[1][idx] = before_maxi + S;
            used[idx] = 'p';
        }
    }else if(T[idx] == 'r'){
        if(used[idx - K] == 'r'){
            dp[2][idx] = -1;
        }else{
            dp[2][idx] = before_maxi + P;
            used[idx] = 'r';
        }
    }else{
        cout << "error" << endl;
    }
    for(int i = 0; i < 3; i++){
        if(dp[i][idx] == 0){
            dp[i][idx] = before_maxi;
        }
    }
    dps(idx + 1);
    return;
}

int main(){
    cin >> N >> K;
    cin >> R >> S >> P; //
    cin >> T;
    int before_maxi = 0;
    for(int i = 0; i < K; i++){
        if(T[i] == 's'){
            dp[0][i] += before_maxi + R;
            used[i] = 's';
        }else if(T[i] == 'p'){
            dp[1][i] += before_maxi + S;
            used[i] = 'p';
        }else if(T[i] == 'r'){
            dp[2][i] += before_maxi + P;
            used[i] = 'r';
        }else{
            cout << "error" << endl;
            return 0;
        }
        for(int j = 0; j < 3; j++){
            if(dp[j][i] == 0){
                dp[j][i] = before_maxi;
            }
        }
        before_maxi = max(dp[0][i], max(dp[1][i], dp[2][i]));
    }
    dps(K);
    // 結果を出力
    cout << max(dp[0][N - 1], max(dp[1][N - 1], dp[2][N - 1])) << endl;

    // debug
//    for(int i = 0; i < N; i++){
//        cout << dp[0][i] << " ";
//    }
//    cout << endl;
//    for(int i = 0; i < N; i++){
//        cout << dp[1][i] << " ";
//    }
//    cout << endl;
//    for(int i = 0; i < N; i++){
//        cout << dp[2][i] << " ";
//    }
//    cout << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+20;
const ll mod=1e9+7;
char s[N],t[N];
int fail[N],suf[N];
void getfail(int *fail,char *s)
{
	fail[0]=-1;
	int i=0,j=-1;
	while(s[i])
	{
		if(j==-1||s[i]==s[j])
		{
			fail[i+1]=j+1;
			i++,j++;
		}
		else
			j=fail[j];
	}
}
int main()
{
	scanf("%s",s);
	ll ans=0;
	int len=strlen(s);
	for(int i=0;s[i];i++)
	t[i]=s[len-i-1];
	t[len]='\0';
	getfail(fail,s);
	getfail(suf,t);
	int m;
	if(fail[len]==0||len%(len-fail[len]))
	m=1;
	else
	m=2;
	bool flag=true;
	for(int i=1;s[i];i++)
	{
		if(s[i]!=s[i-1])
			flag=false;
	}	
	if(flag)
	m=len;
	if(m==1||flag)
	ans=1;
	else
	{
		for(int i=0;i<len-1;i++)
		{
			int k=len-i-1;
			if((fail[i+1]==0||(i+1)%((i+1)-fail[i+1])) &&(suf[k]==0||(k)%(k-suf[k])))
			ans++;
		}
	}	
	printf("%d\n%d\n",m,ans);
	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> X(M);
    for(auto &x:X) cin>>x;
    sort(X.begin(), X.end());
    vector<int> seg;
    for(int i=0;i<M-1;i++) seg.push_back(X[i+1]-X[i]);
    sort(seg.begin(), seg.end(),greater<int>());
    int64_t ans=0;
    if(seg.size())for(int i=N-1;i<seg.size();i++) ans+=seg[i];
    cout<<ans<<endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
   // freopen("in.txt", "r", stdin);
    char x,y;
    while(cin >> x >> y) {
        if (x < y)
        {
            printf("<\n");
        } else if(x > y){
            printf(">\n");
        } else printf("=\n");
    }
    return 0;
}

Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())

ANS=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500+j*100+k*50==X:
                ANS+=1

print(ANS)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b){
	if(a%b==0) return b;
	else return gcd(b,a%b);
}

int main(){
	int K;
	cin >> K;
	long long int ans = 0;
	rep(i,K){
		rep(j,K){
			rep(k,K){
				ans += gcd(i+1,gcd(j+1,k+1));
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
	ll f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
//**********head by yjjr**********
#define pb push_back
const int maxn=1e5+6;
struct point{int id,val;};
vector<point> v[4];
int n,r,c,s[maxn<<1],top=0;
inline bool check(int x,int y){
	if(x==0||x==r||y==0||y==c)return 1;else return 0;
}
void push(int id,int x,int y){
	if(x==0)v[0].pb({id,y});
	else if(y==c)v[1].pb({id,x});
	else if(x==r)v[2].pb({id,y});
	else if(y==0)v[3].pb({id,x});
}
inline bool cmp1(point a,point b){return a.val<b.val;}
inline bool cmp2(point a,point b){return a.val>b.val;}
int main()
{
	r=read(),c=read(),n=read();
	rep(i,1,n){
		int X1=read(),Y1=read(),X2=read(),Y2=read();
		if(check(X1,Y1)&&check(X2,Y2))push(i,X1,Y1),push(i,X2,Y2);
	}
	sort(v[0].begin(),v[0].end(),cmp1);
	sort(v[1].begin(),v[1].end(),cmp1);
	sort(v[2].begin(),v[2].end(),cmp2);
	sort(v[3].begin(),v[3].end(),cmp2);
	rep(j,0,3)
		for(int i=0;i<v[j].size();i++){
			if(top==0){s[++top]=v[j][i].id;continue;}
			if(s[top]==v[j][i].id)top--;else s[++top]=v[j][i].id;
		}
	if(top==0)puts("YES");else puts("NO");
	return 0;
}
	

Measured memory_bytes: 2584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  string s;cin>>s;
  lvector R(n+1,0),G(n+1,0),B(n+1,0);
  ll pos=n-1;
  while(pos>-1) {
    if(s[pos]=='R') R[pos]+=1;
    if(s[pos]=='G') G[pos]+=1;
    if(s[pos]=='B') B[pos]+=1;
    R[pos]+=R[pos+1];G[pos]+=G[pos+1];B[pos]+=B[pos+1];
    pos--;
  }
  for(ll i=0;i<n-2;++i) {
    for(ll j=i+1;j<n-1;++j) {
      if(s[i]==s[j]) continue;
      if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R')) {
        ans+=B[j+1];
        if(2*j-i<n&&s[2*j-i]=='B') ans--;
      }
      else if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R')) {
        ans+=G[j+1];
        if(2*j-i<n&&s[2*j-i]=='G') ans--;
      } 
      else if((s[i]=='G'&&s[j]=='B')||(s[i]=='B'&&s[j]=='G')){
        ans+=R[j+1];
        if(2*j-i<n&&s[2*j-i]=='R') ans--;
      }
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3728
N, K = map(int, input().split())
a_list = list(map(int, input().split()))
MOD = 10 ** 9 + 7

inversion = 0
for i in range(len(a_list)):
    for j in range(i + 1, len(a_list)):
        if a_list[i] > a_list[j]:
            inversion += 1

total_lower = 0
for i in range(len(a_list)):
    total_lower += len([x for x in a_list if x < a_list[i]])


total_k = (K * (K - 1)) // 2
total = (total_lower * total_k+ inversion * K) % MOD
print(total)

Measured memory_bytes: 42716
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var ABCD = ReadLine().ToCharArray().Select(c => long.Parse(c.ToString())).ToArray();
            for (var i = 0; i < 8; ++i)
            {
                var s = ABCD[0];
                var t = i;
                var ans = ABCD[0].ToString();
                for(var j=0;j<3;++j)
                {
                    if ((t & 1) == 0)
                    {
                        s += ABCD[j + 1];
                        ans += "+" + ABCD[j + 1].ToString(); 
                    }
                    else
                    {
                        s -= ABCD[j + 1];
                        ans += "-" + ABCD[j + 1].ToString();
                    }
                    t >>= 1;
                }
                if (s == 7)
                {
                    WriteLine(ans + "=7");
                    return;
                }
            }
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main(){
  int n;
  cin >> n;
  vector<queue<int>> a(n);
  int q;
  cin >> q;
  REP(i,q){
    int b,t;
    cin >> b >> t;
    if(b==0){
      int x;
      cin >> x;
      a[t].push(x);
    }else if(b==1){
      if(!a[t].empty()){
        cout << a[t].front() << endl;
      }
    }else{
      if(!a[t].empty()){
        a[t].pop();
      }
    }
  }
}



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

using namespace std;

typedef long long ll;

ll get_ans(ll n, ll pot, int cnt) {
  if (pot == 0) return 0;
  ll d = n / pot;
  ll ans = get_ans(n % pot, pot / 10, cnt - 1) + d;
  if (d) {
    ans = max(ans, d - 1 + cnt * 9);
  }
  return ans;
}

int main() {
  ll n;
  cin >> n;
  ll pot = 1;
  int cnt = 0;
  while (pot * 10 <= n) cnt++, pot *= 10;
  cout << get_ans(n, pot, cnt) << endl;
}


Measured memory_bytes: 256
def resolve():
    n = int( input() )
    h = list(map(int,input().split()))
    if n==1:
        print('Yes')
        exit(0)
    right = h[-1]
    for left in h[-2::-1]:
        if(left>right+1):
            print('No')
            exit(0)
        if(left==right+1):
            left=left-1
        right=left
    print('Yes')


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 63984