akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vp a;

int main(){
	cin>>n;
	a=vp(2*n);
	for(int i=0;i<n;i++){
		int A,B;
		cin>>A>>B;
		a[i]={A,i};
		a[i+n]={B,i+n};
	}
	sort(a.begin(),a.end());
	vi b(n);
	ll res=0,B=0;
	for(int i=0;i<n;i++) res+=a[i].first;
	for(int i=n;i<2*n;i++){
		int I=a[i].second;
		if(I<n) b[I]++;
		else b[I-n]--;
	}
	for(int i=0;i<n;i++) if(!b[i]) B=1;
	if(!B&&b!=vi(n,1)&&b!=vi(n,-1)){
      if(a[n].second%n!=a[n-1].second%n) res+=a[n].first-a[n-1].first;
      else res+=min(a[n+1].first-a[n-1].first,a[n].first-a[n-2].first);
    }
	cout<<res<<endl;
}


Measured memory_bytes: 2944
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final double varN = Integer.parseInt(sc.next());
        final double varX = Integer.parseInt(sc.next());
        final double varT = Integer.parseInt(sc.next());
        sc.close();

        int result = 0;
        result = (int) (Math.ceil(varN / varX) * varT);
        System.out.println(result);
    }
}

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

using ll = int_fast64_t;
using pll = pair<ll,ll>;
#define rep(i,n) for(int i=0;i<(n);++i)

signed main(){

  ll n,m;
  cin>>n>>m;
  vector<ll> a(n);
  for(auto&ai:a)cin>>ai;
  sort(rbegin(a),rend(a));

  auto count_hs = [&](ll v){
    ll res = 0;
    rep(i,n){
      auto itr = upper_bound(begin(a),end(a),v-a[i],greater<>());
      int j = itr-begin(a);
      res += j;
    }
    return res;
  };
  ll lef=0,req=1e10;
  while(req-lef>1){
    ll mid = lef+req>>1;
    (count_hs(mid)>m?lef:req) = mid;
  }

  vector<ll> sum(n+1);
  rep(i,n)sum[i+1]=sum[i]+a[i];

  priority_queue<pll> que;
  ll ans = 0;
  rep(i,n){
    auto itr = upper_bound(begin(a),end(a),req-a[i],greater<>());
    ll j = itr-begin(a);
    ans += a[i]*j;
    ans += sum[j];
    if(itr!=end(a) and next(itr)!=end(a))que.emplace(a[i]+*next(itr),i*n+j);
  }

  ans += lef*(m-count_hs(req));

  cout<<ans<<endl;

}

Measured memory_bytes: 6940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 131074;
typedef long long ll;
typedef pair<ll,ll> pll;
vector<pair<ll,ll> > V[maxn],edge[maxn];
int q[maxn],n; 
inline void merge(vector<pll> &res,vector<pll> &va,vector<pll> &vb,ll wa,ll wb,ll limit){
	vector<pll> tmp;
	unsigned j=0;
	for(auto i:va){
		while(j<vb.size() && vb[j].fi<=limit-wa-wb-i.se) j++;
		if(j!=0){
			tmp.push_back({i.fi+wa,vb[j-1].se+wb});
			tmp.push_back({vb[j-1].se+wb,i.fi+wa});
		}
	}sort(tmp.begin(),tmp.end());
	res.clear();
	for(auto it:tmp)
		if(res.empty()||it.se<res.back().second)
			res.push_back(it);
}
inline bool check(ll limit){
	Dep(i,n-1,0){
		int u = q[i];
		if(edge[u].size()==0){
			V[u].clear();
			V[u].push_back({0,0});
		} else{
			merge(V[u],V[edge[u][0].fi],V[edge[u][1].fi],edge[u][0].se,edge[u][1].se,limit);
		}
		if(V[u].empty()) return false;
	}return true;
}
int main(){
	n = rd();
	Rep(i,2,n){
		int u = rd(),w = rd();
		edge[u] . push_back({i,w});
	}
	int front=0,rear=0;
	q[rear++] = 1;
	while(front<rear){
		int u=q[front++];
		for(auto v:edge[u]) q[rear++] = v.fi;
	}
	ll l= 0,r = 1e18,ans=-1;
	while(l<=r){
		ll mid=(l+r)>>1;
		if(check(mid)){
			ans = mid;
			r=mid-1;
		} else{
			l=mid+1;
		}
	}writeln(ans);
	return 0;
}


Measured memory_bytes: 31884
import java.util.Scanner;

class Main {

    static int gcd(int x, int y) {
        if (y == 0) {
            return x;
        } else {
            return gcd(y, x % y);
        }
    }

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

        int chukan = sc.nextInt();
        int kimatu = sc.nextInt();
        int saisi = sc.nextInt();
        while (chukan != -1 || kimatu != -1 || saisi != -1) {
            int o = kimatu + chukan;
            if (o < 30) {
                System.out.println("F");
            } else if (chukan == -1 || kimatu == -1) {
                System.out.println("F");
            } else if (80 <= o) {
                System.out.println("A");
            } else if (65 <= o && o < 80) {
                System.out.println("B");
            } else if (50 <= o && o < 65) {
                System.out.println("C");
            } else if (30 <= o && o < 50 && saisi >= 50) {
                System.out.println("C");
            } else if (30 <= o && o < 50 && saisi < 50) {
                System.out.println("D");

            }
            chukan = sc.nextInt();
            kimatu = sc.nextInt();
            saisi = sc.nextInt();
        }
    }

}



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




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  ll a,b,c,k,n,m,temp,count=0,ans=0,i;
  string s;
  cin>>n>>k;
  temp=n/k;
  ans=n-k*temp;
  ll temp1=abs(ans-k);
  if(temp1<ans)cout<<temp1<<endl;
  else cout<<ans<<endl;


return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

ll mod = 1e9 + 7;

ll po(ll base, int n){
	ll ans = 1;
	for (int i = 0; i < n; i++){
		ans *= base;
		if (ans > mod)
			ans %= mod;
	}
	return ans;
}

int main(){
	int n;
	cin >> n;
	if (n == 1){
		cout << "0\n";
		return 0;
	}
	ll ans = 0;
	ans += po(10, n) - 2 * po(9, n) + po(8, n);
	while (ans < 0){
		ans += mod;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
ll mod= 1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll a[210000];
main(){
    ll n,h,m,r,ans=1e10;
    cin>>h>>n;
    ll s=0;
    rep(i,0,n)cin>>a[i];
    rep(i,0,n)s+=a[i];
    if(s>=h)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
    long long int k,s,x,y,z,cnt=0;
    scanf("%lld%lld",&k,&s);
    for(x=0; x<=k; x++)
    {
        for(y=0 ; y<=k; y++)
        {
            z=s-x-y;
            if(z>=0&&z<=k)
            {
                if(x+y+z==s)
                {
                    cnt++;
                }
            }
        }
    }
    printf("%lld\n",cnt);
}


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

const int INF = 1000000007;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int> > a(n, vector<int>(m, 0));
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    int ans = INF;
    for (int bit = 1; bit < (1 << n); bit++) {
        vector<int> u(m, 0);
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if ((bit >> i) & 1) {
                sum += c[i];
                for (int j = 0; j < m; j++) u[j] += a[i][j];
            }
        }
        bool f = true;
        for (int j = 0; j < m; j++) {
            if (u[j] < x) f = false;
        }
        if (f) ans = min(sum, ans);
    }
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
/******************************************************************

	AOJ 0529　ダーツの問題

	4本投げたときの合計値をできるだけ最大化したい

	解法:半分全列挙

	全探索は計算量的に無理なので、二本のダーツを
	投げたときのとりうる値(0を含む)を全部上げ、
	そこから二分探索でとりうる最大値を確定させる

*******************************************************************/

#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>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

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

#define INF 1000000000
#define EPS 1e-10

#define MAX_M 1002
#define MAX_N 1002

int M, N;
int J[MAX_M][MAX_N], O[MAX_M][MAX_N], I[MAX_M][MAX_N];
int K;
string maze[MAX_M];

int main(){

	cin >> M >> N;
	cin >> K;
	for (int i = 0; i < M; i++){
		cin >> maze[i];
	}

	for (int i = 0; i < M; i++){
		for (int j = 0; j < N; j++){
			J[i + 1][j + 1] = J[i + 1][j] + J[i][j + 1] - J[i][j];
			O[i + 1][j + 1] = O[i + 1][j] + O[i][j + 1] - O[i][j];
			I[i + 1][j + 1] = I[i + 1][j] + I[i][j + 1] - I[i][j];
			if (maze[i][j] == 'J')
				J[i + 1][j + 1]++;
			else if (maze[i][j] == 'O')
				O[i + 1][j + 1]++;
			else
				I[i + 1][j + 1]++;
		}
	}

	for (int i = 0; i < K; i++){
		int sy, sx, gy, gx;
		cin >> sy >> sx >> gy >> gx;
		sy--;
		sx--;
		int j_ans = J[gy][gx] - J[sy][gx] - J[gy][sx] + J[sy][sx];
		int o_ans = O[gy][gx] - O[sy][gx] - O[gy][sx] + O[sy][sx];
		int i_ans = I[gy][gx] - I[sy][gx] - I[gy][sx] + I[sy][sx];
		printf("%d %d %d\n", j_ans, o_ans, i_ans);
	}

}

Measured memory_bytes: 13960
// youngjinp20
// 2020 03

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAX = 100;
int N, W;
int w[MAX];
int v[MAX];

int main() {
	cin >> N >> W;

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

	ll dp[W+1] = {0};

	for (int j=0; j<N; j++) {
		for (int i=W; i>0; i--) {
			if (i >= w[j]) {
				dp[i] = max(dp[i-w[j]]+v[j], dp[i]);
			}
		}
	}

	cout << dp[W];

	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int mx = 1e5+10;
int dp[mx];
int main()
{
    memset(dp,63,sizeof dp);
    int n,w;
    cin>>n>>w;
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        int v,we;
        cin>>v>>we;
        for(int j=1e5;j>=we;j--)
            dp[j]=min(dp[j],dp[j-we]+v);
    }
    int pos=0;
    for(int i=0;i<=1e5;i++)
    {
        if(dp[i]<=w)
        {
            pos=i;
        }
    }
    cout<<pos<<endl;
}



Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#include "atcoder/all"
using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;



signed main(){
	int N;
	cin >> N;
	int ans = INF;
	auto f = [&](int i) {
		int j = 2 * N / i;
		vector<int>r = {0, -1};
		vector<int>m = {i, j};
		auto p = crt(r, m);
		if(p.first != 0) CHMIN(ans, p.first);
	};
	for(int i = 1; i * i <= 2 * N; i++) {
		if(2 * N % i) continue;
		f(i);
		f(2 * N / i);
	}
	out(ans);
}

Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

    int a,b,c;
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    sortd(v);
    auto diff1 = v[0] - v[1];
    auto diff2 = v[0] - v[2];

    int ans = 0;
    ans += diff1 / 2; diff1 %= 2;
    ans += diff2 / 2; diff2 %= 2;

    if (diff1 == 1 and diff2 == 1) ans += 1;
    if (diff1 == 1 and diff2 == 0) ans += 2;
    if (diff1 == 0 and diff2 == 1) ans += 2;

    cout << ans << endl;
}

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

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

  vector<vector<int>> vec(M);
  
  for (int i = 0; i < M; i++) {
    int k; cin >> k;
    vec[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> vec[i][j];
      --vec[i][j];
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++) cin >> p[i];



  int ans = 0;
  for (int bit = 0; bit < (1<<N); bit++) {
    bool ok = true;
    for (int i = 0; i < M; i++) {
      int con = 0;
      for (int id : vec[i]){
        if(bit & (1<<id)) con++;
      }
      if(con % 2 != p[i]) ok = false;
    }
    if(ok) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <tuple>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <string,string> mss;
#define INF 1000000000

int main(){
  string s;
  cin>>s;
    string res = "";
    for(int i=1; i<=s.size(); ++i) {
        if(i%2!=0) {
            res+=s[i-1];
        }
    }
    cout<<res<<'\n';
  return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        int x = 0, y = 0;////
        while (true)
        {
            string st = Console.ReadLine();
            if (st == null) { break; }
            int[] a = st.Split(',').Select(int.Parse).ToArray();
            //Array.Sort(a);
            if (a[0]*a[0]+a[1]*a[1]==a[2]*a[2]) { x++; }
            if (a[0] == a[1]) { y++; }
        }
        Console.WriteLine(x);
        Console.WriteLine(y);
    }
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    if (a + b < 10) {
        cout << a + b << endl;
    } else {
        cout << "error" << endl;
    }
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

A = int(input())
B = int(input())
C = int(input())
D = int(input())

# print(A)
# print(B)
# print(C)
# print(D)

# print(A if A < B else B)
# print(C if C < D else D)

print((A if A < B else B) + (C if C < D else D))

Measured memory_bytes: 2940
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(len(a)):
    aa = a[i]
    if aa % 2 == 0:
        while True:
            if aa % 2 == 0:
                cnt += 1
                aa = aa // 2
            else:
                break
print(cnt)


Measured memory_bytes: 4148
n = int(input())
a = list(map(int, input().split()))

ma = max(a)
tmp = 1
m = 0
while True:
    if tmp >= ma:
        break
    tmp *= 2
    m += 1

memo = [0 for i in range(m+1)]

for j in range(m+1):
    cnt0 = 0
    cnt1 = 0
    for ai in a:
        if ai & (1 << j):
            cnt1 += 1
        else:
            cnt0 += 1
    if cnt1 % 2 == 0 and cnt0 % 2 == 0:
        memo[j] = 1

ans = []


for ai in a:
    ansi = 0
    for j in range(m+1):
        if ai & (1 << j):
            if memo[j]:
                ansi += 2 ** j
        else:
            if memo[j] == 0:
                ansi += 2 ** j

    ans.append(str(ansi))

print(" ".join(ans))



Measured memory_bytes: 109796
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string,int>table;
int main()
{
    string word,frequent,longest;
    size_t N=0;
    while(cin>>word)
    {
        table[word]++;
        if(table[word]>N)
        {
            N=table[word];
            frequent=word;
        }
        if(word.size()>longest.size())
        {
            longest=word;
        }
    }
    cout<<frequent<<" "<<longest<<endl;
    return 0;
}


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

#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define AI(a,size,n) array<int,size> a;REP(i,n){assert(0<scanf("%d",&a[i]));}
#define VI(v,n) vector<int> v(n);REP(i,n){assert(0<scanf("%d",&v[i]));}
#define STR(s) string s;cin>>s

int main(){
  INT(n); STR(s);
  int ans = 0, l = 0, r = n / 2 + 1;
  auto check = [&](int m){
    map<string, int> mp;
    REP(i, n - m + 1){
      string t = s.substr(i, m);
      if (mp.count(t)){
        if (mp[t] + m <= i){
          return true;
        }
      } else {
        mp[t] = i;
      }
    }
    return false;
  };
  while(l + 1 < r){
    int m = (l + r) / 2;
    if (check(m)){
      l = m;
    } else {
      r = m;
    }
  }
  ans = l;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 6668
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
N = lines.shift() * 1
s = lines.shift()
c = 1
a = s[0]
for (i=1; i<s.length; i++) {
    if (a != s[i]) {
        c++
    }
    a = s[i]
}
console.log(c)

Measured memory_bytes: 8136
#include<bits/stdc++.h>
#include<string>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define forN(i, n) for(int i = 0; i <n ; ++i)
#define endl "\n"
typedef long long ll;
using namespace  std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int N = 1000 + 5;
ll h , n ,A[N] , B[N],DP[N][10004];

ll calc(int idx , int health){
    if(health<=0)return 0;
    if(idx == n ){
        if(health>0){
            return INF;
        }
        return 0;
    }
    if(DP[idx][health]!=-1)return DP[idx][health];
    ll take = calc(idx , health-A[idx]) + B[idx];
    ll dont = calc(idx+1 , health);
    return DP[idx][health] = min(take,dont);
}

int main(){
    fastIO;
    cin>>h>>n;
    for(int i = 0 ; i<n ; i++){
        cin>>A[i]>>B[i];
    }
    memset(DP,-1,sizeof DP);
    cout<<calc(0,h);
}


Measured memory_bytes: 82664
#include <iostream>
#include <algorithm>
using namespace std;
#define r(I,N)for(int I=0;I<(int)(N);I++)
int main(void){
	long long dp[4][4001];
	fill_n(*dp,4*4001,0);
	r(i,1001)dp[0][i]=1;
	for(int i=1;i<=3;i++)
		for(int j=4000;j>=0;j--)
			for(int k=0;k<=1000;k++){
				if(j-k<0)break;
				dp[i][j]+=dp[i-1][j-k];
			}
	int n;
	while(cin>>n)cout<<dp[3][n]<<endl;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
	char str[3];
	cin>>str;
	int count=0,max=0;
	for(int i=0;i<3;i++){
		if(str[i]=='R'){
			count++;
			if(max<count)	max=count;
		}else count=0;
		}
	

cout<<max;
return 0;
}

Measured memory_bytes: 3588
from sys import stdin
A, B, Q = list(map(int, input().split()))
# もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。
INF = 10 ** 18

S = [-INF] + list(map(int, (stdin.readline() for _ in range(A))))+[INF]
T = [-INF] + list(map(int, (stdin.readline() for _ in range(B))))+[INF]

from bisect import bisect_right
# from bisect import bisect_left as bisect_right #これでも通ったりする。
from itertools import product

for q in range(Q):  # 各問に答える
    x = int(input())  # 位置の指定
    s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    # 左右の神社と寺のの組み合わせ
    for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):
        t_root = abs(t - x) + abs(s - t)  # 寺から最初に回るルート
        s_root = abs(s - x) + abs(s - t)
        ans = min(ans, t_root, s_root)
    # 最小をとって終わり
    print(ans)

'''
bisect_right

ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。


In[3]: A
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In[4]: bisect.bisect_right(A, 2.5)
Out[4]: 3

In[5]: bisect.bisect_right(A, 3)
Out[5]: 4
'''


Measured memory_bytes: 12812
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

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();}

const int MAX_K = 500000;
bool fact_initialized = false;
long long fact[MAX_K], fact_inv[MAX_K], inv[MAX_K];

// This will be automatically called during combination_mod
void combination_init(int mod)
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;

    for(int i = 2; i < MAX_K; ++i)
    {
        fact[i] = fact[i-1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i-1] * inv[i] % mod;
    }
}

// Used:
//   ABC151-E
long long combination_mod(int n, int k, int mod)
{
    if (n < k || n < 0 || k < 0) return 0;
    if(!fact_initialized)
    {
        combination_init(mod);
        fact_initialized = true;
    } 
    return fact[n] * (fact_inv[k] * fact_inv[n-k] % mod) % mod;
}


int main(){
    std::ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int mod = 1000000007;
    ll res = 0;
    k = min(k, n-1);
    for(int i=0;i<=k;++i)
    {
        ll comb_zero = combination_mod(n, i, mod);
        ll comb = combination_mod(n - 1, i, mod);
        res += comb_zero * comb % mod;
        res %= mod;
    }
    cout << res << endl;
}

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

int main(){
int H, W;
while (true){
	cin >> H >> W;
	
	if (H == 0 && W == 0){
		break;
	}
	
	for (int h = 0; h < H; h++){
		for (int w = 0; w < W; w++){
			cout << '#';
		}cout << endl;
	}cout << endl;
	
}
}



Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e12)
#define PI (acos(-1))

#define amari(x) ((x) % 1000000007)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

#define rep(i,n) for(int i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

  long n, k;
  string s;

  cin >> n >> k;
  cin >> s;

  vector<int> v1;
  vector<int> v2;

  int x = 0;
  int y = 0;
  int z = 1;

  rep(i, n) {
    if (s[i] == '0' && z == 1) {
      v1.push_back(x);
      z = 0;
      x = 0;
      y++;
    } else if (s[i] == '0' && z == 0) {
      y++;
    } else if (s[i] == '1' && z == 1) {
      x++;
    } else {
      v2.push_back(y);
      z = 1;
      y = 0;
      x++;
    }
  }
  if (z == 1) {
    v1.push_back(x);
    v2.push_back(0);
  } else {
    v1.push_back(0);
    v2.push_back(y);
  }

  // rep(i, v1.size()) {
  //   cout << v1[i] << v2[i] << endl;
  // }

  long l = v1.size();
  long sum = 0;
  for (int i = 0; i < min(l-1, k); i++) {
    sum += v1[i] + v2[i];
  }
  sum += v1[min(l-1,k)];

  long m = sum;

  for (int i = 0; i < l - min(l-1, k) - 1; i++) {
    sum -= v1[i];
    sum -= v2[i];
    sum += v1[min(l-1, k) + i + 1];
    sum += v2[min(l-1, k) + i];
    m = max(sum, m);
  }

  cout << m << endl;

  return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int dp[3030][3030];

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  int N, T, A, B; cin >> N >> T;
  vector<pair<int, int>> ps;
  for(int i = 0; i < N; ++i) {
    cin >> A >> B;
    ps.emplace_back(A, B);
  }
  sort(ps.begin(), ps.end());
  
  // 普通にdpすると最大値がサンプルより小さくなる。。。ラストの選び方のせいか。
  // T秒以降食べてはいけないなら普通のナップサックDPで良くなる。
  // T秒を跨いで食べる場合、できるだけ満足度が高い状態が良い。 -> 重さが小さい順にDPテーブルを埋める
  for(int i = 0; i < N; ++i) {
    int w = ps[i].first, v = ps[i].second;
    for(int j = 0; j < T; ++j) {
      dp[i+1][min(T, j + w)] = max(dp[i+1][min(T, j + w)], dp[i][j] + v);
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }
    dp[i+1][T] = max(dp[i+1][T], dp[i][T]);
  }

  cout << dp[N][T];
  return 0;
}

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

template <class T> void readVal(vector<T>& vec, int idx) {
    T input;
    std::cin >> input;
    vec[idx] = input;
}

int main()
{
    int size;
    cin >> size;
    vector<int> x(size); 
    vector<int> y(size);
    for (int i = 0; i < size; i++) {
        readVal(x, i);
        readVal(y, i);
    }
    int ans = 1;
    int dir(0), vecx(0), vecy(0), new_vecx(0), new_vecy(0);
    for (int i = 0; i <= size; i++) {
        new_vecx = x[(i + 1) % size] - x[i % size];
        new_vecy = y[(i + 1) % size] - y[i % size];
        int cross_prod = (vecx * new_vecy - vecy * new_vecx);
        if (cross_prod != 0) {
            if (cross_prod * dir >= 0) {
                dir = cross_prod > 0 ? 1 : -1;
            }
            else {
                ans = 0;
                break;
            }
        }
        vecx = new_vecx;
        vecy = new_vecy;
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <vector>

int main() {
  int d,n;
  scanf("%d",&d);
  scanf("%d",&n);
  int k;
  if(d<1) {
    k = 1;
  } else {
    if(d<2) {
      k = 100;
    } else {
      k = 10000;
    }
  }
  if(n<100) {
    printf("%d\n",k*n);
  } else {
    printf("%d\n",k*(n+1));
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextInt();
		sc.close();

		for (int i = 1; ; i++) {
			if (x * i % 360 == 0) {
				System.out.println(i);
				return;
			}
		}
	}
}


Measured memory_bytes: 35724
x, n = list(map(int, input().split()))
ps = list(map(int, input().split())) if n else []

pss = [0] * 102
for p in ps:
    pss[p] = 1

#print(pss)
for i in range(102):
    if x - i > -1 and pss[x - i] == 0:
        print(x - i)
        break
    if x + i < 102 and pss[x + i] == 0:
        print(x + i)
        break


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

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


}

/*



 */


Measured memory_bytes: 19060
n=int(input())
dice=[input().split() for i in range(n)]
def E(ls):
    ls=[ls[3],ls[1],ls[0],ls[5],ls[4],ls[2]]
    return ls

def N(ls):
    ls=[ls[1],ls[5],ls[2],ls[3],ls[0],ls[4]]
    return ls

def R(ls):
    ls=[ls[0],ls[2],ls[4],ls[1],ls[3],ls[5]]
    return ls
    
def same(d1,d2):
    d1_ls=[d1,]
    for i in range(3):
        d1=E(d1)
        d1_ls.append(d1)
    d1=E(d1)
    d1=N(d1)
    d1_ls.append(d1)
    d1=N(N(d1))
    d1_ls.append(d1)
    for i in range(6):
        d=d1_ls[i]
        for j in range(3):
            d=R(d)
            d1_ls.append(d)
    if d2 in d1_ls:
        return True
    else:
        return False
k=0
for i in range(n):
    for j in range(i+1,n):
        if same(dice[i],dice[j]):
            k+=1
            break 
    else:continue    
    break
if k==1:
    print('No')
else:
    print('Yes')


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

const int INF = 1e9;

void calc(vector<int>& dp, int mx) {
  dp[0] = 0;
  for (int n = 1; n <= mx; n++) {
    dp[n] = INF;
    int power;
    power = 1;
    while (power <= n) {
      dp[n] = min(dp[n], dp[n - power] + 1);
      power *= 6;
    }
    power = 1;
    while (power <= n) {
      dp[n] = min(dp[n], dp[n - power] + 1);
      power *= 9;
    }
  }
}

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

  vector<int> dp(N + 10);
  calc(dp, N);

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

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int n; cin>>n;
  while(n-->0){
    string s;
    int h,l;
    cin >> s;
    sort(s.begin(),s.end());
    sscanf(s.c_str(),"%d",&l);
    sort(s.rbegin(),s.rend());
    sscanf(s.c_str(),"%d",&h);
    cout << h - l << endl;
  }
  return 0;
}

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

// THINK: INT vs LONG LONG?

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

	string s; cin >> s;
	if (s.back() != 's') {
		s += 's';
	} else {
		s += "es";
	}
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<string.h>

#define N 10000

int main(void)
{
  char ch[N],ch1[N];
  int i,j,n;

  while(scanf("%s",ch)!=EOF)
    {
      i=0;
      while(i<=strlen(ch)-1)
        {
           if(ch[i]!='@')
	    {
	      printf("%c",ch[i]);
	      i++;
	    }
          else
	    {
	      i++;
	      ch1[0]=ch[i];
	      ch1[1]='\0';
	      sscanf(ch1,"%d",&n);
	      i++;
	      for(j=1;j<=n;j++)
	        {
	          printf("%c",ch[i]);
	        }
	      i++;
            }
        }
      printf("\n");
    }
  return 0;
}

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

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

    int r, D, x2000;
    cin >> r >> D >> x2000;

    int x = x2000;
    rep(i,10) {
        x = r * x - D;
        cout << x << endl;
    }
    
    return 0;
}


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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    ull ans = 0;
    sort(all(h));
    reverse(all(h));
    for(int i = k; i < n; i++) {
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
     
    int main() {
    long long h , s;
    std :: cin >> h >> s;
     
    if(s >= h) {
    std :: cout << "0\n";
    return 0;
    }
     
    long long  arr[h] , prefix = 0;
    for(auto i = 0 ; i < h ; i++) {
    std :: cin >> arr[i];
    prefix += arr[i];
    }
     
    std :: sort(arr , arr + h);
     
    for(int i = 0 ; i < s ; i++) prefix -= arr[h - 1 - i];
    std :: cout << prefix << '\n';
    }

Measured memory_bytes: 1792
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 10桁出力 cout << setprecision(10) << double;
#include <queue>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

// 2辺の平行四辺形の中の不思議光数
int solve(LL yoko, LL tate) {
	return 0;
}

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
	LL n, x;
	cin >> n >> x;

	LL ans = 0;
	ans = x + (n - x);	//最初2本
	//cout << "ans=" << ans << endl;


	LL tate = x;
	LL yoko = n - x;

	while (1) {

		if (tate > yoko) {
			swap(tate, yoko);
		}
		//cout << "tate=" << tate << " , yoko=" << yoko << endl;
		if (yoko%tate != 0) {
			ans += floor(yoko / tate)*tate*2;
			//cout << "ans=" << ans << endl;
			yoko = yoko%tate;
		}else{
			ans += (yoko / tate - 1)*2*tate + tate;
			//cout << "ans = " << ans << endl;

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


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int l[3];
  cin >> l[0] >> l[1] >> l[2];
  sort(l,l+3);
  cout << l[0] << " "  << l[1] << " " << l[2] << endl;
  return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int dy[]={-1,0,1,0};
int dx[]={0,-1,0,1};

int H,W;
char fld[1111][1111];
int dist[1111][1111];
signed main(){
	cin>>H>>W;
	rep(i,H)cin>>fld[i];
	fill_n(*dist,1111*1111,1001001001);
	queue<pint>que;
	rep(i,H)rep(j,W){
		if(fld[i][j]=='#'){
			dist[i][j]=0;
			que.push({i,j});
		}
	}
	while(que.size()){
		int y,x;
		tie(y,x)=que.front();
		que.pop();
		rep(d,4){
			int ny=y+dy[d];
			int nx=x+dx[d];
			if(ny<0||ny>=H||nx<0||nx>=W||dist[ny][nx]<=dist[y][x]+1)continue;
			dist[ny][nx]=dist[y][x]+1;
			que.push({ny,nx});
		}
	}

	int ans=0;
	rep(i,H)rep(j,W)chmax(ans,dist[i][j]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 27316
N = int(input())
S = input()
b = S.count(".")
c = 0
d = N
for i in range(0, N):
    if S[i] == ".":
        b -= 1
        d = min(b+c, d)
    if S[i] == "#":
        c += 1
        d = min(b + c -1, d)
print(d)

Measured memory_bytes: 3500
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;

    vl dp(n+2, -1);  // dp[i] : i段目からn段目に上る場合の数
    rep(i, m) {
        ll a;
        cin >> a;
        dp[a] = 0;
    }

    dp[n+1] = 0;
    dp[n] = 1;
    for(ll i = n-1; i >= 0; i--) {
        if(dp[i] == -1) {
            dp[i] = (dp[i+1] + dp[i+2])%mod;
        }
    }

    out(dp[0]);
    re0;
}

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

using namespace std;

int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int sum = 0;
    for(int i = 0; i < n - 2; i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')sum++;
    }
    cout << sum << endl;
    return 0;
}

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

int main(){
    int h,w,t,y;
    
    while(1){
        cin >> h >> w;
        if(h==0 && w==0)break;
        
        
        for(t=1; t<=h; t++){
            for(y=1; y<=w; y++){
                if(t==1 || t==h || y==1 || y==w ){
                    cout << "#";
                }
                    else{cout << ".";}
             }
             cout << "\n";
            }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3076
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();
		long ans = 0;
		
		ans = Math.max(a*c, a*d);
		ans = Math.max(ans, b*c);
		ans = Math.max(ans, b*d);
		
		System.out.println(ans);

	}

}


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

int main(){
	int K, X;
	cin >> K >> X;
	int fir = X - K + 1;
	for(int i = 0; i < 2 * K - 1; i++){
		cout << fir << " ";
		fir++;
	}
	cout << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


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

	if ((N + 1) / 2 >= K) {
		int A = K;
		int B = K + N + N / 2;
		int C = K + N + N;
		rep(i, (N + 1) / 2) {
			putint(A + i);
			putint(B + i);
			putint(C + i * 2);
		}
		B = K + N / 2;
		C = K + N + !(N & 1);
		for (int i = (N + 1) / 2; i < N; i++) {
			putint(A + i);
			putint(B + i);
			putint(C + i * 2);
		}
		fwrite(dn, 1, di - dn, stdout);
	}
	else printf("-1");

	Would you please return 0;
}

Measured memory_bytes: 4096
package main

import (
	"fmt"
)

func main() {
	var A, B, X int
	var ans string
	fmt.Scan(&A, &B, &X)

	if A <= X && X <= A+B {
		ans = "YES"
	} else {
		ans = "NO"
	}

	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

namespace my
{
	//-----------------------------------------------------------------------------
	inline char cn()
	{
		static char buf[1000010],*p1=buf,*p2=buf;
		return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
	}
	#define cn getchar
	template<class TY>void read(TY &x)
	{
		x=0;int f1=1;char ch=cn();
		while(ch<'0'||ch>'9'){if(ch=='-')f1=-1;ch=cn();}
		while(ch>='0'&&ch<='9')x=x*10+(ch-'0'),ch=cn(); x*=f1;
	}
	char Output[1000100],Zk[100];int op_top=0,Zk_top;
	void fcheck(int Type=0){if(Type||op_top>=1000000)fwrite(Output,1,op_top,stdout),op_top=0;}
	template<class TY>inline void write(TY x)
	{
		if(x==0){Output[op_top++]='0';fcheck();return;}
		if(x<0)Output[op_top++]='-',x=-x;
		Zk_top=0;while(x)Zk[++Zk_top]=x%10+'0',x/=10;
		while(Zk_top)Output[op_top++]=Zk[Zk_top--];fcheck();
	}
	#define K_G Output[op_top++]=' '
	#define H_C Output[op_top++]='\n'
	//--------------------------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------------------------
	#define ll long long
	#define uint unsigned int
	#define ull unsigned long long
	#define INV(x) ksm(x,mod-2)
	#define inf 999999999
	#define mod 998244353
	
	template<class TY>void add(TY &x,TY y){x=(x+y>=mod?x+y-mod:x+y);}
	template<class TY>void dec(TY &x,TY y){x=(x-y<0?x-y+mod:x-y);}
	template<class TY>TY add(TY x){return x>=mod?x-mod:x;}
	template<class TY>TY dec(TY x){return x<0?x+mod:0;}
	//
	int ksm(int x,int y){int re=1;for(;(y&1?re=1ll*re*x%mod:0),y;y>>=1,x=1ll*x*x%mod);return re;}
	int *fac,*inv_fac,*inv;
	void work_math(const int N)
	{
		fac=new int[N+5];inv_fac=new int[N+5];inv=new int[N+5];
		inv[1]=1;for(int i=2;i<=N;i++)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
		fac[0]=inv_fac[0]=1;for(int i=1;i<=N;i++)fac[i]=1ll*fac[i-1]*i%mod;
		inv_fac[N]=INV(fac[N]);
		for(int i=N-1;i>=1;i--)inv_fac[i]=1ll*inv_fac[i+1]*(i+1)%mod;
	}
	int C(int x,int y){return 1ll*fac[x]*inv_fac[y]%mod*inv_fac[x-y]%mod;}
	//
	template<class TY>TY gcd(TY x,TY y){return !y?x:gcd(y,x%y);}
	template<class TY>TY exgcd(TY a,TY b,TY &x,TY &y){
		if(!b)return x=1,y=0,a;
		TY re=exgcd(b,a%b,y,x);
		return y-=a/b*x,re;
	}
	//
	template<class TY>void discretization(TY *arr,int St,int Ed){
		vector<TY>Arr;Arr.clear();
		for(int i=St;i<=Ed;i++)Arr.push_back(arr[i]);
		sort(Arr.begin(),Arr.end());
		for(int i=St;i<=Ed;i++)arr[i]=lower_bound(Arr.begin(),Arr.end(),arr[i])-Arr.begin()+1;
	}
	//-----------------------------------------------------------------------------------------------
	
	//----------------------------------------------------------------------------------------------- 
	#define maxn 100010
	int n,a[maxn];
	
	void main()
	{
		read(n);
		for(int i=1;i<=n;i++)read(a[i]);
		for(int i=n-1;i>=1;i--){
			if(a[i]>a[i+1])a[i]--;
			if(a[i]>a[i+1]){
				printf("No\n");
				return;
			}
		}
		printf("Yes\n");
		fcheck(1);return;
	}
}

int main(){my::main();return 0;}

Measured memory_bytes: 3396
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
using namespace std;
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)

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

    ll N, M, l = -1, r = 1000000;
    cin >> N >> M;
    vector<ll> L(M), R(M);
    REP(i, M) {
        cin >> L[i] >> R[i];
        l = max(l, L[i]);
        r = min(r, R[i]);
    }

    cout << max(0, int(r-l+1)) << "\n";
}

Measured memory_bytes: 1792
N = int(input())
nums = list(map(int, input().split()))
before = nums[0]
cnt = 0
ans = 0
for i in range(1, N):
  if before >= nums[i]:
    cnt += 1
  else:
    ans = max(ans, cnt)
    cnt = 0
  before = nums[i]
ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 63856
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define l  long
#define ll  long long

int main()
{
     fast
     ll int x,c=0;cin>>x;
     while(x>5)
     {
         if(x>=500) {x-=500;c+=1000;}
         else {x-=5;c+=5;}
     }
     cout<<c;
    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 n=sc.nextInt();
		String s=sc.next();
		int[] array=new int[n];
		int min=99999,sum=0;

		for(int i=0;i<n-2;i++) {
			if(s.substring(i,i+3).equals("ABC"))sum++;
		}

		System.out.println(sum);


	}
}
/*
 6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40
 */

//Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));




Measured memory_bytes: 22100