akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(ll i=0;i<((ll)n);i++)
#define REP1(i,n) for(ll i=1;i<((ll)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll mpow(ll m, ll p){
  ll power = m;
  ll res = 1;
  while(p>0){
    if(p&1)
      res = res*power%MOD;
    power = (power*power)%MOD;
    p /= 2;
  }

  return res;
}

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

  ll n;
  cin>>n;
  vll t(n),a(n);
  REP(i,n)cin>>t[i];
  REP(i,n)cin>>a[i];

  ll lim=0;
  bool flag=true;
  bool ansflag=false;
  REP(i,n){
    if(t[i]==a[i]){
      flag=false;
      lim=t[i];
    }
    if(flag){
      if(t[i]>a[i])
        ansflag=true;
    }
    else{
      if(t[i]<a[i])
        ansflag=true;
    }
  }
  REP(i,n){
    if(t[i]>lim || a[i]>lim)
      ansflag=true;
  }
  if(ansflag){
    cout<<0<<endl;
    return 0;
  }


  ll l=n-1,r=0;
  REP(i,n){
    if(t[i]==a[i]){
      l=min(l,i);
      r=max(r,i);
    }
  }

  ll ptl=1;
  for(ll i=1; i<=l; i++){
    if(t[i-1]==t[i])
      ptl=ptl*t[i]%MOD;
  }

  ll ptr=1;
  for(ll i=n-2; i>=r; i--){
    if(a[i+1]==a[i])
      ptr=ptr*a[i]%MOD;
  }

  ll ans=ptl*ptr%MOD;
  ans = ans*mpow(lim,max(r-l-1,0LL))%MOD;
  cout<<ans<<endl;

}



Measured memory_bytes: 1792
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def main():
    N ,Q = ints_raw()
    origST = []

    for idx  in range(N):
        S,T,X = ints_raw()
        origST.append([S-X,T-X,X])
    Ds = [int(input()) for _ in range(Q)]

    origST.sort()
    stidx = 0
    cur_set = []
    for q in Ds:

        while stidx < len(origST):
            st = origST[stidx]
            if st[0] > q:
                break
            heappush(cur_set,(st[2],st[1]))
            stidx+=1
        while cur_set and cur_set[0][1] <=q:
            heappop(cur_set)
        if len(cur_set)==0:
            print(-1)
        else:
            print(cur_set[0][0])
main()


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

int n;

int main() {
	cin>>n;
	if(n%10==2 or n%10==4 or n%10==5 or n%10==7 or n%10==9) cout<<"hon\n";
	else if(n%10==0 or n%10==1 or n%10==6 or n%10==8) cout<<"pon\n";
	else if(n%10==3) cout<<"bon\n";
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  set<int> G, H;
  for(int i = 0; i <= F; i++){
    for(int j = 0; j <= F; j++){
      int I = 100 * A * i + 100 * B * j;
      int J = C * i + D * j;
      if(I <= F) G.insert(I);
      if(J <= F) H.insert(J);
    }
  }
  int K = 1, L = 0;
  for(int g : G){
    for(int h : H){
      if(g + h > F || 100 * h > E * g) continue;
      if(L * g <= K * h){
        K = g;
        L = h;
      }
    }
  }
  cout << K + L << " " << L << endl;
  return 0;
}


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

int n;
long long a[300005];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= 3 * n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + (3 * n) + 1);//
	long long ans = 0;
	for (int i = n + 1; i <= 3 * n; i += 2) {
		ans += a[i];
	}
	cout << ans;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int a,b,c; cin >> a >> b >> c;
    if(a*a+b*b==c*c) cout << a*b/2 << endl;
    else if(b*b+c*c==a*a) cout << b*c/2 << endl;
    else cout << a*c/2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	if (A * B >= C * D) printf("%d\n", A * B);
	else printf("%d\n", C * D);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
using namespace std;

int N;

int main() {
    cin >> N;
    vector <int> V(N,0), DP(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> V[i];
    }
    DP[0] = 0; DP[1] = abs(V[1] - V[0]);
    for (int i = 2; i < N; ++i)
        DP[i] = min(DP[i - 1] + abs(V[i] - V[i - 1]), DP[i - 2] + abs(V[i] - V[i - 2]));
    cout << DP[N - 1];
    return 0;
}



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

#define ll long long
#define ar array

int n, dp[3][2];

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

	cin >> n;
	cin >> dp[0][0] >> dp[1][0] >> dp[2][0];
	for (int i=1, a, b, c; i<n; ++i) {
		cin >> a >> b >> c;
		for (int j=0; j<3; ++j) dp[j][1]=dp[j][0];
		dp[0][0]=a+max(dp[1][1], dp[2][1]);
		dp[1][0]=b+max(dp[0][1], dp[2][1]);
		dp[2][0]=c+max(dp[0][1], dp[1][1]);
	}
	cout << max({dp[0][0], dp[1][0], dp[2][0]});
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 3608
N, K = map(int, input().split())

sum_pattern_num = 0

for num_cnt in range(K, N+2):
    if num_cnt == K:
        min_sum_frac = sum([i for i in range(0, K)])
        max_sum_frac = sum([i for i in range(N - K + 1, N + 1)])
    else:
        min_sum_frac = min_sum_frac + (num_cnt - 1)
        max_sum_frac = max_sum_frac + (N - num_cnt + 1)
    sum_pattern_num = \
        (sum_pattern_num + (max_sum_frac - min_sum_frac + 1)) % 1000000007

print(sum_pattern_num)

Measured memory_bytes: 16848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main(){
  ll n;
  cin>> n;
  vll v(n),c(n);
  for (ll i=0;i<n;i++) {
    cin >> v[i];
  }
  for (ll i=0;i<n;i++) {
    cin >> c[i];
  }
  
  vll a(n);
  ll ans=0;
  for (ll i=0;i<n;i++) {
    a[i]=v[i]-c[i];
    if (a[i]>0) {
      ans+=a[i];
    }
  }
  
  cout<<ans;
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	DUMP(n);
	int a1 = (int)sqrt(n);
	DUMP(a1);
	int cnt = 1;
	int ans = INT_MAX;
	DUMP(ans);
	while(cnt <= a1){
		if(n % cnt == 0){
			stringstream ss;
			ss << n/cnt;
			string s;
			ss >> s;
			ans = min(ans,SZ(s));
		}
		cnt++;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    REP (i, b) cout << a;
    cout << endl;
}

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

int main() {
	string s;
	cin >> s;
	string k = "Good";
	for(int i = 0;i < 3;i++)
	{
		if(s.at(i) == s.at(i+1))
		{
			k = "Bad";
		}
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int w,h,i,j;
  while(1) {
    scanf("%d %d\n",&h,&w);
    if(h==0 && w==0) break;
    for(i=1;i<=h;i++) {
      for(j=1;j<=w;j++) {
        (i+j)%2==0 ? printf("#") : printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2052
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())

for _ in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if A[y][x] == b:
                A[y][x] = -1

for y in range(3):
    f = True
    for x in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

for x in range(3):
    f = True
    for y in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print('Yes')
        exit()

f = True
for x in range(3):
    if A[x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

f = True
for x in range(3):
    if A[2 - x][x] != -1:
        f = False
if f:
    print('Yes')
    exit()

print('No')


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int n;
int a[20005];
signed main()
{
	int i,j,k,ans=0;
	cin>>n;
	for (i=1;i<=n;i++)
		cin>>a[i];
	int tot=0;
	for (i=1;i<=n;i++)
	{
		if (i%2==1&&a[i]%2==1)
			tot++;
	}
	cout<<tot<<endl;
	return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
using std::cin;using std::cerr;
using std::max;using std::min;
#define N 100005
#define ll long long
#define db double
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
int n,Max,A[N],cnt[2][N],Max1[2],id1[2],Max2[2],id2[2],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&A[i]),cnt[i&1][A[i]]++,Max=max(Max,A[i]);
	for(int i=0;i<2;i++)
		for(int j=1;j<=Max;j++)
			if(cnt[i][j]>Max1[i]) Max2[i]=Max1[i],id2[i]=id1[i],Max1[i]=cnt[i][j],id1[i]=j;
			else if(cnt[i][j]>Max2[i]) Max2[i]=cnt[i][j],id2[i]=j;
	if(id1[0]^id1[1]) ans=max(ans,Max1[0]+Max1[1]);
	else ans=max(ans,max(Max1[0]+Max2[1],Max2[0]+Max1[1]));
	printf("%d\n",n-ans);
	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main()
{
	int n;
	cin >> n;
	int m[n+1];
	vector<int> vec;
	for(int i=0;i<n;i++)
	{
		int s;
		cin >> s;
		cin >> m[s];
		vec.pb(m[s]);
	}
	sort(vec.begin(),vec.end(),greater<int>());
	int t = vec[0];
	int b;
	for(int i=1;i<n+1;i++)
	{
		if(m[i]==t)
		{
			b=i;
			break;
		}
	}
	cout << b << ' ' << m[b] << endl;
	return 0;
}

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

int main() {
    int N, two = 0, four = 0, other = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a % 4 == 0) four++;
        else if (a % 2 == 0) two++;
        else other++;
    }

    if (two > 0) other++;

    if (four + 1 >= other) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
x = int(input())
n = x // 100 + 10
for i1 in range(n+1):
  for i2 in range(n+1-i1+1):
    for i3 in range(n+1-i1-i2+1):
      for i4 in range(n+1-i1-i2-i3+1):
        for i5 in range(n+1-i1-i2-i3-i4+1):
          for i6 in range(n+1-i1-i2-i3-i4-i5+1):
            if 100*i1+101*i2+102*i3+103*i4+104*i5+105*i6 == x:
              if i1<=1000000 and i2<=1000000 and i3<=1000000 and i4<=1000000 and i5<=1000000 and i6<=1000000:
                print(1)
                exit()
print(0)

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

sumA=0
for i in range(N):
    for j in range(N):
        if A[i]>A[j] and i>j:
            sumA+=(K-1)*K//2
        if A[i]>A[j] and i<j:
            sumA+=K*(K+1)//2
    sumA=sumA % (10**9+7)
print(sumA)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int n;
vector<vector<int>> g;
vector<bool> seen;
int ans = 0;

void dfs(int v) {
    if (seen[v]) return;
    seen[v] = true;
    bool flag = true;
    rep(i, n) if (!seen[i]) flag = false;
    if (flag) ans++;
    for (int u : g[v]) dfs(u);
    seen[v] = false;
}

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

    int m;
    cin >> n >> m;
    
    g.resize(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    seen.resize(n);
    dfs(0);
    cout << ans << endl;
}


Measured memory_bytes: 3632
n = gets.chomp
x = gets.chomp.split.map(&:to_f)
y = gets.chomp.split.map(&:to_f)

xy = x.zip(y).map{|v| (v[0] - v[1]).abs }

(1..3).each do |d|
  puts xy.inject(0){|total, v| total += v ** d } ** (1.0/d)
end

puts xy.max

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main() { 
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) {
        cin >> A[i];
    }
    sort(ALL(A));
    bool ans = true;
    REP(i, N - 1) {
        if (A[i] == A[i + 1]) {
            ans = false;
        } 
    }

    cout << (ans == true ? "YES" : "NO") << endl;
    return 0; 
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

const int MOD = (int)1e9 + 7;

int add(int x, int y) {
	return (x + y >= MOD ? x + y - MOD : x + y);
}

int mult(int x, int y) {
	return (x * 1LL * y) % MOD;
}

const int MAX_N = (int)1e5 + 777;
const int MAX_K = 32;

int dp[MAX_N][MAX_K];

void solve() {
	dp[0][0] = 1;

	for(int i = 0; i < MAX_N - 1; ++i) {
		for(int j = 0; j < MAX_K; ++j) {
			for(int j2 = j; j2 < MAX_K; ++j2) {
				dp[i + 1][j2] = add(dp[i + 1][j2], dp[i][j]);
			}
		}
	}

	int n, m;
	int answ = 1;
	cin >> n >> m;

	for(int i = 2; i * i <= m; ++i) {
		if(m % i == 0) {
			int cnt = 0;

			for(; m % i == 0; m /= i)
				++cnt;

			answ = mult(answ, dp[n][cnt]);
		}
	}

	if(m > 1)
		answ = mult(answ, dp[n][1]);

	cout << answ << '\n';
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

// MOD確認

ll A[20];

int main(){
   string S;
   cin >> S;
   if(S[S.size()-1] != 's') cout << S + "s" << endl;
   else cout << S + "es" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;

ll a[maxn];

void solve() {
	ll n,cur=0,fee=1000; cin >> n;
	vector<ll> up, down, res;
	rep(i,0,n) cin >> a[i];
	if (a[0] < a[1]) down.push_back(0);
	rep(i,1,n-1) {
		if (a[i] >= a[i-1] && a[i] >= a[i+1]) up.push_back(i);
		else if (a[i] <= a[i-1] && a[i] <= a[i+1]) down.push_back(i);
	}
	if (a[n-1] > a[n-2]) up.push_back(n-1);
	// for(auto c:up) cout << c << ' ';
	// 	cout << '\n';
	// for(auto c:down) cout << c << ' ';
	// 	cout << '\n';
	ll p1=0,p2=0,l1=up.size(),l2=down.size();
	res.push_back(1000);
	rep(i,0,n) {
		if (p1 < l1 && up[p1] == i) {
			fee += cur * a[i];
			cur = 0;
			p1++;
//			cout << cur << "---" << fee << '\n';
			res.push_back(fee);
			continue;
		}
		if (p2 < l2 && down[p2] == i) {
			cur += fee/a[i];
			fee -= fee/a[i]*a[i];
			p2++;
			continue;
		}
	}
	sort(res.begin(), res.end(), greater<ll>());
	cout << res[0] << '\n';
}

int main(int argc, char * argv[]) 
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
	//freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

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

    return 0;
}

Measured memory_bytes: 3672
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)

def f(j, max1, max2):
    L_temp = L[j+1:]
    # print("max1 = ", max1, "max2 = ", max2, L_temp)
    dif = max1 - max2
    left = -1
    right = len(L_temp)
    while right - left != 1:
        temp = (left+right)//2
        if dif < L_temp[temp]:
            left = temp
        else:
            right = temp
    return left+1


ans = 0
max1 = 0
max2 = 0
for i in range(N):
    max1 = L[i]
    for j in range(i+1, N-1):
        max2 = L[j]
        ans += f(j, max1, max2)
        # print("ans = ", ans)
print(ans)


Measured memory_bytes: 50872
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  string S;
  cin >> S;
  int L=S.length(),check=0;
  for(int i=0;i<7;i++){
    string S2=S.substr(0,i)+S.substr(L-7+i,7-i);
    if(S2=="keyence") check=1;
  }
  if(check==1) cout << "YES" << endl;
  else cout <<"NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
//lli p = 1000000007;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    string t;
    cin>>s;
    cin>>t;
    int n1 = s.length();
    int n2 = t.length();

    int min = INT32_MAX;
    for (int i=0;i<n1;i++)
    {
        if (i+n2<=n1)
        {
            int ans = 0;
            for (int j=0;j<n2;j++)
            {
                if (s[i+j]!=t[j]) ans++;
            }
            if (ans<min) min = ans;
        }
    }

    cout<<min<<"\n";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    ll p = 1;
    int n;
    cin >> n;
    ll a[n];
    rep(i, n){
        cin >> a[i];
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }

    rep(i, n){
        if(a[i]!=0 && p > (long double)1e18 / a[i]){
            cout << -1 << endl;
            return 0;
        }
        p *= a[i];
    }
    cout << p << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 4332
import sys
sdin = sys.stdin.readline

n, c = map(int, sdin().split())
stc = []
for _ in range(n):
    stc.append(tuple(map(int, sdin().split())))
    
table = [[0]*(10**5) for _ in range(c)]

for s,t,c in stc:
    table[c-1][s-1:t] = [1]*(t-s+1)
    
ans = max(map(sum, zip(*table)))
print(ans)

Measured memory_bytes: 40928
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

const int maxn = 100000;
int num[maxn];
int cun[maxn];

int multi(int a, int b)
{
	int ans1 = 1,ans2=1,k1,k2;
	ans1 = a*b; ans2 = a*b;
	if (ans1!=0&&ans1 / 10 == 0) return ans2;
	while (ans1)// 6789
	{
		k1 = ans1 % 10;
		ans1 /= 10;
		if (ans1)
			k2 = ans1 % 10;
		else break;
		if (k2 != k1 - 1) return 0;
	}
	return ans2;
}

int main()
{
	int t,i,duide,k=1,mans,count=0;
	scanf("%d",&t);
	
	for (int i = 1; i <= t; i++)
	{
		scanf("%d", &num[i]);
		if (num[i] == 0) count++;
	}
	if (count == t) { printf("0\n"); return 0; }
	for(int i=1;i<=t-1;i++)
		for (int j = i+1; j <= t; j++)
		{

			duide = (multi(num[i], num[j]));
			if (duide)			
				cun[k++] = duide;			
		}
	mans = cun[1];
	for (int i = 2; i <= k; i++)//3 4 11 115 1 2 6 6789
	{
		if (mans < cun[i])
			mans = cun[i];
	}
	if(mans) printf("%d\n",mans);
	else printf("-1\n");
	//for (i = 1; i <= t; i++)
		//printf("%d ", num[i]);
	return 0;

}

Measured memory_bytes: 3236
from math import atan,degrees
a,b,x=map(int,input().split())
if a*a*b>x*2:
  aa,bb=(x/(a*b))*2,b
else:
  x=a*a*b-x
  aa,bb=a,(x/(a*a))*2
print(degrees(atan(bb/aa)))

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

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s;
	cin>>s;
	char prev=s[0];
	int ans=0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!=prev)
		{
			ans++;
			prev=s[i];
		}
	}
	cout<<ans<<'\n';
}

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

namespace MSPC2020
{
    class D
    {
        static void Main(string[] args)
        {
            //var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            //var LRd = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //var X = int.Parse(Console.ReadLine());
            //var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = long.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var total = 1000L;
            var stock = 0L;
            for (int i = 0; i < N - 1; i++)
            {
                var now = A[i];
                var next = A[i + 1];
                if (now < next && 0 < total / now)
                {
                    stock += total / now;
                    total = total % now;
                }
                else if (now > next)
                {
                    if (0 < stock)
                    {
                        total += stock * now;
                        stock = 0;
                    }
                }
            }
            if (0 < stock)
            {
                total += A[N - 1] * stock;
            }
            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 28232
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}


class Sieve_of_Eratosthenes {
public:
	vector<bool> PN;
	
	Sieve_of_Eratosthenes(int x){
		init(x);
	}
	
	void huga(int t, int x){
		if(PN[t]) return;
		for(int i = t*t; i <= x; i+=t)
			PN[i] = true;
	}
	
	void init(int x){
		PN.resize(x+5);
		PN[0]=PN[1]=PN[4]=true;
		for(int i = 6; (i-1)*(i-1) <= x; i+=6)
		huga(i-1,x),huga(i+1,x);
		for(int i = 6; i <= x; i+=6)
			PN[i]=PN[i+2]=PN[i+3]=PN[i+4]=true;
	}
};

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	
	Sieve_of_Eratosthenes S(210000);
	
	int N;
	
	cin>>N;
	
	for(int i = N; ; i++){
		if(S.PN[i] == false){
			cout<<i<<endl;
			return 0;
		}
	}
	
	return 0;
}

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

#define mod 1000000007

#define rep(i, n) for(int i=0; i<n; ++i)

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N, K;
	string S;
	int count = 0;
	
	cin >> N >> K >> S;
	
	rep(i, N - 1)
		if(S[i] == S[i+1])
			count++;
	
	int ans = min(count + 2 * K, N - 1);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n; cin >> n;
	vl a(n); rep(i,n) cin >> a[i];
	ll ok = 1e6; ll ng = 0;
	while(ok-ng>1){
		ll mid = (ok+ng)/2;
		stack<P> st;
		bool flag = true;
		rep(i,n){
			if(mid == 1){
				if(i<n-1 && a[i+1] < a[i]){
					flag = false;
					break;
				}
			}
			if(st.empty()) st.emplace(a[i],1);
			else{
				if(st.top().first > a[i]){
					while(!st.empty() && st.top().first > a[i]){
						st.pop();
					}
					if(st.empty()){
						st.emplace(a[i],2);
						continue;
					}
					if(st.top().first == a[i]){
						ll pre = a[i];
						bool emp = false;
						while(st.top().first==pre && st.top().second==mid){
							pre--;
							if(pre == 0) break;
							st.pop();
							if(st.empty()){
								emp = true;
								st.emplace(pre,2);
								break;
							}
						}
						if(pre == 0){
							flag = false;
							break;
						}
						if(emp) continue;
						if(st.top().first == pre){
							P p = st.top(); st.pop();
							p.second++;
							st.emplace(p);
						}else{
							st.emplace(pre,2);
						}
					}else{
						st.emplace(a[i],2);
					}
				}else if(st.top().first < a[i]){
					st.emplace(a[i],1);
				}else{
					if(st.top().second < mid){
						P p = st.top(); st.pop();
						p.second++;
						st.emplace(p);
						continue;
					}
					ll pre = a[i];
					bool emp = false;
					while(st.top().first==pre && st.top().second==mid){
						pre--;
						if(pre == 0) break;
						st.pop();
						if(st.empty()){
							emp = true;
							st.emplace(pre,2);
							break;
						}
					}
					if(pre == 0){
						flag = false;
						break;
					}
					if(emp) continue;
					if(st.top().first == pre){
						P p = st.top(); st.pop();
						p.second++;
						st.emplace(p);
					}else{
						st.emplace(pre,2);
					}
				}
			}
		}
		if(flag) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}

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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	long long n,d;
	cin>>n>>d;
	long long ans=0;
	for(long long i=0;i<n;i++){
		long long a,b;
		cin>>a>>b;
		if(d*d>=a*a+b*b) ans++;
	}

	cout<<ans<<endl;

	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

template<typename T>
bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return 1;
	}
	return 0;
}

template<typename T>
bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return 1;
	}
	return 0;
}


Measured memory_bytes: 3616
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    if (b < 2)
        cout << 0;
    else
        cout << (b - 2) / (a - 1) + 1;
    return 0;
}


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

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

const int N = 2e3 + 10;
const ll mod = 1e9 + 7;
int n, m, s[N], t[N];
ll dp[N][N];

int main() {
	n = read(), m = read();
	for (int i = 0; i < n; i++) s[i] = read();
	for (int i = 0; i < m; i++) t[i] = read();
	dp[0][0] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i > 0) dp[i][j] += dp[i - 1][j];
			if (j > 0) dp[i][j] += dp[i][j - 1];
			if (i > 0 && j > 0 && s[i - 1] != t[j - 1]) dp[i][j] += mod - dp[i - 1][j - 1];
			dp[i][j] %= mod;
		}
	}
	printf("%lld\n", dp[n][m]);
	return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

typedef pair<int, int> P; 


int main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;

    while(n > 0) {
        n = n/k;
        ans++;
    }
    
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxs=1<<15|1;
int n,m,f[maxs][16],p[maxs],d[16][16],v[maxs],ans;
int U;
int main(){
	scanf("%d%d",&n,&m);U=(1<<n)-1;
	for(int i=1,x,y,z;i<=m;i++)scanf("%d%d%d",&x,&y,&z),d[x][y]=d[y][x]=z;
	for(int i=1;i<=n;i++)v[1<<i-1]=i;
	for(int s=1;s<=U;s++){
		int t=v[s&-s];
		p[s]=p[s-(1<<t-1)];
		for(int i=t+1;i<=n;i++)
			if(s&(1<<i-1))p[s]+=d[t][i];
	}
	ans=-0x3f3f3f3f;for(int s=0;s<=U;s++)for(int i=0;i<=n;i++)f[s][i]=ans;f[1][1]=0;
	for(int s=1;s<=U;s++){
		for(int i=1;i<=n;i++){
			for(int s0=s;s0;s0=(s0-1)&s)
				if(s0&(1<<i-1))f[s][i]=max(f[s][i],f[(s-s0)|(1<<i-1)][i]+p[s0]);
			for(int j=1;j<=n;j++)
				if(!(s&(1<<j-1))&&d[i][j])
					f[s|(1<<j-1)][j]=max(f[s|(1<<j-1)][j],f[s][i]+d[i][j]);
		}
		if(s&(1<<n-1))ans=max(ans,f[s][n]);
	}
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)ans-=d[i][j];
	printf("%d\n",-ans);
    return 0;
}

Measured memory_bytes: 2432
N = int(input())
count = 0
ans = []
for i in range(N+1):
    count1 = 0
    count2 = 0
    N1 = N - i
    x = i
    for j in reversed(range(7)):
        while x >= 6**j:
            x -= 6**j
            count1 += 1
    for j in reversed(range(6)):
        while N1 >= 9**j:
            N1 -= 9**j
            count2 += 1
    count = count1 + count2
    ans.append(count)
print(min(ans))


Measured memory_bytes: 49372
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl

int main() {
    string s;
    while (cin >> s) {
        int ct[3]{};
        for (char c : s)
            ++ct[c - 'a'];
        int mn = min({ ct[0], ct[1], ct[2] });
        ct[0] -= mn;
        ct[1] -= mn;
        ct[2] -= mn;
        if (ct[0] >= 2 || ct[1] >= 2 || ct[2] >= 2)
            cout << "NO" << endl;
        else
            cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long int ll;
 
int main()
{
 int N;
 int x[100],y[100],h[100];
 scanf("%d",&N);
 int z;
 for(int i=0;i<N;i++)
 {
	scanf("%d %d %d",&x[i],&y[i],&h[i]);
	if(h[i]!=0){z=i;}
 }
 int ans=-1;
 int anx=-1,any=-1;
 for(int i=0;i<=100;i++)
 {
	for(int j=0;j<=100;j++)
	{
		int flg=1;
		int pt=h[z]+abs(i-x[z])+abs(j-y[z]);
		for(int k=0;k<N;k++)
		{
			if(max(pt-abs(i-x[k])-abs(j-y[k]),0)!=h[k]){flg=-1;}
		}
		if(flg==1&&pt>=0){anx=i; any=j; ans=pt;}
	}
 }
 printf("%d %d %d",anx,any,ans);
} 

Measured memory_bytes: 3832
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

vector<int> bfs(int s, int N, vector<vector<int>> &graph){
  vector<int> dist(N, INF);
  dist[s] = 0;
  queue<int> q;
  q.push(s);
  while(!q.empty()){
    int p = q.front(); q.pop();
    for(auto v : graph[p]){
      if(dist[v] != INF) continue;
      dist[v] = dist[p]+1;
      q.push(v);
    }
  }
  return dist;
}

signed main() {
  int N, u, v; 
  cin >> N >> u >> v;
  u--; v--;

  vector<vector<int>> graph(N);
  REP(i, N-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    graph[a].emplace_back(b);
    graph[b].emplace_back(a);
  }

  vector<int> dist1 = bfs(u, N, graph);
  vector<int> dist2 = bfs(v, N, graph);

  int ans = 0;
  REP(i, N) if(dist1[i] <= dist2[i]) chmax(ans, dist2[i]-1);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8064
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')
import numpy as np

def solve():
    A = LLI(3)
    # print(A)
    n = II()
    C = np.array([[0, 0, 0] for _ in range(3)])
    # print(C)
    for i in range(n):
        b = II()
        for j in range(3):
            for k in range(3):
                if A[j][k] == b:
                    C[j][k] = 1

    # print(C)
    # tate, yoko
    for i in range(3):
        # print(C[i, :])
        # print(C[:, i])
        if sum(C[:, i]) == 3 or sum(C[i, :]) == 3:
            print('Yes')
            return

    # naname
    if C[0][0] + C[1][1] + C[2][2] == 3 or C[0][2] + C[1][1] + C[2][0] == 3:
        print('Yes')
        return

    print('No')



if __name__ == '__main__':
    solve()


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

int main() {
    while(true) {
        int a, b;
        string op;
        cin >> a >> op >> b;
        
        if (op == "?") break;
        
        else if (op == "+") {
            cout << a + b << endl;
        }
        
        else if (op == "-") {
            cout << a - b << endl;
        }
        
        else if (op == "*") {
            cout << a * b << endl;
        }
        
        else if (op == "/") {
            cout << a / b << endl;
        }
    }
}


Measured memory_bytes: 3156
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int N;
    long Y;

    private void solve() {
        N = nextInt();
        Y = nextLong();

        for (int i = 0;i <= N;i++) {
            for (int j = 0;j <= N - i;j++) {
                int k = N - i - j;

                long x = 10000L * i;
                long y = 5000L * j;
                long z = 1000L * k;

                if (x + y + z == Y) {
                    out.println(i + " " + j + " " + k);
                    return;
                }
            }
        }
        out.println(-1 + " " + (-1) + " " + (-1));
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,o;
  cin >> s >> o;
  int c=0;
  for(int i=0;i<s.length();i++)
  {
    if(s[i]!=o[i])
      c++;
  }
  cout << c;
}
  

Measured memory_bytes: 3912
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] product = {1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,28,30,32,35,36,40,42,45,48,49,54,56,64,72,81};
    boolean bl = false;
    for(int i = 0; i < product.length; i++){
      if(n == product[i]){
        bl = true;
      }
    }
    if(bl){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 25044
#include <iostream>
 
using namespace std;
 
int main(){
 
  int N,A,B;
 
  cin >> N >> A >> B;
 
  if((N*A) > B){
	cout << B << "\n";
  }
  else{
	cout << N*A << "\n";
  }
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

vector<int> G[MAX_N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n], b[n];
    int f[n+1] = {};
    int g[n+1] = {};
    rep(i,n){
        cin >> a[i];
        f[a[i]]++;
        G[a[i]].push_back(i);
    } 
    rep(i,n){
        cin >> b[i];
        g[b[i]]++;
    } 

    vector<P> v(n+1);
    rep(i,n+1){
        v[i].first = f[i] + g[i];
        if(v[i].first > n){
            cout << "No" << endl;
            return 0;
        }
        v[i].second = i;
    }

    sort(v.begin(), v.end(), greater<P>());

    priority_queue<pair<P,int>> que;
    rep(i,n+1){
        que.push(pair<P,int>(P(v[i].first,g[v[i].second]),v[i].second));
    }

    int c[n] = {};
    int minusloop = -1001001001;
    rep(i,n+1){
        int ite = v[i].second;
        int cnt = g[ite];
        pair<P,int> keep;
        keep.second = -1;
        // cout << i << ' ' << ite << ' ' << cnt << endl;
        while(cnt > 0){
            pair<P,int> p;
            p = que.top();
            que.pop();
            if(p.second == ite){
                keep = p;
                continue;
            }

            int y = p.second;
            int nokori = f[y];
            while(cnt > 0 && f[y] > 0){
                int ite2 = G[y][f[y]-1];
                c[ite2] = ite;
                f[y]--;
                cnt--;
            }

            if(f[y] > 0){
                p.first.first += 100;
                que.push(p);
            } 
        }
        if(keep.second != -1){
            keep.first.first = minusloop;
            minusloop++;
            que.push(keep);
        }
    }   

    cout << "Yes" << endl;
    rep(i,n) cout << c[i] << ' ';
    cout << endl;
    return 0;
}




Measured memory_bytes: 22008
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = (n % 1000 == 0) ? 0 : 1000 - (n % 1000);
        System.out.println(ans);
    }
}


Measured memory_bytes: 35764
#include <bits/stdc++.h>
using namespace std;
int main()
{long long i,k,sum,x,y,z,n,t,d,l,m,j;
cin>>n;
long long a[n+1]={0};
for(i=1;i<=n;i++)
{a[i]=0;}
for(i=1;i<100;i++){
for(j=1;j<100;j++){
for(k=1;k<100;k++){x=(i+j+k)*(i+j+k);x=x-(i*j)-(i*k)-(j*k);
if(x<=n){a[x]++;} }    
}}
for(i=1;i<=n;i++)
{cout<<a[i]<<"\n";}
return 0;
}


Measured memory_bytes: 3660
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
s = [["."] * (w+2)] + [[".", *i, "."] for i in s] + [["."] * (w+2)]
ans = "Yes"
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == "#":
            if s[i-1][j] == "." and s[i][j-1] == "." and s[i][j+1] == "." and s[i+1][j] == ".":
                ans = "No"
                break
print(ans)

Measured memory_bytes: 9200
from collections import deque
H,W = map(int,input().split())
ch,cw = map(lambda x:int(x)-1, input().split())
dh,dw = map(lambda x:int(x)-1, input().split())
M = [input() for _ in range(H)]

cnt = 0
Q = deque()
Q.appendleft((ch, cw, cnt))
VISITED = set()
answer = 0
while Q:
    curh, curw, cnt = Q.popleft()
    if (curh, curw) in VISITED:
        continue
    else:
        answer = max(answer, cnt)
        VISITED.add((curh, curw))
    if (curh,curw) == (dh,dw):
        print(answer)
        break
    minh = curh-2 if curh-2 >= 0 else 0
    minw = curw-2 if curw-2 >= 0 else 0
    maxh = curh+2 if curh+2 <= H-1 else H-1
    maxw = curw+2 if curw+2 <= W-1 else W-1

    for h in range(minh, maxh+1):
        for w in range(minw, maxw+1):
            if M[h][w] == "#" or (h,w) == (curh,curw):
                continue
            else:
                Q.append((h,w,cnt+1))
    for a, b in [(-1,0), (1,0), (0,-1), (0,1)]:
        h,w = curh+a, curw+b
        if (0 <= h < H) and (0 <= w < W) and not M[h][w] == "#":
            Q.appendleft((h,w,cnt))
else:
    print(-1)

Measured memory_bytes: 209152
def sol():
    S = input()
    N = len(S)

    prev = ''
    left = 0
    right = 1
    ans = 0
    while right <= N:
        while right <= N and S[left: right] == prev:
            right += 1

        if right >= N:
            if S[left: right] == prev:
                break
            else:
                ans += 1
                break

        prev = S[left: right]
        left = right
        right += 1
        ans += 1

    print(ans)


sol()

Measured memory_bytes: 40304
from sys import stdin
N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())

chr = S[K-1]
ans = S
for c in range(0,N):
    if S[c] != chr:
        ans = ans.replace(S[c],'*')
print(ans)


Measured memory_bytes: 3060