akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define M 1000000007
#define SI(x) scanf("%d", &x)
#define PI(x) printf("%d\n", x)
#define SL(x) scanf("%I64d", &x)
#define PL(x) printf("%I64d\n", x)
#define PB push_back
#define mp make_pair

using namespace std;

map< pair<ll, ll>, ll> m;
ll knapSack(ll W, ll wt[], ll val[], int n)
{
   // Base Case
   if (n == 0 || W == 0)
       return m[mp(W, n)] = 0;

   // If weight of the nth item is more than Knapsack capacity W, then
   // this item cannot be included in the optimal solution
   if( m[mp(W, n)] ) return m[mp(W, n)];
   if (wt[n-1] > W)
       return m[mp(W, n)] = knapSack(W, wt, val, n-1);

   // Return the maximum of two cases:
   // (1) nth item included
   // (2) not included
   else return m[mp(W, n)] = max( val[n-1] + knapSack(W-wt[n-1], wt, val, n-1),
                    knapSack(W, wt, val, n-1)
                  );
}

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

    ll wt[n];
    ll val[n];

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

    cout << knapSack(w, wt, val, n) << endl;
}


Measured memory_bytes: 6400
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <iomanip>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

void draw(int h, int w) {
    if(h == 0 || w == 0) {cout << endl; return;}
    F(k, 0, h){
      string width = "";
      F(i, 0, w){
          if((k + i)%2 == 0)
              width += '#';
          else
              width += '.';
      }
      cout << width << endl;
    }
    cout << endl;
}

int main() {
    vvi data;
    while(1) {
        int h,w;
        vi vec;
        cin >> h >> w;
        if(h == 0 && w == 0)break;
        vec.push_back(h);
        vec.push_back(w);
        data.push_back(vec);
    }

    F(i, 0, data.size()){
        draw(data[i][0], data[i][1]);
    }

    return 0;
}



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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1000000000 + 7;
const int N = 1e6 + 5;

typedef long long ll;

string s, ans;

int main()
{
      cin >> s;

      for(int i = 0; i < s.size() - 8; i ++)
            ans += s[i];

      cout << ans << endl;
}


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

int main()
{
  int n;
  long long z, w, a[2000];
  cin >> n >> z >> w;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  if(n == 1) cout << labs(a[0] - w) << endl;
  else{
    if(labs(a[n - 1] - w) > labs(a[n - 2] - a[n - 1])){
      cout << labs(a[n - 1] - w) << endl;
    } else {
      cout << labs(a[n - 2] - a[n - 1]) << endl;
    }
  }

  return 0;
}

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

using namespace std;

int main() {
	long long int a, b, v, w, t;

	cin >> a >> v >> b >> w >> t;

	bool ans = true;

	if (a < b) {
		if (a + t*v >= b + w*t) {
			ans = true;
		} else {
			ans = false;
		}
	} else if (a > b) {
		if (a - v*t <= b - w*t) {
			ans = true;
		} else {
			ans = false;
		}
	}

	if (ans) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}

	return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<memory.h>
#include<cmath>
#include<set>
#include<queue>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long LL;
struct IO_Tp
{
    inline bool is(const char x)
    {
        return x>='0'&&x<='9';
    }
    inline IO_Tp& operator>>(int &x)
    {
        x=0;
        static char ch;
        bool neg=false;
        while(ch=getchar(),!is(ch))neg=ch=='-';
        do x=x*10+(ch&15); while(ch=getchar(),is(ch));
        if(neg)x=-x;
        return *this;
    }
    inline IO_Tp& operator>>(long long &x)
    {
        x=0;
        static char ch;
        bool neg=false;
        while(ch=getchar(),!is(ch))neg=ch=='-';
        do x=x*10+(ch&15); while(ch=getchar(),is(ch));
        if(neg)x=-x;
        return *this;
    }
    inline void put(int x)
    {
        if(x>9)put(x/10);
        putchar(x%10+'0');
    }
    inline IO_Tp& operator<<(int x)
    {
        if(x<0)putchar('-'),x=-x;
        put(x);
        putchar('\n');
        return *this;
    }
    inline IO_Tp& operator<<(LL x)
    {
        if(x<0)putchar('-'),x=-x;
        put(x);
        putchar('\n');
        return *this;
    }
}IO;
int n;
LL pre[200005],suc[200005],a[200005],s1[200005],s2[200005],s3[200005],s4[200005];
int main()
{
	IO>>n;
	rep(i,1,n)IO>>a[i];
	rep(i,1,n)pre[i]=pre[i-1]+a[i]; 
	//rep(i,1,n)IO<<pre[i];
	rep(i,1,n)suc[i]=suc[i-1]+a[n+1-i];
	//rep(i,1,n)IO<<suc[i];
	for(int i=2;i<=n-2;i++)
	{
		LL sum=(pre[i]+1)/2;
		int k=lower_bound(pre+1,pre+i,sum)-pre;
		if(k==i){s1[i]=pre[k-1];s2[i]=a[i];continue;}
		LL d1=pre[i]-pre[k],d2=pre[k];
		if(k!=1)
		{
			LL d3=pre[k-1],d4=pre[i]-pre[k-1];
			if(abs(d2-d1)>abs(d4-d3))d1=d3,d2=d4;
		}
		s1[i]=d1;s2[i]=d2;
	}
	for(int i=2;i<=n-2;i++)
	{
		LL sum=(suc[i]+1)/2;
		int k=lower_bound(suc+1,suc+i,sum)-suc;
		if(k==i){s3[i]=suc[k-1];s4[i]=suc[i]-s3[i];continue;}
		LL d1=suc[i]-suc[k],d2=suc[k];
		if(k!=1)
		{
			LL d3=suc[k-1],d4=suc[i]-suc[k-1];
			if(abs(d2-d1)>abs(d4-d3))d1=d3,d2=d4;
		}
		s3[i]=d1;s4[i]=d2;
	}
	LL mini=1e9;
	for(int i=2;i<=n-2;i++)
	{
		LL maxi=max(s1[i],max(s2[i],max(s3[n-i],s4[n-i])));
		LL minii=min(s1[i],min(s2[i],min(s3[n-i],s4[n-i])));
		if(maxi-minii<mini)mini=max(s2[i],s4[n-i])-min(s1[i],s3[n-i]);
	}
	IO<<mini;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll a, b, c, d, ma = -100000000000000001;
  cin >> a >>  b >>  c >>  d;
  if((a >= 0) && (c >= 0)) ma = b * d;
  else if((b <= 0) && (d <= 0)) ma = a * c;
  else if((a >= 0) && (d <= 0)) ma = a * d;
  else if((b <= 0) && (c >= 0)) ma = b * c;
  else if((a <= 0) && (b >= 0) && (c >= 0)) ma = b * d;
  else if((a >= 0) && (c <= 0) && (d >= 0)) ma = b * d;
  else if((a <= 0) && (b >= 0) && (d <= 0)) ma = a * c;
  else if((b <= 0) && (c <= 0) && (d >= 0)) ma = a * c;
  else {
    if(a * c < b * d) ma = b * d;
    else ma = a * c;
  }
  cout << ma << endl;
}

Measured memory_bytes: 3644
def main():
    N = int(input())
    C = input()
    l, r = 0, N - 1
    c = 0
    while True:
        while l < r and C[l] == 'R':
            l += 1
        while l < r and C[r] == 'W':
            r -= 1
        if l >= r:
            break
        c += 1
        l += 1
        r -= 1

    return c

print(main())


Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,x;
  cin >> n >> x;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  mat dp(n,vec(x+1,0));
  for(ll i=0;i<=x;i++)  dp[0][i]=i%a[0];
  for(ll i=1;i<n;i++) {
    for(ll j=0;j<x+1;j++) {
      dp[i][j]=(dp[i-1][j%a[i]]+i*dp[i-1][j]%mod)%mod;
    }
  }
  cout << dp[n-1][x] << endl;
}

Measured memory_bytes: 160792
import math
s = input()
count = 1
slist = list(s)
strlen = len(s)
count = None
if strlen % 2 == 1:
    count = math.ceil(strlen/2)
    center = slist[math.floor(strlen/2)]
    for i in range(math.floor(strlen/2)):
        if center == slist[math.floor(strlen/2)- i - 1] and center == slist[math.ceil(strlen/2)+i]:
            count +=1
        else:
            break
else:
    count = strlen / 2
    center = slist[int(strlen/2)]
    for i in range(int(strlen/2)):
        if center == slist[int(strlen/2)+i] and center == slist[int(strlen/2) - 1 - i]:
            count += 1
        else:
            break
print(int(count))


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

namespace cShaprTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split('/');
            var year = int.Parse(input[0]);
            int month = int.Parse(input[1]);
            int day = int.Parse(input[2]);

           var inputDate = new DateTime(year, month, day);
            var compareDate = new DateTime(2019, 4, 30);

            int result = DateTime.Compare(inputDate, compareDate);

            if (result <= 0)
                Console.WriteLine("Heisei");
            else
                Console.WriteLine("TBD");
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
typedef long long ll;


int main(){
  int n;
  cin >> n;
  int v[n];
  rep(i,n){
    cin >> v[i];
  }
  map<int,int> even;
  map<int,int> odd;
  rep(i,n){
    if(i%2){
      odd[v[i]]++;
    }else{
      even[v[i]]++;
    }
  }
  vector<pair<int,int>> oddArray;
  vector<pair<int,int>> evenArray;

  for(auto map_ite = odd.begin(); map_ite!= odd.end();map_ite++){
    oddArray.push_back(make_pair(map_ite->second,map_ite->first));
  }

  for(auto map_ite = even.begin(); map_ite!= even.end();map_ite++){
    evenArray.push_back(make_pair(map_ite->second,map_ite->first));
  }

  sort(all(oddArray));
  sort(all(evenArray));
  int oddI=oddArray.size()-1,evenI = evenArray.size()-1;
  int ans = 1e9;
    if(oddArray[oddI].second != evenArray[evenI].second){
      cout << n - oddArray[oddI].first - evenArray[evenI].first << endl;
      return 0;
    }else{
      if(oddI-1 >= 0){
        ans = min(ans,n - oddArray[oddI-1].first - evenArray[evenI].first);
      }
      if(evenI-1 >= 0){
        ans = min(ans,n - oddArray[oddI].first - evenArray[evenI-1].first);
      }
    }

  ans = min(ans,n - oddArray[oddI].first);
  ans = min(ans,n - evenArray[evenI].first);
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}


const ll MOD = 1000003;
const int SZ = 2123456;
ll inv[SZ];
ll fact[SZ];
ll fact_inv[SZ];
ll choose(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}
ll mod_pow(ll a, ll b, ll p) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}

ll mod_inv(ll a, ll p) {
  return mod_pow(a % p, p - 2, p);
}

ll easy(ll a, ll n) {
  if (n >= MOD) return 0;
  ll s = a % MOD;
  ll t = (a + n - 1 + MOD) % MOD;
  if (s > t) return 0;
  if (s == 0) return 0;
  return fact[t] * fact_inv[s-1] % MOD;
}

int main2() {
  ll x = nextInt();
  ll d = nextInt();
  ll n = nextInt();
  
  if (d == 0) {
     cout << mod_pow(x, n, MOD) << endl;
     return 0; 
  }
  ll ans = easy(x * inv[d] % MOD, n);

  ans *= mod_pow(d, n, MOD);
  ans %= MOD;

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

int main() {

  inv[1] = 1;
  for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  fact[0] = 1;
  for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
  fact_inv[0] = 1;
  for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;

  int Q = nextInt();
  REP(q, Q)
    main2();
  return 0;
}


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

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

#define INF 1123456789
int N;
vector<int> T, A;

void init()
{
	cin >> N;
	rep(i, N) {
		T.PB(GET<int>());
	}
	rep(i, N) {
		A.PB(GET<int>());
	}
}

int calc()
{
	vector<int> v(N);
	v[0] = -T[0];
	reps(i, 1, N) {
		if (T[i] != T[i-1]) {
			v[i] = -T[i];
		} else {
			v[i] = T[i];
		}
	}
	if (v.back() < 0 && A.back() != -v.back() || v.back() > 0 && A.back() > v.back()) return 0;
	v.back() = -A.back();
	rrep(i, N-1) {
		if (A[i] != A[i+1]) {
			if (v[i] < 0 && A[i] != -v[i] || v[i] > 0 && A[i] > v[i]) {
				return 0;
			}
			v[i] = -A[i];
		}
		else {
			if (v[i] < 0 && A[i] < -v[i]) {
				return 0;
			}
			chmin(v[i], A[i]);
		}
	}
	int res = 1;
	rep(i, N) {
		if (v[i] > 0) res *= v[i];
		res %= MOD;
	}
	return res;
}

void solve()
{
	cout << calc() << endl;
}





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

int main() {
  int n,m,c,max;
  string e;
  max = 0;
  cin >> n;
  vector<string> r(n);
  for(int i = 0; i < n; i++) {
    cin >> r.at(i);
  }
  cin >> m;
  vector<string> b(m);
  for(int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  for(int i = 0; i < n; i++) {
    c = 0;
    e = r.at(i);
    for(int j = 0; j < n; j++) {
      if(r.at(j) == e) {
        c++;
      }
    }
    for(int t = 0; t < m; t++) {
      if(b.at(t) == e) {
        c--;
      }
    }
    if(max < c) {
      max = c;
    }
  }
  cout << max << endl;   
}

Measured memory_bytes: 3628
#
# abc087 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5
3 2 2 4 1
1 2 2 2 1"""
        output = """14"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 1 1 1
1 1 1 1"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """7
3 3 4 5 4 5 3
5 3 4 4 2 3 2"""
        output = """29"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """1
2
3"""
        output = """5"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(2)]

    ans = 0
    if N == 1:
        ans = A[0][0]+A[1][0]
    else:
        for i in range(N):
            ans = max(ans, sum(A[0])+A[1][N-1],
                      sum(A[0][:N-1-i])+sum(A[1][N-1-i-1:]))

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16144
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
		for(int i=0;i<x[2];i++){
			int n=i%2;
			if(x[n]%2==1)x[n]--;
			x[n^1]+=x[n]/2;x[n]/=2;
		}
		Console.WriteLine(x[0]+" "+x[1]);
	}
}

Measured memory_bytes: 13396
#include <stdio.h>
int main () {
	int a,b,c;
	scanf("%d %d %d", &a,&b,&c);
	if(a==b){
		printf("%d\n",c);
	}else if(b==c){
		printf("%d\n",a);
	}else{
		printf("%d\n",b);
	}
	
}

Measured memory_bytes: 128
package main

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

func main() {
	scan_init()
	a := scanInt()
	sum := a + int(math.Pow(float64(a),2)) + int(math.Pow(float64(a),3))
	fmt.Println(sum)
}
var sc = bufio.NewScanner(os.Stdin)
func scan_init () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
func scan () string{
 sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1772
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){return *(ll *)a - *(ll *)b;}

int main(void){
    ll n,k,i,ans=0;
    scanf("%lld%lld",&n,&k);
    ll h[n];
    for(i=0;i<n;i++){
        scanf("%lld",&h[i]);
    }
    qsort(h,n,sizeof(ll),compare);
    for(i=0;i<n-k;i++){
        ans+=h[i];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3324
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

typedef double ld;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const ll MOD = 1e9 + 7;

int main(){ _

	ll N;
	cin >> N;
	
	vector<int> table((int)1e3 + 10, 0);

	for(int i = 2; i <= N; i++){
	
		int x = i;
		for(int j = 2; j*j <= x; j++){
			while(!(x % j)){
				table[j]++;
				x/=j;
			}
		}
		if(x != 1) table[x]++;
	
	}

	ll ans = 1;
	for(int i = 0; i < (1e3 + 10); i++){
		if(!table[i]) continue;
		ans = (ans * (table[i] + 1)) % MOD;
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
    while (true) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int ans = 0;
        for (int i = 1; i <= n - 2; ++i) {
            for (int j = i + 1; j <= n - 1; ++j) {
                for (int k = j + 1; k <= n; ++k) {
                    if (i + j + k == x) {
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}



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

int main() {
	int a, b;
	cin>>a>>b;
	if((a%2==0&&b%2==0)||(a%2==1&&b%2==1)) cout<<(a+b)/2<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int K = GetInt();
		long[] a = GetLongs(N);

		long[] csum = new long[N + 1];
		for(int i = 0; i < N; i++)
			csum[i + 1] = csum[i] + a[i];

		var list = new List<long>();
		for(int l = 1; l <= N; l++)
			for(int r = l; r <= N; r++)
				list.Add(csum[r] - csum[l - 1]);

		list.Sort();
		list.Reverse();

		long ans = 0;		
		bool[] removed = new bool[list.Count];
		for(int i = 42; i >= 0; i--)
		{
			int cnt = 0;
			for(int j = 0; j < list.Count; j++)
			{
				if(removed[j])
					continue;

				if(contain(list[j], i))
					cnt++;				
			}

			if(cnt >= K)
			{
				ans |= (1L << i);
				for(int j = 0; j < list.Count; j++)
				{
					if(removed[j])
						continue;

					if(!contain(list[j], i))
						removed[j] = true;
				}
			}
		}

		Console.WriteLine(ans);
	}

	private bool contain(long s, int x) => ((s >> x) & 1) == 1;
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 21984
n,m = map(int,input().split())
l = []
for i in range(n):
    a,b = map(int, input().split())
    l.append((a,b))
ans = 0
l.sort()
for a,b in l:
  if b >= m:
    ans += a * m
    break
  else:
    ans += a*b
    m -= b
print(ans)

Measured memory_bytes: 16892
import sys
input = sys.stdin.readline

def main():
    t1 = "dream"[::-1]
    t2 = "dreamer"[::-1]
    t3 = "erase"[::-1]
    t4 = "eraser"[::-1]

    s = input().strip()[::-1]

    while True:
        ok = False
        if len(s) >= 7:
            if s[:7] == t2:
                s = s[7:]
                ok = True
        if len(s) >= 6:
            if s[:6] == t4:
                s = s[6:]
                ok = True
        if len(s) >= 5:
            if s[:5] == t1 or s[:5] == t3:
                s = s[5:]
                ok = True
        
        if len(s) < 5 or not ok:
            break
    
    if s != "":
        print("NO")
    else:
        print("YES")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

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

      map < ll ,ll > mp;
      ll sum = 0;

      for (int i=0 ; i<n ; i++){
            ll a;
            cin >> a;

            mp[a]++;
            sum+=a;
      }

      ll q;
      cin >> q;

      while(q--){
            ll b,c;
            cin >> b >> c;

            ll cnt = mp[b];

            mp[c]+=cnt;
            mp[b] = 0;

            sum-=cnt*b;
            sum+=cnt*c;

            cout << sum << endl;
      }

      return 0;
}



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

int main() {
    int n,q;
    string s;
    cin >> n >> q >> s;
    vector<int> ans (n);
    int count = 0;
    ans.at(0) = 0;
    for(int i=0; i<n-1; i++){
        if(s.at(i) == 'A' && s.at(i+1) == 'C') count++;
        ans.at(i+1) = count;
    }
    vector<vector<int>> lr (q);
    for(int i=0; i<q; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        lr.at(i).push_back(a);
        lr.at(i).push_back(b);
    }
    for(int i=0; i<q; i++){
        cout << ans.at(lr.at(i).at(1)) - ans.at(lr.at(i).at(0)) << endl;
    }
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

bool f(int i) {
	ll t = i,rev=0;
	while(i){
		rev=rev*10+i%10;
		i/=10;
	}
	
	return rev==t;

}

void solve() {
	ll a,b;
	cin>>a>>b;
	ll ans =0;
	for(int i=a;i<=b;i++)
		ans+=(ll)f(i);
	cout<<ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	//ll t;cin>>t;while(t--)
	solve();

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	vector<int>num(n); rep(i, n)num[i] = 1;
	vector<bool>red(n); red[0] = true;
	rep(i, m) {
		int x, y; cin >> x >> y; x--; y--;
		if (red[x])red[y] = true;
		num[x]--; num[y]++;
		if (num[x] == 0)red[x] = false;
	}
	int ans = 0;
	rep(i, n) {
		if (red[i])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>

using namespace std;

int main(){

	int n,k;
	vector<int> vec;
	cin >> n >> k;
	for(int i=0;i<k;i++){
		int a;
		cin >> a;
		vec.push_back(a);
	}
	while(n<100000){
		int temp = n;
		int flag = true;
		while(temp != 0){
			int num1 = temp%10;
			for(int i=0;i<k;i++){
				if(num1 == vec[i]){
					flag = false;
					break;
				}
			}
			if(flag==false) break;
			temp/=10;
		}
		if(flag==true) break;
		n++;
	}
	cout << n << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int N;

bool solve(vector<int> &H, vector<int> &W){
  REP(i, N) REP(j, N) if(W[j] > 0) { W[j]--; H[i]--; }
  REP(i, N) if(H[i] != 0) return 0;
  return 1;
}

int main() {
  while(cin >>N && N){
    vector<int> H(N), W(N);
    REP(i, N) cin >>H[i];
    REP(i, N) cin >>W[i];
    SORT(H); REVERSE(H);
    cout <<(solve(H, W) ? "Yes" : "No") <<endl;
  }
  return 0;
}

Measured memory_bytes: 1284
array = []
suum = 0
while True:
    n = int(input())
    if n == 0:
        break
    array.append(n)
for i in range(len(array)):
    for i2 in range(len(str(array[i]))):
        suum += int(str(array[i])[i2])
    print(suum)
    suum = 0

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s; cin >> s;
  int n = SZ(s);
  map<ll, int> mp;
  mp[0] = 0;
  ll now = 0;
  REP(i, n) {
    now ^= 1ll << (s[i] - 'a');
    //cout << bitset<26>(now) << endl;
    int mi = mp.find(now) != mp.end() ? mp[now] : INF;
    REP(j, 26) {
      ll tmp = now ^ (1ll<<j);
      if(mp.find(tmp) != mp.end()) chmin(mi, mp[tmp] + 1);
    }
    //cout << mi << endl;
    mp[now] = mi;
  }

  cout << max(1, mp[now]) << endl;


}
























Measured memory_bytes: 12948
def gcd(a,b):
    while b != 0:
        temp = b
        b = a%b
        a = temp
    return a
A,B,C,D = map(int,input().split())
if C >=D:
    lc = int(C*D/gcd(C,D))
else: lc = int(C*D/gcd(D,C))
A = A-1
A_n = A - (A//C + A//D - A//lc)
B_n = B - (B//C + B//D - B//lc)
print(int(B_n-A_n))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
using namespace std;
static const int MAX = 100;

int main(){
    int n, A[MAX], ans = 0, t;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];

    int flag = 1;

    while (flag){
        flag = 0;
        for (int j = n-1; j > 0; j--){
            if(A[j] < A[j-1]){
                t = A[j];
                A[j] = A[j-1];
                A[j-1] = t;
                flag = 1;
                ans++;
            }
        }
    }

    for (int k = 0; k < n; k++){
        cout << A[k];
        if(k < n-1){
            cout << " ";
        }else{
        cout << endl;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3100
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;


public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        int S = scan.nextInt();
        int next = S+1;
        if (S == 1000000000) {
            next = S - 1;
        }
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < K; i++) {
            list.add(S);
        }
        for (int i = K; i < N; i++) {
            list.add(next);
        }
        System.out.println(list.stream().map(i -> i.toString()).collect(Collectors.joining(" ")));
        return;
    }
}


Measured memory_bytes: 46692
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;



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

	cin >> N;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	map<long long int, int>m;
	for (int i = 0; i < N; i++)m[v[i]] = i & 1;
	sort(v.begin(), v.end());
	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += (i & 1) != m[v[i]];
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int K,S;
  cin >> K >> S;
  int count = 0;
  for(int x = 0; x <= K; x++){
    for(int y = 0; y <= K; y++){
      int z = S-x-y;
      if(z >= 0 && z <= K){
          count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3500
N = int(input())
data = list(map(int,input().split()))
dataSum = sum(data)
min = 10000
for i in range(N):
    sumT = sum(data[0:i + 1])
    if abs(sumT * 2 - dataSum)  < min:
        min = abs(sumT * 2 - dataSum)
    else:
        print (min)
        break


Measured memory_bytes: 2940
A, B = map(int, input().split())

from collections import defaultdict
def factorization(n):
    d = defaultdict(int)
    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
            d[i] = cnt
    if temp != 1:
        d[temp] = 1
    if len(d) == 0:
        d[n] = 1
    return d
ans = 0
d = factorization(A)
d[1] = 1
for x in d.keys():
    if B%x == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9648
def main():
    N = int(input())
    heights = list(map(int, input().split()))

    heights = heights[::-1]
    res = True
    for i in range(N - 1):
        if heights[i] == heights[i + 1] - 1:
            heights[i + 1] -= 1
        elif heights[i] < heights[i + 1]:
            res = False
            break

    print('Yes' if res else 'No')


if __name__ == '__main__':
    main()


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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main(void){
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  REP(i, M){
    cin >> s[i] >> c[i];
  }

  vector<int> flag(N);
  REP(i, N){flag[i] = 10;}

  bool res = true;
  REP(i, M){
    int tmp = s[i] - 1;
    int conf = flag[tmp];
    if (conf == 10){flag[tmp] = c[i];}
    else{
      if (conf != c[i]){res = false;flag[tmp] = c[i];}
    }
  }
  REP(i, M){
    if (s[i] == 1 and c[i] == 0 and N != 1){res = false;}
  }

  int ans=0;
  if (!res) ans = -1;
  else{
    REP(i, N){
      int val = pow(10, N-i-1);
      int tmp = flag[i];
      if (tmp == 10){
        if (i == 0 and N >= 2){tmp = 1;}
        else {tmp = 0;}}
      ans += tmp * val;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

ll A, B, res;
bool a[40], b[40];

int main() {
	cin >> A >> B;
	--A;
	a[0] = (A & 1) ^ !(A & 2);
	b[0] = (B & 1) ^ !(B & 2);
	for (int i = 1; i != 40; ++i) {
		a[i] = (!(A & 1) && (A&(1ll << i)));
		b[i] = (!(B & 1) && (B&(1ll << i)));
	}
	for (int i = 0; i != 40; ++i) {
		if (a[i] ^ b[i]) {
			res += 1ll << i;
		}
	}
	cout << res << endl;
	return 0;
}

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

int main()
{
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=k+1;i<=n;i++){
        if(a[i]>a[i-k]) printf("Yes\n");
        else printf("No\n");
    }
}


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

namespace CompetitiveProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }

        static void MainStream()
        {
            string[] a_b_c = Console.ReadLine().Split(' ');
            int a = int.Parse(a_b_c[0]);
            int b = int.Parse(a_b_c[1]);
            int c = int.Parse(a_b_c[2]);

            int count = b / a;

            if(count<c)
            {
                Console.WriteLine(count);
            }
            else
            {
                Console.WriteLine(c);
            }
        }



    }
}


Measured memory_bytes: 11092
import queue

class BreadthFirstSearch:
    def __init__(self, h, w, start_xy, board):
        self.h, self.w = h, w
        (self.sx, self.sy) = start_xy
        self.board = board
        self.hist = [[False] * w for i in range(h)]

    def get_step(self, wall="#"):
        '''
        区切り文字を指定する(デフォルトは#)
        ゴールに着くまでの最短距離を出力
        ゴールにたどり着かない場合は0を出力
        '''
        q = queue.Queue()
        q.put((self.sx, self.sy))
        self.hist[self.sy][self.sx] = True
        step = 0
        count = 1
        next_count = 1
        ans = 0
        # キューが空になるまで
        while not q.empty():
            x, y = q.get()
            count -= 1
            if count == 0:
                step += 1
                count = next_count
                next_count = 0
            # ゴールにたどり着くまでのステップ
            for (i, j) in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                # 範囲内か
                if not(0 <= x+i <= w - 1) or not(0 <= y+j <= h - 1):
                    continue
                # 壁では無いか
                if self.board[y+j][x+i] == wall:
                    continue
                # 既に通ったところか
                if self.hist[y+j][x+i]:
                    continue
                # 通った印をつける
                self.hist[y+j][x+i] = True
                q.put((x+i, y+j))
                next_count += 1
        return step


# 図の形
h, w = map(int, input().split())
# ボードの読み込み
board = [[i for i in list(str(input()))] for i in range(h)]
# スタート地点
ans_ = []
for s_i in range(h):
    for s_j in range(w):
        if board[s_i][s_j] == "#":
            continue
        s_xy = (s_j, s_i)
        bfs = BreadthFirstSearch(h, w, s_xy, board[:])
        ans = bfs.get_step()
        ans_.append(ans)
print(max(ans_) - 1)


Measured memory_bytes: 58344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
ll mod=1000000007;
ll NMAX = 1000007;

ll gcd(ll a, ll b){
  ll r=a%b;
  while(r>0){
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

vector<ll> eratosthenes(ll n){
    vector<ll> list(n+1,1);
    for(ll i=0;i<=n;i++){
        list.at(i) = 1;
    }
    ll upper = ceil(sqrt(n));
    for(ll i=2;i<=upper;i++){
        if(list.at(i) == 1){
          	list.at(i) = i;
            ll cnt=2*i;
            while(cnt <= n){
              	if(list.at(cnt) == 1){
	                list.at(cnt)=i;
                }
                cnt += i;
            }
        }
    }

    return(list);
}

int main() {
  ll n;
  vector<ll> a(NMAX);
  const vector<ll> list = eratosthenes(NMAX);
  cin >> n;
  //c[i]:数列aの中でiが出現した回数
  vector<ll> c(NMAX,0);
  rep(i,n){
    cin >> a[i];
    c[a[i]]++;
  }
  
  if(n == 2){
    if(gcd(a[0],a[1]) != 1){
      cout << "not coprime" << endl;
    }else{
      cout << "pairwise coprime" << endl;
    }
    return(0);
  }
  
  bool pairwise=true;
  for(ll i=2;i<NMAX;i++){
    ll cnt=0;
    //iの倍数が何回現れるか
    for(ll j=i;j<NMAX;j+=i){
      cnt += c[j];
    }
    if(cnt > 1) pairwise=false;
  }
  
  if(pairwise){
    cout << "pairwise coprime" << endl;
    return(0);
  }
  
  ll g=gcd(a[0],a[1]);
  //cout << g << endl;
  
  for(ll i=2;i<n;i++){
    g = gcd(a[i],g);
    //cout << g << endl;
  }

  if(g == 1){
    cout << "setwise coprime" << endl;
  }else{
    cout << "not coprime" << endl;
  }
  
  return(0);
}


Measured memory_bytes: 26848
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<double >    vecd;
typedef vector<vector<int> >  vec2int;
typedef vector<vector<double> >  vec2d;
typedef vector<ll >     vecll;
typedef vector<string > vecstr;
typedef vector<bool > vecbool;
typedef vector<vector< bool > > vec2bool;
typedef vector<bool > vecbool;
////////////////////////////////////////////////
int main()
{
  string s;cin >>s;
  int n = s.size();
  vecstr v;
  string tmp = "";
  REP(i,n){
    if(i < n - 1 && s.substr(i,2) == "BC"){
      tmp += "D";
      i++;
      if(i == n - 1){
	v.push_back(tmp);
      }
    }else if(s[i] == 'B'||s[i] == 'C'){
      if(tmp.size() > 0){
	v.push_back(tmp);
      }
      tmp = "";
    }else{
      tmp += "A";
      if(i == n - 1){
	v.push_back(tmp);
      }
    }// else{
    //   cout << "ERROR"  << s[i] << endl;
    // }
    // cout << i << " " <<s[i] << " " <<tmp << endl;
  }
  // REPvec(itr, v){
  //   cout << *itr << endl;
  // }
  ll ans = 0;
  REPvec(itr, v){
    string ss = *itr;
    int m = ss.size();
    vecint na(m,0);
    if(ss[0] == 'A'){
      na[0] = 1;
    }
    REP(i,m - 1){
      if(ss[i + 1] == 'A'){
	na[i + 1] = na[i] + 1;
      }else{
	na[i + 1] = na[i];
      }
    }
    // cout << "ss :"<< ss << endl;
    // REP(i,m){
    //   cout << na[i] << endl;
    // }
    ///////////////
    REP(i,m){
      if(ss[i] == 'D'){
	ans += (ll)na[i];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3196
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las
    

main = do
    (n, k) <- readTuple2
    print $ n - k + 1


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

int main() {
    int K,S; cin>>K>>S;
    int ans =0;
    for(int x=0;x<=K;x++){
        for(int y=x;y<=K;y++){
            for(int z=y;z<=K;z++){
                if(x+y+z==S){
                    if(x==y&&x==z)ans+=1;
                    else if(x!=z && x!=y && z!=y)ans+=6;
                    else ans +=3;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cctype>

using namespace std;
int main(){
	char ch;
	int cnt[26]={};
	
	while(cin >> ch){
		ch = tolower(ch);
		if(isalpha(ch)){
			cnt[ch-'a']++;
		}
	}
	
	for(int i = 0;i<26;i++){
		printf("%c : %d\n",i+'a',cnt[i]);
	}
	
	return 0;
}

Measured memory_bytes: 1128
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
int main()
{
	string s;
	int a,b;
	cin>>a>>b;
	cin>>s;
	for(int i=1;i<s.size();i++)
	{
		if(i==a)
		{
			if(s[i]!='-')
			{
			cout<<"No";
			return 0;
		    }
		}
		else if(!isdigit(s[i]))
		{
		cout<<"No";
		return 0;
	    }
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int yaku = 0;

		while(a<=b){
			
			if (c % a == 0) {
				yaku++;
			}

			a++;
		}
		System.out.println(yaku);
	}

}



Measured memory_bytes: 26376
#include<bits/stdc++.h>
#define LL long long
#define M 1000005 
using namespace std;
const int P=1e9+7;
int main(){
	int A[100],n;
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	int ans=0;
	for(int i=2;i<n;i++)
		ans+=(A[i-1]<A[i]&&A[i]<A[i+1])||(A[i+1]<A[i]&&A[i]<A[i-1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256