akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  int n;
  cin>>n;

  vector<ll> p(n);
  ll ma=-INF;
  int dai;
  ll mi=INF;
  int sho;
  rep(i,n){
    cin>>p[i];
    if(chmax(ma,p[i])) dai=i;
    if(chmin(mi,p[i])) sho=i;
  }

  if(ma+mi>=0){
    cout << 2*n-1 << endl;
    rep(i,n){
      cout << dai+1 << " " << i+1 << endl;
    }
    rep(i,n-1){
      cout << i+1 << " " << i+2 << endl;
    }
  }
  else {
    cout << 2*n-1 << endl;
    rep(i,n){
      cout << sho+1 << " " << i+1 << endl;
    }
    for(int i=n-1;i>=1;i--){
      cout << i+1 << " " << i << endl;
    }    
  }


}

Measured memory_bytes: 3616
package main

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

func main() {
	sc := NewScanner()

	s := sc.NextLine()
	k := sc.NextInt()

	ans := "1"
	for i := 0; i < k; i++ {
		if string(s[i]) == "1" {
			//
		} else {
			ans = string(s[i])
			break
		}
	}
	fmt.Printf("%v\n", ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
auto divv = [](ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
};

auto isprime = [](auto n){
  bool isPrime = true;
  for(decltype(n) i = 2; i <= sqrt(n); ++i)
  {
      if(n % i == 0)
      {
          isPrime = false;
          break;
      }
  }
  return isPrime;
};

int main() {
    ll n,k;
    cin>>n>>k;


    unordered_set<ll> divn,divk;
    auto y = divv(n);
    for(auto it:y){
        divn.insert(it);
    }
    {
        ll lim = sqrt(k);
        fr(i, 1, lim+1){
            if(k%i ==0){
                divk.insert(i);
                divk.insert(k/i);
            }
        }
    }
    ll sum=0;
    for(auto it:divk) if(divn.count(it)) if(isprime(it)) sum++;
    pr(sum);
}


Measured memory_bytes: 896
from heapq import heappop,heappush
q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)

Measured memory_bytes: 110936
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in();
	
	cout << 3*N*N << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[101111],dp[101111];
int n,k;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	memset(dp,63,sizeof(dp));
	dp[1]=0;
	for(int i=1;i<=n;i++)
		if(dp[i]<=1.5e9)
			for(int j=1;j<=k && j+i<=n;j++)
			    dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
	cout<<dp[n]<<endl;
	return 0;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/e.in", "r", stdin);
//  freopen("../IO/f.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

constexpr int MOD = 1000'000'007;
constexpr int N = 100'025;
int dp[N][2];
char L[N];

void solve(std::istream &in, std::ostream &out) {
  in >> L;
  int n = strlen(L);
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int k = 0; k < 2; ++k) {
      // place 0
      dp[i + 1][L[i] == '1' ? 1 : k] = (dp[i + 1][L[i] == '1' ? 1 : k] + dp[i][k]) % MOD;
      // place 1
      if (k || L[i] == '1') {
        dp[i + 1][k] = (dp[i + 1][k] + (int64_t) 2 * dp[i][k]) % MOD;
      }
    }
  }
  cout << (dp[n][0] + dp[n][1]) % MOD << '\n';
}


Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main(){
  int i;
  int go = 0,nana = 0;
  while(cin >> i){
    if(i == 5)
      go++;
    else if (i == 7)
      nana++;
  }
  if(go == 2 && nana == 1)
    cout << "YES";
  else
    cout << "NO";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
// AtCoder Beginner Contest 095 - Problem C: Half and half (https://atcoder.jp/contests/abc095/tasks/arc096_a) 
#include <bits/stdc++.h>

using namespace std;

int solve(int A, int B, int C, int X, int Y)
{
    if (2*C >= A + B)
        return X*A + Y*B;

    auto m = min(X, Y);
    auto ans = 2*C*m;

    X -= m;
    Y -= m;

    ans += (A <= 2*C) ? A*X : 2*C*X;
    ans += (B <= 2*C) ? B*Y : 2*C*Y;
    
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

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

    auto ans = solve(A, B, C, X, Y);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    if (a == b) {
        cout << c << endl;
    } else if (a == c) {
        cout << b << endl;
    } else {
        cout << a << endl;
    }
    return 0;
}



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

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//s.find(w[i])==string::npos
//findの使い方

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

long long int n,cnt=0,ans=0,a[100000],b,c,cmp[100000],data[100000],m,h,x,y;

string s,w;

int main(void){
     cin >> n;
     rep(i,n){
         cin >> a[i];
     }
     sort(a,a+n);
     rep(i,n){
         if(a[i]!=a[i+1]){
             ans++;
         }
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

int main(int argc, char* argv[]) {

	string s,t;

	cin >> s;
	cin >> t;

	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());


	if(t>s){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
using ll = long long int;

int main(){
    int X,Y,A,B,C;
    cin>>X>>Y>>A>>B>>C;
    vector<int> p(A);
    vector<int> q(B);
    vector<int> r(C);
    for(int i=0;i<A;i++) cin>>p[i];
    for(int i=0;i<B;i++) cin>>q[i];
    for(int i=0;i<C;i++) cin>>r[i];
    
    sort(p.begin(),p.end(),greater<int>());
    sort(q.begin(),q.end(),greater<int>());
    sort(r.begin(),r.end(),greater<int>());
    
    vector<int> a(X+Y+C);
    for(int i=0;i<X;i++) a[i]=p[i];
    for(int i=0;i<Y;i++) a[i+X]=q[i];
    for(int i=0;i<C;i++) a[i+X+Y]=r[i];
    
    sort(a.begin(),a.end(),greater<int>());
    
    ll sum=0;
    for(int i=0;i<X+Y;i++) sum+=a[i];
    
    cout<<sum<<endl;
    
    return 0;
}




Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int main(void){
	int N; cin >> N;
	int a[101];
	for(int i = 0; i < N; i++) cin >> a[i];

	int res = 0;
	int len = 1;
	for(int i = 0; i < N-1; i++){
		if(a[i] == a[i+1]) len++;
		else{
			res += len/2;
			len = 1;
		}
	}
	res += len/2;

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::base_sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x  << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

void readf(string x){
	freopen((x+".in").c_str(),"r",stdin);
	freopen((x+".out").c_str(),"w",stdout);
}


int read()
{
	bool min = 0;
	int  result = 0;
	char ch;
	ch = getchar();
	while(1)
	{
		if(ch == '-') break;
		if(ch >='0' && ch <= '9') break;
		ch = getchar();
	}
	if(ch == '-') min = 1;else result = ch-'0';
	while(1)
	{
		ch =getchar();
		if(ch< '0' || ch>'9') break;
		result = result * 10 + (ch-'0');
	}
	if(min) return -result;
	return result;
}
#define n 200005
int x[n],R[20][n],L[20][n],kiri[(1<<20)],kanan[(1<<20)];

int main(){
	int N,V;
	cin >> N >> V;
	int po = 0;
	int tmp = V;
	while(tmp) tmp/=2,po++;
	
	
	for(int i=1;i<=N;i++) cin >> x[i];
	tmp = V/2;
	for(int i=0;i<po;i++){
	//	tmp = V/2;
		for(int j=1;j<=N;j++){
			L[i][j] = j;
			if(j == 1) continue;
			if(x[j] - x[j-1] <= tmp) L[i][j] = L[i][j-1];
	//		cout << L[i][j] << " " << i << " " << j << "\n";
 		}
		tmp /=2;
	}
	tmp = V/2;
	for(int i=0;i<po;i++){
//		tmp = V;
		for(int j=N;j>=1;j--){
			R[i][j] = j;
			if(j == N) continue;
			if(x[j+1] - x[j] <= tmp) R[i][j] = R[i][j+1];
		}
		tmp /=2;
	}
	int i = po;
	for(int j=N;j>=1;j--){
		R[i][j] = j;
		if(j == N) continue;
		if(x[j+1] - x[j] <= V) R[i][j] = R[i][j+1];
	}
	for(int j=1;j<=N;j++){
		L[i][j] = j;
		if(j == 1) continue;
		if(x[j] - x[j-1] <= V) L[i][j] = L[i][j-1];
	}
	memset(kiri,0,sizeof kiri);
	for(int i=0;i<(1<<po);i++) kanan[i] = N  + 1;
	for(int i=0;i<(1<<po);i++){
		for(int j=0;j<po;j++){
			if(i & (1 << j)){ 
				int l = kiri[i^(1<<j)];
				kiri[i] = max(kiri[i],R[j][l+1]);
				int r = kanan[i^(1<<j)];
				kanan[i] = min(kanan[i],L[j][r-1]);
		//		cout << i << " " << kiri[i] <<" " << kanan[i]<< "\n";
			}
		}
	}
	
	int dp[n];
	for(int i=0;i<n;i++) dp[i] = 1e9;
	for(int i=0;i<(1<<po);i++){
		int l = ((1 << po) - 1) ^ i;
		dp[kiri[i]] = min(dp[kiri[i]],kanan[l]);
	//;;	cout << dp[kiri[i]] << "\n"; 
	}
	for(int i=N;i>=0;i--){
		dp[i] = min(dp[i],dp[i+1]);
	//	cout << dp[i] << "\n";
	}
	int ki=0,ka = 2;
	for(int i=1;i<=N;i++){
		ka = max(ka,i+1);
		while(ka <= N && x[ka] - x[ka-1] <= V) ka++; 
		if(x[i] - x[i-1] > V) ki = i-1;
	//	cout << ki << " " << ka << "\n";
		if(dp[ki] <= ka) cout << "Possible\n";
		else cout << "Impossible\n";
	}
}



Measured memory_bytes: 39808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    int f = 0;
    rep(i, N)
    {
        cin >> A.at(i);
        if (A.at(i) % 2 == 0 && (A.at(i) % 3 != 0 && A.at(i) % 5 != 0))
        {
            f = 1;
        }
    }
    if (f == 0)
    {
        cout << "APPROVED" << endl;
    }
    else
    {
        cout << "DENIED" << endl;
    }
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const ll MAX_A = (int)(6e5 + 5);

int n;

vector<bool> primes(MAX_A);

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (ll i = 0; i < MAX_A; ++i) {
    primes[i] = true;
  }

  for (ll i = 2; i * i < MAX_A; ++i) {
    if (!primes[i]) continue;

    for (ll j = i * i; j < MAX_A; j += i) {
      primes[j] = false;
    }
  }

  int cnt = 0;

  for (ll i = 2; i < MAX_A; ++i) {
    if (cnt == n) break;

    if (primes[i] && i % 5 == 1) {
      printf("%d ", i);
      cnt += 1;
    }
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	/** MOD */
	private static long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if (Math.abs(n - m) > 1) {
				System.out.println(0);
			} else {
				System.out.println(fractorialMod(n) * fractorialMod(m) % MOD * ((n == m) ? 2L : 1L) % MOD);
			}
		}
	}

	/**
	 * @param n 入力数字
	 * @return 入力数字の階乗 mod MOD
	 */
	private static long fractorialMod(int n) {
		long result = 1L;
		for (int i = 2; i <= n; i++) {
			result = result * i % MOD;
		}
		return result;
	}
}


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

int comp(const void *a, const void *b) {
    return *(int *)b-*(int *)a;
}

#define MOD 1000000007LL
long long dp[210][100010] = {0LL};

int main(void) {
    int i, j, N, X, S[210];
    scanf("%d%d", &N, &X);
    for (i=0;i<N;i++) scanf("%d", &S[i]);

    qsort(S,N,sizeof(int),comp);
    for (j=0;j<=X;j++) dp[N][j] = j;
    for (i=N-1;i>=0;i--) for (j=0;j<=X;j++) {
        dp[i][j] += dp[i+1][j%S[i]];
        dp[i][j] %= MOD;
        dp[i][j] += dp[i+1][j]*(N-i-1);
        dp[i][j] %= MOD;
    }

    // for (i=1;i<=N;i++) {
    //     dp[0][X] *= N;
    //     dp[0][X] %= MOD;
    // }
    printf("%lld\n", dp[0][X]);
    return 0;
}

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

int main() {
    int N; cin >> N;
    bool ok = true;
    for(int i=0; i<N; ++i) {
        int a; cin >> a;
        if((a % 2 == 0) && (a % 3 != 0) && (a % 5 != 0)) ok = false;
    }
    cout << (ok ? "APPROVED\n" : "DENIED\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define DEBUG(a) cerr<<#a<<"="<<a<<endl
#define DEBUG_ARRAY(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define DEBUG(a) 
#define DEBUG_ARRAY(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> P;
typedef pair<ll,P> PP;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

const string YES = "YES";
const string NO = "NO";
vector<ll> m[4];
void solve(std::vector<long long> a, std::vector<long long> b){
    REP(3){
        m[--a[i]].push_back(--b[i]);
        m[b[i]].push_back(a[i]);
    }
    bool flag=true;
    int cnt[4];
    fill(cnt,cnt+4,0);
    REP(4){
        cnt[m[i].size()]++;
    }
    if(m[1].size()==2&&m[2].size()==2){
        cout<<YES<<endl;
    }else{
        cout<<NO<<endl;
    }
}

int main(){
    std::vector<long long> a(3);
    std::vector<long long> b(3);
    for(int i = 0 ; i < 3 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int N;
  string str;
  cin >> N;
  str = to_string(N);
  
  int last_index = str.size() - 1;
  if (str[last_index] == '2' || str[last_index] == '4' || str[last_index] == '5' || str[last_index] == '7' || str[last_index] == '9')
  {
      cout << "hon" << endl;
  }
  else if (str[last_index] == '3')
  {
      cout << "bon" << endl;
  }
  else
  {
      cout << "pon" << endl;
  }
}

Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main(){
    int n;
    int a[100000];
    int b[100000];

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

    int ans=0;
    for(int i=0;i<n;i++){
        ans+=b[i]-a[i]+1;
    }
    cout<<ans;
}

Measured memory_bytes: 256
fun main(args: Array<String>){

    val (a, b) = readLine()!!.split(" ").map { it.toInt() }

    if ( a >= 13 ) {
        println(b)
        return
    }

    if (a in 6..12) {
        println(b/2)
        return
    }

    println(0)

    
}

Measured memory_bytes: 36160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=100000+5;

int a[N];
int b[N];

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

    cout<<(n+2*d)/(2*d+1);
    return 0;
}
/*

*/


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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	int a, b;
	long long res = 1;
	bool flag;
	cin >> a >> b;
	
	int i = 2;
	
	while (a != 1 || b != 1) {
		flag = false;
		
		if (a % i == 0) {
			a /= i;
			flag = true;
		}
		
		if (b % i == 0) {
			b /= i;
			flag = true;
		}
		
		if (flag) {
			res *= i;
		} else {
			++i;
		}
	}
	
	cout << res;
}


Measured memory_bytes: 256
def connect_dfs(N,E,start):
    connect = {start}
    q = [start]
    while q:
        i = q.pop()
        for j in E[i]:
            if j in connect:continue
            connect.add(j)
            q.append(j)
    return connect

def remove_Edge(N,Ef,Eb,start,goal):
    v = connect_dfs(N,Ef,start) & connect_dfs(N,Eb,goal)
    for i in range(N):
        if i in v:continue
        for j in Eb[i]:
            Ef[j].pop(i)

def Bellman_Ford(N,E,start,INFTY=10**18):
    def update(dist,N,E,start):
        done = [False]*N
        done[start] = True
        q = [start]
        d = dist[:]
        while q:
            i = q.pop()
            di = d[i]
            for j,c in E[i].items():
                d[j] = min(d[j],d[i]+c)
                if not done[j]:
                    q.append(j)
                    done[j] = True
        return d
    #
    d = [INFTY]*N
    d[start] = 0
    for _ in range(N-1):
        d = update(d,N,E,start)
    if d!=update(d,N,E,start):
        return None
    else:
        return d

def main():
    N,M = map(int,input().split())
    ABC = [list(map(int,input().split())) for _ in [0]*M]
    E = [{} for _ in [0]*N]
    Eb = [{} for _ in [0]*N]
    for a,b,c in ABC:
        E[a-1][b-1] = -c
        Eb[b-1][a-1] = c
    
    remove_Edge(N,E,Eb,0,N-1)
    d = Bellman_Ford(N,E,0)
    if d == None:
        print("inf")
    else:
        print(-d[-1])
    
main()

Measured memory_bytes: 4432
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n; cin >> n;
	vector<int> a(n);
	int mod = 1000000007;
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
		sum %= mod;
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		sum -= a[i];
		if (sum < 0) sum += mod;
		ans += a[i] * sum;
		ans %= mod;
	}
	cout << ans << endl;
}

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

int main()
{
	int a;
  	string str;
  
  cin>>a;
  cin>>str;
  
  if(a>=3200)
  {
    cout<<str<<endl;
  }
  else
  {
	cout<<"red"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
int A[200010];
int B[200010];
bool flag = true;
ll ans = 0;

queue<int> mx;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    for(int i = 0; i < N; i++){
        int l = (i - 1 + N) % N;
        int r = (i + 1) % N;
        if(B[i] >= B[l] + B[r]) mx.push(i);
    }
    while(!mx.empty()){
        int id = mx.front();
        mx.pop();
        int l = (id - 1 + N) % N;
        int r = (id + 1) % N;
        ans += B[id] / (B[l] + B[r]);
        B[id] %= B[l] + B[r];
        if(B[id] < A[id]){
            if((A[id] - B[id]) % (B[l] + B[r]) != 0)flag = false;
            ans -= (A[id] - B[id]) / (B[l] + B[r]);
            B[id] = A[id];
        }
        int r2 = (r + 1) % N;
        int l2 = (l - 1 + N) % N;
        if(B[r] > B[id] + B[r2] && B[r] != A[r]) mx.push(r);
        if(B[l] > B[id] + B[l2] && B[l] != A[l]) mx.push(l);
    }
    for(int i = 0; i < N; i++) if(A[i] != B[i]) flag = false;
    cout << (flag ? ans : -1) << endl;
    return 0;
}

Measured memory_bytes: 2304
#include"iostream"
#include"cstdio"

#define MAXN
using namespace std;

bool f[150];
int N;

void DFS(int x)
{
	if(x > N)	
		return ;
	f[x] = true;
	DFS(x + 4);
	DFS(x + 7);
}

int main()
{
	cin >> N;
	DFS(0);
	if(f[N])
		puts("Yes");
	else	
		puts("No");
	return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 3e5+23;

set<pair<int, int>> s;
pair<int, int> H[N], W[N];

void solve() {
  int h, w, m; scanf("%d%d%d", &h, &w, &m);
  for (int i = 0; i < m; ++i) {
    int x, y; scanf("%d%d", &x, &y);
    s.emplace(--x, --y);
    ++H[x].first;
    ++W[y].first;
  }
  for (int i = 0; i < h; ++i)
    H[i].second = i;
  for (int i = 0; i < w; ++i)
    W[i].second = i;
  int cnt = 0, a = max_element(H, H+h)->first, b = max_element(W, W+w)->first;
  for (const auto &e: s) {
    cnt += (H[e.first].first+W[e.second].first) == (a+b);
  }
  sort(H, H+h, greater<pair<int, int>>());
  sort(W, W+w, greater<pair<int, int>>());
  int cntH = 0, cntW = 0;
  for (int i = 0; i < h; ++i)
    cntH += (H[i].first == H[0].first);
  for (int i = 0; i < w; ++i)
    cntW += (W[i].first == W[0].first);
  if (1LL*cntH*cntW > cnt)
    printf("%d", a+b);
  else
    printf("%d", a+b-1);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = n-1; i >= 0; i--){
        cout << a[i];
        if(i != 0){
            cout << " ";
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3084
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
for i in range(n):
    for j in range(2):
        if b[i] - a[i+j] <= 0:
            a[i+j] -= b[i]
            ans += b[i]
            break
        else:
            b[i] -= a[i+j]
            ans += a[i+j]
            a[i+j] = 0

print(ans)

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

int main() {
  int n;
  cin>>n;
  vector<tuple<string,int,int>> a;
  for(int i=1;i<=n;i++){
    string s;
    int p;
    cin>>s>>p;
    p=-p;
    a.push_back(tie(s,p,i));
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    cout<<get<2>(a[i])<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

int main() {
  int x, n;
  cin >> x >> n;
  if(n == 0) {cout << x << endl;return 0;}
  vector<int>p(n);
  rep(i, n) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  bool same = false;
  rep(i, n) {
    if(p[i] == x) {
      //cout << i << endl;
      same = true;
      int j = 1;
      int k = 1;
      while(1) {
        if(i-k < 0) {
          cout << x-k << endl;
          break;
        }
        else if(p[i-k] != x-k) {
          cout << x-k << endl;
          break;
        }
        else if(i+j >= n && i-k >= 0) {
          cout << x+j << endl;
          break;
        }
        else if(p[i+j] != x+j) {
          cout << x+j << endl;
          break;
        }
        else {
          j++;
          k++;
        }
      }
      break;
    }
  }
  if(!same) {cout << x << endl;}
}

Measured memory_bytes: 3624
from sys import stdin

def partition(A):
    # パーティションの基準
    p = A[-1]

    # 分かれ目を決める
    p_idx = 0
    for i, num in enumerate(A[:-1]):
        if num <= p:
            A[p_idx], A[i] = A[i], A[p_idx]
            p_idx = p_idx + 1
    A[p_idx], A[len(A) - 1] = A[len(A) - 1], A[p_idx]
    return p_idx

def main():
    lines = stdin.readlines()
    nums = [int(n) for n in lines[1].split(' ')]
    p_idx = partition(nums)
    res = [str(n) if i != p_idx else '['+str(n)+']' for i, n in enumerate(nums)];
    print(' '.join(res))

if __name__ == '__main__':
    main()


Measured memory_bytes: 17068
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Measured memory_bytes: 14456
S = input()
if(S == 'SUN'):
  print('7')
elif(S == 'MON'):
  print('6')
elif(S == 'TUE'):
  print('5')
elif(S == 'WED'):
  print('4')
elif(S == 'THU'):
  print('3')
elif(S == 'FRI'):
  print('2')
else:
  print('1')

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BTrained {
public:
    vector<int> a[100010];
    vector<int> visit;
    int res = 1e6;

    void dfs(int u, int cnt){
        //cout << u sp cnt sp res << endl;
        if(u == 1){
            chmin(res, cnt);
            return;
        }
        visit[u] = 1;
        for(auto const& e : a[u]){
            if(visit[e]) continue;
            dfs(e, cnt+1);
        }
    }

	void solve(std::istream& in, std::ostream& out)
	{
	    int n, ina;
	    in >> n;
	    for(int i=0; i<n; i++){
	        in >> ina;
	        ina--;
	        a[i].push_back(ina);
	    }

	    visit.assign(100010, 0);
	    dfs(0, 0LL);

	    if(res == 1e6) out << -1 << endl;
	    else out << res << endl;
	}
};


int main() {
	BTrained solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 8320
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    ll ans = 0;
    rep(i,n-1){
        ans += min(a*(x[i+1]-x[i]), b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3972
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long ans = 1;
		int mod = (int) Math.pow(10, 9) + 7;
		for (int i = 2; i <= n; i++) {
			for (int j = 2; (i % j != 0 && j < i) || j == i; j++) {
				if (j == i) {
					int s = 0;
					for (int k = 1; k <= n; k++) {
						s += findS(k, i);

					}

					ans = (ans * (s + 1) ) % mod;

				}
			}
		}
		System.out.println(ans);
	}

	private static int findS(int k, int i) {
		int s = 0;
		for (int j = k; j % i == 0; j /= i) {

			s++;

		}
		return s;
	}
}

Measured memory_bytes: 22868
#include <iostream>
#define REP(i, a, n) for(int i = (a); i <= n; i++)
#define INF 100000000
using namespace std;

int N, M, C, S, G;
int D[21][101][101];
int P[51], Q[21][51], R[21][51];
int cost[101][101];

int main(void) {
  while(cin >> N >> M >> C >> S >> G, N) {
    REP(i, 1, C) REP(j, 1, N) REP(k, 1, N) D[i][j][k] = INF;
    REP(i, 1, C) REP(j, 1, N) D[i][j][j] = 0;
    REP(i, 1, M) {
      int x, y, d, c; cin >> x >> y >> d >> c;
      D[c][x][y] = min(D[c][x][y], d);
      D[c][y][x] = min(D[c][x][y], d);
    }

    REP(c, 1, C) {
      REP(k, 1, N) REP(i, 1, N) REP(j, 1, N) {
        D[c][i][j] = min(D[c][i][j], D[c][i][k] + D[c][k][j]);
      }
    }

    REP(i, 1, C) cin >> P[i];
    REP(i, 1, C) {
      REP(j, 1, P[i] - 1) cin >> Q[i][j];
      REP(j, 1, P[i]) cin >> R[i][j];
    }
    REP(i, 1, N) REP(j, 1, N) cost[i][j] = INF;
    REP(i, 1, N) cost[i][i] = 0;
    REP(c, 1, C) {
      int k = 1;
      int d[2000001];
      d[0] = 0;
      REP(i, 1, 2000000) {
        if(k < P[c] && i > Q[c][k]) k++;
        d[i] = d[i - 1] + R[c][k];
      }
      REP(i, 1, N) REP(j, 1, N) {
        if(D[c][i][j] >= INF) continue;
        cost[i][j] = min(cost[i][j], d[D[c][i][j]]);
      }
    }

    REP(k, 1, N) REP(i, 1, N) REP(j, 1, N) {
      cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
    }

    cout << (cost[S][G] >= INF ? -1 : cost[S][G]) << endl;
  }

  return 0;
}

Measured memory_bytes: 11760
/*Alohomora*/
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define mod1       1000000007
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll fact(ll n){ if(n==0){return 1;}return (n*fact(n-1))%mod1;}
ll power(ll x, ll y,ll mod){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod1-2,mod1);}
ll gcd(ll a,ll b){if(b==0){return a;}gcd(b,a%b);}
ll a[2000000];
void sieve(){ll i,j;fli(i,2,1000001){if(a[i]==0){for(j=i*i;j<1000001;j+=i){a[j]=1;}}}}
map<ll,vector<ll> >m1;
vector<ll>v1;
bool compar(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second);
} 
ll level[1000000];
vector<ll>root;
set<ll>s1;
void factorise(long long n) 
{ 
    while (!(n%2)) 
    { 
        n >>= 1; 
        s1.insert(2);
    } 
    for (long long i=3; i<=sqrt(n); i+=2) 
    { 
        while (n%i==0) 
        { 
        	s1.insert(i);
            n=n/i; 
        } 
    } 
  	if (n>2) 
  	{
       s1.insert(n);
	}
} 
void comp()
{
	ll i,j,k,m,n,temp,t1,t2,t3;
	cin>>t1>>t2;
	if((t1+t2)%2)
	cout<<"IMPOSSIBLE\n";
	else
	cout<<(t1+t2)/2<<"\n";	

}	 
int main()
{
	speedup;
	ll i=0,t;
	ll n;
	//cin>>t;
	t=1;
	while(t--)
	{
	 comp();
	}
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

std::map<long long, int> primeFact(long long n) {
    std::map<long long, int> res;
    for (long long i=2; i*i<=n; i++) {
        while (n%i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) {
        res[n] = 1;
    }
    return res;
}

long long inv(long long n) {
    long long res = 1;
    while (n > 1) {
        res *= (MOD - MOD/n);
        res %= MOD;
        n = MOD % n;
    }
    return res;
}

void solve() {
    int n;
    ll m;
    cin >> n >> m;

    auto pf = primeFact(m);

    vector<ll> comb(31);
    ll nume = 1, deno = 1;
    for (int i=0; i<31; ++i) {
        comb.at(i) = nume * inv(deno) % MOD;
        nume *= n+i;
        nume %= MOD;
        deno *= i+1;
        deno %= MOD;
    }

    ll res = 1;
    for (auto iter=pf.begin(); iter!=pf.end(); ++iter) {
        res *= comb.at(iter->second);
        res %= MOD;
    }

    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf 1e9 + 1;
ll dp[1001][1001];
struct item{
    int wt,val;
};
ll solve(item arr[],int n,int W){
    int maxVal = n * 1000;
    int dp[n+1][maxVal+1];
    for(int v = 0;v<=maxVal;v++){
        dp[1][v] = inf;
    }
    dp[1][0] = 0;
    dp[1][arr[1].val] = arr[1].wt;
    for(int i=2;i<=n;i++)
    {
        for(int v = 0;v<=maxVal;v++){
            dp[i][v] = dp[i-1][v];
            if(arr[i].val > v){
                continue;
            }
            else{
                dp[i][v] = min(dp[i][v],arr[i].wt + dp[i-1][v-arr[i].val]);
            }
        }
    }
    int ans = 0;
    for(int i=0;i<=maxVal;i++){
        if(dp[n][i] <= W){
            ans = i;
        }
    }
    return ans;
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,W;
    cin>>n>>W;
    item arr[n+1];
    for(int i=1;i<=n;i++){
        cin >> arr[i].wt >> arr[i].val;
    }
    cout<<solve(arr,n,W)<<endl;
    return 0;
}

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

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  ll ans=1e18;
  for(ll i=0;i<(1<<n);i++) {
    bitset<15> b(i);
    vector<ll> aa(n);
    ll tans=0;
    ll temp=a[0];
    for(ll j=0;j<n;j++) {
      if(j!=0&&b.test(j)) {
        aa[j]=max(a[j],temp+1);
        tans+=aa[j]-a[j];
      }
      else {
        aa[j]=a[j];
      }
      temp=max(temp,aa[j]);
    }
    ll count=0;
    temp=0;
    for(ll j=0;j<n;j++) {
      if(temp<aa[j]) {
        count++;
      }
      temp=max(temp,aa[j]);
    }
    if(count>=k) {
      ans=min(ans,tans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        h:usize,
        w:usize,
        ch:usize,
        cw:usize,
        dh:usize,
        dw:usize,
        s:[Chars;h],
    }
    let (ch, cw) = (ch - 1, cw - 1);
    let (dh, dw) = (dh - 1, dw - 1);
    let mut dist = vec![vec![std::i32::MAX; w]; h];
    dist[ch][cw] = 0;
    let mut bfs = VecDeque::new();
    bfs.push_back(State::new((ch, cw), 0));
    let directions = vec![(1, 0), (-1, 0), (0, 1), (0, -1)];
    while let Some(State {
        now: (x, y),
        cost: c,
    }) = bfs.pop_front()
    {
        if dist[x][y] < c {
            continue;
        }
        for &d in directions.iter() {
            match next((x, y), d, h, w) {
                Some((nx, ny)) => {
                    if s[nx][ny] == '#' {
                        continue;
                    } else {
                        if dist[nx][ny] > dist[x][y] {
                            dist[nx][ny] = dist[x][y];
                            bfs.push_front(State::new((nx, ny), dist[x][y]));
                        }
                    }
                }
                None => {}
            }
        }
        for dx in -2..=2 {
            for dy in -2..=2 {
                match next((x, y), (dx, dy), h, w) {
                    Some((nx, ny)) => {
                        if s[nx][ny] == '#' {
                            continue;
                        } else {
                            if dist[nx][ny] > dist[x][y] + 1 {
                                dist[nx][ny] = dist[x][y] + 1;
                                bfs.push_back(State::new((nx, ny), dist[x][y]));
                            }
                        }
                    }
                    None => {}
                }
            }
        }
    }
    let ans = dist[dh][dw];
    if ans == std::i32::MAX {
        println!("{}", -1);
    } else {
        println!("{}", ans);
    }
}

struct State {
    now: (usize, usize),
    cost: i32,
}
impl State {
    pub fn new(now: (usize, usize), cost: i32) -> Self {
        State { now, cost }
    }
}

fn next(from: (usize, usize), to: (i32, i32), h: usize, w: usize) -> Option<(usize, usize)> {
    let (h, w) = (h as i32, w as i32);
    let (x, y) = (from.0 as i32, from.1 as i32);
    let (dx, dy) = to;
    let (nx, ny) = (x + dx, y + dy);
    let det = nx >= 0 && nx < h && ny >= 0 && ny < w;
    if det {
        Some((nx as usize, ny as usize))
    } else {
        None
    }
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i = 0; i < n; ++i) cin >> h.at(i);
  
  sort(h.begin(), h.end());
  int ans = h.at(n-1);
  for(int i = 0; i < n - k + 1; ++i){
    ans = min(ans, h.at(i+k-1) - h.at(i));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define P pair<int, int>
#define PP pair<int,pair<int, int>>
#define pb push_back
#define pp pop_back
#define lson root << 1
#define INF (int)2e9 + 7
#define rson root << 1 | 1
#define LINF (unsigned long long int)1e18
#define mem(arry, in) memset(arry, in, sizeof(arry))
using namespace std;

int main()
{
    string s;
    int x;
    cin >> s >> x;
    int n = s.size();
    for(int i = 0; i < n; i += x) cout << s[i];
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n,h,w;
    cin >> n >> h >> w;
    int ans = 0;
    int a,b;
    REP(i,n){
        cin >> a >> b;
        if(a >= h && b >= w){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

  map<int,vector<vector<int>>> uvw;
  //uvw[u] = vector of {vertex v connected to u, weight w of the edge u-v }
  REP(i, N-1){
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--; //0-indexed
    w = w%2;
    uvw[u].push_back({v,w});
    uvw[v].push_back({u,w});
  }

  vector<bool> visited(N, false);
  vector<int> stack = {0};
  vector<int> dist(N, 0);

  while(!stack.empty()){
    int from = stack.back();
    stack.pop_back();
    visited.at(from) = true;

    for(vector<int> v: uvw[from]){
      int to = v.at(0);
      int weight = v.at(1);
      if(visited.at(to)) continue;
      stack.push_back(to);
      dist.at(to) = (dist.at(from) + weight)%2;
    }
  }

  REP(i,N){
    printf("%d\n", dist.at(i)%2);
  }
}


Measured memory_bytes: 21376
from itertools import permutations

n = int(input())

lis = [list(map(int, input().split())) for _ in range(n)]

s = 0
count = 0

for i in permutations(range(n), n):
    count += 1
    for a, b in zip(i, i[1:]):
        s += ((lis[a][0] - lis[b][0])**2 + (lis[a][1] - lis[b][1])**2) ** 0.5

print(s/count)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

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

    while(k)
    {
        while(k and a>=b) b*=2,k--;
        while(k and b>=c) c*=2,k--;
        if(a<b and b<c) break;
        if(k==0) break;
    }
    if(a<b and b<c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3620