akhauriyash/Code-Regression huggingface dataset:
n,m,l=map(int,input().split())
d=[[10**18]*n for i in range(n)]
for _ in range(m):
    a,b,c=map(int,input().split())
    if c<=l:
        d[a-1][b-1]=c
        d[b-1][a-1]=c
for i in range(n):
    d[i][i]=0
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])

for i in range(n):
    for j in range(n):
        if d[i][j]<=l:
            d[i][j]=1
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
q=int(input())
for i in range(q):
    s,t=map(int,input().split())
    s-=1
    t-=1
    print(d[s][t]-1 if d[s][t]-1<999999999999999999 else -1)




Measured memory_bytes: 58584
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  int ans=0;
  int mp[n][n]={0};
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    mp[a][b]=mp[b][a]=1;
  }
 
  queue<int> bfs;
  rep(i,n){
    repi(j,i+1,n){
      bool flag[n]={0};
      if(mp[i][j]==1){
	mp[i][j]=0;
	mp[j][i]=0;
	bfs.push(0);
	flag[0]=true;
	while(!bfs.empty() ){
	  int num;
	  num=bfs.front();
	  bfs.pop();
	  rep(k,n){
	    if(mp[num][k]==1 && !flag[k]){
	      bfs.push(k);
	      flag[k]=true;
	    }
	  }
	}
	rep(k,n){
	  if(!flag[k]){
	    ans++;
	    break;
	  }
	}
	mp[i][j]=mp[j][i]=1;
      }
      
    }
  }

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






Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

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

   if (((X[0] == X[1]) && (X[2] == X[3]) && (X[1] != X[2])) ||
       ((X[0] == X[2]) && (X[1] == X[3]) && (X[0] != X[1])) ||
       ((X[0] == X[3]) && (X[1] == X[2]) && (X[0] != X[1]))) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
   return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>)
{
    val n = readInt()
    val task = Array<Pair<Long, Long>>(n, {Pair<Long, Long>(0L, 0L)})

    for (i in 0..n-1) {
        val (a, b) = readLine()!!.split(" ").map{it.toLong()}
        task[i] = Pair<Long, Long>(b, a)
    }
    task.sortBy { it.first }

    var flag = true
    var sum = 0L
    for (item in task) {
        sum += item.second
        if (sum > item.first) {
            flag = false
            break
        }
    }

    println(if (flag) "Yes" else "No")
}

// Read an integer
// Usage: val a = readInt()
fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
fun readString() = readLine()!!


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

void solve() {
  i64 N, A, B; cin >> N >> A >> B;
  vi64 h(N); cin >> h;

  auto check = [&](i64 md) {
    auto H = h;
    rep(i, N) H[i] -= B * md;
    int i = 0;
    i64 d = A - B;
    while (true) {
      while (i < N && H[i] <= 0) i++;
      if (i == N) return true;

      i64 c = (H[i] + d - 1) / d;
      if (c > md) return false;

      H[i] -= c * d;
      md -= c;
    }
  };

  i64 ok = 1e9, ng = 0;
  while (ok - ng > 1) {
    i64 md = (ok + ng) / 2;
    if (check(md)) ok = md; else ng = md;
  }
  cout << ok << '\n';
}


Measured memory_bytes: 1792
n = int(input())
p = list(map(int, input().split()))
c = 0

for i in range(n - 2):
    if p[i] < p[i + 1] <= p[i + 2] or p[i] >= p[i + 1] > p[i + 2]:
        c = c + 1

print(c)

Measured memory_bytes: 2940
use std::io;

fn main() {
    let mut buf: String = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().parse::<usize>().unwrap();

    let mut buf: String = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.trim().split_whitespace();
    let d = iter.next().unwrap().parse::<usize>().unwrap();
    let mut x = iter.next().unwrap().parse::<i32>().unwrap();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let a = buf.trim().parse::<usize>().unwrap();
        let mut i = 0;
        while a * i + 1 <= d {
            x += 1;
            i += 1;
        }
    }
    println!("{}", x);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    map<string, int> m;
    FOR(i, 0, n) {
        string s; cin >> s;
        ++m[s];
    }
    cout << m.size() << "\n";
}

Measured memory_bytes: 19276
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n=0;cin>>n;
int arr[n]; for (int i =0 ; i<n ; i++){cin>>arr[i];}
int counter=0;
for (int i =0 ; i<n ; i=i+2){if(arr[i]%2!=0){counter++;}}
cout<<counter;
}

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    ll ret = INF;
    for(i=1;i*i<=n;i++){
        if(n%i==0){
            ret = min(ret,i-1+n/i-1);
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main()
{
using namespace std;
int box[10];
for (int i=0;i<10;i++)
        cin >>box[i];
for (int i=1;i<10;i++)
{
        int key = box[i];
        int j = i-1;
        while (j>=0 && box[j] > key)
        {
                box[j+1]=box[j];
                j--;
        }
        box[j+1] = key;
}
cout << box[9] <<endl;
cout << box[8] <<endl;
cout << box[7] <<endl;
}

Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<int> dp(n + 2, 1e9 + 2);
    dp[0] = -1e9 - 2;
    for (int i = 0; i < n; i++) {
        int a; std::cin >> a;
        auto iter = std::upper_bound(dp.begin(), dp.end(), -a);
        *iter = -a;
    }
    std::cout << std::lower_bound(dp.begin(), dp.end(), 1e9 + 2)
        - dp.begin() - 1 << std::endl;
    return 0;
}


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

int main() {
  char c;
  cin >> c;
  if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u'){
    cout << "vowel";
  }
  else{
    cout << "consonant";
  }
  cout << endl;
  return 0; 
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

count = 0
for i in range(n):
    sum = 0
    for j in range(m):
        sum += a[i][j]*b[j]
    if sum + c > 0:
        count += 1
print(count)

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

int main(){
  int N;cin>>N;
  if(N==3){
    cout<<"2 5 63"<<endl;
    return 0;
  }
  vector<int> v;
  for(int i=2;i<=30000;i++){
    if(i%2==0||i%3==0) v.push_back(i);
  }
  ll sum=0;
  vector<int> ans;
  for(int i=0;i<N-1;i++){
    ans.push_back(v[i]);
    sum+=1LL*v[i];
  }
  for(int i=N-1;i<v.size();i++){
    if((sum+1LL*v[i])%6==0){
      ans.push_back(v[i]);
      break;
    }
  }
  if(ans.size()==N-1){
    ans.pop_back();
    sum-=1LL*v[N-2];
    for(int i=N-2;i<v.size()-1;i++){
      bool flag=0;
      for(int j=i+1;j<v.size();j++){
        if((sum+1LL*(v[i]+v[j]))%6==0){
          ans.push_back(v[i]);
          ans.push_back(v[j]);
          flag=1;
          break;
        }
      }
      if(flag==1) break;
    }
  }
  rep(i,N-1) cout<<ans[i]<<" ";
  cout<<ans[N-1]<<endl;
  return 0;
}


Measured memory_bytes: 640
// Author: πα

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

int main()
{
    int l, r, m = 2019, ans = INT_MAX;
    cin >> l >> r;
    int x = (l/m + bool(l%m)) * m;
    if(x <= r)
        return cout << 0, 0;
    for(int i = l; i <= r; ++i)
        for(int j = i+1; j <= r; ++j)
            ans = min(ans, int(1LL*i*j % m));
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b, c, d, n;
    int cnt;

    while (scanf("%d", &n) != EOF){
        cnt = 0;
        for (a = 0; a <= 9; a++){
            for (b = 0; b <= 9; b++){
                for (c = 0; c <= 9; c++){
                    for (d = 0; d <= 9; d++){
                        if ((a + b + c + d) == n){
                            cnt++;
                        }
                    }
                }
            }
        }
        printf("%d\n", cnt);
    }
    return (0);
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 500007;

int n;
int A, B, C, D;

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	cin >> n >> A >> B >> C >> D;
}

void work ()
{
	// main work
	
	--n;
	int del = B - A;
	LL nl, nr;
	lpi ( i, 0, n ){
		nl = C * SC ( LL, i ) - D * SC ( LL, n - i );
		nr = D * SC ( LL, i ) - C * SC ( LL, n - i );
		if ( del >= nl && del <= nr ){
			cout << "YES" << endl;
			return;
		}
	}
	
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9+7;

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;
  }
  bool findSet(int x, int y) {
    return root(x) == root(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; cin >> n >> m;
  vector<int> pp(n);
  vector<int> p(n);
  for(int i=0; i<n; i++) {
    cin >> p[i];
    pp[i] = i+1;
  }
  UnionFind uf(n+1);
  for(int i=0; i<m; i++){
    int x, y;
    cin >> x >> y;
    uf.unionSet(x, y);
  }

  int cnt = 0;
  for(int i=0; i<n; i++){
    if( uf.root(p[i]) == uf.root(pp[i]) ) cnt++;
  }
  cout << cnt << endl;

  return 0;
}

//


Measured memory_bytes: 1408
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int N , M; cin >> N >> M;
  int ans;
  int sum = 0;
  vector<int> A(M);
  for(int i = 0; i < M; i++){
    cin >> A[i];
    sum += A[i]; 
  }
  ans = N - sum;
  if(ans >= 0){
  cout << ans << endl;
  }
  else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3640
x,k,d=map(int,input().split())
if abs(x)>=k*d:
    ans=abs(x)-k*d
else:
    c=abs(x)//d#0に近づくまでの移動回数
    tmp1=abs(x)-c*d#c回移動時点での座標
    t=k-c#残り移動回数
    tmp2=tmp1-d
    #print(tmp1,tmp2)
    if t%2==0:
        ans=tmp1
    else:
        ans=abs(tmp2)


print(ans)

Measured memory_bytes: 9148
#include <stdio.h>

int main()
{
    int n;
    int p[4][3][10] = {0};
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int b, f, r, v;
        scanf("%d %d %d %d", &b, &f, &r, &v);
        p[b - 1][f - 1][r - 1] += v;
    }
    for (int b = 0; b < 4; b++)
    {
        for (int f = 0; f < 3; f++)
        {
            for (int r = 0; r < 10; r++)
            {
                printf(" %d", p[b][f][r]);
            }
            printf("\n");
        }
        if (b != 3)
        {
            printf("####################\n");
        }
    }

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A.at(i);
  }
  sort(A.rbegin(), A.rend());
  
  int t = N - 1;
  long long ans = 0;
  rep(i, N) {
    int lim = 2;
    if(i == 0) lim = 1;
     rep(j, lim) {
      if(t > 0) {
        ans += A.at(i);
        t--;
      }
    }
  }
  cout << ans << endl;
}

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

inline ll f(ll b, ll n) {
    return n < b ? n : f(b, n/b) + n%b;
}

int main()
{
    ll n, s, ans = -1;
    scanf("%lld%lld", &n, &s);

    if (s == n) ans = n+1;

    for (ll i = 1, b; i*i <= n; i++) {
        if (i > 1 && f(i, n) == s && (ans == -1 || ans > i))
            ans = i;
        if ((n+i-s)%i == 0 && (b=(n+i-s)/i) > 1 &&
            f(b, n) == s && (ans == -1 || ans > b))
            ans = b;
    }

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


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

int main(){
    string s,ss;
    cin >> s;
    ss="hi";
    int nagasa=s.size();
    if(nagasa%2==1){
        puts("No");
        return 0;
    }
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]!='h'){
                puts("No");
                return 0;
            }
        }
        else{
            if(s[i]!='i'){
                puts("No");
                return 0;
            }
        }
    }
    
    puts("Yes");

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc() getchar()
#define pc(a) putchar(a)
#define int long long
#define inf (1ll<<60)
inline int read()
{
    int x=0,f=1;
    char c=gc();
    while(c>'9'||c<'0')
    {
        if(c=='-') f=-f;
        c=gc();
    }
    while(c>='0'&&c<='9') x=x*10+c-'0',c=gc();
    return x*f;
}
int Num[25];
inline void write(int x)
{
    if(!x) {pc('0');return;}
    if(x<0) x=-x,pc('-');
    int top=0;
    while(x) Num[++top]=x%10,x/=10;
    while(top) pc(Num[top--]+'0');
    return;
}
#define ma 100005
const int cost[15]={0,2,5,5,4,5,6,3,7,6};
const char nu[15]={'0','1','2','3','4','5','6','7','8','9'};
string dp[ma];
inline bool empty(string s){return !s.size();}
int us[ma];
inline bool cmp(int x,int y){return x>y;}
inline bool bet(string x,string y)
{
	if(x.size()==y.size()) return x>y;
	return x.size()>y.size();
}
signed main()
{
    int n=read(),m=read();
    for(int i=1;i<=m;i++) us[i]=read();
    sort(us+1,us+m+1,cmp);
    for(int i=1;i<=m;i++)
    {
        for(int j=cost[us[i]];j<=n;j++)
        {
        	if(empty(dp[j-cost[us[i]]])&&j^cost[us[i]]) continue;
            string nxt=dp[j-cost[us[i]]]+nu[us[i]];
            if(empty(dp[j])||bet(nxt,dp[j]))
                dp[j]=nxt;
        }
    }
//    for(int i=1;i<=n;i++)
//    	cout<<i<<' '<<dp[i]<<endl;
    cout<<dp[n];
}








Measured memory_bytes: 42556
import sys

n, k, s = map(int, sys.stdin.readline().split())

def main():
    m = 10 ** 9
    a = [None] * n
    for i in range(k):
        a[i] = s
    for i in range(k, n):
        if s < m:
            a[i] = m
        else:
            a[i] = 1
    return a

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Measured memory_bytes: 6684
#include<bits/stdc++.h>
using namespace std;
const int N=30;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
char s[N];
int n,vis[N];
int main() {
    scanf("%s",s+1),n=strlen(s+1);
    for(int i=1;i<=n;i++) vis[s[i]-'a']=1;
    if(n<26) {
        for(int i=0;i<26;i++)
            if(!vis[i]) {
                printf("%s",s+1);
                putchar(i+'a');
                return 0;
            }
    }
    int z=n;
    while(z>1&&s[z-1]>s[z]) --z;
    if(z==1) return puts("-1"),0;
    for(int i=n;i;i--) {
        for(char c=s[i]+1;c<='z';c++)
            for(int j=i+1;j<=n;j++)
                if(s[j]==c) {
                    for(int k=1;k<i;k++) putchar(s[k]);
                    putchar(c);return 0;
                }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextInt();
        long v = sc.nextInt();
        long b = sc.nextInt();
        long w = sc.nextInt();
        long t = sc.nextInt();

        long d = Math.abs(a-b);
        if(v <= w) {
            System.out.println("NO");
            return;
        }
        long s = v-w;
        if(s * t >= d) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }


    }


}

Measured memory_bytes: 35784
def main():
    from math import gcd
    n, *a = map(int, open(0).read().split())
    m = max(a)

    c = [0] * (m + 1)
    g = a[0]
    for i in a:
        g = gcd(g, i)
        c[i] = 1

    if g > 1:
        pre = "not"
    else:
        for i in range(2, 10 ** 6 + 1):
            if sum(c[i::i]) > 1:
                pre = "setwise"
                break
        else:
            pre = "pairwise"

    print(pre + " coprime")


if __name__ == '__main__':
    main()


Measured memory_bytes: 121468
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int H, W; cin >> H >> W;
  int h, w; cin >> h >> w;
  cout << H * W - h * W - w * H + h * w << endl;
}


Measured memory_bytes: 3628
#pragma target("avx")
#pragma target("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
        int h, w;
        scanf("%d %d", &h, &w);
        std::vector<V> a(h+2, V(w+2, 1));
        rep(i, 1, h+1){
                char s[w+1];
                scanf("%s", s);
                rep(j, 1, w+1) a[i][j] = (s[j-1]=='#');
        }


        std::queue<PP> que;
        rep(i, 1, h+1) rep(j, 1, w+1) {
                if(a[i][j]){
                        rep(I, 0, 4){
                                que.emplace(1, P(i+dx[I], j+dy[I]));
                        }
                }
        }

        int ans = 0;
        while(!que.empty()){
                P p;
                int d;
                std::tie(d, p) = que.front();
                que.pop();
                if(a[p.fi][p.se]) continue;
                a[p.fi][p.se] = 1;
                ans = std::max(ans, d);
                rep(i, 0, 4){
                        int nx=p.fi+dx[i], ny=p.se+dy[i];
                        if(!a[nx][ny]) que.emplace(d+1, P(nx, ny));
                }
        }
        printf("%d\n", ans);
        return 0;
}

Measured memory_bytes: 105384
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

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

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

long long pdp[3030][6030];
long long sdp[3030][6030];
long long ans = 0;
int n, t;
int a[6000], b[6000];

signed main()
{
    srand(time(NULL));
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> t;
    t--;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int ot = 0; ot <= t; ot++)
        {
            if (i > 0)
                pdp[i][ot] = max(pdp[i][ot], pdp[i - 1][ot]);
            pdp[i][ot + a[i]] = max(pdp[i][ot + a[i]], (i > 0 ? pdp[i - 1][ot] : 0) + b[i]);
            ans = max(ans, pdp[i][ot + a[i]]);
        }
    }
    for (int i = n - 1; i >= 0; i--)
    {
        for (int ot = 0; ot <= t; ot++)
        {
            if (i + 1 < n)
                sdp[i][ot] = max(sdp[i][ot], sdp[i + 1][ot]);
            sdp[i][ot + a[i]] = max(sdp[i][ot + a[i]], (i + 1 < n ? sdp[i + 1][ot] : 0) + b[i]);
            ans = max(ans, sdp[i][ot + a[i]]);
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int ot = 1; ot <= t; ot++)
        {
            pdp[i][ot] = max(pdp[i][ot], pdp[i][ot - 1]);
            sdp[i][ot] = max(sdp[i][ot], sdp[i][ot - 1]);
        }
    }
    for (int i = 1; i + 1 < n; i++)
    {
        for (int pa = 0; pa <= t; pa++)
        {
            ans = max(ans, pdp[i - 1][pa] + sdp[i + 1][t - pa] + b[i]);
        }
    }
    cout << ans;
}


Measured memory_bytes: 284928
#include<stdio.h>
int main(){
	int a,b,c,x,n;
	int i,k,j,sum = 0;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&x);
	if(a>=0 &&a<=50 &&b>=0&&b<=50&&c>=0&&c<=50){
		if(a+b+c>1){
			if(x>=50 &&x<=20000 && x%50== 0){
				for(i = 0;i<=a;i++){
					for(j = 0;j<=b;j++){
						for(k =0;k<=c;k++){
							if(x == i*500+j*100+k*50){
								sum++;
							}
						}
					}
				}
				printf("%d",sum);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
	int k,n;
	cin>>k>>n;
	int a[n];
	rep(i,n)cin >>a[i];
	sort(a,a+n-1);
	int Max=a[0]+k-a[n-1];
	rep(i,n-1)Max=max(Max,a[i+1]-a[i]);
	cout << k-Max;
	return 0;
}

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

using namespace std;

typedef pair<string,int> data_t;

int main() {
  int n;
  cin >> n;
  vector<data_t> a(n);
  vector<data_t> b(n);
  for(int i=0;i<n;i++){
    cin >> a[i].first >> a[i].second;
    a[i].second*=-1;
    b[i].first=a[i].first;
    b[i].second=a[i].second;
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(a[i].first==b[j].first&&a[i].second==b[j].second)cout << j+1 << endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

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

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  int n = std::ceil( (double)N/1000 );
  std::cout << n*1000 - N << std::endl;
  return 0;
}



Measured memory_bytes: 3648
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int wa[100001];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    set<int> ac;
    int wa_cnt = 0;
    for(int i = 0;i<m;i++)
    {
        char x[3];
        int p;
        scanf("%d %s",&p,&x);
        if(x[0] == 'A' && ac.count(p) == 0) {
            ac.insert(p);
            wa_cnt += wa[p];
        }
        else wa[p]+=1;
    }
    printf("%d %d",(int)ac.size(),wa_cnt);
    return 0;
}


Measured memory_bytes: 4992
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8[:], i8)")
def binary_search(a, key):
    """Meguru type binary search"""
    ng = -1
    ok = len(a)

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] >= key:
            ok = mid
        else:
            ng = mid

    return ok


@nb.njit("i8(i8, i8[:])")
def solve(N, L):
    L.sort()
    ans = 0
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            c = binary_search(L, L[a] + L[b]) - 1
            ans += c - b
    return ans


def main():
    N = int(input())
    L = np.array(input().split(), dtype=np.int64)

    ans = solve(N, L)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 119048
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<complex>
using namespace std;

int main(){
    bool a[1001]={false};
    bool b[1001]={false};
    int mm[1001]={0};
    char tmp[100];
    int x,y;
    for (;;) {
        fgets(tmp,100,stdin);
        if(tmp[0]<'0' || tmp[0]>'9') break;
        sscanf(tmp,"%d,%d",&x,&y);
        a[x]=true;
        mm[x]+=1;
    }
    for (;;) {
        if (fgets(tmp,100,stdin)==NULL) break;
        sscanf(tmp,"%d,%d",&x,&y);
        b[x]=true;
        mm[x]+=1;
    }
    for (int i=1;i<1001;++i) {
        if (a[i] && b[i]) {
            printf("%d %d\n",i,mm[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 3204
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
    int a, b;
    cin >> a;
    cin >> b;

    int tot = 1;
    int res = 0;
    while (tot < b)
    {
        tot += a - 1;
        res++;
    }

    cout << res << endl;

    return 0;
}


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

int main()
{
   int h, w;
   cin >> h >> w;
   vector<vector<int>> dp(10,vector<int>(10,INF));
   rep(i,10) dp[i][i] = 0;

   rep(i,10) rep(j,10) 
   {
      int c;
      cin >> c;
      dp[i][j] = c;
   }

   rep(k,10)
   {
      rep(i,10)
      {
         rep(j,10) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
   }
   ll ans = 0;
   rep(i,h) rep(j,w)
   {
      int a;
      cin >> a;
      if(a == -1) continue;
      ans += dp[a][1];
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
h,w,n = map(int, input().split())
memo = {}
dxy = [(0,1), (0,0), (1,0), (-1,0), (0,-1), (1,1), (-1,-1), (-1,1), (1,-1)]
for i in range(n):
    a,b = map(int, input().split())
    for dx,dy in dxy:
        x,y = a+dx,b+dy
        if 1 < x < h and 1 < y < w:
            if (x,y) not in memo:
                memo[(x,y)] = 0
            memo[(x,y)] += 1

ans = [0 for i in range(10)]
for k,v in memo.items():
    ans[v] += 1
ans[0] = (h-2)*(w-2) - sum(ans)
[print(i) for i in ans]

Measured memory_bytes: 166700
package main

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

var lower, higher []int
var heapSize int

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
	}

	sort.Ints(as)
	as = reverse(as)

	lower = make([]int, n+10)
	higher = make([]int, n+1)
	sum := 0
	for i := 0; i < n; i++ {
		c := insert(as[i])
		sum += c
	}
	fmt.Println(sum)
}

func insert(val int) int {
	if heapSize == 0 {
		heapAppend(val, val)
		return 0
	}
	l, r := popFirst()
	heapAppend(val, l)
	heapAppend(val, r)
	return l
}

func popFirst() (int, int) {
	l, h := lower[0], higher[0]
	first, last := 0, heapSize-1
	swap(first, last)
	heapSize--
	heapify(first)
	return l, h
}

func swap(i, j int) {
	lower[i], higher[i], lower[j], higher[j] = lower[j], higher[j], lower[i], higher[i]
}

func heapAppend(l, h int) {
	if l > h {
		l, h = h, l
	}
	last := heapSize
	lower[last] = l
	higher[last] = h
	heapSize++
	heapify(last)
}

func heapify(i int) {
	l := i<<1 + 1
	r := i<<1 + 2
	largest := i
	if l < heapSize && lower[l] > lower[i] {
		largest = l
	}
	if r < heapSize && lower[r] > lower[largest] {
		largest = r
	}
	if largest != i {
		swap(i, largest)
		heapify(largest)
	}
}

func reverse(vs []int) []int {
	var res []int
	for i := len(vs) - 1; i >= 0; i-- {
		res = append(res, vs[i])
	}
	return res
}


Measured memory_bytes: 11624
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 500000 + 9;
int n,m,vis[N],c;
vector<int>a[N];
void dfs(int u)
{
    vis[u]=1;
    c++;
    for(auto v:a[u])
    {
        if(!vis[v])dfs(v);
    }
}

 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        cin>>n>>m;
        int u,v;
        forr(i,1,m)
        {
            cin>>u>>v;
            a[u].push_back(v);
            a[v].push_back(u);
        }
        int ans = 0;
        forr(i,1,n)
        {
            if(!vis[i])
            {
                c=0;
                dfs(i);
                ans=max(ans,c);
            }
        }
        cout<<ans<<endl;







return 0;
}


Measured memory_bytes: 28612
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var a = new int[3, 3];
            for(int i  =0; i < 3; i++)
            {
                var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for(int j = 0; j < 3; j++)
                {
                    a[i, j] = input[j];
                }
            }
            var n = int.Parse(Console.ReadLine());

            var bingo = new bool[3, 3];

            for(int i = 0; i < n; i++)
            {
                var b = int.Parse(Console.ReadLine());
                for (int j = 0; j < 3; j++) 
                {
                    for(int k = 0; k < 3; k++)
                    {
                        if(b == a[j, k])
                        {
                            bingo[j, k] = true;
                        }
                    }
                }
            }

            for(int i = 0; i < 3; i++)
            {
                if (bingo[i, 0] && bingo[i, 1] && bingo[i, 2]) 
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            for (int i = 0; i < 3; i++)
            {
                if (bingo[0, i] && bingo[1, i] && bingo[2, i]) 
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            if (bingo[0, 0] && bingo[1, 1] && bingo[2, 2])
            {
                Console.WriteLine("Yes");
                return;
            }
            if (bingo[0, 2] && bingo[1, 1] && bingo[2, 0])
            {
                Console.WriteLine("Yes");
                return;
            }

            Console.WriteLine("No");
        }
    }
}


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

int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    cout << (s[0] == s[1] and s[2] == s[3] and s[0] != s[2] ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	unsigned long long dp[100];
	dp[0] = 0;
	dp[1] = 1;
	dp[2] = 2;
	dp[3] = 4;
	rep(i,4,40){
		dp[i] = dp[i-1] + dp[i-2] + dp[i-3];	
	}
	

	int n;
	while( cin >> n ){
		if( !n )
			ret 0;

		if( dp[n] % 3650 )
			cout << dp[n] / 3650 + 1 << endl;
		else
			cout << dp[n] / 3650 << endl;
	}

	ret 0;
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int N,A,B,C,X;
    while(cin >> N >> A >> B >> C >> X){
        if(N == 0 && A == 0 && B == 0 && C == 0 && X == 0)return 0;
        vector<int> vec;
        for(int a = 0;a < N;a++){
            int b;cin >> b;
            vec.push_back(b);
        }
        int ans = 0;
        int i = 0;
        while(1){
            if(vec.at(i) == X){
                i++;
            }
            X = (A*X+B)%C;
            if(ans >= 10001){
                cout<<-1<<endl;
                break;
            }
            if(i == N){
                cout<<ans<<endl;
                break;
            }
            ans++;

        }
    }
}



Measured memory_bytes: 3148
N = int(input())
L = list(map(int, input().split()))

cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if (L[i] != L[j] and L[j] != L[k] and L[k] != L[i]
                    and min(L[i] + L[j], L[j] + L[k], L[k] + L[i]) > max(L[k], L[i], L[j])):
                # print(i, j, k)
                cnt += 1
print(cnt)

Measured memory_bytes: 9212
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

ll N, A, B;
ll ans;

int main(void) {
    scanf("%lld %lld %lld", &N, &A, &B);

    if ((B-A)%2==0) ans += (B-A)/2;
    else {
        if (A-1<N-B) {
            ans += A;
            ll s = B - A;
            ans += (s-1)/2;
        } else {
            ans += N - B + 1;
            ll s = A + (N-B) + 1;
            ans += (N-s)/2;
        }
    }

    printf("%lld\n", ans);
    

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
    int n;
    scanf("%d",&n);
    int ok = 0;
    for(int i = 1; i <= 9; i++){
        for(int j = i; j <= 9; j++){
            ok |= (i*j==n);
        }
    }
    if(ok) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

int main(void){
    int info;
    cin >> info;
    int b = 0,f = 0,r = 0,v = 0;
    int room[4][3][10]={{{}}};
    
    for (int i = 1; i <= info; i++){
        cin >> b >> f >> r >> v;
        room[b-1][f-1][r-1] += v;
    }
    for (int x = 0; x <= 3; x++){
        for (int y = 0; y <= 2; y++){
            for (int z = 0; z <= 9; z++){
                if (z < 9){
                    cout  << " " << room[x][y][z];
                }
                else{
                    cout <<  " " << room[x][y][z] << endl;
                }
            }
        }
        if (x < 3){
            cout << "####################" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3080
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int> >

const int maxn = 1000* 100 + 5;
int a[maxn];

int32_t main(){
    int mn = 2, n, ans = 0;
    cin >>n;
    for(int i = 0; i < n; i ++)
        cin >>a[i];
    ans = a[0] - 1;
    for(int i = 1; i < n; i ++){
        if(a[i] == mn)
            mn ++;
        else if(a[i] > mn){
            ans += (a[i] - 1)/ mn;
        }
    }
    cout <<ans <<endl;
    return false;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long long MOD = 1000000000 + 7;
typedef long long ll;

int main() {
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	int A, B, C;
	cin >> A >> B >> C;

	if (C >= A && C <= B) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



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

int main()
{
	std::array<int,4> a = {};
	for(int i=0;i<6;i++)
	{
		int n;
		std::cin >> n;
		a[n-1]++;
	}
	int unique_cnt = 0;
	for(auto const & e : a)
	{
		if(e == 1) 
		{
			unique_cnt++;
			if(unique_cnt > 2)
			{
				goto fail;
			}
		}
		else if(e > 2)
		{
			goto fail;
		}
	}
	std::cout << "YES" << std::endl;
	return 0;
fail:
	std::cout << "NO" << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;
 

int solve(int *w,int n) {
	int g_m = w[0]; //整个数组中的最小值 
	 
	map<int,int> address; //元素在排序后的数组中的下标映射 
	int *tmp = new int[n];
	bool *T = new bool[n]; //标记当前位置是否被访问 
	
	int ans = 0; //最终结果 
	
	for (int i=0;i<n;i++) {
		//找出最小值 
		if (w[i] < g_m) {
			g_m = w[i];
		}
		//初始化 
		T[i] = false;
		tmp[i] = w[i];
	}
	//对临时数组排序 
	sort(tmp,tmp+n);
	//建立映射 
	for (int i=0;i<n;i++) {
		pair<int, int> pair_map(tmp[i],i);
		address.insert(pair_map);
	}
	for (int i = 0;i<n;i++) {
		if (T[i]) { //当前位置已被访问过了 
			continue;
		}
		int m = w[i]; //当前圈里的最小值 
		int cur = i;//当前所处的位置
		int S = 0; //当前所需的花费
		int count = 0; //当前圈里的元素个数
		 
		while (1) {
			count++;
			int v = w[cur];
			m = min(v,m);
			S += v;
			T[cur] = true;
			cur = address.at(v); 
			if (T[cur]) {
				break;
			}
		}
		ans += min(S + (count - 2) * m,S + m + (1+count) * g_m);
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	int *w = new int[n];
	for (int i = 0;i<n;i++) {
		cin >> w[i];
	}
	int ans = solve(w,n);
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll X, A;
  IN(X,A);
  if(X<A) OUT("0");
  else    OUT("10");

  return 0;
}

Measured memory_bytes: 256