akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
using namespace std;

int main() {
    long long int a, b, n;
    cin >> a >> b >> n;
    if (n >= b) n = b - 1;
    cout << a * n / b - a * (n / b) << endl;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll A,B,C;
    cin >> A >> B >> C;
    SANKOU((A+B+C)>=22,bust,win);
}

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

using namespace std; 

int main(){ 
  int n,k;
  cin>>n>>k;
  int a[100]={0};
  for(int i=0;i<k;++i){
    int d;
    cin>>d;
    for(int j=0;j<d;j++){
      int x;
      cin>>x;
      a[x-1]+=1;
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(a[i]!=0) ans+=1;
  }
  cout<<n-ans;
  
}   


Measured memory_bytes: 3592
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]
def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True
def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret
print(dfs(0, 'TTT'))

Measured memory_bytes: 3872
inf = 10**10

n = int(input())
ans = inf
def f(x):
    cur = 0
    while x >0:
        cur += x % 10
        x = x //10
    return cur
for a in range(1,n):
    b = n-a
    ans = min(ans,f(a)+f(b))
print(ans)


Measured memory_bytes: 40812
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
const int MD=1e9+7;
int pri[N],tot,phi[N];
bool p[N];
void init() {
    p[1]=true,phi[1]=1;
    for(int i=2;i<N;i++) {
        if(!p[i]) pri[++tot]=i,phi[i]=i-1;
        for(int j=1;j<=tot&&i*pri[j]<N;j++) {
            p[i*pri[j]]=true;
            if(i%pri[j]==0) {
                phi[i*pri[j]]=phi[i]*pri[j];
                break;
            }
            else phi[i*pri[j]]=phi[i]*(pri[j]-1);
        }
    }
}
int quick_pow(int x,int y) {
    int ans=1;
    while(y) {
        if(y&1) ans=1LL*ans*x%MD;
        y>>=1;
        x=1LL*x*x%MD;
    }
    return ans;
}
void add(int &x,int y) {
    x+=y;
    if(x>=MD) x-=MD;
}
int main() {
    init();
    int n,k,ans=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++) {
        add(ans,1LL*quick_pow(k/i,n)*phi[i]%MD);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 4348
#include<iostream>
#include<vector>
#include<sstream>
#include<algorithm>
#include<cstdlib>
using namespace std;

bool cmp(const string& a,const string b)
{
  if(a.size() != b.size())
    return a.size() < b.size();
  if(a != b)
    return (atoi)(a.c_str()) < (atoi)(b.c_str());
  return false;
}

int main()
{
  int n;
  vector<string> vec;
  cin >> n; 
  vec.resize(n);

  int men = 100000000;  
  int Size[6];
  for(int i=0;i<6;i++)
    Size[i] = 0;
  for(int i=0;i<n;i++)
    cin >> vec[i],Size[vec[i].size()]++,men = min(men,(int)vec[i].size());

  sort(vec.begin(),vec.end(),cmp);
    
  if(Size[men] >= 4)
      cout << vec[0] << vec[3] << endl;
  else if(Size[men] == 3)
    cout << vec[1] << vec[0] << endl;
  else if(Size[men] == 2)
    {
      string a,b;
      a = vec[0]+vec[2];
      b = vec[2]+vec[0];
      cout << min((atoi)(b.c_str()),(atoi)(a.c_str())) << endl;
    }
  else if(Size[men] == 1)
    {
      vector<string> ans;
      for(int i=0;i<min(4,n);i++)
	for(int j=0;j<min(4,n);j++)
	  if(i != j)
	    ans.push_back(vec[i]+vec[j]);
      sort(ans.begin(),ans.end(),cmp);
      cout << ans[2] << endl;
    }

  return 0;
}

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

using namespace std;

using ll = long long;

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

    string s;
    cin >> s >> s;
    char c = s.front();
    cin >> s;
    cout << "A" + string(1, c) + "C\n";

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        while(true){
            try{
            StringTokenizer st=new StringTokenizer(br.readLine()," ");
            int a=Integer.parseInt(st.nextToken());
            int b=Integer.parseInt(st.nextToken());
            int gcd=GCD(a,b);
            long lcm=LCM(a,b,gcd);
            System.out.println(gcd+" "+lcm);
            }catch(Exception e){
                System.exit(0);
            };
        }
    }
    
    static int GCD(int a,int b){
        while(a!=b){
            if(a<b) b-=a;
            else a-=b;
        }return a;
    }
    
    static long LCM(int a,int b,int gcd){
        return ((long)a*b)/gcd;
    }
    
}

Measured memory_bytes: 24556
def main():
    n = int(input())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    for answer in calc(n, x, y):
        print("{:.6f}".format(answer))


def calc(n, x, y):
    ret = []
    patterns = [1, 2, 3]
    for pattern in patterns:
        sum = 0
        for i in range(0, n):
            sum += (abs(x[i] - y[i])) ** pattern
        ret.append(sum ** (1 / pattern))

    last = 0
    for i in range(0, n):
        last = max(last, abs(x[i] - y[i]))
    ret.append(last)

    return ret


if __name__ == "__main__":
    main()



Measured memory_bytes: 5648
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    var sum = 0
    
    for (i in 1..3) {
      sum += input.nextInt()
    }
    
    if (sum >= 22) {
      println("bust")
    } else {
      println("win")
    }    
  }
}

Measured memory_bytes: 36372
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF INT_MAX

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

// ????????¨???????????????????¨???????????§???????
struct Edge {
    int from, to, cost;
    Edge(int f, int s, int d) : from(f), to(s), cost(d) {}
};

// 1??????????????????????????????????????±????????????????????????????????? vector
// Edges????????????????????????????????????????????°??????????????????
typedef vector<Edge> Edges;

// ???????????±??????????????? vector
// Graph??????????????????????????°?????????????????§??? V ??§?????????
typedef vector<Edges> Graph;

// union-find??¨
int uf[100010];
int rank[100010];

// ?????????
void init(int n) {
    rep(i,0,n) {
        uf[i] = i;
        rank[i] = 0;
    }
}

// find (??¨??????????±???????)
int find(int x) {
    if(uf[x] == x) return x;
    else return uf[x] = find(uf[x]);
}

// x ??¨ y ????±??????????????????????
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]) uf[x] = y;

    else {
        uf[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
    }
}

// x ??¨ y ???????????????????±???????????????????
bool same(int x, int y) {
    return find(x) == find(y);
}

bool comp(const Edge &e1, const Edge &e2) {
    return e1.cost < e2.cost;
}

int kruskal(Graph &G) {
    int V = G.size();
    vector<Edge> es;
    rep(i,0,V) rep(j,0,G[i].size()) es.push_back(G[i][j]);
    int E = es.size();
    sort(es.begin(), es.end(), comp);
    init(V); int res = 0;
    for(int i=0; i<E; i++) {
        Edge e = es[i];
        if(!same(e.from, e.to)) {
            unite(e.from, e.to);
            res += e.cost;
        }
    }
    return res;
}

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int V, E;
    cin >> V >> E;
    Graph G(V);
    int s, t, d;
    rep(i,0,E) {
        cin >> s >> t >> d;
        G[s].push_back(Edge(s,t,d));
        G[t].push_back(Edge(t,s,d)); // ????????°??????????????§
    }

    int ans = kruskal(G);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int main()
{
    ll n , gcd , x;
    cin >> n;
    for(ll i = 0 ; i < n ; i++)
    {
        cin >> x;
        if(!i) 
            gcd = x;
        gcd = __gcd ( x , gcd);
    }
    cout << gcd << endl;
    return 0;
}

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

int main()
{
 	char str[7];
    cin >> str;
  
  	if ((str[2] == str[3]) && (str[4] == str[5])) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, ll> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

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

    int n;
    cin >> n;
    vector<int> pos(n);
    for(int i = 0; i < n; ++i){
        int p;
        cin >> p;
        --p;
        pos[p] = i;
    }
    
    int max_len = 0;
    int len = 0;
    int val = -1;
    for(int i = 0; i < n; ++i){
        if(pos[i] > val){
            ++len;
            val = pos[i];
        }
        else{
            max_len = max(max_len, len);
            len = 1;
            val = pos[i];
        }
    }
    max_len = max(max_len, len);
    int res = n - max_len;
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	string s;
	cin >> s;
	// RRRR...RRRLLLL...LLL....の塊で考える
	// 切り替わるところでずっとステップを踏み続ける
	// R側で、10^100回目でLの最も左=s[now + r_cnt - 1]にいるのはr_cnt / 2
	// L側で、10^100回目でRの最も右=s[now + r_cnt]にいるのはl_cnt / 2
	int ans[100001] = {};
	int now = 0;
	while(now < s.length()){
		int r_cnt = 0;
		int l_cnt = 0;
		while(now + r_cnt < s.length() && s[now + r_cnt] == 'R') r_cnt++;
		while(now + r_cnt + l_cnt < s.length() && s[now + r_cnt + l_cnt] == 'L') l_cnt++;
		ans[now + r_cnt - 1] = l_cnt / 2 + r_cnt / 2 + r_cnt % 2;
		ans[now + r_cnt] = l_cnt / 2 + l_cnt % 2 + r_cnt / 2;
		now += r_cnt + l_cnt;
	}

	for(int i = 0; i < s.length(); i++){
		cout << ans[i];
		if(i == s.length() - 1) cout << endl;
		else cout << " ";
	}
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

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

const int MAX_N = 1000 * 1000 + 10;
bool isPrime[MAX_N];

void makePrimes() {
  REP(i, MAX_N) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i * i < MAX_N; i++)
      if (isPrime[i])
          for (int j = i * i; j < MAX_N; j += i)
              isPrime[j] = false;
}

bool can[MAX_N];

int main() {
  makePrimes();

  for (int N, X; cin >> N >> X, (N || X); ) {
      memset(can, 0, sizeof(can));
      can[0] = true;
      REP(i, N) {
          int a; cin >> a;
          for (int p = 0; p + a <= X; p++)
              if (can[p]) can[p + a] = true;
      }

      int ans = -1;
      for (int i = 0; i <= X; i++)
          if (isPrime[i] && can[i])
              ans = i;
      if (ans == -1)
          cout << "NA" << endl;
      else
          cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,m;
  cin >> n >> m;

  ll l=1,r=n;
  for(int i=0;i<m;i++){
    ll L,R;
    cin >> L >> R;
    if(l<L)l=L;
    if(R<r)r=R;
  }

  if(r>=l)cout << r-l+1 << endl;
  else cout << 0 << endl;


}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{//ABC130A
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		System.out.println(x<a? 0 :10);
		sc.close();
	}
}

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

int main() {
  string s, t;
  cin >> s >> t;

  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == t.at(i)){
      count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    for(int i=1; i<=9; i++){
        if((N%i==0) && (N/i)<=9){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    int N, K, Q;
    cin >> N >> K >> Q;
    int A[Q];
    REP(i, Q)
    {
        cin >> A[i];
        A[i]--;
    }

    int solved[N] = {0};
    REP(i, Q)
    {
        solved[A[i]]++;
    }
    int point[N];
    REP(i, N)
    {
        point[i] = K + solved[i] - Q;
        if (point[i] > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}


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

#define SIZE 400
#define NUM 251

typedef struct {
	int t, h;
	long long num;
} edge;

int main()
{
	int i, N, M, u, w, *adj[100001], deg[100001] = {}, q[100001] = {};
	long long *block[100001] = {};
	edge e[200001];
	scanf("%d %d", &N, &M);
	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &u, &w);
		e[i*2].t = u;
		e[i*2].h = w;
		e[i*2+1].t = w;
		e[i*2+1].h = u;
		e[i*2].num = -1;
		e[i*2+1].num = -1;
		deg[u]++;
		deg[w]++;
	}
	for (i = 1; i <= N; i++) {
		adj[i] = (int*)malloc(sizeof(int) * deg[i]);
		if (deg[i] > SIZE) block[i] = (long long*)malloc(sizeof(long long) * ((deg[i] + SIZE - 1) / SIZE));
	}
	for (i = 0; i < N - 1; i++) {
		u = e[i*2].t;
		w = e[i*2].h;
		adj[u][q[u]++] = i * 2;
		adj[w][q[w]++] = i * 2 + 1;
	}
	
	int par[100001] = {}, head, tail;
	long long dp[100001] = {};
	par[1] = 1;
	q[0] = 1;
	for (head = 0, tail = 1; head < tail; head++) {
		u = q[head];
		for (i = 0; i < deg[u]; i++) {
			w = e[adj[u][i]].h;
			if (par[w] == 0) {
				par[w] = u;
				q[tail++] = w;
			}
		}
	}
	for (head--; head >= 0; head--) {
		u = q[head];
		dp[u] = 1;
		for (i = 0; i < deg[u]; i++) {
			w = e[adj[u][i]].h;
			if (w == par[u]) continue;
			else {
				if (e[adj[u][i]].num == -1) e[adj[u][i]].num = dp[w];
				dp[u] = dp[u] * (e[adj[u][i]].num + 1) % M;
			}
		}
	}
	printf("%lld\n", dp[1]);
	
	int j, k;
	for (head = 0; head < tail; head++) {
		u = q[head];
		if (deg[u] > SIZE) {
			for (i = 0; i <= (deg[u] - 1) / SIZE; i++) {
				for (j = 0, block[u][i] = 1; j < SIZE && i * SIZE + j < deg[u]; j++) block[u][i] = block[u][i] * (e[adj[u][i*SIZE+j]].num + 1) % M;
			}
		}
		for (i = 0; i < deg[u]; i++) {
			if (e[adj[u][i]^1].num >= 0) continue;
			else e[adj[u][i]^1].num = 1;
			if (deg[u] > SIZE) {
				for (k = 0; k < i / SIZE; k++) e[adj[u][i]^1].num = e[adj[u][i]^1].num * block[u][k] % M;
				for (j = i / SIZE * SIZE; j < deg[u] && j < (i / SIZE + 1) * SIZE; j++) if (j != i) e[adj[u][i]^1].num = e[adj[u][i]^1].num * (e[adj[u][j]].num + 1) % M;
				for (k = i / SIZE + 1; k <= (deg[u] - 1) / SIZE; k++) e[adj[u][i]^1].num = e[adj[u][i]^1].num * block[u][k] % M;
			} else {
				for (j = 0; j < deg[u]; j++) if (j != i) e[adj[u][i]^1].num = e[adj[u][i]^1].num * (e[adj[u][j]].num + 1) % M;
			}
		}
	}
	
	long long ans;
	for (u = 2; u <= N; u++) {
		ans = 1;
		for (i = 0; i < deg[u]; i++) ans = ans * (e[adj[u][i]].num + 1) % M;
		printf("%lld\n", ans);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 11880
#include<stdio.h>
int main(void)
{
    int n,m,count=0;
    scanf("%d%d",&n,&m);
    int h[n],a[m],b[m],trash[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&h[i]);
        trash[i] = 0;
    }
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        if(h[a[i]-1] < h[b[i]-1])
        {
            trash[a[i]-1] = 1;
        }
        if(h[a[i]-1] > h[b[i]-1])
        {
            trash[b[i]-1] = 1;
        }
        if(h[a[i]-1] == h[b[i]-1])
        {
            trash[a[i]-1] = 1;
            trash[b[i]-1] = 1;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(trash[i] == 0)
        {
            count++;
            //printf("%d\n",i+1);
        }
    }
    printf("%d",count);

}

Measured memory_bytes: 3288
#!/usr/bin/env python3
from itertools import*
s = input()
k = int(input())
t = [len(list(e)) for _, e in groupby(s)]
if len(set(s)) == 1:
    a = len(s) * k // 2
elif k > 1 and s[0] == s[-1]:
    p = sum(e // 2 for e in t[1:-1]) * k
    l, r = t[0], t[-1]
    q = (l + r) // 2 * ~-k + l // 2 + r // 2
    a = p + q
else:
    a = sum(e // 2 for e in t) * k
print(a)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int m = 26;
const int n = 365;
int c[m];
int s[n][m];
int last[m];
int d;

void calc(vl &t){
	ll score = 0;
	rep(i,d){
		score += s[i][t[i]-1];
		last[t[i]-1] = i+1;
		rep(j,m){
			score -= c[j] * (i+1 - last[j]);
		}
		cout << score << "\n";
	}
}

int main(){
	int m = 26;
    cin >> d;
	rep(i,m) cin >> c[i];
	rep(i,d){
		rep(j,m) cin >> s[i][j];
	}
	vl t(d); rep(i,d) cin >> t[i];
	calc(t);
}

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') f = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> Tp chkmax(Tp &x, Tp y) {return x > y ? x : x=y;}
template <typename Tp> Tp chkmin(Tp &x, Tp y) {return x < y ? x : x=y;}
template <typename Tp> Tp Max(Tp x, Tp y) {return x > y ? x : y;}
template <typename Tp> Tp Min(Tp x, Tp y) {return x < y ? x : y;}

const int MAXN = 200010;

LL sum = 0, ans = 0x3f3f3f3f3f3f3f3fLL;
int n, num[MAXN];

LL abs(LL x) {return x > 0 ? x : -x;}

int main()
{
	in(n);

	FOR(i, 1, n) in(num[i]), sum += num[i];

	LL tmp = 0;

	FOR(i, 1, n - 1) {
		tmp += num[i];
		chkmin(ans, abs(tmp - (sum - tmp)));
	}

	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int m, d;
    cin >> m >> d;
    int ans = 0;
    REP(i, 0, d + 1) {
        int a = i / 10;
        int b = i % 10;
        if (a >= 2 && b >= 2 && a * b <= m && 1 <= a * b) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
(loop :named n-loop :with n := (read)
      :do (loop :for j :upto n :with y := (read)
                :do (loop :for k :upto (- n j)
                          :if (= y (+ (* 10000 j) (* 5000 k) (* 1000 (- n j k))))
                            :do (format t "~A ~A ~A" j k (- n j k))
                            :and
                              :do (return-from n-loop))
                :finally (princ "-1 -1 -1")))

Measured memory_bytes: 13416
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.c
 * Author: Ivan
 *
 * Created on July 2, 2018, 3:17 PM
 */

#include <stdio.h>
#include <stdlib.h>
#define INFTY 1000000001
#define MAX_SIZE 500000
/*
 * 
 */

int Left[MAX_SIZE/2 + 2], Right[MAX_SIZE/2 + 2];
int count = 0;

void merge(int A[], int left, int mid, int right);
void mergeSort(int A[], int left, int right);

int main(int argc, char** argv) {
    int *A, n;
    scanf("%d", &n);
    A = (int *)malloc(sizeof(int) * n);
    
    for (int jx = 0; jx < n; ++jx) scanf("%d", &A[jx]);
    
    mergeSort(A, 0, n);
    
    for (int ix = 0; ix < n; ++ix)
    {
        if (ix) printf(" ");
        printf("%d", A[ix]);
    }
    printf("\n%d\n", count);
    
    return (EXIT_SUCCESS);
}

void merge(int A[], int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; ++i) Left[i] = A[left + i];
    for (int j = 0; j < n2; ++j) Right[j] = A[mid + j];
    Left[n1] = INFTY;
    Right[n2] = INFTY;
    int i = 0, j = 0;
    for (int k = left; k < right; ++k)
    {
        if (Left[i] <= Right[j])
        {
            A[k] = Left[i];
            i = i + 1;
        }
        else 
        { 
            A[k] = Right[j]; 
            j = j + 1;
        }
        count++;
    }
}

void mergeSort(int A[], int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}




Measured memory_bytes: 5604
from fractions import gcd
# from functools import reduce
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

n=int(input())

a=list(map(int,input().split()))

left=[0]*(n+1)
right=[0]*(n+1)

for i in range(n):
    left[i+1]=gcd(left[i],a[i])
    right[n-i-1]=gcd(right[n-i],a[n-i-1])

# print(left)
# print(right)
last=[0]*n

for i in range(n):
    last[i]=(gcd(left[i],right[i+1]))


print(max(last))

Measured memory_bytes: 16696
from collections import defaultdict
from bisect import bisect_left

def prime_factor(n):
    d = defaultdict(int)
    for i in range(2, n + 1):
        if i * i > n:
            break
            
        while n % i == 0:
            d[i] += 1
            n //= i
            
    if n != 1:
        d[n] += 1
            
    return d

N = int(input())
d = prime_factor(N)

x = [0] * 10 ** 5
x[0] = -1
for i in range(1, 10 ** 5):
    x[i] = x[i - 1] + i

ans = 0
for v in d.values():
    ans += bisect_left(x, v) - 1
print(ans)


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

int main() {
	int N, A;
  	cin >> N >> A;
  	int amari;
  	amari = N % 500;
  	if (amari <= A){
      cout << "Yes" << endl;
    }
  	else{
      cout << "No" << endl;
	  }
 
}

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

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;
bool isMultiple (string s, int base, int m) {
	ll temp = 0;
	for (int i=0; i<s.length(); i++) {
		temp = (temp*base+s[i]-'0')%m;
	}
	if (temp==0) {return true;}
	return false;
}
void solve()
{
	string s;
	cin>>s;
	int mod=2019;
	//vector<int>acc(size(s));
	int sum=0;
	int ten=1;
	//map<int,int>used;
	vector<int>tenpower(240,1);
	// 224=1; 223=0?
	rep(i,230){
		ten*=10;
		ten%=mod;
		/*if(i==224){
			cout<<ten<<endl;
		}*/
		tenpower[i+1]=ten;
	}
/*	rep(i,230){
		cout<<tenpower[i]<<" "<<i<<" "<<tenpower[i%224]<<endl;
	}*/
	reverse(all(s));
	vector<int>app(2020);
	ll ans=0;
	rep(i,size(s)){
		int tmp=s[i]-'0';
		tmp*=tenpower[i%224];
		sum+=tmp;
		sum%=mod;
		app[sum]++;
		if(sum==0){
			ans++;
		}
	}
	
	rep(i,2019){
		ans+=(ll)app[i]*(app[i]-1)/2;
	}
	cout<<ans<<endl;
}

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


Measured memory_bytes: 3792
a,b,k=list(map(int, input().split()))

DivList = []

for i in range(min(a,b)+1):
    if i ==0:
        continue
    if a % i == 0 and b%i ==0:
        DivList.append(i)
DivList.sort(reverse=True)
# print(DivList)
print(DivList[k-1])

Measured memory_bytes: 3060
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	string s; cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int dp[100005];
vector<int> bank;

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;cin >> N;
    
    bank.push_back(1);
    for(int i = 6;i<=279936;i*=6) bank.push_back(i);
    for(int i = 9;i<=531441;i*=9) bank.push_back(i);
    sort(bank.begin(),bank.end());
    for(int i = 0;i<=N;i++) dp[i] = 1000;
    dp[0] = 0;

    for(int i = 0;i<=N;i++){
        for(int j = 0;j<bank.size();j++){
            if(i+bank.at(j) <= N){
                dp[i+bank.at(j)] = min(dp[i+bank.at(j)],dp[i]+1);
            }
        }
    }
    cout << dp[N] << endl;
    
}


Measured memory_bytes: 3804
import java.util.Scanner;

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

	int x = scan.nextInt();
	int a = scan.nextInt();
	int b = scan.nextInt();

	if(Math.abs(x-a) > Math.abs(x-b)){
	    System.out.println('B');
	}else{
	    System.out.println('A');
	}
    }
}


Measured memory_bytes: 22608
n,m,s=map(int,input().split())
uvab=[list(map(int,input().split())) for _ in range(m)]
cd=[list(map(int,input().split())) for _ in range(n)]
g=[[] for _ in range(n)]
for u,v,a,b in uvab:
    u,v=u-1,v-1
    g[u].append([v,a,b])
    g[v].append([u,a,b])

#「現在いる頂点、現在持っている銀貨枚数」を頂点とし、ダイクストラ法でとく。
from heapq import heappop,heappush
inf=float('inf')
maxs=50*m
ans=[[inf]*(maxs+1) for _ in range(n)]
s=min(s,maxs)
todo=[[0,0,s]]
ans[0][s]=0
while todo:
    t,v,ss=heappop(todo)
    if ans[v][ss]<t:continue
    for nv,na,nb in g[v]:
        if na>ss:continue
        if ans[nv][ss-na]>t+nb:
            heappush(todo,[t+nb,nv,ss-na])
            ans[nv][ss-na]=t+nb
    c,d=cd[v]
    nss=min(ss+c,maxs)
    if ans[v][nss]>t+d:
        heappush(todo,[t+d,v,nss])
        ans[v][nss]=t+d
for i in range(1,n):
    print(min(ans[i]))


Measured memory_bytes: 127300
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0; i < n; i++) {
			h[i]=sc.nextInt();
		}
		boolean[] good = new boolean[n];
		for(int i = 0; i < n; i++) {
			good[i]=true;
		}
		for(int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(h[a-1] < h[b-1]) {
				good[a-1]=false;
			}
			else if(h[a-1] > h[b-1]) {
				good[b-1] = false;
			}
			else {
				good[a-1]=false;
				good[b-1] = false;
			}
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			//System.out.println(good[i]);
			if(good[i]==true) {
				count++;
			}
		}
		System.out.println(count);
	 }
}

Measured memory_bytes: 59804
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> C(N);
  int A,B;
  int z,count;
  
  for(int i = 0; i < N; i++){
    cin >> C.at(i);
  }
  
  for(int i = 0; i < N; i++){
    z = 0;
    count = 0;
    for(int j = 0; j < N; j++){
      if(z < C.at(j)){
        z = C.at(j);
        count = j;
      }
    }
     A = A + z;
     C.at(count) = 0;
    count = 0;
     z = 0;
    for(int k = 0; k < N; k++){
     if(z < C.at(k)){
       z = C.at(k);
       count = k;
      }
    }
     B = B + z;
     C.at(count) = 0;
    }

   cout << A - B << endl;
  
}

Measured memory_bytes: 3556
import math
a,b = map(int,input().split())

tax_8 = 0.08
tax_10 = 0.1

li = [99999999999]
for i in range(1,1010):
    temp = math.floor(i *tax_8)
    temp2 = math.floor(i*tax_10)
    if temp == a and temp2 == b:
        li.append(i)
li.sort()
if li[0] == 99999999999:
    print("-1")
else:
    print(li[0])

Measured memory_bytes: 3064
path = []
for _ in range(3):
    a, b = map(int, input().split())
    path.append((a, b))

def g(cur, lt, lp):
    if not lp or not lt:
        return not lp and not lt

    for nt in lt:
        if (cur, nt) in lp:
            lpc = lp.copy()
            lpc.remove((cur, nt))
            ltc = lt.copy()
            ltc.remove(nt)
            if g(nt, ltc, lpc):
                return True
        elif (nt, cur) in lp:
            lpc = lp.copy()
            lpc.remove((nt, cur))
            ltc = lt.copy()
            ltc.remove(nt)
            if g(nt, ltc, lpc):
                return True
    return False

def f():
    for i in range(1, 5):
        lt = list(range(1, 5))
        lt.remove(i)
        if g(i, lt, path):
            return True
    return False

print("YES" if f() else "NO")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/


struct Edge{
    long long to, cost;
    Edge(long t, long c){
        to = t;
        cost = c;
    }
};

class Bellman_Ford{
private:
    const long long Inf = 1LL << 50;
    vector<long long> dist;
    vector<vector<Edge> > adj;
public:
    Bellman_Ford(int v){
        dist = vector<long long>(v + 1);
        adj = vector<vector<Edge> >(v + 1);
        for(int i = 0; i < (int)dist.size(); i++)dist[i] = Inf;
    }

    void add_edge(int from, int to, int cost){
        adj[from].push_back(Edge(to, cost));
    }

    bool shortest_path(int s){
        dist[s] = 0;
        for(int k = 0; k < (int)dist.size(); k++){
            for(int i = 0; i < (int)dist.size(); i++){
                for(int  j = 0; j < (int)adj[i].size(); j++){                        
                    Edge e = adj[i][j];
                    if(dist[e.to] > dist[i] + e.cost && dist[i] != Inf){
                        dist[e.to] = dist[i] + e.cost;
                    }
                }
            }
        }
        return true;
    }

    long long get_distance(int x){
        return dist[x];
    }

    void DEBUG(){
        for(int i = 0; i < (int)dist.size(); i++){
            cout << 1 << " --> " << i << " = " << dist[i] << endl;
        }
    }
};



int main(){
    int n, m, a, b, c;
    cin >> n >> m;
    Bellman_Ford bel(n);
    rep(i, m){
        cin >> a >> b >> c;
        bel.add_edge(a, b, -c);
    }
    bel.shortest_path(1);
    ll first = bel.get_distance(n);
    bel.shortest_path(1);
    ll second = bel.get_distance(n);
    if(first == second){
        cout << -bel.get_distance(n) << endl;
    }else{
        cout << "inf" << endl;
    }
    return 0;
}


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

signed main() {
    int n;
    cin >> n;
    string c(n, '0');
    function<void(int,int)> dfs;
    dfs = [&](int x, int v) {
        if (x == n) cout << c << endl;
        else {
            for(int i = 0; i != v; i++) {
                c[x] = 'a'+i;
                dfs(x+1,v+(i+1==v));
            }
        }
    };
    dfs(0,1);
}


Measured memory_bytes: 1536
program main
implicit none
character(len=10**5) :: s
integer :: l,i,a,b,nc

read(*,*) s
l = len_trim(s)

nc = 0
read(s(1:1),*) a
do i = 2, l
   read(s(i:i),*) b
   if(a/=b) then
      nc = nc+1
   end if
end do
write(*,'(i0)') min(nc,l-nc)*2

end program main


Measured memory_bytes: 1084
/*
ID: arunesh2
TASK: ride
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() 
{
    /*ofstream fout ("ride.out");
    ifstream fin ("ride.in");*/
    int n,x;cin>>n>>x;
    int l[n+1];
    l[0]=0;
    for(int i=1;i<=n;i++)
    {
       cin>>l[i];
    }
    
    for(int i=2;i<n+1;i++)
        l[i]=l[i]+l[i-1];
    int count=0;
    for(int i=0;i<=n;i++)
    {
        if(l[i]<=x)
            count++;
    }
    cout<<count<<"\n";
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i

g = {}
(n - 1).times do
  a, b, c = gets.chomp.split(' ').map(&:to_i)
  g[a] ||= {}
  g[b] ||= {}
  g[a][b] = c
  g[b][a] = c
end

q, k = gets.chomp.split(' ').map(&:to_i)

d = {}
d[k] = 0
st = [k]

loop do
  break if st.empty?
  v = st.pop
  dr = d[v]
  g[v].keys.each do |i|
    unless d[i]
      d[i] = dr + g[v][i]
      st.push(i)
    end
  end
end

q.times do
  x, y = gets.chomp.split(' ').map(&:to_i)
  puts d[x] + d[y]
end


Measured memory_bytes: 51708
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>


using namespace std;


int main(){
    int N;
    long long K;
    cin >> N >> K;
    int a, b;
    pair<int, int> p;
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pp;
    for (int i = 0; i < N; i++){
        cin >> a >> b;
        p.first = a;
        p.second = b;
        pp.push(p);
    }
    while(1){
        K = K-pp.top().second;
        if (K < 1) break;
        else pp.pop();
    }
    cout << pp.top().first << endl;

    return 0;
}

Measured memory_bytes: 1400
import bisect
n,m=(int(i) for i in input().split())
a=[[] for _ in range(n)]
s=[]

for _ in range(m):
    x,c=(int(i) for i in input().split())
    a[x-1].append(c)
    s.append((x,c))

[a[i].sort() for i in range(n)]

for x,c in s:
    print("{:06}{:06}".format(x, bisect.bisect_left(a[x-1],c)+1))

Measured memory_bytes: 29684
using System;
using System.IO;
using System.Collections.Generic;
using System.Numerics;

namespace abc140
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc140B();
        }

        public static void solve_abc140B()
        {
            int n = Convert.ToInt32(Console.ReadLine());            
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] c = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            
            int sum = 0;
            int prev = n;
            for (int i = 0; i < n; i++)
            {
                sum += b[a[i] - 1];
                if (a[i] - prev == 1)
                {
                    sum += c[prev - 1];
                }
                prev = a[i];
            }

            Console.WriteLine(sum);
        }
        public static void solve_abc140A()
        {
            int n = Convert.ToInt32(Console.ReadLine());            

            Console.WriteLine(Math.Pow(n, 3));
        }
    }
}


Measured memory_bytes: 11220
let rec solve = function
  | 'm' :: 'a' :: 'e' :: 'r' :: 'd' :: s
  | 'e' :: 's' :: 'a' :: 'r' :: 'e' :: s
  | 'r' :: 'e' :: 's' :: 'a' :: 'r' :: 'e' :: s
  | 'r' :: 'e' :: 'm' :: 'a' :: 'e' :: 'r' :: 'd' :: s -> solve s
  | [] -> true
  | _ -> false

let () =
  let s = read_line () in
  Array.init (String.length s) (fun i -> s.[i])
  |> Array.to_list
  |> List.rev
  |> solve
  |> (function true -> "YES" | false -> "NO")
  |> print_endline

Measured memory_bytes: 7424
k = int(input())

lunlun = set([1,2,3,4,5,6,7,8,9])

for i in range(9):
    for x in list(lunlun):
        iti = int(str(x)[-1])
        l = x*10 + (iti-1)
        m = x*10 + (iti+0)
        n = x*10 + (iti+1)

        lunlun.add(m)
        if iti != 9:
            lunlun.add(n)
        if iti != 0:
            lunlun.add(l)

print(sorted(lunlun)[k-1])

Measured memory_bytes: 28428
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int N, M, Q;
int a[55], b[55], c[55], d[55];

int A[10];
int ans = -1;

void calc() {
    int cur = 0;
    REP(i, Q) {
        if (A[b[i]] - A[a[i]] == c[i]) {
            cur += d[i];
        }
    }
    chmax(ans, cur);
}

void dfs(int cur) {
    if (cur == N) {
        calc();
        return;
    }

    const auto prev = cur == 0 ? 1 : A[cur - 1];
    FOR(i, prev, M + 1) {
        A[cur] = i;
        dfs(cur + 1);
        A[cur] = 0;
    }
}

int main(void) {
    cin >> N >> M >> Q;
    REP(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;b[i]--;
    }

    dfs(0);

    cout << ans << endl;
}


Measured memory_bytes: 3608
n = int(input())

dp = [0] * (n + 1)
for i in range(n):
     if i in range(5):
          dp[i+1] = i + 1
     else:
          j = 1
          k = 1
          a = [100001]
          b = [100001]
          while i + 1 - 6**j >= 0:
              a += [dp[i + 1 - 6**j]]
              j += 1
          while i + 1 - 9**k >= 0:
              b += [dp[i + 1 - 9**k]]
              k += 1
          dp[i + 1] = min(dp[i],min(a),min(b)) + 1
print(dp[n])



Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  int n,d;cin>>n>>d;
  cout<<(2*d+n)/(2*d+1)<<endl;
}

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

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

    int sum = 0;
    for (int i=0; i<2; i++) {
        if (A>B) {
            sum += A;
            A--;
        } else {
            sum += B;
            B--;
        }
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>

using namespace std;

#define ll long long
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)

int main()
{
    int n;
    
    cin >> n;
    vector<int> l(n);
    rep(i,n)
    {
        cin >> l[i];
    }
    sort(l.begin(),l.end(),greater<int>());
    ll counter = 0;
    
    for (int i = 0; i < n-1; i++)
    {
        int j,k;
        j = i+1;
        k = n-1;
        while(j<k)
        {
            if (l[i]<l[j]+l[k])
            {
                counter+=k-j;
                j++;
            }else
            {
                k--;
            }
            //cout << counter << endl;
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 256