akhauriyash/Code-Regression huggingface dataset:
x = int(input())

if 400 <= x and x <= 599:
    print(8)
if 600 <= x and x <= 799:
    print(7)
if 800 <= x and x <= 999:
    print(6)
if 1000 <= x and x <= 1199:
    print(5)
if 1200 <= x and x <= 1399:
    print(4)
if 1400 <= x and x <= 1599:
    print(3)
if 1600 <= x and x <= 1799:
    print(2)
if 1800 <= x and x <= 1999:
    print(1)

Measured memory_bytes: 9140
#include <iostream>
#include <map>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define INF 1100000000
#define LLINF 1100000000000000000
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair

using namespace std;
typedef long long ll;

int main()
{
  string pat[4] = {"maerd", "remaerd", "esare", "resare"};
  string S; cin >> S;
  reverse(ALL(S));
  REP(i, S.size()) {
    bool flag = true;
    REP(j, 4) {
      if (S.substr(i, pat[j].size()) == pat[j]) {
        flag = false;
        i += pat[j].size() - 1;
      }
    }
    if (flag) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 512
#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 pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

ll x[100001];
int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    rep(i,n) cin>>x[i];
    ll ans=0;
    rep(i,n-1){
        ans+=min(b,(ll)(x[i+1]-x[i])*a);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
h,w=iim()
p = []
for i in range(h):
    p.append(input())

print('#'*(w+2))
for i in p:
    print('#'+i+'#')
print('#'*(w+2))

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

int main() {
  int N, M;
  cin >> N >> M;
  vector <int>A(M);
  int SUM;
  for(int i = 0; i < M ; i++){
    cin >> A.at(i);
    N-=A.at(i);
    //cout << A.at(i) << endl;
  }
  //cout << SUM << endl;
  //int C=N-(SUM);
  //cout << C << endl;  
  if (N >= 0){
  cout << N << endl;
  }
  else{
    cout << -1 << endl;
  }
}


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

int main(){

    int p,q,r;
    cin >> p >> q >> r;

    int ans=p+q+r;
    ans-=max({p,q,r});
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    double a,b,x; cin>>a>>b>>x;
    double maxyouryo = a*a*b;
    double hanbunyouryo = maxyouryo/2;
    double theta = 0.0;
    double i;
    if(x<=hanbunyouryo){ // 半分より少ないとき、
        i = x * 2.0 / (a*b);
        theta = atan(b/i);
    }else{
        i = (maxyouryo - x)/(a*a/2.0);
        theta = atan(i/a);
    }
    double ans = theta * 180.0 / M_PI;
    printf("%.7lf",ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;


const int mod=1000000007;
//const int mod=998244353;





int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,d;
    cin>> n >>m;
    vi v(n);
    for (int i=0; i<n; i++)
        v[i]=m+i;
//    print(v);
    a=accumulate(all(v),0);
//    cout<<a<<'\n';
    c=10000000;
    for(int i=0; i<n; i++)
    {
        if(abs(v[i])<c){
            c=abs(v[i]);
            b=v[i];
        }
    }
    cout<<a-b<<'\n';
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int d[26];

int32_t main()
{
  string s; cin >> s;
  for (int i=0; i<s.size(); i++)
  {
    d[s[i] - 'a']++;
  }
  for (int i=0; i<26; i++) if (d[i]==0) return cout << (char) (i + 'a'), 0;
  cout << "None";
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    string s;
    cin >> s;
    ll n=s.size();
    //cout << n << "\n";
    ll point1;
    ll point2;
    ll flag=0;
    if(n==2)
    {
        if(s[0]==s[1])
        {
            flag=1;
            point1=0;
            point2=1;
        }
    }
    for(ll i=0;i<=n-2;i++)
    {
        //cout << s[i] <<"\n";
        if(i!=n-2)
        {

            if(s[i+1]==s[i] || s[i+2]==s[i] && flag==0)
            {
                flag=1;
                point1=i;
                point2=i+2;
            }
        }
        if(i==n-2)
        {
            if(s[i]==s[i+1] && flag==0)
            {
                point2=i+1;
                point1=i-1;
                flag=1;
            }
        }
    }
    //cout << flag<<"\n";
    if(flag==1)
    {

        cout << point1+1 <<" "<< point2+1;
    }
    else
    {
        cout <<"-1 -1";
    }
    /*for(ll j=point1;j<=point2;j++)
    {
        cout << s[j];
    }*/
}


Measured memory_bytes: 512
fun main() {
    val n = readLine()!!.trim().toInt()
    val bars = readLine()!!.trim().split(' ').map(String::toInt).sorted()
    var sum = 0
    for (i in bars.indices) {
        for (j in 0 until i) {
            if (bars[i] == bars[j]) break
            if (bars[i] >= bars[j] shl 1) continue
            for (k in 0 until j) {
                if (bars[j] == bars[k]) break
                if (bars[i] >= bars[j] + bars[k]) continue
                ++sum
            }
        }
    }
    println(sum)
}

Measured memory_bytes: 40732
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <vector>
using namespace std;
int main(){
    int n,c=0,p[100000];
    cin>>n;
    for(int i=0;i<n;i++)cin>>p[i];
    for(int i=0;i<n;i++){
        if(p[i]==i+1){
            swap(p[i],p[i+1]);
            c++;
        }
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 640
/*----- || Hare Krishna || -----*/

/*  "WHY DO WE FALL, BRUCE?"  */

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define elif else if
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384
#define MOD 1000000007
using namespace std;

char alpha[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

string s;
int t;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> s;
    int n = s.size();
    if(s[n-1]=='s'){
    	s+="es";
	}
	else{
		s+='s';
	}
	cout << s << endl;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 string a,b;
  int ans=0;
  getline(cin,a);
  getline(cin,b);
  for(int i=0;i<a.size();i++){
    if(a[i]==b[i])ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int N=400,M=1010;
const int NN=400,MM=2010;
const int INF=2139062143;
int n,m,k,s,t;
inline int read(){
	int x=0,f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return x*f;
}
int last[NN],le;
void cl()
{
	memset(last,0,sizeof(last));
	le=1;
}
struct node{
	int u,v,cap,flow,cost,next;
}edge[MM<<1];
void add(int u,int v,int cap,int cost)
{
	edge[++le].u=u,edge[le].v=v,edge[le].cap=cap,edge[le].cost=cost,edge[le].flow=0,edge[le].next=last[u],last[u]=le;
	edge[++le].u=v,edge[le].v=u,edge[le].cap=0,edge[le].cost=-cost,edge[le].flow=0,edge[le].next=last[v],last[v]=le;
}
bool vis[NN];
int d[NN];
int p[NN];
queue<int> q;
bool spfa()
{
	memset(d,127,sizeof(d));
	q.push(s);
	vis[s]=1,d[s]=0,p[s]=0;
	while (!q.empty())
	{
		int u=q.front();
		q.pop();
		vis[u]=0;
		for (register int i=last[u];i;i=edge[i].next)
		{
			int v=edge[i].v;
			if (edge[i].cap>edge[i].flow&&d[v]>d[u]+edge[i].cost)
			{
				d[v]=d[u]+edge[i].cost;
				p[v]=i;
				if (!vis[v])
				{
					vis[v]=1;
					q.push(v);
				}
			}
		}
	}
	return d[t]!=INF;
}
int maxflow,mincost;
void MCMF()
{
	maxflow=0,mincost=0;
	while (spfa())
	{
		int f=INF,u=t;
		while (u!=s)
		f=min(f,edge[p[u]].cap-edge[p[u]].flow),u=edge[p[u]].u;
		mincost+=f*d[t];
		maxflow+=f;
		u=t;
		while (u!=s)
		edge[p[u]].flow+=f,edge[p[u]^1].flow-=f,u=edge[p[u]].u;
	}
}
int main()
{
	while (scanf("%d",&n)!=EOF&&n)
	{
		cl();
		int maxday=0;
		s=0;
		add(s,1,2,0);
		for (register int i=1;i<=n;++i)
		{
			int u=read(),v=read(),cost=read();
			maxday=max(maxday,max(u,v));
			add(u,v+1,1,-cost);
		}
		for (register int i=1;i<=maxday;++i)
		add(i,i+1,2,0);
		t=maxday+1;
		MCMF();
		printf("%d\n",-mincost);
	}
	return 0;
}

Measured memory_bytes: 3356
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  string s;
  cin >> s;
  s.insert(4, " ");
  //vector<ll> a(n);  rep(i, 0, n) cin >> a[i];
  cout << s << "\n";

}

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

int a()
{
    int a, b, c, d, e;
    std::cin >> a >> b >> c >> d >> e;
    
    int ans = 0;
    if(a == 0)
    {
        ans = 1;
    }
    else if(b == 0)
    {
        ans = 2;
    }
    else if(c == 0)
    {
        ans = 3;
    }
    else if(d == 0)
    {
        ans = 4;
    }
    else
    {
        ans = 5;
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}


int main(int argc, const char * argv[])
{
    a();
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int field[12][13],dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
char c;

void sink(int x,int y){
	field[y][x]=0;
	for(int i=0;i<4;i++){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx>=0&&nx<12&&ny>=0&&ny<12&&field[ny][nx]==1)sink(nx,ny);
	}
}

int main(){
	while(cin>>c){
		field[0][0]=c-'0';
		for(int i=0;i<12;i++){
			for(int j=0;j<12;j++){
				if(i+j!=0){cin>>c;field[i][j]=c-'0';}
			}
		}
		int ans=0;
		for(int i=0;i<12;i++){
			for(int j=0;j<12;j++){
				if(field[i][j]==1){ans++;sink(j,i);}
			}
		}
		cout<<ans<<endl;
	}
}

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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define PF push_front
#define PB push_back
#define FST first
#define SEC second
#define sz(obj) ((int)(obj).size())
#define ALL(v) (v).begin(), (v).end()

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int gcd(int a, int b){ int c; while (a != 0){ c = a; a = b % a; b = c; } return b; }

bool F(int a, int b, int c, int d){
  bool f[2] = {false, false};
  if (a != 0 and b != 0) f[0] = true;
  if (a == 0 and b == 0) f[0] = true;
  if (c != 0 and d != 0) f[1] = true;
  if (c == 0 and d == 0) f[1] = true;

  return (f[0] and f[1]);
}
signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s;
  int cnt[4] = {0, 0, 0, 0};

  cin >> s;
  REP(i, sz(s)){
    if (s[i] == 'N') cnt[0]++;
    if (s[i] == 'S') cnt[1]++;
    if (s[i] == 'E') cnt[2]++;
    if (s[i] == 'W') cnt[3]++;
  }

  if (F(cnt[0], cnt[1], cnt[2], cnt[3])) cout << "Yes" << endl;
  else cout << "No" << endl;

  return (0);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <deque>
#include <queue>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

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

    deque<int> d;
    REP(0, n, N) {
        int tmp; cin >> tmp;
        d.push_back(tmp);
    }

    // for(deque<int>::iterator it = d.begin(); it != d.end(); ++it) {
    //     cout << (*it) << endl;
    // }

    vector<int> v;
    for (int A = 0; A <= min(N, K); ++A) {
        for (int B = 0; B <= min(N, K) - A; ++ B) {
            // cout << A << ", " << B << endl;
            priority_queue<int, vector<int>, greater<int> > q;
            for (deque<int>::iterator it = d.begin(); it != d.begin() + A; ++it) {
                q.push(*it);
            }

            for (deque<int>::reverse_iterator it = d.rbegin(); it != d.rbegin() + B; ++it) {
                q.push(*it);
            }

            // while (!q.empty()) {
            //     cout << q.top() << endl;
            //     q.pop();
            // }

            int L = K - (A + B);
            int l = 0;
            // cout << "L: " << L << endl;
            while (!q.empty() && l < L) {
                int t = q.top();
                if (t > 0) {
                    break;
                } else {
                    q.pop();
                }
                l++;
            }

            int cnt = 0;
            while (!q.empty()) {
                cnt += q.top();
                q.pop();
            }

            v.push_back(cnt);
        }
    }

    // for (vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
    //     cout << (*it) << endl;
    // }

    cout << *max_element(v.begin(), v.end()) << endl;

    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer

case class Dice(var d:Array[String]) {
  private val s = Array(4,0,2,3,5,1)
  private val w = Array(2,1,5,0,4,3)
  private val h = Array(0,2,4,1,3,5)
  private val all = Array.ofDim[Array[String]](24)

  def rotateAll() = {
    all(0) = d
    all(1) = s.map(d)
    all(2) = s.map(all(1))
    all(3) = s.map(all(2))
    all(4) = w.map(d)
    all(5) = w.map(w).map(all(4))
    (0 to 17).foreach { s => all(s+6) = h.map(all(s)) }
  }

  def getAll = all

  override def toString() = d(0)
}

object Main extends App {
  val faces = readLine.split(" ")
  val n = readInt
  val dice = Dice(faces)

  dice.rotateAll()
  (0 until n).foreach { s =>
    val l =  readLine.split(" ")
    println(dice.getAll.find(t => t(0) == l(0) && t(1) == l(1)).get(2))
  }
}

Measured memory_bytes: 43672
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    string s;cin >> s;
    int k;cin >> k;
    int cnt=0;
    vec<string> ans; 
    rep(i,s.size())rep2(j,i,min(s.size(),i+k))ans.push_back(s.substr(i,j-i+1));
    sort(all(ans));
    
    rep(i,k){
        if(i!=0&&ans[i]==ans[i-1])k++;
        if(i==k-1)cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4304
N, K = map(int, input().split())
P = dict()
C = dict()

for i, p in enumerate(map(int, input().split())):
    P[i+1] = p
for i, c in enumerate(map(int, input().split())):
    C[i+1] = c

ans = -float("inf")
for pos in range(1, N+1):
    i = pos
    score = 0
    for k in range(1, K+1):
        i = P[i]
        score += C[i]
        ans = max(ans, score)
        if i == pos:
            if score > 0:
                lastAns = score * ((K//k)-1)
                NumberOfCycle = (K%k) + k
                lastScore = lastAns
                j = i
                for _ in range(NumberOfCycle):
                    j = P[j]
                    lastScore += C[j]
                    lastAns = max(lastAns, lastScore)
                ans = max(ans, lastAns)
            break
print(ans)


Measured memory_bytes: 74884
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		for(int c=1;c<4;c++){
			if(A*B*c % 2 !=0){
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}	
}

Measured memory_bytes: 23892
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x

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

    vector<int> v;
    rep(i, n) {
        capi(h);
        v.push_back(h);
    }

    sort(all(v));

    int ans = 0;
    rep(i, n - k) {
        ans += v[i];
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 4892
N = input()

arr = []

for i in xrange(N):
    A,B = raw_input().split()
    B = int(B)
    arr.append([A,B,i+1])


arr.sort(key = lambda x : -x[1])
arr.sort(key = lambda x : x[0])

for i in xrange(N):
    print arr[i][2]

Measured memory_bytes: 2568
#include <stdio.h>
#include <string.h>
int main(void) {
	char in[1025], *p;
	const char *fmt = "%s";
	int length;

	fgets(in, 1024, stdin);
	for (p = strtok(in, " .,"); p != NULL; p = strtok(NULL, " .,")) {
		length = strlen(p);
		if (2 <  length && length < 7) {
			printf(fmt, p);
			fmt = " %s";
		}
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	string s;
	cin >> s;
	int n = s.size();
	ll ans = 0;
	rep(bit, (1 << n - 1)) {
		ll t = (s[0] - '0');
		ll temp = 0;
		rep(i, n - 1) {
			if (bit & (1 << i)) {
				temp += t;
				t = (s[i + 1] - '0');
			} else {
				t = 10 * t + (s[i + 1] - '0');
			}
		}
		temp += t;
		ans += temp;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
const int mod = 1000000007;


int32_t main()
{





   
      int k;
      cin >> k;
      string s;
      cin >> s;


      if(s.length() <= k)
      {
        cout << s;
      }
      else
      {
        cout << s.substr(0,k) + "...";
      }
    



    return 0;
}



Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){

  vector<int> list;
  int n;
  int m;
  int j;
  int num;
  int tmp;
  int c;
  int a=0;
  int k;
  int size;
  /*
  for (int i=0; i<n; i++){
   cin >> num;
   for(j=0; j<i; j++) {
     cin >> tmp;
     x.push_back(tmp);
   }
   list.push_back(x);
  }
  */
  cin >> n;
  cin >> m;
   for (int i=0; i<n; i++){
   cin >> num;
   for(j=0; j<num; j++) {
     cin >> tmp;
     list.push_back(tmp);
   }
  }

  for (k = 1; k <= m; k++){
    c = count(list.begin(), list.end(), k);
    //cout << c << endl;
    if(c==n){a = a + 1;}
    else{;}
  }
  
  cout << a << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
const ll N = 100010;
struct Segment{
	ll cnt, val, lson, rson;//出现次数，值 
}tr[N * 20];
ll rt[N];
struct node{
	ll pre, to, col, val;
}edge[N << 1];
ll head[N], tot;
ll n, q;
ll dis[N], dep[N], fa[N], son[N], sz[N], bl[N];
void dfs1(ll x) {
	sz[x] = 1;
	for (ll i = head[x]; i; i = edge[i].pre) {
		ll y = edge[i].to;
		if (y == fa[x]) continue;
		dep[y] = dep[x] + 1;
		dis[y] = dis[x] + edge[i].val;
		fa[y] = x;
		dfs1(y);
		sz[x] += sz[y];
		if (sz[y] > sz[son[x]]) {
			son[x] = y;
		}
	}
}
void dfs2(ll x, ll chain) {
	bl[x] = chain;
	if (son[x]) dfs2(son[x], chain);
	for (ll i = head[x]; i; i = edge[i].pre) {
		ll y = edge[i].to;
		if (y == fa[x] || y == son[x]) continue;
		dfs2(y, y);
	}
}
ll LCA(ll u, ll v) {
	while (bl[u] != bl[v]) {
		if (dep[bl[u]] < dep[bl[v]]) swap(u, v);
		u = fa[bl[u]];
	}
	return dep[u] < dep[v] ? u : v;
}
void push_up(ll cur) {
	tr[cur].cnt = tr[tr[cur].lson].cnt + tr[tr[cur].rson].cnt;
	tr[cur].val = tr[tr[cur].lson].val + tr[tr[cur].rson].val;
}
void ins(ll &cur, ll pre, ll l, ll r, ll pos, ll v) {
	cur = ++tot;
	tr[cur] = tr[pre];
	if (l == r) {
		tr[cur].cnt++;
		tr[cur].val += v;
		return;
	}
	ll mid = (l + r) >> 1;
	if (pos <= mid) ins(tr[cur].lson, tr[pre].lson, l, mid, pos, v);
	else ins(tr[cur].rson, tr[pre].rson, mid + 1, r, pos, v);
	push_up(cur);
}
ll ask_val(ll cur, ll l, ll r, ll pos) {
	if (l == r) return tr[cur].val;
	ll mid = (l + r) >> 1;
	if (pos <= mid) return ask_val(tr[cur].lson, l, mid, pos);
	else return ask_val(tr[cur].rson, mid + 1, r, pos); 
}
ll ask_cnt(ll cur, ll l, ll r, ll pos) {
	if (l == r) return tr[cur].cnt;
	ll mid = (l + r) >> 1;
	if (pos <= mid) return ask_cnt(tr[cur].lson, l, mid, pos);
	else return ask_cnt(tr[cur].rson, mid + 1, r, pos); 
}
void solve(ll x) {
	for (ll i = head[x]; i; i = edge[i].pre) {
		ll y = edge[i].to;
		if (y == fa[x]) continue;
		ins(rt[y], rt[x], 1, n, edge[i].col, edge[i].val);
		solve(y);
	}
}
void add(ll u, ll v, ll c, ll d) {
	edge[++tot] = node{head[u], v, c, d};
	head[u] = tot;
}
int main() {
	scanf("%lld%lld", &n, &q);
	for (ll i = 1, u, v, c, d; i < n; i++) {
		scanf("%lld%lld%lld%lld", &u, &v, &c, &d);
		add(u, v, c, d);
		add(v, u, c, d);
	}
	dfs1(1);
	dfs2(1, 1);
	solve(1);
	while (q--) {
		ll x, y, u, v;
		scanf("%lld%lld%lld%lld", &x, &y, &u, &v);
		ll lca = LCA(u, v);
//		cout << lca << endl; 
		ll value = ask_val(rt[u], 1, n, x) + ask_val(rt[v], 1, n, x) - 2 * ask_val(rt[lca], 1, n, x);
		ll cnt = ask_cnt(rt[u], 1, n, x) + ask_cnt(rt[v], 1, n, x) - 2 * ask_cnt(rt[lca], 1, n, x);
//		cout << value << endl;
//		cout << cnt << endl;
		printf("%lld\n", dis[u] + dis[v] - 2 * dis[lca] - value + cnt * y);
	}
	return 0;
}

Measured memory_bytes: 73728
#include<iostream>
#include<string>
#include<queue>

using namespace std;

string a,b,c;

void solve(){
    queue<char> aq, bq, cq;
    for(int i=0;i<a.length();i++){
        aq.push(a[i]);
    }
    for(int i=0;i<b.length();i++){
        bq.push(b[i]);
    }
    for(int i=0;i<c.length();i++){
        cq.push(c[i]);
    }
    char cur;
    cur = aq.front();aq.pop();
    while(1){
        if(cur=='a'){
            if(aq.empty()){
                cout << 'A' << endl;
                break;
            }
            cur = aq.front();aq.pop();
        }
        else if(cur=='b'){
            if(bq.empty()){
                cout << 'B' << endl;
                break;
            }
            cur = bq.front();bq.pop();
        }
        else if(cur=='c'){
            if(cq.empty()){
                cout << 'C' << endl;
                break;
            }
            cur = cq.front();cq.pop();
        }
    }
}

int main(){
    cin >> a >> b >> c;
    solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#define MOD 1000000007
using namespace std;

int a,b,c;

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b>>c;
	cout<<((a+b)*c)/2;
		return 0;
}

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

map<char, int> create_map() {
    map<char, int> m;
    m.insert({'I', 1});
    m.insert({'V', 5});
    m.insert({'X', 10});
    m.insert({'L', 50});
    m.insert({'C', 100});
    m.insert({'D', 500});
    m.insert({'M', 1000});
    return m;
}
map<char, int> m = create_map();
string str;
int idx;

int setN(char i, char j, char k) {
    int num = 0;
    if (idx >= 1 && (str[idx] == k || str[idx] == j) && str[idx-1] == i) { num = m[str[idx]] - m[str[idx-1]]; idx-=2; }
    else if (str[idx] == i) {
        for (; ;) {
            if (idx < 0) break;
            if (str[idx] != i) break;
            num+= m[str[idx--]];
        }
    }
    if (idx >= 0 && str[idx] == j) { num += m[str[idx--]]; }
    return num;
}


int main() {
    while(cin>>str) {
        int n = 0;
        idx = int(str.size()-1);
        n = setN('I', 'V', 'X');
        if (idx >= 0) n+= setN('X', 'L', 'C');
        if (idx >= 0) n+= setN('C', 'D', 'M');
        if (idx >= 0) for (; ;) { if (idx < 0) break; n+= m[str[idx--]]; }
        cout << n << endl;
    }
    return 0;
}



Measured memory_bytes: 3140
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
    }
    
    Scanner sc;
    int N;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        N = sc.nextInt();
    }
    
    //解答処理
    String solve() {
        String s = null;
        if (N < 1000){
            s = "ABC";
        } else {
            s = "ABD";
        }
        
        return s;
    }
    
    //出力
    void show(String answer) {
        System.out.println(answer);
    }
}


Measured memory_bytes: 35808
import sys
import numpy as np

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


D = ini()
C = inl()
assert len(C) == 26
S = np.zeros((D, 26), dtype="int32")
for i in range(D):
    S[i, :] = inl()


def calc_score(sol):
    last = -np.ones((26, D + 1))
    score = 0
    for d in range(D):
        ct = sol[d]
        score += S[d, ct]
        for i in range(26):
            last[i, d + 1] = last[i, d]
        last[ct, d + 1] = d
        for i in range(26):
            score -= C[i] * (d - last[i, d + 1])
    return score, last


def main():
    sol = np.random.randint(0, 26, D)
    sol_bak = sol.copy()
    max_score, last = calc_score(sol)
    last_bak = last.copy()

    def update(d, before, after):
        score = max_score
        score -= S[d, before]
        score += S[d, after]
        lb = last[before, d]
        la = last[after, d]
        da = db = 0
        for x in range(d, D):
            if x > d and sol[x] == before:
                break
            last[before, x + 1] = lb
            db += 1
        score -= C[before] * (d - lb) * db
        for x in range(d, D):
            if x > d and sol[x] == after:
                break
            last[after, x + 1] = d
            da += 1
        score += C[after] * (d - la) * da
        sol[d] = after
        return score

    tried = set()
    for i in range(20000):
        new_d = np.random.randint(0, D)
        c_before = sol[new_d]
        c_after = np.random.randint(0, 26)
        if c_before == c_after:
            continue
        candidate = new_d * 26 + c_after
        if candidate in tried:
            continue
        tried.add(candidate)
        new_score = update(new_d, c_before, c_after)
        if max_score < new_score:
            max_score = new_score
            sol_bak = sol.copy()
            last_bak[c_before, :] = last[c_before, :].copy()
            last_bak[c_after, :] = last[c_after, :].copy()
            tried = set()
        else:
            sol = sol_bak.copy()
            last[c_before, :] = last_bak[c_before, :].copy()
            last[c_after, :] = last_bak[c_after, :].copy()

    print(*(sol + 1), sep="\n")


main()


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

using namespace std;

#define PB push_back
#define MP make_pair
#define X first
#define Y second

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for(typeof((c).begin())v=(c).begin();v!=(c).end();++v)

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

clock_t start;
void Time(bool timeIt) {
	if (!timeIt) return;
	clock_t end = clock();
	double elapsed_time = ((db)end - (db)start) / (db)CLOCKS_PER_SEC;
	printf("Time elapsed = %0.4lf\n", elapsed_time); 
}

#define LINF (long long)1e18
#define EPS 1e-9
#define INF 1000000007ll
#define SIZE 100010
#define MAX_A 1000010

int vis[SIZE] = {0}, idx = 0;
vi adj[SIZE];
multiset<ll> mn[SIZE];
ll a[SIZE];

void dfs(int v) {
	vis[v] = 1;
	mn[idx].insert(a[v]);
	for (auto t: adj[v]) {
		if (!vis[t]) dfs(t);
	}
}

int main() {
	start = clock();

	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0 ; i < n ; ++i) scanf("%lld", &a[i]);
	for (int i = 0 ; i < m ; ++i) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].PB(v);
		adj[v].PB(u);
	}

	for (int i = 0 ; i < n ; ++i) {
		if (!vis[i]) {
			++idx;
			dfs(i);
		}
	}
	if (idx == 1) {
		printf("0\n");
		return 0;
	}

	int ones = 0, mult = 0;
	ll ans = 0;

	for (int i = 1 ; i <= idx ; ++i) {
		if (mn[i].size() == 1) ++ones;
		else mult += mn[i].size() - 2;
	}
	if (ones > mult + 2) {
		printf("Impossible\n");
		return 0;
	}

	multiset<ll> inside;
	for (int i = 1 ; i <= idx ; ++i) {
		ans += *mn[i].begin();
		mn[i].erase(mn[i].begin());
		inside.insert(mn[i].begin(), mn[i].end());
	}

	multiset<ll>::iterator it = inside.begin();
	idx -= 2;
	while (idx--) {
		ans += 1ll * (*it);
		++it;
	}

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

	Time(false);
	return 0;
}

Measured memory_bytes: 20992
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n , a , b;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    int passed = 0;
    int bcnt = 0;
    for(int i = 0 ; i<s.length() ; i++){
        if(s[i] == 'c'){
            cout<<"No\n";
        }
        else{
            if(s[i] == 'a' && passed<a+b){
                ++passed;
                cout<<"Yes\n";
            }
            else if(s[i] == 'b' && passed<a+b && bcnt<b){
               ++bcnt;
               ++passed;
               cout<<"Yes\n"; 
            }
            else{
                cout<<"No\n";
            }
        }
    }
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
int a[100010],num[100010];
int main(){
	ll sum=0;
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		num[a[i]]++;
		sum+=a[i];
	}
	int m;
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		int b,c;
		scanf("%d%d",&b,&c);
		sum+=(c-b)*num[b];
		num[c]+=num[b];
		num[b]=0;
		printf("%lld\n",sum);
	}
}	
/*
4
1 2 3 4
3
1 2
3 4
2 4
*/

Measured memory_bytes: 4584
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    import os, zlib, base64
    open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode("c${rg!EVAZ482$CKlrlIjDT8clO_cF5yqiy(l%O1AWaJU`#Gf0Fz}`6d(ZZ>lg8*h)W5dVYI!J4DJ7Rsi~T_x3kOrGmZwSMMN(AtvbRj=8{cwUccq~y6v{RfdTuM{zm{od)1+p+0jX8H{m3zj9k3DfdD|kt#ttwqO+tPa(y7PDsK@%)R%HZ~ZiQT>31Hl)ib4$=$OC-pgyc|+A|Dl!quY#3uxOB3!~5q7D#Od4iSgBHc!MH`IcgTD38dlH83py|YtVv0$ynxH2zoJdzBd`%2v~1GMV8oB>|nlub7aT=3wVWvh;|3P+lTT`h7W@OqYL<gJnGf^!oFeLYcchT2J54RE58K4bPC7mh*RR-I0{3WoP_P}Of}kIRiVbWlPR(a>%lb^G?XCErAHDuw%2|W<Q}2n5yC6AtMNf*vlq#})r?+NI1s!>e{dwybJ_D?(FKbGl7FDa&m8")))
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 13044
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A, B;
i64 X[101010], Y[101010];
vector<pair<i64, i64> > vx, vy;
set<pair<i64, i64> > sx, sy;
map<pair<i64, i64>, int> trans;

bool vis[101010];

i64 iabs(i64 a)
{
	return a > 0 ? a : -a;
}

i64 dist(int a, int b)
{
	return max(iabs(X[a] - X[b]), iabs(Y[a] - Y[b]));
}

queue<int> Q;

void visit(i64 x, i64 y)
{
	sx.erase({ x, y });
	sy.erase({ y, x });
	int idx = trans[{x, y}];
	vis[idx] = true;
	Q.push(idx);
}

int hoge(vector<pair<i64, i64> > &X, i64 a, i64 bl, i64 br)
{
	return upper_bound(X.begin(), X.end(), make_pair(a, br)) - lower_bound(X.begin(), X.end(), make_pair(a, bl));
}

set<pair<i64, i64> >::iterator upp(set<pair<i64, i64> > &S, pair<i64, i64> P)
{
	auto p = S.lower_bound(P);
	if (p == S.end()) return p;
	if (*p < P) ++p;
	return p;

}

int main()
{
	scanf("%d%d%d", &N, &A, &B); --A; --B;
	for (int i = 0; i < N; ++i) {
		i64 p, q;
		scanf("%lld%lld", &p, &q);
		X[i] = p + q;
		Y[i] = p - q;

		vx.push_back({ X[i], Y[i] });
		vy.push_back({ Y[i], X[i] });
		trans.insert({ {X[i], Y[i]}, i });
	}
	sort(vx.begin(), vx.end());
	sort(vy.begin(), vy.end());

	for (int i = 0; i < N; ++i) vis[i] = false;
	Q.push(A); vis[A] = true;
	i64 d = dist(A, B);

	for (int i = 0; i < N; ++i) if (i != A) {
		sx.insert({ X[i], Y[i] });
		sy.insert({ Y[i], X[i] });
	}

	while (!Q.empty()) {
		int p = Q.front(); Q.pop();
		vis[p] = true;
		{
			auto pt = upp(sx, make_pair(X[p] - d, Y[p] - d));
			while (pt != sx.end() && pt->first == X[p] - d && pt->second <= Y[p] + d) {
				auto p2 = pt;
				++p2;
				i64 x = pt->first, y = pt->second;
				visit(x, y);
				pt = p2;
			}
		}
		{
			auto pt = upp(sx, make_pair(X[p] + d, Y[p] - d));
			while (pt != sx.end() && pt->first == X[p] + d && pt->second <= Y[p] + d) {
				auto p2 = pt;
				++p2;
				i64 x = pt->first, y = pt->second;
				visit(x, y);
				pt = p2;
			}
		}
		{
			auto pt = upp(sy, make_pair(Y[p] - d, X[p] - d));
			while (pt != sy.end() && pt->first == Y[p] - d && pt->second <= X[p] + d) {
				auto p2 = pt;
				++p2;
				i64 y = pt->first, x = pt->second;
				visit(x, y);
				pt = p2;
			}
		}
		{
			auto pt = upp(sy, make_pair(Y[p] + d, X[p] - d));
			while (pt != sy.end() && pt->first == Y[p] + d && pt->second <= X[p] + d) {
				auto p2 = pt;
				++p2;
				i64 y = pt->first, x = pt->second;
				visit(x, y);
				pt = p2;
			}
		}
	}
	i64 ans = 0;
	for (int i = 0; i < N; ++i) if (vis[i]) {
		ans += hoge(vx, X[i] - d, Y[i] - d, Y[i] + d);
		ans += hoge(vx, X[i] + d, Y[i] - d, Y[i] + d);
		ans += hoge(vy, Y[i] - d, X[i] - d + 1, X[i] + d - 1);
		ans += hoge(vy, Y[i] + d, X[i] - d + 1, X[i] + d - 1);
	}

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


Measured memory_bytes: 23776
import sys
read = sys.stdin.read
def main():
    n, *x = map(int, read().split())
    r = float('inf')
    for i1 in range(1, 101):
        rt = 0
        for xe in x:
            rt += (xe - i1)**2
        r = min(r, rt)
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N,P;
  string S;
  cin >> N >> P >> S;
  
  vi a(N+1);
  int ten=1;
  ll ans=0;
  if(P!=2&&P!=5) {
    vl count(P);
    count[0]++;
    rep(i,N) {
      a[i+1]=(a[i]+(S[N-i-1]-'0')*ten)%P;
      count[a[i+1]]++;
      (ten*=10)%=P;
    }
  
    rep(i,P) ans+=count[i]*(count[i]-1)/2;
  }
  else {
    rep(i,N) {
      if(!((S[i]-'0')%P)) ans+=i+1;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4448
import fractions

A, B, C, D = map(int, input().split())
E = (C * D) // fractions.gcd(C, D)
num_c = B // C - A // C + (1 if A % C == 0 else 0)
num_d = B // D - A // D + (1 if A % D == 0 else 0)
num_e = B // E - A // E + (1 if A % E == 0 else 0)
num = B - A + 1 - (num_c + num_d - num_e)
print(num)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = 998244353;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll h, w, ans = 0;
    string s[1005];
    bool visited[1005][1005]{};
    cin >> h >> w;
    REP(i,h){
        cin >> s[i];
    }
    queue<P3> que;
    REP(i,h)REP(j,w){
        if(s[i][j] == '#'){
            que.push({{i,j},0});
            visited[i][j] = true;
        }
    }
    while(!que.empty()){
        P3 p = que.front();
        que.pop();
        int pi = p.first.first, pj = p.first.second;
        ans = max(ans, p.second);
        REP(k,4){
            int ni = pi + di[k], nj = pj + dj[k];
            if(ni < 0 || ni >= h) continue;
            if(nj < 0 || nj >= w) continue;
            if(visited[ni][nj]) continue;
            que.push({{ni,nj},p.second+1});
            visited[ni][nj] = true;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 26420
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define L long
#define W V<L>
L E=70;W S(V<W>p){if(!E){return{1,0};}V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1){T[(x[1]+1)&1].push_back({x[0]/2,(x[1]+1)/2});}}L i=2;while(i--){L c=0;for(W x:T[!i]){L Q=(2*x[0]+x[1])%3;c^=Q+1;}if(!c){E--;W A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p){v[0]++;}W A=S(p);A[0]--;return A;}int main(){L M=2e17,n,a,b;cin>>n;V<W>p(n);while(n--){cin>>a>>b;p[n]={a+M,b+M};}W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

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

int main(){

    int x, a, b; cin >> x >> a >> b;
    cin >> x >> a >> b;
    if(a - b >= 0) cout << "delicious" << endl;
    else if(-a + b <= x) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;

}

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

int main(int argc, char const *argv[])
{
	ll n, k; cin >> n >> k;
	ll t = n / k;
	cout << min(abs(n - t * k), abs(n - (t + 1) * k)) << endl;
	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int k, x;
  cin >> k >> x;
  int min_x = x - k + 1;
  int max_x = x + k - 1;
  rep(i, min_x, max_x + 1) {
      if(i == max_x) {
          cout << i << endl;
          return 0;
      }
      cout << i << " " ;
  }
}


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

int main(){
    int N;cin>>N;
    set<ll> st;
    bool flg = 0;
    rep(i,N){
        ll a;cin>>a;
        auto it = st.find(a);
        if(i==0){
            st.insert(a);
        }else if(it != st.end()){
            flg = 1;
            break;
        }else{
            st.insert(a);
        }
    }
    if(flg == 1){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }
    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
const int N(1111111);
int go[N];
int main() {
	int n;
	cin >> n;
	for(int i(0); i < n; i++) {
		scanf("%d", &go[i]);
	}
	int ans(0);
	for(int i(0); i < n; i++) {
		if(i == go[go[i] - 1] - 1) {
			ans++;
		}
	}
	cout << ans / 2 << endl;
}


Measured memory_bytes: 640
import java.util.*;

public class Main{

    final static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        System.out.println(A());
    }

    public static String A() {
        int input = sc.nextInt();
        if(input >= 30){
            return "Yes";
        }
        else{
            return "No";
        }
    }
}


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

int main(){
    int n;
    vector<int> p;

    cin>>n;
    p = vector<int>(n);
    for(int i=0;i<n;i++){
        cin >>p[i];
    }

    int c=0;
    int m= 200001;
    for(int i=0;i<n;i++){
        if(p[i]<=m){
            c++;
            m=p[i];
        }
    }
    cout<<c<<endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int num = 0;
		int count = 0;
		double answer = 0.0;

		// 数の入力
		num = scan.nextInt();

		for (int i = 1; i <= num; i++) {
			if (i % 2 == 1) {
				count++;
			}
		}

		answer = (double) count / (double) num;
		System.out.println(answer);

	}
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int k,n; cin >> k >> n;
    vector<int> A(n);
    rep(i,n) cin >> A[i];
    int tmp;
    int MIN = k;
    rep(i,n){
        if(i == n - 1){
            tmp = k + A[0] - A[i];
        }else{
            tmp = A[i+1] - A[i];
        }
        MIN = min(MIN,k - tmp);
    }
    cout << MIN << endl;
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k < a)
	{
		cout<<k<<endl;
	}
	else if(k <= a+b)
	{
		cout<<a<<endl;
	}
	else
	{
		cout<<2*a+b-k<<endl;
	}
	return 0;
}

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

using namespace std;

namespace {

#define VEVE(i, a, b) for (ll i = a, __##i = b; i < __##i; ++i)
#define DYDY(i, a, b) for (ll i = a, __##i = b; i > __##i; --i)
#define RARA(x, seq) for (auto &x : seq)
#define SIZE(x) ((ll)(x.size()))
#define ALL(x) x.begin(), x.end()

typedef int ll;
typedef double dd;

void Solve(ll) {
  ll n;
  if (not(cin >> n))
    return;
  vector<set<ll>> adj(n);
  VEVE(e, 0, n - 1) {
    ll a, b;
    cin >> a >> b;
    --a, --b;
    adj[a].emplace(b);
    adj[b].emplace(a);
  }
  string color;
  cin >> color;
  vector<bool> del(n);
  {
    queue<ll> que;
    // remove black leaves
    VEVE(v, 0, n) que.emplace(v);
    while (not que.empty()) {
      const ll at = que.front();
      que.pop();
      if (SIZE(adj[at]) <= 1 and color[at] == 'B') {
        del[at] = true;
        if (SIZE(adj[at]) == 1) {
          const ll to = *adj[at].begin();
          que.push(to);
          adj[at].clear();
          adj[to].erase(at);
        }
      }
    }
  }
  const ll rem = count(ALL(del), false);
  if (rem == 0) {
    cout << "0\n"; // no white vertex
    return;
  }
  if (rem == 1) {
    cout << "1\n"; // one white vertex
    return;
  }
  vector<bool> bad(n);
  VEVE(v, 0, n) bad[v] = not del[v] and (SIZE(adj[v]) % 2) != (color[v] == 'W');
  const ll euler_tour_cost = 2 * (rem - 1) + count(ALL(bad), true);
  vector<ll> cost(n);
  VEVE(v, 0, n) {
    if (bad[v])
      cost[v] = 2;
    else
      cost[v] = 0;
  }
  ll res = euler_tour_cost;
  vector<ll> dp(n, -1); // max weight path going down from v including v
  function<void(ll, ll)> dfs = [&](ll at, ll par) {
    dp[at] = cost[at];
    RARA(to, adj[at]) if (to != par) {
        dfs(to, at);
        res = min(res, euler_tour_cost - (dp[at] + dp[to]));
        dp[at] = max(dp[at], dp[to] + cost[at]);
      }
    res = min(res, euler_tour_cost - dp[at]);
  };
  {
    const ll root = find(ALL(del), false) - del.begin();
    dfs(root, root);
  }
//  if (rem == 13)
//    VEVE(v, 0, n) RARA(to, adj[v]) cerr << v << color[v] << " " << to << color[to] << endl;
//  DEBUG(bad);
//  DEBUG(dp);
  cout << res << endl;
}

void Init() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
}

int32_t main() {
#ifdef AZN
  freopen("input.txt", "r", stdin);
#endif
  Init();
  ll tests = 11;
  VEVE(test, 1, tests + 1) Solve(test);
  return 0;
}


Measured memory_bytes: 23724