akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
num = gets.strip.split.map(&:to_i)
for i in 1..n
  num[i-1] = num[i-1]-i
end
a = num.sort
if n%2==1
  b = a[(n-1)/2]
else
  b = (a[n/2-1]+a[n/2])/2
end
s = 0
for i in 0..n-1
  s += (a[i]-b).abs
end
puts s

Measured memory_bytes: 32956
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<vector<char>> c(h,vector<char>(w));
  vvi d(h,vector<int>(w));
  rep(i,h)rep(j,w) cin>>c[i][j];
  int ans=0;
  rep(i,h)rep(j,w){
    if(c[i][j]=='#'){
      d[i][j]=1;
    }
  }
  for(int i=0;i<pow(2,h);i++){
    for(int j=0;j<pow(2,w);j++){
      int count=0;
      for(int k=0;k<h;k++){
        for(int l=0;l<w;l++){
          if(i>>k&1) continue;
          if(j>>l&1) continue;
          count+=d[k][l];
        }
      }
      if(count==k) ans++;
    }
  }
  cout<<ans;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 10e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
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;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  int A,B;
  cin >> A >> B;
  int cnt = 0;
  FOR(i,1,10)
  {
    rep(j,10)
    {
      rep(k,10)
      {
        int tmp = 10001 * i + 1010 * j + k * 100;
        if(tmp >= A && tmp <= B)
        {
          cnt ++;
        }
      }
    }
  }
  cout << cnt <<endl;
}


Measured memory_bytes: 256
#pragma warning( disable : 6031)

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
const long long mod = 1000000007;
//const long long mod = 998244353;
using std::vector;
using std::pair;
using std::string;
using std::map;
int main() {
	int N;
	char* S = new char[200001];
	scanf("%s", S);
	for (N = 0; S[N] != 0; N++);
	int t = 1;
	int* m2019 = new int[2019]{ 1 };
	int m = 0;
	for (int i = N - 1; i >= 0; i--) {
		m = (m + (S[i] - '0') * t) % 2019;
		m2019[m]++;
		t = (t * 10) % 2019;
	}
	long long res = 0;
	for (int i = 0; i < 2019; i++) {
		res += m2019[i] * (m2019[i] - 1) / 2;
	}
	printf("%lld", res);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll mod_pow(ll a,ll n,ll mod){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll N,W,S,Q;
ll a[100010];
map<ll,ll> cnt;

int main(){
  while(1){
    cin>>N>>S>>W>>Q;
    if(N==0)break;
    cnt.clear();
    ll g=S;
    rep(i,N){
      a[i]=(g/7)%10;
      if(g%2==0) g=g/2;
      else g=(g/2)^W;
    }
    reverse(a,a+N);
    ll crtsum=0,res=0;
    if(Q==2||Q==5){
      rep(i,N){
        cnt[a[i]%Q]++;
        if(a[i]>0)res+=cnt[0];
      }
    }else{
      cnt[crtsum]++;
      rep(i,N){
        crtsum+=a[i]*mod_pow(10,i,Q);
        crtsum%=Q;
        if(a[i]>0)res+=cnt[crtsum];
        cnt[crtsum]++;
      }
    }
    cout<<res<<endl;
  }
  return 0;
}



Measured memory_bytes: 9472
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  while(1) {
    int m[6] = {500, 100, 50, 10, 5, 1};
    int n;
    cin >> n;
    if(n == 0) break;
    n = 1000 - n;
    int ans = 0;
    while(n > 0) {
      FOR(i,0,6) {
        if(n >= m[i]) {
          ans++;
          n -= m[i];
          break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3064
N = [int(i) for i in input().split()]
M = [int(i) for i in input().split()]

distanceList = []

distance = 0
for i in range(N[1]):
    M.append((M[i] + N[0]))

for i in range(len(M) - 1):
    distanceList.append(M[i + 1] - M[i])

print(N[0] - max(distanceList))

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    vector<string> a(n), b(m);
    rep(i, n) cin>>a[i];
    rep(i, m) cin>>b[i];
    for(int x=0; x<n; x++){
        if(x+m > n) continue;
        for(int y=0; y<n; y++){
            if(y+m > n) continue;
            bool isok = true;
            for(int i=0; i<m; i++){
                for(int j=0; j<m; j++){
                    if(isok && a[y+i][x+j] != b[i][j]){
                        isok = false;
                        break;
                    }
                }
            }
            if(isok) {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}
// abc054_b

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

C = sorted(Counter(A).items(), reverse = True)

edge = []
for k,v in C:
    if len(edge) >=2:
        break
    if v >= 2:
        for _ in range(v // 2):
            edge.append(k)
if len(edge) <= 1:
    print(0)
    exit()
print(edge[0] * edge[1])

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

int main() {
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    
    vector<pair<int, int>> A(N);
    for (int i = 0, a; cin >> a; i++) A.at(i) = {a, i + 1};
    
    sort(A.begin(), A.end());
    
    for (auto a : A) cout << a.second << "\n";
    
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200000];
int b[200000];
long long solve(int t) {
    long long cur = 0;
    int x = t;
    for (int i = 0; i < n; i++) {
        b[x] = a[i];
        x += 2;
        if (x >= n) {
            x = 1 - t;
        }
    }
    if (n % 2 == 1 && n > 2 && t == 1) {
        swap(b[n - 1], b[2]);
    }
    if (n % 2 == 1 && n > 2 && t == 0) {
        swap(b[0], b[n - 3]);
    }
    for (int i = 0; i + 1 < n; i++) {
        cur += abs(b[i] -b[i + 1]);
    }
    return cur;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    reverse(a, a + n);
    cout << max(solve(0), solve(1));
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>

using namespace std;

int main() {
  string s;
  long long k;
  cin >> s >> k;
  for (int i = 0; i < k; i++) {
    if (s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}


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

constexpr int INF = 1<<30;

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int amin = INF, dmax = 0, ans = 0;
    for(int i=0;i<N;i++){
        if(a[i]-amin > dmax){
            dmax = a[i] - amin;
            ans = 1;
        }
        else if(a[i]-amin == dmax){
            ans++;
        }
        amin = min(amin, a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6)

def DFS(v, parent):
  global v_count
  for u in adj[v]:
    if u != parent:
      v_count[u] += v_count[v]
      DFS(u,v)

N, Q = map(int, input().split())

adj = [[] for _ in range(N)]
v_count = [0] * N

for i in range(N-1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  adj[a].append(b)
  adj[b].append(a)# aがbの親とは限らないため

for j in range(Q):
  p, x = map(int, input().split())
  v_count[p-1] += x

# 0起点に親ノードの数字を子ノードに足していく
DFS(0, -1)# 現在のノード, 親ノード
print(*v_count)


Measured memory_bytes: 230960
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

A,B,C,D = map(int, input().split())

nrofC = (B // C) - ((A-1) // C)
nrofD = (B // D) - ((A-1) // D)

cdlcm = (C * D) // gcd(D,C)
nrofCD = (B // cdlcm) - ((A-1) // cdlcm)

print((B-(A-1)) - nrofC - nrofD + nrofCD)


Measured memory_bytes: 3064
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k,L;
ll cnt,a[200000],b[200000];
string s;
int main(void){
    cin>>n>>m>>k;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='o'){
            if(cnt<=i){
                a[L]=i;
                cnt=i+k+1;
                L++;
                if(L==m)break;
            }
        }
    }
    L=m-1;
    cnt=0;
    reverse(s.begin(),s.end());
    for(int i=0;i<s.size();i++){
        if(s[i]=='o'){
            if(cnt<=i){
                b[L]=n-i-1;
                cnt=i+k+1;
                L--;
                if(L==-1)break;
            }
        }
    }
    for(int i=0;i<m;i++){
        if(a[i]==b[i])cout<<a[i]+1<<endl;
    }
}


Measured memory_bytes: 4996
#include<bits/stdc++.h>
using namespace std;
int strint(string s){
	if(s=="SUN") return 7;
	if(s=="MON") return 6;
	if(s=="TUE") return 5;
	if(s=="WED") return 4;
	if(s=="THU") return 3;
	if(s=="FRI") return 2;
	if(s=="SAT") return 1;
}
int main(){
	string s;
	cin>>s;
	cout<<strint(s);
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc,char **argv) {
	char s[25];
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++){
		if(s[i]==','){
			s[i]=' ';
		}
	}
	printf("%s\n",s);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 

#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

const int N =1e5+5;

int mod= 1e9+7;
int dx[4]={0,0,+1,-1};
int dy[4]={+1,-1,0,0};

int a[N];


void solve(){
      int n,k;
	  cin>>n>>k;
   	
	 vi v(n,0); 	

	  rep(i,0,n)
		   cin>>v[i];

	  rep(i,0,k+1){		
		  rep(j,0,n){
		    if(i>=v[j] && !a[i-v[j]])
				 a[i]=1;
		}
	  }

	cout<<(a[k]==1?"First":"Second")<<endl;  

}

int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
		solve();


	return 0;	   
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}
 
int main() {
	int N; cin >> N;
	vector<int> A(N);
	rep(i, N) cin >> A[i];
	bool ans = true;
	for(int i = N - 2; i >= 0; --i) {
	    if(A[i + 1] >= A[i]) continue;
	    else if(A[i + 1] + 1 == A[i]) --A[i];
	    else ans = false;
	}
	if(ans) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 640
import collections

N = int(input())
S = list(input())

already = []
ans = 0

for i in range(N-2):
    tmp = []
    point = 1
    if S[i] not in already:
        already.append(S[i])
        while True:
            # print(S[i])
            # print(ans)
            # print(tmp)
            # print(S[i+point])
            if S[i+point] not in tmp:
                # print('aa')
                ans += len(set(S[i+point+1:]))
                # print(str(S[i])+str(S[i+point]))
                # print(set(S[i+point+1:]))
                # print(len(set(S[i+point+1:])))
                tmp.append(S[i+point])
            point += 1
            if i + point == N-1:
                break

print(ans)

Measured memory_bytes: 3852
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, k) = get!(usize, usize);
    let mut v: Vec<char> = get!(String).chars().collect();
    //eprintln!("{:?}", v);
    let c = v[k - 1] as u32 + 32;
    //eprintln!("{}", c);
    v[k - 1] = std::char::from_u32(c).unwrap();
    let mut ans = String::new();
    for i in 0..n {
        let tmp = v[i];
        //eprintln!("{:?}", tmp);
        ans += &tmp.to_string();
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <vector>
#include <queue>
using i64 = long long;

/*
 * delta(V v, fn (V t))
 * index(V v) -> int
 */
template<class V, class Delta, class Index>
std::vector<i64> bfs(std::size_t N, V s, Delta delta, Index index) {
  std::vector<i64> dist(N, -1);
  std::queue<V> que;
  dist[index(s)] = 0;
  que.push(s);
  while(!que.empty()) {
    V v = que.front();
    que.pop();
    delta(v, [&](V t) {
        if(dist[index(t)] == -1) {
          dist[index(t)] = dist[index(v)] + 1;
          que.push(t);
        }
    });
  }
  return dist;
}

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class F>
struct lattice_delta {
  i64 H, W;
  F f;
  using P = std::pair<i64, i64>;
  lattice_delta(i64 H, i64 W, F f): H(H), W(W), f(f) {}
  template<class Func>
  void operator()(P v, Func func) {
    const static vector<i64> dx { 1, 0, -1, 0 };
    i64 i = v.first;
    i64 j = v.second;
    for(i64 q = 0; q < 4; q++) {
      i64 x = i + dx[q];
      i64 y = j + dx[q ^ 1];
      if(0 <= x && x < H && 0 <= y && y < W && f(P(x, y))) {
        func(P(x, y));
      }
    }
  }
};

template<class F>
lattice_delta<F> make_lattice_delta(i64 H, i64 W, F f) { return lattice_delta<F>(H, W, f); }

struct lattice_index {
  i64 H, W;
  using P = std::pair<i64, i64>;
  lattice_index(i64 H, i64 W): H(H), W(W) {}
  i64 operator()(P v) {
    return v.first * W + v.second;
  }
};


int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  i64 H, W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,0,H) {
    cin >> S[i];
  }
  i64 ans = 0;
  using P = std::pair<i64, i64>;
  vector<i64> dx { 1, 0, -1, 0 };
  auto delta = make_lattice_delta(H, W, [&](P v) { return S[v.first][v.second] == '.'; });
  auto index = lattice_index(H, W);
  rep(i,0,H) rep(j,0,W) {
    if(S[i][j] == '#') continue;
    auto res = bfs(H * W, P(i, j), delta, index);
    ans = std::max(ans, *std::max_element(all(res)));
  }
  cout << ans << endl;
}


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

int main() {
  int n; cin >> n;
  vector<string> str(n);
  for(int i=0; i<n; ++i){
    string x; cin >> x;
    sort(x.begin(), x.end());
    str[i] = x;
  }

  sort(str.begin(), str.end());

  str.push_back("?????");

  long long same = 1,ans = 0;
  for(int i=1; i<n+1; ++i){
    if(str[i] == str[i-1]){
      ++same;
    }else{
      ans += same * (same-1) / 2;
      same = 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int a[MAXN];
long long b[MAXN];
int bit[MAXN];
int n;

void upd(int pos, int val){
    while(pos <= n + 1){
        bit[pos] += val;
        pos += pos & -pos;
    }
}

int get(int pos){
    int ret = 0;
    while(pos){
        ret += bit[pos];
        pos -= pos & -pos;
    }
    return ret;
}

map<long long, int> idx;
void compressB(){
    vector<long long> values;
    for(int i = 0; i <= n; i++)
        values.push_back(b[i]);
    sort(values.begin(), values.end());
    values.resize(unique(values.begin(), values.end()) - values.begin());
    for(int i = 0; i < values.size(); i++){
        idx[values[i]] = i + 1;
    }
    for(int i = 0; i <= n; i++){
        b[i] = idx[b[i]];
    }
}

long long countInversions(){
    long long ret = 0;
    for(int i = 0; i <= n; i++){
        ret += get(b[i]);
        upd(b[i], 1);
    }
    return ret;
}

int main()
{
    int k;
    scanf("%d %d", &n, &k);
    b[0] = -k;
    long long sum = 0;
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        sum += a[i];
        b[i] = sum - 1ll * (i + 1) * k;
    }
    compressB();
    printf("%lld\n", countInversions());
    return 0;
}


Measured memory_bytes: 16624
using System;
using System.Linq;

namespace Myatcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int[] A = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
            int n = A[0], m = A[1], x = A[2], y = A[3];
            int[] X = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
            int[] Y = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
            Array.Sort(X);
            Array.Sort(Y);
            if (X[n - 1] < Y[0] && x < Y[0] && X[n - 1] < y && x < y) Console.WriteLine("No War");
            else Console.WriteLine("War");
        }
    }
}

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

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi a(n), b;

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

		for(int i=0;i<n;i++)
		{
			auto it=upper_bound(b.begin(), b.end(), -a[i]);

			if(it==b.end())
			{
				b.push_back(-a[i]);
			}
			else
			{
				*it=-a[i];
			}
		}
//for(int mb:b) printf("%d ", mb); printf("\n");
		printf("%u\n", b.size());
	}
	return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back

using namespace std;
typedef long long ll;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vv(N);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    vv[a].PB(b);
    vv[b].PB(a);
  }

  vector<bool> flag(N, false);
  for (auto to : vv[0]) flag[to] = true;
  for (auto to : vv[N - 1]) {
    if (flag[to]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}

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

int main(){
int N;
int num[3],invnum[3],res,ans;

cin >> N;

num[0] = N/100;
res = N%100;

num[1] = res/10;

num[2] = res%10;


if(num[0] == num[1]){
if(num[1] >= num[2]){

invnum[0] = num[0];
invnum[1] = num[0];
invnum[2] = num[0];

}else{

invnum[0] = num[0]+1;
invnum[1] = num[0]+1;
invnum[2] = num[0]+1;


}
}else if(num[0] > num[1]){

invnum[0] = num[0];
invnum[1] = num[0];
invnum[2] = num[0];


}else{

invnum[0] = num[0]+1;
invnum[1] = num[0]+1;
invnum[2] = num[0]+1;


}




ans = invnum[0]*100+invnum[1]*10+invnum[2];

cout << ans << endl;
}


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

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    string S, T;
    cin >> S;
    cin >> T;

    int ans = -1;
    if(T.length() > S.length()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for(int i=0; i<S.length()+T.length()-1; i++){
        bool fl = true;
        for(int j=0; j<T.length(); j++){
            if(S[i+j] != '?' && S[i+j] != T[j]) fl = false;
        }
        if(fl) ans = i;
    }

    if(ans == -1){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for(int i=0; i<S.length(); i++){
        if(i >= ans && i < ans+T.length()){
            cout << T[i-ans];
        }else{
            if(S[i] == '?') cout << 'a';
            else cout << S[i];
        }
    }
    cout << endl;

    return 0;
}

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

int main() {
	bool flag = true;
	int a,b;
	char n[11];
	cin >> a>>b>>n;
	for (int i = 0; i < a; i++) {
		if (!isdigit(n[i])) flag = false;
	}
	if (n[a] != '-') flag = false;
	for (int i = a + 1; i < a + b + 1; i++) {
		if (!isdigit(n[i])) flag = false;
	}
	if (flag == true)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

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

using namespace std;

int main(){
    int N;
    cin >> N;
    bool flag = true;
    int max = 0;
    int count = 0;
    vector<int> H(N);
    vector<int> diff(N);

    rep(i, N){
        cin >> H[i];
        if (i==0)   max = H[i];
        if (max - H[i] > 1){
            flag = false;
        }
        if (max < H[i]){
            max = H[i];
        }
    }

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


    return 0;
}



Measured memory_bytes: 1024
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<iostream>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0) return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p; }
#define flush fflush(stdout)
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
ll st[3000001];ll y=-1000000000000000;
ll query(int l,int r,int i,int qs,int qe)
{
    if(l>r)
        return y;
    if(qs>r||qe<l)
        return y;
    if(qs<=l&&qe>=r)
    {
        return st[i];
    }
    int m=(l+r)/2;
    return max(query(l,m,2*i+1,qs,qe),query(m+1,r,2*i+2,qs,qe));
}
void update(int l,int r,int i,int in1,ll x)
{
    if(l>r)
        return;
    if(in1>r||in1<l)
        return;
    if(l==r)
    {
        st[i]=x;
        return;
    }
    int m=(l+r)/2;
    update(l,m,2*i+1,in1,x);
    update(m+1,r,2*i+2,in1,x);
    st[i]=max(st[2*i+1],st[2*i+2]);
}
int main()
{
    IOS;//ifstream fin("input.txt");ofstream fout("output.txt");
    int n;
    cin>>n;int h[n];ll a[n];ll mx;
    for(int i=0;i<=3000000;i++)
        st[i]=0;
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll dp[n];
    for(int i=0;i<n;i++)
    {
        mx=0;
        if(h[i]>=2)
            mx=query(0,n-1,0,0,h[i]-2);
        dp[i]=a[i]+mx;
        update(0,n-1,0,h[i]-1,dp[i]);
    }
    ll ans=0;
    for(int i=0;i<n;i++)
        ans=max(ans,dp[i]);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 27648
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for (int i=0;i<(n);i++)

using namespace std;

const int INF = 1e9;
const int MAX_V = 210;
struct edge{
	int to, cap, rev;
	edge(int to,int cap, int rev):to(to),cap(cap),rev(rev){}
};
vector<vector<edge> > G(MAX_V); //??°???????????£??\???????????¨???
bool used[MAX_V]; //DFS??§??¢???????????????????????????????????°

void add_edge(int from, int to, int cap){
		G[from].push_back(edge(to,cap,G[to].size()));
		G[to].push_back(edge(from,0,G[from].size() - 1));
}

int dfs(int v, int t, int f){
	if(v == t) return f;
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if( !used[e.to] && e.cap > 0){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d > 0){
				e.cap -=d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int maxflow(int s, int t){
	int flow = 0;
	for(;;){
		fill(used,used + MAX_V,false);
		int f = dfs(s,t,INF);
		if(f == 0)return flow;
		flow += f;
	}
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
int x,y,e;
	cin >> x >> y >> e;
	int s = x+y, t = s+1;
	REP(i,e){
		int from,to;
		cin >> from >> to;
		add_edge(from,to + x,1);
	}
	REP(i,x){
		add_edge(s,i,1);//?§?????????????????????????
	}
	REP(i,y){
		add_edge(x + i,t,1);//????????????????????????
	}
	cout << maxflow(s,t) << endl;
  return 0;
}

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

using ll = long long;
constexpr int mod = 1000000007;

int add(int& x, int y){
    if((x += y) >= mod) x -= mod;
    return x;
}

int mul(int x, int y){
    return (int)((ll)x * y % mod);
}

int dp[1000005];

int main(){
    int n;
    cin >> n;
    dp[0] = dp[1] = 1;
    int ans = 0;
    for(int i = 1; i < n; ++i){
        add(dp[i + 2], dp[i + 1]);
        add(dp[i + 1], dp[i]);
        add(dp[i + 2], dp[i - 1]);
        add(ans, mul(dp[i - 1], mul(n, i)));
        add(ans, mul(dp[i - 1], mul(n - 1, n - i - 1)));
    }
    add(ans, dp[n]);
    add(ans, mul(dp[n - 1], n - 1));
    cout << ans << endl;
}

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

int main(){
    int N;
    vector<int> p(N), s(N);
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> p[i];
    }
    for(int i = 0;i < N;i++){
        s[i] = i+1;
    }
    int cnt = 0;
    for(int i = 0;i < N;i++){
        if(p[i] != s[i]){
            cnt += 1;
        }
    }
    if(cnt <= 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
#include <iostream>


int main()
{
   std::string S;
   int flag=0;
   int flag2=0;
   std::cin >> S;
    int A=atoi(S.c_str());
    int B=A/100;
    int C=A%100;
    if(1<=B && B<=12){
        flag++;
    }
    if(1<=C && C<=12){
        flag2++;
    }
    if(flag==0 && flag2==0){
        std::cout << "NA" << std::endl;
    }
    if(flag==0 && flag2==1){
         std::cout << "YYMM" << std::endl;
    }
    if(flag==1 && flag2==0){
         std::cout << "MMYY" << std::endl;
    }
    if(flag==1 && flag2==1){
         std::cout << "AMBIGUOUS" << std::endl;
    }
    return 0;
}

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

int main(void) {

	int W,H,x,y,r;

	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

	if(x<=0||x>=W){
		printf("No\n");
	}
	else if(y<=0||y>=H){
		printf("No\n");
	}
	else if(x-r<0||x+r>W){
		printf("No\n");
	}
	else if(y-r<0||y+r>H){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    string s, t, u;
    cin >> s >> t;

    int a, b;
    cin >> a >> b;

    cin >> u;

    if(s == u){
        cout << a - 1 << " " << b << endl;
    }
    else {
        cout << a  << " " << b - 1<< endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>

using namespace std;

int point = 0;
int n, m, q;
vector<int> a(50);
vector<int> b(50);
vector<int> c(50);
vector<int> d(50);
vector<int> A(10);


void dfs(int index, int val){
    if(index == n){
        int tmp = 0;
        for(int i=0;i<q;i++){
            if(A[b[i]-1] - A[a[i]-1] == c[i]){
                tmp += d[i];
            }
        }
        point = max(tmp, point);
        return;
    }

    A[index] = val;
    for(int i=val;i<=m;i++){
        dfs(index+1, i);
    }
}

int main(){

    cin >> n >> m >> q;

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

    dfs(0, 1);

    cout << point << endl;
}   

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

int main() {
int n;
cin >> n;
vector<ll> a(n+1);
a.at(0) = 2;
a.at(1) = 1;
for(int i = 2; i <= n;  i++){
  a.at(i) = a.at(i-1) + a.at(i-2);
}
cout << a.at(n) << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

signed main() {
    string S; cin >> S;
    bool can;
    int ans=INF;
    rep(i,26){
        int cnt=0;
        string T=S;
        while(1){
            can = true;
            rep(j,T.size()-1){
                if(T[j]!=T[j+1]) can = false;
            }
            if(can) break;
            rep(j,T.size()){
                if(T[j]==(char)('a'+i) || T[j+1]==(char)('a'+i))T[j]=(char)('a'+i);
            }
            T.erase(T.end()-1);
            cnt++;
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;

}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

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

  VI v(n);
  vector<bool> flags(n, false);
  // flags[0] = true;
  REP(i, n) {
    int tmp;
    cin >> tmp;
    tmp--;
    v[i] = tmp;
  }

  int now = 0;
  ll loop_num = 0;
  VI first_reach(n, 0);
  ll amari;
  while (true) {
    if (flags[now]) {
      amari = first_reach[now];
      break;
    }

    flags[now] = true;
    first_reach[now] = loop_num + 1;
    now = v[now];
    loop_num++;
  }
  amari--;
  loop_num = loop_num - amari;

  // ANS(loop_num - amari);
  // ANS(amari);
  int ans;

  now = 0;
  if (k <= amari) {
    REP(i, k) {
      now = v[now];
    }
    ans = now;
  } else {
    REP(i, amari) {
      now = v[now];
    }
    VI loops;
    loops.push_back(now);
    REP(i, loop_num - 1) {
      now = v[now];
      loops.push_back(now);
    }
    // REP(i, loops.size()) {
    //   ANS(loops[i]);
    // }
    ll t = (k - amari) % loop_num;
    ans = loops[t];
  }
  ANS(ans + 1);

  return 0;
}


Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string n="Three";
  cin >> N;
  for(int i=0;i<N;i++){
     string c;
     cin>>c;
    if(c=="Y"){
     n="Four";
      break;
    }else {
      n=n;
    }
    
   }cout<<n<<endl;
 
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  string a, b, c;
  cin >> a >> b >> c;
  string S = a + b + c;
  ll ans = stoi(S);
  if (ans % 4 == 0) {
    COUT("YES");
  } else {
    COUT("NO");
  }
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll contract(ll x, ll i) {
	return ((x >> (i+1)) << i) + (x % (1 << i));
}

ll expand(ll x, ll i) {
	return ((x >> i) << (i+1)) + (x % (1 << i));
}

bool ok(ll n, ll a, ll b) {
	return a < (1 << n) && b < (1 << n) && __builtin_popcount(a^b) % 2 == 1;
}

vl gray_code(ll n, ll a, ll b) {
	assert(ok(n,a,b));
	if (n == 1) return {a,b};

	ll i = 0;
	while ((a & (1 << i)) == (b & (1 << i))) i++;
	
	ll c = contract(a,i), d = contract(b,i);
	ll e = 0;
	do e = rand() % (1 << (n-1));
	while (!ok(n-1,c,e));
	
	vl v = gray_code(n-1,c,e), w = gray_code(n-1,e,d);

	vl res;
	for (ll x: v) res.pb(expand(x,i) ^ (a & (1 << i)));
	for (ll x: w) res.pb(expand(x,i) ^ (b & (1 << i)));
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, a, b;
	cin >> n >> a >> b;

	ll k = __builtin_popcount(a^b);
	if (k%2 == 0) {
		cout << "NO" << endl;
		return 0;
	}
	
	cout <<"YES" << endl;
	vl res = gray_code(n,a,b);
	for (ll x: res) cout << x << " ";
	cout << endl;
}



Measured memory_bytes: 2520
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(b/a, c) << endl;
  return 0;
}

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

cnt, minus = 0, 1
for i in a:
    cnt += minus * i
    minus *= -1

x = [cnt]
for i in range(1,n):
    x.append(2 * a[i - 1] - x[i - 1])
print(*x)


Measured memory_bytes: 95604
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
                     // I'm in Love with Experience. 
void solve()
{
    ll N,X,T;cin>>N>>X>>T;
    if(N<X)cout<<T<<'\n';
    else if(N%X==0)
    {
        ll a = N/X;
        cout<< a*T <<'\n';
    }
    else
    {
        ll a = N/X + 1;
        cout<< a*T <<'\n';
    }
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    solve();exit(0);
}/*Solved By:- Ritik Agarwal*/

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
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; }
const int INF = 1<<30;

int main(){
	double n, k;
	double ans = 0;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		if(i >= k){
			ans += 1;
			continue;
		}
		double m = i;
		double cnt = 0;
		while(k > m){
			m *= 2;
			cnt++;
		}
		ans += pow(0.5,cnt);
	}
	cout << fixed << setprecision(10) << ans / n << endl;
}


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

int main(){
    int n;
    long long X=0,x=0,ans=1e11;
    cin>>n;
    vector<long long>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        X+=a[i];
    }
    for(int i=0;i<n;i++){
        x+=a[i];
        if(i+1<n)ans=min(ans,abs(X-2*x));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    char s[20],t[20],u[20];
    ll a,b;
    scanf("%s%s%lld%lld%s",s,t,&a,&b,u);
    if(strcmp(s,u)==0){
        printf("%lld %lld\n",a-1,b);
    }else{
        printf("%lld %lld\n",a,b-1);
    }

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

int main()
{
    fastio;
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    vector<bool> a;
    transform(S.begin(), S.end() - 1,
              S.begin() + 1, back_inserter(a),
              [](auto a, auto b) { return a == b; });

    cout << (any_of(a.begin(), a.end(), [](int a) { return a; }) ? "no" : "yes") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;
int main(){
  int n, l[10], max = 0, sum = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &l[i]);
    sum += l[i];
    if(max < l[i]){
      max = l[i];
    }
  }

  if(max < (sum - max)){
    printf("Yes");
  }else{
    printf("No");
  }
}


Measured memory_bytes: 128
// Goods things are coming, just keep believing 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define okay cout << "okay" << endl
// #define hey cout << "hey" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define endl '\n'
#define ff first 
#define int long long
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 #define ld long double
#define INF 1000000000;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
 
 
const int N = 2e5 + 5;
const int LG = 20;
const int mod = 1e9 + 7;

int arr[N];
int n, m;

void solve()
{
	int h, a;
	cin >> h >> a;
	int ans =  h / a;
	ans += ((h % a) != 0);
	cout << ans;
}

 
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int t = 1;
	// cin >> t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ipa pair<lld,lld>
#define lld long long int
#define x first
#define y second
#define ld long double
#define pb push_back
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI (atan(1)*4)
#define mp make_pair
#define mlog 21
#define mod 1000000000
using namespace std;
const int maxn=1e6+2;
main()
{
	fastread;
	lld i,j,n;
	cin>>n;
	lld a[n+3],b[n+3],c[n+3],dp[n+3][5];
	for(i=1;i<=n;++i)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	dp[1][0]=a[1];
	dp[1][1]=b[1];
	dp[1][2]=c[1];
	for(i=2;i<=n;++i)
	{
		dp[i][0]=max(max(dp[i-1][1],dp[i-1][2])+a[i],dp[i-1][0]);
		dp[i][1]=max(max(dp[i-1][0],dp[i-1][2])+b[i],dp[i-1][1]);
		dp[i][2]=max(max(dp[i-1][1],dp[i-1][0])+c[i],dp[i-1][2]);
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}

Measured memory_bytes: 6528