akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define MAX 3
int ar[MAX][MAX];
int tmp[MAX][MAX];
int arx[4]={0,1,0,-1};
int ary[4]={1,0,-1,0};
void judgeof0(int *,int *);
void swap(int *,int *);
int cal(void);
int dfs(int,int,int,int,const int);

int main(){
  int i,j,ans,x,y,k;
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
      scanf("%d",&ar[i][j]);
    }
  }
  judgeof0(&x,&y);
  for(i=0;i<100;i++){
    for(j=0;j<MAX;j++){
      for(k=0;k<MAX;k++){
	tmp[j][k]=ar[j][k];
      }
    }
  
  ans=dfs(x,y,-1,0,i);
  if(ans!=-1){
    printf("%d\n",ans);
    break;
  }
  for(j=0;j<MAX;j++){
    for(k=0;k<MAX;k++){
      ar[j][k]=tmp[j][k];
    }
  }
  ans=-1;
  if(i==99)printf("%d\n",ans);
  }
  return 0;
}
void judgeof0(int x[],int y[]){
  int i,j;
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
      if(!ar[i][j]){
	*x=j;
	*y=i;
	return;
      }
    }
  }

}

void swap(int x[],int y[]){
  int tmp;
  tmp=*x;
  *x=*y;
  *y=tmp;

}
int cal(){
  int i,tmp,sum=0;
  for(i=0;i<9;i++){
    tmp=ar[i/MAX][i%MAX];
    if(tmp){
      tmp--;
      sum+=abs((i/MAX)-(tmp/MAX))+abs((i%MAX)-(tmp%MAX));
    }

  }

  return sum;
}

int dfs(int x,int y,int t,int dep,const int lim){
  int i,x1,y1,res,h;
  h=cal();
  if(h==0)return dep;
  if(dep+h>lim)return -1;
  for(i=0;i<4;i++){
    x1=x+arx[i];
    y1=y+ary[i];
  
  if(~t && i==(t+2)%9){
    continue;
  }
  if(!(x1>=0&&x1<MAX&&y1>=0&&y1<MAX)){
    continue;
  }
  swap(&ar[y][x],&ar[y1][x1]);
  res=dfs(x1,y1,i,dep+1,lim);
  if(~res){
    return res;
  }
  swap(&ar[y][x],&ar[y1][x1]);
}
  return -1;

}



Measured memory_bytes: 2108
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
#define maxn 200005
const ll mod=1e9+7;
using namespace std;
ll fac[maxn];
ll a[maxn];
ll dis;
 int vis[maxn];
ll quickpow(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=ans*a%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans%mod;
}
void init()
{
    fac[0]=1;
    for(int i=1;i<maxn;i++)
        fac[i]=(fac[i-1]*1LL*i)%mod;
}
ll getc(ll n,ll m)
{
    if(m==0||m==n)
        return 1;
    ll res=fac[n];
 res=res*quickpow(fac[n-m],mod-2)%mod;
 res=res*quickpow(fac[m],mod-2)%mod;
 return res;
}
int main()
{ll n;
memset(vis,0,sizeof(vis));
init();
   scanf("%lld",&n);
   int i;
   for( i=1;i<=n+1;i++)
    {
          scanf("%lld",&a[i]);
          if(!vis[a[i]])
    vis[a[i]]=i;
    else
       dis=i;
    }

for(int i=1;i<=1+n;i++)
{


    ll ans=(getc(n+1,i)-getc(n-dis+vis[a[dis]],i-1)%mod+mod)%mod;

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


Measured memory_bytes: 4352
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

A,B = LI()
print(max(0, A-B*2))


Measured memory_bytes: 6980
use proconio::{input,marker::Usize1};

fn main() {
   input! {
      n:usize,
      mut k:usize,
      mut a:[Usize1;n],
   }

   let mut ans = 0;
   while k != 0 {
      if k & 1 == 1 {
         ans = a[ans];
      }
      a = a.iter().map(|i| a[*i]).collect();
      k >>= 1;
   }

   println!("{}", ans+1);
}


Measured memory_bytes: 6504
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
if n%2==1:
    a.append(0)    
a.sort()
if n%2==1:
    for i in range(1,n+1,2):
        #print(i)
        if a[i]!=(i-1) or a[i-1]!=(i-1):
            print("0")
            exit()
    print(2**((n-1)//2)%mod)
else:
    for i in range(1,n+1,2):
        #print(i)
        if a[i]!=(i) or a[i-1]!=(i):
            print("0")
            exit()
    print(2**(n//2)%mod)


Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
long long n,m,c,i,j,k,h,w,a,b;
int main(){
  cin>>n;
  vector<int> x(n);
  for(;i<n;i++)cin>>x[i],k+=(x[i]-1);
  cout<<k;
}

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

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

  vector<int> A(N),B(N);
  for(int i = N - 1;i >= 0;i--) {
    cin >> A.at(i);
  }
  int head = 0,tail = N - 1;
  for(int i = 0;i < N;i++) {
    if(i % 2 == 0) {
      B.at(head) = A.at(i);
      head++;
    }else {
      B.at(tail) = A.at(i);
      tail--;
    }
  }

  for(int i = 0;i < N;i++) {
    cout << B.at(i) << " ";
  }
  
  cout << endl;

}

Measured memory_bytes: 3712
import scala.io.StdIn

object Main extends App {
  val Array(a, b) = StdIn.readLine().split(' ').map(_.toInt)
  val s = StdIn.readLine()
  val r = s.slice(0, a) + s.slice(a+1, s.length)
  //println(r)
  println(if(s.length == (a + b + 1) && s.charAt(a) == '-' && r.forall(p => p.isDigit)) "Yes" else "No")
}


Measured memory_bytes: 27460
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
//
//class UnionFind {
//private:
//    int sz;
//    vector<int> par, size_;
//public:
//    UnionFind(){}
//    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
//        iota(par.begin(), par.end(), 0);
//    }
//    int find(int x){
//        if(par[x] == x) return x;
//        else return par[x] = find(par[x]);
//    }
//    void unite(int x, int y){
//        x = find(x); y = find(y);
//        if(x == y) return;
//        if(size_[x] < size_[y]) swap(x,y);
//        par[y] = x;
//        size_[x] += size_[y];
//    }
//    int size(int x){
//        x = find(x);
//        return size_[x];
//    }
//    bool same(int x, int y){
//        return find(x) == find(y);
//    }
//};
//void no(){
//    cout << "Impossible" << endl;
//    exit(0);
//}
//int main(){
//    cin.tie(nullptr);
//    ios::sync_with_stdio(false);
//    int n, m;
//    cin >> n >> m;
//    vector<vector<int>> g(n);
//    vector<int>a(n);
//    rep(i,n)cin >> a[i];
//    rep(i,m){
//        int x, y;
//        cin >> x >> y;
//        x--;y--;
//        g[x].push_back(y);
//        g[y].push_back(x);
//    }
//    if(m == n - 1){
//        cout << 0 << endl;
//        return 0;
//    }
//    if(n / 2 < n - m - 1){
//        no();
//    }
//}
int main(){
    int a, b, c, d, k;
    cin >> a >> b >> c >> d >> k;
    if(b > d){
        cout << (c - a - 1) * 60 + (60 - b + d) - k << endl;
    }else{
        cout << (c - a) * 60 + (d - b) - k << endl;
    }
}


Measured memory_bytes: 3640
a,b,c,k=map(int,open(0).read().split())
#while k:k-=1;t=a<b;b*=2-t;c*=1+t
while k:k-=1;exec(f'{"bc"[a<b]}*=2')
#while k:k-=1;exec('%c*=2'%'bc'[a<b])
#while k:k-=1;vars()['bc'[a<b]]*=2
print('NYoe s'[b<c::2])

Measured memory_bytes: 9008
import math
n = int(input())
m = int(math.sqrt(n))


min = n
for i in range(1,m+1):
  if n%i == 0:
    waru = i
    shou = n//i
    
    if (waru+shou-2) < min:
      min = waru+shou-2
print(min)

Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
using namespace std;
namespace IO{
	const int BS=(1<<20); int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout);}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush(),OS=OT;}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=Getchar();
		for(;!isdigit(cw);cw=Getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=Getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}
using namespace IO;
int n,fs[M],nt[M],to[M],tmp;
void link(int x,int y){nt[tmp]=fs[x],fs[x]=tmp,to[tmp++]=y;}
int DP(int x,int last){
	int sg=0;
	for(int i=fs[x];i!=-1;i=nt[i]) if(to[i]!=last) sg^=(DP(to[i],x)+1);
	return sg;
}
int main(){
	n=read(),memset(fs,-1,sizeof(fs));
	for(int i=1;i<n;i++){int x=read(),y=read();link(x,y),link(y,x);}
	puts(DP(1,0)?"Alice":"Bob"); return 0;
}

Measured memory_bytes: 9344
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
      	
        //sec--1
        int X = sc.nextInt();
        int Y = sc.nextInt();
        
        //sec--2
        //鶴と亀の数の組合せが存在する
        if(2*X <= Y && 4*X >= Y && Y%2==0 ) {
        System.out.println("Yes");
        } else {
        //鶴と亀の数の組合せが存在しない
        System.out.println("No");
        }
   }
}


Measured memory_bytes: 35448
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-7

#define INF 1e9

/*
 */

int const MaxSize = 800 + 10;
int dist[MaxSize][MaxSize];
string m[MaxSize];
int H, W, K;

int dr[4] = { 0, 1, 0, -1 };
int dc[4] = { 1, 0, -1, 0 };

int nm(int dist) {
	int ans = dist / K;

	if (dist % K)
		ans++;
	return ans + 1;
}

//0 if c, 1 if j
int main() {

	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);
	cin >> H >> W >> K;

	LP(i, 0, H)
		cin >> m[i];

	queue<PII> toVisit;
	LP(i, 0, H)
	{
		LP(j, 0, W)
		{
			dist[i][j] = INF;

			if (m[i][j] == 'S') {
				toVisit.push(PII(i, j));
				dist[i][j] = 0;
			}
		}
	}

	while (toVisit.size()) {
		PII cur = toVisit.front();
		toVisit.pop();
		int r = cur.first;
		int c = cur.second;

		LP(i, 0, 4)
		{
			int nr = r + dr[i];
			int nc = c + dc[i];

			if (nr >= 0 && nr < H && nc >= 0 && nc <= W && dist[nr][nc] == INF
					&& m[nr][nc] != '#') {
				int newD = dist[r][c] + 1;
				if (newD <= K) {
					if (newD == K) {

					} else {
						toVisit.push(PII(nr, nc));
					}

					dist[nr][nc] = newD;
				}
			}
		}
	}

	int ans = INF;

	LP(r, 0, H)
	{
		LP(c, 0, W)
		{
			if (r == 0 || r == H - 1 || c == 0 || c == W - 1) {
				if (dist[r][c] < INF) {
					ans = 1;
				}
			}

			if (dist[r][c] < INF) {

					//cout << "HERE??" << r << " " << c << " " << dist[r][c] << endl;
				ans = min(ans, nm(r));
				ans = min(ans, nm(H - 1 - r));
				ans = min(ans, nm(c));
				ans = min(ans, nm(W - 1 - c));
			}
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 3456
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
map<int,bool>m;
int M(int a,int b)
{
    if(a>b) swap(a,b);
    while(b%a!=0)
    {
        int t=b%a;
        b=a;
        a=t;
    }
    return a;
}
int main()
{
    int n,x,a[100005];
    bool flag=false;
    scanf("%d%d",&n,&x);
    for(int i=0;i<n;i++)
        {scanf("%d",&a[i]);if(a[i]==x) flag=true;}
    if(!flag)
        a[n++]=x;
    sort(a,a+n);
    int cnt=0;
    for(int i=1;i<n;i++)
    {
        int t=a[i]-a[i-1];
        if(!m[t]) a[cnt++]=t,m[t]=true;
    }
    int ans=a[0];
    for(int i=1;i<cnt;i++)
    {
        if(ans==1) break;
        else ans=M(ans,a[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
<?php
list($n) = ints();
$base = [
    [0, 0],
    [0, 10 ** 9],
];
$mins = array_fill(0, 4, PHP_INT_MAX);
$maxs = array_fill(0, 4, 0);
for ($i = 0; $i < $n; ++$i) {
    list($x, $y) = ints();
    for ($j = 0; $j < 2; ++$j) {
        $d = abs($base[$j][0] - $x) + abs($base[$j][1] - $y);
        if ($d < $mins[$j]) $mins[$j] = $d;
        if ($d > $maxs[$j]) $maxs[$j] = $d;
    }
}
$max = 0;
for ($i = 0; $i < 4; ++$i) {
    if ($maxs[$i] - $mins[$i] > $max) $max = $maxs[$i] - $mins[$i];
}
echo $max;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16148
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main() {
    int a,b;
    cin>>a>>b;
    int maxi=0;
    rep(i,a){
        int sum=0;
        rep(j,b){
            int a;
            cin>>a;
            if(a==1)sum++;
        }
        maxi=max(maxi,sum);
    }
    cout<<maxi<<endl;
    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
using namespace std;

int main(void) {
	int n, m, x, a[100];
	int mae = 0, ato = 0;
	cin >> n >> m >> x;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		if (a[i] < x) mae++;
		else if(x < a[i]) ato++;
	}
	cout << min(mae, ato) << endl;
	return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
mod = 10 ** 9 + 7

i = 2
f = 1
fn = N
while i <= A:
    f = (f * i) % mod
    fn = (fn * (N + 1 - i)) % mod
    i += 1
fa, fna = f, fn
while i <= B:
    f = (f * i) % mod
    fn = (fn * (N + 1 - i)) % mod
    i += 1
fb, fnb = f, fn


def pow(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return pow(x, y // 2) ** 2 % mod
    else:
        return x * pow(x, y // 2) ** 2 % mod


nca = (fna * pow(fa, mod - 2)) % mod
ncb = (fnb * pow(fb, mod - 2)) % mod
print((pow(2, N) - 1 - nca - ncb) % mod)


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

int main() {
	int N;
	priority_queue<int> m;
	priority_queue<int, vector<int>, greater<int>> p;
	vector<int> x;
	vector<int> y;

	cin >> N;
	for( int i = 0; i < N; i++ ) {
		int A;
		cin >> A;
		if( A < 0 ) {
			m.push( A );
		}
		else {
			p.push( A );
		}
	}

	int ans = 0;
	if( p.empty() ) {
		ans = m.top();
		m.pop();
		while( !m.empty() ) {
			x.push_back( ans );
			y.push_back( m.top() );
			ans -= m.top();
			m.pop();
		}
	}
	else if( m.empty() ) {
		ans = p.top();
		p.pop();
		while( p.size() > 1 ) {
			x.push_back( ans );
			y.push_back( p.top() );
			ans -= p.top();
			p.pop();
		}
		x.push_back( p.top() );
		y.push_back( ans );
		ans = p.top() - ans;
	}
	else {
		while( p.size() > 1 ) {
			ans = m.top();
			x.push_back( ans );
			y.push_back( p.top() );
			ans -= p.top();
			m.push( ans );
			m.pop();
			p.pop();
		}
		ans = p.top();
		while( !m.empty() ) {
			x.push_back( ans );
			y.push_back( m.top() );
			ans -= m.top();
			m.pop();
		}
	}

	cout << ans << endl;
	for( int i = 0; i < x.size(); i++ ) {
		cout << x[i] << " " << y[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3576
N,M = map(int, input().split())
H = list(map(int, input().split()))
A = [list(map(int,input().split())) for i in range(M)]
#print(A)
#print(H)
res = []




for i in A:
    #print(i)
    if H[i[0]-1] > H[i[1]-1]:
        res.append(i[1])
    elif H[i[0]-1] == H[i[1]-1]:
        res.append(i[0])
        res.append(i[1])
    else:
        res.append(i[0])
print(N-len(set(res)))

Measured memory_bytes: 34508
// 582 F Next Level DSU
#include<bits/stdc++.h>
#define pb push_back
#define f first
#define s second     
#define fio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define mp make_pair
#define int long long
#define double float

using namespace std;
template <typename T>
void watch(vector<T> v)
{
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";
    cout<<"Look above\n";
    cout<<"\n";
}
const int INF = 1e15;
const int MAX = 2e5+3;
int MOD = 998244353;
int32_t main()
{
      fio
      int n;
      cin>>n;
      vector<int> ord[n];
      for(int i=0;i<n;i++)
      {
         for(int j=0;j<n-1;j++)
         {
            int x;
            cin>>x;
            x--;
            ord[i].pb(x);
         }
      }

      vector<int> ptr(n, 0);
      set<int> count;
      for(int i=0;i<n;i++)
         count.insert(i);
      set<pair<int, int > > st;
      vector<int> changed;
      for(int i=0;i<n;i++){
         int x = i, y = ord[i][0];
         if(x > y)
            swap(x, y);
         if(st.find({x, y}) == st.end())
            st.insert({x, y});
         else
         {
            st.erase({x, y});
            changed.pb(x);
            changed.pb(y);
            ptr[x]++;
            ptr[y]++;
            if(ptr[x] == n-1)
               count.erase(x);
            if(ptr[y] == n-1)
               count.erase(y);
              
         }
         
      }
      if(changed.size() == 0)
      {
         cout<<-1;
         return 0;
      }
      int days = 1;
      while(!count.empty())
      {
         vector<int> temp;
         for(int i=0;i<changed.size();i++)
         {
            int ind = changed[i];
            int x = ind, y = ord[ind][ptr[ind]];
            if(x > y)
               swap(x, y);
            if(st.find({x, y}) == st.end())
               st.insert({x, y});
            else
            {
               st.erase({x, y});
               temp.pb(x);
               temp.pb(y);
               ptr[x]++;
               ptr[y]++;
               if(ptr[x] == n-1)
                  count.erase(x);
               if(ptr[y] == n-1)
                  count.erase(y);
            }
         }
         changed = temp;
         if(changed.size() == 0)
         {
            days = -1;
            break;
         }
         days++;
      }
      cout<<days;

}



Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 505
int n,m;
char mp[MN][MN];
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
	for(int i=1;i<=n;i++,puts("")){
		for(int j=1;j<=m;j++)
		if(j==1) printf("#");
		else if(i&1&&j!=m) printf("#");
		else cout<<mp[i][j];
	}
	puts("");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
		if(j==m) printf("#");
		else if(~i&1&&j!=1) printf("#");
		else cout<<mp[i][j];
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <ctime>

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define TT int test_cases; cin >> test_cases; while(test_cases--)
#define TT1 int test_cases=1; while(test_cases--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
using namespace std;
typedef long long int ll;

 
int main() {
    
    FAST;
    TT1{
        
        int x,n;cin>>x>>n;
        vector<int> p(n);
        unordered_map<int,int> h;
        for(int i=0;i<n;i++)
        {
            cin>>p[i];
            h[p[i]]=1;
        }
        int ans=x;
        
        for(int i=0;i<=n;i++)
        {
            int x1=x-i;
            int x2=x+i;
            
            if(h[x1]==0) {ans=x1;break;}
            if(h[x2]==0) {ans=x2;break;}
        }
        cout<<ans<<"\n";
        
        
    }
}

Measured memory_bytes: 3668
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#define N 200011
using namespace std;
int ti,All[N],siz,tot,indexx[N],dp[N],vist[N],hashh[N],n,fa[N],cir[N],cnt;
vector<int> V[N];
struct apple{
	int v,nxt;
}edge[N*4];
void addedge(int x,int y){
	edge[++tot].v=y;
	edge[tot].nxt=indexx[x];
	indexx[x]=tot;
}
void dfs(int u,int f){
	int t=indexx[u],vv;
	while(t){
		vv=edge[t].v;
		if(!cir[vv] || vv==f){
			dfs(vv,u);
			V[u].push_back(dp[vv]);
		}
		t=edge[t].nxt;
	}
	ti++;
	int len=V[u].size();
	for(int i=0;i<len;i++){
		hashh[V[u][i]]=ti;
	}
	for(int i=0;i<=n*2;i++){
		if(hashh[i]!=ti){
			dp[u]=i;
			break;
		}
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&fa[i]);
		addedge(fa[i],i);
	}
	int x=1;
	while(1){
		if(vist[x]) break;
		vist[x]=1;
		x=fa[x];
	}
	memset(vist,0,sizeof(vist));
	int u=x;
	while(1){
		if(cir[u]) break;
		cir[u]=1;
		cnt++;
		u=fa[u];
	}
	if(cnt%2==0){
		printf("POSSIBLE");
		return 0;
	}
	u=x;
	while(1){
		if(vist[u]) break;
		vist[u]=1;
		dfs(u,0);
		All[++siz]=dp[u];
		u=fa[u];
	}
	sort(All+1,All+siz+1);
	for(int i=1;i<siz;i++){
		if(All[i]!=All[i+1]){
			printf("POSSIBLE");
			return 0;
		}
	}
	printf("IMPOSSIBLE");
	return 0;
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int l, r, d, ans = 0;
    cin >> l >> r >> d;
    ans = (int)(r / d) - (int)((l - 1) / d);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)

void resolve()
{
    int N, M;
    cin >> N >> M;
    vector<int> s(M), c(M);
    RPT0(i, M) cin >> s[i] >> c[i];

    int start = (N == 1) ? 0 : (N == 2) ? 10 : (N == 3) ? 100 : 0;
    int end = (N == 1) ? 9 : (N == 2) ? 99 : (N == 3) ? 999 : 0;

    int ans = -1;
    RPT(i, start, end)
    {
        bool hit = true;
        RPT0(j, M)
        {
            string str = to_string(i);
            int target = str[s[j] - 1] - '0';
            if (target != c[j]) {
                hit = false;
                break;
            }
        }
        if (hit) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long x,y,h,no;
int g;
int main()
{
    cin>>x>>y;
    h=y/x;
    no=1;
    while(no<=h)
    {
        g++;
        no*=2;
    }
    cout<<g<<endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> vec(n, 0);
    for(int i = 2, a; i <= n; i++){
        scanf("%d", &a);
        vec[a-1]++;
    }
    for(auto x : vec){
        printf("%d\n", x);
    }
    return 0;
}

Measured memory_bytes: 4048
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	map<string, int> a;
	int f = 0, l = 0;
	string s, t;
	for (string b; cin >> b;) {
		if (f < ++a[b]) {
			s = b;
			f = a[b];
		}
		if (l < b.size()) {
			t = b;
			l = b.size();
		}
	}
	cout << s << " " << t << endl;
	return 0;
}

Measured memory_bytes: 1196
from collections import deque
A, B, C = map(deque, (input(), input(), input()))
d = {'a':A, 'b':B, 'c':C}
c = 'a'
while True:
  X = d[c]
  if not X:
    print(c.upper())
    exit()
  c = X.popleft()


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

int main(){
    int m,f,r;
    int num = 0;
    string grade;
    while(1){
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r ==-1) break;
        if(m + f < 30 || m == -1 || f == -1) grade += 'F';
        else if(m + f >= 80) grade += 'A';
        else if(m + f >=65 && m + f < 80) grade += 'B';
        else if(m + f >= 50 && m + f < 65) grade += 'C';
        else if(m + f >= 30 && m + f < 50) {
            (r >= 50)?grade+= 'C':grade+='D';
        }
       
    }
    for(int i = 0; i < grade.length(); i++){
        cout << grade[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>
#include<queue>
#include<set>
#include<math.h>
#include<random>
#include<set>

#define lli long long int
#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}

struct SegmentTree {
private:
	int n;
	vector<long long int> node;
	int TANNI;

	long long int Func(long long int a, long long int b) {
		return min(a,b);
	}

public:
	//元配列ｖをセグメント木で表現する。
	SegmentTree(vector<long long int> v, long long int tanni) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪→これをｎとおく。
		//セグメント木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1;
		while (n < sz)n *= 2;

		TANNI = tanni;
		node.resize(2 * n - 1, TANNI);

//最下段に値を入れた後に、下の段から順番に値を入れる。
//値を入れるには、自分の子の２値を参照すればよい。
for (int i = 0; i < sz; i++)node[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)node[i] = Func(node[2 * i + 1], node[2 * i + 2]);
	}

	void update(long long int x, long long int val) {
		//最下段のノードにアクセスする。
		x += (n - 1);

		//最下段のノードを更新したら、あとは親に上って更新していく。
		node[x] = val;

		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = Func(node[2 * x + 1], node[2 * x + 2]);
		}
	}

	long long int getVal(int x) {
		x += (n - 1);
		return node[x];
	}

	long long int getAns(int a, int b, int k = 0, int l = 0, int r = -1) {
		//最初に呼び出された時の区間は[0,n)
		if (r < 0)r = n;

		//要求区間と対象区間が交わらない→単位元を返す。
		if (r <= a || b <= l) return TANNI;

		//要求区間が対象区間を完全に被覆する→対象区間を答えの計算に使う。
		if (a <= l && r <= b) return node[k];

		//要求区間が対象区間の一部を被覆→子をよびだす。
		//左の子をvl、右の子をvrとしている。
		//新しい対象区間は現在の対象区間を半分に割ったもの。
		int vl = getAns(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = getAns(a, b, 2 * k + 2, (l + r) / 2, r);
		return Func(vl, vr);


	}



};



int main()
{
	string str;
	cin >> str;

	if (str == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}



	return 0;

}



Measured memory_bytes: 3628
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <numeric>
#define ll long long
#define MODD 998244353
#define MAXA 1000000
using namespace std;


ll sum_vals[MAXA+1];
ll sum_sq_vals[MAXA+1];
int smallest_prime[MAXA+1];
int moebius[MAXA+1];
ll pairwise_prod[MAXA+1];

ll modpow(ll x, ll y) {
    x%=MODD;
    ll xs = x;
    ll answer = 1;
    while(y) {
        if (y&1) {
            answer = (answer * xs) % MODD;
        }
        y >>= 1;
        xs = (xs * xs) % MODD ;
    }
    return answer;
}



int main() {

    for(int i=1;i<=MAXA;i++) {
        smallest_prime[i]=-1;

    }
    for(int i=2;i<=MAXA;i++) {
        if(smallest_prime[i]==-1) {
            for(int j=i;j<=MAXA/i;j++) {
                smallest_prime[j*i]=i;
            }
            smallest_prime[i]=i;
        }
    }
    
    moebius[1]=1;
    for(int i=2;i<=MAXA;i++) {
        int x=i;
        int p=smallest_prime[i];
        while(x%p==0) {
            x/=p;
        }
        if(x*p==i) {
            moebius[i]=-moebius[x];
        } else {
            moebius[i]=0;
        }
        
    }
    
    
    for(int i=1;i<=MAXA;i++)
        sum_vals[i]=sum_sq_vals[i]=0;
    
    int N;
    cin>>N;
    for(int i=1;i<=N;i++) {
        int x;
        cin>>x;
        vector<int> divs;
        for(int y=1;y*y<=x;y++) {
            if (x%y==0) {
                divs.push_back(y);
                if (y*y != x) {
                    divs.push_back(x/y);
                }
            }
        }
        for(int y : divs) {
            sum_vals[y] += x;
            sum_sq_vals[y] += (ll)x*(ll)x;
            sum_vals[y] %= MODD;
            sum_sq_vals[y] %= MODD;
        }
    }
    
    ll TWO_INV = modpow(2, MODD-2);
    for(int x=1;x<=MAXA;x++) {
        pairwise_prod[x]=(-sum_sq_vals[x]+sum_vals[x]*sum_vals[x]);
        pairwise_prod[x]%=MODD;
        pairwise_prod[x]*=TWO_INV;
        pairwise_prod[x]%=MODD;
        pairwise_prod[x]=(pairwise_prod[x]+MODD)%MODD;
    }
    
    ll ans = 0;
    for(int x=1;x<=MAXA;x++) {
        ll curr_sum = 0;
        for(int y=1;x*y<=MAXA;y++) {
            curr_sum += pairwise_prod[x*y]*moebius[y];
            curr_sum %= MODD;
        }
        curr_sum = (curr_sum+MODD)%MODD;
        ans += curr_sum * modpow(x, MODD-2)%MODD;
        ans %= MODD;
    }
    
    
    cout << ans << endl;
    
    // dp[x] = sum_{y} pairwise_prod[x*y]*moebius[y].
    
    
    
    // val[x]=1/x*pairwise_prod[x]
    // x*val[x]=pairwise_prod[x]

}


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


int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; i++){
    cin >> s.at(i);
  }

  for(int i=0; i<n; i++){
    sort(s.at(i).begin(), s.at(i).end());
  }
  sort(s.begin(),s.end());

  int64_t count = 0;
  int64_t sc = 1;
  string s0 = "a";
  for(int i=0; i<n-1; i++){
    string s1 = s.at(i);
    string s2 = s.at(i+1);
    if(s2 != s1){
      count += sc*(sc-1)/2;
      sc = 1;
    }else{
      sc += 1;
    }
  }
  if(sc != 1){
    count += sc*(sc-1)/2;
  }

  cout << count << endl;

}

Measured memory_bytes: 7296
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

struct Node {
    ll l,r,cnt;
    Node () {};
    Node (ll l, ll r , ll cnt) : l(l), r(r), cnt(cnt) {}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<ll> L(N+1),R(N+1),overl(N),overr(N);
    rep(i,N-1) {
        ll tmpl = A[i], tmpr = A[i+1];
        if (A[i] < A[i+1]) {
            while (tmpl < tmpr) {
                tmpl *= 4;
                overl[i+1]++;
            }
        } else {
            while (tmpl >= tmpr*4) {
                tmpr *= 4;
                overl[i+1]--;
            }
        }

        tmpl = A[i];
        tmpr = A[i+1];
        if (A[i] > A[i+1]) {
            while (tmpl > tmpr) {
                tmpr *= 4;
                overr[i]++;
            }
        } else {
            while (tmpl*4 <= tmpr) {
                tmpl *= 4;
                overr[i]--;
            }
        }
    }
    vector<Node> sta;
    rep(i,N) {
        Node node = Node(i,i+1,0);
        L[i+1] = L[i];
        while (true) {
            if (sta.empty() or node.cnt + overl[node.l] <= 0) {
                sta.emplace_back(node);
                break;
            }
            ll val = node.cnt + overl[node.l];
            auto top = sta.back(); sta.pop_back();
            L[i+1] += val*(top.r-top.l)*2;
            node.l = top.l;
            node.cnt = val+top.cnt;
        }
        L[i+1]++;
    }

    sta.clear();
    for (int i = N-1; i >= 0; i--) {
        Node node = Node(i-1,i,0);
        R[i] = R[i+1];
        while (true) {
            if (sta.empty() or node.cnt + overr[node.r] <= 0) {
                sta.emplace_back(node);
                break;
            }
            ll val = node.cnt + overr[node.r];
            auto top = sta.back(); sta.pop_back();
            R[i] += val*(top.r-top.l)*2;
            node.r = top.r;
            node.cnt = val+top.cnt;
        }
    }

    ll ans = 1e18;
    rep(i,N+1) {
        chmin(ans,L[i]+R[i]);
    }

    cout << ans << ln;
}


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

ll solve(vector<int> A, vector<int> B, int N) {
    ll res = 0;
    rep(i, 0, N) {
        int d = min(A[i], B[i]);
        A[i] -= d;
        B[i] -= d;
        res += d;
        d = min(A[i+1], B[i]);
        A[i+1] -= d;
        B[i] -= d;
        res += d;
    }
    return res;
}


int main() {
    int N; cin >> N;
    vector<int> A(N+1), B(N);
    rep(i, 0, N+1) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    ll ans = solve(A, B, N);
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    ans = max(ans, solve(A, B, N));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int N, M, K, Q, W, H, R, C;
string S;

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

    cin >> N;
    vector<int> X(N);
    REP(i, N) cin >> X.at(i);

    int ans = INF;
    for (int x = -100; x <= 100; x++) {
        int sum = 0;
        REP(i, N) { sum += (X[i] - x) * (X[i] - x); }
        chmin(ans, sum);
    }

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


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

using namespace std ; 

const int N = 3e4 + 7 ;

bool vis[N] ;
int rem ; 

int roof = N - 7 ; 

void add(int x){
        if(vis[x])
                return ; 
        vis[x] = 1; 
        cout<< x<<" "; 
        rem -- ; 
}

int main(){
       // freopen("in.in" , "r" ,stdin) ; 
        int n ; 
        cin >> n; 
        rem = n ; 

        if(n == 3){
                cout<< "2 5 63" ;
        }
        else{
                add(2) ; add(3) ; add(4) ; add(9) ;
                int cur6 = 15  ;
                while(rem > 1 && cur6 + 6 < roof ){
                        add(cur6) ; 
                        add(cur6+6) ; 
                        cur6+=12 ;
                }
                int cur24 = 8 ; 
                while(rem > 1 && cur24 + 2 < roof){
                        add(cur24) ; 
                        add(cur24 +2) ; 
                        cur24+=6 ; 
                }

                int cur60 = 6 ; 

                while(rem && cur60 <= roof){
                        add(cur60) ; 
                        cur60+= 6 ; 
                }

               
        }

        return 0 ;
}

Measured memory_bytes: 3664
program city_savers
  implicit none
  integer :: n, i
  integer(8) :: a(100001) = 0_8, b(100000) = 0_8, c(100001) = 0_8, m1 = 0_8, m2 = 0_8
  read(*,*) n
  read(*,*) a(1:n+1)
  read(*,*) b(1:n)
  c(1:n+1) = a(1:n+1)
  do i = 1, n
    if (b(i) <= c(i)) then
      m1 = m1+b(i)
      cycle
    end if
    if (b(i) <= c(i)+c(i+1)) then
      m1 = m1+b(i)
      c(i+1) = c(i)+c(i+1)-b(i)
      cycle
    end if
    m1 = m1+c(i)+c(i+1)
    c(i+1) = 0_8
  end do
  c(1:n+1) = a(1:n+1)
  do i = n, 1, -1
    if (b(i) <= c(i+1)) then
      m2 = m2+b(i)
      cycle
    end if
    if (b(i) <= c(i)+c(i+1)) then
      m2 = m2+b(i)
      c(i) = c(i)+c(i+1)-b(i)
      cycle
    end if
    m2 = m2+c(i)+c(i+1)
    c(i) = 0_8
  end do
  write(*,'(i0)') max(m1,m2)
  stop
end program city_savers

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

int main(){
    int a,b;
    cin >> a >> b;
    if (a==b)  cout << "a" << " == " << "b" <<endl;
    if (a>b)  cout << "a" << " > " << "b" <<endl;
    if (a<b)  cout << "a" << " < " << "b" <<endl;
}


Measured memory_bytes: 3088
#include <iostream>

using namespace std;

const int MAX = 100;
unsigned long long luca[MAX];

unsigned long long luca_num(int N){
    if(N == 0) return 2;
    if(N == 1) return 1;
    if(N >= 2){
        if(luca[N] != 0) return luca[N];
        else{
            return luca[N] = luca_num(N-1) + luca_num(N-2);
        }
    }
}

int main(){
    int N;
    cin >> N;
    cout << luca_num(N) << endl;

    return 0;
}

Measured memory_bytes: 256
import scala.math._
object Main extends App{
    val Array(a,b,preh,m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    
    val h = preh + m/60.0
    
    val pre_angle = (h - m/5.0).abs
    val angle = if(pre_angle <= 6) BigDecimal(pre_angle*30) else BigDecimal((12-pre_angle)*30)
    
    
    println(sqrt((a*a+b*b-2*a*b*cos(angle.toDouble.toRadians)).toDouble))
}


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


int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    int sum = 0;
    for(int i=0;i<n;++i) cin>>a[i];
    sum=accumulate(a.begin(),a.end(),0);
    //cout<<sum;
    sort(a.rbegin(),a.rend());
    int co = 0;
    sum = ceil(sum /(4.0*m));
    //cout<<sum;
    for(int i=0;i<n;++i)
    {
        if(a[i]>=sum) co++;
    }
    if(co>=m) cout<<"Yes";
    else cout<<"No";
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a,b,c,ans=0,tmp=0;
  cin >> a;
  rep(i,a){
    cin >> b >> c;
    if(b==c){
      tmp++;
    }
    else {
     ans = max(ans,tmp);
     tmp = 0;
    }
  }
  ans = max(ans,tmp);
  if(ans>=3) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 3632
#ifdef _MSC_VER
#  define _CRT_SECURE_NO_WARNINGS
#  define _USE_MATH_DEFINES
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double;
using u32 = unsigned int; using u64 = unsigned long long int; using str = string;
template <typename T> using vec = vector<T>; void in() { }
template <typename T, typename...TS> void in(T &&x, TS &&...xs) { cin >> x; in(move(xs)...); }
template <typename T> void out(T &&x) { cout << x << "\n"; }
template <typename T, typename...TS> void out(T &&x, TS &&...xs) { cout << x << " "; out(move(xs)...); }
#define indef(t, ...) t __VA_ARGS__; in(__VA_ARGS__)
#define get(t) []{ t x; cin >> x; return x; }()
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define even(x) ((abs(x) & 1) == 0)
#define odd(x) ((abs(x) & 1) == 1)
#define bit(x, i) (((x) >> i) & 1)
#define append emplace_back
#define bisect_left lower_bound
#define bisect_right upper_bound
#define bound(a, x, b) (a <= x && x <= b)
const i64 MOD = 1000000007ll;
const f64 EPS = 1e-10;

void solve() {
    indef(str, s);
    times(3-s.size(), _) {
        s = "0" + s;
    }
    out("ABC" + s);
}

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

#ifdef _MSC_VER
    /**
    ifstream fin("input.txt"); cin.rdbuf(fin.rdbuf()); assert(fin);
    ofstream fout("output.txt"); cout.rdbuf(fout.rdbuf()); assert(fout);
    /**/
#endif

    //cout << fixed << setprecision(9);
    solve();
    return 0;
}

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

using namespace std;

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

    vector<vector<int> > dp(n+1, vector<int>(n+1, 0));

    int ans = 0;

    for(int i=n-1; i>=0; i--){
        for(int j=n-1; j>i; j--){
            if(str[i]==str[j])
                dp[i][j] = dp[i+1][j+1]+1;
            else
                dp[i][j] = 0;
            ans = max(ans, min(dp[i][j], j-i));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 98304
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '1') ans++;
    }    
    cout << ans << endl;
}

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

#define all(A) begin(A), end(A)
#define sz(A) int(A.size())

using namespace std;

typedef long long ll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  ll n;
  cin >> n;
  vector <ll> div;
  for (ll d = 1; d * d <= n; d++) {
    if (n % d == 0) {
      if (d != 1) div.push_back(d);
      if (d != n / d) div.push_back(n / d);
    }
  }
  ll ans = 0;
  for (ll d: div) {
    ll m = d - 1;
    if (n % m == n / m) {
      ans += m;
    }
  }
  cout << ans << endl;
  return (0);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 500 + 10, M = 1000000000 + 7;
int n, need[N], memo[N], row[N];
char s[N][N];

void paint(int x, int y) {
	for (int i = 0; i < n; ++i)
		memo[i] = s[x][i];
	for (int i = 0; i < n; ++i)
		s[i][y] = memo[i];
}

int calc(int idx, int jdx) {
	int ret = 0;
	for (int i = 0; i < n; ++i) {
		if (s[idx][i] == '.' && jdx != i) {
			++ret;
			paint(jdx, i);
		}
	}
	if (s[idx][jdx] == '.') {
		++ret;
		paint(jdx, jdx);
	}
	for (int j = 0; j < n; ++j)
		for (int i = 0; i < n; ++i)
			if (s[i][j] == '.') {
				++ret;
				break;
			}
	return ret;
}

int main() {
	if (0) freopen("a.in", "r", stdin);
	scanf("%d", &n);
	memset(row, -1, sizeof row);
	for (int i = 0; i < n; ++i) {
		scanf("%s", s[i]);
		for (int j = 0; j < n; ++j) {
			if (s[i][j] == '#') row[j] = i;
			else ++need[i];
		}
	}
	int mn = 1e9;
	for (int i = 0; i < n; ++i)
		mn = min(mn, need[i]);
	if (mn == n)
		return cout << -1 << endl, 0;
	bool ok;
	for (int i = 0; i < n; ++i)
		if (need[i] == mn && row[i] != -1)
			return cout << calc(i, row[i]) << endl, 0;
	for (int i = 0; i < n; ++i)
		if (need[i] == mn) {
			paint(i, i);
			return cout << 1 + calc(i, i) << endl, 0;
		}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 36;
struct Card { char suit; int value; };

int bubble(struct Card A[], int n) {
	for (int i = 0; i < n; i++) {
		for (int j = n-1; j > i; j--) {
			if (A[j].value < A[j - 1].value) {
				Card temp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = temp;
			}
		}
	}
	return 0;
}

int selection(struct Card A[], int n) {
	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (A[j].value < A[minj].value) {
				minj = j;
			}
		}
		Card temp = A[i];
		A[i] = A[minj];
		A[minj] = temp;
	}
	return 0;
}

void print(struct Card A[], int n) {
	for (int i = 0; i < n-1; i++) {
		cout << A[i].suit << A[i].value << ' ';
	}
	cout << A[n - 1].suit << A[n - 1].value << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int n) {
	for (int i = 0; i < n; i++) {
		if (C1[i].suit != C2[i].suit) {
			return false;
		}
	}
	return true;
}

int main() {
	int n;
	cin >> n;
	Card C1[MAX], C2[MAX];
	for (int i = 0; i < n; i++) {
		cin >> C1[i].suit >> C1[i].value;
	}
	for (int i = 0; i < n; i++) {
		C2[i] = C1[i];
	}
	bubble(C1, n);
	selection(C2, n);

	print(C1, n);
	cout << "Stable" << endl;
	print(C2, n);
	if (isStable(C1, C2, n)) {
		cout<< "Stable" << endl;
	}else {
		cout << "Not stable" << endl;
	}

	return 0;
}


Measured memory_bytes: 3104
#include <cstdio>

int main()
{
    int no_of_elements;
    scanf("%d", &no_of_elements);

    long long sum = 0;
    while(no_of_elements--)
    {
        int element;
        scanf("%d", &element);

        sum += element - 1;
    }

    printf("%d\n", sum);
    return 0;
}

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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

const int dx[4] = {0,  0, 1, -1};
const int dy[4] = {1, -1, 0,  0};

const int N = 100001;
int n;
ll cnt[N];
bool isPrime(int n){
		for(int i = 2; i <= sqrt(n); i++)
			if (n % i == 0)
				return false;
		return true;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	
	for(int i = 2; i <= n; i++){
			int x = i;
			int d = 2;
			
			while(x != 0){
				if (isPrime(x)){
					cnt[x]++;
					break;
				}
				while(x % d == 0){
					cnt[d]++;
					x /= d;	
				}
				d++;
			}
	}
	ll ans = 1;
	for(int i = 2; i <= 1000; i++)
		if (cnt[i] > 0){
			ans *= (cnt[i] + 1);
			ans = ans % 1000000007;
		}
	cout << ans << endl;
  	return 0;
}


Measured memory_bytes: 256