akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

ll calc(ll k,ll d) {
  return k*(k+1)/2*d;
}

const ll n=26;
ll c[n],q[444];
ll a[444][n];
set<ll> s[n];

ll solve(ll x,ll y) {
  ll ans=0;
  {
    ans-=a[x][q[x]];
    iter(s[q[x]]) it2=s[q[x]].lower_bound(x);
    iter(s[q[x]]) it1=it2,it3=it2;it1--,it3++;
    ans+=calc(*it2-*it1-1,c[q[x]]);
    ans+=calc(*it3-*it2-1,c[q[x]]);
    ans-=calc(*it3-*it1-1,c[q[x]]);
    s[q[x]].erase(it2);
  }
  {
    q[x]=y;
    s[q[x]].in(x);
    ans+=a[x][q[x]];
    iter(s[q[x]]) it2=s[q[x]].lower_bound(x);
    iter(s[q[x]]) it1=it2,it3=it2;it1--,it3++;
    ans-=calc(*it2-*it1-1,c[q[x]]);
    ans-=calc(*it3-*it2-1,c[q[x]]);
    ans+=calc(*it3-*it1-1,c[q[x]]);
  }
  return ans;
}

         
void Main() {
  srand((unsigned)time(NULL));
  int T;
  R T;
  rep(i,n) R c[i];
  rep(i,T)rep(j,n) R a[i][j];
  rep(i,n) s[i].in(-1),s[i].in(T);
  rep(k,T) {
    ll M=0,x=0;
    rep(i,n) {
      if(M<a[k][i]) {
        M=a[k][i];
        x=i;
      }
    }
    q[k]=x;
    s[x].in(k);
  }
  ll ans[T];
  mem(ans);
  clock_t t2=clock();
  for(int tt=0;;tt++) {
    ll e[2][3],sum=0;
    rep(i,2) {
      ll x=rand()%T,y=rand()%n;
      e[i][0]=q[x],e[i][1]=x,e[i][2]=y;
      sum+=solve(x,y);
    }
    if(sum<0) {
      rrep(i,2) {
        int x=e[i][1];
        s[q[x]].erase(x);
        q[x]=e[i][0];
        s[q[x]].in(x);
      }
    } else {
      rep(i,2) ans[e[i][1]]=e[i][2];
    }
    clock_t t3=clock();
    double t4=(double)(t3-t2)/CLOCKS_PER_SEC;
    if(tt>=2&&(double)t3/CLOCKS_PER_SEC+t4*2>1.800) break;
    t2=t3;
  }
  rep(i,T) pr(ans[i]+1);
}

int main(){Main();return 0;}


Measured memory_bytes: 3724
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare(const void *a, const void *b)
{
    if (*(intmax_t *)a < *(intmax_t *)b)
        return -1;
    if (*(intmax_t *)a > *(intmax_t *)b)
        return 1;
    return 0;
}

int main(void)
{
    intmax_t N, K, H[(int)2e5];
    intmax_t ans = 0;

    scanf("%jd%jd", &N, &K);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &H[i]);
    }

    if (K >= N) {
        puts("0");
        return 0;
    }

    qsort(H, N, sizeof(intmax_t), compare);

    for (size_t i = 0; i < (N - K); i++) {
        ans += H[i];
    }

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

    return 0;
}


Measured memory_bytes: 3324
myArray = list()
for n in range(5):
   myArray.append(int(input()))
k = int(input())
myflag = True

for i in range(len(myArray)-1):
    for j in range(i+1,len(myArray)):
        if myArray[j] - myArray[i] > k:
            myflag = False

if myflag:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

class UnionFind {
public:
    vector<int> parent;  //親ノード
    vector<int> Siz;  //集合の大きさ

    // コンストラクタ
    UnionFind(int n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(int n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    int root(int x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {

        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }

        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }

        Siz[x] += Siz[y];
        parent[y] = x;
    }

    // xとyが同じ集合に属するかどうか
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    int size(int x) {
        return Siz[root(x)];
    }
};

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

    vector<ll> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
    }

    // Kruskal法で使用する枝
    using Edge = pair<ll, pair<int, int>>;
    vector<Edge> edges;

    vector<int> ids(n);
    iota(ids.begin(), ids.end(), 0);

    // x軸方向にソートして隣接している部分のみ
    sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] < x[j]; });
    for(int i = 0; i+1 < ids.size(); i++) {
        int u = ids[i];
        int v = ids[i+1];
        edges.push_back(Edge(x[v] - x[u], make_pair(u, v)));
    }

    // y軸方向にソートして隣接している部分のみ
    sort(ids.begin(), ids.end(), [&](int i, int j) { return y[i] < y[j]; });
    for(int i = 0; i+1 < ids.size(); i++) {
        int u = ids[i];
        int v = ids[i+1];
        edges.push_back(Edge(y[v] - y[u], make_pair(u, v)));
    }

    // Kruskal法
    sort(edges.begin(), edges.end());
    UnionFind Uni(n);
    ll ans = 0;
    for(auto e : edges) {

        int u = e.second.first;
        int v = e.second.second;
        ll cost = e.first;

        if(Uni.same(u, v)) {
            continue;
        }

        Uni.unite(u, v);
        ans += cost;
    }

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

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

int main() {
    string s;
    cin >> s;
    int n = s.size();

    vector<int> num(100005);
    vector<int> right(100005);
    vector<int> left(100005);

    int cnt;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            cnt = 0;
        }
        else if (s[i] == 'L') {
            cnt++;
            left[i] = cnt;
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 'L') {
            cnt = 0;
        }
        else if (s[i] == 'R') {
            cnt++;
            right[i] = cnt;
        }
    }

    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') {
            int j = i + right[i];
            if ((j - i) % 2 == 0) {
                num[j]++;
            }
            else {
                num[j - 1]++;
            }
        }
        else if (s[i] == 'L') {
            int j = i - left[i];
            if ((i - j) % 2 == 0) {
                num[j]++;
            }
            else {
                num[j + 1]++;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if (i != 0) {
            cout << " ";
        }
        cout << num[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>

int main()
{
    int H, W;

    while(true){
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0){
            break;
        }

        for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1000
if __name__ == '__main__':
    h,w = list(map(int, input().split()))
    s = []
    for i in range(h):
        s.append(input())
    
    l = [[0 for i in range(w)] for j in range(h)]
    r = [[0 for i in range(w)] for j in range(h)]
    u = [[0 for i in range(w)] for j in range(h)]
    d = [[0 for i in range(w)] for j in range(h)]

    for i in range(h):
        for j in range(0, w):
            if(s[i][j] == "#"):
                l[i][j] = 0
            elif(j == 0):
                l[i][j] = 1
            else:
                l[i][j] = l[i][j-1] + 1
            
            tw = w-j-1
            if(s[i][tw] == "#"):
                r[i][tw] = 0
            elif(j == 0):
                r[i][tw] = 1
            else:
                r[i][tw] = r[i][tw+1] + 1
            
            if(s[i][j] == "#"):
                u[i][j] = 0
            elif(i == 0):
                u[i][j] = 1
            else:
                u[i][j] = u[i-1][j] + 1
                
            th = h-i-1
            if(s[th][j] == "#"):
                d[th][j] = 0
            elif(i == 0):
                d[th][j] = 1
            else:
                d[th][j] = d[th+1][j] + 1
            
    result = 0

    for i in range(h):
        for j in range(w):
            result = max(result, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3)


    print(result)


Measured memory_bytes: 184580
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;


int main()
{
	
	string s;
	cin >> s;
	LL sz = s.size();

	string last = "";
	bool lastu = false;
	LL cnt = 0;
	for (int i = 0; i < sz-1; ++i) {
		string nw(s[i], 1);
		if (last == nw) {
			nw.push_back(s[i+1]);
			i++;
			if (i == sz-1) {
				lastu = true;
			}
		}
		last = nw;
		cnt++;
	}

	if (lastu) {

	}
	else {
		string nw(s[sz-1], 1);
		if (last == nw) {

		}
		else {
			cnt++;
		}
	}
	cout << cnt << endl;

}

Measured memory_bytes: 640
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int t = sc.nextInt();
        int s = sc.nextInt();
        int u = sc.nextInt();


        if (s * u < t) {
            System.out.print("No");
        } else {
            System.out.print("Yes");
        }
    }

}



Measured memory_bytes: 35732
#include<bits/stdc++.h>
    using namespace std;
     
    int main(){
    	int n;
      cin >> n;
      if(n/10==9){
        cout << "Yes" << endl;
        return 0;
      }
      if(n%10==9){
        cout << "Yes" << endl;
        return 0;
      }
    cout << "No" << endl;
      return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)

int main() {
    int h, w, m;
    cin >> h >> w >> m;
    vector<int> ver(w), hol(h);
    set<pair<int, int>> bombs;
    rep(i, m) {
        int hi, wi; cin >> hi >> wi;
        hi--; wi--;
        hol[hi]++;
        ver[wi]++;
        bombs.insert({hi, wi});
    }
    vector<int> hs, ws;
    int hM = 0, wM = 0;
    rep(i, h) {
        if (hol[i] > hM) {
            hM = hol[i];
            hs = {i};
        } else if (hol[i] == hM) {
            hs.push_back(i);
        }
    }
    rep(i, w) {
        if (ver[i] > wM) {
            wM = ver[i];
            ws = {i};
        } else if (ver[i] == wM) {
            ws.push_back(i);
        }
    }
    int ans = hM + wM - 1;
    for (int i: hs) {
        for (int j: ws) {
            if (!bombs.count({i, j})) {
                ans = hM + wM;
                goto output;
            }
        }
    }
    output:
    cout << ans << endl;
}

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


int main() {
  vector<char> N(3);

  for(int i=0;i<3;i++){
      cin >> N.at(i);
  }
  

  for(int i=0;i<3;i++){
    if(N.at(i)=='7'){
        cout << "Yes" << endl;
        break;
    }
    if(i==2){
        cout << "No" << endl;
    }
  }
}

  


Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(in.readLine());
    if(k%2!=0)
      System.out.println((k/2)*(k/2+1));
    else
      System.out.println((k/2)*(k/2));
  }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)        (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007
double tick() { static clock_t oldt; clock_t newt = clock(); double diff = 1.0*(newt - oldt) / CLOCKS_PER_SEC; oldt = newt; return diff; }
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
inline LL moduloMultiplication(LL x, LL y) { return (x%mod * 1LL * y%mod) % mod; }
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}
inline LL inv(LL a) { return power(a, mod - 2) % mod; }
LL gcd(LL a, LL b)
{
	if (!a)
		return b % mod;
	return gcd(b%a, a) % mod;
}


int main()
{
	LL n;
	cin >> n;
	LL ans = (pow(2, (LL)log2(n)+1)) - 1;
	cout << ans << endl;
	



	

}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <string.h>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end  
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define RB rbegin()
#define E end()
#define RE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;
#define valid(a,b,c) (a >= b && a < c ? 1 : 0)
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int mod = (int)1e9 + 7;
ll gcd(ll a, ll b) {return (b==0? a:gcd(b,a%b));}
ll egcd(ll a, ll b, ll & x, ll & y) {if (a == 0){x = 0;y = 1;return b;}ll x1, y1;ll d = egcd(b % a, a, x1, y1);x = y1 - (b / a) * x1;y = x1;return d;}
ll mbinp(ll a, ll b){a %= mod;if (b == 0)return 1;ll ans = mbinp(a, b/2);ll tmp = (ans * ans) % mod;if (b % 2)return ((tmp * a) % mod);return ((tmp) % mod);}
ll binp(ll a, ll b){if (b == 0)return 1;ll ans = binp(a, b/2);ll tmp = (ans * ans);if (b % 2)return ((tmp * a));return ((tmp));}

const int maax = 305;
double dp[maax][maax][maax];
int n;
int tab[4];

double solve(int a, int b, int c)
{
	if (a+b+c ==0)
		return dp[a][b][c] = 0;
	if (dp[a][b][c] > -1)
		return dp[a][b][c];
	double res = 0;
	double pos = (double)n/(a+b+c);
	if (a)
		res += (solve(a-1,b,c) + pos) * ((double) a / (a+b+c));
	if (b)
		res += (solve(a+1,b-1,c) + pos) * ((double) b / (a+b+c));
	if (c)
		res += (solve(a,b+1,c-1) + pos) * ((double) c / (a+b+c));
	return (dp[a][b][c] = res);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	REP(i,0,n)
	{
		int x ;
		cin >> x ; tab[x]++;
	}
	REP(i,0,maax)REP(j,0,maax)REP(k,0,maax)dp[i][j][k] = -1;
	double res = solve(tab[1],tab[2],tab[3]);
	cout << fixed << setprecision(12) << res;
}


Measured memory_bytes: 222080
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var Ai = Sarray();
            var mask = (long)Pow(2, 19);
            var ruiBit = Enumerable.Range(0, 20).Select(_ => new long[N + 1]).ToArray();
            for (var j = 0; j < 20; ++j, mask >>= 1)
            {
                for (var i = 1; i <= N; ++i)
                    ruiBit[j][i] = ruiBit[j][i - 1] + ((mask & Ai[i - 1]) == 0 ? 0 : 1);
            }
            var l = 0;
            var r = 1;
            var ans = 0L;
            while (r < N + 1)
            {
                var isOk = true;
                for (var i = 0; i < 20; ++i)
                    if (1 < ruiBit[i][r] - ruiBit[i][l]) isOk = false;
                if (isOk)
                {
                    ans += r - l;
                    ++r;
                }
                else
                    ++l;
            }
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 56508
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge, rst = [ [] for i in range(N) ], 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for j in edge[i]:
        if H_ls[i] <= H_ls[j]:
            is_peak = False
            break
    if is_peak:
        rst += 1
print(rst)

Measured memory_bytes: 29440
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::marker::*;
use proconio::*;

#[fastout]
fn main() {
    input! {
        n: String,
    }

    println!("{}", if n.contains("7") { "Yes" } else { "No" });
}


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

int main() {
  int n;
  cin >> n;
  ll total = 1;
  bool ans = true;
  bool tf = false;
  vector<ll> k(n);
  rep(i, n) {
    cin >> k[i];
    if (k[i] == 0) tf = true;
  }
  if (tf) {
    cout << 0 << endl;
  } else {
    rep(i, n) {
      if (to_string(total).size() + to_string(k[i]).size() > 20) {
        ans = false;
        break;
      }
      if (to_string(total).size() + to_string(k[i]).size() >= 19) {
        if ((to_string(total)[0] - '0') * (to_string(k[i])[0] - '0') >= 10) {
          ans = false;
          break;
        }
      }
      total *= k[i];

      if (total > 1000000000000000000) {
        ans = false;
        break;
      }
    }
    if (ans)
      cout << total << endl;
    else
      cout << -1 << endl;
  }
}


Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#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() {
    long long N;
    cin >> N;
    
    for (long long h = 1; h <= 3500; ++h) {
        for (long long n = 1; n <= 3500; ++n) {
            if (4 * h * n - N * n - N * h <= 0) continue;
            if (N * h * n < 4 * h * n - N * n - N * h) continue;
            if (N * h * n % (4 * h * n - N * n - N * h) == 0) {
                cout << h << " " << n << " " << N * h * n / (4 * h * n - N * n - N * h) << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>
#include <bitset>
#include <memory>

constexpr long long int MOD = 1000000007;
static std::vector<long long int> factorial, inverse_factorial;
long long int power(long long int base, long long int exp) {
	switch (exp) {
	case 0: return 1;
	case 1: return base % MOD;
	default: return power(base, exp & 1) * power(base * base % MOD, exp >> 1) % MOD;
	}
}
long long int combination(int n, int r) {
	return factorial[n] * inverse_factorial[n - r] % MOD * inverse_factorial[r] % MOD;
}
long long int make_empty(long long int n, long long int empty) {
	return combination(n, empty) * combination(n - 1, n - empty - 1) % MOD;
}
int main() {
	int n, k; std::cin >> n >> k;
	factorial = std::vector<long long int>(n + 1, 1);
	inverse_factorial = std::vector<long long int>(n + 1, 1);
	auto inv = factorial;
	for (auto i = 2; i < factorial.size(); ++i) {
		factorial[i] = i * factorial[i - 1] % MOD;
		inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
		inverse_factorial[i] = inv[i] * inverse_factorial[i - 1] % MOD;
	}
	long long int result = 0;
	for (auto e = 0; e <= k && e < n; ++e) {
		result += make_empty(n, e);
		result %= MOD;
	}
	std::cout << result << std::endl;
}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
 
typedef pair<int,int> P;
 
int main(){
  int n,m;
  P a[110];
  
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> a[i].first >> a[i].second;
  }
 
  sort(a,a+m);
 
  int r = 0;
  int ans = 0;
 
  while(r<n){
    int id = -1;
    for(int i=0;i<m;i++){
      if(a[i].first<=r+1){
	if(id<0 || a[id].second < a[i].second)id = i;
      }
    }
    if(id<0 || a[id].second<=r){
      cout << "Impossible\n";
      return 0;
    }
    r = a[id].second;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 0
/*	
*  Sachin Mittal
*/
#include<bits/stdc++.h>
#define int long long
#define M 998244353
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define mem0(dp) memset(dp,0,sizeof(dp))
#define mem1(dp) memset(dp,-1,sizeof(dp))
#define pb push_back
#define fr(i,j,n) for(int i=j;i<n;i++)
#define sz(s) (int)(s.size())
using namespace std;
int32_t main(){

ios
int t=1;
//cin>>t;
while(t--)
{
	int n;cin>>n;
	cout<<(n/500)*1000+((n%500)/5)*5;
}
}

Measured memory_bytes: 256
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = list(map(int, input().split()))
    p.sort()
    max_p = max(p)
    start = 0
    for i in range (max_p + 2):
        flg = 0
        for j in range(N):
            if i == p[j]:
                flg = 1
        if flg == 0:
            if start == 0:
                ans = i
                start = 1
            else:
                if abs(X-i) < abs(X-ans):
                    ans = i
    print(ans)            

Measured memory_bytes: 63832
#include <iostream>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;

int main() {
  lli n, m;
  cin >> n >> m;
  if (n < m)
    swap(n, m);
  if (n == 1 && m == 1) {
    cout << 1 << endl;
  } else if (m == 1) {
    cout << n - 2 << endl;
  } else if (m == 2) {
    cout << 0 << endl;
  } else {
    cout << (n - 2) * (m - 2) << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll read()
{
    char ch=getchar();
    ll x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}


int main()
{
    ll ans=0;
    int n,i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
            ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
n = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(n-1) :
    minj = i
    for j in range(i+1, n) :
        if A[j] < A[minj] :
            minj = j
    if A[i] != A[minj] :
        A[i], A[minj] = A[minj], A[i]
        ans += 1
for i in range(n-1) :
    print(A[i], end=" ")
print(A[n-1])
print(ans)


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

int main(){
    string s;
    int k;
    cin >> s >> k;
    for(int i = 0; i < s.size(); i++){
        int tmp = (26 - (s[i] - 'a')) % 26;
        if(k >= tmp){
            s[i] = 'a';
            k -= tmp;
        }
    }
    if(k > 0){
        s[s.size() - 1] = 'a' + (s[s.size() - 1] - 'a' + k) % 26;
    }
    cout << s << endl;
}

Measured memory_bytes: 512
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0 ; i<n;i++){
            p[i] = sc.nextInt();
        }
        int ans = 1;
        boolean[] b = new boolean[n];
        b[0] = true;
        int j = 0;
        for(int i = 1;i<n;i++){
            if(b[j]){
                if(p[i]<=p[j]){
                    b[i] = true;
                    j = i;
                    ans ++;
                } else {
                    b[i] = false;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 78308
import sys
import collections
input = lambda: sys.stdin.readline()
exec("try:sys.stdin=open('in.txt','r');sys.stdout=open('out.txt','w')\nexcept:pass")

N = int(input())
A = list(map(int, input().split()))
d = collections.Counter()
for i in range(N):
    d[A[i] + 1] += 1
    d[A[i]] += 1
    d[A[i] - 1] += 1
print(max(list(d.values())))


Measured memory_bytes: 23756
X,Y,A,B,C = gets.chomp.split.map(&:to_i)
p = gets.chomp.split.map(&:to_i).sort.reverse
q = gets.chomp.split.map(&:to_i).sort.reverse
r = gets.chomp.split.map(&:to_i).sort.reverse
count = 0
array = []
array = array.push(p[0..X-1]).push(q[0..Y-1]).push(r[0..C-1]).flatten!.sort.reverse
puts array[0..X+Y-1].inject(:+)

Measured memory_bytes: 32892
import java.util.*;
public class Main{
    void run(){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int N = sc.nextInt();
            int M = sc.nextInt();
            int[] cost = new int[N];
            int[][] rank = new int[3][N];
            for(int i = 0; i < N; i++){
                sc.nextLine();//空白読み込み
                sc.nextLine();//名前読み込み
                cost[i] = sc.nextInt();
                rank[0][i] = sc.nextInt();
                rank[1][i] = sc.nextInt();
                rank[2][i] = sc.nextInt();
                
            }
            int[][] dp = new int[3][M+1];
            for(int i = 0; i < 3; i++){
                for(int ii = 0; ii < N; ii++){
                    for(int c = 0; c <= M - cost[ii]; c++){
                        dp[i][c+cost[ii]] = Math.max(dp[i][c+cost[ii]], dp[i][c]+rank[i][ii]);
                    }
                }
            }
            /*
            System.out.println(Arrays.toString(dp[0]));
            System.out.println(Arrays.toString(dp[1]));
            System.out.println(Arrays.toString(dp[2]));
            */

            int max = 0;
            for(int[] d: dp){
                for(int c: d){
                    max = Math.max(max, c);
                }
            }
            System.out.println(max);
        }
    }
    public static void main(String[] args){
        new Main().run();   
    }
}

Measured memory_bytes: 159576
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<double> v(n);
    for(int i =0; i<n ; ++i)
    {
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    long double sum =0;
    long long k = 2;
    for(int i = 0; i< n; ++i)
    {
        if(i == 0 || i == 1)
        {
            sum += 1.0 * v[i];
        }
        else
        {
            sum+= 1.0 * v[i]*k;
            k*= 1LL * 2;
        }
        
    }
    cout << fixed << setprecision(8) <<  1.0 * sum / k;
    
   


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int X,N;
    cin>>X>>N;
    vector<int> list(102,1);
    rep(i,N){
        int p;
        cin>>p;
        list.at(p)=0;
    }
    int ans=0;
    rep(i,102){
        if(list.at(i)){
            if(abs(X-i)<abs(X-ans)){ans=i;}
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const int SIZE=1e6+10;
const double PI=acos(-1);

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	vector<int> cnt(3,0);
	for(int i=0;i<s.size();i++){
		cnt[int(s[i]-'a')]++;
	}
	sort(cnt.begin(),cnt.end());
	cnt[2]-=cnt[0];
	cnt[1]-=cnt[0];
	cnt[0]-=cnt[0];
	if(cnt[2]>=2 || cnt[1]>=2){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3756
#include <iostream>

using namespace std;

int main()
{
    int a, b,c;

    cin >> a >> b >> c;

    int temp;
    temp = b;
    b = a;
    a = temp;
    temp = a;
    a = c;
    c = temp;

    cout << a << " " << b << " " << c;
}

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

int main() {
  int A,B;
  cin>>A>>B;
  if(A>=13){
    cout<<B<<endl;
  }
  else if(A<6){
    cout<<0<<endl;
  }
  else{
    cout<<B/2<<endl;
  }
}

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

int main() {

  string S,T;
  cin >> S >> T;

  for (int i=0; i<S.size(); i++) {
    if (S == T) {
      cout << "Yes" << endl;
      return 0;
    }

    int len = S.size();
    char c = S[len-1];
    for(int i = len - 1; i > 0; --i) {
        S[i] = S[i-1];
    }
    S[0] = c;

  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    int a,b,c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) <<endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var diffs = new List<int>();
            for (int i = 0; i < S.Length-2; i++)
            {
                diffs.Add(Math.Abs(753 - int.Parse(S.Substring(i, 3))));
            }
            Console.WriteLine(diffs.Min());
        }
    }
}


Measured memory_bytes: 13268
a,b = map(int, input().split())
A1=int((a//0.08)//1)
A2=int((a+2//0.08)//1)
B1=b*10
B2=(b+2)*10
s=min(A1,A2,B1,B2)
t=max(A1,A2,B1,B2)
ans=-1
for i in range(s,t+1):
    if i*0.08//1==a and i*0.1//1==b:
        ans=i
        break
print(ans)

Measured memory_bytes: 9264
#include<iostream>
using namespace std;
int main(){
	int n,w;
	cin >> n;
	cin >> w;
	long long value[n];
	int weight[n];
	for(int a = 0;a < n;a++){
	    cin >> weight[a];
		cin >> value[a];
	}
	long long dp[n+1][w+1];
	for(int a = 0;a <= n;a++){
		dp[a][0] = 0;
	}
	for(int a = 0;a <= w;a++){
		dp[0][a] = 0;
	}
	for(int a = 1;a <= n;a++){
		for(int b = 1;b <= w;b++){
			if (weight[a-1] > b) dp[a][b] = dp[a-1][b];
			else dp[a][b] = max(dp[a-1][b],dp[a-1][b-weight[a-1]] + value[a-1]);
		}
	}
	cout << dp[n][w];
}

Measured memory_bytes: 79104
#include <stdio.h>
int BinarySearch (int* ,int ,int);
int main()
{
  int i,a=0,same=0;
  int S[100000],T[50000],s_num,t_num;
  scanf("%d",&s_num);
  for(i=0;i<s_num;i++)
    { 
      scanf("%d",&S[i]);
      // printf("S %d \n",S[i]);
    }
  scanf("%d",&t_num);
  for(i=0;i<t_num;i++)
    {
      scanf("%d",&T[i]);
      // printf("T %d \n",T[i]);
    }

  for(i=0;i<t_num;i++)
    {
      same+=BinarySearch(S,T[i],s_num);
      // printf("aaaaaaaaa\n");
    }
  printf("%d\n",same);
  return 0;
}

int BinarySearch(int* S,int key,int s_num)
{
  int i=0,left=0,right=s_num,mid=0;
  while(left < right)
    {
      mid = (left+right)/2;
      if(key == S[mid]) return 1;
      else if (key > S[mid]) left = mid +1;
      else right = mid;
    }
  return 0;
}

Measured memory_bytes: 1184
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp;
	int n;
	cin >> n;
	vector<ll> a(n);
	REP(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	
	bool ch = true;
	ans = 1;
	REP(i, n){
		if(ans == 0 || a[i] <= (ll)1000000000000000000 / ans){
			ans *= a[i];
		}
		else ch = false;
	}
	if(ch) cout << ans << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 4052
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a:usize,
        b:usize,
        c:usize
    }

    let ans = std::cmp::min(c, a + b + 1) + b;
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << "\n";
}

Measured memory_bytes: 256
#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<pair<pair<string,int>,int>> p(n);
  rep(i,n){
    cin>>p[i].fi.fi>>p[i].fi.se;
    p[i].fi.se*=-1;
    p[i].se=i+1;
  }

  sort(all(p));

  for(auto x : p){
    cout << x.se << endl;
  }

}


Measured memory_bytes: 256
/*
 
dunjen_master
 
*/
 
 

 
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
 
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;
 
typedef long long int ll;
typedef unsigned long long int llu;
 
 

inline ll mul(ll a,ll b){

    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
inline ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}

  

 
#define all(x) (x).begin(),(x).end()


ll a[105][105];
ll c[105];


int main(){


   
    ll n,m,x;
    cin>>n>>m>>x;

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

    ll ans=1e18;
    for(int i=0;i<(1<<n);i++){
        ll b[m];
        ll ans22=0;
        memset(b,0,sizeof(b));
        for(int j=0;j<n;j++){
            if(i&(1<<j)){
                for(int k=0;k<m;k++){
                    b[k]+=a[j][k];
                }
                ans22+=c[j];
            }
        }
        bool f=true;
        for(int k=0;k<m;k++){
            if(b[k]<x)f=false;
        }

        if(f){
            ans=min(ans,ans22);
        }
    }
    if(ans==(ll)1e18){
        cout<<"-1"<<endl;
        return 0;
    }
    cout<<ans<<endl;
   

    

    
}

    

    
 
    



Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n,k; cin>>n>>k;
    bool num[10]={};
    rep(i,k){
        int d; cin>>d;
        num[d]=1;
    }
    for(int i=n;;i++){
        int tmp=i;
        bool flg=1;
        while(tmp>0){
            if(num[tmp%10]){
                flg=0; break;
            }
            tmp/=10;
        }
        if(flg){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int w, d;
	while (cin >> w >> d, w, d) {
		int a1[22] = {}, a2[22] = {};
		for (int i = 0; i < w; i++) { int k; cin >> k; a1[k]++; }
		for (int i = 0; i < d; i++) { int k; cin >> k; a2[k]++; }
		int ans = 0;
		for (int i = 1; i <= 20; i++)
			ans += max(a1[i], a2[i])*i;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3044
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int H, W; cin >> H >> W;
  vector<vector<char> > cambus(H, vector<char>(W));
  rep(i, H) {
    rep(j, W) cin >> cambus[i][j];
  }
  rep(i, H) {
    rep(j, W) {
      if (cambus[i][j] == '.') continue;
      bool can = false;
      if (i != 0) can = can || cambus[i - 1][j] == '#';
      if (j != 0) can = can || cambus[i][j - 1] == '#';
      if (j != W - 1) can = can || cambus[i][j + 1] == '#';
      if (i != H - 1) can = can || cambus[i + 1][j] == '#';
      if (!can) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input()) 
A = list(map(int, input().split())) 
cnt = 0
for j in range(N-1):
    min_i = j
    for i in range(j, N):
        if A[i] < A[min_i]:
            min_i = i
    if A[j] > A[min_i]:
        v = A[j]
        A[j] = A[min_i]
        A[min_i] = v
        cnt += 1
print(*A)
print(cnt)


Measured memory_bytes: 5600
while 1:
    h, m, s = map(int, raw_input().split())
    if h == m == s == -1:
        break
    rest = 2 * 60 * 60
    rest -= h * 60 * 60 + m * 60 + s
    rest3 = rest * 3
    print "%02d:%02d:%02d" % (rest / 3600, rest % 3600 / 60, rest % 3600 % 60)
    print "%02d:%02d:%02d" % (rest3 / 3600, rest3 % 3600 / 60, rest3 % 3600 % 60)

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

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

    d = d*d;
    LL ans = 0;
    while (n--) {
        LL x, y;
        cin >> x >> y;
        ans += (x*x+y*y) <= d;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3636
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
using namespace std;
using lint = long long;
template<class T> using grid = vector<vector<T>>;
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; }
static const lint MOD = (lint)1e9+7;

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

    for (int C = 1; C <= 3; ++C)
    {
        if ((A*B*C) & 1)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        vector<int> a;
        while(n > 0){
            if(n % 26 == 0){
                a.pb(26);
                n -= 26;
            }else{
                a.pb(n % 26);
            }
            n /= 26;
        }
        string ans;
        for(int i = 0; i < a.size(); i++){
            char c = 'a' + a[i] - 1;
            ans += c;
        }
        reverse(all(ans));
        cout << ans << '\n';
    }
}

Measured memory_bytes: 34588
//#include <bits/stdc++.h>
// utility
#include <bitset>
#include <tuple>
#include <typeinfo>
// error handling
#include <cassert>
// string
#include <cctype>
#include <cstring>
#include <string>
// container
#include <array>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// algorithm
#include <algorithm>
// iterator
#include <iterator>
// math
#include <cmath>
#include <complex>
#include <numeric>
#include <random>
// i/o
#include <cstdio>
#include <iomanip>
#include <iostream>

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]) == typeid(INF) and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  rep(i, 0, N) { cin >> v[i]; }
  int ans = INF;
  for (int i = 0; i + K - 1 < N; i++) {
    int l = v[i], r = v[i + K - 1];

    if (l * r >= 0) {
      chmin(ans, max(abs(l), abs(r)));
    } else {
      chmin(ans, abs(l) + abs(r) + min(abs(l), abs(r)));
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024