akhauriyash/Code-Regression huggingface dataset:
#include <stdint.h>
#include <stdio.h>
#include <algorithm>

unsigned readUnsigned() {
    int c;
    do { c = ::getchar_unlocked(); } while (c < '0');
    unsigned result = c - '0';
    while ((c = ::getchar_unlocked()) >= '0') {
        result *= 10;
        result += c - '0';
    }
    return result;
}

const unsigned MAX_N = 2000;
unsigned A[MAX_N];
long long unsigned dp[MAX_N];

int main() {
    unsigned N = readUnsigned();
    long long unsigned x = readUnsigned();
    for (unsigned i = 0; i < N; ++i) {
        A[i] = readUnsigned();
    }

    long long unsigned best = 0;
    for (unsigned i = 0; i < N; ++i) {
        dp[i] = A[i];
        best += A[i];
    }

    for (unsigned k = 1; k <= N; ++k) {
        long long unsigned cost = k * x;
        for (unsigned i = 0; i < N; ++i) {
            dp[i] = std::min<long long unsigned>(dp[i], A[(i+N-k)%N]);
            cost += dp[i];
        }
        best = std::min(best, cost);
    }
    printf("%llu\n", best);
}


Measured memory_bytes: 128
#include<stdio.h>

#define max(p,q)((p)>(q)?(p):(q))

int M=-1e9,ans=-1e9;

void f(){
	int t;
	if(~scanf("%d",&t)){
		f();
		ans=max(ans,M-t);
		M=max(M,t);
	}
}

int main(){
	scanf("%*d");
	f();
	printf("%d\n",ans);
}


Measured memory_bytes: 8036
# from line_profiler import LineProfiler
from collections import deque
from sys import stdin

def main():
    while(True):
        W, H = map(int, stdin.readline().split())
        if not W: break
        tx,ty = map(int, stdin.readline().split())
        kx,ky = map(int, stdin.readline().split())
        ma = [[False]*(W+2) for _ in range(H+2)]
        for i in range(1,H+1):
            for j,a in enumerate(stdin.readline().split()):
                ma[i][j+1] = bool(1-int(a))
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if tx == kx and ty == ky:
                ans = c
                break
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = [ dx, dy] if ma[ty+dy][tx+dx] else [0,0]
                kdx, kdy = [-dx,-dy] if ma[ky-dy][kx-dx] else [0,0]
                if (tx+tdx,ty+tdy,kx+kdx,ky+kdy) in pas: continue
                if c+1 > 100: continue
                que.append([tx+tdx,ty+tdy,kx+kdx,ky+kdy,c+1])
                pas.add((tx+tdx,ty+tdy,kx+kdx,ky+kdy))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


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

int main(){
  int N, K;
  int a[60];
  cin >> N >> K;
  for(int i = 0; i < N; i++)cin>>a[i];
  sort(a, a + N, greater<int>());

  int snake = 0;
  for(int i = 0; i < K; i++){
    snake += a[i];
  }
  cout << snake << endl;
}


Measured memory_bytes: 256
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

template <typename T>
std::vector<T> make_v(usize a) { return std::vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(usize a, Ts... ts) {
  return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t) fill_v(e, v);
}

template <typename T, typename V>
inline void chmin(T &a, V b) {
  if (a > b) a = b;
}
template <typename T, typename V>
inline void chmax(T &a, V b) {
  if (a < b) a = b;
}

} // namespace null_null

#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

namespace null_null {

void main_() {
  usize N, M;
  std::cin >> N >> M;
  static std::vector<i32> G[3][101010];
  for (usize i = 0; i < M; i++) {
    i32 u, v;
    std::cin >> u >> v;
    u--, v--;
    for (usize j = 0; j < 3; j++) {
      G[j][u].push_back(v);
    }
  }

  usize S, T;
  std::cin >> S >> T;
  S--, T--;

  auto bfs = [&](int s) {
    static bool vis[3][101010] = {};

    static i64 dist[3][101010];
    for (usize i = 0; i < 3; i++) {
      for (usize j = 0; j < 101010; j++) {
        dist[i][j] = 1e18;
      }
    }

    vis[0][s] = true;
    dist[0][s] = 0;
    std::queue<std::pair<i64, i64>> q;
    q.push({0, s});

    while (!q.empty()) {
      std::pair<i64, i64> p = q.front();
      q.pop();
      i64 m = p.first, x = p.second;

      for (auto t : G[m][x]) {
        if (!vis[(m + 1) % 3][t]) {
          vis[(m + 1) % 3][t] = true;
          dist[(m + 1) % 3][t] = dist[m][x] + 1;
          q.push({(m + 1) % 3, t});
        }
      }
    }

    return dist[0][T];
  };

  i64 ans = bfs(S);

  if (ans == 1e18) {
    std::cout << -1 << std::endl;
  } else {
    std::cout << ans / 3 << std::endl;
  }
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


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

using namespace std;

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    int L = A + B;
    int R = C + D;

    if (L > R) {
        cout << "Left" << endl;
    } else if (L < R) {
        cout << "Right" << endl;
    } else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))

# 調整
for L in s:
    for i in range(len(L)):
        L[i] -= 1

res = 0
for bit in range(1<<N):
    ok = True
    for i in range(M):
        con = 0
        for v in s[i]:
            if bit & (1<<v):
                con += 1
        if con % 2 != p[i]:
            ok = False
    if ok:
        res += 1
print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MAX_N 10000
#define INF 1e9

using namespace std;

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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a = 0, b = 0;
    ll n;
    cin >> n;
    while (1) {
        a++;
        ll at = a;
        b = 0;
        at = at * at * at * at * at;
        if (at - n == 0) {
            cout << a << ' ' << 0 << endl;
            return 0;
        } else if (at - n < 0) {
            ll bt = 0;
            while (at - n < bt) {
                b--;
                bt = b;
                bt = bt * bt * bt * bt * bt;
            }
            if (at - n == bt) {
                cout << a << ' ' << b << endl;
                return 0;
            }
        } else {
            ll bt = 0;
            while (at - n > bt) {
                b++;
                bt = b;
                bt = bt * bt * bt * bt * bt;
            }
            if (at - n == bt) {
                cout << a << ' ' << b << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3640
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u64 = read();
    let a: u64 = read();
    let b: u64 = read();
    let ab: u64 = a + b;

    let l = n / ab;
    let mut ans = l * a;
    let left = n - l * ab;
    if left >= a {
        ans += a;
    } else {
        ans += left;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

int main() {
	map<string, bool> mp;
	string s;
	ll k;

	cin >> s >> k;

	repi(i, 1, k + 1) {
		for (ll j = 0; j + i <= s.length(); j++) {
			string t = s.substr(j, i);
			mp[t] = true;
		}
	}

	auto it = mp.begin();
	repi(i, 1, k) it++;

	wrln(it->first);

	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll h[100000];
ll N,A,B;

bool isOK(ll p){
    ll c = 0;
    for(int i=0;i<N;i++){
        ll t = h[i] - p*B;
        if(t <= 0) continue;
        c += t / (A-B);
        if(t % (A-B) != 0) c++;
    }
    return c <= p;
}

int main(){
    cin >> N >> A >> B;
    for(int i=0;i<N;i++) cin >> h[i];
    ll sp,ep;
    sp = 0;
    ep = 2e9;
    while(ep-sp>1){
        ll p = (sp+ep)/2;
        if(isOK(p)) ep = p;
        else sp = p;
    }
    cout << ep << endl;
    return 0;
}

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

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  for(int i=0; i<N; i++){
    int m;
    cin >> m;
    x.at(i)=abs(X-m);
  }
  int D = x.at(0);
  for(int i=0; i<N-1; i++){
    int A = max(D, x.at(i+1));
    int B = min(D, x.at(i+1));
    int r;
    r = A%B;
    while(r!=0){
      A=B;
      B=r;
      r=A%B;
    }
    D=B;
  }
  cout << D << endl;
}

Measured memory_bytes: 768
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define MAXI (1<<32)
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define SIZ 1000005
#define SIZE 200005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair<ll,ll>&a,const pair<ll,ll>&b){
	return a.ss < b.ss;
}

//ll p[20000005]={0};
//vector<ll>ans;
/*void sieve(){
    ll i,j;
    p[0]=p[1]=1;
    for(i=2;i*i<=20000005;i++){
        if(!p[i]){
            for(j=2*i;j<20000005;j+=i){
                p[j]=1;
            }
        }
    }
    fo(i,2,20000005){
        if(!p[i]){
            ans.pb(i);
        }
    }
}*/

signed main(){ 
    IOS
    //io_set();
    set < ll > s;
    vector < pll > v;
    ll n, k, x;
    cin >> n >> k;
    map < ll , ll > m; 
    rep(i, n){
        cin >> x;
        s.insert(x);
        m[x]++;
    }
    if(k >= sz(s)){
        cout << 0 << endl;
        return 0;
    }
    else{
        ll x = sz(s) - k;
        for(auto it : s){
            v.eb(it,m[it]); 
        }
        ll c = 0;
        sort(all(v),comp);
        rep(i, x){
            c += v[i].ss;
        }
        cout << c << endl;
    }
    return 0;
}



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

int main()
{
  int A,B,C,D,E, K, KT=0 ;

  cin>>A>>B>>C>>D>>E>>K;

  if ( ((B-A)> K) || ((C-A)> K) || ((D-A)> K) || ((E-A)> K) ||
      ((C-B)> K) || ((D-B)> K) || ((E-B)> K) || ((D-C)> K)
      || ((E-C)> K) || ((E-D)> K) )

      cout<<":("<<endl;
   else
    cout<<"Yay!"<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 200005 , S = 0 , T = 200000;
struct node{int to,next,val;}e[N<<4];
int head[N],cnt,dep[N],q[N],c[N],n;
void add(int x,int y,int z){e[cnt]=(node){y,head[x],z};head[x]=cnt++;}
void insert(int x,int y,int z){add(x,y,z),add(y,x,0);}
int bfs()
{
	int l=0,r=0;q[r++] = S;memset(dep,-1,sizeof(dep));dep[S] = 1;
	while(l<r)
	{
		int x = q[l++];
		for(int i=head[x];i!=-1;i=e[i].next)
		{
			int to1=e[i].to;
			if(dep[to1]==-1&&e[i].val)dep[to1] = dep[x]+1 , q[r++] = to1;
		}
	}return dep[T] != -1;
}
int dfs(int x,int maxf)
{
	if(x==T)return maxf;int tflow = maxf , nowf;
	for(int i=head[x];i!=-1;i=e[i].next)
	{
		int to1=e[i].to;
		if(dep[to1]==dep[x]+1&&e[i].val)
		{
			nowf = dfs(to1 , min(tflow , e[i].val) );
			if(nowf && x>=1 && x<=n-1 && to1) c[x]=to1-n+2;
			e[i].val-=nowf , tflow -= nowf , e[i^1].val += nowf;
			if(!tflow)break;
		}
	}if(tflow)dep[x]=-1;return maxf-tflow;
}
vector<int >v[N];
int Dinic()
{
	int sum = 0;
	while(bfs())sum += dfs(S,1<<30);
	return sum;
}
int vis[N];pair<int ,int > ans[N];
int main()
{
	scanf("%d",&n);memset(head,-1,sizeof(head));
	for(int i=1;i<n;i++)
	{
		int siz; scanf("%d",&siz); insert(S,i,1); insert(n+i-1,T,1);
		for(int j=1,x;j<=siz;j++)
		{
			scanf("%d",&x),v[x].push_back(i);
			if(x!=1)insert(i,n+x-2,1);
		}
	}
	// puts("B");
	if(Dinic()==n-1)
	{
		// puts("a");
		int l = 0 , r = 0;
		for(int i=0;i<v[1].size();i++)
			q[r++] = v[1][i] , vis[v[1][i]] = 1;
		while(l<r)
		{
			int x = q[l++]; ans[x] = make_pair(vis[x] , c[x]); x = c[x];
			for(int i=0;i<v[x].size();i++)
				if(!vis[v[x][i]]) q[r++] = v[x][i] , vis[v[x][i]] = x;
		}
		if(r==n-1)for(int i=1;i<n;i++)printf("%d %d\n",ans[i].first,ans[i].second);
		else puts("-1");
	}else puts("-1");
}


Measured memory_bytes: 25472
import collections
N = int(input())
S = list(input())
rightE = S.count('E')
rightW = S.count('W')
leftE = 0
leftW = 0
ans = N
for n in range(N):
    if S[n] == 'E':
        rightE -= 1
        ans = min(ans,leftW+rightE)
        leftE += 1
    else:
        rightW -= 1
        ans = min(ans,leftW+rightE)
        leftW += 1
print(ans)


Measured memory_bytes: 6220
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, W, ans = 0;
    cin >> n >> W;
    vector<long long>dp(W + 5, 0);
    for(long long i = 0; i < n; i++){
        long long weight, value;
        cin >> weight >> value;
        for(long long u = W - weight; u >= 0; u--){
            dp[u + weight] = max(dp[u + weight], dp[u] + value);
            ans = max(ans, dp[u + weight]);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x, y; cin >> x >> y;
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			if (i + j == x and 2 * i + 4 * j == y) {
				cout << "Yes" << "\n";
				return 0;
			}
		}
	}
	cout << "No" << "\n";
}

Measured memory_bytes: 3616
import java.util.Scanner;
public class Main{
 
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
      
      int ans = 0;
      
      for(int i = x;i>=0;i++)
      {
        for(int j =2;j<=350;j++)
        {
          if(i<j*j){
            ans = i;
            break;
          }
          
          if(i%j==0)
            break;
        }
        
        if(ans!=0)
          break;
      }
      
 
      System.out.println(ans);
 
      
 
 
 
      
      
 
 
 
		
		
	}
 
}

Measured memory_bytes: 23764
#include<iostream>

int main(){
    
    size_t k, s, cnt = 0;
    std::cin >> k >> s;

    for(size_t i = 0; i <= k; i++){
        for(size_t j = 0; j <= k; j++){
            if(i + j <= s && s - i - j <= k) cnt++;
        }
    }

    std::cout << cnt << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 X, Y;
  std::cin >> X >> Y;
  std::cout << (Y % 2 == 0 && 2 * X <= Y && Y <= 4 * X ? "Yes" : "No") << std::endl;
  // a = 2X - Y/2
  // b = Y/2 - X
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    clock_t start = clock();
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n - 1));
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n - 1; ++j)
        {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    vector<int> idx(n, 0);
    int day = 1;
    vector<bool> seen(n, true);
    while (true)
    {
        seen.assign(n, true);
        bool flg = false;
        // cout << "day " << day << endl;
        for (int i = 0; i < n; ++i)
        {
            if (idx[i] > n - 2)
            {
                continue;
            }
            int rival = a[i][idx[i]];
            if (idx[rival] > n - 2 || i == rival)
            {
                continue;
            }
            if (seen[rival] && seen[i] && i == a[rival][idx[rival]])
            {
                idx[i]++;
                idx[rival]++;
                seen[i] = false;
                seen[rival] = false;
                flg = true;
            }
        }
        // for (int i = 0; i < n; i++)
        // {
        //     cout << i + 1 << ':' << idx[i] << endl;
        // }
        int cnt = count(ALL(idx), n - 1);
        if (cnt == n)
        {
            cout << day << endl;
            return 0;
        }
        if (!flg)
        {
            cout << -1 << endl;
            return 0;
        }
        clock_t end = clock();
        if((double)(end-start)/CLOCKS_PER_SEC>1.8){
            // cout<<(double(end-start) / CLOCKS_PER_SEC)<<endl;s
            cout<<n*(n-1)/2<<endl;
            return 0;
        }
        day++;
    }
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
const int N=200005;
char s[N];
int n,f[N],pos[N][26];
int main(){
	scanf("%s",s);
	int n=strlen(s);
	f[n]=1;
	for (int i=0;i<26;i++) pos[n][i]=n;
	for (int i=n-1;i>=0;i--){
		for (int j=0;j<26;j++) pos[i][j]=pos[i+1][j];
		pos[i][s[i]-'a']=i;
		f[i]=n;
		for (int j=0;j<26;j++) f[i]=std::min(f[i],f[pos[i][j]+1]+1);	
	} 
	int p=0;
	for (int i=f[0];i;i--){
		for (int j=0;j<26;j++)
			if (f[pos[p][j]+1]+1==i){
				putchar(j+'a');
				p=pos[p][j]+1;
				break;
			}
	}
} 

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




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

  vector<ll> p(n);
  vector<ll> q(n);
  ll sho=INF;
  ll memo;
  ll sum=0;
  bool zr=true;
  rep(i,n){
    cin>>p[i]>>q[i];
    if(p[i]>q[i]) {
      zr=false;
      if(q[i]<sho) memo=i;
      chmin(sho,q[i]);
    }
    sum+=p[i];
  }
  
  if(zr) cout << 0 << endl;
  else cout << sum-sho << endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <iomanip>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
    cin.sync_with_stdio( false );

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

    vector <int> dist;
    dist.push_back(a[0] + k - a[n-1]);
    for (int i=1;i<n;i++){
        dist.push_back(a[i]-a[i-1]);
    }

    sort(dist.begin(), dist.end());
    cout<<k-dist[dist.size()-1]<<endl;
    return 0;
}


Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int H,W; cin>>H>>W;
    vector<string> S(H);
    rep(h,0,H) cin>>S.at(h);

    rep(h,0,H){
        rep(w,0,W){
            char s=S.at(h).at(w);
            if(s=='.'){
                int bomb=0;
                rep(y,-1,2)rep(x,-1,2){
                    int _x=w+x,_y=h+y;
                    if(_x>=0 && _x<W && _y>=0 && _y<H){
                        if(S.at(_y).at(_x)=='#') bomb++;
                    }
                }
                S.at(h).at(w)=bomb+'0';
            }
        }
    }

    rep(h,0,H) cout<<S.at(h)<<endl;;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

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

map<int, int> v;
int n, m, k;

void solve(int N, int value){
  if(N == 0){
    value -= k;
    if(value < 1) value = 1;
    v[value]++;
    return;
  }
  else{
    for(int i = 1 ; i <= m ; i++){
      solve(N-1, value+i);
    }
  }
}

int main(){
  while(cin >> n >> m >> k, n|m|k){
    v.clear();
    solve(n, 0);
    int M = 1;    
    rep(i, n) M *= m;
   
    double ans = 0.0;
    for(map<int, int>::iterator it = v.begin() ; it != v.end() ; it++){
      ans += double(((double)it->second * (double)it->first) / (double)M);
    }
    printf("%.8f\n", ans);    
  }  
  return 0;
}

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

int main() {
  int K;
  string S;
  cin >> K >> S ;
  int s=S.size();
  if (s<=K){
  cout <<S << endl;
  }
  else {
    string k ="";
    for(int i=0;i<K;i++){
      k+=S.at(i);
    }
    
    cout<<k<<"..."<<endl;
  }
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>

using ll = long long;

int main() {
  size_t N;

  std::cin >> N;

  std::vector<std::pair<ll, ll>> D(N);

  for (size_t i=0; i<N; i++) {
    ll A, B;
    std::cin >> A >> B;
    D[i] = std::make_pair(A, B);
  }

  std::sort(D.begin(), D.end(),
            [](auto a, auto b) {
              return b.first + b.second < a.first + a.second;
            });

  ll res_a = 0;
  ll res_b = 0;

  for (size_t i=0; i<N; i++) {
    if (i%2 == 0)
      res_a += D[i].first;
    else
      res_b += D[i].second;
  }

  std::cout << (res_a - res_b) << std::endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int  maxn = 1e5 + 5;
int n, k;
int arr[105];
bool dp[maxn];
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for(int i = 0; i < n; i ++){
        cin >> arr[i];
    }
    for(int stones = 0; stones <= k; stones ++){
        for(int i = 0; i < n; i ++){
            if(stones >= arr[i] and !dp[stones - arr[i]]){
                dp[stones] = true;
            }
        }
    }
    if(dp[k]) cout << "First\n";
    else cout << "Second\n";
    return 0;
}


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

bool pcheck(int x){
	string s = to_string(x);
	rep(i,s.size()/2){
		if(s[i]!=s[s.size()-1-i]){
			return false;
		}
	}
	return true;
}


int main() {
	int a,b;
	cin >> a >> b;
	int ans=0;
	if(a==b){
		if(pcheck(a)) ans++;
	}else{
		rep2(i,a,b+1){
			if(pcheck(i)) ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(long i=0; i<(long)(n); i++)
int main(){
long N, K, ans=-1e18; cin >> N >> K; vector<long> P(N), C(N);
REP(i, N){ cin >> P[i]; P[i]--; }
REP(i, N){ cin >> C[i]; }

long j=0, k=0; long sub=0;
REP(i, N){ 
  j=P[i]; ans=max(ans, C[j]); sub=C[j]; k=1;
  if(K<=5000){ while(k<K){ j=P[j]; sub+=C[j]; ans=max(ans, sub); k++; } }
  else{
    while(i!=j){ j=P[j]; k++; sub+=C[j]; ans=max(ans, sub); }
    if(sub>0){ sub=sub*((K/k)-1); REP(r, k+K%k){ j=P[j]; sub+=C[j]; ans=max(ans, sub); } }
  }
}
cout << ans << "\n";
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    char a = s.at(0);
    char b = s.at(1);
    char c = s.at(2);
    if(a=='S' && b=='S' && c=='S') cout << 0 << endl;
    if(a=='S' && b=='S' && c=='R') cout << 1 << endl;
    if(a=='S' && b=='R' && c=='S') cout << 1 << endl;
    if(a=='R' && b=='S' && c=='S') cout << 1 << endl;
    if(a=='R' && b=='S' && c=='R') cout << 1 << endl;
    if(a=='S' && b=='R' && c=='R') cout << 2 << endl;
    if(a=='R' && b=='R' && c=='S') cout << 2 << endl;
    if(a=='R' && b=='R' && c=='R') cout << 3 << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  int N, M;
  cin >> N >> M;
  auto wa = vector<int>(N, 0);
  auto ac = vector<bool>(N, false);
  REP(i, M) {
    int p;
    string S;
    cin >> p >> S;
    p--;
    if(!ac[p] && S == "WA") {
      wa[p]++;
    } else {
      ac[p] = true;
    }
  }

  int ac_cnt = 0;
  int wa_cnt = 0;
  REP(i, N) {
    if(ac[i]) {
      ac_cnt++;
      wa_cnt += wa[i];
    }
  }
  cout << ac_cnt << " " << wa_cnt << endl;
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define N 100010
struct pp{int x,y,i;
}p[N];
struct aa{int x,y,z;
}a[N*2];
int f[N];
long long ans;
int i,n,cnt,x,y,fx,fy;
inline int read()
{
	char ch=getchar();
	int x=0,f=1;
	while (ch<'0'||ch>'9')
		{
			if (ch=='-') f=-1;
			ch=getchar();
		}
	while (ch<='9'&&ch>='0')
		{
			x=x*10+ch-'0';
			ch=getchar();
		}
	return x*f;
}
inline void write(long long x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>=10) write(x/10);
	putchar(x%10+'0');
}
inline bool cmp1(pp a,pp b)
{
	return a.x<b.x;
}
inline bool cmp2(pp a,pp b)
{
	return a.y<b.y;
}
inline void add(int x,int y,int z)
{
	cnt++;
	a[cnt].x=x;
	a[cnt].y=y;
	a[cnt].z=z;
}
inline bool cmp(aa a,aa b)
{
	return a.z<b.z;
}
inline int getf(int x)
{
	if (x==f[x]) return x;
	return f[x]=getf(f[x]);
 } 
int main()
{
	n=read();
	for (i=1;i<=n;i++)
	{
		p[i].x=read();
		p[i].y=read();
		p[i].i=i;
		f[i]=i;
	}
	sort(p+1,p+n+1,cmp1);
	for (i=1;i<n;i++) add(p[i].i,p[i+1].i,abs(p[i].x-p[i+1].x));
	sort(p+1,p+n+1,cmp2);
	for (i=1;i<n;i++) add(p[i].i,p[i+1].i,abs(p[i].y-p[i+1].y)); 
	sort(a+1,a+cnt+1,cmp);
	for (i=1;i<=cnt;i++)
	{
		x=a[i].x;
		y=a[i].y;
		fx=getf(x);
		fy=getf(y);
		if (fx==fy) continue;
		ans+=a[i].z;
		f[fx]=fy;
	}
	write(ans);
}

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

using namespace std;

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination1(int, int);
};
int Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_Cannot_Wait_for_Holiday(void) {

	string S;
	cin >> S;

	if		(S.compare("SUN") == 0) cout << 7 << flush;
	else if (S.compare("MON") == 0) cout << 6 << flush;
	else if (S.compare("TUE") == 0) cout << 5 << flush;
	else if (S.compare("WED") == 0) cout << 4 << flush;
	else if (S.compare("THU") == 0) cout << 3 << flush;
	else if (S.compare("FRI") == 0) cout << 2 << flush;
	else							cout << 1 << flush;

	return;
}

void B_ROT_N(void) {

	int N;
	string S;
	cin >> N >> S;

	for (char it : S) cout << char(((int)it - (int)'A' + N) % 26 + (int)'A') << flush;
	return;
}

int main(void) {

	//A_Cannot_Wait_for_Holiday();
	B_ROT_N();
	return 0;
}


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define ten(n) ((int)1e##n)
#define fst first
#define snd second
using ll=long long;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pil=pair<int,ll>;using pli=pair<ll,int>;
using vs=vector<string>;using vvs=vector<vs>;using vvvs=vector<vvs>;
using vb=vector<bool>;using vvb=vector<vb>;using vvvb=vector<vvb>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
ll ri(){ll l;cin>>l;return l;} string rs(){string s;cin>>s;return s;}
template<class T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
ostream&operator<<(ostream&o,const vb&t){forr(e,t)o<<"#."[e];return o;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";forr(e,t)o<<e<<",";o<<"}"<<endl;return o;}
#ifdef LOCAL
vs s_p_l_i_t(const string&s,char c){vs v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vs::iterator it){cerr<<endl;}
template<class T,class... Args>void e_r_r(vs::iterator it,T a,Args... args){cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it,args...);}
#define out(args...){vs a_r_g_s=s_p_l_i_t(#args,',');e_r_r(a_r_g_s.begin(),args);}
#else
#define out(args...)
#endif

template <typename T> vector<T> divisors(T n) {
  vector<T> ret;
  for (T 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.begin(), ret.end());
  return ret;
}

void Main() {
  ll n = ri();
  auto D = divisors(n);

  int mi = 1e9;

  forr(d, D) {
    ll e = n / d;
    int x = floor(log10(d)) + 1;
    int y = floor(log10(e)) + 1;
    out(d, e, x, y);
    amin(mi, max(x, y));
  }
  cout << mi << endl;

}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


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

int main(){
	int m,n;
	while(cin >> m >>n)
	{
		int i = m +n;
		
		int count = 0;
		while(i){
				count++;
			i = i/10;
		
		}
		cout << count << endl;
	}
	
    return 0;
	
}

Measured memory_bytes: 1160
var s:ansistring;
pos1,pos2,v1,v2:longint;
begin
  readln(s);
  pos1:=pos('+',s);
  pos2:=pos('-',s);
  if pos1>0 then
    begin
      val(copy(s,1,pos1-2),v1);
      val(copy(s,pos1+2,length(s)-pos1+1),v2);
      writeln(v1+v2);
    end
  else
    begin
      val(copy(s,1,pos2-2),v1);
      val(copy(s,pos2+2,length(s)-pos2+1),v2);
      writeln(v1-v2);
    end;
end.


Measured memory_bytes: 128
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int h, w; cin >> h >> w;
	vector<string> a(h);
	rep(i, h) cin >> a[i];
	rep(i, h) {
		rep(j, w) {
			if (a[i][j] == '.') continue;
			int dx[4] = { 0,0,1,-1 } ,dy[4] = { 1,-1,0,0 };
			bool flag = true;
			rep(k, 4) {
				if (dx[k] + i<0 || dx[k] + i>h - 1 || dy[k] + j<0 || dy[k] + j>w - 1) continue;
				if (a[dx[k] + i][dy[k] + j] == '#') {
					flag = false;
				}
			}
			if (flag) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long D;
        D = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(N, D);
    }
}

class Solver {
    public void solve(long N, long D) {
        System.out.println((int) Math.ceil(N / (2.0 * D + 1)));
    }
}



Measured memory_bytes: 21716
#include<iostream>
#include<vector>
int main(int argc, char** argv){
  int H,W,N;
  int i,j,w=0,h=0;
  std::cin >> H;
  std::cin >> W;
  std::cin >> N;

  std::vector<int> a(N);
  std::vector<std::vector<int> > out(H,std::vector<int>(W,0));
  for(i = 0; i < N; ++i){
    std::cin >> a[i];
  }
  for(i = 0; i < N; ++i){
    for(j = 0; j < a[i]; ++j){
      out[h][w] = i+1;
      if(w < W-1) ++w;
      else{
	w = 0;
	++h;
      }
    }
  }
  for(h = 0; h < H; ++h){
    if(h%2 == 0){
      for(w = 0; w < W; ++w){
	if(w < W-1){
	  std::cout << out[h][w] << " ";
	}else{
	  std::cout << out[h][w] << std::endl;
	}
      }
    }else{
      for(w = W-1; w >= 0; --w){
	if(w != 0){
	  std::cout << out[h][w] << " ";
	}else{
	  std::cout << out[h][w] << std::endl;
	}
      }
    }
  }
  return 0;
}


Measured memory_bytes: 384
let input = readLine()!.split(separator: " ").map{ Int($0)! }
let N = input[0]
let Ma = input[1]
let Mb = input[2]

var dp = Array(repeating: Array(repeating: Optional<Int>.none, count: 40 * 10 + 1), count: 40 * 10 + 1)
dp[0][0] = 0

var sumOfA = 0
var sumOfB = 0
for _ in stride(from: 0, to: N, by: 1) {
    let chemical = readLine()!.split(separator: " ").map{ Int($0)! }
    let a = chemical[0]
    let b = chemical[1]
    let c = chemical[2]

    for j in stride(from: sumOfA + a, through: a, by: -1) {
        for k in stride(from: sumOfB + b, through: b, by: -1) {
            guard let previousValue = dp[j - a][k - b] else { continue }

            dp[j][k] = min(dp[j][k] ?? Int.max, previousValue + c)
        }
    }

    sumOfA += a
    sumOfB += b
}

var result: Int? = nil
for i in stride(from: 1, through: sumOfA, by: 1) {
    for j in stride(from: 1, through: sumOfB, by: 1) {
        guard i * Mb == j * Ma, let cost = dp[i][j] else { continue }
        result = min(result ?? Int.max, cost)
    }
}

print(result ?? -1)


Measured memory_bytes: 9724
#include<iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main()
{
    int k[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int num;
    cin >> num;
    cout << k[num -1] << endl;;

    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
INF=10**9+7
ans=0
for i in range(k,n+2):
    a=i*(i-1)//2
    b=(2*n-i+1)*i//2
    temp=b-a+1
    ans=(ans+temp)%INF
print(ans)


Measured memory_bytes: 63804
import java.util.Scanner;

public class Main{
   public static void main(String [] args){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
        if(a<b){
          if(b<c)
            System.out.println("Yes");
          else
            System.out.println("No");
        }
        else
            System.out.println("No");
      sc.close();
   }
}


Measured memory_bytes: 26152
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;cin>>n>>k;
    int a[n];
    for (int i=0;i<n;i++)
        cin>>a[i];
    int dp[n]={0};
    for (int i=1; i<n; i++){
        int mn=INT_MAX;
        for (int j=i-1; j>=0 && j>=i-k;j--){
            int x=abs(a[i]-a[j])+dp[j];
            mn=min(mn,x);
        }
        dp[i]=mn;
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 4372
#include <iostream>
#include <vector>
using namespace std;
int N;
vector<int> G[110000];
const int INF = 1 << 29;
int rec(int v, int p) {
	int all = 0;
	int zero_num = 0;
	for (auto to : G[v]) {
		if (to == p) continue;
		int tmp = rec(to, v);
		all += tmp;
		if (tmp == 0) ++zero_num;
	}
	if (zero_num > 1) all += zero_num - 1;
	return all;
}
int main() {
	cin >> N;
	int r = -1;
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
		if (G[a].size() > 2) r = a;
		if (G[b].size() > 2) r = b;
	}
	if (r == -1) {
		cout << 1 << endl;
		return 0;
	}
	cout << rec(r, -1) << endl;
}

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

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> h(n+1);
	set<int> s;
	for(int i = 1; i <= n; i++){
		cin >> h[i];
		s.insert(i);
	}
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		if(h[a] > h[b]){
			if(s.find(b) != s.end()) s.erase(b);
		}
		else if(h[b] > h[a]){
			if(s.find(a) != s.end()) s.erase(a);
		}
		else{
			if(s.find(b) != s.end()) s.erase(b);
			if(s.find(a) != s.end()) s.erase(a);
		}
	}
	cout << s.size() << endl;
	return 0;
}


Measured memory_bytes: 8304
#include<stdio.h>
#include<string.h>
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		char s[100];
		scanf("%s",s);
		if(strcmp(s,"snuke")==0){
			printf("%c%d\n",'A'+j,i+1);
		}
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,x,y;
int l,r,ans=1;
pair<int,int> p[100005];
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	cin>>p[i].first>>p[i].second;
	sort(p,p+m);
	l=p[0].first,r=p[0].second;
	for(int i=1;i<m;i++)
	{
		x=p[i].first,y=p[i].second;
		if(x<r)
		{
			if(x>l)l=x;
			if(y<r)r=y;
		}
		else ans++,l=x,r=y;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main()
{
  int K, ans;
  vector<int> H(2, 0), M(2, 0);
  cin >> H.at(0) >> M.at(0) >> H.at(1) >> M.at(1) >> K;
  ans = H[1] * 60 + M[1] - (H[0] * 60 + M[0]) - K;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N, M;
	cin >> N >> M;

	int imos[100010] = {};
	rep(i, M) {
		int L, R;
		cin >> L >> R;
		imos[L]++;
		imos[R + 1]--;
	}
	rep(i, N) {
		imos[i + 1] += imos[i];
	}
	int kotae = 0;
	rep1(i, N) if (imos[i] == M) kotae++;

	co(kotae);
	
	Would you please return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		int[] hight = new int[10];
		
		sc = new Scanner(System.in);
		for(int i = 0; i < 10; i++){
			hight[i] = sc.nextInt();
		}
		Arrays.sort(hight);
		
		for(int i = 9 ; i > 6; i--){
			System.out.println(hight[i]);
		}
	}
}

Measured memory_bytes: 17168