akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 100000 + 5;
const int M = 3000 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline ll read() {
    ll res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

int n, m;
std::pair<ll, ll> a[N];
ll ans;

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%lld %lld", &a[i].fir, &a[i].sec);
    }
    std::sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        ll tmp = m > a[i].sec ? a[i].sec : m;
        ans += a[i].fir * tmp;
        m = std::max(0ll, m - a[i].sec);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#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 = 1e5+23;

int h[N];
pair<int, int> a[N];

void solve() {
  int n, m; scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &a[i].second, &a[i].first);
    ++h[a[i].second];
  }
  for (int i = 1; i <= n; ++i) {
    h[i] += h[i-1];
  }
  sort(a, a+m);
  int prev = 0, ans = 0;
  for (int i = 0; i < m; ++i) {
    if (h[a[i].first-1] == h[prev]) continue;
    if (a[i].second <= prev) continue;
    ++ans;
    prev = a[i].first-1;
  }
  printf("%d", ans);
}

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


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

int main()
{
  long long int x, y;
  cin >> x >> y;
  long long int ans = 0;
  if (x >= 0 && y >= 0 && y >= x)
  {
    cout << y - x << endl;
  }
  else if (x >= 0 && y >= 0 && x > y)
  {
    ans = min((x - y + 2), (1 + y - (-x)));
    cout << ans << endl;
  }
  else if (x < 0 && y < 0 && x >= y)
  {
    ans = 2 + abs(y) - abs(x);
    cout << ans << endl;
  }
  else if (x < 0 && y < 0 && x < y)
  {
    ans = y - x;
    cout << ans << endl;
  }
  else if (x >= 0 && y < 0)
  {
    if (abs(x) >= abs(y))
    {
      ans = 1 + y - (-x);
      cout << ans << endl;
    }
    else
    {
      ans = (-y) - x + 1;
      cout << ans << endl;
    }
  }
  else if (x < 0 && y >= 0)
  {
    if (abs(x) < abs(y))
    {
      ans = (1 + y - (-x));
      cout << ans << endl;
    }
    else
    {
      ans = min(((-y) - x + 1), y - x);
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1000000007;

int main(){
    int n,q;
    cin>>n>>q;
    Graph tree(n);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int> ans(n,0);//まず根のみ加点して探索しつつ配点していく
    rep(i,q){
        int p,x;
        cin>>p>>x;
        p--;
        ans[p]+=x;
    }
    vector<int> seen(n,-1);
    seen[0]=0;
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(auto nv:tree[v]){
            if(seen[nv]==-1){
                que.push(nv);
                seen[nv]=seen[v]+1;
                ans[nv]+=ans[v];
            }
        }
    }
    rep(i,n) cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 16372
#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);
}

void solve() {
  int h, w, a, b; scanf("%d%d%d%d", &h, &w, &a, &b);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (i < b && j < a) putchar('1');
      else if (i >= b && j >= a) putchar('1');
      else putchar('0');
    }
    putchar('\n');
  }
}

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


Measured memory_bytes: 3676
# -*- coding: utf-8 -*-
import statistics

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

def argmin(z):
    min_idx = 0
    min_val = 10000
    for k, v in enumerate(z):
        if min_val > v:
            min_idx = k
            min_val = v
    return min_idx, min_val

m = statistics.mean(a)
z = [abs(b - m) for b in a]

k, v = argmin(z)
print(k)


Measured memory_bytes: 5784
from subprocess import *
cmd=['pypy3','-c',"""
from collections import deque
N=int(input())
G=[[] for i in range(N)]
a=[0 for i in range(N-1)]
b=[0 for i in range(N-1)]
edges=dict()
for i in range(N-1):
    a[i],b[i]=map(int,input().split())
    a[i]-=1;b[i]-=1
    G[a[i]].append(b[i])
    G[b[i]].append(a[i])
    edges[(min(a[i],b[i]),max(a[i],b[i]))]=i
M=int(input())
u=[0 for i in range(M)]
v=[0 for i in range(M)]
for i in range(M):
    u[i],v[i]=map(int,input().split())
    u[i]-=1;v[i]-=1
root=[0 for i in range(M)]
for i in range(M):
    q=deque([u[i]])
    parents=[-1 for i in range(N)]
    reached=[0 for i in range(N)]
    while(len(q)>0):
        r=q.popleft()
        reached[r]=1
        for p in G[r]:
            if reached[p]==1:
                continue
            parents[p]=r
            q.append(p)
    x=v[i]
    while(1):
        if parents[x]==-1:
            break
        s=min(x,parents[x])
        t=max(x,parents[x])
        root[i]+=2**edges[(s,t)]
        x=parents[x]
ans=0
def cnt(x):
    ans=0
    for i in range(M):
        if x|(2**i)==x:
            ans+=1
    return ans
q=deque([])
q.append(0)
S=[0 for i in range(2**M)]
reached=[0 for i in range(2**M)]
while(len(q)>0):
    i=q.popleft()
    for j in range(M):
        if i&(2**j)==0:
            S[i|(2**j)]=S[i]|root[j]
            if reached[i|(2**j)]==0:
                q.append(i|(2**j))
                reached[i|(2**j)]=1
    ans+=(-1)**(cnt(i))*2**(N-bin(S[i]).count("1")-1)
print(ans)
"""]
call(cmd)

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

int main(){
    int64_t A, B;
    int64_t res;
    // vector<int64_t> vp;
    // int64_t vp[100010];
    // string res;


    cin >> A >> B;
    // for (int i=0; i<N; i++){
    //     cin >> vp[i];
    // }

    int64_t subAB = A - B;
    if (subAB % 2 != 0) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    res = (subAB > 0)? B + subAB/2 : A - subAB/2 ;

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
template<class T> inline int add(T& a, T b, T M = MOD){a%=M;b%=M;a+=b;if(a>=M)a%=M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){a%=M;b%=M;a*=b;if(a>=M)a%=M;return a;};

string s;int dp[110000][13];
signed main(){
  cin>>s;int n = s.length();
  reverse(s.begin(), s.end());
  s = '#' + s;dp[0][0] = 1;
  int d = 1;
  repd(i,1,n+1){
    rep(j,13){
      rep(k,10){
        if(s[i] != '?' && s[i] != (char)('0'+k))continue;
        int m = (j-(k*d)%13+13)%13;
        add(dp[i][j], dp[i-1][m]);
      }
    }
    mul(d, 10LL, 13LL);
  }

  cout << dp[n][5] << endl;
}


Measured memory_bytes: 10748
// inputに入力データ全体が入る
function Main(input) {
  	
  	const reverse = (s) => {
      return s.split("").reverse().join("");
    };
  	
  	var WORDS = ["dream", "dreamer", "erase", "eraser"].map(reverse);
  	var S = reverse(input.split("\n")[0]);
  	var S_org = reverse(input.split("\n")[0]);
  	var word = "";
  	var T = ""; // 結果
  	var length = 0;
  	
  	// 一文字ずつ追加していきWORDSに一致するものがあるかどうか判定する
    // 見つかったらカウンタをリセットする、文字列も削る
  while(S.length>5){
      	word += S[length];
    
    	var result = -1;
    	var idx = 0;
    	// 文字が含まれるか検索
    	for(var i=0; i<WORDS.length; i++){
          // 一致する文字があるかどうか確かめる
          idx = word.indexOf(WORDS[i]);
          // 無かったら次へ
          if(idx == -1){
          	continue; 
          }
          // 余分な文字を削除し完全一致するか判定
          if(word.slice(idx) === WORDS[i]){
		  	result = i;
          }
        }
      	// 一致したものがあるとき
      	if(result != -1){
        	T += WORDS[result];  // 前に文字列を追加
          	S = S.slice(length);// 追加した文字までを削除する
          	word = ""   // 文字のリセット
          	length = 0; // カウントのリセット
        }
      	length += 1;
	}
  
  	// SとTが一致するとき
  	if(S_org == T){
      console.log("YES");
    // しないとき
    }else{
      console.log("NO");
    }
}

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

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

int main(){
  int H, N;
  cin >> H >> N;
  constexpr const int M = 1<<4;
  vector<int> dp(M,-1);
  vector<vector<int>> X(H);
  for(int i = 0; i < N; ++i){
    int x, y;
    cin >> x >> y;
    X[y].push_back(x);
  }
  int bit = 0;
  for(auto x : X[0]){
    bit |= 1<<x;
  }
  dp[bit] = 0;
  for(int i = 0; i < H-1; ++i){
    vector<int> dp_(M,-1);
    int bit_ = 0;
    for(auto x : X[i+1]){
      bit_ |= 1<<x;
    }
    for(int j = 0; j < M; ++j){
      if((bit&j) != bit) continue;
      for(int k = 0; k < 3; ++k){
        if(dp[j] < 0) continue;
        int tmp = bit_;
        if((j>>k&1) or (j>>(k+1)&1)) continue;
        if((tmp>>k&1) or (tmp>>(k+1)&1)) continue;
        tmp |= 1<<k;
        tmp |= 1<<(k+1);
        dp_[tmp] = dp[j]+1;
      }
    }
    if(bit == 0 and bit_ == 0 and dp[0] >= 0){
      dp_[M-1] = dp[0]+2;
    }
    dp_[bit_] = max(dp_[bit_],*max_element(dp.begin(), dp.end()));
    swap(bit,bit_);
    swap(dp,dp_);
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;
}



Measured memory_bytes: 3484
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  string s;
  cin >> s;
  rep(i, 3){
    if(s[i] == '1') cout << '9';
    else cout << '1';
  }
  cout << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	ns := make([]int, 4)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d %d", &ns[0], &ns[1], &ns[2], &ns[3])

	sort.Sort(sort.IntSlice(ns))
	if ns[0] == 1 && ns[1] == 4 && ns[2] == 7 && ns[3] == 9 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

int main() {
	int a, b, c, x, y, answer = 0;
	cin >> a >> b >> c >> x >> y;
	while (x >= 1 || y >= 1) {
		if (x >= 1 && y >= 1) {
			answer += min(c * 2, a + b);
			x--;
			y--;
		}
		else if (x >= 1) {
			answer += min(c * 2, a);
			x--;
		}
		else if (y >= 1) {
			answer += min(c * 2, b);
			y--;
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 1e9+7;
int N;
double p[3004];
double DP[3004][3004]; // iまで考慮してj回勝利した時の確率

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

  cin >> N;
  rep(i, N) cin >> p[i];
  DP[0][0] = 1.0;
  rep(i, N+1) {
    if (i==0) continue;
    rep(j, i+1) { // i回目の時は0回からi+1回までのi+2通りある。
      if (j==0) {
        DP[i][j] = (1.0-p[i-1])*DP[i-1][j];
        continue;
      }
      DP[i][j] = (1.0-p[i-1])*DP[i-1][j] + p[i-1]*DP[i-1][j-1];
    }
  }

  double ans = 0.0;
  for (int i=N/2+1; i<N+1; i++) {
    ans += DP[N][i];
  }
  cout << setprecision(10) << ans << "\n";
  return 0;
}

Measured memory_bytes: 68992
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt int

func main() {
	var x uint64
	fmt.Scan(&x)

	// 5を上に向けて置く
	// その後，5-->6-->5-->6-->...を繰り返す
	// 2ターンで得られるポイントは11

	if x%11 == 0 {
		fmt.Println((x / 11) * 2)
	} else {
		if x%11 <= 6 {
			fmt.Println((x/11)*2 + 1)
		} else {
			fmt.Println((x/11)*2 + 2)
		}
	}
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) < abs(a[j]) }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1,tt;
const ll nax=2e18;
void solve(){
	ll n, tot=0, m, ans=0;
	cin>>n>>m;
	vector<ll> v(n);
	rep(i,0,n){
		cin>>v[i];
		tot+=v[i];
	}
	rep(i,0,n){
		if(4*m*v[i]>=tot)ans++;
	}
	ans>=m?cout<<"Yes":cout<<"No";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	//cin>>t;
    while(t--){
        solve();
    }
    return 0 ;
}


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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  int tmp = 0;
  for (int i = 0; i < 3; i++)
  {
    if(s[i]=='R') ans++;
    else{
      tmp=max(tmp,ans);
      ans=0;
    }
  }
  cout << max(ans,tmp) << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
ll A, B, K;

void solve() {
	
	cin >> A >> B >> K;

	for (int i = 0; i < K; i++) {
		if (i % 2 == 0) {
			A /= 2;
			B += A;
		}
		else {
			B /= 2;
			A += B;
		}
	}

	cout << A << ' ' << B << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long ll;

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

	map<int, set<int>> friends;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		friends[a].insert(b);
		friends[b].insert(a);
	}

	int ans = 0;

	vector<bool> visited(n, false);
	for (int s = 0; s < n; ++s) {
		if (visited[s]) continue;

		queue<int> q;
		q.push(s);

		int cnt = 0;

		while (!q.empty()) {
			int x = q.front();
			q.pop();

			if (visited[x]) continue;
			++cnt;
			visited[x] = true;

			for (auto y : friends[x]) q.push(y);
		}

		ans = max(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}


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

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

    vector<int> degree(n);
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;

        degree[a] += 1;
        degree[b] += 1;
    }

    for(int i=0; i<n; i++){
        if(degree[i] % 2 == 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3792
import math

n=int(input())

def keta(n):
    return int(math.log10(n)+1)
def max(a,b):
    if a>b :return a
    else: return b

result=100
for i in range(1,math.ceil(math.sqrt(n)+3)):
    if n%i==0 and result>max(keta(i),keta(n//i)):
        result=max(keta(i),keta(n//i))
print(result)


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int h, n;
    cin >> h >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vi dp(20001, INF);
    dp[0] = 0;
    rep(i, n) {
        rep(j, 20001) {
            if (j-a[i]<0 || dp[j-a[i]]==INF) continue;
            dp[j] = min(dp[j], dp[j-a[i]]+b[i]);
        }
    }
    int ans = INF;
    for (int i=h; i<=20000; ++i) ans = min(ans, dp[i]);
    cout << ans << endl;
    return 0;
}


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

int main ()
{
    int K,N;
    vector<long> h;
    cin >> N >> K;
    long tmp;
    for(int i=0;i<N;i++){
        cin >> tmp;
        h.push_back(tmp);
    }
    sort(h.begin(),h.end());
    long ans=1000000009;
    for(int i=0;i<N-K+1;i++){
        ans=min(ans,h.at(K+i-1)-h.at(i));
    }
    cout << ans <<endl;
}












Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

ll n;
ll a[100005];

bool f(ll p)
{
    ll t = a[p];
    for(ll i = 0; i < n; i++)
    {
        if(p == i) continue;
        if(t * 2 < a[i]) return false;
        t += a[i];
    }
    return true;
}

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }
    sort(a, a + n);
    ll lt = 0, rt = n - 1, mid, ans = n;
    while(lt <= rt)
    {
        mid = (lt + rt) / 2;
        if(f(mid)) ans = mid, rt = mid - 1;
        else lt = mid + 1;
    }
    printf("%lld\n", n - ans);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll n;
    cin >> n;
    vector<string> W(n);
    for (auto & w : W) {
        cin >> w;
    }

    bool ok = true;
    set<string> used;
    used.insert(W[0]);
    for (ll i = 1; i < n; ++i) {
        if (W[i][0] != W[i-1][W[i-1].length()-1]) {
            ok = false;
            break;
        }
        if (used.find(W[i]) != used.end()) {
            ok = false;
            break;
        }
        used.insert(W[i]);
    }

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}


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

int main(){
	int n,m;
	cin >> n;
  	vector<int> a(n);
	for(int i = 0; i< n;i++) {
    	cin >> a[i];
    }
  	int count = 0;
	for(int i = 0; i < n-1; i++) {
		if(a[i] != i+1)
          	count++;
    }
  	cout << (count > 2 ? "NO" : "YES")<< endl;
	
}


Measured memory_bytes: 256
#!/usr/bin/env python3

def solve(a,b):
  str1 = str(a)*b
  str2 = str(b)*a
  if str1 < str2:
    return str1
  else:
    return str2



def main():
  a,b = map(int,input().split())
  print(solve(a,b))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9100
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int W = scan.nextInt();
        int H = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        int r = scan.nextInt();
        
        if(r <= x && x <= (W-r) && r <= y && y <= (H-r)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26268
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define all(c)          c.begin(), c.end()
#define int             long long
#define ff              first
#define ss              second
#define nl              '\n'

int32_t main()
{
	ninja
	int t; 
	int s,w; cin>>s>>w;
	if(s>w)
		cout<<"safe";
	else
		cout<<"unsafe";
}



Measured memory_bytes: 3640
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

void Main() {
  int n; cin >> n;
  int a = n / 100, b = n % 100;
  bool f1 = (1 <= a && a <= 12);
  bool f2 = (1 <= b && b <= 12);
  if(f1 && f2) {
    cout << "AMBIGUOUS\n";
  } else if(f1) {
    cout << "MMYY\n";
  } else if(f2) {
    cout << "YYMM\n";
  } else {
    cout << "NA\n";
  }
}

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

typedef long long ll;
#define INF 1000000000
#define MOD 1000000007

using namespace std;

ll dp[100001];

int main() {
	ll n;
	cin >> n;
	ll h[n];
	for (int i = 0; i < n; i++) cin >> h[i];

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
	    dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
	}
	cout << dp[n-1] << endl;
}


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

class AIZU0025{
   public static void Translate(string s, out List<int> b) {
      b=new List<int>();
      string[] ss=s.Split(' ');
      foreach (string s1 in ss) b.Add(int.Parse(s1));
   }
   public static void Main(string[] args) {
      List<int> Target=new List<int>(), Query=new List<int>();
      Queue<string> G=new Queue<string>();
      string s;int hit, blow;
      string[] ss;
      while(true) { 
         s = Console.ReadLine();
         if (string.IsNullOrEmpty(s)) break;
         ss=s.Split(' ');
         if (ss.Length<4) break;
         for (int I = 0; I<4; I++) Target.Add(int.Parse(ss[I]));
         s = Console.ReadLine();
         if (string.IsNullOrEmpty(s)) break;
         ss=s.Split(' ');
         if (ss.Length<4) break;
         for (int I = 0; I<4; I++) Query.Add(int.Parse(ss[I]));
         hit = Hit(Target,Query);
         blow = Target.Intersect(Query).Count()-hit;
         G.Enqueue(string.Format("{0} {1}",hit,blow));
         Target.Clear();Query.Clear();
      }
      while (G.Count>0) Console.WriteLine(G.Dequeue());
   }
   public static int Hit(List<int> Target,List<int> Query) {
      int res = 0;
      for (int i = 0; i<4; i++)
         if (Target[i]==Query[i]) 
            res++;
      return res;
   }
}

Measured memory_bytes: 10940
n = int(input())
a = input()
b = input()
if a[0]==b[0]:
    ans = 3
else:
    ans = 6
l = []
k = 0
while k<n:
    if k==n-1:
        l.append(1)
        k += 1
    elif a[k]==a[k+1]:
        l.append(0)
        k += 2
    else:
        l.append(1)
        k += 1
for i in range(1,len(l)):
    if l[i]==1 and l[i-1]==1:
        ans *= 2
    elif l[i]==0 and l[i-1]==1:
        ans *= 2
    elif l[i]==0 and l[i-1]==0:
        ans *= 3
print((ans)%(10**9+7))

Measured memory_bytes: 38256
#include <iostream> 
#include <vector> 
using namespace std; 
  
int main() 
{
  float d,t,s;
  cin>>d>>t>>s;
  float speed=d/t;
  if(speed<=s)
  {
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3720
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    in();
    string s;cin>>s;
    cout<<count(s.begin(),s.begin()+count(s.begin(),s.end(),'R'),'W')<<endl;
}


Measured memory_bytes: 3752
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second   
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef vector<int> vi;
typedef pair<int, int> pii; 
typedef pair<int , pii> piii ; 
typedef unsigned long long ull ;


void solve()
{
    int h , w;
    cin >> h >> w;
    if(min(h , w) == 1){
        cout << 1; 
        return ;
    }
    h = h * w ;
    h = (h + 1)/2 ;
    cout << h; 
}   

     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

// longlong??§??£?¨?????????¨??????INT_MAX???????????´
template<class V> class segtree {
private:
    int n,sz;
    vector<V> node;
public:
    segtree(vector<V> v){
        sz = (int)v.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n-1);
        rep(i,sz){
            node[i+n-1] = v[i];
        }
        for(int i=n-2; i>=0; i--){
            node[i] = min(node[i*2+1],node[i*2+2]);
        }
    }
    void update(int k,int a)
    {
    	k += n-1;
    	node[k] = a;
    	while(k>0){
    		k = (k-1)/2;
    		node[k] = min(node[2*k+1],node[2*k+2]);
    	}
    }
    V query(int a,int b,int k=0,int l=0,int r=-1)
    {
        if(r < 0) r = n;
    	if(r <= a || b <= l){
    		return INT_MAX;
    	}
    	if(a <= l && r <= b){
    		return node[k];
    	}else{
    		V vl = query(a,b,2*k+1,l,(l+r)/2);
    		V vr = query(a,b,2*k+2,(l+r)/2,r);
    		return min(vl,vr);
    	}
    }
    void print()
    {
        rep(i,sz){
            cout << query(i,i+1) << " ";
        }
        cout << endl;
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    segtree<int> st(vector<int>(n,INT_MAX));
    rep(i,q){
        int a,b,c;
        cin >> a >> b >> c;
        if(a == 0){
            st.update(b,c);
        }else{
            cout << st.query(b,c+1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main()  {
    fastio;
    int x;
    cin>>x;
    if(x >= 30) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3608
# n = gets.to_i
a,b,c = gets.split.map(&:to_i)

if a < b
  if (a..b).include?(c)
    puts "Yes"
  else
    puts "No"
  end
else
  if (b..a).include?(c)
    puts "Yes"
  else
    puts "No"
  end
end


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n,k;
    cin >> n >> k;
    bool flag[101][101];

    if((n-1)*(n-2)/2 < k){
        cout << -1 << endl;
        return 0;
    }

    rep(i,101){
        rep(j,101){
            flag[i][j] = false;
        }
    }

    reps(i,1,n){
        flag[0][i] = true;
    }
    int cnt = (n-2)*(n-1)/2;
    int edge = n-1;

    rep(i,n){
        reps(j,i+1,n){
            if(!flag[i][j]){
                flag[i][j]=true;
                cnt--;
                edge++;
            }
            if(cnt == k){
                break;
            }
        }
        if(cnt == k){
            break;
        }
    } 
    cout << edge << endl;

    rep(i,101){
        rep(j,101){
            if(flag[i][j]){
                cout << i+1 << " " << j+1 << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
using System;

namespace AOJ.Volume0
{
    public class Differential
    {
        public static int Main()
        {
            decimal high = 0;
            decimal low = 9999999999;
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                decimal tall = decimal.Parse(input);
                if (high < tall) { high = tall; }
                if (low > tall) { low = tall; }
            }

            Console.WriteLine(high - low);
            return 0;
        }
    }
}

Measured memory_bytes: 9360
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int ans = N;
        
        for(int i=1; i<N; i++){
            if(S.charAt(i)==S.charAt(i-1)){
                ans -= 1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 24756
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
    ($line:expr,$name:ident,$t:tt) => {
        let $name=value!($line,$t);
    };
    }

    macro_rules! values_def {
    ($lines:expr,$n:expr,$name:ident,$t:tt) => {
        let $name={
        let mut vec=Vec::new();
        for i in 0..$n{
            let mut next=$lines.next().unwrap().split_whitespace();
            vec.push(value!(next,$t));
        }
        vec
        };
    };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(a:i64 b:i64));
    if a > b { a - 1 } else { a }.to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "5 5" => "5",
    test2: "2 1" => "1",
    test3: "11 30" => "11",
}


Measured memory_bytes: 4352
//
// Created by yamunaku on 2019/07/14.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

class UnionFind{
    vi node;
public:
    UnionFind(int n){
        node=vi(n,-1);
    }
    int root(int x){
        if(node[x]<0) return x;
        return node[x]=root(node[x]);
    }
    bool uni(int x, int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(-node[x]<-node[y]) swap(x,y);
        node[x]+=node[y];
        node[y]=x;
        return true;
    }
};

int main(){
    int n,r;
    cin >> n >> r;
    vi p(n);
    UnionFind uf(n);
    rep(i,n){
        cin >> p[i];
        p[i]--;
        uf.uni(i,p[i]);
    }
    vi c(n);
    rep(i,n){
        c[uf.root(i)]++;
    }
    vi v;
    v.reserve(n);
    rep(i,n){
        if(c[i]>0) v.push_back(c[i]);
    }
    n=v.size();
//    sort(all(v));
    rep(i,n){
        if(v[i]==r){
            CYES;
            return 0;
        }
    }
    random_device seed_gen;
    mt19937 engine(seed_gen());
    int q=1e8/n;
    rep(_,q){
        shuffle(all(v), engine);
        int k=0,idx=0;
        while(k<r){
            k+=v[idx];
            idx++;
        }
        if(k==r){
            CYES;
            return 0;
        }
    }
    CNO;
    return 0;
}




Measured memory_bytes: 7472
#define watch5(a,b,c,d,e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d << " | "<<#e<<": "<<e<<endl;
#define watch4(a,b,c,d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define watch3(a,b,c) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define sharingan cerr << "\n-------------------------------------------\n\n";
#define watch2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
#define Yup ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(a) cerr <<#a<<": "<<a<<endl;
#define __gcd(a, b) __algo_gcd(a, b)
#define PI 3.14159265358979323846
#define mod 1000000007
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<array>
#include<cstdio>
#include<bitset>
#include<vector>
#include<utility>
#include<sstream>
#include<cstring>
#include <climits>
#include <fstream>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include <unordered_map>
using namespace std;

#define endl "\n"
#define int long long

int w, n;
int dp[101][100001];
int wt[101], v[101];

int go( int i, int left ){
    if( left < 0 )return INT_MIN;
    if( i == n || left == 0 )return 0;
    if( dp[i][left] != -1 )return dp[i][left];
    int ans = go(i+1, left-wt[i]) + v[i];
    ans = max(ans, go(i+1, left));
    return dp[i][left] = ans;
}

int32_t main(){
    Yup;
    cin >> n >> w;
    for( int i = 0; i < n; i++ ){
        cin >> wt[i] >> v[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << go(0, w);
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;
int x, a, b;

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

	int when = -a + b;
	
	if(when <= 0) {
		cout << "delicious";
	} else if(when <= x) {
		cout << "safe";
	} else {
		cout << "dangerous";
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c,ans=0;
    cin>>a>>b>>c;
    ans=a-b;
    if(ans>=c)cout<<0<<endl;
    else cout<<c-ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	//まず逆数の総和を求める。

	double A[100000];
	double total=0;
	int N;
	int i;

	scanf("%d", &N);

	for (i = 0; i < N; i++) {
		scanf("%lf", &A[i]);
	}

	for (i = 0; i < N; i++) {
		total = total + (1 / A[i]);
	}

	total= 1 / total;

	printf("%lf\n", total);

	return 0;


	
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
    int a,b,c,x = 0;
    scanf("%d %d %d",&a,&b,&c);
    if(a ==5 && b ==5 && c == 7) printf("YES\n");
    else if(a ==5 && b ==7 && c == 5)printf("YES\n");
    else if(a ==7 && b ==5 && c == 5)printf("YES\n");
    else printf("NO\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    int y=0;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[n];
        if(a[n]>=k)
            y++;
    }
    cout<<y;



    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
vector<int> v[100005];
LL val[100005];
LL Max[100005];
LL Min[100005];
int ok=1;
void dfs(int x,int f){
    if(v[x].size()==1&&f!=0){
        Min[x]=Max[x]=val[x];
        //Min[x]=val[x]&1;
        return ;
    }
    vector<pll> tmp;
    for(auto it:v[x]){
        if(it!=f){
            dfs(it,x);
            tmp.pb(mp(Max[it],Min[it]));
        }
    }
    for(auto& it:tmp){
        if(it.x%2==val[x]%2){
            it.x=min(it.x,val[x]);
        }
        else{
            it.x=min(it.x,val[x]-1);
        }
        if(it.x<it.y)ok=0;
    }
    LL a=0,b=0;
    for(auto &it:tmp){
        a+=it.x;
        b+=it.y;
    }
    a=2*val[x]-a;
    b=2*val[x]-b;
    if(a<0){
        if(a%2)a=1;
        else a=0;
    }
    if(b%2==val[x]%2)
        b=min(b,val[x]);
    else    
        b=min(b,val[x]-1);
    if(a>b){
        ok=0;
    }
    Min[x]=a;
    Max[x]=b;
   // printf("%d %d %d\n",x,Max[x],Min[x]);
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;i++)
        scanf("%lld",&val[i]);
    for(int i = 1;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].pb(y);
        v[y].pb(x);
    }
    if(n==2){
        if(val[1]==val[2]){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    else{
        for(int i=1;i<=n;i++){
            if(v[i].size()!=1){
                dfs(i,0);
                if(Min[i]!=0){
                    ok=0;
                }
                break;
            }
        }
        if(ok){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
}

Measured memory_bytes: 18688
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

N=int(input())
for h in range(1,3501):
    for n in range(1,3501):
        if (4*h*n-N*n-N*h)!=0 and (N*h*n)%(4*h*n-N*n-N*h)==0 and 1<=(N*h*n)//(4*h*n-N*n-N*h)<=3500:
            w=(N*h*n)//(4*h*n-N*n-N*h)
            print(h,n,w)
            exit()



Measured memory_bytes: 41136
N = int(input())
a = [0] + [int(input()) for _ in range(N)]
ans = 0
idx = 1
flag = False
for i in range(N):
    ans += 1
    if a[idx] == 2:
        print(ans)
        flag = True
        break
    idx = a[idx]
else:
    print(ans if flag else -1)


Measured memory_bytes: 7888