akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    string str;

    cin >> str;

    int i = 0;
    int j = str.size() - 1;
    int ans = 0;
    int left = 0;
    int right = 0;

    while(i < j){
        while(i < str.size() && str[i] == 'x'){
            i++;
            left++;
        }

        while(j >= 0 && str[j] == 'x'){
            j--;
            right++;
        }

        if(str[i] == str[j]){
            if(i > j){
                break;
            }else{
                ans += abs(left - right);
                left = right = 0;
                i++;
                j--;
            }
        }else{
            cout << -1 << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 512
N,K = map(int,input().split())
s = input()
#first
last = -1
ck = K
pre = ''
for i in range(N):
    c = s[i]
    if c == '0' and pre != '0':
        ck -= 1
        if ck < 0:
            last = i - 1
            break
    pre = c
else:
    last = N-1
#print('last:',last)

if last == N-1:print(len(s))
else:
    ## step by step
    cameLast = False
    ilr = 0
    g_max = 0
    while True:
        #print('calc g.:',last - ilr + 1)
        g_max = max(g_max,last - ilr + 1)
        if cameLast:break
        pre = ''
        for i in range(ilr,N):
            if s[i] == '1' and pre == '0':
                ilr = i
                break
            else:pre = s[i]
        else:#print('CANNOT REACH HERE!! - no next ilr')
            ilr = len(s) - 1
        prel = ''
        for j in range(last+1,N):
            if s[j] == '0' and prel == '1':
                last = j - 1
                break
            else:prel = s[j]
        else:#'reach last s[]'
            last = len(s) - 1
            cameLast = True
    print(g_max)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
//typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=998244353;         
const int N=3e3+4;

ll dp[N][N];

int main()
{
	int n,sum; scn(n); scn(sum);

	int a[n]; rep(i,0,n)scn(a[i]);

	ll ans=0;

	dp[0][0]=1;

	for(int i=0;i<n;i++)
	{
		rep(j,0,sum+1)
		{
			dp[i+1][j]=(dp[i+1][j]+(2*dp[i][j]))%mod;

			if(j+a[i]<=sum)
			dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+dp[i][j])%mod;
		}
	}

	cout<<dp[n][sum];

    return 0;
}

Measured memory_bytes: 74080
n = int(input())
w = list(map(int,input().split()))

ans = 999999
for i in range(n):
    if i == 0:continue
    sum1 = sum(w[0:i])
    sum2 = sum(w[i:n])
    ans = min(ans,abs(sum1-sum2))
    # print(i,w[0:i],w[i:n],ans)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> E(N, vector<int>(N, 0));
  for (int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a][b] =1;
    E[b][a] = 1;
  }
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    P[i] = i;
  }
  int count = 0;
  while (1){
    bool flg = true;
    for (int i = 0; i < N - 1; i++){
      if (E[P[i]][P[i + 1]] == 0){
        flg = false;
      }
    }
    if (flg){
      count++;
    }
    if (!next_permutation(P.begin() + 1, P.end())){
      break;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
from numpy import*
h,*s=open(0)
h,w=int32(h.split())
r=range
s=int32([[u>'#'for u in t]for t in s])
a,b,c,d=eval('copy(s),'*4)
for i in r(w):a[:,i],b[:,~i]=-~a[:,i-1]*s[:,i],-~b[:,-i]*s[:,~i]
for i in r(1,h):c[i,:],d[~i,:]=-~c[i-1,:]*s[i,:],-~d[-i,:]*s[~i,:]
print(int((a+b+c+d).max())-3)

Measured memory_bytes: 122032
N, K = map(int, input().split())
A = list(map(int, input().split()))

# nの約数を求める。計算量O(sqrt(N))
def get_divisors(n):
    from math import sqrt, ceil
    from collections import deque
    divisors = deque([])
    for num in range(ceil(sqrt(n)), n+1):
        if n % num == 0:
            divisors.append(n//num)
            if n//num != n:
                divisors.appendleft(num)
    return list(divisors)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors

total = sum(A)
divisors = make_divisors(total)
ans = -1
for d in divisors:
    R = [a%d for a in A]
    R.sort(reverse=True)
    pr = 0
    nr = -sum(R)
    for i, r in enumerate(R):
        pr += d-r
        nr += r
        if nr+pr >= 0:
            if pr <= K and nr+pr == 0:
                ans = d
            break
    if ans != -1:
        print(ans)
        break
else:
    print(1)


Measured memory_bytes: 42220
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
ll a[200010];
ll b[200010];

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];

    rep(i, n) b[i+1] = b[i] + a[i];
    sort(b, b+n+1);

    ll ans = 0;
    set<ll> used;
    rep(i, n+1) {
        auto it = used.find(b[i]);
        if (it == used.end()) {
            used.insert(b[i]);
            ll num = upper_bound(b, b+n+1, b[i]) - lower_bound(b, b+n+1, b[i]);
            ans += num * (num - 1) / 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 12800
#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
	string s;
	cin >> s;
	int count1 = 0;
	int count2 = 0;
	for (int i = 0; i < s.length(); i++) {
		if ((int(s[i]) - int('0'))%2 == i%2)
			count1+=1;
		else
			count2+=1;
	}
	cout << (count1<count2?count1:count2) << endl;
	
	return 0;
}

Measured memory_bytes: 512
// 2011/06/30 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string srv;
		cin >> srv;
		if(srv=="0")
			break;

		int pntA = 0;
		int pntB = 0;
		for(int i=1; i<srv.size(); i++)
			if(srv[i]=='A')
				pntA++;
			else
				pntB++;

		if(pntA>pntB)
			pntA++;
		else
			pntB++;

		cout << pntA << ' ' << pntB << endl;
	}

	return 0;
}

Measured memory_bytes: 0
N,M,X,Y = gets.chomp.split.map(&:to_i)
x = gets.chomp.split.map(&:to_i)
y = gets.chomp.split.map(&:to_i)
x_max = 0
y_min = 0

x.sort!.reverse!
x[0] > X ? x_max = x[0] : x_max = X

y.sort!
y[0] < Y ? y_min = y[0] : y_min = Y

puts x_max < y_min ? "No War" : "War"

Measured memory_bytes: 1788
if __name__ == "__main__":
    n = int(input())
    A = list(map(int, input().split()))

    swap_count = 0
    flag = True
    while flag:
        flag = 0
        for j in range(1, n):
            if A[j-1] > A[j]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                swap_count += 1

    print(' '.join(map(str, A)))
    print(swap_count)



Measured memory_bytes: 5600
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int dp[1001][1001];

int main(){
  int W, N, v[1024], w[1024], c = 0, res = 0;
  while(scanf("%d", &W) && W){
    c++;
    scanf("%d", &N);
    for(int i = 0; i < N; ++i) scanf("%d,%d", v + i, w + i);
    res = 0;
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < N; ++i){
      for(int j = 0; j <= W; j++){
	if(j < w[i]) dp[i + 1][j] = dp[i][j];
	else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
      }
    }
    for(int j = 0; j < W; ++j) if(dp[N][j] < dp[N][W]) res++;
    printf("Case %d:\n%d\n%d\n", c, dp[N][W], res);
  }
  return 0;
}

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

int main () {
	int w[10];
	int k[10];
	for (int i = 0; i < 10; i++) {
		cin >> w[i];
	}
	for (int i = 0; i < 10; i++) {
		cin >> k[i];
	}
	sort(w, w + 10);
	sort(k, k + 10);
	int wSum = 0, kSum = 0;
	for (int i = 9; i > 6; i--) {
		wSum += w[i];
	}
	for (int i = 9; i > 6; i--) {
		kSum += k[i];
	}
	cout << wSum << " " << kSum << endl;
	return 0;
}

Measured memory_bytes: 0
N = int(input())

h = list(map(int, input().split()))

def sink(mountain):
    if mountain == []:
        return 0

    takes = 0

    min_h = min(mountain)

    sank = [i - min_h for i in mountain]

    takes += min_h

    small_mnt = []

    for i, height in enumerate(sank):
        if height > 0:
            small_mnt.append(height)
        else:
            takes += sink(small_mnt)
            small_mnt.clear()

    takes += sink(small_mnt)

    return takes

print(sink(h))


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

string s;

Int dfs(Int sum,Int r,Int d){
    if(d>=s.size()) return sum+r;
    else{
        Int a=dfs(sum+r,s[d]-'0',d+1);
        Int b=dfs(sum,10*r+s[d]-'0',d+1);
        return a+b;
    }
}

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

    cin>>s;
    cout<<dfs(0,s[0]-'0',1)<<'\n';
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] age){
		Scanner G = new Scanner(System.in);
		String imput = G.nextLine();
		String[] arrayimput = imput.split(" ");
		int a = Integer.parseInt(arrayimput[0]);
		int b= Integer.parseInt(arrayimput[1]);
		int c = Integer.parseInt(arrayimput[2]);
		int i, j=0;
		for( i=1 ; i<=c ; i++){
			if( a<=i & b>=i & c%i==0 ){
				j++;
			}
		}
		System.out.println(j);
	}
}

Measured memory_bytes: 26164
N, M = map(int,input().split())
X = [int(x) for x in input().split()]
X.sort(reverse=True)
valX = [X[x] - X[x + 1] for x in range(M - 1)]
valX.sort(reverse=True)

if N >= M:
    print(0)
    exit()

if N == 1:
    print(max(X) - min(X))
    exit()

for i in range(N - 1):
    valX[i] = 0

print(sum(valX))

Measured memory_bytes: 13832
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
  #define cerrendl 42
#endif
//}}}

signed main() {
  int h,w,n;cin>>h>>w>>n;
  int z = max(h, w);
  int ans = divceil(n, z);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//
//  abc148_d.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll INF = 1000000007;
#define PI 3.14159265

const int MAX = 110000;

ll fac[MAX], finv[MAX], inv[MAX];

std::vector<int> permutations;

int gcd(int a, int b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}

int main() {
  ll n;
  std::cin >> n;
  int a[n];

  int index = 0;
  int broken = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    if (a[i] == index + 1) {
      index++;
    }
    else {
      broken++;
    }
  }

  if (broken == n) {
    std::cout << -1 << std::endl;
  }
  else {
    std::cout << broken << std::endl;
  }

  return 0;
}



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

int main() {
   long long X,K,D;
   cin >> X >> K >> D;
   X=abs(X);
   long long m=X;
   if (K<1000000000 || (X/D)<1000000000) {
   for (int i=0; i<K; i++) {
       if (m>abs(m-D)) { 
           if (m-D<0) {
               m=abs(m-D);
               if ((K-i)%2==0) {
               m=min(abs(m+D),abs(m-D));
           }
               break;
           }
           m=abs(m-D);
       }
       else {
           if ((K-i)%2==1) {
               m=min(abs(m+D),abs(m-D));
           }
           break;
       }
   }
   cout << m << endl;
   }
   else {
       long long a=X%D;
       if ((X/D+1)>K && X>K*D) {
           cout << X-K*D << endl;
       }
       else {
           long long b=(X-a)/D;
           if ((K-b)%2==0) cout << a << endl;
           else cout << D-a << endl;
       }
   }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string s;
  cin>>s;
  bool f=0;
  f|=(s[0]==s[1]&&s[1]==s[2]);
  f|=(s[1]==s[2]&&s[2]==s[3]);
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())

dp = [10**6 for _ in range(n+1)]
dp[0] = 0

for i in range(n+1):
    j6 = 1
    while i+j6<=n:
        dp[i+j6] = min(dp[i]+1,dp[i+j6])
        j6 *= 6
    j9 = 1
    while i+j9<=n:
        dp[i+j9] = min(dp[i]+1,dp[i+j9])
        j9 *= 9
print(dp[n])


Measured memory_bytes: 79208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	cout << a*b/2 << endl;
}

Measured memory_bytes: 892
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

int mod_inv(ll x, ll p) {
    ll m = p - 2;
    ll ans = 1;
    ll now_val = x;
    while(m > 0) {
        if(m & 1) ans = (ans * now_val) % p;
        now_val = (now_val * now_val) % p;
        m >>= 1;
    }
    return ans;
}


int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    ll INF = 1e9 + 7;
    ll x[200001], x_inv[200001];
    x[0] = 1LL;
    ll ans = 0LL;

    for(ll i = 1; i <= 200000; i++) {
        x[i] = (x[i - 1] * i) % INF;

    }
    x_inv[200000] = mod_inv(x[200000], INF);

    for(ll i = 199999; i >= 0; i--) {
        x_inv[i] = (x_inv[i + 1] * (i + 1)) % INF;
    }
    for(int i = 1; i <= W - B; i++) {
        ll t1 = (((x[i + B + H - A - 2] * x_inv[i + B - 1]) % INF) * x_inv[H - A - 1]) % INF;
        ll t2 = (((x[W - i - B + A - 1] * x_inv[W - i - B]) % INF) * x_inv[A - 1]) % INF;
        ans = (ans + t1 * t2) % INF;
    }

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


Measured memory_bytes: 3328
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
string parse[6];
int N;
int C[6];
int A[6];
//x?????¢???
int find(string s,char c){
   REP(i,s.size()){
       if(s[i]==c){
          return i;
       }
   }
   return -1;
}
//x??????????????°???????????????
int getC(string s){
    int num=find(s,'x');
    if(num==-1){
       return stoi(s);
    }else{
       if(num==0){
          return 1;
       }else if(num==1&&s[0]=='-'){
          return -1;
       }
       return stoi(s.substr(0,num));
    }
}
//x?????????????????????
int getA(string s){
    int a=find(s,'^');
    if(a==-1){
       int b=find(s,'x');
       if(b==-1){
          return 0;
       }else{
          return 1;
       }
    }else{
       return stoi(s.substr(a+1,s.size()));
    }
}

//+???????§£??????
int split(string s){
    int count=0;
    string a="";
    REP(i,s.size()){
       if(s[i]=='+'||s[i]=='-'){

          parse[count]=a;
          a="";
          if(s[i]=='-'){
             a="-"+a;
          }
          count++;
          continue;
       }
       a.push_back(s[i]);
    }
    parse[count]=a;
    count++;
    return count;
}
bool check(int x){
   int ans=0;
   REP(i,N){
       int sum=1;
       REP(j,A[i]){
           sum*=x;
       }
       sum*=C[i];
       ans+=sum;
   }
   //cout<<"x="<<x<<" ans"<<ans<<endl;
   return ans==0;
}

string solve(){
   string s="";
   for(int i=2000;i>=-2000;i--){
       if(check(i)){
          if(i<0){
             s=s+"(x+"+to_string(abs(i))+")";
          }else if(i==0){
             s=s+"x";
          }else{
             s=s+"(x-"+to_string(i)+")";
          }
       }
   }
   return s;
}

int main(){
    string s;
    cin>>s;
    N=split(s);
    REP(i,N){
        //cout<<parse[i]<<endl;
        C[i]=getC(parse[i]);
        A[i]=getA(parse[i]);
        //cout<<C[i]<<" "<<A[i]<<endl;
    }
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 3284
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	int N, K;
	cin >> N >> K;
	int a[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	if((N-1)%(K-1) == 0) cout << (N - 1) / (K - 1) << endl;
	else cout << (N - 1) / (K - 1) + 1 << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{
    long A, B, C;

    cin >> A >> B >> C;

    long initA = A, initB = B, initC = C;

    if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
        cout << "0" << endl;
        return 0;
    }

    unordered_map<long, unordered_map<long, unordered_set<long>>> appearedSet;
    appearedSet[A] = unordered_map<long, unordered_set<long>>();

    int count = 0;
    do
    {
        long divA = A / 2;
        long divB = B / 2;
        long divC = C / 2;
        A = divB + divC;
        B = divA + divC;
        C = divB + divA;
        count++;

        const auto BCsetIt = appearedSet.find(A);
        if (BCsetIt == appearedSet.end()) {
            // New
            appearedSet[A] = unordered_map<long, unordered_set<long>>();
        }
        const auto cList = appearedSet[A].find(B);
        if (cList == appearedSet[A].end()) {
            // New
            appearedSet[A][B] = unordered_set<long>();
        }
        const auto cIt = appearedSet[A][B].find(C);
        if (cIt != appearedSet[A][B].end()) {
            // Duplicated!
            cout << "-1" << endl;
            return 0;
        }
        appearedSet[A][B].insert(C);

    } while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0);

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())

ans = 0
c = factorization(N)  
#print(c)
for i in range(len(c)):
  A = c[i][1]
  if(c[i][0] == 1):
    n = 0
  else:
    n = int((-1+math.sqrt(1+8*A))/2 + 0.01) 
  ans += n
  
print(ans)    

Measured memory_bytes: 9504
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repk(i,k, n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500001
#define MOD 1000000007
typedef long long  ll;

using namespace std;


int max;
int cnt[MAX];

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

	int ans = 0;

	rep(i, S.length()/2) {
		//cout << S[i] << " " << S[S.length() - (i + 1)] << endl;
		if (S[i] != S[S.length() - 1 - i]) {
			ans++;
		}
	}

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

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();


		Set<Integer> adj[] = new HashSet[n+1];
		for(int i = 1; i<adj.length; i++) {
			adj[i] = new HashSet<Integer>();
		}


		for(int i = 0; i < m; i++) {
			int a = scan.nextInt();
			int b = scan.nextInt();

			adj[a].add(b);
			adj[b].add(a);
		}

		int[] dist = new int[n+1];
		dist[0] = 0;
		int[] ans = new int[n+1];

		Set<Integer> endcheck = new HashSet<>();
		endcheck.add(1);
		Set<Integer> start = new HashSet<>();
		start.add(1);

		do {
			Set<Integer> tmpst = new HashSet<>();

			Iterator<Integer> stit = start.iterator();
			while(stit.hasNext()) {
				int v1 = stit.next();

				int tdist = dist[v1] + 1;

				Iterator<Integer> adjit = adj[v1].iterator();
				while(adjit.hasNext()) {
					int v2 = adjit.next();
					if(!endcheck.contains(v2)) {
						tmpst.add(v2);
						endcheck.add(v2);

						if(dist[v2] < 1 || dist[v2] > tdist) {
							dist[v2] = tdist;
							ans[v2] = v1;
						}
					}

				}
			}

			start = tmpst;

		}while(endcheck.size() < n);

		System.out.println("Yes");
		for(int i = 2; i < n+1; i++) {
			System.out.println(ans[i]);
		}


	}

}


Measured memory_bytes: 107840
#include<iostream>
using namespace std;
int main() {
	long long int N, K,k;
	long long int i = 0;
	cin >> N >> K;
	k = K;
	if (N == K) {
		cout << 2 << endl;
		return 0;
	}
	while (1) {
		i++;
		if (N <= K) {
			if (N == K) {
				cout << i + 1 << endl;
				return 0;
			}
			cout << i << endl;
			return 0;
		}
		K = k * K;
	}
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        sb.append(sc.next());
      
        char c = sb.charAt(k-1);
      
        c = Character.toLowerCase(c);
        sb.setCharAt(k-1,c);
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 22612
n = gets.strip.to_i
ss = n.times.map { gets.strip }

count = 0
xa = 0
ba = 0
bx = 0

ss.each do |s|
    (0..s.length-2).each do |i|
        if s[i] + s[i+1] == "AB"
            count += 1
        end
    end

    if s.start_with?("B") && s.end_with?("A")
        ba += 1
        next
    end
    if s.end_with?("A")
        xa += 1
        next
    end
    if s.start_with?("B")
        bx += 1
        next
    end
end

s2 = ""
while xa > 0 || ba > 0 || bx > 0
    if s2 == ""
        if xa > 0
            s2 += "XA"
            xa -= 1
        elsif ba > 0
            s2 += "BA"
            ba -= 1
        elsif bx > 0
            s2 += "BX"
            bx -= 1
        end
    else
        if s2.end_with?("A")
            if ba > 0
                s2 += "BA"
                ba -= 1
            elsif bx > 0
                s2 += "BX"
                bx -= 1
            elsif xa > 0
                s2 += "XA"
                xa -= 1
            end
        else
            if ba > 0
                s2 += "BA"
                ba -= 1
            elsif xa > 0
                s2 += "XA"
                xa -= 1
            elsif bx > 0
                s2 += "BX"
                bx -= 1
            end
        end
        
    end
end

count2 = 0
(0..s2.length-2).each do |i|
    if s2[i] + s2[i+1] == "AB"
        count2 += 1
    end
end

puts count + count2


Measured memory_bytes: 38012
#include <bits/stdc++.h>
 using namespace std;
 int main() { 
   int n;cin>>n;
   vector<int>x(n);
   for(int i=0;i<n;i++){
     cin>>x[i];
   }
   int ans=0;
   for(int i=0;i<n-2;i++){
     if(x[i]<x[i+1]&&x[i+1]<x[i+2]){
       ans++;
     }
     else if(x[i]>x[i+1]&&x[i+1]>x[i+2]){
       ans++;
     }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}
//cout << fixed << setprecision(15);
int N, M, K, H, W, L, R, X;
string S, T;

signed main(){
  int A, B;
  cin >> N >> A >> B;
  int ans = A + B*(N-1) - A*(N-1) - B + 1;
  if(ans < 0) ans = 0;
  if(A != B && N == 1)  ans = 0;
  COUT(ans);
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
typedef long long ll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7;
using namespace std;
ll t;
ll arr[200005];
int main()
{
    ll a,b,c,d,e,f,i,j;
    d=1e17;
    cin>>c;
    for(i=0;i<5;i++)
    {
        cin>>a;
        d=min(d,a);

    }
    f=c/d;
    if(c%d==0)f--;
    cout<<f+5<<endl;


return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k,a,b;
    cin>>k;
    cin>>a>>b;
    int tmp = a/k;
    tmp *=k;
    if(tmp < a)tmp+=k;
    if(tmp <= b)
    {
        cout<<"OK"<<endl;
    }
    else cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3624
#![allow(unused_imports)]
use proconio::marker::*;
use proconio::{fastout, input};

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

    let res = solve(n);
    println!("{}", res);
}

fn solve(n: usize) -> usize {
    if n == 0 {
        1
    } else {
        0
    }
}


Measured memory_bytes: 2172
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {


	int N;
	scanf("%d", &N);

	printf("%d", N * 800 - (N / 15) * 200);






}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

static class CodeJam
{
    static bool Safe(string s)
    {
        string s3 = s.Substring(Math.Max(0, s.Length - 3));

        if (s3 == "AGC") { return false; }
        if (s3 == "GAC") { return false; }
        if (s3 == "ACG") { return false; }

        if (s.Length == 4)
        {
            if (s[0] == 'A' && s[1] == 'G' && s[3] == 'C') { return false; }
            if (s[0] == 'A' && s[2] == 'G' && s[3] == 'C') { return false; }
        }

        return true;
    }

    static long Solve(int N)
    {
        var C = new[] { 'A', 'C', 'G', 'T' };
        var dp1 = new Dictionary<string, long>();
        foreach (char c1 in C)
        {
            foreach (char c2 in C)
            {
                dp1[c1.ToString() + c2.ToString()] = 1;
            }
        }
        for (int i = 2; i < N; ++i)
        {
            var dp2 = new Dictionary<string, long>();
            foreach (var key1 in dp1.Keys)
            {
                foreach (char c in C)
                {
                    string key2 = key1 + c.ToString();
                    if (Safe(key2))
                    {
                        string key = key2.Substring(Math.Max(key2.Length - 3, 0));
                        if (!dp2.ContainsKey(key)) { dp2[key] = 0; }
                        dp2[key] = (dp2[key] + dp1[key1]) % 1000000007;
                    }
                }
            }
            dp1 = dp2;
        }
        long sum = 0;
        foreach (long value in dp1.Values) { sum = (sum + value) % 1000000007; }
        return sum;
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        Console.WriteLine(Solve(N));
    }
}


Measured memory_bytes: 15328
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  long double a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  long double A=sqrt((a-c)*(a-c)+(b-d)*(b-d)),
  B=sqrt((a-e)*(a-e)+(b-f)*(b-f)),
  C=sqrt((e-c)*(e-c)+(f-d)*(f-d)),
  s=(A+B+C)/2,
  S=sqrt(s*(s-A)*(s-B)*(s-C));
  cout<<fixed<<setprecision(16)<<S*2/(A+B+C+4*S/max({A,B,C}))<<endl;
}

Measured memory_bytes: 3720
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
using namespace std;
typedef long long int llint;
int main(){
	char a, b, c;
	cin >> a >> b >> c;
	if (a == 'a'){
		if (b == 'b'){
			if (c == 'c'){
				cout << "Yes" << endl;
			}
			else{
				cout << "No" << endl;
			}
		}
		else if (b == 'c'){
			if (c == 'b'){
				cout << "Yes" << endl;
			}
			else{
				cout << "No" << endl;
			}
		}
		else{
			cout << "No" << endl;
		}
	}
	else if (a == 'b'){
		if (b == 'a'){
			if (c == 'c'){
				cout << "Yes" << endl;
			}
			else{
				cout << "No" << endl;
			}
		}
		else if (b == 'c'){
			if (c == 'a'){
				cout << "Yes" << endl;
			}
			else{
				cout << "No" << endl;
			}
		}
		else{
			cout << "No" << endl;
		}
	}
	else if (a == 'c'){
		if (b == 'a'){
			if (c == 'b'){
				cout << "Yes" << endl;
			}
			else{
				cout << "No" << endl;
			}
		}
		else if (b == 'b'){
			if (c == 'a'){
				cout << "Yes" << endl;
			}
			else{
				cout << "No" << endl;
			}
		}
		else{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll a, b, c, ans = 0;
  scanf("%lld%lld%lld", &a, &b, &c);
  if(a == b && b == c && !(a & 1)) {
    printf("-1");
    return 0;
  }
  while(!(a & 1) && !(b & 1) && !(c & 1)) {
    ans++;
    ll ta = b + c, tb = a + c, tc = a + b;
    a = ta / 2, b = tb / 2, c = tc / 2;
  }
  printf("%lld", ans);
  return 0;
}

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int a;
    cin >> a ;
    int temp500 =0, temp5 =0, coin = 0;
    if(a !=0){
        temp500 = a/500;
        temp5 = (a-(temp500*500))/5;
        coin = temp500 * 1000 + temp5 * 5;
        cout << coin << endl;
    }else{
        cout << 0 << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n;
    cin>>n;
    long long a[n],ans=0;
    f(i,0,n){
        cin>>a[i];
        ans+=a[i];
    }
    sort(a,a+n);
    if(ans%10!=0){
        cout<<ans<<endl;
        return 0;
    }
    else{
        f(i,0,n){
            if(a[i]%10!=0){
                cout<<ans-a[i]<<endl;
                return 0;
            }
        }
    }
    cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; j < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  int A[N];
  int minus = 0;
  ll sum = 0;
  int minn = INF;
  rep(i,N) {
    cin >> A[i];
    if(A[i] < 0) {
      minus++;
      
    }
    minn = min(minn,abs(A[i]));
    sum += abs(A[i]);
  }
  if(minus % 2 == 0) {
    cout << sum << endl;
  } else {
    cout << sum - 2 * minn << endl;
  }
  return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  int ans[N];
  for(int i=1; i<=N-1; i++) ans[i] = 0;
  for(int i=1; i<=N; i++){
    for(int j=i+1; j<=N; j++){
      ans[min(abs(i-j), abs(i-X)+1+abs(j-Y))]++;
    }
  }
  for(int i=1; i<=N-1; i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define NO_DATA -1
#define MAX_COUNT 20

int main(int argc, const char * argv[]) {
    char data[MAX_COUNT+1];
    int count;
    
    for (int i = 0; i <= MAX_COUNT; i++ ) {
        data[i]='\0';
    }
    
    scanf("%s", data);
    for(count=0; data[count]!='\0'; ++count);

    for(int i=count-1;i>=0;i--) {
        printf("%c", data[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <cmath>

int N;

typedef struct {
  double x;
  double y;
} grid;

void kochCurve(grid l, grid r, int n) {
  if (n >= N)
    return;
  ++n;
  grid s = {(2.0 * l.x + r.x) / 3.0, (2.0 * l.y + r.y) / 3.0};
  grid t = {(l.x + 2.0 * r.x) / 3.0, (l.y + 2.0 * r.y) / 3.0};
  grid u;
  u.x = (r.x - l.x) / 6.0 - (r.y - l.y) * sqrt(3.0) / 6.0 + s.x;
  u.y = (r.y - l.y) / 6.0 + (r.x - l.x) * sqrt(3.0) / 6.0 + s.y;
  kochCurve(l, s, n);
  std::cout << s.x << " " << s.y << std::endl;
  kochCurve(s, u, n);
  std::cout << u.x << " " << u.y << std::endl;
  kochCurve(u, t, n);
  std::cout << t.x << " " << t.y << std::endl;
  kochCurve(t, r, n);
}

int main() {
  std::cin >> N;
  grid l = {0.0, 0.0};
  grid r = {100.0, 0.0};
  std::cout << l.x << " " << l.y << std::endl;
  kochCurve(l, r, 0);
  std::cout << r.x << " " << r.y << std::endl;
  return 0;
}

Measured memory_bytes: 3244
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int mod(unsigned long num){
	unsigned long MOD = 1.0E+9;
	MOD += 7;
	return num % MOD;
}

int main(){

	unsigned long MOD = 1.0E+9;
	MOD += 7;
	// printf("%ld\n",MOD);

	unsigned long N;
	unsigned long pow = 1;

	scanf("%ld",&N);

	for(int i=1; i<=N; i++){
		pow = pow*i;
		pow = mod(pow);
	}

	printf("%ld\n",pow);

	return 0;
}

Measured memory_bytes: 128
q = int(input())
ab = [list(map(int, input().split())) for _ in range(q)]

for a, b in ab:
    if a == b:
        print(2 * a - 2)
        continue

    l = 1
    r = 10 ** 10
    while r - l > 1:
        m = (l + r) // 2
        mx = (m + 1) // 2 * (m + 1 - (m + 1) // 2)
        if mx < a * b:
            l = m
        else:
            r = m

    print(l - 1)


Measured memory_bytes: 3188
a,b=map(int,input().split())

def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return int(a*b/gcd(a,b))

g=gcd(a,b)
def prime_factorization(n):
    #nを素因数分解して、昇順のリストを返す
    m=n
    ans = []
    p = 2

    while p<m**0.5:
        if n%p == 0:
            ans.append(p)
            while n%p==0:
                n /= p
        else:
            p += 1
            
    if n!=1:
        ans.append(int(n))
    
    return ans

l=prime_factorization(g)
print(len(l)+1)


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(ll i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

ll mp[30][30];
ll dx[4] = {1,-1,0,0},dy[4] = {0,0,1,-1};
vector<string> vs;
ll n,m;
ll bfs(P st)
{
	memset(mp,-1,sizeof(mp));
	queue<ll> que;
	mp[st.fi][st.se] = 0;
	que.push(st.fi);
	que.push(st.se);
	ll ma = -1;
	while(que.size())
	{
		ll x = que.front();
		que.pop();
		ll y = que.front();
		que.pop();
		FOR(i,0,4)
		{
			ll sx = x+dx[i];
			ll sy = y+dy[i];
			if(sx<0||sx>=n||sy<0||sy>=m||vs[sx][sy] == '#'||mp[sx][sy]!=-1)
				continue;
			mp[sx][sy] = mp[x][y]+1;
			que.push(sx);
			que.push(sy);
			ma = max(ma,mp[sx][sy]);
		}
	}
	return ma;
}
int main()
{
	cin>>n>>m;
	FOR(i,0,n)
	{
		string s;
		cin>>s;
		vs.push_back(s);
	}
	ll ma = -1;
	FOR(i,0,n)
	{
		FOR(j,0,m)
		{
			if(vs[i][j] == '#')continue;
			ma = max(ma,bfs(P(i,j)));
		}
	}
	cout<<ma<<Endl;
	return 0;
}


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

long long mini(long long a, long long b){
    return (a<b) ? a : b;
}

long long maxi(long long a, long long b){
    return (a>b) ? a : b;
}

int main(){

    int n, W;
    cin >> n >> W;
    int items[n][2];
    int suma = 0;
    for(int i = 0; i < n; i++){
        cin >> items[i][0] >> items[i][1];
        suma += items[i][1];
    }
    long long dp[suma+1];
    dp[0] = 0;
    for(int i = 1; i <= suma; i++) dp[i] = 1000000000000;
    for(int i = 0; i < n; i++){
        for(int j = suma; j >= items[i][1]; j--){
            dp[j] = mini(dp[j], dp[j-items[i][1]]+items[i][0]);
        }
    }

    long long ans = -1;
    for(int i = 0; i <= suma; i++){
        if(dp[i]<=W) ans = maxi(ans,i);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int n,a,b;
int h[SIZE];

bool check(int c){
  ll h2[SIZE];

  for(int i=0;i<n;i++){
    h2[i] = h[i];
  }

  for(int i=0;i<n;i++){
    h2[i] = max(0LL, h2[i] - (ll)b*c);
  }

  ll t = 0;
  
  for(int i=0;i<n;i++){
    t += (h2[i] + (a-b) - 1)/(a-b);
  }

  return c >= t;
}

int main(){
  
  scanf("%d%d%d",&n,&a,&b);

  for(int i=0;i<n;i++){
    scanf("%d",h+i);
  }

  int l=0,r=1000000000;

  while(l<r){
    int mid = (l+r)/2;

    if(check(mid)){
      r = mid;
    }else{
      l = mid+1;
    }
  }
  
  cout << l << endl;
  
  return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;

            str = Console.ReadLine ().Split (' ');
            int a = int.Parse (str[0]);
            int b = int.Parse (str[1]);

            Console.WriteLine (a * b + " " + 2 * (a + b));
        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}


Measured memory_bytes: 15904
lines = readlines.map(&:chomp).map{ |line| line.split(' ') }
lines.each do |a,op,b|
    a = a.to_i
    b = b.to_i
    if op == "+" then
        puts a+b
    elsif op == "-" then
        puts a-b
    elsif op == "*" then
        puts a*b
    elsif op == "/" then
        puts a/b
    elsif op == "?" then
        break
    end
end


Measured memory_bytes: 6876
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    if(s[0] == 'W' || s.back() == 'W'){
        cout << 0 << endl;
        return 0;
    }

    n *= 2;

    ll ans = 1, tmp = 1;
    for(int i = 1; i < n; i++){
        if(s[i] == 'W'){
            if(tmp % 2 == 0){
                ans *= tmp;
                ans %= mod;
                tmp--; 
            }else{
                tmp++;
            }
        }else{
            if(tmp % 2 == 1){
                ans *= tmp;
                ans %= mod;
                tmp--;
            }else{
                tmp++;
            }
        }
    }
    ll fact = 1;
    for(ll i = 1; i <= n/2; i++)    fact = fact*i%mod;
    if(tmp != 0)    cout << 0 << endl;
    else            cout << ans*fact%mod << endl;
    return 0;
}

Measured memory_bytes: 640
//Beginner

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int n,r;cin>>n>>r;
    if(n>=10)cout<<r<<nnn;
    else cout<<r+(100*(10-n))<<nnn;
    return 0;
}

Measured memory_bytes: 256
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=100010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,Q;
int head[N],maxE; struct Edge { int nxt,to,rdis; }e[N<<1];
inline void Add(int u,int v,int w) { e[++maxE].nxt=head[u]; head[u]=maxE; e[maxE].to=v; }
signed main()
{
    int x=read();
    printf("%lld\n",x^1ll);
    return 0;
}

Measured memory_bytes: 3760
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  return n-1>>1;
}

Measured memory_bytes: 22076