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

int main(){
    int n,k;
    cin >> n >> k;
    vector<long long> array(n);
    for(int i=0;i<n;i++){
        cin >> array.at(i);
    }
    sort(array.begin(),array.end());
    int size = array.size() -1;
    for(int i=0;i<k;i++){
        if(size < 0) break;
        array.at(size) = 0;
        size --;
    }

    long long sum = 0;
    for(int i=0;i<n;i++) sum+=array.at(i);
    cout << sum << endl;
}

Measured memory_bytes: 4824
import sys
sys.setrecursionlimit(10 ** 5)

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w') 

readline =sys.stdin.readline

# time - O(n2)
def process():
    k,s = map(int,readline().rstrip().split())
    cnt=0

    for i in range(0,k+1):
        for j in range(0,k+1):
            z = s-(i+j)
            if z>=0 and z<=k:
                cnt+=1
    
    return cnt



# for _ in range(int(readline().rstrip())):
print(process())


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

int main(){

    string a,b;

    cin >> a >>b;

    if(a[0]-b[0]>0)cout << '>' << endl;
    else if(a[0]-b[0]<0) cout << '<' << endl;
    else cout << '=' << endl;

    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 5e2 + 5;

char c[MAXN][MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n){
		scanf("%s", &c[i][0]);
	}
	int cnt_row = INF;
	REP(i, 0, n){
		int cnt = 0;
		REP(j, 0, n){
			if (c[i][j] == '#'){
				cnt++;
			}
		}
		if (cnt == 0){
			continue;
		}
		int cur = 0;
		if (c[i][i] == '.'){
			cur++;
			int fl = 0;
			REP(j, 0, n){
				if (c[j][i] == '#'){
					fl = 1;
					break;
				}
			}
			if (!fl){
				cur++;
			}
			cnt++;
		}
		cur += n - cnt;
		cnt_row = min(cnt_row, cur);
	}
	if (cnt_row == INF){
		printf("-1\n");
		return;
	}
	int ans = cnt_row;
	REP(j, 0, n){
		int fl = 0;
		REP(i, 0, n){
			if (c[i][j] == '.'){
				fl = 1;
				break;
			}
		}
		ans += fl;
	}
	printf("%d\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 
 

void func()
{
   ll n;
   cin>>n;
   ll arr[n+1];
   f(i,1,n+1) cin>>arr[i];
   sort(arr+1,arr+n+1);
   reverse(arr+1,arr+n+1);
   vll v;
   v.pb(arr[1]);
   f(i,2,n+1) 
   {
	   v.pb(arr[i]);
	   v.pb(arr[i]);
   }
   
   ll cnt=n-1;
   ll ans=0;
   f(i,0,cnt) ans+=v[i];
   cout<<ans<<endl;

}   
     
     
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE
        
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
       func();
    }
     
    return 0;
}


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

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,m;
  cin >> n >> m;
  ll k[m];
  vector<vector<ll>> s(m);
  for(int i=0;i<m;i++){
    cin >> k[i];
    for(int j=0;j<k[i];j++){
      ll a;
      cin >> a;
      s[i].push_back(a-1);
    }
  }

  ll p[m];
  for(int i=0;i<m;i++)cin >> p[i];

  ll l=0;
  for(int b=0;b<(1<<n);b++){
    ll w=0;
    for(int i=0;i<m;i++){
      ll q=0;
      for(int j=0;j<k[i];j++){
        if(b & (1<<s[i][j]))q++;
      }
      if((q-p[i])%2==0)w++;
    }
    if(w==m){
      l++;
    }
  }

  cout << l << endl;

}

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

using namespace std;

struct Node {
    int key;
    Node* left;
    Node* right;

    Node() : key(0), left(NULL), right(NULL) {}
};

void insert(Node** root, int key) {
    Node* new_node = new Node;
    new_node->key = key;

    if (*root == NULL) {
        *root = new_node;
    } else {
        Node* node1 = *root;
        Node* node2;
        while (node1 != NULL) {
            node2 = node1;
            if (node1->key > key)
                node1 = node1->left;
            else
                node1 = node1->right;
        }

        if (node2->key > new_node->key)
            node2->left = new_node;
        else
            node2->right = new_node;
    }
}

void print_inorder(Node* node) {
    if (node == NULL)
        return;

    print_inorder(node->left);
    cout << ' ' << node->key;
    print_inorder(node->right);
}

void print_preorder(Node* node) {
    if (node == NULL)
        return;

    cout << ' ' << node->key;
    print_preorder(node->left);
    print_preorder(node->right);
}

void delete_tree(Node* node) {
    if (node->left != NULL)
        delete_tree(node->left);
    if (node->right != NULL)
        delete_tree(node->right);
    if (node != NULL)
        delete node;
}

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

    Node* root = NULL;

    for (int i = 0; i < n; ++i) {
        string inst;
        cin >> inst;

        if (inst == "insert") {
            int k;
            cin >> k;
            insert(&root, k);
        } else {
            print_inorder(root);
            cout << '\n';
            print_preorder(root);
            cout << '\n';
        }
    }

    delete_tree(root);
}



Measured memory_bytes: 18708
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define int ll


signed main(){
  int n;
  while(1){

    pair<double,string> l[100]={};
    cin>>n;
    if(!n) break;
    rep(i,n){
      double p,a,b,c,d,e,f,s,m;
      string u;
      cin>>u>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      l[i].S = u;
      a+=b+c+d+e;
      int k = m-1;
      while(k>0){
        a+=d+e;
        k--;
      }
      f*=s;
      f*=m;
      f-=p;
      l[i].F =-(1.0)*f/a;
    }

    sort(l,l+n);

    rep(i,n){
      cout<<l[i].S<<endl;
    }
    cout<<'#'<<endl;
  }
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 5e5+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    int temp=0,ans=0;
    for(int i=0;i<n-1;i++){
        temp=0;
        while(arr[i]>=arr[i+1]){
            i++;
            temp++;
            if(i>=n-1)break;
        }
        ans=max(temp,ans);
    }
    cout<<ans;
}



Measured memory_bytes: 4060
a, b, c, x, y = gets.chomp.split.map(&:to_i)
sum = 0


if c * 2 < a + b
  z = [x, y].min
  x -= z
  y -= z
  sum += c * z * 2
end

if x > 0
  if c * 2 < a
    sum += c * 2 * x
  else
    sum += a * x
  end
end

if y > 0
  if c * 2 < b
    sum += c * 2 * y
  else
    sum += b * y
  end
end

puts sum

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll INF = 1145148931919810;
ll n, m, d;
int main(){
    ll N, M;
    cin >> N >> M;
    cout << min(N, M / 2) + max<ll>(0, M - N * 2) / 4 << endl;
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

int main() {
    i64 N, A, B; cin >> N >> A >> B;

    vector<i64> H(N);
    REP(i, N) cin >> H[i];

    auto possible = [&](i64 t) {
        i64 cnt = 0;
        REP(i, N) {
            i64 rem = H[i] - B * t;
            if (rem <= 0) continue;
            cnt += rem / (A - B) + (rem % (A - B) > 0);
        }
        return cnt <= t;
    };

    i64 ub = 1e9 + 1;
    i64 lb = 0;
    while (ub - lb > 1) {
        i64 mid = (ub + lb) / 2;
        if (possible(mid)) ub = mid;
        else lb = mid;
    }

    cout << ub << endl;

    return 0;
}

Measured memory_bytes: 3920
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
using namespace std;

const double pi = acos(-1);

#define nyan cout<<"(=^•ω•^=)"<<endl;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)

bool solve(string i){
    if(i[0]==i[1]&&i[1]==i[2])return true;
    return false;
}

signed main(){
    int n;cin>>n;
    for(int i=n;i<=999;i++){
        if(solve(to_string(i))){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

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

int main() {
  string x,y;
  cin >> x >> y;
  if (x[0] == y[2] && x[1] == y[1] && x[2] == y[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

int main(void){
  char x[1200];
  int k = 0;
  char l;
  while(cin >> l){
	x[k] = l;
	k++;
  }
  
  int alfabet[26][2];
  for(int i = 0; i < k; i++){
	if(isupper(x[i])){
	  x[i] += 32;
	}
  }
  for(int i = 0; i < 26; i++){
	alfabet[i][0] = i + 97;
  }
  for(int i = 0; i < 26; i++){
	alfabet[i][1] = 0;
  }
  for(int i = 0; i < k; i++){
	for(int j = 0; j < 26; j++){
	  if((char)alfabet[j][0] == (char)x[i]){
		alfabet[j][1]++;
	  }
	}
  }
  for(int i = 0; i < 26; i++){
	cout << (char)alfabet[i][0] << " : " << alfabet[i][1] << endl;
  }
  
  return 0;
}




Measured memory_bytes: 3076
#define errOut(s) \
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
//#include <boost/multi_array.hpp>
//#include <boost/optional.hpp>
//#include <boost/range/adaptors.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int64_t solve(int64_t n, int64_t d, std::vector<int64_t> xs,
              std::vector<int64_t> ys) {
  int64_t ret = 0;
  int64_t dd = d * d;
  for (int i = 0; i < n; i ++ ) {
    if (xs[i] * xs[i]  + ys[i] * ys[i] <= dd) {
      ret ++;
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  int64_t d;
  std::cin >> d;
  std::vector<int64_t> xs(n);
  std::vector<int64_t> ys(n);
  for (int i = 0; i < n; i++) {
    std::cin >> xs[i];
    std::cin >> ys[i];
  }
  auto const res = solve(n, d, std::move(xs), std::move(ys));
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 6336
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long x = 101, p = 1, y, k = 0;
	cin >>  y;
	while(x < y)
		{
			k ++;
			x *= 1 + p / 100.;
		}
	cout << k + 1;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define ll long long
int main(void)
{
    ll lun[100005];
    int i, t, k;
    ll n, m;
    scanf("%lld", &k);
    lun[0] = 1;
    lun[1] = 2;
    lun[2] = 3;
    lun[3] = 4;
    lun[4] = 5;
    lun[5] = 6;
    lun[6] = 7;
    lun[7] = 8;
    lun[8] = 9;
    i = 0;
    t = 9;
    while (1) //文字列の読み込み
    {
        if (t >= k)
        {
            printf("%lld\n", lun[k - 1]);
            break;
        }
        m = lun[i] * 10;
        if (lun[i] % 10 == 0)
        {
            lun[t] = m;
            lun[t + 1] = m + 1;
            t += 2;
        }
        else if (lun[i] % 10 == 9)
        {
            lun[t] = m + 8;
            lun[t + 1] = m + 9;
            t += 2;
        }
        else
        {
            n = lun[i] % 10;
            lun[t] = m + n - 1;
            lun[t + 1] = m + n;
            lun[t + 2] = m + n + 1;
            t += 3;
        }
        i++;
    }
    return 0;
}

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

int main(){
    long long a, b, c;
    cin >> a >> b >> c;
    if (a + b > c){
        cout << "No" << endl;
    }
    else if (2*a*b+2*b*c+2*c*a < a*a+b*b+c*c){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;
int ans[1000005];
stack<int> s1;
bool query(int x){
    cout<<"? "<<s1.top()<<" "<<x<<endl;
    cout.flush();
    char y;
    cin>>y;
    return y=='Y';
    
}
int main(){
    int a,b;
    cin>>a>>b;
    if(a<=b){
        cout<<"Impossible"<<endl;
        return 0;
    }
    //s1.push(1);
    for(int i=0;i<a+b;i++){
        if(s1.empty()){
            s1.push(i);
            continue;
        }
        if(query(i)){
            s1.push(i);
        }else{
            s1.pop();
        }
    }
    int hold = s1.top();
    while(s1.size()){
        s1.pop();
    }
    s1.push(hold);
    
    for(int i=0;i<a+b;i++){
        if(query(i)){
            ans[i] = 1;
        }else{
            ans[i] = 0;
        }
    }
    cout<<'!';
    for(int i=0;i<a+b;i++){
        cout<<ans[i];
    }
}

Measured memory_bytes: 724
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class EDividingChocolate {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int h, w, K; cin >> h >> w >> K;
      vector<vector<int>> mat(h, vector<int>(w));
      rep(i, h) {
        rep(j, w) {
          char c; cin >> c;
          mat[i][j] = ((c == '1') ? 1 : 0);
        }
      }
      int ans = 10000;
      int s = 1<<(h-1);
      rep(i, s) {
        int now = __builtin_popcount(i);
        int cnt = now;
        debug(i, now);
        vector<int> tmp1(cnt+1);
        vector<int> tmp2(cnt+1);
        rep(j, w) {
          int p = 0;
          rep(k, h) {
            tmp2[p] += mat[k][j];
            if (i&(1<<k)) {
              p++;
            }
          }
          bool flag = true;
          rep(k, cnt+1) {
            if (tmp1[k] + tmp2[k] > K) {
              now++;
              flag = false;
              break;
            }
          }
          if (flag) {
            rep(k, cnt+1) {
              tmp1[k] += tmp2[k];
              tmp2[k] = 0;
            }
          }

          if (!flag) {
            rep(k, cnt+1) {
              tmp1[k] = tmp2[k];
              tmp2[k] = 0;
            }
            bool flag2 = true;
            rep(k, cnt+1) {
              if (tmp1[k] > K) {
                flag2 = false;
                break;
              }
            }
            if (!flag2) {
              debug(i, j);
              now = 10000;
              break;
            }
          }
        }
        chmin(ans, now);
      }
      cout << ans << endl;
    }
};

signed main() {
  EDividingChocolate solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

bool is_ok(vll& A, int N, ll K, ll X) {
    rep(i, N) {
        ll t = (A[i] + (X - 1)) / X - 1;
        K -= t;
        if (K < 0) {
            return false;
        }
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    ll K;
    cin >> N;
    cin >> K;
    vll A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());

    ll L = 0, R = 1000000000;
    for (int i = 0; i < 100; i++) {
        auto M = (R + L) / 2;
        if (M == 0) {
            break;
        }
        if (is_ok(A, N, K, M) == true) {
            R = M;
        }
        else {
            L = M;
        }
    }
    
    cout << ll(R) << endl;
    return 0;
}

Measured memory_bytes: 4776
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val k = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val s = a.sum()
    val div = mutableListOf<Int>()
    for (d in 1..s) {
        if (d * d > s) break
        if (s % d == 0) {
            div.add(d)
            if (d * d != s) {
                div.add(s / d)
            }
        }
    }
    div.sortDescending()
    for (d in div) {
        val b = a.map { it % d }.sorted().toList()
        var minus = 0L
        var plus = b.map { (d - it).toLong() }.sum()
        for (i in 0 until n - 1) {
            minus += b[i]
            plus -= d - b[i]
            if (Math.max(minus, plus) <= k) {
                println(d)
                return
            }
        }
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 50668
import sys
import bisect

N, K = map(int, sys.stdin.readline().split())
d = []


for i in range(N):
    a, b = map(int, sys.stdin.readline().split())
    d.append([a,b])

d.sort()

l = [0] * N
l[0] = d[0][1]

for i in range(1, N):
    l[i] = d[i][1]+ l[i-1]

pos = bisect.bisect_left(l, K)
print(d[pos][0])

Measured memory_bytes: 24360
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  for(int j=0; j<n; j++){
    cin >> b[j];
  }
  for(int k=0; k<n-1; k++){
    cin >> c[k];
  }
  
  int sum=0;
  for(int m=0; m<n; m++){
    sum += b[a[m]-1];
    if(a[m+1]-a[m]==1){
      sum += c[a[m]-1];
    }
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 3620
while 1:
  n = input()
  if n==0: break
  x = []
  y = [0]*(n+1)
  for i in range(n):
    a=map(int, raw_input().split())
    a.append(sum(a))
    x.append(a)
    for j in range(n+1): y[j] += a[j]
  x.append(y)
  for a in x: print "".join([str(e).rjust(5) for e in a])

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


int main(){
    int h,n;
    cin >> h >> n;
    int a[n];
    int b[n];
    for(int i = 0;i<n;++i){
        cin >> a[i] >> b[i];
    }
    int dp[h+1];//minimum number of magic point needs to be consumed before winning
    for(int i= 1;i<=h;++i)
        dp[i] = INT_MAX;
    dp[0] = 0;//minimum points consumed to beat a monster of strength 0
   // for(int i = 1;i<=h;++i) cout << dp[i] << " "; cout<<"\n";
    for(int H = 1;H <= h;++H){//health of monster
        for(int i = 0;i<n;i++){
            if(H < a[i]){
                dp[H] = min(dp[H],b[i]);
            }
            else if(H-a[i]>=0 && dp[H-a[i]]!=INT_MAX){
                dp[H] = min(dp[H],b[i] + dp[H-a[i]]);
            }
        }
    }
    
    cout << dp[h]<<"\n";
    return 0;
}

//1(4) -> 2(4/2) => 4(4/4)

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

using namespace std;

int main() {
    int y, m, d;
    char c1, c2;
    cin >> y >> c1 >> m >> c2 >> d;

    if (m > 4) {
        cout << "TBD" << endl;
    } else {
        cout << "Heisei" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
	return (b > 0)? gcd(b, a % b) : a ;
}
int main(){
	int N; 
	cin >> N;
	int A[114514] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
	}
	int ans = A[0]; 
	for(int i = 0; i < N; i++){
		ans = gcd(ans, A[i]); 
	}
	cout << ans << endl; 
}

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

int a[100001], u[100001];
signed main(){
	int n;
	scanf("%lld", &n);
	for(int i = 1;i <= n;i++)scanf("%lld", &a[i]);
	int ans1 = 0, ans2 = 0;
	for(int i = 1;i <= n;i++){
		u[i] = u[i-1]+a[i];
		if(i%2 == 1 && u[i] <= 0){
			ans1 += -u[i]+1;
			u[i] = 1;
		}
		if(i%2 == 0 && u[i] >= 0){
			ans1 += u[i]+1;
			u[i] = -1;
		}
	}
	for(int i = 1;i <= n;i++){
		u[i] = u[i-1]+a[i];
		if(i%2 == 1 && u[i] >= 0){
			ans2 += u[i]+1;
			u[i] = -1;
		}
		if(i%2 == 0 && u[i] <= 0){
			ans2 += -u[i]+1;
			u[i] = 1;
		}
	}
	printf("%lld\n", min(ans1, ans2));
	return 0;
}


Measured memory_bytes: 1792
a,b = list(map(int,input().split()))
ls = [['#']*99 for i in range(49)] + [['.']*99 for i in range(49)]
i,j = 0,0
for c in range(a - 1):
    ls[i][j] = '.'
    if j >= 97:
        j = 0;i += 2
    else:
        j += 2
i,j = 51,0
for c in range(b - 1):
    ls[i][j] = '#'
    if j >= 97:
        j = 0;i += 2
    else:
        j += 2
print(98,99)
for j in range(98):
    print(''.join(ls[j]))

Measured memory_bytes: 3064
"""
X文字が条件にあてはまるとき、X-1文字も条件に当てはまる。したがって、二分探索を使うのがよい。
一回の探索に、O(N**2)かかる。
探索はO(logN)回行うため、全体でO(N**2logN)で、ギリ間に合う。
"""
N = int(input())
S = input()

def is_ok(X):
    dic = {}
    for i in range(N+1-X):
        sub = S[i:i+X]
        if sub not in dic:
            dic[sub] = (i,i+X-1)
        else:
            if dic[sub][1] < i:
                return True
    return False

def bisearch(high,low):
    while high - low > 1:
        mid = (high+low)//2
        if is_ok(mid):
            low = mid
        else:
            high = mid
    return low
print(bisearch(N,0))

Measured memory_bytes: 100340
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

long long int ans[114514] = {};

int main() {

    string s;
    cin >> s;

    long long int cnt = 0;

    for ( long long int i = 0; i < s.size(); i++ ) {

        if ( s[i] == 'R' ) {
            if ( s[i+1] == 'L' ) {
                ans[i] += cnt / 2 + 1;
                ans[i+1] += ( cnt + 1 ) / 2;
                cnt = 0;
            } else {
                cnt++;
            }
        }

    }

    cnt = 0;
    for ( long long int i = s.size() - 1; i >= 0; i-- ) {
        if ( s[i] == 'L' ) {
            if ( s[i-1] == 'R' ) {
                ans[i] += cnt / 2 + 1;
                ans[i-1] += ( cnt + 1 ) / 2;
                cnt = 0;
            } else {
                cnt++;
            }
        }
    }

    for ( long long int i = 0; i < s.size(); i++ ) {
        if ( i != 0 ) cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;

}


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

int main(){
  int K;
  string S;

  cin >> K >> S;

  if(K < S.size()){
    for(int i = 0;i < K;i++){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }else{
    for(int i = 0;i < S.size();i++){
      cout << S.at(i);
    }
    cout << endl;
  }
}

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


class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().ToCharArray();
        var t = Console.ReadLine().ToCharArray();

        var count = 0;
        for (var i = 0; i < s.Length; i++)
        {
            if (s[i] == t[i]) count++;
        }

        Console.Write(count);
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int main(void) {
    int day[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};
    int excess, i;
    int m, d;
    
    while(1) {
        scanf("%d %d", &m, &d);
        if(m == 0)
            break;
        
        int sum_day = 0;
        
        if(m > 1) {
            for(i = 1; i < m; i++) {
                sum_day += day[i];
            }
            
            sum_day += d;
            
            excess = sum_day % 7;
        } else if(m == 1) {
            sum_day = 0;
            sum_day += d;
            
            excess = sum_day % 7;
        }
        
        if(m > 1 || m == 1) {
            switch(excess) {
                case 0: puts("Wednesday"); break;
                case 1: puts("Thursday"); break;
                case 2: puts("Friday"); break;
                case 3: puts("Saturday"); break;
                case 4: puts("Sunday"); break;
                case 5: puts("Monday"); break;
                case 6: puts("Tuesday"); break;
            }
        }
    }
    
    return(0);
}

Measured memory_bytes: 584
N = int(input())
xys = []
for i in range(N):
    x,y = map(int, input().split())
    xys.append((x,y))

xys.sort()
diffs = []
count = []
# 全探索して、一番共通項が多い差分から計算する
for i in range(N):
    for j in range(i+1,N):
        x1,y1 = xys[i]
        x2,y2 = xys[j]
        diff = (x1-x2, y1-y2)
        if diff not in diffs:
            diffs.append(diff)
            count.append(1)
        else:
            k = diffs.index(diff)
            count[k] += 1
if N == 1:
    print(1)
else:
    print(N-max(count))

Measured memory_bytes: 3188
#include <iostream>


using namespace std;

int main() {
    int n;
    cin>>n;
    for(int i= 1;i<n+1;i++){
    if(i%3 ==0){
        cout<<" "<<i;
    }
    else if(i%10 ==3){
        cout<<" "<<i;
    }
    else if((i/10)%10 ==3){
        cout<<" "<<i;
    }
    else if((i/100)%10 ==3){
        cout<<" "<<i;
    }    
    else if((i/1000)%10 ==3){
        cout<<" "<<i;
    }    
}
cout<<endl;
    	return 0;
}


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

using namespace std;

const int N = 10;
char g[N][N];
char buff[31];

const string dc = "UDRL";
const int di[] = {-1, 1, 0, 0};
const int dj[] = {0, 0, 1, -1};

pair<int, int> tmp[31];
#include <map>
map<pair<char, char>, bool> taboo;

bool rec(int h, int w, int i, int j, int depth, int lim, char last)
{  
  if (depth == lim) return true;
  g[i][j] = '.';

  for (int d = 0; d < 4; ++d) {
    if (taboo[make_pair(dc[d], last)]) {
      continue;
    }
    for (int len = 0; ; ++len) {
      int ni = i + di[d] * len;
      int nj = j + dj[d] * len;
      if (ni < 0 || nj < 0) break;
      if (h <= ni || w <= nj) break;
      if (g[ni][nj] == '.') continue;
      if (rec(h, w, ni, nj, depth + 1, lim, dc[d])) {
        buff[depth] = dc[d];
        tmp[depth] = make_pair(ni, nj);
        return true;
      }
      break;
    }
  }

  g[i][j] = 'o';
  return false;
}

int main(void)
{
  taboo[make_pair('U', 'D')] = true;
  taboo[make_pair('D', 'U')] = true;
  taboo[make_pair('R', 'L')] = true;
  taboo[make_pair('L', 'R')] = true;
  
  int h, w;
  while (cin >> h >> w) {
    int si, sj;
    int lim = 0;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> g[i][j];
        if (g[i][j] == 'o') ++lim;
        if (g[i][j] != 'o' && g[i][j] != '.') {
          si = i;
          sj = j;
        }
      }
    }
    fill(buff, buff + 31, '\0');
    rec(h, w, si, sj, 0, lim, g[si][sj]);
    puts(buff);
    
    continue;
    cout << si << ' ' << sj << endl;
    for (int i = 0; i < lim; ++i) {
      cout << tmp[i].first << ' ' << tmp[i].second << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N,M = map(int,input().split())
if M&1:
    print(-1)
    exit()

AB = [[int(x) for x in input().split()] for _ in range(M)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

# まずは全域木をつくる
tree = [set() for _ in range(N+1)]
visited = [False] * (N+1)
q = [1]
while q:
    x = q.pop()
    for y in graph[x]:
        if visited[y]:
            continue
        visited[y] = True
        tree[x].add(y)
        tree[y].add(x)
        q.append(y)

answer = []
out_deg = [0] * (N+1)
# 木を残して適当に決める
for a,b in AB:
    if b in tree[a]:
        continue
    answer.append('{} {}'.format(a,b))
    out_deg[a] += 1

def dfs(x = 1,parent = None):
    for y in tree[x]:
        if y == parent:
            continue
        dfs(y,x)
        if out_deg[y] & 1:
            answer.append('{} {}'.format(y,x))
            out_deg[y] += 1
        else:
            answer.append('{} {}'.format(x,y))
            out_deg[x] += 1

dfs()

print('\n'.join(answer))



Measured memory_bytes: 170676
#include <stdio.h>
#define N 100
int selectionSort(int *, int);

int main(){

  int n, A[N];
  int i, total;


  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  total=selectionSort(A, n);

  for(i=0; i<n-1; i++){
    printf("%d ", A[i]);
  }
  printf("%d\n", A[n-1]);
  printf("%d\n", total);

  return 0;

}

int selectionSort(int A[], int n){

  int i, j, min, temp, count=0;

  for(i=0; i<n-1; i++){
    min=i;
    for(j=i+1; j<n; j++){
      if(A[j]<A[min]){
	min=j;

      }
    }
    temp=A[i];
    A[i]=A[min];
    A[min]=temp;

    if(i!=min) count++;
  }

  return count;
}



Measured memory_bytes: 2104
#include <stdio.h>

typedef long long ll;

const ll M = 1000000007;

int main() {
    int N;
    scanf("%d", &N);
    ll ans = 1;
    for (int i = 1; i <= N; i ++) {
        ans = (ans * i) % M;
    }
    printf("%lld\n", ans);
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int n,m,c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for(int i=0;i<m;i++){
    cin >> b[i];
  }
  vector<vector<int>> a(n,vector<int>(m,0));
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> a[i][j];
    }
  }
  int cnt=0;
  for(int i=0;i<n;i++){
    ll f=c;
    for(int j=0;j<m;j++){
      f +=a[i][j]*b[j];
    }
    if(f>0)
      cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &out, const vector<int> &b) {
    for (auto k : b) out << k << " ";
    return out;
}

istream& operator>> (istream& in, pii& b) {
    in >> b.first >> b.second;
    return in;
}

ostream& operator<< (ostream& out, const pii& b) {
    out << "{" << b.first << ", " << b.second << "}";
    return out;
}

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
#else
    #define dbg(x) 57
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
#endif

const ld PI = acos(-1);

#define time clock() / (double) CLOCKS_PER_SEC

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2 << "\n";
            return 0;
        }
    }
    for (int i = 0; i < n - 2; i++) {
        if (s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << "\n";
            return 0;
        }
    }
    cout << "-1 -1\n";
}
/*

*/


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

vector<long long int> dp(100005,-1);
long long int n,ara[100005],k;
int f(long long int i){

    if(i>=n) return 0;


    if(dp[i]!=-1) return dp[i];

    long long int  ans=10000000000;

    for(long long int j=1;j<=k && i+j<=n ;j++){

        ans= min(ans,f(i+j)+abs(ara[i+j]-ara[i]));
    }


    dp[i] = ans;
    return dp[i];


}




int main()
{
    long long int i;
    cin>>n>>k;
    for(i=1;i<=n;i++){
        cin>>ara[i];
    }

    cout<<f(1)<<endl;

    return 0;
}


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

int main(){
  using coord= pair<int, int>;
  int H,W,M;
  cin >> H >> W >> M;

  set<coord> targets;
  int x,y;
  for(int i=0; i<M; i++){
    cin >> x >> y;
    x--; y--; // 1-indexed -> 0-indexed
    targets.insert(make_pair(x,y));
  }

  vector<int> Nrow(H);
  vector<int> Ncol(W);
  for(auto [x,y]:targets){
    Nrow.at(x)++;
    Ncol.at(y)++;
  }

  vector<int> argmax_row;
  int cummax_row= -1;
  for(int h=0; h<H; h++){
    if(cummax_row > Nrow.at(h)){ continue; }
    else if(cummax_row < Nrow.at(h)){
      cummax_row= Nrow.at(h);
      argmax_row.clear();
      argmax_row.emplace_back(h);
    }
    else{
      argmax_row.emplace_back(h);
    }
  }

  vector<int> argmax_col;
  int cummax_col= -1;
  for(int w=0; w<W; w++){
    if(cummax_col > Ncol.at(w)){ continue; }
    else if(cummax_col < Ncol.at(w)){
      cummax_col= Ncol.at(w);
      argmax_col.clear();
      argmax_col.emplace_back(w);
    }
    else{
      argmax_col.emplace_back(w);
    }
  }

  int64_t Ncross= (int64_t) argmax_row.size()* argmax_col.size();
  if(Ncross > M){
    int ans= cummax_row+ cummax_col;
    cout << ans << endl;
  }
  else{
    vector<bool> filled(Ncross);
    for(size_t i=0; i<argmax_row.size(); i++){
      for(size_t j=0; j<argmax_col.size(); j++){
        size_t id= i* argmax_col.size() + j;
        filled.at(id)= targets.count(make_pair(argmax_row.at(i), argmax_col.at(j)));
      }
    }
    bool vacant_exist= false;
    for(auto b:filled){
      vacant_exist |= !b;
    }

    int ans= vacant_exist ? cummax_row+ cummax_col
                          : cummax_row+ cummax_col- 1;
    cout << ans << endl;
  }
}

Measured memory_bytes: 23760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    
    if((B-A)%2 == 0){
        cout << (B-A)/2 << endl;
    }else if(B-A == 1){
        cout << min(B-1, N-A) << endl;
    }else{
        cout << min(A, N-B+1) + (B-A-1)/2 << endl;
    }

}

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

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

tmp = A[0]
for i in range(N):
    tmp = gcd(tmp, A[i])
    
    
for i in range(N):
    A[i] //= tmp
 
A.sort(reverse=True)

v1 = A[0]
count1 = 0
for i in range(N):
    tmp1 = v1
    v1 = gcd(v1, A[i])
    if  v1 == 1:
        count1 += 1
        if count1 == 1:
            v1 = tmp1
        
        
v2 = A[1]
count2 = 0
for i in range(N):
    tmp2 = v2
    v2 = gcd(v2, A[i])
    if v2 == 1:
        count2 += 1
        if count2 == 1: 
            v2 = tmp2

if 1:
    s1 = 1
    s2 = 1
    if count1 == 1 and v1 <= 10 ** 9:
        s1 = v1
    if count2 == 1 and v2 <= 10 ** 9:
        s2 = v2
    print(tmp * max(s1, s2))

Measured memory_bytes: 14080
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S, T;
	cin >> S >> T;
	int res = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i])res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		char[] num = new char[8];
		
		for (int i=0; i<n; i++) {
			num = sc.next().toCharArray();
			Arrays.sort(num);
			
			StringBuilder sb = new StringBuilder();
			for (int j=0; j<8; j++) {
				sb.append(num[j]);
			}
			int min = Integer.parseInt(sb.toString());
			
			sb.setLength(0);
			for (int j=7; j>=0; j--) {
				sb.append(num[j]);
			}
			int max = Integer.parseInt(sb.toString());
			
			out.println(Math.abs(max-min));
		}
	}
}


Measured memory_bytes: 26128
from sys import stdin
import math

if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    X = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    yen = 100
    cnt = 0
    while (yen<X):
        yen = math.floor(yen*1.01)
        cnt += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 63432
fun main(args: Array<String>) {
    val array = Array(5) {
        readLine()!!.toInt()
    }
    val round = { it: Int -> (10 - it % 10) % 10 }
    var ans = array.sumBy { it + round(it) } - array.map { round(it) }.max()!!
    println(ans)
}

Measured memory_bytes: 31992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, l);
    
    int a = l;
    int b = l+n-1;
    int sum = 0;
    For(i, n) sum += l+i;
    
    if(a > 0 && b > 0){
        sum -= a;
    }
    if(a < 0 && b < 0){
        sum -= b;
    }
    Cout(sum);
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

struct UnionFind {
  vector<int> parent;

  UnionFind(int n) : parent(n) {
    for (int i = 0; i < n; i++) parent[i] = i;
  }

  int root(int x) {
    if (parent[x] == x)
      return x;
    else
      return parent[x] = root(parent[x]);
  }

  void unite(int a, int b) {
    int ra = root(a);
    int rb = root(b);
    if (ra == rb) return;
    parent[ra] = parent[rb];
  }

  bool same(int a, int b) {
    return root(a) == root(b);
  }
};

// ====================================================================

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i]--;
  }

  UnionFind uni(n * 2);
  for (int i = 0; i < n; i++) uni.unite(v[i], i + n);
  // cout << uni.parent << endl;

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    uni.unite(a, b);
  }

  // 数字iが書かれている所は位置x+nにある
  // cout << uni.parent << endl;

  int count = 0;
  for (int i = 0; i < n; i++) {
    if (uni.same(v[i], v[i] + n)) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1408
n = int(input())
h = [list(map(int, input().split())) for _ in range(n)]
# dp[i][j]: i-1日目に1つの行動を取った際の最大幸福度
dp = [[0] * 3 for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(3):
        for k in range(3):
            # 2回連続は不可
            if j == k:
                continue
            dp[i][k] = max(dp[i][k], dp[i - 1][j] + h[i - 1][k])
print(max(dp[n]))

Measured memory_bytes: 47340
K = int(input())

def make_num(K=K):
    n = 0
    for c in range(1, K+1):
        n = (n * 10 + 7) % K
        if n % K == 0:
            return c

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    print(make_num())

Measured memory_bytes: 9112