akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	int x=Integer.parseInt(str[0]);
            	int y=Integer.parseInt(str[1]);

            	if(x==0&&y==0){
            		break;
            	}
            	for(int i=0;i<x;i++){
            		for(int j=0;j<y;j++){
            			if(i==0||j==0||i==x-1||j==y-1){
            				System.out.print("#");
            			}else{
            				System.out.print(".");
            			}
            		}
            		System.out.println();
            	}
            	System.out.println();
            }
        }
    }

}

Measured memory_bytes: 30704
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
using namespace std;

int main() {
  int n;
  cin >> n;
  set<string> s;
  string st;
  rep(i, 0, n) {
    cin >> st;
    s.insert(st);
  }
  cout << s.size();
}


Measured memory_bytes: 19228
#include <iostream>
#include <queue>
#include <algorithm>
 
int main(void) {
    std::priority_queue<int> height;
 
    for (int i = 0; i < 10; ++i) {
        int h;
        std::cin >> h;
        height.push(h);
    }
 
    for (int i = 0; i < 3; ++i) {
        std::cout << height.top() << std::endl;
        height.pop();
    }
 
    return 0;
}

Measured memory_bytes: 1216
/**************************************
 * Au: Hany01
 * Prob: AGC001D
 * Date: Oct 10th, 2018
 * Email: hany01@foxmail.com
**************************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
#define Rep(i, j) for (register int i = 0, i##_end_ = j; i < i##_end_; ++ i)
#define For(i, j ,k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define SZ(a) ((int)(a.size()))
#define ALL(a) a.begin(), a.end()
#define PB(a) push_back(a)
#define MP(a, b) make_pair(a, b)
#define X first
#define Y second
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define y1 wozenmezhemecaia 
#ifdef hany01
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline T read() {
    register char c_; register T _, __;
    for (_ = 0, __ = 1, c_ = getchar(); !isdigit(c_); c_ = getchar()) if (c_ == '-')  __ = -1;
    for ( ; isdigit(c_); c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}
//EOT


const int maxn = 105;

int n, m, A[maxn];
vector<int> odd;

int main()
{
#ifdef hany01
    File("agc001d");
#endif

    n = read<int>(), m = read<int>();
    For(i, 1, m) {
        A[i] = read<int>();
        if (A[i] & 1) odd.PB(i);
    }

    if (SZ(odd) > 2) { puts("Impossible"); return 0; }

    if (SZ(odd)) swap(A[1], A[odd[0]]);
    if (SZ(odd) > 1) swap(A[m], A[odd[1]]);

    For(i, 1, m) printf("%d ", A[i]);
    putchar('\n');

    if (m == 1) {
        if (n == 1) puts("1"), puts("1");
        else printf("2\n%d %d\n", A[1] - 1, 1);
        return 0;
    }

    ++ A[1], -- A[m];
    if (!A[m]) -- m;
    printf("%d\n", m);
    For(i, 1, m) printf("%d ", A[i]);
    putchar('\n');

    return 0;
}


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

int main()
{
    char str[21];
    int i;
    cin>>str;
    for(i=0;str[i]!='\0';)
        i++;
    for(int k=i-1;k>=0;k--)
    {
        cout<<str[k];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1132
n,k = map(int,input().split())
a = [int(i) for i in input().split()]

dp = [0]*(k+1)
dp[0] = 0

for i in range(1,k+1):
  for j in range(n):
    if i-a[j] >= 0 and dp[i-a[j]] == 0:
      dp[i] = 1
      break
    #dp[i] = 0

if dp[k] == 1:
  print("First")
else:
  print("Second")


Measured memory_bytes: 9532
#include <stdio.h>
#include <math.h>
int main(void)
{
  int n,i,j,c,f;
  while(1){
    c=0;
    scanf("%d",&n);
    if(!n) break;
    for(i=n+1;i<=2*n;i++){
      f=1;
      for(j=2;j<=sqrt(i);j++){
	if(!(i%j)){
	  f=0;break;
	}
      }
      if(f) c++;
    }
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   string S;
   cin >> S;
   int size = S.size();
   int ans[size];
   memset(ans,0,sizeof(ans));
   for(int i = 0 ; i < size; i++){
      if(S[i]=='R'){
         int j = i;
         while(S[j]=='R'){
            j++;
         }
         int dist = j-i;
         int iN = (dist+1)/2;
         int jN = dist/2;
         if(dist%2==0){
            ans[j]+=iN;
            ans[j-1]+=jN;
         }
         else{
            ans[j-1]+=iN;
            ans[j]+=jN;
         }
         i=j-1;
      }
   }
   for(int i = size-1 ; i >= 0; i--){
      if(S[i]=='L'){
         int j = i;
         while(S[j]=='L'){
            j--;
         }
         int dist = i-j;
         int iN = (dist+1)/2;
         int jN = dist/2;
         if(dist%2==0){
            ans[j]+=iN;
            ans[j+1]+=jN;
         }
         else{
            ans[j+1]+=iN;
            ans[j]+=jN;
         }
         i=j+1;
      }
   }
   for(int i=0;i<size;i++){
      cout << ans[i] << " " ;
   }
   cout << endl;
   return 0;
}


Measured memory_bytes: 4156
#include <cstdio>
#include <cctype>
#include <utility>
#include <array>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	array<int, 3> l{};
	for (int a, b, c, n = 0; scan(a, b, c);) {
		if (a > b) swap(a, b);
		if (b > c) swap(b, c);
		double r = (a * a + b * b - c * c) / 2.0 / a / b;
		if (r > -1) {
			n++;
			if (r == 0)
				l[0]++;
			else if (r > 0)
				l[1]++;
			else
				l[2]++;
		} else {
			out(n);
			for (int x: l)
				out(' ' ,x);
			outl();
			break;
		}
	}
}


Measured memory_bytes: 2540
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

t = 0

for i in range(n):
    if i != n-1:
    #自分の担当箇所に全力投球

        #敵の方が多い
        if b[i] < a[i]:
            t += b[i]#倒せるだけ

        #倒せる数の方が多い
        else:
            #自分のとこ倒して、隣を倒せるだけ倒す
            if a[i+1] > b[i] - a[i]:
                t += min(a[i+1]+a[i],b[i])
                a[i+1] = max(0,a[i+1] + a[i]- b[i])

            #隣を全部倒す
            else:
                t += a[i]+a[i+1]
                a[i+1] = 0
            #a[i+1] = max(0,a[i+1] - (b[i]-a[i])) #残ったらその分を隣に回す
            #t += b[i] + max(0,(a[i]-b[i]))
        #print(i,t)
    else:
        if b[i] - a[i] < 0:
            t += b[i]
        else:
            t += (a[i] + min(b[i] - a[i],a[i+1]))#残りと最後のやつの比較

    #print(i,t)

        #t += min(b[n-1],)
print(t)


Measured memory_bytes: 82020
r, c = gets.split.map(&:to_i)

ary = []

r.times{
    line = gets.split.map(&:to_i)
    line.push(line.inject(:+))
    ary.push(line)
}

 c += 1

sum_line = []
c.times{|i|
    sum = 0
    for j in 0..(r-1) do
        sum += ary[j][i]
    end
    sum_line.push(sum)
}

ary.push(sum_line)

(r+1).times{|i|
    puts ary[i].join(" ")
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)

const LL mod=(1e9)+7;
int main()
{
    LL n;
    cin>>n;
    LL a[n+1];
    LL s[n+1];
    MEM(s,0);
    for(LL i=1; i<=n; i++)
    {
        cin>>a[i];
        s[i]=s[i-1]+a[i];
        s[i]=s[i]%mod;
    }
    LL ans=0;
    LL sum=s[n];
    for(LL i=1; i<=n; i++)
    {
        LL x=a[i];
        LL y=sum-s[i];
        if(y<0)
            y+=mod;
        ans+=((x%mod)*(y%mod))%mod;
        ans=ans%mod;
    }
    cout<<ans;
}


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

using namespace std;

const int INF = 1 << 30;

int main()
{
  int N, T, A[100000];

  cin >> N >> T;
  for(int i = 0; i < N; i++) cin >> A[i];

  int ret = 0;

  int small = INF, big = 0;
  for(int i = 0; i < N; i++) {
    small = min(small, A[i]);

    big = max(big, A[i] - small);
  }

  int curr = big;
  small = INF, big = 0;

  for(int i = 0; i < N; i++) {
    small = min(small, A[i]);
    if(A[i] - small == curr) ++ret;
  }

  cout << ret << endl;
}


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

using namespace std;

const int MAX = 1e9+7;
typedef long long ll;

ll quickPow(ll a, ll b){
	ll p = 1%MAX;
	while(b){
		if(b & 1)
			p = p * a % MAX;
		a = a * a % MAX;
		b >>= 1;
	}
	return p;
}

int main(){
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int a[n];
	map<int, int> mark;
	for(int i=0; i<n; i++){
		cin >> a[i];
		mark[a[i]]++;
	}

	bool ok = true;
	if(n%2 != 0)
		if(mark[0] != 1)
			ok = false;

	int i = (n%2 == 0)? 1 : 2;
	for(; i<=n; i+=2)
		if(mark[i] != 2){
			ok = false;
			break;
		}

	if(ok)
		cout << quickPow(2, n/2) << endl;
	else
		cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long s,c,n=0;
	cin>>s>>c;
	c=c/2;
	if(c < s){
		cout << c;
		
	}else{
		cout << s+(c-s)/2;
		
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args : Array<String>) {
    val S = readLine()!!
    val stack = Stack<Char>()
    var answer = 0

    S.forEach {
        // see stack top
        val top = if (!stack.empty()) {
            stack.peek()
        } else it

        val canRemove = it != top
        if (canRemove) {
            answer += 2
            stack.pop()
        } else {
            stack.push(it)
        }
    }

    println(answer)
}


Measured memory_bytes: 36076
#include <iostream>
using namespace std;
int main()
{
  char c;
  int n, x = 0, max = 0;
  cin >> n;
  while( cin >> c )
  {
    if( c == 'I' )
      x++;
    else
      x--;
    if( max < x ) 
      max = x;
  }
  cout << max;
}

Measured memory_bytes: 3144
a_L = map(int,input().split())

a_L = list(sorted(a_L))

diff1 = a_L[2]-a_L[1]
diff2 = a_L[2]-a_L[0]


if (diff1+diff2) % 2 == 0:
    print((diff1+diff2)//2)
else:
    print((diff1+diff2+3)//2)

Measured memory_bytes: 61720
n = int(input())
dp = [0] * (n + 1)
a = 9
b = 6
for i in range(1, n + 1):
    if a * 9 <= i: a *= 9
    if b * 6 <= i: b *= 6
    if i - a >= 0:
        if i - b >= 0:
            dp[i] = min(dp[i - a], dp[i - b], dp[i - 1]) + 1
        else:
            dp[i] = min(dp[i - a], dp[i - 1]) + 1
    elif i - b >= 0:
        dp[i] = min(dp[i - b], dp[i - 1]) + 1
    else:
        dp[i] = dp[i - 1] + 1
print(dp[-1])

Measured memory_bytes: 3828
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
#include <complex>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace  std;
using ll = long long;
const ll mod = 1e9 + 7;
typedef pair<int, int> pairs;
typedef complex<ll> G;
const int N = 1e5+5;

const int INF = 1e9+5;
void solve(){

    int n, k;
    cin >> n >> k;

    int a[n];
    for(int i=0;i < n;++i) {
        cin >> a[i];
    }
    vector<int>dp(n, INF);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j=i;j <= k+i;j++) {
            if(j < n) {
                dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
            }
        }

    }
    cout << dp[n-1] << '\n';





}
int main() {
    fast;
    solve();

}


Measured memory_bytes: 1024
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a >= 13) System.out.println(b);
        else if((a >= 6) && (a <= 12)) System.out.println(b / 2);
        else System.out.println(0);
    } 
}

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

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

    long r = 0, g = 0, b = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R') r++;
        else if (s[i] == 'G') g++;
        else if (s[i] == 'B') b++;
    }
    long ans = r * g * b;
    int k;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; 2 * j - i < n; j++)
        {
            k = j + (j - i);
            if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k]) ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include<stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	(((0<=a)&&(a<=10000))&&((b>=0)&&(b<=10000))&&((c>=0)&&(c<=10000)));
	if((a <= b)&&(b <= c))
	{
		printf("%d %d %d\n",a,b,c);
	}
	else
	{
		if((a <= c)&&(c <= b))
		{
			printf("%d %d %d\n",a,c,b);
		}
		
		else
		{
			if((b <= a)&&(a <= c))
			{
				printf("%d %d %d\n",b,a,c);
			}
		
			else
			{
				if((b <= c)&&(c <= a))
				{
					printf("%d %d %d\n",b,c,a);
				}
				else
				{
					if((c <= b)&&(b <= a))
				{
					printf("%d %d %d\n",c,b,a);
				}
					else
					{
						if((c <= a)&&(a <= b))
					{
						printf("%d %d %d\n",c,a,b);
					}
					}
				}
			}
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define repb(i,a,b)         for(ll i=a;i>=b;i--)
#define f(n)                for (ll i=0;i<n;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define tr(c,it)            for(((c).begin())it=(c).begin();it!=(c).end();it++)
#define sz(c)               (c).size()
#define all(c)              (c).begin(),(c).end()
#define sl(a)               scanf("%lld",&a);
#define TH                  1000
#define F                   first
#define S                   second
#define N                   100005
ll MOD=pow(10,9)+7;

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

    vector <ll> v;
    ll a[n+1];
    v.pb(0);
    rep(i,1,n+1)
    {
        cin>>a[i];
        ll k;cin>>k;
        v.pb(k);
    }

    ll dp[n+1][w+1];
    mem(dp,0);

    rep(i,1,n+1)
    {
        rep(j,1,w+1)
        {
            if(j>=a[i])
                dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-a[i]]);
            else
                dp[i][j]=dp[i-1][j];
        }
    }

    cout<<dp[n][w]<<endl;
}


Measured memory_bytes: 79104
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, m, k;
string s;

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

    V<Pii> v;
    char c = ' ';
    int cnt = 0;
    REP(i, n+1) {
        if (i < n && c == s[i]) {
            cnt++;
        } else {
            if (cnt > 0) {
                v.push_back({c - '0', cnt});
            }
            if (i < n) {
                c = s[i];
                cnt += 1;
            }
        }
    }

    int maxi = 0;
    REP(i, v.size()) {
        int r, l = i > 0 ? v[i-1].second : 0;
        if (v[i].first == 0) {
            r = i+2*k-1 < v.size() ? v[i+2*k-1].second : v.back().second;
        } else {
            r = i+2*k < v.size() ? v[i+2*k].second : v.back().second;
        }
        maxi = max(maxi, r - l);
    }
    std::cout << maxi << '\n';

    return 0;
}


Measured memory_bytes: 1528
N = gets.to_i
A = gets.split.map(&:to_i).sort!

lgcd = [A[0]]
1.upto(N-1) do |i|
  lgcd[i] = lgcd[i-1].gcd(A[i])
end

rgcd = []
rgcd[N-1] = A[-1]
(N-2).downto(0) do |i|
  rgcd[i] = rgcd[i+1].gcd(A[i])
end

ans = 0
0.upto(N-1) do |i|
  gcd = if i == 0
    rgcd[1]
  elsif i == N-1
    lgcd[N-2]
  else
    rgcd[i+1].gcd(lgcd[i-1])
  end

  ans = gcd if ans < gcd
end

puts ans

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

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int h,w; cin>>h>>w;
  vector<string> a(h);
  for (int i=0; i<h; i++) {
    cin>>a[i];
  }
  queue<ii> q;
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (a[i][j]=='#') q.push(make_pair(i,j));
    }
  }
  int dx[] = {1, -1, 0, 0};
  int dy[] = {0, 0, 1, -1};
  int ans=0;
  vector<ii> nxt;
  while(!q.empty()) {
    int nx, ny;
    ny = q.front().first;
    nx = q.front().second;
    q.pop();
    for (int i=0; i<4; i++) {
      int tx = nx + dx[i];
      int ty = ny + dy[i];
      if (0<=tx&&tx<w&&0<=ty&&ty<h&&a[ty][tx]=='.') {
        a[ty][tx] = '#';
        nxt.push_back(make_pair(ty,tx));
      }
    }
    if (q.empty()) {
      ans++;
      for(auto& v: nxt) {
        q.push(make_pair(v.first, v.second));
      }
      nxt={};
    }
  }
  cout << ans-1 << endl;
}

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


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

using namespace std;

int cnt[2][100010];

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

	for (int i = 0; i < n; i++) {
		int j = i & 1;
		int x;
		cin >> x;
		cnt[j][x]++;
	}

	int mx1, mx2;
	mx1 = mx2 = 0;
	for (int i = 1; i <= 100000; i++) {
		if (cnt[0][i] > cnt[0][mx1]) mx1 = i;
	}
	for (int i = 1; i <= 100000; i++) {
		if (cnt[1][i] > cnt[1][mx2]) mx2 = i;
	}

	if (mx1 != mx2) {
		cout << n - cnt[0][mx1] - cnt[1][mx2] << endl;
	}
	else {
		int tmx1 = 0, tmx2 = 0;
		for (int i = 1; i <= 100000; i++) {
			if (i != mx1 && cnt[0][i] > cnt[0][tmx1]) tmx1 = i;
		}
		for (int i = 1; i <= 100000; i++) {
			if (i != mx2 && cnt[1][i] > cnt[1][tmx2]) tmx2 = i;
		}
		cout << min(n - cnt[0][mx1] - cnt[1][tmx2], n - cnt[0][tmx1] - cnt[1][mx2]) << endl;
	}
}


Measured memory_bytes: 4368
n, k = map(int, input().split())
X = list(map(int, input().split()))
ans = pow(10,9)+7
for i in range(n-k+1):
    ans = min(ans, min(abs(X[i])+abs(X[i+k-1]-X[i]), abs(X[i+k-1])+abs(X[i]-X[i+k-1])))
print(ans)

Measured memory_bytes: 20124
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=3050;
//↑templete
int main(){
	int N, T;
	cin>>N>>T;
	vpint A;
	for(int i=0;i<N;i++){
		int a, b;
		cin>>a>>b;
		A.eb(a, b);
	}
	sort(A.begin(), A.end());
	int DP[SIZE][2*SIZE]={};	//i番目までの商品の中で、時間T-1までに注文して時間jまでに食べ終わった商品のおいしさの最大値
	for(int i=0;i<N;i++){
		for(int j=0;j<T+SIZE;j++){
			DP[i+1][j]=max(DP[i+1][j], DP[i][j]);
			if(j<T){
				DP[i+1][j+A[i].first]=max(DP[i][j+A[i].first], DP[i][j]+A[i].second);
			}
		}
	}
	int ans=0;
	for(int i=0;i<2*SIZE;i++){
		ans=max(ans, DP[N][i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 72960
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.next();
        boolean f = false;
        for (int i = 0; i < s.length()-1; i++) {
            if (s.charAt(i) == s.charAt(i+1)){
                System.out.println((i+1) +" " + (i+2));
                f= true;
                break;
            }
            
        }
        if (f==false){
        for (int i = 0; i < s.length()-2; i++) {
            if (s.charAt(i) == s.charAt(i+2)){
                System.out.println((i+1) +" " + (i+3));
               f = true;
                break;
                
            }
        }
        }
        if (f==false)
            System.out.println("-1 -1");
    }

}


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



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

        }
        else if(s[i] == '1'){
            ans = ans + "1";

        }
        else if(s[i] == 'B'){
            if(ans.size() > 0){
            ans.erase(ans.size() - 1);

            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

template<typename T>
T up(const T& l, const T& r) {//SegmentTreeのupdate関数
    T res;
    res = l+r;
    return res;
}

template<typename T>
class SegmentTree {
public:
    vector<T> seg;
    int sz = 1;
    T unit;
    //T (*up)(const T& l,const T& r);
    SegmentTree(int n, T unit = 0) {
        this->unit = unit;
        //int sz = 1;
        while (sz < n) sz <<= 1;
        seg.resize(sz * 2, unit);
        //up = &up1;
    }
    void set(const int& k, const T& x) {//左からk番目の葉にxを代入する
        seg[sz - 1 + k] = x;
    }
    T get(const int& k) {//左からk番目の葉を得る
        return seg[sz - 1 + k];
    }
    void update(int k, const T& v) {// k 番目の値をvに変更
        k += sz - 1;
        seg[k] = v;
        while (k > 0) {
            k = (k - 1) / 2;
            seg[k] = up(seg[2 * k + 1], seg[2 * k + 2]);
        }
    }
    T query(int a, int b, int k, int l,int r) {//[a,b)のupの合成を求める(a,b,0,0,sz)のように使う
        if (r <= a || b <= l) {
            return unit;
        }
        if (a <= l && r <= b) {
            return seg[k];
        }
        else {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return up(vl, vr);
        }
    }
};
template<typename T>
int lower_bound_sg(SegmentTree<T>& sg,T c,int n){//各点0,1が格納されていて、累積和がcと一致する最小のindexを返す
    int sz = sg.sz;
    int lb = -1;
    int ub = n+2;
    while(ub-lb>1){
        int mid = (lb+ub)/2;
        int temp = sg.query(0, mid, 0, 0, sz);//[0,mid)の和
        if(temp<c){
            lb = mid;
        }else{
            ub = mid;
        }
    }
    return lb;
}

int main(){
    int n;
    cin >> n;
    vector<P> p(n);
    REP(i,n){
        cin >> p[i].first;
        p[i].second = i+1;
    }
    sort(all(p));
    SegmentTree<int> sg(n+2);
    ll res = 0;
    sg.update(0,1);
    sg.update(n+1,1);
    int sz = sg.sz;
    Rep(i,n){
        int temp = sg.query(0,p[i].second,0,0,sz);
        int t = p[i].second-lower_bound_sg(sg,temp,n);
        int t2= lower_bound_sg(sg,temp+1,n)-p[i].second;
        res+=(double)t*t2*(i+1);
        sg.update(p[i].second,1);
    }
    put(res);
    return 0;
}


Measured memory_bytes: 3840
n, m = map(int, input().split())
 
root = [-1]*n
def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]
 
def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x
 
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a, b)
 
ans = 0
for i in range(n):
    ans = max(ans, -root[i])
 
print(ans)


Measured memory_bytes: 13348
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [h, w] <- map strToInt . words <$> getLine
    -- kaigyousuuretu
    cs <- replicateM h getLine
    -- 出力
    putStrLn $ replicate (w + 2) '#'
    forM cs (putStrLn . (\x -> ['#'] ++ x ++ ['#']))
    putStrLn $ replicate (w + 2) '#'


Measured memory_bytes: 1404
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int> > Matrix;


int main(){
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++){
    bool ok = true;
    string s = to_string(i);
    for (int j = 0; j < s.size(); j++){
      if (s[j] != s[s.size()-1-j]) ok = false;
    }
    if (ok) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;


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

    int a,b,c;
    int k;
    
    //1 秒間で処理できる for 文ループの回数は、108=100,000,000108=100,000,000 回程度 今回純粋にやったら8秒かかる
    for(int i=0;i<=2000;i++){
        for(int j=0;j<=2000;j++){
            k=n-i-j;
                if(10000*i+5000*j+1000*k==y && i+j+k==n && 0<=k && k<=2000){
                    cout << i <<" "<< j <<" "<< k << endl;
                    return 0;
                }
        }
    }
    cout << -1 <<" "<< -1 <<" "<< -1 << endl;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

const int maxn = 2005;

ll a[maxn], b[maxn * 2];
ll x;
int n;

int q[maxn * 2], front, rear;

ll solve(int v){
    for(int i = 1;i <= n;i++){
        b[i] = a[i];
        b[i + n] = a[i];
    }
    front = 1, rear = 0;
    ll ans = 0;
    for(int i = 1;i <= 2 * n;i++){
        while(front <= rear and q[front] < i - v){
            front++;
        }
        while(front <= rear and b[q[rear]] >= b[i]){
            rear--;
        }
        q[++rear] = i;
        if(i > n){
            ans += b[q[front]];
        }
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    cin >> x;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    } 
    ll ret = 1e18;
    for(int offset = 0;offset < n;offset++){
        ll ans = 1LL * offset * x;
        ans += solve(offset);
        ret = min(ret, ans);
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 384
//#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
//#define int long long
typedef long long ll;
typedef float f80;
//#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

int a[100005];
void solve() {
	int n=4;
	cin>>n;
	fr(i,1,n) {
		cin>>a[i];
	}
	int lo=*min_element(a+1, a+n+1),hi=*max_element(a+1,a+n+1),mid=(lo+hi)/2;
	while(lo<hi) {
		int pe=0;
		ll cnt=0;
		oset lol;
		lol.insert(0);
		fr(i,1,n) {
			if(a[i]<=mid)
				pe++;
			else
				pe--;
			lol.insert(pe);
			cnt+=lol.order_of_key(pe);
		}
		trace(lo,hi,mid,cnt,(n*(n+1))/2);
		if(2*cnt>(n*(n+1LL))/2) {
			hi=mid;
		} else
			lo=mid+1;
		mid=(lo+hi)/2;
	}
	cout<<mid<<endl;

}
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	fr(i,1,t)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int x = scanner.nextInt();
			if (x == 0)
				break;
			boolean sign = x > 0;
			StringBuilder builder = new StringBuilder();
			x = Math.abs(x);
			while (x > 0) {
				int t = (x % 10);
				if (!sign && t != 0) {
					t = 10 - t;
					x += 10;
				}
				builder.insert(0, t);
				sign = !sign;
				x /= 10;

			}
			System.out.println(builder);
		}

	}
}

Measured memory_bytes: 24720
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,K,X,Y,total;
    cin >> N >> K >> X >> Y;
    total = 0;
    for(int i = 1;i <= N;i++){
        if(i <= K){
            total += X;
        }else{
            total += Y;
        }
    }
    cout << total << endl;
}


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

void bubble_sort(vector<string> &C,int N){
  for(int i=0;i<N;i++){
    for(int j=N-1;j>i;j--){
      if(int(C.at(j).at(1))<int(C.at(j-1).at(1))){
        swap(C.at(j),C.at(j-1));
      }
    }
  }
}

void selection_sort(vector<string> &C,int N){
  for(int i=0;i<N;i++){
    int minj= i; 
    for(int j=i;j<N;j++){
      if(int(C.at(j).at(1))<int(C.at(minj).at(1))){
        minj = j;
      }
    }
    swap(C.at(i),C.at(minj));
  }
}

int main() {

  int N;
  cin >> N;
  vector<vector<char>> V(9);
  queue<char> q;
  vector<string> C(N);
  vector<string> D(N);
  vector<string> F(N);
  
  for(int i=0;i<N;i++){
    cin >> C.at(i);
    V[int(C.at(i).at(1)-'0')-1].push_back(C.at(i).at(0));
    D.at(i) = C.at(i);
    F.at(i) = C.at(i);
  }
  
  for(int i=0;i<9;i++){
    if(V.at(i).size()!=0){
    for(int h=0;h<V.at(i).size();h++){    
      q.push(int(V.at(i).at(h)));
    }
    }
  }
  
  bubble_sort(D,N);
  selection_sort(F,N);
  bool bs=true;
  bool ss=true;
  for(int k=0;k<N;k++){
    if(D.at(k).at(0)!=q.front()){
      bs = false;
    }
    if(F.at(k).at(0)!=q.front()){
      ss = false;
    }
    q.pop();
  }
  
  for(int k=0;k<N-1;k++){
    cout <<  D.at(k) << ' ';
  }
    cout << D.at(N-1) << endl;
  if(bs){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }
  for(int k=0;k<N-1;k++){
    cout <<  F.at(k) << ' ';
  }
    cout << F.at(N-1) << endl;
  if(ss){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }
   
}


Measured memory_bytes: 3220
#include<stdio.h>

int main(void) {
	int i, N;
	long long A[200000];
	long long cnt = 0;

	scanf("%d", &N);

	for (i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
	}

	for (i = 0; i < N-1; i++) {
		if(A[i]>A[i+1]){ 
			cnt += (A[i] - A[i + 1]);
			A[i + 1] = A[i];
		}
	}
	printf("%lld", cnt);
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));
	int n;
	cin >> n;
	if(n==1)
	{
		cout << "1.0000000000" << endl;
		return 0;
	}
	if(n%2==0)
	{
		cout << "0.500000000" << endl;
		return 0;
	}
	std::cout << std::fixed;
    std::cout << std::setprecision(10);
	double x= n/2 + 1;
	cout << x/n << endl;
	
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	if l, r := a+b, c+d; l > r {
		fmt.Println("Left")
	} else if l < r {
		fmt.Println("Right")
	} else {
		fmt.Println("Balanced")
	}
}


Measured memory_bytes: 512
function main(input) {
  input=input.trim();
  var a = parseInt(input.split(" ")[0], 10);
  var b = parseInt(input.split(" ")[1], 10);
  if(a==1){
    a=1000
  }
  if(b==1){
    b=1000
  }
  if(a==b){
    console.log("Draw");
  }else if(a<b){
    console.log("Bob");
  }else{
    console.log("Alice");
  }

}



main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define x first
#define y second
#define N 131072
#define pi acos(-1)
typedef complex<double> C;
int main()
{
	int n;
	scanf("%d",&n);
	char c[200005];
	scanf("%s",c+1);
	int cnt[200005];
	int rev[200005];
	cnt[0]=0;
	rev[n+1]=0;
	for(int i = 1;c[i]!=0;i++){	
		cnt[i]=cnt[i-1];
		if(c[i]=='#')
		cnt[i]++;
	}
	for(int i = n;i>0;i--){
		rev[i]=rev[i+1];
		if(c[i]=='.')
		rev[i]++;
	}
	int ans=1e9;
	for(int i = 0;i<=n;i++){
		ans=min(ans,cnt[i]+rev[i+1]);
	//	printf("%d %d\n",cnt[i],rev[i+1]);
	}
	printf("%d\n",ans);
}
/*
int mod=998244353;
LL f_pow(LL a,LL b){
	LL res=1,temp=a;
	while(b){
		if(b&1)res=res*temp%mod;
		temp=temp*temp%mod;
		b>>=1;
	}
	return res;
}
int main(){
	int n;
	scanf("%d",&n);
	int a[305];
	for(int i = 0;i<n;i++)
	scanf("%d",&a[i]);
	LL dp[305][30005];
	dp[0][0]=1;
	for(int i = 0;i<n;i++){
		for(int j =0;j<30005-a[i];j++){
			dp[i+1][j+a[i]]+=dp[i][j];
			dp[i+1][j+a[i]]%=mod;
			dp[i+1][j]+=dp[i][j];
			dp[i+1][j]+=dp[i][j];
			dp[i+1][j]%=mod;
		}
	}
}*/

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

vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n % i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}

ll gcd (ll x, ll y) { return y ? gcd(y,x%y) : x; }

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a,b);
  vector<pair<ll,int>> v = factorize(g);
  ll ans = v.size() + 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

int N;
int A, B, C;
vi l(10);

int dfs(int s, int a, int b , int c) {
    if (s == N) {
        if (min(a, min(b, c)) > 0) {
            return abs(a - A) + abs(b - B) + abs(c - C) - 30;
        }
        else {
            return 1e9;
        }
    }
    int r1,r2,r3,r4;
    r1 = dfs(s+1,a,b,c);
    r2 = dfs(s+1,a+l[s],b,c) + 10;
    r3 = dfs(s+1,a,b+l[s],c) + 10;
    r4 = dfs(s+1,a,b,c+l[s]) + 10;
    return min(min(r1,r2),min(r3,r4));
}

int main() {
    cin >> N >> A >>  B >> C;
    rep(i, N) cin >> l[i];

    cout << dfs(0,0,0,0) << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using  namespace  std;
const  int N = 5005, mod = 1e9 + 7;
int n, f[N][N], m; char s[N];
int  main() {
	scanf("%d%s", &n, s + 1); m = strlen(s + 1);
	f[0][0] = 1;
	for (int i = 0; i < n; i++)
		for (int j = 0; j <= i; j++) {
			if (j) f[i + 1][j - 1] = (f[i + 1][j - 1] + f[i][j]) % mod;
			else f[i + 1][j] = (f[i + 1][j] + f[i][j]) % mod;
			f[i + 1][j + 1] = (f[i + 1][j + 1] + 1ll * f[i][j] * 2) % mod;
		}
	for (int i = 1; i <= m; i++) f[n][m] = 1ll * f[n][m] * 500000004 % mod;
	printf("%d \n", f[n][m]);
	return  0;
}

Measured memory_bytes: 96384
#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
const int _ = 100007;
char s[_];int n;
int main()
{
	register int i,a,ans=0;
	scanf("%s",s+1),n=strlen(s+1);
	for(i=1,a=0;i<=n;i++)
	{
		if(s[i]=='g')
		{
			if(a<=0)a++;
			else ans++,a--;
		}
		if(s[i]=='p')
		{
			if(a<=0)ans--,a++;
			else a--;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, k = LI()
if k == 0:
    print(n ** 2)
    quit()
ans = 0
for b in range(1, n+1):
    x, y = divmod(n, b)
    z = b - k
    if z < 0:
        continue
    if y - k + 1 < 0:
        ans += z * x
    else:
        ans += z * x + (y - k + 1)
print(ans)

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

int main() {
	int input;
	unsigned long result = 0;

	cin >> input;
	for (int i = 1; i <= input; i++)
	{
		if (i % 3 != 0 && i % 5 != 0) {
			result += i;
		}
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FOD(i,a,b) for(ll i=(a);i>=(b);--i)
#define name "a"
#define pb push_back
typedef pair < ll , ll > ii;
const ll maxn=2e3+7,oo=1e18,mod=1e9+7;
vector < ll > a[maxn];
ll dx,x,y,n,d[maxn][maxn],cnt[maxn];
priority_queue < ii , vector < ii > , greater < ii > > q;
void dij(int st)
{
    while(!q.empty())
        q.pop();
    d[st][st]=0;
    q.push(ii(d[st][st],st));
    while(!q.empty())
    {
        dx=q.top().first;
        x=q.top().second;
        q.pop();
        if(d[st][x]!=dx)
            continue;
        for(int i:a[x])
        {
            if(d[st][i]>d[st][x]+1)
            {
                d[st][i]=d[st][x]+1;
                q.push(ii(d[st][i],i));
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen(name".inp","r",stdin);
    //freopen(name".out","w",stdout);
    cin>>n>>x>>y;
    a[x].pb(y);
    a[y].pb(x);
    FOR(i,1,n-1)
    {
        a[i].pb(i+1);
        a[i+1].pb(i);
    }
    FOR(i,1,n)
    {
        fill(d[i]+1,d[i]+1+n,oo);
        dij(i);
    }
    FOR(i,1,n)
        FOR(j,i+1,n)
            ++cnt[d[i][j]];
    FOR(i,1,n-1)
        cout<<cnt[i]<<'\n';
}


Measured memory_bytes: 31744
s=str(input())
t=str(input())
a=len(s)-len(t)
A=[]
d=0
if a==0:
    for k in range(len(t)):
        if t[k]!=s[k]:
            d+=1
    print(d)
else:    
    
    for i in range(a):
        b=0
        for j in range(len(t)):
            if t[j]==s[j+i]:
                b+=1
        A.append(b)

    c=max(A)
    print(len(t)-c)
    

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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

int main()
{
    int a, b, k;
    cin >> a >> b >> k;

    for(int i = a; i <= min(b, a + k - 1); i++)
        cout << i << endl;
    for(int i = max(a + k, b - k + 1); i <= b; i++)
        cout << i << endl;

    return 0;
}


Measured memory_bytes: 256
n,y=map(lambda x: int(x), input().split())
r1=-1
r2=-1
r3=-1
find=False
for i in range(n+1):
    if find==True:
        break
    for j in range(n-i+1):
        if find==True:
            break
        if i*10000+j*5000+(n-i-j)*1000==y:
            r1=i
            r2=j
            r3=n-i-j
print('{} {} {}'.format(r1,r2,r3))

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {

	sc.Split(bufio.ScanWords)

	N, D := nextInt(), nextInt()
	var count int = 0
	for i := 0; i < N; i++ {
		X, Y := nextInt(), nextInt()
		if D*D >= X*X+Y*Y {
			count++
		}
	}

	fmt.Println(count)

}


Measured memory_bytes: 4892
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# def power(x, y):
#     if y == 0:
#         return 1
#     elif y == 1:
#         return x % mod
#     elif y % 2 == 0:
#         return power(x, int(y/2)) ** 2 % mod
#     else:
#         return power(x, int((y-1)/2)) ** 2 * x % mod

# # nCaとしたときのaのmaxがa_max
# a_max = 10 ** 5
# # a, bの最大値+2
# fact = [1] * (a_max + 2)
# # 逆元
# for i in range(1, a_max + 1):
#     fact[i] = (fact[i-1] * i) % mod
# # combination
# def C(n, a):
#     tmp = 1
#     for i in range(n, n-a, -1):
#         tmp = (tmp * i) % mod
#     return tmp * power(fact[a], mod - 2)


upper = 10**5  # 必要そうな階乗の限界を入れる
factorial = [1]
for i in range(1, upper):
    factorial.append(factorial[i-1] * i % mod)
def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, int(y/2)) ** 2 % mod
    else:
        return power(x, int((y-1)/2)) ** 2 * x % mod
 
def C(n, r):
    return (((factorial[n] * x_inv[r]) % mod) * x_inv[n-r]) % mod
 
x_inv = [0] * upper
x_inv[-1] = power(factorial[-1], mod-2)
for i in range(upper-2, -1, -1):
    x_inv[i] = x_inv[i+1] * (i+1) % mod
 




N, K = MAP()
A = LIST()

A.sort()
# each max, min
max_wa = 0
min_wa = 0

for i in range(N-(K-1)):# N-(K-1)の範囲 
    # A[i]の値がmax,minになる集合SがnCk個ある．
    max_wa += A[N-1-i] * C(N-1-i, K-1)
    min_wa += A[i] * C(N-1-i, K-1)
print((max_wa - min_wa) % mod)






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

bool bool_stringCreate(string s){
	
	for(int i = 0; i < (signed)s.length(); ){
		if(s.substr(i, 13) == "dreamereraser")
			i += 13;
		else if(s.substr(i, 12) == "dreamererase")
			i += 12;
		else if(s.substr(i, 11) == "dreameraser")
			i += 11;
		else if(s.substr(i, 10) == "dreamerase")
			i += 10;
		else if(s.substr(i, 6) == "eraser")
			i += 6;
		else if(s.substr(i ,7) == "dreamer")
			i += 7;
		else if(s.substr(i, 5) == "dream" || s.substr(i, 5) == "erase")
			i += 5;
		else
			return 0;
	}

	return 1;
}

int main(){

	string s;

	cin >> s;
	
	if(bool_stringCreate(s))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 640