akhauriyash/Code-Regression huggingface dataset:
def dfs(N, AB):
    status = [-1] * N
    for i in range(N):
        if status[i] == 1:
            continue
        stack = [i]
        status[i] = 0
        while stack:
            v = stack[-1]
            if AB[v]:
                n = AB[v].pop()
                if status[n] == -1:
                    stack.append(n)
                    status[n] = 0
                elif status[n] == 0:
                    idx = stack.index(n)
                    cycle = stack[idx:]
                    
                    return cycle
            else:                  
                status[v] = 1
                stack.pop()

    return False


def find_smaller_cycle(cycle, AB):
    i = 0
    while i < len(cycle):
        v = cycle[i]
        if AB[v]:
            n = AB[v].pop()
            if n in cycle:
                r = cycle.index(n)
                if i < r:
                    cycle = cycle[:i+1] + cycle[r:]
                else:
                    cycle = cycle[r:i+1]
                i = cycle.index(v)
        else:
            i += 1
            
    return cycle


N, M = [int(i) for i in input().split()]

AB = [[] for _ in range(N)]
for _ in range(M):
    A, B = [int(i) - 1 for i in input().split()]
    AB[A].append(B)
                      
cycle = dfs(N, AB)
if not cycle:
    print(-1)
else:
    cycle = find_smaller_cycle(cycle, AB)
            
    print(len(cycle))
    for v in cycle:
        print(v + 1)

Measured memory_bytes: 3316
sx, sy, tx, ty = (int(i) for i in input().split())
s=""
x = sx
y = sy
while y!=ty:
    y+=1
    s+="U"
while x!=tx:
    x+=1
    s+="R"
while y!=sy:
    y-=1
    s+="D"
while x!=sx:
    x-=1
    s+="L"
x-=1
s+="L"
while y!=ty+1:
    y+=1
    s+="U"
while x!=tx:
    x+=1
    s+="R"
y-=1
s+="D"
x+=1
s+="R"
while y!=sy-1:
    y-=1
    s+="D"
while x!=sx:
    x-=1
    s+="L"
s+=("U")
print(s)

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


int main() {

  int N;
  int digit;
  int tmp;
  int d = 10;
  int d2 = 1;
  int digitsum;
  int syo;
  int judge;

  cin >> N;
  tmp = N;
  judge = N;

  while(tmp != 0){
    tmp /= 10;
    digit += 1;

  }

  rep(i,digit){
    syo = N % d;
    digitsum += syo / d2;
    N = N - syo;
    d *= 10;
    d2 *= 10;
    syo = 0;
  }

  if(judge % digitsum == 0){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
using namespace std;
int d[1000][1000], sx, sy;
char s[1000][1000];
int h,w,n;
int k, l;
 
int bfs(int,int,int,int);
 
int main(){
  int result = 0;
  int x[10], y[10], v;
  scanf("%d %d %d", &h, &w, &n);
  for(k = 0 ; k < h ; k++){
      scanf("%s",s[k]);
    }
  for( k = 0 ; k < h ; k++ ){
    for( l = 0 ; l < w ; l++){
      if(s[k][l] == 'S'){
    x[0] = l; y[0] = k;
      }
      if('1' <= s[k][l] && s[k][l] <= '9'){
    v = s[k][l]-'1'+1;
    x[v] = l; y[v] = k;
      }
    }
  }
  for (k = 1 ; k <= n ; k++){
    
    result += bfs(x[k-1],y[k-1],x[k],y[k]);
  }
  printf("%d\n", result);
  return 0;
}
 
int bfs(int sx, int sy, int gx, int gy){
  queue<int> Q;
  int i, j;
  int dx[4]={0, 1, 0, -1};
  int dy[4]={1, 0, -1, 0};
   
 
  for( i =  0 ; i < h ; i++ ){
    for( j = 0 ; j < w ; j++ ){
      d[i][j] = 1000000;
    }
  }
 
  Q.push(sy*w+sx);
  d[sy][sx]=0; /*??????????????°???????????????*/
 
  while( !Q.empty() ){
    int u = Q.front(); Q.pop();
    int pi = u/w;
    int pj = u%w;
    if( pi == gy && pj == gx )return d[gy][gx];
    for ( int r = 0; r < 4; r++ ){
      int ni = pi + dy[r];
      int nj = pj + dx[r];
      if ( ni < 0 || nj < 0 || ni >= h || nj >= w ) continue;
      if ( s[ni][nj] == 'X' ) continue;
      if( d[ni][nj] > d[pi][pj]+1 ){
      d[ni][nj] = d[pi][pj] + 1;
      Q.push( ni * w + nj );
      }
 
    }
 
 
  }
  //  printf("%d\n",u);
  return -1;
}

Measured memory_bytes: 5932
n, a, b = gets.chomp.split(" ").map(&:to_i);
xs = gets.chomp.split(" ").map(&:to_i);

count = 0
xs.each_with_index  do |x, i|
  next if i == 0
  if (xs[i] - xs[i-1]) * a > b
    count += b
  else
    count += (xs[i] - xs[i-1]) * a
  end
end

puts count


Measured memory_bytes: 9476
s = input()
ans_list = []

for i in range(len(s)):
  if(s[i] != 'B'):
    ans_list.append(s[i])
  elif(s[i] == 'B' and len(ans_list) != 0):
    ans_list.pop()
    
ans_str = ''.join(ans_list)

print(ans_str)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <map>

int main()
{
	int j = 0; int l = 0; int ii = 0;
	std::string k;
	std::cin >> k;
	for (int i = 0; i < k.length(); i++)
		if (k[i] == 'A' || k[i] == 'C' || k[i] == 'T' || k[i] == 'G') {
			j++;
		}
		else
		{
			if (l < j)
				l = j; 
			j = 0;
		}
	l < j ? std::cout << j : std::cout << l;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a;a%=b;return gcd(b,a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
ll sum[10000001];
void solveforthiscase(const int & test)
{
cin>>n;
ll ans=0;
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j+=i)
sum[j]++;
for(int i=1;i<=n;i++)
ans=ans+sum[i]*i;
cout<<ans;





return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE 
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout); 
    // freopen("error.txt", "w", stderr); 
    // #endif 
    clock_t start, end;
    start = clock(); 
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    solveforthiscase(i);
    end = clock(); 
    long double t_t = (long double)(end - start) /(long double)(CLOCKS_PER_SEC); 
    cerr << (long double)t_t*1000<< " ms ";
}


Measured memory_bytes: 81932
#include<iostream>
using namespace std;
int main(){
	int a,b,w;
	cin>>w>>a>>b;
	b-=a;
	if(b<0){
		b=0-b;
	}
	b-=w;
	if(b<=0){
		cout<<0;
		return 0;
	}
	cout<<b;
	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
# define MOD 1000000007
typedef long long ll;
int dp[10000][101][2];
int D, n;
string K;
int solve(int index, int sum, int tight){
    if(dp[index][sum][tight] != -1) return dp[index][sum][tight];
    int ans = 0;
    int limit = 9;
    if(tight) limit = K[index] - '0';
    if(index == n-1){
        for(int i=0;i<=limit;i++){
            if(i%D == sum){
                ans++;
            }
        }
        return ans;
    }
    for(int i=0;i<=limit;i++){
        if(tight == 1 and i == limit) ans = (ans + solve(index + 1, (D + sum - i%D)%D, 1))%MOD;
        else ans = (ans + solve(index + 1, (D + sum - i%D)%D, 0))%MOD;
    }
    return dp[index][sum][tight] = ans;
}
int main(){
	cin>>K>>D;
	n = K.length(); 
	memset(dp, -1, sizeof(dp));
	int ans = (MOD + solve(0, 0, 1) - 1)%MOD; // for 0%D
	cout<<ans;
	return 0;
}

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int a,b;
    string s;
	cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ ) {
    if ( A[j] <= x ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i + 1;
}

int main() {
  int i, q;

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

  q = partition(0, n - 1);

  for ( i = 0; i < n; i++ ) {
    if ( i ) printf(" ");
    if ( i == q ) printf("[");
    printf("%d", A[i]);
    if ( i == q ) printf("]");
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 2960
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, m = [int(item) for item in input().split()]
sc = []
for _ in range(m):
    s, c = [int(item) for item in input().split()]
    sc.append((s, str(c)))

if n == 1:
    for i in range(10):
        target = str(i)
        ok = True
        for s, c in sc:
            if target[s-1] != c:
                ok = False
        if ok:
            print(i)
            exit()
else:
    for i in range(10**(n-1), 10**n):
        target = str(i)
        ok = True
        for s, c in sc:
            if target[s-1] != c:
                ok = False
        if ok:
            print(i)
            exit()

print(-1)

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vi = vector<int>;
using vs = vector<string>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repp(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define repd(i, n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

const ll M = 1e9 + 7;



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

	ll n, m = M;
	cin >> n;

	ll p = 1, pr = 1, prd = 1;
	rep(i, n) {
		p *= 10;
		p %= m;
		pr *= 9;
		pr %= m;
		prd *= 8;
		prd %= m;
	}

	ll answer = (p - 2 * pr + prd) % m;
	if(answer < 0) answer += m;

	cout << answer << endl;
}

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

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  int nbEnt[n], plc[n];
  for (int i = 0; i < n; ++i)
  {
    nbEnt[i] = 0;
    plc[i] = 0;
  }
  vector<int> adjas[n];
  for (int i = 0; i < m; ++i)
  {
    int x, y;
    cin >> x >> y;
    --x; --y;
    adjas[x].push_back(y);
    nbEnt[y]++;
  }
  vector<int> next;
  for (int i = 0; i < n; ++i)
    if (nbEnt[i] == 0)
      next.push_back(i);
  int best = 0;
  for (int i = 0; i < n; ++i)
  {
    int act = next[i];
    for (int j = 0; j < adjas[act].size(); ++j)
    {
      if (nbEnt[adjas[act][j]] == 0)
	continue;
      plc[adjas[act][j]] = max(plc[adjas[act][j]], plc[act] + 1);
      best = max(best, plc[adjas[act][j]]);
      nbEnt[adjas[act][j]]--;
      if (nbEnt[adjas[act][j]] == 0)
	next.push_back(adjas[act][j]);
    }
  }
  cout << best << '\n';
}


Measured memory_bytes: 7164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,n-2) {
    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()

n = len(s)

ans = True
if n % 2 == 0:
    for i in range(n//2):
        if s[2*i] == 'L':
            ans = False
            break
        if s[2*i+1] == 'R':
            ans = False
            break
else:
    for i in range(n//2):
        if s[2*i] == 'L':
            ans = False
            break
        if s[2*i+1] == 'R':
            ans = False
            break
    else:
        if s[-1] == 'L':
            ans = False

if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
// ABC168D
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
const int INF=1001001001;
vector<int> to[100005];
int main() {
	int n,m;

	cin>>n>>m;
	rep(i,m){
		int a,b;
		cin >>a>>b;
		--a;--b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	queue<int>q;
	vector<int>dist(n,INF);
	vector<int>pre(n,-1);
	dist[0]=0;
	q.push(0);
	while (!q.empty()){
		int v=q.front();q.pop();
		for (int u:to[v]){
			if (dist[u] !=INF) continue;
			dist[u]=dist[v]+1;
			pre[u]=v;
			q.push(u);
		}
	}
	cout << "Yes" << endl;
	rep(i,n){
		if (i==0) continue;
		int ans=pre[i];
		++ans;
		cout <<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 10640
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	cnt := make(map[int]int)

	for _, num := range a {
		if cnt[num] == 1 {
			fmt.Println("NO")
			return
		} else {
			cnt[num] = 1
		}
	}
	fmt.Println("YES")
}


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

int main() {
	double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	x2 -= x1; y2 -= y1;
	printf("%.7lf\n", sqrt(x2*x2 + y2*y2));
}

Measured memory_bytes: 3268
import java.util.*;
public class Main{
 	public static void main(String[] args){
      Scanner sc=new Scanner(System.in);
      int a,b;
      a=sc.nextInt();
      b=sc.nextInt();
      if(Math.abs(a-b)>1){
      System.out.println(":(");
        return;
      }
       System.out.println("Yay!");
    }
  
  
  
  
  
}

Measured memory_bytes: 21844
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int s = sumDigits(N);
    if(N %s == 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
  public static int sumDigits(int n){
    int sum = 0;
    while(n!=0){
      sum += n %10;
      n /= 10;
    }
    return sum;
  }
}


Measured memory_bytes: 20948
/*input
1000000000 1 1
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = unsigned long long;
using ld = long double;
using pii = pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=1e18;
const int INF=1e6+1;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    ll a,b,c;
    cin>>a>>b>>c;
    if(c<=(a+b)){
        cout<<"No";
        return 0;
    }
    if(4LL*(a*b)<(c-b-a)*(c-b-a)){
        cout<<"Yes";

    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
 		Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int k = scan.nextInt();
      	int [] input = new int[n];
      	for(int i = 0; i < n; i++){ input[i] = scan.nextInt();}
      	scan.close();
      	System.out.println(solve(k, input));
	}
  
  private static int solve(int k, int[] input){
    if(input.length == 0) return 0;
    int[] dp = new int[input.length];
    Arrays.fill(dp, Integer.MAX_VALUE);
    dp[0] = 0;
    for(int i = 1; i < dp.length; i++){
    	for(int j = 0; j < k && (j + i < dp.length); j++){
          dp[i + j] = Math.min(dp[i+j], Math.abs(input[i-1] - input[i+j]) + dp[i-1]);
        }      
    }
    return dp[dp.length -1];
  }
}

Measured memory_bytes: 52056
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var C = cin.ReadInt;
            var X = cin.ReadInt;

            var cnt = 0;

            for (int i = 0; i <= A; ++i)
                for (int j = 0; j <= B; ++j)
                    for (int k = 0; k <= C; ++k)
                        if (500 * i + 100 * j + 50 * k == X)
                            ++cnt;

            WriteLine(cnt);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11220
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();

        x = x-z;
        System.out.println(x/(y+z));

    }
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

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

int main(){
	int n[4], x=0 , y=0;

	cin>>n[0]>>n[1]>>n[2];

	for(int i=0; i < 3; i++){
		if(n[i] > x){
			x = n[i];
		}
	}
	y = n[0] + n[1] + n[2] - x + (x*10);
	cout<<y<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Van Hanh Pham (skyvn97)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] values = IOUtils.readIntArray(in, n, 0);
            long res = 0;
            int cost = 1;
            for (int i = 0; i < n; i++) {
                int canBuy = (values[i] - 1) / cost;
                res += canBuy;
                int afterBuy = canBuy == 0 ? values[i] : 1;
                cost = Math.max(cost, afterBuy + 1);
            }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String nextString() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }

    static class IOUtils {
        public static int[] readIntArray(InputReader in, int size, int start) {
            int[] res = new int[start + size];
            for (int i = start; i < start + size; i++)
                res[i] = in.nextInt();
            return res;
        }

    }
}



Measured memory_bytes: 23396
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;
typedef pair<int,int> pii;
int N,M;

bool myCompare(pii A, pii B){return A.second < B.second;}

int main(){
  scanf("%d %d", &N, &M);

  vector<pii> v(M);
  for(int i=0; i<M; i++){
    int a,b; scanf("%d %d", &a, &b);
    v[i] = make_pair(a,b);
  }
  
  sort(v.begin(), v.end(), myCompare);
  
  int ans=0;
  int num_broken_bridge=0;
  for(int i=0; i<M; i++){
    if(v[i].first > num_broken_bridge){
      num_broken_bridge = v[i].second-1;
      ans++;
    }
  }
  printf("%d\n", ans);
}

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

int main()
{
  int N;
  cin >> N;

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


Measured memory_bytes: 3544
def main():
    from sys import exit
    from builtins import ord, range
    s = input()
    t = input()
    tset = set(t)
    slen = len(s)
    aord = ord('a')
    if len(tset - set(s)) != 0:
        print(-1)
        exit()
    s2t = [i - aord for i in (s + s).encode('ascii')]
    lut = [[-1 for _ in range(slen)] for _ in range(26)]
    for c in tset:
        b = ord(c) - aord
        j = 0
        for i in range(slen * 2 - 1, -1, -1):
            if s2t[i] == b:
                j = 0
            else:
                j += 1
            if i < slen:
                lut[b][i] = j
    p = 0
    for c in t:
        b = ord(c) - aord
        p += lut[b][p % slen] + 1
    print(p)


main()


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> p(n);
    rep (i, n) cin >> p[i];
    int res = 1e9;
    FOR (i, 1, 101) {
        int tmp = 0;
        rep (j, n) {
            int d = (i - p[j]) * (i - p[j]);
            tmp += d;
        }
        res = min(res, tmp);
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
"""
A - Frog 1
"""
class DP():
    def __init__(self):
        pass
    
    def chmin(self, a, b):
        if a>b:
            return b
        else:
            return a
        
    def chmax(self):
        if a<b:
            return b
        else:
            return a
        
N = int(input())
# K = int(input())
cost_list = list(map(int, input().split()))
# cost_list = [2, 9, 4, 5, 1, 6, 10]
# N = len(cost_list)
K = 2

dpfun = DP()
# dp = np.ones(N) * np.inf
INF = 2**60
dp = [INF]*N
" 初期条件 "
dp[0] = 0

for i in range(1, N, 1):
    if i==1:    
        dp[i] = dpfun.chmin(dp[i], dp[i-1] + abs(cost_list[i] - cost_list[i-1]))
    else:
        for j in range(1, K+1, 1):
            dp[i] = dpfun.chmin(dp[i], dp[i-j] + abs(cost_list[i] - cost_list[i-j]))
print(int(dp[-1]))

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

#define Dark '0'
#define White '1'
#define Keep 0
#define Cut 1
int H,W,K,ans=1e9;
char g[10][1001];
int main()
{
//	freopen("1.txt","r",stdin);
	cin>>H>>W>>K;
	ffor(i,H)cin>>g[i];
	ffor(i,1<<(H-1))
	{
		int cnt=0;
		cnt+=__builtin_popcount(i);
		vector<int>split;
		ffor(j,H)
		{
			if((i>>j)&1)
			{
				split.push_back(j);
			}
		}
		if(split.empty())split.push_back(-1);
		vector<vector<int>>p(H);
		ffor(k,H)p[k]=vector<int>(W);
		int id=0;
		ffor(k,H)
		{
			ffor(j,W)
			{
				p[id][j]+=g[k][j]=='1';
			}
			if(split[id]==k)id++;
		}
//		for(int j=0; j<=id; j++) {
//			for(int k=0; k<W; k++)
//				cout<<p[j][k]<<' ';
//			cout<<endl;
//		}
//		cout<<endl;
		vector<int>sum(id+1);
		for(int j=0; j<W; j++)
		{
			for(int k=0; k<=id; k++)
			{
				if(p[k][j]>K)
				{
					goto brk;
				}
			}
			for(int k=0; k<=id; k++)
			{
				sum[k]+=p[k][j];
				if(sum[k]>K)
				{
					for(int q=0; q<=id; q++)sum[q]=p[q][j];
//					cout<<"At:"<<j<<endl;
					cnt++;
					break;
				}
			}
		}
//		cout<<"PopCount:"<<__builtin_popcount(i)<<endl;
//		cout<<"Cnt:"<<cnt<<endl;
		ans=min(ans,cnt);
brk:
		;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define REP(i,a,b) for(int i = (int)(a); (i) < (int)(b); i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;

int main(){
	int n;
	cin >> n;
	ll res = 0LL;
	
	string s;
	ll m = 0LL;
	ll a = 0LL;
	ll r = 0LL;
	ll c = 0LL;
	ll h = 0LL;
	rep(i,n){
		cin >> s;
		if (s[0] == 'M') m++;
		if (s[0] == 'A') a++;
		if (s[0] == 'R') r++;
		if (s[0] == 'C') c++;
		if (s[0] == 'H') h++;
	}

	ll D[5] = {m,a,r,c,h};
	int P[10] = {0,0,0,0,0,0,1,1,1,2};
	int Q[10] = {1,1,1,2,2,3,2,2,3,3};
	int R[10] = {2,3,4,3,4,4,3,4,4,4};
	rep(j,10){ res += D[P[j]]*D[Q[j]]*D[R[j]]; }
	cout << res << endl;
	return 0;
}

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

using namespace std;

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

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

bool dp[125252];

int main(){
    int x;
    cin>>x;
    dp[0] = true;
    REP(j,6){
        int v = 100 + j;
        REP(i,125000){
            if(dp[i])dp[i+v]=true;
        }
    }
    cout << dp[x] << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll s = 0;
	for (int i = 0; i < n; i++) {
		s ^= a[i];
	}
	ll ans = s;
	for (int i = 0; i < n; i++) {
		a[i] &= ~s;
	}

	int r = 0;
	vector<int> top(n);
	for (int i = 60; i >= 0; i--) {
		int j = r;
		for (; j < n; j++) {
			if(a[j] >> i & 1) {
				swap(a[r], a[j]);
				break;
			}
		}
		if (j == n) {
			continue;
		}
		top[r] = i;
		for (int k = 0; k < n; k++) {
			if (r == k) {
				continue;
			}
			if (a[k] >> i & 1) {
				a[k] ^= a[r];
			}
		}
		r++;
	}

	ll x = 0;
	for (int i = 60; i >= 0; i--) {
		ll nx = x | (1ll << i);
		ll b = nx;
		for (int j = 0; j < r; j++) {
			if (b >> top[j] & 1) {
				b ^= a[j];
			}
		}
		if ((b & nx) == 0) {
			x = nx;
		}
	}
	ans += x * 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include <string.h>
#include <algorithm>
#include <string>
#include <math.h>
typedef long long ll;
using namespace std;

double gcd( double m, double n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
    double p=0;
	// ユークリッドの方法
	while( m > n )
	{
        m = m/2;
        p+=1;
	}
	return p;
}//gcd

int main()
{
    int a[100],n,h=0,l=0,f=0,b=0,ans;
    memset(a,0,sizeof(a));
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++)
    {
        if(h<=l)
        {
            h+=a[f];
            f++;
        }else
        {
            l+=a[n-1-b];
            b++;
        }
    }
    if(h >= l)
    {
        ans = h-l;
    }
    else
    {
        ans = l-h;
    }
    
    cout << ans << endl;
 




    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, A;
  cin >> H >> A;
  if(H%A==0) cout << H/A;
  else cout << H/A+1;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int q,n;
bool f[1111111];
int main(void){
  cin >> q;
  for(int k = 0; k < q; k++){
    int c = 0;
    memset(f,false,sizeof(f));
    cin >> n;
    while(n > 9){
      if(f[n]){
	c = -1;
	break;
      }
      f[n] = true;
      c++;
      int best = 0;
      for(int i = 10; i <= 1000000; i*=10){
	best = max(best,(n/i)*(n%i));
      }
      n = best;
    }
    cout << c << endl;
  }
}

Measured memory_bytes: 2256
use std::io::stdin;
fn get_string() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

macro_rules! input {
    ($single:ty) => ( get_string().parse::<$single>().unwrap() );
    ($plural:ty,) => ({
        let line = get_string();
        line.split_whitespace().map(|v| v.parse::<$plural>().unwrap()).collect::<Vec<$plural>>()
    });
    ($($plural:ty),+) => ({
        let line = get_string();
        let mut iter = line.split_whitespace();
        ($(iter.next().unwrap().parse::<$plural>().unwrap()),+)
    });
    ($single:ty; $times:expr) => ( (0..$times).map(|_| input!($single)).collect::<Vec<$single>>() );
    ($($plural:ty),+; $times:expr) => ( (0..$times).map(|_| input!($($plural),+)).collect::<Vec<($($plural),+)>>() );
}

#[allow(dead_code)]
fn get_value<T: std::str::FromStr>() -> T {
    get_string().parse().ok().unwrap()
}
#[allow(dead_code)]
fn get_values_for<T: std::str::FromStr>(times: u64) -> Vec<T> {
    (0..times).map(|_| get_value()).collect()
}
#[allow(dead_code)]
fn get_vector<T: std::str::FromStr>() -> Vec<T> {
    get_string()
        .split_whitespace()
        .map(|v| v.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn get_vectors_for<T: std::str::FromStr>(times: u64) -> Vec<Vec<T>> {
    (0..times).map(|_| get_vector()).collect()
}

fn main() {
    let n = input!(String);
    let s = n.chars().fold(0, |i, v| i + v.to_digit(10).unwrap());
    if n.parse::<u32>().ok().unwrap() % s == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

using namespace std;

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

	if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]){

			cout << "Bad"<< endl;
		}else{
			cout << "Good" << endl;
		}
		return 0;

}


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

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

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

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

    cout << max - min << endl;
}

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

int main(){
	int x,y;

	while(1){
		cin >> x >> y;
		if( x==0 && y==0 ) break;
		if( x>y ){
			cout << y << " " << x << "\n";
		}else{
			cout << x << " " << y << "\n";
		}
	}

	return 0;
}

Measured memory_bytes: 1160
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const ll inf = numeric_limits<ll>::max();

ll solve() {
    ll N, X, D;
    cin >> N >> X >> D;

    if(D == 0) {
        if(X) return N + 1;
        else return 1;
    }

    ll ans = 0;
    map<ll, V<pair<ll, PLL>>> rng;
    for(ll k = 0; k <= N; k++) {
        ll x = k * X;
        ll l = k * (k - 1) / 2;
        ll r = k * ((N - 1) + (N - 1 - (k - 1))) / 2;
        rng[abs(x) % abs(D)].emplace_back(x, PLL(l, r));
    }

    for(auto &&ele : rng) {
        V<PLL> rngs;
        for(auto e : ele.second) {
            ll x;
            PLL pll;
            tie(x, pll) = e;
            ll l, r;
            tie(l, r) = pll;
            ll ld = x + l * D;
            ll rd = x + r * D;
            rngs.emplace_back(min(ld, rd), max(ld, rd));
        }

        sort(ALL(rngs));
        DEBUG(rngs);
        rngs.emplace_back(inf, inf);
        ll l, r;
        tie(l, r) = rngs[0];
        for(ll i = 1; i < rngs.size(); i++) {
            ll nl, nr;
            tie(nl, nr) = rngs[i];
            if(nl <= r) {
                chmax(r, nr);
                continue;
            } else {
                ans += (r - l) / abs(D) + 1;
                l = nl;
                r = nr;
            }
        }
    }

    return ans;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 24192
n, q = map(int, input().split())
s = str(input())
cum = [0]*n
for i in range(n):
    if i == 0:
        continue
    if s[i-1] == 'A' and s[i] == 'C':
        cum[i] = cum[i-1]+1
    else:
        cum[i] = cum[i-1]
#print(cum)

for i in range(q):
    l, r = map(int, input().split())
    l, r = l-1, r-1
    print(cum[r]-cum[l])

Measured memory_bytes: 52568
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, A, B = LI()

    print(min(A, B), max(A + B - N, 0))

if __name__ == '__main__':
    resolve()


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

int main(){
	int n;
	cin >> n;
	vector<int> mo(n+1);
	vector<int> yu(n);
	rep(i, n+1){
    	cin >> mo.at(i);
    }
	rep(i, n){
    	cin >> yu.at(i);
    }
	ll cou = 0;
	for(int i=0; i<n; i++){
    	if(mo.at(i) - yu.at(i) >= 0){
        	cou += yu.at(i);
        	yu.at(i) = 0;
        }else{
        	cou += mo.at(i);
        	yu.at(i) -= mo.at(i);
        }
    	if(mo.at(i+1) - yu.at(i) >= 0){
        	cou += yu.at(i);
        	mo.at(i+1) -= yu.at(i);
        }else{
        	cou += mo.at(i+1);
        	mo.at(i+1) = 0;
        }
    }
	cout << cou << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if(a < b)swap(a,b);
  long long int r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
}
int main(){
  long long int N;
  cin >> N;
  long long int x[N+1],b[N];
  cin >> x[0];
  for (int i=1;i<N+1;i++)cin >> x[i];
  sort(x,x+N+1);
  for (int i=0;i<N;i++)b[i]=x[i+1]-x[i];
  long long int ans=b[0];
  for (int i=1;i<N;i++)ans=gcd(ans,b[i]);
  cout << ans<< endl;
}

Measured memory_bytes: 1920
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;

int main(void)
{
	int n,i,j;
	long long yaku,bai,x,a,b,ama,t[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%lld",&t[i]);
	x=1;
	for(i=0;i<n;i++)	{
		a=x;	b=t[i];
		if(a<b)	swap(a,b);
		while(1)	{
			ama=a%b;
			if(ama==0)	break;
			a=b;
			b=ama;
		}
		x=b*(x/b)*(t[i]/b);
	}
	printf("%lld\n",x);
	return 0;
}

Measured memory_bytes: 128
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    var n = 0
    val b = new ArrayBuffer[Int]
    while({n=readInt;n}!=0) {
      var min = n
      for(i<-0 to 100) {
        for(j<-0 to Math.sqrt(n-i*i*i).toInt+1) {
          val m = j*j+i*i*i
          if(m>=0 && m<=n) {
            if(min > i+j+(n-m)) min = i+j+(n-m)
          }
        }
      }
      b += min
    }
    println(b.mkString("\n"))
  }
}

Measured memory_bytes: 70464
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

struct Edge {
  int s,t,c;
  Edge(int s, int t, int c) :s(s),t(t),c(c) {}
};
bool operator<(const Edge &a, const Edge &b) {
  return a.c < b.c;
}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }

};


int main() {
  int n, m;
  while(cin>>n>>m,n||m) {
    vector<Edge> es;
    REP(i, m) {
      int a, b, c;
      cin >> a >> b>> c;
      a--;b--;
      es.push_back(Edge(a,b,c));
    }
    
    sort(ALL(es));
    int ans = INF;
    for (int i=0; i<m; ++i) {
      UnionFind uf(n);
      for (int j=i; j<m; ++j) {
        uf.unionSet(es[j].s, es[j].t);
        if (uf.size(es[j].s) == n) {
          ans = min(ans, es[j].c - es[i].c);
        }
      }
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
  }
}

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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    int a;
    int cnt1 = 0, cnt2=0;
    for(int i=0;i<3;i++){
        cin>>a;
        if(a==5) cnt1 ++;
        else if(a==7) cnt2++;
    }
    if(cnt1==2 && cnt2==1)  cout<<"YES\n";
    else
                            cout<<"NO\n";
    return 0;
}



Measured memory_bytes: 256
n, k = map(int, input().split())
L, R = [], []
MOD = 998244353
for _ in range(k):
    t1, t2 = map(int, input().split())
    L.append(t1)
    R.append(t2)

dp = [0] * (n+1)
dp[1] = 1
acc = [0] * (n+1)
acc[1] = 1

for idx1 in range(2, n+1):
    for idx2 in range(k):
        if idx1 - L[idx2] < 0:
            continue
        dp[idx1] += (acc[idx1-L[idx2]] - acc[max(0, idx1-R[idx2]-1)]) % MOD
        dp[idx1] %= MOD
    acc[idx1] = (acc[idx1-1] + dp[idx1]) % MOD

print(dp[-1])

Measured memory_bytes: 76908
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=1e5+10;

int n;
int a[maxn],cnt[maxn];
int ans=0;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if (a[i]>=1) cnt[a[i]-1]++;
		cnt[a[i]]++;
		cnt[a[i]+1]++;
	}
	
	for(int i=0;i<=1e5;i++)
		ans=max(ans,cnt[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] str1 = Console.ReadLine().Split(' ');
        int n = int.Parse(str1[0]);
        int a = int.Parse(str1[1]);
        int b = int.Parse(str1[2]);
        string str = Console.ReadLine();
        int i;
        int u = 0;
        int v = 0;
        for (i = 0; i < n; i++)
        {
            if (str[i] == 'a')
            {
                if (u < a + b)
                {
                    Console.WriteLine("Yes");
                    u++;
                }
                else Console.WriteLine("No");
            }
            else if (str[i] == 'b')
            {
                if ((u < a + b) && (v < b))
                {
                    Console.WriteLine("Yes");
                    u++;v++;
                }   
                else Console.WriteLine("No");
            }
            else Console.WriteLine("No");
        }
    }
}

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

using namespace std;

bool solve(int bl, int cl,vector<int>& a, int i) {
    if( i == 9 ) return true;
    else {
        int t = a[i];
        return ( t > bl && solve(t,cl,a,i+1) ) ||
               ( t > cl && solve(bl,t,a,i+1) );
    }
}

int main(){
    int n;
    cin >> n;
    while(n--){
        vector<int> a(9);
        int fst;
        cin >> fst;
        for(int i=0;i<9;++i){
            cin >> a[i];
        }

        if( solve(fst, 0, a, 0) ) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1184
N,P=map(int,input().split())
D=dict()
k=2
Q=P
while(True):
    if k*k>P:
        break
    if Q%k==0:
        if k in D:
            D[k]+=1
        else:
            D[k]=1
        Q=Q//k
    else:
        k+=1
if Q!=1:
    D[Q]=1
ans=1
for p in D:
    ans=ans*(p**(D[p]//N))
print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
    int a = 0;
    int h;
    int m;
    int s;
    scanf("%d",&a);
    h = a/60/60;
    m = (a-h*60*60)/60;
    s = a-(m*60+h*60*60);
    printf("%d:%d:%d\n",h,m,s);
    return 0;
    
}


Measured memory_bytes: 2084
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    int sum=0;
    for(int i=1;i<=b-a-1;i++){
        sum+=i;
    }
    cout<<sum-a<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/
int main(){
    string s; cin >> s;
    int n = s.size();

    int count = 0;
    _rep(i, 1, n){
        if(s[i] != s[i - 1]) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;
import java.util.Arrays;

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

int i=0;
for(i=0;i<n;i++){
    p[i]=scan.nextInt();
}
  
  int min=p[0];
    int sum=0;
    
  for(i=0;i<n;i++){
    if(min>=p[i]){
      min=p[i];
      sum=sum+1;
    }
  }
      

System.out.println(sum);
}
}

Measured memory_bytes: 65572
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cout.tie(NULL) ;
    
    int n;
    scanf("%d", &n);
    vector<int> dp(3,0);

    for(int i1 = 0; i1 < n; i1++) 
    {
        vector<int> new_dp(3, 0);
        vector<int> c(3);
        for(int i = 0; i < 3; i++) 
            scanf("%d", &c[i]);

        for(int i = 0; i < 3; i++)   //Parent Possibility
        {
            for(int j = 0; j < 3; j++)   // Current Child Possibility
            {
                if(i != j && (new_dp[j] < dp[i] + c[j])) 
                    new_dp[j] =  dp[i] + c[j];
            }
        }
        dp = new_dp;
    }
    printf("%d\n", max({dp[0], dp[1], dp[2]}));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

ll DP[20000];

signed main(){
  int N,W;
  cin >> N >> W;
  ll v,w;
  FOR(i,0,N){
    cin >> v >> w;
    FOR(i,0,10001){
      if(DP[i] || i == 0)DP[i+w] = max(DP[i+w],DP[i]+v);
    }
  }
  ll ans;
  FOR(i,0,W+1){
    ans = max(DP[i],ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3180