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

bool syo[1000][1000];
bool sude[1000][1000];
int zi[1000][1000];
int kox[1000000];
int koy[1000000];
int kon;
int koxs[1000000];
int koys[1000000];
int kons;
int cx[10];
int cy[10];
int sx,sy;

int main()
{
	int h,w,n;
	scanf("%d %d %d",&h,&w,&n);
	for(int i = 0; i < h; i++)
	{
		char ww[1111];
		scanf("%s",ww);
		for(int ii = 0; ii < w; ii++)
		{
			if('1' <= ww[ii] && ww[ii] <= '9')
			{
				int d = ww[ii] - '1';
				cy[d] = i;
				cx[d] = ii;
			}
			if(ww[ii] == 'S')
			{
				sy = i;
				sx = ii;
			}
			if(ww[ii] == 'X')
			{
				syo[i][ii] = true;
			}
			else
			{
				syo[i][ii] = false;
			}
		}
	}
	int time = 0;
	int nx = sx;
	int ny = sy;
	for(int k = 0; k < n; k++)
	{
		for(int i = 0; i < h; i++)
		{
			for(int ii = 0; ii < w; ii++)
			{
				zi[i][ii] = 1000000;
				sude[i][ii] = false;
			}
		}
		zi[ny][nx] = 0;
		kox[0] = nx;
		koy[0] = ny;
		kon = 1;
		while(1)
		{
			kons = 0;
			for(int i = 0; i < kon; i++)
			{
				if(syo[koy[i]][kox[i]] || sude[koy[i]][kox[i]])
				{
					continue;
				}
				sude[koy[i]][kox[i]] = true;
				if(kox[i] == cx[k] && koy[i] == cy[k])
				{
					goto aa;
				}
				if(kox[i] > 0)
				{
					if(zi[koy[i]][kox[i] - 1] > zi[koy[i]][kox[i]])
					{
						zi[koy[i]][kox[i] - 1] = zi[koy[i]][kox[i]] + 1;
						koxs[kons] = kox[i] - 1;
						koys[kons] = koy[i];
						kons++;
					}
				}
				if(kox[i] < w - 1)
				{
					if(zi[koy[i]][kox[i] + 1] > zi[koy[i]][kox[i]])
					{
						zi[koy[i]][kox[i] + 1] = zi[koy[i]][kox[i]] + 1;
						koxs[kons] = kox[i] + 1;
						koys[kons] = koy[i];
						kons++;
					}
				}
				if(koy[i] > 0)
				{
					if(zi[koy[i] - 1][kox[i]] > zi[koy[i]][kox[i]])
					{
						zi[koy[i] - 1][kox[i]] = zi[koy[i]][kox[i]] + 1;
						koxs[kons] = kox[i];
						koys[kons] = koy[i] - 1;
						kons++;
					}
				}
				if(koy[i] < h - 1)
				{
					if(zi[koy[i] + 1][kox[i]] > zi[koy[i]][kox[i]])
					{
						zi[koy[i] + 1][kox[i]] = zi[koy[i]][kox[i]] + 1;
						koxs[kons] = kox[i];
						koys[kons] = koy[i] + 1;
						kons++;
					}
				}
			}
			for(int i = 0; i < kons; i++)
			{
				kox[i] = koxs[i];
				koy[i] = koys[i];
			}
			kon = kons;
		}
aa:
		time += zi[cy[k]][cx[k]];
		nx = cx[k];
		ny = cy[k];
	}
	printf("%d\n",time);
	return 0;
}

Measured memory_bytes: 14328
h, w = gets.chomp.split.map(&:to_i)
a = []
h.times do |i|
  s = gets.chomp.split("")
  next if s.uniq.length == 1 && s[0] == '.'
  a.push(s)
end

b = a.transpose
c = []
w.times do |i|
  s = b[i]
  next if s.uniq.length == 1 && s[0] == '.'
  c.push(s)
end

puts c.transpose.map{|s| s.join}


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

const int INF = 1e7;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<int>> s(h, vector<int>(w));
  rep(i, h) rep(j, w) {
    char c;
    cin >> c;
    s[i][j] = (int)(c - '0');
  }
  
  int ans = INF;
  rep(bit, 1<<(h-1)) {
    int now = 0;
    vector<int> cho(h); // i行目はcho[i]番目のチョコ
    int c = 0;
    rep(i, h-1) {
      if (bit & 1<<i) {
        c++;
        now++;
      }
      cho[i+1] = c;
    }

    vector<int> whi(h);   // i番目のチョコの白マス数
    vector<int> nwhi(h);  // i番目のチョコの1列後の白マス数
    rep(j, w) {
      rep(i, h) nwhi[i] = whi[i];
      rep(i, h) nwhi[cho[i]] += s[i][j];
      rep(i, h) if (nwhi[i] > k) {
        now++;
        rep(i2, h) nwhi[i2] -= whi[i2];
        break;
      }
      rep(i, h) whi[i] = nwhi[i];
      rep(i, h) if (whi[i] > k) {
        now = INF;
        break;
      }
    }
    // printf("now = %d\n", now);
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
using ll = long long;
using P = pair<ll, ll>;
vector<int> to[100005];
int cost[100005];

int x[10];
int y[10];

double dist(ll i, ll j) {
    int xx = (x[i]-x[j])*(x[i]-x[j]);
    int yy = (y[i]-y[j])*(y[i]-y[j]);
    return sqrt(xx+yy);
}

int a[51],b[51],c[51],d[51];
int A[11];
int n, m, q;
ll ans = 0;
void dfs(int dep) {
    //cout << dep << endl;
    if (dep == n+1) {
        int tmp = 0;
        rep(i,q) {
            if(A[b[i]]-A[a[i]]==c[i]) {
                tmp += d[i];
            }
        }
        ans = max(tmp, ans);
        return;
    }
    FOR(i, min(m,A[dep]),m+1) {
        A[dep+1] = i;
        dfs(dep+1);
    }
}

signed main(){
    cin >> n >> m >> q;
    //cout << n <<m << q<< endl;
    rep(i,q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    A[0] = 1;
    dfs(0);
    cout << ans << endl;

    return 0;
}



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

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

using namespace std;
using lint=long long;

int main(){
	int x,y,a,b,c; scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	vector<int> p(a),q(b),r(c);
	rep(i,a) scanf("%d",&p[i]);
	rep(i,b) scanf("%d",&q[i]);
	rep(i,c) scanf("%d",&r[i]);

	sort(p.rbegin(),p.rend());
	sort(q.rbegin(),q.rend());
	sort(r.rbegin(),r.rend());

	while(r.size()>x+y) r.pop_back();

	vector<int> s;
	rep(i,x) s.emplace_back(p[i]);
	rep(i,y) s.emplace_back(q[i]);
	sort(s.rbegin(),s.rend());

	lint ans=accumulate(s.begin(),s.end(),0LL);
	rep(i,r.size()){
		if(s[x+y-1-i]>=r[i]) break;
		ans+=r[i]-s[x+y-1-i];
	}
	printf("%lld\n",ans);

	return 0;
}


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

int nib(int x){
  if(x==0) return 10000;
  int beki=0;
  while(x%2==0){
    beki++;
    x/=2;
  }
  return beki;
}

int main(){
  int A,B,C; cin >> A >> B >> C;
  if(A%2==1||B%2==1||C%2==1){
    cout << 0 << endl;
  }else if(A==B&&B==C){
    cout << -1 << endl;
  }else{
    cout << min({nib(abs(A-B)),nib(abs(A-C)),nib(abs(C-B))}) << endl;
  }
}

Measured memory_bytes: 256
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let line = read_as_vec::<i64>();
    let (a, v) = (line[0], line[1]);
    let line = read_as_vec::<i64>();
    let (b, w) = (line[0], line[1]);
    let t = read_as_vec::<i64>()[0];
    if v <= w {
        println!("NO");
        return;
    }

    let distance = (a - b).abs();
    let speed = (v - w).abs();

    //if (distance + speed - 1) / speed <= t {
    if distance <= speed * t {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 2164
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		
		double root_N = Math.sqrt((double)N);
		int root_N_kirisute = (int)root_N;
		//a<b
		//int a = 1;
		long b = N;
		for(int i = root_N_kirisute; i>=2; i--){
			if(N%i == 0){
				b = (N/i);
				break;
			}
		}
		int b_keta = (int)Math.log10((double)b) + 1;
		System.out.println(b_keta);
		
	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
    ll N , A , B ;
    cin >> N >> A >> B ;
    if(abs(A - B)%2 == 1){
        cout << "Borys" << endl;
    }else{
        cout << "Alice" << endl;
    }
    return 0 ;
}

 


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

using namespace std;

long long lcm(long long a, long long b) {
  return ((a * b) / __gcd(a, b));
}

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  --a;
  long long first = a / c;
  first += a / d;
  first -= (a / lcm(c, d));
  long long second = b / c;
  second += (b / d);
  second -= (b / lcm(c, d));
  cerr << first << ' ' << second << '\n';
  a++;
  cout << (b - a + 1) - (second - first) << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int sum,a,n,q,b,c;
map<long long int, int> mmp;
int main(){
	scanf("%lld",&n);
	while(n --){
		scanf("%lld",&a);
		sum += a;
		if(!mmp.count(a)) mmp[a] = 1;
		else mmp[a] ++;
	}
	scanf("%lld",&q);
	while(q --){
		scanf("%lld%lld",&b,&c);
		if(mmp.count(b)){
			int tmp = mmp[b];
			sum -= b*tmp;
			sum += c*tmp;
			if(!mmp.count(c)) mmp[c] = 0;
			mmp[c] += tmp;
			mmp[b] = 0;
		}
		printf("%lld\n",sum);
	}
    return 0;
}

Measured memory_bytes: 8844
n,x,y = map(int, input().split())
ans = [0]*n
for i in range(1 , n):
  for j in range(i+1 ,n+1):
    ans[min(abs(j-i),abs(x-i)+abs(y-j)+1)]+=1
    
for i in range(1,n):
  print(ans[i])

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

#define sz(o) ((int)o.size())
#define all(o) o.begin(), o.end()
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define repr(i, a, b) for(int i = (a); i >= (b); i--)
//#define vpal 100

typedef long long int ll;
typedef vector<ll> vll;
typedef vector<int> vi;

void solve(int testcase) {
    int a, b, x;
    cin >> a >> b >> x;
    if(a > x){
        cout << "NO";
        return;
    }
    else if(a == x){
        cout << "YES";
        return;
    }
    b >= x - a ? cout << "YES" : cout << "NO";
}

int main() {
    #ifdef vpal
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << setprecision(10);
    clock_t b = clock();
    int t = 1;
    //cin >> t;
    rep(tt, 1, t) solve(tt);
    clock_t e = clock();
    cerr << (double(e - b) / CLOCKS_PER_SEC) << " sec";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+10;
using namespace std;
inline ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
inline ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline void umax(ll &p,ll q){if(p<q)p=q;}
inline void umin(ll &p,ll q){if(p>q)p=q;}
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    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 n,m,k,t,d[maxn];
vi e[maxn];
bool cmp(const int &p,const int &q)
{
    return d[p]>d[q];
}
void dfs(int p)
{
    int cnt=0;
    for(int x:e[p])
    {
        dfs(x);
    }
    sort(e[p].begin(),e[p].end(),cmp);
    for(int x:e[p])
    {
        d[p]=max(d[p],d[x]+(++cnt));
    }
}
int main()
{
    int i,j;
    scanf("%d",&n);
    rep(i,2,n)scanf("%d",&j),e[j].pb(i);
    dfs(1);
    printf("%d\n",d[1]);
    return 0;
}


Measured memory_bytes: 13952
#include <stdio.h>
int main(void){
    int n ;
    scanf("%d" , &n) ;
    int str[n] ;
    int i , j , k , v ;
    
    for(i = 0 ; i < n ; i++){
        scanf("%d" , &str[i]) ;
    }
    
    for(i = 0 ; i < n ; i++){
        v = str[i] ;
        j = i - 1 ;
        while(j >= 0  &&  str[j] > v){
            str[j + 1] = str[j] ;
            j-- ;
        }
        str[j + 1] = v ;
        for(k = 0 ; k < n ; k++){
            printf("%d" , str[k]) ;
            if(k < n - 1){
                printf(" ") ;
            }
        }
        printf("\n") ;
    }
    return 0 ;
}


Measured memory_bytes: 1992
N = input()
act = []
new = []

for i in range(0,N):
	act.append(raw_input().split(' '))

for i in act:
	tli = []
	for j in i:
		tli.append(int(j))
	new.append(tli)

ans = []

for i in range(0,N):
	emp = [0]*3
	ans.append(emp)


for i in range(0,N):
	for j in range(0,3):
		if(i == 0):
			ans[i][j] = new[i][j]

		else:
			m = -99999	
			for x in range(0,3):
				if(x != j):
					if(m < ans[i-1][x]):
						m = ans[i-1][x]

			ans[i][j] = new[i][j] + m

print(max(ans[N-1]))


Measured memory_bytes: 76988
#include <set>
#include <map>
#include <unordered_map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <tuple>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const ll INF = 2147483647;
#define rep(i, n) rep3(i, 0, n)
#define rep2(i, n) rep3(i, 1, n+1)
#define rep3(i, x, n) for(ll i = x; i < (ll)(n); i++)

template<class T>
void printv(vector<T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << *it << ",";
    }
    cout << endl;
}
template<class T>
void printp(vector<pair<T,T>> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}
template<class T>
void printp(map<T,T> v) {
    for(auto it = v.begin(); it != v.end(); it++){
        cout << (*it).first << "," << (*it).second << endl;
    }
    cout << endl;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

// nPnの順列に対して処理を実行する
void foreach_permutation(int n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int main() {
    ll N;
    vector<ll> l(2001);
    cin>>N;
    rep(i,N) cin>>l[i];
    sort(l.begin(), l.begin()+N);
    
    ll res = 0;
    
    //printv(l);
    
    rep(i,N){
        rep3(j,i+1,N){
            ll k = distance(
                l.begin(),
                lower_bound(l.begin(), l.begin()+N, l[i]+l[j])
            );
            //cout << i<< ","<<j<<","; cout<<k<<endl;
            res += (k - (j+1) >= 0) ? k - (j+1) : 0;
        }
    }
    
    cout << res;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a<=0&&b>=0) {
			System.out.println("Zero");
		}
		else if(a>0&&b>0) {
			System.out.println("Positive");
		}
		else{
			if((b-a+1)%2==0) {
				System.out.println("Positive");
			}
			else {
				System.out.println("Negative");
			}
		}
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>

static const std::string MISS_STR = "Hoshino";
static const std::string CORRECT_STR = "Hoshina";

int main(void) {
    int n;
    std::cin >> n;

    std::string dummy;
    std::cin.get();

    for (int i = 0; i < n; i++) {
        std::string str;
        std::getline(std::cin, str);

        std::string::size_type pos;
        while (pos = str.find(MISS_STR), pos != std::string::npos) {
            str.replace(pos, CORRECT_STR.size(), CORRECT_STR);
        }

        std::cout << str << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  string ans = "AAA";
  ans.at(0) = A.at(0) - 32;
  ans.at(1) = B.at(0) - 32;
  ans.at(2) = C.at(0) - 32;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    long long n;
    std::cin >> n;
    if(n % 2){
        std::cout << 0;
        return 0;
    }
    n /= 2;
    long long c = 0;
    for (long long i = 5; n / i >= 1; i*=5) {
        c += n/i;
    }
    std::cout << c;
}

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

int n,x,y,z,mx,ji;
const long long mod=1e9+7;
long long ans,dp[45][1000010];
int main()
{
	scanf("%d%d%d%d",&n,&x,&y,&z);
	ans=1;
	for(int i=1;i<=n;++i)
	ans=ans*10%mod;
	mx=(1<<(x+y+z))-1;
	ji=(1<<(x+y+z-1));
	ji|=(1<<(y+z-1));
	ji|=(1<<(z-1));
	dp[0][0]=1;
	for(int i=1;i<=n;++i)
	{
		for(int j=0;j<=mx;++j)
		{
			if(dp[i-1][j]==0)
			continue;
			for(int k=1;k<=10;++k)
			{
				int cur=(j<<k)|(1<<(k-1));
				cur&=mx;//只取后(x+y+z)位
				if((cur&ji)==ji)
				continue;
				dp[i][cur]=(dp[i][cur]+dp[i-1][j])%mod; 
			}
		}
	}
	for(int i=0;i<=mx;++i)
	ans=(ans-dp[n][i]+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 121088
#include <iostream>
int main() {
    int m[7][7] = {
        { 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 3, 5, 2, 4, 0 },
        { 0, 4, 0, 1, 6, 0, 3 },
        { 0, 2, 6, 0, 0, 1, 5 },
        { 0, 5, 1, 0, 0, 6, 2 },
        { 0, 3, 0, 6, 1, 0, 4 },
        { 0, 0, 4, 2, 5, 3, 0 }
    }, a[101], b[7], n, t, f;
    for (int i = 1; i <= 6; ++i) {
        std::cin >> n;
        a[n] = i;
        b[i] = n;
    }
    std::cin >> n; // skip
    while (std::cin >> t >> f) {
        std::cout << b[m[a[t]][a[f]]] << std::endl;
    }
}



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

int main() {
	int h, w;
	cin >> h >> w;
	int m = 0;
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < w; j++) {
			m += s[j] == '#';
		}
	}
	cout << (m == h + w - 1 ? "Possible" : "Impossible") << endl;
	return 0;
}


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

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}

bool have[105];
int n,k,d,a,ans;

int main(){
	memset(have,false,sizeof(have));
	cin>>n>>k;
	for(int i=1;i<=k;++i){
		cin>>d;
		for(int j=1;j<=d;++j){
			cin>>a;
			have[a]=true;
		}
	}
	for(int i=1;i<=n;++i){
		if(!(have[i]))ans++; 
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  vector<int>dig(n,0);
  
  for(int i=0;i<n;i++){
    cin >> dig[i];
  }
  
  int max = 0;
  int min = 9999999999;
  
  for(int i=0;i<n;i++){
    if(max < dig[i])
      max = dig[i];
  }
  
  for(int i=0;i<n;i++){
    if(min > dig[i])
      min = dig[i];
  }
  
  cout << max - min << endl;
  
  return 0;
}

    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  int m[10][1000] = {};
  REP(i, 2) {
    REP(j, n) {
      cin >> m[i][j];
    }
  }
  m[1][0] += m[0][0];
  REP(i, n-1) {
    m[0][i+1] += m[0][i];
    m[1][i+1] += max(m[0][i+1], m[1][i]);
  }
  dump(m[1][n-1]);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main( ) {
    int input_a;
    int input_b;
 
    while(1) {
        scanf("%d %d",& input_a ,& input_b);
 
        if( input_a == 0 && input_b == 0 ) {
            break;
        }
 
        if( input_a < input_b ) {
            printf("%d %d\n",input_a ,input_b);
        } else {
            printf("%d %d\n",input_b ,input_a);
        }
    }
 
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
// lower_boundは二分探索
struct edge { int to, cost; };
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

llint binary_search(vector<int>&s,llint a) {
	llint l = -1;
	llint r = (int)s.size();
	while (r - l > 1) {
		llint mid = l + (r - l) / 2;

		if (s[mid]>=a) r = mid;
		else l = mid;
	}
	return r;
}
int k(ll n) {
	int x=0;
	while (n) {
		x+=n % 10;
		n /= 10;
	}
	return x;
}
ll max(ll x, ll y) {
	if (x < y)return y;
	return x;
}

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

	string ans = "";
	rep(i, 0, s.size()) {
		if (s[i] == '0')ans.push_back('0');
		if (s[i] == '1')ans.push_back('1');
		if (s[i] == 'B' && !ans.empty())ans.erase(ans.size() - 1);
	}
	cout << ans << endl;
	return 0;
}


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

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    if(s[0] == s[1] | s[1] == s[2] | s[2] == s[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }
    return 0;
}


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

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

  string res = "NG";

  for(int i=A; i<=B; i++){
    if(i%K==0){
      res = "OK";
      break;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#define sp system("pause");
using namespace std;
int n;
vector<int> p;
map<int,int> mp;
bool prime(int x)
{
	if(x==2||x==3)
		return x;
	for(int i=2;i*i<x;i++)
		if(!x%i)
			return false;
	return true;
}
void getprime(void)
{
	for(int i=2;i<=997;i++)
		if(prime(i))
		{
			p.push_back(i); 
			mp[i]=1;
		}
}
void fac(int x)
{
	int i=0;
	while(p[i]<=x)
	{
		if(x%p[i])
		{
			i++;
			continue;
		}
		mp[p[i]]++;
		x/=p[i];	
	}
}
long long ans=1;
int main(){
	cin>>n;
	getprime();
	for(int i=1;i<=n;i++)
		fac(i);
	for(int i=0;i<p.size();i++)
		ans=(ans*mp[p[i]])%1000000007;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

long int LCM(long int, long int);
void swap(long int*, long int*);

int main(){
  long int a,b;
  long int lcm,gcd;

  while(scanf("%ld %ld",&a,&b) != EOF){
    swap(&a,&b);
    lcm = LCM(a,b);
    gcd = a/lcm*b;
    printf("%ld %ld\n",lcm,gcd);
  }
  return 0;
}

long int LCM(long int a, long int b){
  int r;
  if (b==0){
    return a;
  }
  else {
    r = a % b;
    return LCM(b,r);
  }
}

void swap(long int *x, long int *y){
  long int temp;
  if(*x<*y){
    temp = *x;
    *x = *y;
    *y = temp;
  }
}


Measured memory_bytes: 2032
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int m[] = new int[5];
		int minP = 2001,minJ = 2001;
		
		for(int i=0; i<5; i++){
			m[i] =s.nextInt(); 	
		}
		
		for(int i=0; i<5; i++){
			if(i < 3){
				if(m[i] < minP)	minP = m[i];
			}
			else{
				if(m[i] < minJ)	minJ = m[i];
			}
		}
		
		System.out.println(minP + minJ -50);

	}

}

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

int main() {
  
  string S, T;
  cin >> S >> T;
  int N, M;
  N = S.size();
  M = T.size();
  vector<int> vec(N);
  
 for (int i=0; i < N-M+1; i++){
   for (int j=0; j < M; j++){
     if (T.at(j) == S.at(j+i))
       vec.at(i)++;
   }
 }
 
  sort(vec.begin(), vec.end());
  
  cout << M - vec.at(N-1) << endl;
  
}


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

using namespace std;

int main(){
    long int N;
    cin >> N;
    long int i,M,k;
    for(i=1;i<=N;i++){
        if(N % i == 0) M = N/i;
        if(i*i > N) break;
            }
    k = 0;
    while(M>0){
        k++;
        M = M / 10;
    }
    
    cout << k << endl;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> cnt(1e5+1, 0);
  REP(i, N){
    cin >> A[i];
    cnt[A[i]]++;
  }
  int mult = 0;
  REP(i, 1e5+1){
    if(cnt[i] >= 2){
      mult += cnt[i]-1;
    }
  }
  int ans = N - mult;
  if(mult % 2){
    ans--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int a,b;
    R(a,b);
    if(a>b)swap(a,b);
    REP(i,b)printf("%d",a);
    puts("");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)
using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;

char str[308];
int n,K,Ans;
int f[305][305][305];

int main(){
	scanf("%s%d",str+1,&K); n=strlen(str+1);
	memset(f,0x80,sizeof(f));
	F(i,1,n) F(k,0,K) f[i][i][k]=1;
	F(i,2,n){
		if(str[i]==str[i-1]){
			F(k,0,K) f[i-1][i][k]=2;
		}
		else{
			f[i-1][i][0]=1;
			F(k,1,K) f[i-1][i][k]=2;
		}
	}
	F(Q,3,n){
		F(i,1,n-Q+1){
			int j=i+Q-1;
			f[i][j][0]=max(f[i+1][j][0],max(f[i][j-1][0],f[i+1][j-1][0]+2*(str[i]==str[j])));
			F(k,1,min(K,Q)){
				f[i][j][k]=max(f[i+1][j][k],max(f[i][j-1][k],f[i+1][j-1][k-(str[i]!=str[j])]+2)); 
			}
			F(k,min(K,Q)+1,K) f[i][j][k]=f[i][j][k-1];
		}
	}
	F(k,0,K) Ans=max(Ans,f[1][n][k]);
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 111104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    int n,m,i,j,x,y;
    int a[7]= {1,3,5,7,8,10,12};
    int b[4]= {4,6,9,11};
    while(~scanf("%d %d",&x,&y))
    {
        if(x==2&&y==2)
        {
            printf("Yes\n");
        }
        else
        {
            j=0;
            for(i=0; i<7; i++)
            {
                if(a[i]==x)
                {
                    j++;
                }
                if(a[i]==y)
                {
                    j++;
                }
            }
            m=0;
            for(n=0; n<4; n++)
            {
                if(b[n]==x)
                {
                    m++;
                }
                if(b[n]==y)
                {
                    m++;
                }
            }

            if(m==2||j==2)
            {
                printf("Yes\n");
            }
            else
                printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<ll,ll>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define f(i,x,z) for(int i=x;i<z;i++)
#define debug(x) cout<<"DEBUG------> "<<x<<endl
#define endl "\n"
#define srt(v) sort(v.begin(), v.end())
int main()
{
	int t;
	std::vector<ll> v,v1;
	cin>>t;
	f(i,0,t)
	{
		ll a;
		cin>>a;
		v.pb(a);
		if(i==0)
		{
			v1.pb(a%1000000007);
		}
		else
		{
		    ll te=(v1[i-1]%1000000007)+(a%1000000007)%1000000007;
			v1.pb(te);
		}
	}
	int j=t-1;
	ll  sum=0;
	for(j=t-1;j>=1;j--)
	{
		sum=(sum%1000000007)+(v1[j-1]*v[j])%1000000007;
		sum=sum%1000000007;
	}
	cout<<sum;
   return 0;
}


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

int main(){
    int d, e;
    while(cin >> d >> e, d != 0){
        double mini = 1e9;
        for(int x=0;x<=d;++x){
            int y = d - x;
            mini = min(mini, abs(sqrt(x*x+y*y)-e));
        }
        printf("%.5f\n",mini);
    }

    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  int a,b;
  cin >> a >> b;
  if(a<=b){
    cout << "unsafe";
  }
  else{
    cout << "safe";
  }
}

Measured memory_bytes: 3648
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,A,B,C,D;
struct atom{
	long long L,R;
}x[1000000];
int len;
int in(long long B,long long L,long long R,long long dis){
	if (B>=L&&B<=R) return 1;
	if (B<L){
		B+=(L-B)/dis*dis;
		while (B<L) B+=dis;
		if (B<=R) return 1; else return 0;
	}
	B-=(R-B)/dis*dis;
	while (B>R) B-=dis;
	if (B>=L) return 1; else return 0;
}
int main(){
	cin>>n>>A>>B>>C>>D; long long L=A,R=A,Dis=0;
	if (abs(B-A)>1ll*(n-1)*D){
		cout<<"NO"<<endl; return 0;
	}
	for (int i=1;i<n;i++){
		Dis=C+D; L+=C; R+=D;
	//	cout<<L<<" "<<R<<endl;
	}
//	cout<<L<<" "<<R<<" "<<Dis<<endl;
	if (Dis<=0||in(B,L,R,Dis)) cout<<"YES"<<endl; else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    n,m = (int(x) for x in input().split())
    d = dict()
    pos = True
    for _ in range(m):
        a,b = (int(x) for x in input().split())
        if a in d and d.get(a) != b:
            pos = False
        else:
            d[a] = b
    if d.get(1) == 0 and n != 1:
        pos = False
    ans = []
    for i in range(1,n+1):
        if d.get(i):
            ans.append(d.get(i))
        else:
            ans.append(1 if i == 1 and n!=1 else 0)
    if not pos:
        print(-1)
    else:
        print("".join( map(str,ans) ))
    
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  
#include <numeric>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
using ll = long long;
 
const int precision = 3;
const int modulo =  1000000007; // 10^9 + 7
const ll lmodulo =  1000000007; // 10^9 + 7
 
const double EPS = 1e-9;
const ll inf = 1e18;
 
 void solve() {
 	int n, k; cin >> n >> k;
 	vector<int> h(n);
 	for (auto &it : h) cin >> it;

 	vector<int> dp(n, 1e9 + 100);
 	dp[0] = 0;

 	for (auto i = 0; i < n; ++i) {
 		for (int j = i + 1; j <= i + k and j < n; ++j) {
 			int a = abs(h[i] - h[j]);
 			dp[j] = min(dp[j], a + dp[i]);
 		}
 	}
 	cout << dp[n - 1];
 }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(precision);
  cout.setf(ios_base::fixed);
  solve();
  return 0;
}



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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long
#define endl "\n"
#define inf          INT_MAX
#define zer          INT_MIN
#define nl cout<<'\n' ; 
void speed() { ios_base::sync_with_stdio(false);cin.tie(NULL);}

void solve()
{
	string a , b ; cin>>a>>b ; 
	
	int n = a.length() , m = b.length();
	
	vector<vector<int>> dp(n+1 , vector<int>(m+1 , 0));
	
	for(int i=1 ; i<=n ; i++)
	{
		for(int j = 1 ; j<=m ; j++)
		{
			if(a[i-1]==b[j-1])
			{
				dp[i][j] = dp[i-1][j-1] + 1; 
			}
			else {
				dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
			}
		
		}
	}
	
	//cout<<dp[n][m] ;  
	
	int i= n , j = m ; 
	
	string ans = "" ; 
	
    while(i>0 && j>0)
    {
		if(a[i-1]==b[j-1])
		{
			ans+=a[i-1] ;
			i-- , j-- ; 
		}
		else {
			if(dp[i-1][j]>dp[i][j-1]) i-- ; 
			else j-- ;   
		}
		
	}
	
	reverse(ans.begin() , ans.end());
	
	cout<<ans; 

	
}

int main()
{
	speed(); 
    int T = 1;
   // cin >> T;
    while (T--){
    solve();
}
}


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

int main() {
  int r,c;
  string s;
  cin >> r >>c;

  for (int i=0;i<(c+2);i++){
	cout << "#";
  }
  cout << endl;

  for (int i=0;i<r;i++){
	cout << "#";
    cin >> s;
    cout << s;
    cout << "#" << endl;
  }
  for (int i=0;i<(c+2);i++){
	cout << "#";
  }
  
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_d

#include <iostream>
#include <vector>

using namespace std;

long long dp[110][101000] = {0};

int main(){
    long long N, M;
    cin >> N >> M;
    vector<long long> w(N);
    vector<long long> v(N);

    for(long long i=0; i<N; ++i){
        cin >> w[i];
        cin >> v[i];
    }

    // init
    for(long long i=0; i<=N; ++i) dp[i][0] =0;
    for(long long j=0; j<=M; ++j) dp[0][j] =0;

    for(long long i=1; i<=N; ++i){
        for(long long j=1; j<=M; ++j){
            if(w[i-1]<=j){
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1]);
            }else{
                dp[i][j] = max(dp[i-1][j], dp[i][j]);
            }
        }
    }

    cout << dp[N][M] << endl;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define PI 3.141592653589793238
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in3.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tt, T)
	{
		//cout << "Case #" << tt << ": ";
		int n; cin >> n;
		vector<int> v;
		FOR1(i, n){
			int a; cin >> a;
			v.pb(a);
		}
		sort(all(v), greater<int>());
		int com = v[0];
		for(int i = 2; i < n; i++){
			com += v[i/2];
		}
		cout << com;
		cout << '\n';
	}
	return 0;
}

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

class D
{
	static void Main()
	{
		var k = int.Parse(Console.ReadLine());
		if (k <= 9) { Console.WriteLine(k); return; }

		var t = 9;
		var q = new Queue<string>(Enumerable.Range(1, 9).Select(i => $"{i}"));

		while (q.TryDequeue(out var s))
		{
			for (int i = -1; i <= 1; i++)
			{
				var c = (char)(s[^1] + i);
				if (c < '0' || c > '9') continue;
				q.Enqueue(s + c);
				if (++t == k) { Console.WriteLine(s + c); return; }
			}
		}
	}
}


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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A[i];
    }

    ll Q;
    cin >> Q;

    while(Q--){
        ll b, m, e;
        cin >> b >> m >> e;

        auto it = A.begin();
        rotate(it+b, it+m, it+e);
    }

    FOR(i, 0, N){
        if(i){
            cout << ' ';
        }
        cout << A[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3228
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int c[202020];
LL cnt[202020];
const int mod = 1e9 + 7;
LL dp[202020];
int main(){
    INIT;
    cin >> n;
    dp[0] = 1;
    for(int i = 1;i <= n;i++){
        cin >> c[i];
        if(c[i] == c[i - 1]){
            dp[i] = dp[i - 1];
            continue;
        }
        dp[i] = (dp[i - 1] + cnt[c[i]]) % mod;
        cnt[c[i]] = dp[i] % mod;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>

using namespace std;

int main()
{
    int n, i, a[100000], p, j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    if(n==2)
    {
        i=a[1];
    }
    else
    {
    for(i=a[1];;i--)
    {
        p=1;
        for(j=0;j<n;j++)
        {
            if(a[j]%i!=0)
            {
               p=p+1;
            }
            if(p==3)
            break;
        }
        if(p==1||p==2)
            break;
    }
    }
    printf("%d\n",i);
    return 0;
}

Measured memory_bytes: 640
def main():
    N = int(input())
    p = list(map(float, input().split()))
    a = [[0] * (N + 1) for _ in range(N)]
    a[0][1] = p[0]
    a[0][0] = 1 - p[0]
    for i in range(1, N):
        a[i][0] = a[i - 1][0] * (1 - p[i])
        for j in range(1, i + 2):
            a[i][j] = a[i - 1][j - 1] * p[i] + a[i - 1][j]* (1 - p[i])
    print(sum(a[-1][(N+1)//2:]))
main()


Measured memory_bytes: 180984
#include<cstdio>
#include<algorithm>
#include<cmath>
typedef long long ll;
using namespace std;

int main()
{
	ll n;
	scanf("%lld",&n);
	ll ans=0;
	ll ans1=0;
	for(ll i=sqrt(n)+1;i>=1;i--)
	{
		if(n%i==0)
		{
			ans=i;
			ans1=n/i;
			break;
		}
	}
	if(ans==1)
	printf("%lld\n",n-1);
	else
	printf("%lld\n",ans+ans1-2);
	return 0;
}

Measured memory_bytes: 128
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_080_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 N       PIC 9(9).
    01 D       PIC 9(9).
    01 R       PIC 9(1).
    01 harshad PIC 9(2).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT N.

    MOVE N TO D.

    MOVE 0 TO harshad

    PERFORM UNTIL D = 0
        DIVIDE 10 INTO D GIVING D REMAINDER R
        ADD R TO harshad
    END-PERFORM.

    DIVIDE harshad INTO N GIVING D REMAINDER R.

    IF R = 0 THEN
        DISPLAY "Yes"
    ELSE
        DISPLAY "No"
    END-IF.

    STOP RUN.


Measured memory_bytes: 384
import sys
import math 
a,b,h,m=map(int,input().split())
x=(6*m)
y=(30*h) 
y+=(m/60)*30
z=min(360-abs(x-y),abs(x-y))*(math.pi/180)
c=math.sqrt(b*b+a*a-2*a*b*math.cos(z))
print(c)

Measured memory_bytes: 9440
from collections import deque


h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
dist=[[0 for i in range(w)] for j in range(h)]
que=deque([])
que.append([0,0])
dyx=[[1,0],[0,-1],[-1,0],[0,1]]
ndot=0
for i in range(h):
  for j in range(w):
    if s[i][j]==".":
      ndot+=1
s[0][0]="#"

while que:
  y,x=que.popleft()
  for dy,dx in dyx:
    nx=x+dx
    ny=y+dy
    if (nx<0 or nx>w-1 or ny<0 or ny>h-1):
      continue
    if s[ny][nx]==".":
      dist[ny][nx]=dist[y][x]+1
      que.append([ny,nx])
      s[ny][nx]="#"

ans=ndot-dist[h-1][w-1]-1
if dist[h-1][w-1]==0:
  ans=-1
print(ans)

Measured memory_bytes: 3316
from sys import stdin


def insertion_sort(A, N):
    for i in range(1,N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        
        for j in range(N-1):
            print(A[j], end=" ", sep=" ")
        print(A[N-1])
            

def main():
    read = stdin.readline
    N = int(read())
    data = list(map(int, read().split(" ")))
    for j in range(N-1):
        print(data[j], end=" ", sep=" ")
    print(data[N-1])
    insertion_sort(data, N)
    
if __name__ == "__main__":
    main()
    


Measured memory_bytes: 5984
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int a[3600*24];
int main(void)
{
	int i,n,mx,x,h,m,s,t1,t2;
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
//		printf("%d\n",n);
		for(i=0;i<3600*24;i++)	a[i]=0;
		for(i=0;i<n;i++)	{
			scanf("%d:%d:%d",&h,&m,&s);
			t1=h*3600+m*60+s;
			scanf("%d:%d:%d",&h,&m,&s);
			t2=h*3600+m*60+s;	
			a[t1]++;	a[t2]--;	
		}

		x=0;	mx=0;
		for(i=0;i<3600*24;i++)	{
			x+=a[i];	
			mx=max(mx,x);
		}
		printf("%d\n",mx);
	}
	return 0;
}


Measured memory_bytes: 3020