akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int m, n; cin >> n >> m;
  vector<string> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  for (int i = 0; i <= n - m; i++) {
    for (int j = 0; j <= n - m; j++) {
      // debug2(i, j);
      bool match = true;
      for (int k = 0; k < m; k++) {
        for (int l = 0; l < m; l++) {
          if (b[k][l] != a[i+k][j+l]) {
            // cout << "i = " << i << ", j = " << j << ", k = " << k << ", l = " << l << endl;
            match = false;
            break;
          }
        }
        if (!match) break;
      }
      if (match) {
        Yes();
        return;
      }
    }
  }
  No();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long K, long long X)
{
    cout << ( ( 500 *K >= X) ? "Yes" : "No") << endl;
}

/*
高橋君は 
500
 円玉を 
K
 枚持っています。 これらの総額が 
X
 円以上である場合は Yes を、そうでない場合は No を出力してください。
*/
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long K;
    scanf("%lld", &K);
    long long X;
    scanf("%lld", &X);
    solve(K, X);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int A,B;
  scanf("%d %d",&A,&B);
  
  int ptap = 1;
  int n = 0;
  
  while(ptap < B)
  {
    //A個増えるが1個挿すために使うからへる
    ptap += A - 1;
    n++;
  }
  printf("%d",n);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

struct CumulativeSum{
    vector<int> data;
    CumulativeSum(int sz) : data(sz, 0) {};
    void add(int k, int x){
        data[k] += x;
    }
    void build(){
        for(int i = 1; i < data.size(); i++){
            data[i] += data[i - 1];
        }
    }
    //区間[0,k]の和
    int query(int k){
        if(k < 0) return 0;
        return (data[min(k, (int)data.size() - 1)]);
    }
    //区間[l.r)の和
    int query(int l, int r){
        return query(r - 1) - query(l - 1);
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    CumulativeSum cs(s.size()), ct(t.size());
    rep(i, 0, s.size()){
        cs.add(i, (s[i] == 'A' ? 1 : 2));
    }
    rep(i, 0, t.size()){
        ct.add(i, (t[i] == 'A' ? 1 : 2));
    }
    cs.build();
    ct.build();
    int q;
    cin >> q;
    rep(i, 0, q){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int tmps = cs.query(a - 1, b);
        int tmpt = ct.query(c - 1, d);
        if(tmps % 3 == tmpt % 3) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

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

int we[110], v[110], dp[100100];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, w;
    cin >> n >> w;
    fill(dp + 1, dp + 100010, 2e9);
    for (int i = 1; i <= n; ++i) {
        cin >> we[i] >> v[i];
        for (int j = 100000; j >= 1; --j) {
            if (j - v[i] >= 0) {
                dp[j] = min(0LL + dp[j], 0LL + dp[j - v[i]] + we[i]);
               // cout << j << " " << dp[j] << '\n';
            }
        }
    }
    for (int i = 100000; i >= 1; --i) {
        if (dp[i] <= w) {
            cout << i;
            return 0;
        }
    }
}


Measured memory_bytes: 4048
#include <iostream>
#include <math.h>
using namespace std;
int main(void)
{
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}
}

Measured memory_bytes: 1116
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

//しっかり制約確認したか?
int main()
{
    int n; cin >> n;
    int ans = 0;
    vector<int> v(n);
    rep(i, n){
        cin >> v[i];
        if((i+1) % 2 == 1 && v[i] % 2 == 1)ans++;
    }
    cout << ans << endl;
    system("pause");
}


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

int main(){
  int i,j,cnt;
  int n,k,q;
  cin>>n>>k>>q;
  int a[q];
  for(i=0;i<q;i++)cin>>a[i];
  int p[n];
  for(i=0;i<n;i++)p[i]=k-q;
  for(i=0;i<q;i++)p[a[i]-1]++;
  for(i=0;i<n;i++){
    if(p[i]>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

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

int main(){
  int n,ans=0;cin>>n;
  vector<int> x(n,0),y(n,0);
  REP(i,n) cin>>x.at(i);
  REP(i,n) if(x.at(i)==i+1) y.at(i)=1;
  REP(i,n-1){
    if(y.at(i)==1){
      ans++;
      y.at(i)=y.at(i+1)=0;
    }
  }
  if(y.at(n-1)==1) ans++;
  cout<<ans;
}

Measured memory_bytes: 1024
from collections import deque

N = int(input())

length = {}
conn = [[] for _ in range(N + 1)]
for i in range(N - 1):
    u, v, w = [int(x) for x in input().split()]
    conn[u].append(v)
    conn[v].append(u)
    length[(u, v)] = w

q = deque([1])
dist = [-1] * (N + 1)
dist[1] = 0
while q:
    u = q.popleft()
    for v in conn[u]:
        if dist[v] == -1:
            if u < v:
                dist[v] = dist[u] + length[(u, v)]
            else:
                dist[v] = dist[u] + length[(v, u)]
            q.append(v)

for i in range(1, N + 1):
    print(dist[i] % 2)

Measured memory_bytes: 46344
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  string s;
  cin >> s;
  int i=0,r,l,k,a[100000]={0},n=s.size();
  while(i<n) {
    r=0;
    while(s[i]=='R') {
      i++;
      r++;
    }
    l=0;
    k=i;
    while(s[i]=='L') {
      i++;
      l++;
    }
    a[k-1]=(r+1)/2+l/2;
    a[k]=r/2+(l+1)/2;
  }
  for(i=0; i<n-1; i++) {
    cout << a[i] << " ";
  }
  cout << a[n-1] << endl;
}

Measured memory_bytes: 1024
from itertools import product
H, W, K = map(int, input().split())
choco = [list(input()) for _ in range(H)]

def cnt(array):
    count = [0] * H
    split_cnt = 0
    for w in range(W):
        for h in range(H):
            if choco[h][w] == "1":
                count[array[h]] += 1
        if any(i > K for i in count):
            split_cnt += 1
            count = [0] * H
            for h in range(H):
                if choco[h][w] == "1":
                    count[array[h]] += 1
            if any(i > K for i in count):
                return 10 ** 20
    return split_cnt

def get_array(array):
    l = len(array)
    ret = [0] * l
    for i in range(1, l):
        ret[i] = ret[i-1] + array[i]
    return ret

ans = 10 ** 20

for p in product(range(2), repeat=H-1):
    p = get_array([0]+list(p))
    ans = min(ans, cnt(p)+max(p))

print(ans)


Measured memory_bytes: 47196
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(auto &a)
{
    for (auto s: a) cout<<s<<' ';
    cout<<endl;
}

void get(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cin>>a[i];
}

const int p =  1e9 + 7;


int mul(int a, int b) {
    return (1LL * a%p * b%p) % p;
}

int add(int a, int b) {
    ll s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}



vector<int> Z(string s)
{
int n = s.length();
vector<int> z(n);
int L = 0, R = 0;
for (int i = 1; i < n; i++) {
  if (i > R) {
    L = R = i;
    while (R < n && s[R-L] == s[R]) R++;
    z[i] = R-L; R--;
  } else {
    int k = i-L;
    if (z[k] < R-i+1) z[i] = z[k];
    else {
      L = i;
      while (R < n && s[R-L] == s[R]) R++;
      z[i] = R-L; R--;
    }
  }
}
return z;
}

vector<int> opvec(vector<int> a, vector<int> b)
{
    int n = a.size();
    vector<int> res(n);
    for (int i = 0; i<n; i++) res[a[i]] = b[i];
    return res;
}

vector<int> invvec(vector<int> a)
{
    int n = a.size();
    vector<int> res(n);
    for (int i = 0; i<n; i++) res[a[i]] = i;
    return res;
}

vector<int> mulvec(vector<int> a, vector<int> b)
{
    a = invvec(a);
    int n = a.size();
    vector<int> res(n);
    for (int i = 0; i<n; i++) res[a[i]] = b[i];
    return res;
}

vector<int> id(int n)
{
    vector<int> res(n);
    for (int i = 0; i<n; i++) res[i] = i;
    return res;
}

vector<int> power(vector<int> a, int deg)
{
    if (deg==0) return id(a.size());
    if (deg%2==1) return mulvec(power(a, deg-1), a);
    auto kek = power(a, deg/2);
    return mulvec(kek, kek);
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, k;
    cin>>n>>k;
    vector<int> a(n), b(n);
    get(a);
    get(b);
    if (k==1) {print(a); return 0;}
    for (int i = 0; i<n; i++) {a[i]--; b[i]--;}
    vector<int> keks(n);
    
    int m = 0;
    if (k>21) m = (k-20)/6;
    keks = mulvec(opvec(b, a), b);
    keks = mulvec(keks, invvec(a));
    keks = power(keks, m);
    k -= 6*m;
    vector<vector<int>> operations(k);
    operations[0] = a;
    operations[1] = b;
    for (int i = 2; i<k; i++) operations[i] = opvec(operations[i-2], operations[i-1]);
    vector<int> answer = mulvec(keks, operations[k-1]);
    answer = mulvec(answer, invvec(keks));
    for (int i = 0; i<n; i++) answer[i]++;
    print(answer);
    
}

Measured memory_bytes: 26060
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define Mod 998244353
#define INF 1e14
typedef long long int ll;
const ll N=1e5+5;
bool x[N+1]={false};
ll fast(ll n,ll a)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a)%Mod;
        if(n%2==0)
        {
            return (((res%Mod)*(res%Mod))%Mod);
        }
        else{
            return (((((res%Mod)*a)%Mod)*res)%Mod);
        }
    }
}

int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[0]+a[1];


}


Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_i

#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  


#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;


using namespace std;

typedef long long int ll;

const int precision = 16;
const int modulo =  1000000007; // 10^9 + 7
using ll = long long;
const double EPS = 1e-9;


double solveCoins() {
	int n; cin >> n;
	vector<double> p(n);
	for(auto & c : p) cin >> c;

	vector<double> dp(n + 1);
	dp[0] = 1;

	for(auto coin = 0; coin < n; ++coin) {
		auto prob = p[coin];
		for(int i = coin + 1; i >= 0; --i) {
			dp[i] *= (1 - prob);
			if(i != 0) dp[i] += dp[i - 1] * prob;
		}
	}

	double ans = 0;
	for(int heads = 0; heads <= n; ++heads) {
		int tails = n - heads;
		if(heads > tails) {
			ans += dp[heads];
		}
	}
	return ans;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(precision);
	cout.setf(ios_base::fixed);

	auto ret = solveCoins();
	cout << ret << endl;
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>

#define div 1000000000+7

typedef long long ll;

using namespace std;


int main(){
    int n, m;
    long long a[50], b[50], c[50], d[50];
    int temp;
    int result[50];

    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < m; i++){
        cin >> c[i] >> d[i];
    }
    for(int i = 0; i < n; i++){
        int length = 1000000000;
        for(int j = 0; j < m; j++){
            temp = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if(length > temp){
                length = temp;
                result[i] = j+1;
            }
        }
    }
    for(int i = 0; i < n; i++){
        cout << result[i] << endl;
    }
}

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

using namespace std;

const int N = 3e3 + 5;
int n, m, dp[N][N], trace[N][N];
string s, t;

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s >> t; n = s.size(); m = t.size();

    s = '!' + s; t = '!' + t;
    memset(dp, -1, sizeof dp); dp[0][0] = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) if (dp[i][j] != -1) {
            if (s[i + 1] == t[j + 1] && dp[i + 1][j + 1] < dp[i][j] + 1) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
                trace[i + 1][j + 1] = 0;
            }
            if (dp[i + 1][j] < dp[i][j]) {
                dp[i + 1][j] = dp[i][j];
                trace[i + 1][j] = 1;
            }
            if (dp[i][j + 1] < dp[i][j]) {
                dp[i][j + 1] = dp[i][j];
                trace[i][j + 1] = 2;
            }
        }
    }

    string ans = "";
    int i = n, j = m;
    while (i && j) {
        if (!trace[i][j]) {
            ans += s[i];
            --i; --j;
        }
        else if (trace[i][j] == 1) --i;
        else --j;
    }

    reverse(ans.begin(), ans.end() );
    cout << ans;

    return 0;
}


Measured memory_bytes: 70784
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
    int n,ans=0;
    string s;
    cin>>n>>s;
    for(ll i=0;i<n;){
        ll j=i;
        while(true){
            if(i==n){
                break;
            }
            if(s[j]==s[i])i++;
            else break;
        }
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  string s;
  cin >> s;
  vector<char> ans;
  for(int i=0;i<s.size();i++){
    if(i%2==0) ans.push_back(s[i]);
  }

  for(int i=0;i<ans.size();i++){
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
	int n,i;
	scanf("%d",&n);
	int a[100],tmp;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<(n/2);i++){
		tmp=a[i];
		a[i]=a[(n-1)-i];
	   	a[(n-1)-i]=tmp;
	}
	for(int i=0;i<n;i++){
		if(i>=1) printf(" ");
        		printf("%d",a[i]);
	}
	putchar('\n');
	return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string s;
   cin >> s;
   s[3] = '8';
   cout << s << endl;
   return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  cout << N * N * N << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
card = []
for i in range(M):
  b, c = map(int, input().split())
  card.append([c, b])
card.sort(reverse = True)
anslist = []
count = 0
while len(anslist) < N and count < M:
  anslist += [card[count][0] for i in range(card[count][1])]
  count += 1
anslist += [0]*N
anslist = anslist[:N]
anslist.sort()
for i in range(N):
  if anslist[i] < A[i]:
    anslist[i] = A[i]
  else:
    break

print(sum(anslist))


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

int main() {
  int X=1;
  int N;
  int K;
  cin >> N >> K;
  
  int A;
  int B;
  for (int i=0; i<N; i++){
    A = X*2;
    B = X + K;
    if (A<=B){
      X = A;
    }
    else {
      X = B;
    }
  }
  
  cout << X << endl;
}


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

vector<int> F;
void f(int a,int k) {
    if (k==1) F.push_back(0);
    else if (a==1) F.push_back(1);
    else {
        F.push_back((F[a-2]*10)%k);
    }
}
vector<int> amari;
void g(int a,int k) {
    if (k==1) amari.push_back(0);
    else if (a==1) amari.push_back(1);
    else {
        amari.push_back((amari[a-2]+F[a-1])%k);
    }
}
int main() {
   int K;
   cin >> K;
   if (K%2==0 || K%5==0) cout << -1 << endl;
   else {
       if (K%7==0) K/=7;
       for (int i=1; ; i++) {
           f(i,K);
           g(i,K);
           if (amari[i-1]==0) {
               cout << i << endl;break;
           }
       }
   }
}

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

using namespace std;

int main(){
    int N; cin >> N;
    vector<int> value(N);
    for(int i=0; i<N; i++){
        cin >> value[i];
    }

    sort(value.begin(), value.end());
    double tmp = value[0];
    for(int i=1; i<N; i++){
        tmp = (value[i] + tmp) / 2.0;
    }
    cout << tmp;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

int paper[10][10]={0};

void paint(int x, int y)
{
	if( x>=0 && x<=9 && y>=0 && y<=9)
		paper[x][y]++;
	return;
}

void drop(int x, int y, int size)
{
	switch(size)
	{
		case 1:
			paint(x-1, y);
			paint(x+1, y);
			paint(x, y-1);
			paint(x, y+1);
			paint(x, y);
			break;
		case 2:
			drop(x,y,1);
			paint(x-1, y-1); paint(x-1, y+1);
			paint(x+1, y-1); paint(x+1, y+1);
			break;
		case 3:
			drop(x,y,2);
			paint(x-2,y);paint(x,y-2);
			paint(x+2,y);paint(x,y+2);
			break;
	}
	return;
}

int main(void)
{
	int x,y,s;
	while(~scanf("%d,%d,%d",&x,&y,&s))
		drop(x,y,s);

	int blank=0;
	int max=0;
	for(int i=0; i<10; i++)
		for(int j=0; j<10; j++)
		{
			if(paper[i][j]==0)
				blank++;
			if(paper[i][j] > max)
				max = paper[i][j];
		}
	std::cout << blank << std::endl << max << std::endl;

	return 0;
}
			
			

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

int main(){
    ll n,ans =1; cin >> n;
    string s;
    cin >> s;
    char a = s[0];
    for(ll i=0; i<n; ++i){

        if(a != s[i]){
            ++ans;
            a = s[i];
        }
        
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<string> s(H);
  for(int i=0;i<H;i++)cin >> s.at(i);

  for(int i=0;i<W+2;i++)cout << "#";
  cout << endl;
  for(int i=0;i<H;i++){
    cout << "#" << s.at(i) << "#";
    cout << endl;
  }
  for(int i=0;i<W+2;i++)cout << "#";
  cout << endl;
  
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    sum=1
    l=list(S)
    for i in range(len(S)-1):
        if (l[i]!=l[i+1]):
            sum=sum+1
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vl A, B;
void input() {
    cin>>n;
    rep(i,n){
        cin>>x;
        A.pb(x);
    }
}
void solve() { 
    a=1000;
    PP K;
    K={0,0};
    rep(i,n){
    b=max(a,K.fi*A[i]+K.se);
    p=a/A[i];
    q=a%A[i];
    K=max(K,{p,q});
    a=b;
    } 
    print(a);
 }
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,n;scanf("%d%d",&h,&n);
    int sum=0;
    for(int i=0;i<n;i++){
        int a;scanf("%d",&a);
        sum+=a;
    }
    if(sum>=h)printf("%s\n","Yes");
    else printf("%s\n","No");
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
int main() {
	IOS;
	ll n,x;
	cin >> n >> x;
	ll ans;
	REP(i, n) {
		ll t;
		cin >> t;
		t -= x;
		if (t < x)t *= -1;
		if (i == 0)ans = t;
		if (t == 0)continue;
		ans = gcd(t, ans);
	}
	if (ans < 0)ans *= -1;
	dump(ans);
}

Measured memory_bytes: 256
S = input()
N = int(input())
Q = [[] for _ in range(N)]
for i in range(N):
    line = input().split()
    Q[i] = line
reverse = 0
r_b = ""
r_f = ""
for i in range(N):
    if Q[i][0] == '1' :
        reverse = (reverse + 1) % 2
    else :
        if reverse == 0 :
            if Q[i][1] == '1' :
                r_f = Q[i][2] + r_f
            else :
                r_b = r_b +Q[i][2]
        else:
            if Q[i][1] == '1':
                r_b = r_b +Q[i][2]
            else:
                r_f = Q[i][2] + r_f
if reverse == 0 :
    print(r_f + S + r_b)
else:
    r_f = r_f[::-1]
    r_b = r_b[::-1]
    S = S[::-1]
    print(r_b + S + r_f)

Measured memory_bytes: 40700
from functools import reduce

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b): return a * b // gcd(a, b)

def lcm_list(A): return reduce(lcm, A)

MOD = 10**9 + 7

N = int(input())
*A, = map(int, input().split())
L = lcm_list(A)
ans = 0
for a in A:
    ans += L // a
print(ans % MOD)

Measured memory_bytes: 4708
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a:usize = read();
    let b:usize = read();
    let s:Vec<char> = read::<String>().chars().collect();
    let num = s.iter().filter(|&&x| x.is_numeric()).count();
    if s[a] == '-' && num == a + b {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
#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 (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N;
LL T;
LL A[200001];
int main(){
	cin>>N>>T;
	REP(i,N){
	    cin>>A[i];
	}
	LL ans=0;
	REP(i,N){
	    if(i!=N-1){
	       ans+=min(T,A[i+1]-A[i]);
	    }else{
	       ans+=T;
	    }
	}
        cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5000 + 10;
const int INF = 1e9 + 10;
int n, k;
int p[maxn], c[maxn], vis[maxn];
ll ans;
ll sum[maxn], f[maxn];
ll calc(int x)
{
	f[0] = -INF;
	memset(vis, 0, sizeof vis);
	int cur = x, i;
	for(i = 1; ; ++i)
	{
		cur = p[cur];
		sum[i] = sum[i - 1] + c[cur];
		f[i] = max(f[i - 1], sum[i]);
		if(!vis[cur]) vis[cur] = i;
		else break;
	}
	if(k <= i) return f[k];
	ll cycle = sum[i] - sum[vis[cur]];
	if(cycle <= 0) return f[i];
	int cnt = (k - vis[cur]) / (i - vis[cur]), t = vis[cur] + (k - vis[cur]) % (i - vis[cur]);
	return max(f[t] + cnt * cycle, f[i] + (cnt - 1) * cycle);
}
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i) scanf("%d", &p[i]);
	for(int i = 1; i <= n; ++i) scanf("%d", &c[i]);
	for(int i = 1; i <= n; ++i)
		ans = (i == 1 ? calc(i) : max(ans, calc(i)));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 4032
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

string strRev(string str) {
	string res = str;
	for (int i = 0; i < res.size() / 2; i++) {
		swap(res[i], res[res.size() - 1 - i]);
	}
	return res;
}

int main(void) {
	int N;
	cin >> N;
	cin.ignore();
	for (int i = 0; i < N; i++) {
		string str;
		getline(cin, str);
		
		set<string> poss;
		for (int ci = 1; ci < str.size(); ci++) {
			string s1 = str.substr(0, ci);
			string s2 = str.substr(ci);
			
			poss.insert(s1 + s2);
			poss.insert(s2 + s1);
			poss.insert(s1 + strRev(s2));
			poss.insert(strRev(s2) + s1);
			poss.insert(strRev(s1) + s2);
			poss.insert(s2 + strRev(s1));
			poss.insert(strRev(s1) + strRev(s2));
			poss.insert(strRev(s2) + strRev(s1));
		}

		cout << poss.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1296
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        long mod = (long)Math.pow(10,9)+7;
        int n = sc.nextInt();
        long[] m = sc.nextLongArray(n);
        System.out.println(gcd(m));
    }
    
    private static long gcd(long a, long b){
        while (b > 0)
        {
            long temp = b;
            b = a % b; // % is remainder
            a = temp;
        }
        return a;
    }
    
    private static long gcd(long[] input){
        long result = input[0];
        for(int i = 1; i < input.length; i++)
        {
            result = gcd(result, input[i]);
        }
        return result;
    }

}


class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 41268
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    int left = 1,right = n;
    while(m--){
        int l,r;
        cin >> l >> r;
        left = max(left,l);
        right = min(right,r);
    }
    cout << max(right - left + 1,0) << endl;
}


Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using pos = pair<pair<int, int>, int>; //座標、操作回数
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    int H, W; cin >> H >> W;
    vector<vector<char>> grid(H+2, vector<char>(W+2, '#'));
    int cnt = 0; queue<pos> que;
    for(int i=1; i<=H; i++){
        string s; cin >> s;
        for(int j=1; j<=W; j++){
            grid[i][j] = s[j-1];
            if(grid[i][j] == '#'){
                pos p{{i, j}, 0};
                que.push(p);
                cnt++;
            }
        }
    }
    int res = 0;
    while(cnt < H*W){
        pos p = que.front(); que.pop();
        int y = p.first.first, x = p.first.second, cost = p.second;
        rep(i, 4){
            int ny = y + dy[i], nx = x + dx[i];
            if(grid[ny][nx] == '#')continue;
            pos np = {{ny, nx}, cost+1};
            que.push(np);
            grid[ny][nx] = '#';
            res = cost + 1;
            cnt++;
        }
    }
    cout << res << ln;
}


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

unordered_map<char, int > sc;
int n, k, r, s, p, ans = 0;
string ma, pe;

int main() {
	cin >> n >> k >> r >> s >> p >> ma;
	sc['r'] = r, sc['s'] = s, sc['p'] = p;
	for(auto i : ma) {
		if(i == 'r') pe.push_back('p');
		else if(i == 's') pe.push_back('r');
		else pe.push_back('s');
	}
	for(int i = k; i < (int)pe.size(); ++i)
		if(pe[i] == pe[i - k])
			pe[i] = 'f';
	for(auto i : pe)
		ans += sc[i];
	cout << ans;
	return 0;
}

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

using namespace std;

int n, m;
int a[5010], b[5010][201];
int sp[201][13][5010], lg[5010];
long long pref[5010];
long long ans = 0;

void buildSp(){
	for(int k = 1; k <= m; k++){
		for(int i = 1; i <= n; i++) sp[k][0][i] = b[i][k];

		for(int j = 1; j < 13; j++){
			for(int i = 1; i <= n; i++){
				if(i + (1 << (j - 1)) > n) break;
				sp[k][j][i] = max(sp[k][j - 1][i], sp[k][j - 1][i + (1 << (j - 1))]);
			}
		}
	}
}

int query(int k, int i, int j){
	int p = lg[j - i + 1];
	return max(sp[k][p][i], sp[k][p][j - (1 << p) + 1]);
}

void calc(int l, int r, int optL, int optR){
	if(l > r) return;
	int mid = (l + r) >> 1;
	int opt; long long val;
	opt = val = -1;

	for(int i = max(mid, optL); i <= optR; i++){
		long long tmp = 0;
		for(int j = 1; j <= m; j++) tmp += query(j, mid, i);

		tmp -= pref[i - 1] - pref[mid - 1];

		if(val < tmp){
			val = tmp, opt = i;
		}
	}

	ans = max(ans, val);
	calc(l, mid - 1, optL, opt);
	calc(mid + 1, r, opt, optR);
}

int main(){
	for(int i = 2; i <= 5000; i++) lg[i] = lg[i >> 1] + 1;

	scanf("%d%d", &n, &m);

	for(int i = 1; i < n; i++) scanf("%d", &a[i]), pref[i] = pref[i - 1] + a[i];

	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			scanf("%d", &b[i][j]);

	buildSp();

	calc(1, n, 1, n);

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

	return 0;
}

Measured memory_bytes: 55168
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 998244353;
const int e = 5069;
const int base = 311;

// dung igt thay cho gt luc tinh giai thua
// 3
// cach tao hoan vi tu n so : n*(n+1)/2;

int main()
{
    ll H, W;
    ll h, w;
    cin >> H >> W;
    cin >> h >> w;
    cout << H*W - W*h - H*w + h*w;
}


Measured memory_bytes: 256
def main():
    d = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
         'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    S = input()
    print(d[d.index(S) + 1])


if __name__ == '__main__':
    main()


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

int main() {
	int a,b;
	cin >> a >> b;
	int c = b-a;
	int ans = 0;
	for (int i= 0;i < c;i++) {
		ans += i + 1;
	}
	ans -= b;
	cout << ans;
}

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

int main() {
  int64_t N;
  cin >> N;
  int64_t i = 2;
  int64_t min_step = N - 1;
  while (i * i <= N){
    if (N % i == 0){
      min_step = min(min_step, (i + N / i) - 2);
    }
    i++;
  }
  cout << min_step << endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
if n>=m:
  print(0)
else:
  d=[0]*(m-1)
  for i in range(m-1):
    d[i]+=(x[i+1]-x[i])
  d.sort()
  ans=0
  for i in range(m-n):
    ans+=d[i]
  print(ans)

Measured memory_bytes: 13960
#include <stdio.h>

int cards_num;
int cards[50];

void cards_init(int num) {
	int i;
	cards_num=num;
	for(i=0;i<num;i++)cards[i]=i;
}

void rs(int c) {
	int cards2[50];
	int a_start,a_end;
	int b_start,b_end;
	int c_pos=0;
	int i;
	b_start=0;b_end=cards_num/2;
	a_start=b_end;a_end=cards_num;
	while(a_start<a_end || b_start<b_end) {
		for(i=0;a_start<a_end && i<c;i++)cards2[c_pos++]=cards[a_start++];
		for(i=0;b_start<b_end && i<c;i++)cards2[c_pos++]=cards[b_start++];
	}
	for(i=0;i<cards_num;i++)cards[i]=cards2[i];
}

int main(void) {
	int i;
	int cn,rsn,c;
	while(scanf("%d%d",&cn,&rsn)==2) {
		cards_init(cn);
		for(i=0;i<rsn;i++) {
			scanf("%d",&c);
			rs(c);
		}
		printf("%d\n",cards[cn-1]);
	}
	return 0;
}

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

int main() {

  int N;
  cin >> N;

  string S;
  cin >> S;

  int x = 0;
  int answer = 0;

  for (int i = 0; i < N; i++) {
    if (S[i] == 'I') {
      x++;
    } else {
      x--;
    }
    answer = max(answer, x);
  }

  cout << answer << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		String s = scan.next();
		char[] c = new char[s.length()];
		for (int i = 0; i < s.length(); i++) {
			c[i] = s.charAt(i);
		}
		boolean f = true;
		if (c[a] == '-') {
			for (int i = 0; i < a; i++) {
				if (c[i] == '-') {
					f = false;
				}
			}
			for (int i = a+1; i <= a+b; i++) {
				if (c[i] == '-') {
					f = false;
				}
			}
		}
		else {
			f = false;
		}
		if (f) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w;cin>>h>>w;
  string s;
  vector<P> starts;
  vector<vector<char>> maze(h,vector<char>(w));
  rep(i,h) {
    cin>>s;
    rep(j,w) {
      maze[i][j]=s[j];
      if(s[j]=='.') starts.emplace_back(P(i,j));
    }
  }
  ll x,y,nx,ny,ans=-1e9;
  lvector dx{1,0,-1,0},dy{0,1,0,-1};
  vector<lvector> dist(h+1,lvector(w+1,-1));
  queue<P> que;
  for(auto s:starts) {
    que.push(s);
    dist[s.first][s.second]=0;
    while(que.size()) {
      P p=que.front();que.pop();
      x=p.first,y=p.second;
      rep(d,4) {
        nx=x+dx[d],ny=y+dy[d];
        if(0<=nx&&0<=ny&&nx<h&&ny<w&&maze[nx][ny]=='.'&&dist[nx][ny]==-1) {
          dist[nx][ny]=dist[x][y]+1;
          que.push(P(nx,ny));
        }
      }
    }
    rep(i,h)rep(j,w) {ans=max(ans,dist[i][j]);dist[i][j]=-1;}
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int A=stdIn.nextInt();
		int B=stdIn.nextInt();
		if(A>9||B>9)
			System.out.println(-1);
		else
			System.out.println(A*B);
	}
}

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

int main(){
   int N;
   std::cin >> N;
   std::vector<int> a(N);
   for (int i=0; i<N; i++){
      std::cin >> a.at(i);
   }
   int cnt = 0;
   for (int i=0; i<N; i++){
      int tmp = a.at(i);
      if (i+1 == a.at(tmp-1)){
         cnt++;
      }
   }
   std::cout << cnt/2 << std::endl;
}



Measured memory_bytes: 3764
package main

import (
	"fmt"
	"math"
)

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

	// 1枚ずつ買った方が良い？ハーフを2枚買った方が良い？
	x1 := min(A+B, C*2)
	// 少なくとも少ない枚数までは購入する
	y1 := min(X, Y)
	// 安い金額 x 枚数
	ans += x1 * y1

	// XとYのうち枚数が多い方を適当に埋める
	m1 := X - y1
	m2 := Y - y1

	if m1 < m2 {
		ans += min((m1+m2)*C*2, (m1+m2)*B)
	} else {
		ans += min((m1+m2)*C*2, (m1+m2)*A)
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) < abs(a[j]) }


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
n=int(input())
E=[]
for i in range(n-1):
  u,v,w=map(int,input().split())
  E.append([u,v,w])
def BFS(edges,N):
  roots=[[] for i in range(N)]
  for a,b,c in edges:
    roots[a-1]+=[(b-1,c)]
    roots[b-1]+=[(a-1,c)]
  dist=[-1]*N
  stack=[]
  stack.append(0)
  dist[0]=0
  while stack:
    label=stack.pop(-1)
    for i,c in roots[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        stack+=[i]
  return dist
D=BFS(E,n)
for i in range(n):
  print(0 if D[i]%2==0 else 1)

Measured memory_bytes: 58396
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, i;
  cin >> n;
  i=n;
  a=0;
  while(n>0) {
    a += n % 10;
    n /= 10;
  }
    if(i % a == 0) {
      cout << "Yes" << endl;
    }
  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;

priority_queue<long long>q1,q2;

long long sum1,sum2;

long long ans1[100100],ans2[100100],a[300100];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= 3 * n;i++)
	{
		scanf("%d",&a[i]);
		if(i <= n)
			q1.push(-a[i]),sum1 += a[i];
		else if(i > 2 * n)
			q2.push(a[i]),sum2 += a[i];
	}
	ans1[0] = sum1,ans2[n] = sum2;
	for(int i = n + 1;i <= 2 * n;i++)
	{
		if(-a[i] <= q1.top())
		{
			sum1 += a[i] + q1.top();
			q1.pop(),q1.push(-a[i]);
		}
		ans1[i - n] = sum1;
	}
	for(int i = 2 * n ;i >= n + 1;i--)
	{
		if(a[i] <= q2.top())
		{
			sum2 += a[i] - q2.top();
			q2.pop(),q2.push(a[i]);
		}
		ans2[i - n - 1] = sum2;
	}
	long long ans = -0x7fffffffffffffff;
	for(int i = 0;i <= n;i++)
		ans = max(ans1[i] - ans2[i],ans);
	printf("%lld\n",ans);
}

Measured memory_bytes: 5876
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include "iomanip"
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <stack>


using namespace std;


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


    int n, k, tmp;
    cin >> n >> k;
    int count = 0;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        count += tmp >= k;
    }
    cout << count;
    return 0;
}



Measured memory_bytes: 256
N, W = map(int, input().split())
ws = [0] * N
vs = [0] * N

for i in range(N):
  ws[i], vs[i] = map(int, input().split())

dp_table = [[0]*(W+1) for _ in range(N+1)]

for i in range(1,N+1):
  for w_now in range(1,W+1):
    if w_now - ws[i-1] >= 0:
      dp_table[i][w_now] = max( dp_table[i-1][w_now], dp_table[ i-1][w_now-ws[i-1] ] + vs[i-1] )
    else:
      dp_table[i][w_now] = dp_table[i-1][w_now]
print(int(dp_table[-1][-1]))

Measured memory_bytes: 120300
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <math.h>
#include <stdio.h>
using namespace std;
int main(void){
    int n, a;
    cin >> n;
    int x[n];
    int y[n];
    double q=0,w=0,e=0,r=0;
    for (int i = 0; i < n; i++) {
        cin >> a;
        x[i] = a;
    }
    for (int i = 0; i < n; i++) {
        cin >> a;
        y[i] = a;
    }
    for (int i = 0; i < n; i++) {
        q += abs(x[i] - y[i]);
        w += (x[i] - y[i]) * (x[i] - y[i]);
        e += abs(x[i] - y[i]) * abs(x[i] - y[i]) * abs(x[i] - y[i]);
        if(r < abs(x[i] - y[i])){
            r = abs(x[i] - y[i]);
        }
    }
    w = sqrt(w);
    e = pow(e,1.0/3.0);
    printf("%f\n%f\n%f\n%f",q,w,e,r);

    return 0;
}




Measured memory_bytes: 3340
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int s, d, t;
    float sp;
    cin >> d >> t >> s;
    sp = (float)d/t;
    if(sp <= s)
    cout << "Yes";
    else
    cout << "No";
    return 0;
    
}
    

Measured memory_bytes: 3632
#include <stdio.h>

int main(){
    int p,q,r, min, aux;
    scanf ("%d%d%d", &p, &q, &r);
    min = p+q;
    aux = r+q;
    if (aux <= min){
        min = aux;
    }
    aux = p+r;
    if (aux <= min){
        min = aux;
    }
    printf ("%d\n", min);
}

Measured memory_bytes: 128