akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    for (int i = 0; i < n; i++) {
      int pm, pe, pj;
      cin >> pm >> pe >> pj;
      if (pm == 100 || pe == 100 || pj == 100 ||
          pm + pe >= 180 ||
          pm + pe + pj >= 240)
        cout << 'A' << endl;
      else if (pm + pe + pj >= 210 ||
               pm + pe + pj >= 150 && (pm >= 80 || pe >= 80))
        cout << 'B' << endl;
      else
        cout << 'C' << endl;
    }
  }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
const int MOD=2019;
int l,r;

int f(int l)
{
	if(l%MOD==0) return l;
	return l+MOD-(l%MOD);
}

int main()
{
	cin>>l>>r;

	int nxt=f(l);
	if(nxt<=r) cout<<"0";
	else
	{
		long long ans=LLONG_MAX;
		for(int i=l;i<=r;i++)
			for(int j=i+1;j<=r;j++)
				ans=min(ans,(1ll*i*j)%MOD);
		cout<<ans;
	}
}

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

int main(){
	string s;
	cin >> s;

	int res = 0;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == '+') res++;
		else if (s[i] == '-') res--;
	}

	cout << res << endl;
	return 0;
}


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

using namespace std;


int main()
{


/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	const int INF = 1e9 + 5;

	long long n;


	cin >> n;


	cout << n * (n - 1) / 2;


   return 0;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
const ll INF = 999999999999999;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  if( n%2 == 0 ){
    for(ll i=n-1;i>=0;--i){
      if( (i+1)%2 == 0 ){
        printf("%lld ",a.at(i));
      }
    }
    for(ll i=0;i<n;++i){
      if( (i+1)%2 == 1 ){
        printf("%lld ",a.at(i));
      }
    }
  }else{
    for(ll i=n-1;i>=0;--i){
      if( (i+1)%2 == 1 ){
        printf("%lld ",a.at(i));
      }
    }
    for(ll i=0;i<n;++i){
      if( (i+1)%2 == 0 ){
        printf("%lld ",a.at(i));
      }
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a;
    cin >> a;
    cout << a / 100 + a / 10 % 10 + a % 10;
}

Measured memory_bytes: 3580
#include <iostream>
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  while(n!=0||x!=0){
    int i,j,k;
    int o=0;
    for(i=1;i<=n;i++){
      for(j=i+1;j<=n;j++){
    for(k=j+1;k<=n;k++){
      if(i+j+k==x) o++;
    }
      }
    }
 
    cout << o << endl;
 
    cin >> n >> x;
  }
 
 
  return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <cstdlib>

int main()
{
    std::string x;
    int sum;

    while(1)
    {
        std::cin >> x;

        if (x == "0") return 0;

        sum = 0;
        for (int i = 0; i < x.length(); i++)
        {
            sum += x[i] - 0x30;
        }

        std::cout << sum << std::endl;
    }
}


Measured memory_bytes: 3176
t = list(input())
s = list(input())

ans = 10000

for i in range(len(t)-len(s)+1):
    tmpans = 0
    for j in range(len(s)):
        if s[j] != t[i+j]:
            tmpans += 1
    if ans > tmpans:
        ans = tmpans

print(ans)

Measured memory_bytes: 9112
import sys
sys.setrecursionlimit(10**6)

def main():
	n, m = map(int, input().split())
	x=list(map(int, input().split()))
	x.sort()
	a = []
	s = 0
	for i in range(1,m):
		a += [x[i]-x[i-1]]
		s += a[-1]
	a.sort()
	a=a[::-1]
	print(0 if n >= m else s - sum(a[0:n-1]))

main()

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

#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(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
#define FIX <<fixed<<setprecision(10)<<
using namespace std;

using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;

const ll MOD = 1e9+7;

int main(){
int face[6];
int sw;
string order;
REP(i,6){
    cin>>face[i];
}
cin>>order;
REP(i,order.size()){
if(order[i]=='E'){
    sw=face[5];
    face[5]=face[2];
    face[2]=face[0];
    face[0]=face[3];
    face[3]=sw;
}else if(order[i]=='W'){
    sw=face[5];
    face[5]=face[3];
    face[3]=face[0];
    face[0]=face[2];
    face[2]=sw;
}else if(order[i]=='N'){
    sw=face[5];
    face[5]=face[4];
    face[4]=face[0];
    face[0]=face[1];
    face[1]=sw;
}else if(order[i]=='S'){
    sw=face[5];
    face[5]=face[1];
    face[1]=face[0];
    face[0]=face[4];
    face[4]=sw;
}
}
cout<<face[0]<<endl;
}




Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (n); ++i)
#define repe(i, n) for (int64_t i = 0; i <= (n); ++i)
#define reps(i, s, n) for (int64_t i = (s); i < (n); ++i)
#define repse(i, s, n) for (int64_t i = (s); i <= (n); ++i)
#define repr(i, n) for (int64_t i = (n); i >= 0; --i)
const int64_t inf = (int64_t)1e18;
const int64_t mod = (int64_t)1e9 + 7;


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

  char b; cin >> b;
  char ans;
  switch (b) {
    case 'A':
      ans = 'T'; break;
    case 'C':
      ans = 'G'; break;
    case 'G':
      ans = 'C'; break;
    case 'T':
      ans = 'A'; break;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
X, K, D = map(int, input().split())
n = abs(X)//D

if X < 0:
    if K <= n:
        print(abs(X+K*D))
    else:
        if K%2 == n%2:
            print(abs(X+n*D))
        else:
            if X+n*D < 0:
                print(abs(X+(n+1)*D))
            else:
                print(abs(X+(n-1)*D))
else:
    if K <= n:
        print(X-K*D)
    else:
        if K%2 == n%2:
            print(abs(X-n*D))
        else:
            if X-n*D < 0:
                print(abs(X-(n-1)*D))
            else:
                print(abs(X-(n+1)*D))


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

int main() {
  int n;
  long ans = 0;

  cin >> n;

  for (size_t i = 1; i <= n; i++) {
    if (i % 3 != 0 && i % 5 != 0) ans += i;
  }

  cout << ans;
}

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

using namespace std;

int main(void){
    int x, y;
    cin >> x >> y;
    if(x < y){
        int temp = x;
        x = y;
        y = temp;
    }
    if(x != y) x = x % y;
    for(int i = min(x, y); 0 < i; i--){
        if(x % i == 0 && y % i == 0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size())cout << a[i] << " ";cout << "\n"
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,M,r;
    cin >> N >> M >> r;
    struct edge{ll from,to,cost;};
    vector<edge> es(M);
    ll a,b,c;
    vector<ll> dist(N,INF);
    dist[r] = 0;
    rep(i,M){
        cin >> a >> b >> c;
        es[i] = {a,b,c};
    }
    rep(loop,N + 1){
        rep(i,M){
            if(dist[es[i].from] == INF)continue;
            if(dist[es[i].from] + es[i].cost < dist[es[i].to]){
                dist[es[i].to] = dist[es[i].from] + es[i].cost;
                if(loop == N){
                    cout << "NEGATIVE CYCLE" << endl;
                    return 0;
                }
            }
        }
    }
    rep(i,N){
        if(dist[i] == INF)cout << "INF\n";
        else cout << dist[i] << "\n";
    }

}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
template<typename T>void chmax(T& a,const T& b){if(a<b)a=b;}

main(){
  string s,t;
  cin>>s>>t;
  ll n,m;
  n=s.size();m=t.size();

  vector<vector<ll>>lcs(3010,vector<ll>(3010));
  for(ll i=0;i<n;++i){
    for(ll j=0;j<m;++j){
      if(s[i]==t[j])chmax(lcs[i+1][j+1],lcs[i][j]+1);
      chmax(lcs[i+1][j+1],max(lcs[i+1][j],lcs[i][j+1]));
    }
  }
  // lcs[n][m]=lcs
  string ans="";
  while(n>0&&m>0){
    if(lcs[n][m]==lcs[n-1][m])n--;
    else if(lcs[n][m]==lcs[n][m-1])m--;
    else{
      n--;m--;
      ans+=s[n];
    }
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;

}

Measured memory_bytes: 71168
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)cin >> a[i];

	int ans;

	sort(a.begin(), a.end());
	
	if (n == 2) ans = a[1];
	else {
		int i;
		for (i = a[1];; --i) {
			int flag = 0;
			for (int j = 0; j < n; ++j) {
				if (a[j] % i != 0) flag++;
				if (flag > 1) break;
			}
			if (flag < 2) break;
		}
		ans = i;
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

void print_num(vector<int> num, int len)
{
    for (int i = 0; i < len; i++)
    {
        if (i > 0)
        {
            cout << " ";
        }
        cout << num[i];
    }
    
    cout << endl;
}

int bubble_sort(vector<int> &num, int len)
{
    int swap_cnt = 0;
    
    for (int i = 0; i < len; i++)
    {
        for (int j = len - 1; j >= i + 1; j--)
        {
            if (num[j] < num[j - 1])
            {
                swap(num[j], num[j - 1]);
                swap_cnt++;
            }
        }
    }
    
    return swap_cnt;
}

int main()
{
    int cnt = 0;
    int tmp = 0;
    int swap_cnt = 0;
    vector<int> num;
    
    cin >> cnt;
    for (int i = 0; i < cnt; i++)
    {
        cin >> tmp;
        num.push_back(tmp);
    }
    
    swap_cnt = bubble_sort(num, cnt);
    
    print_num(num, cnt);
    cout << swap_cnt << endl;
    
    return 0;
}



Measured memory_bytes: 3160
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

#define MAX_N	(2000)
#define MAX_M	(15)

/* typedef */

typedef vector<int> vi;

template <typename T>
struct Pt3D {
  T x, y, z;

  Pt3D() {}
  Pt3D(int _x, int _y, int _z) { x = _x; y = _y; z = _z; }

  bool operator==(const Pt3D<T>& pt) {
    return x == pt.x && y == pt.y && z == pt.z;
  }

  Pt3D<T> operator+(const Pt3D<T>& pt) {
    return Pt3D<T>(x + pt.x, y + pt.y, z + pt.z);
  }

  Pt3D<T> operator-(const Pt3D<T>& pt) {
    return Pt3D<T>(x - pt.x, y - pt.y, z - pt.z);
  }
  
  Pt3D<T> operator-() { return Pt3D<T>(-x, -y, -z); }
  Pt3D<T> operator*(const T& t) { return Pt3D<T>(x * t, y * t, z * t); }
  Pt3D<T> operator/(const T& t) { return Pt3D<T>(x / t, y / t, z / t); }

  T dot(const Pt3D<T>& v) { return x * v.x + y * v.y + z * v.z; }

  Pt3D<T> cross(const Pt3D<T>& v) {
    return Pt3D<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
  }

  T d2() { return x * x + y * y + z * z; }
  double d() { return sqrt(d2()); }
  Pt3D<T> normalize() { return *this / d(); }
  string to_s() { return "(" + x + "," + y + "," + z + ")"; }
};

typedef Pt3D<int> pt3di;

/* global variables */

pt3di bcs[MAX_N], lcs[MAX_M], eye;
int brs[MAX_N], lbs[MAX_M];
double lis[MAX_M];
vi obsts[MAX_M];
bool rmvd[MAX_N];

/* subroutines */

bool obst(pt3di& pt0, pt3di& pt1, pt3di& sc, int sr) {
  pt3di v0 = sc - pt0;
  pt3di v1 = sc - pt1;
  bool in0 = (v0.d2() < sr * sr);
  bool in1 = (v1.d2() < sr * sr);

  if (in0 && in1) return false;
  if (in0 || in1) return true;

  pt3di v01 = pt1 - pt0;
  double d = v0.cross(v1).d() / v01.d();
  if (d > sr) return false;

  return (v0.dot(v01) > 0 && v1.dot(v01) < 0);
}

/* main */

int main() {
  int n, m, r;
  
  for (;;) {
    cin >> n >> m >> r;
    if ((n | m | r) == 0) break;

    for (int i = 0; i < n; i++)
      cin >> bcs[i].x >> bcs[i].y >> bcs[i].z >> brs[i];

    for (int i = 0; i < m; i++)
      cin >> lcs[i].x >> lcs[i].y >> lcs[i].z >> lbs[i];

    cin >> eye.x >> eye.y >> eye.z;

    for (int i = 0; i < m; i++) {
      lis[i] = (double)lbs[i] / (lcs[i] - eye).d2();

      obsts[i].clear();
      for (int j = 0; j < n; j++)
	if (obst(eye, lcs[i], bcs[j], brs[j])) obsts[i].push_back(j);
    }

    double max_l = 0.0;
  
    for (int bits = 0; bits < (1 << m); bits++) {
      double sum = 0.0;
      int rn = 0;
      bzero(rmvd, sizeof(bool) * n);
      
      for (int i = 0; i < m; i++)
	if ((bits & (1 << i)) != 0) {
	  vi& obsti = obsts[i];
	  for (vi::iterator vit = obsti.begin(); vit != obsti.end(); vit++)
	    if (! rmvd[*vit]) {
	      rmvd[*vit] = true;
	      rn++;
	    }

	  if (rn > r) break;
	  sum += lis[i];
	}

      if (rn <= r && max_l < sum) max_l = sum;
    }

    printf("%.5lf\n", max_l);
  }

  return 0;
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gsort(arr) sort(arr, arr+n, greater<ll>()); 
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sync2 cout<<fixed<<setprecision(10)
const ll inf=1e9+7;
const ll inf2=inf*inf;
#define pi 3.14159265358979323846
#define for0(i,n) for (int i = 0; i <(int)n; i++)
#define for1(i,n) for (int i = 1; i<=(int)n; i++)
#define all(vv) vv.begin(),vv.end()
priority_queue <ll, vector<ll>, greater<ll>> mnheap;
priority_queue <ll> mxheap;
#define vc(vv) vector<ll> vv;
ll gcd(ll x,ll y){if (x == 0)return y;return gcd(y%x, x);}
int is_prime(ll x) {if(x<2)return 0;for(ll i=2;i*i<=x;i++){if(x%i==0)return 0;}return 1;}
inline ll modpw(ll x, ll y, ll z) {ll res=1;x=x%z;while(y){if(y&1) res=(res*x)%z;x=(x*x)%z;y/=2;}return res;}
inline ll modinv(ll x,ll z){return modpw(x,z-2,z);}
ll lcm(ll x,ll y){return (x*y)/gcd(x,y);}
#define pYES cout<<"YES"<<endl
#define pNO cout<<"NO"<<endl

ll dp[105][100005];
int main()
{
     sync;
     int t;
     //cin>>t;
     t=1;
     while(t--)
     {
          ll n,w;
          cin>>n>>w;
          ll a[n+1][2];
          ll sum=0;
          for0(i,n){cin>>a[i+1][0]>>a[i+1][1];sum+=a[i+1][1];}
          for0(i,n+1)for0(j,sum+1)if(/*i!=0 and*/ j!=0)dp[i][j]=inf2;
          for(int i=1;i<=n;i++)
          {
               for(int j=1;j<=sum;j++)
               {
                    
                    if(a[i][1]<=j)
                    {
                         dp[i][j]=min(a[i][0]+dp[i-1][j-a[i][1]],dp[i-1][j]);                         
                    }
                    else
                    {
                         dp[i][j]=dp[i-1][j];
                    }
               }
          }
          int mx=0;
          for(int i=sum;i>=0;i--)
          {
               if(dp[n][i]<=w)
                    mx=max(i,mx);
          }
          cout<<mx<<endl;
     }
}

Measured memory_bytes: 82524
package main

import (
	"fmt"
)

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

	max := max(A, max(B, C))
	sum := A + B + C

	if max%2 != sum%2 {
		max++
	}
	fmt.Println((3*max - sum) / 2)
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


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

int main(){
 

  while(1){
    vector<int> t;
    int n,a;
    cin >> n;
    if(n==0) break;

    for(int i = 0; i < n ; i++){
      cin >> a;
      t.push_back(a) ;
    }
    std::sort(t.begin(),t.end());

    long long mati[10010]={0};
    long long ans=0;

    for(int i = 1; i < n; i++){
      mati[i] = mati[i-1] + t[i-1];
      //   cout << mati[i] << " ";
      ans += mati[i];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<unordered_map>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
long long CountZeroSubstrings(vector<int> A) {
    int n = A.size();

    vector<long long> S(n+1, 0);
    for (int i = 0; i < n; i++)
        S[i+1] = S[i] + A[i];

    long long answer = 0;
    unordered_map<long long, int> H;
    for (int i = 0; i <= n; i++) {
        if (H.count(S[i]))
            answer += H[S[i]];
        H[S[i]]++;      
    }

    return answer;
}

int main(){ 

  int n; cin>> n;
  vector<int> a(n);
  rep(i, n) cin>> a[i];

  cout<< CountZeroSubstrings(a)<< endl;

  return 0;
}

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

#define MAXN 200000
#define INF 0x7fffffff
int A[MAXN+5],tmp[MAXN+5],Sum[MAXN+5];

#define lch (i<<1)
#define rch (i<<1|1)
struct Node{
    int l,r;
    int Min,Max;
}T[MAXN*4+5];
void PushUp(int i){
    T[i].Max=max(T[lch].Max,T[rch].Max);
    T[i].Min=min(T[lch].Min,T[rch].Min);
}
void Build(int i,int l,int r){
    T[i].l=l,T[i].r=r;
    if(l==r){
        T[i].Min=T[i].Max=A[l];
        return;
    }
    int mid=(l+r)>>1;
    Build(lch,l,mid);
    Build(rch,mid+1,r);
    PushUp(i);
}
int QueryMin(int i,int l,int r){
    if(r<T[i].l||T[i].r<l)
        return INF;
    if(l<=T[i].l&&T[i].r<=r)
        return T[i].Min;
    return min(QueryMin(lch,l,r),QueryMin(rch,l,r));
}
int QueryMax(int i,int l,int r){
    if(r<T[i].l||T[i].r<l)
        return -INF;
    if(l<=T[i].l&&T[i].r<=r)
        return T[i].Max;
    return max(QueryMax(lch,l,r),QueryMax(rch,l,r));
}

bool Sorted(int l,int r){
    return Sum[r]-Sum[l]==r-l;
}

int main(){
    //freopen("sort.in" ,"r", stdin);
    //freopen("sort.out","w",stdout);
    int N,K;
    /*
    5 1
    0 1 2 3 4
    */
    scanf("%d%d",&N,&K);
    for(int i=1;i<=N;i++)
        scanf("%d",A+i);
    for(int i=1;i<=N;i++)
        Sum[i]=Sum[i-1]+(A[i]>A[i-1]);
    Build(1,1,N);
    int Ans=1,cnt=Sorted(1,K);
    for(int i=2;i<=N-K+1;i++){
        cnt+=Sorted(i,i+K-1);
        int Max=QueryMax(1,i,i+K-2),Min=QueryMin(1,i,i+K-2);
        if(!(A[i-1]<=Min&&Max<=A[i+K-1])||(Sorted(i-1,i+K-2)&&Sorted(i,i+K-1)))
            Ans++;
    }
    printf("%d",Ans-max(0,cnt-1));
    return 0;
}


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

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

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

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

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

    int h,w;
    cin >> h >> w;
    char s[55][55];
    int black = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> s[i][j];
            if(s[i][j]=='#') black++;
        }
    }
    int dist[55][55];
    memset(dist,-1,sizeof(dist));
    dist[0][0] = 0;
    queue<P> q;
    q.push(P(0,0));
    while(!q.empty()){
        P p = q.front(); q.pop();
        if(p.first==h-1 && p.second==w-1) break;
        for(int i=0;i<4;i++){
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(0<=ny&&ny<h && 0<=nx&&nx<w && s[ny][nx]!='#' && dist[ny][nx]==-1){
                q.push(P(ny,nx));
                dist[ny][nx] = dist[p.first][p.second] + 1;
            }
        }
    }
    if(dist[h-1][w-1]==-1) cout << -1 << endl;
    else cout << h*w-(black+dist[h-1][w-1]+1) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
class rect{
    public static void Main(){
        int i,j;
        while(true){
            i=0;
            String[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            if(a+b == 0)
                break;
            else{
                for(i=0; i<a; i++){
                    j=0;
                    for(j=0; j<b; j++){
                        Console.Write("#");
                    }
                Console.WriteLine("");
                }
            }
            Console.WriteLine("");
        }
    }
}


Measured memory_bytes: 15892
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
#include<numeric>
#include<set>
#include<iterator>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
#define int long long 
main(){
    int q;
    cin>>q;
    bitset<64>a;
    while(q--){
        int x,y;
        cin>>x;
        if(x==0){
            cin>>y;
            cout<<a[y]<<endl;
        }
        if(x==1){
            cin>>y;
            a[y]=1;
        }
        if(x==2){
            cin>>y;
            a[y]=0;
        }
        if(x==3){
            cin>>y;
            a[y]=a[y]^1;
        }
        if(x==4){
            cout<<a.all()<<endl;
        }
        if(x==5){
            cout<<a.any()<<endl;
        }
        if(x==6){
            cout<<a.none()<<endl;
        }
        if(x==7){
            cout<<a.count()<<endl;
        }
        if(x==8){
            cout<<a.to_ulong()<<endl;
        }

    }
    return 0;
}


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

int main() {
    int A;
    int B;
    cin >> A;
    cin >> B;
    if ( A >= 13 )
      cout << B << endl;
    if ( A < 13 && A >= 6 )
      cout << B / 2 << endl;
    if ( A < 6 )
      cout << 0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
 
int main(){
 
    size_t n;
    std::cin >> n;
 
    std::map<std::string, size_t> m;
 
    for(size_t i = 0; i < n; i++){
        std::string s;
        std::cin >> s;
 
        if(m.find(s) != m.end()){
            m[s]++;
        }else{
            m.emplace(s, 0);
        }
    }
 
    size_t max = 0;
 
    for(const auto& e : m){
        max = std::max(max, e.second);
    }
 
    std::vector<std::string> v;
 
    for(const auto& e : m){
        if(e.second == max){
            std::cout << e.first << std::endl;
        }
    }
 
    return 0;
}


Measured memory_bytes: 25216
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(L):
    n = L / 3
    return n ** 3


def main():
    L = read_int()
    print(slv(L))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6340
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#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 reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#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 main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    vector<int> a(3);
    cin >> n >> a[0] >> a[1] >> a[2];
    vector<P> s(n);
    rep(i, n) {
        string t;
        cin >> t;
        s[i].fi = t[0] - 'A';
        s[i].se = t[1] - 'A';
    }
    s.eb(0, 1);
    string ans;
    auto add = [&](int i, int j) {
                   a[i]++; a[j]--;
                   ans += 'A' + i;
               };
    rep(i, n) {
        int x = s[i].fi, y = s[i].se;
        if (a[x] == 0 && a[y] == 0) {
            cout << "No" << endl;
            return 0;
        }
        if (a[x] == 0) {
            add(x, y);
        } else if (a[y] == 0) {
            add(y, x);
        } else {
            int nx = s[i+1].fi, ny = s[i+1].se;
            if (x == nx || x == ny) {
                add(x, y);
            } else {
                add(y, x);
            }
        }
    }
    cout << "Yes" << endl;
    rep(i, n) cout << ans[i] << endl;
}


Measured memory_bytes: 4768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin>>x;
    if(x>=400&&x<=599)
        cout<<"8"<<endl;
    else if(x>=600&&x<=799)
        cout<<"7"<<endl;
        else if(x>=800&&x<=999)
        cout<<"6"<<endl;
        else if(x>=1000&&x<=1199)
        cout<<"5"<<endl;
        else if(x>=1200&&x<=1399)
        cout<<"4"<<endl;
        else if(x>=1400&&x<=1599)
        cout<<"3"<<endl;
        else if(x>=1600&&x<=1799)
        cout<<"2"<<endl;
        else if(x>=1800&&x<=1999)
        cout<<"1"<<endl;

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const long long M =1e5+2,MOD=3e9+7;
typedef long long ll;
#define pb push_back
#define Y printf("YES\n")
#define N printf("NO\n")
#define O printf("-1\n")
bool f_2=false,vis[M]= {false},f=false;
vector<ll>v,v_1,v_2;
string s,p,q,ok,ch;
map<ll,ll>mp,mp_2;
set<ll>st,st_1;
ll arr[M],ar[M];
ll cnt=0,cost=0,mx=0,NODE,t,par,zero=0;
deque<ll>Q;
//vector< pair<ll,ll > >v,v_1;
struct node
{
    ll pa,ran,visit;

};
//node X[M];
int main()
{
    ios::sync_with_stdio(false);//ISHWAR
    cin.tie(0);//Tourist_Twin
   //freopen("kamona.txt","r",stdin);
    ll a,b,c=1,x,y,d,t,sum=0,mx=MOD,i,j,ans;
    cin>>a>>b;
    for(i=a;i<b&&c<=2019;i++)
    {
        d=1;
        for(j=i+1;j<=b&&d<=2019;j++)
        {
            ans=(i*j);
            x=ans%2019;
            if(x<mx)
            {
                mx=x;
            }
            d++;
        }
        c++;
    }
    cout<<mx<<endl;


        return 0;
    }


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

int main()
{
    string s;
    cin >> s;
    cout << 700 + 100 * count(s.begin(), s.end(), 'o') << endl;

    return 0;
}


Measured memory_bytes: 256
using System;

class program
{



    static void Main(string[] args)
    {
        //dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])

        string[] input = Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);

        int[,] graph = new int[N, N];
        int[,] dp = new int[N, N];

        int ans = 0;

        for(int i = 0; i < N; i++)
        {
            for(int j = 0; j < N; j++)
            {
                dp[i, j] = 100000000;
                graph[i, j] = -1;
            }
        }

        for(int i = 0; i < M; i++)
        {
            input = Console.ReadLine().Split();
            int a = int.Parse(input[0]) - 1;
            int b = int.Parse(input[1]) - 1;
            int c = int.Parse(input[2]);
            graph[a, b] = c;
            dp[a, b] = c;
            dp[b, a] = c;
        }

        for(int k = 0; k < N; k++)
        {
            for(int i = 0; i < N; i++)
            {
                for(int j = 0; j < N; j++)
                {
                    dp[i, j] = Math.Min(dp[i, j], dp[i, k] + dp[k, j]);
                }
            }
        }

        for(int i = 0; i < N; i++)
        {
            for(int j = 0; j < N; j++)
            {
                if (graph[i, j] > 0)
                {
                    if (graph[i, j] > dp[i, j]) ans++;
                }
            }
        }

        Console.WriteLine(ans);

    }
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    llint n, k;
    cin >> n >> k;

    vector<llint> a(n);
    vector<llint> f(n);
    for(llint in=0;in<n;++in) {
        cin >> a[in];
    }
    for(llint in=0;in<n;++in) {
        cin >> f[in];
    }
    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<llint>());

    llint l=0, r = a[n-1]*f[0], mid, ans = a[n-1]*f[0], ktmp;
    while(l<r) {
        mid = l + (r - l) / 2;
        ktmp = 0;
        for(llint in=0;in<n;++in) {
          if(a[in]*f[in]<=mid) continue;
            ktmp += a[in] - mid / f[in];
        }
        if(ktmp<=k) {
            chmin(ans, mid);
            r = mid;
        }
        else l = mid + 1;
    }

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


Measured memory_bytes: 6368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

using namespace std;

int main() {
    int N; cin >> N;
    vector<double> vec(N);
    for (int i = 0; i < N; i++)
    {
        cin >> vec[i];
    }
    
    double gousei;
    sort(vec.begin(), vec.end());
    for (int i = 0; i < N-1; i++)
    {
        gousei = (vec[i] + vec[i+1]) / 2;
        vec[i+1] = gousei;
    }

    cout << setprecision(10) << vec[N-1] << endl;
}


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

int main(){
	int n;
	cin >> n;
	map<string,int> cnt;
	rep(i,n){
		string s;
		cin >> s;
		cnt[s]++;
	}
	cout << cnt.size() << endl;
}

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

int combination(int n, int r) {
    if (r * 2 > n) r = n - r;
    int dividend = 1;
    int divisor = 1;
    for (int i = 1; i <= r; ++i) {
        dividend *= (n - i + 1);
        divisor *= i;
    }
    return dividend / divisor;
}

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

    int ans = 0;
    if (N > 1) {
        ans += combination(N, 2);
    }
    if (M > 1) {
        ans += combination(M, 2);
    }

    cout << ans << endl;
}

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

int n;
int a[100005];
vector <int> adjList[100005];
int s;

long long dfs(int u, int p) {
	long long sum = 0;
	long long maxval = 0;
	if (adjList[u].size() == 1) return a[u];
	for (int v : adjList[u]) {
		if (v == p) continue;
		long long cur = dfs(v, u);
		sum += cur;
		maxval = max(cur, maxval);
		if (cur < 0) return -1;
	}
	if (a[u] > sum || maxval > a[u]) return -1;
	return a[u] * 2 - sum;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1; i < n; i++) {
		int u, v; scanf("%d%d", &u, &v);
		adjList[u].push_back(v);
		adjList[v].push_back(u);
	}
	if (n == 2) {
		if (a[1] == a[2]) printf("YES\n");
		else printf("NO\n");
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		if (adjList[i].size() >= 2) s = i;
	}
	if (dfs(s, -1) == 0) printf("YES\n");
	else printf("NO\n");
	return 0;
}


Measured memory_bytes: 16656
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

struct node {
	LL L, R, A, S;
	node(int x) {
		L = max(x, 0);
		R = max(x, 0);
		A = max(x, 0);
		S = x;
	}
	node operator+(const node& o) {
		node res(0);
		res.A = max(max(A, o.A), R + o.L);
		res.L = max(L, S + o.L);
		res.R = max(o.R, o.S + R);
		res.S = S + o.S;
		return res;
	}
};

//ただのセグ木
template<typename T>
class RMQ {
private:
	const T DEF;//デフォルト値(minではINF、sumでは0など)
	vector<T> seg;//生データ
	int width;//セグ木の幅(配列の大きさではない！)
	T query_raw(int a, int b, int k, int l, int r)const {
		if (a >= r || b <= l)return DEF;
		if (a <= l && r <= b)return seg[k];
		return query_raw(a, b, 2 * k + 1, l, (l + r) / 2) + query_raw(a, b, 2 * k + 2, (l + r) / 2, r);
	}
public:
	//サイズn、デフォルト値defのセグ木を作る
	RMQ(int n, T def) :DEF(def) {
		width = 1;
		while (width < n)width *= 2;
		seg.assign(width * 2 - 1, DEF);
	}
	//区間[a,b)のクエリの答えを取得する
	T query(int a, int b)const { return query_raw(a, b, 0, 0, width); }
	//x番目の要素をkに更新する
	void update(int k, T x) {
		k += width - 1;
		seg[k] = x;
		while (k > 0) {
			k = (k - 1) / 2;
			seg[k] = seg[2 * k + 1] + seg[2 * k + 2];
		}
	}
	//配列ごと初期化する
	void init(const vector<T>& vec) {
		for (int i = 0; i < min(width, (int)vec.size()); ++i)
			seg[i + width - 1] = vec[i];
		for (int k = width - 2; k >= 0; --k)
			seg[k] = seg[2 * k + 1] + seg[2 * k + 2];
	}
};

int N, Q;
LL A[123456];

int main() {
	cin >> N >> Q;
	RMQ<node>tree(N, node(0));
	for (int i = 0; i < N; ++i) {
		LL val;
		cin >> val;
		tree.update(i, node(val));
	}
	cout << tree.query(0, N).A << endl;
	for (int i = 0; i < Q; ++i) {
		LL k, x;
		cin >> k >> x;
		k--;
		tree.update(k, node(x));
		cout << tree.query(0, N).A << endl;
	}
	return 0;
}


Measured memory_bytes: 11052
#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 rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXLEN 1001
int dp[MAXLEN][MAXLEN];

int main(){
  int n;cin>>n;
  rep(i, n){
    rep(i, MAXLEN)rep(j, MAXLEN)dp[i][j]=0;

    string l,r;cin>>l>>r;
    rep(x, l.size())rep(y, r.size()){
      if(l[x]==r[y]) dp[x+1][y+1] = dp[x][y]+1;
      else dp[x+1][y+1] = max(dp[x+1][y], dp[x][y+1]);

    // cout<<r[x]<<' '<<l[y]<<endl;
    // rep(x, l.size()+1){
    //   rep(y, r.size()+1)cout<<dp[x][y]<<' ';cout<<endl;
    // }
    // cout<<"#######"<<endl;

    }

    cout<<dp[l.size()][r.size()]<<endl;

  }
  return 0;
}



Measured memory_bytes: 7128
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define int ll

int unko[214514]={};

void tri(){
    REP1(i,214513) unko[i] = i + unko[i-1];
}

signed main(){
    tri();
    int x;
    cin >> x;
    int ans;
    REP(i,214514){
        if(unko[i]>=x){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool isprime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

struct CustomCompare
{
    bool operator()(const int& lhs, const int& rhs)
    {
        return lhs < rhs;
    }
};

bool comp(pair<ll, ll>a,pair<ll,ll>b)
{
    return a.fi>=b.fi;
}

ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}

ll addmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a+b)%mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll ans =0;
string s,t; cin>>s>>t;
rep(i,0,s.size())if(s[i]==t[i])ans++;
cout<<s.size()-ans<<endl;
return 0;
}
/*
1
8
1 7 3 4 7 6 2 9
*/


Measured memory_bytes: 3784
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    K = int(input())
    x = list(int(_) for _ in input().split())
    ans = 0
    for i in range(N):
        ans += min(x[i],K-x[i]) * 2
    print(ans)
    
if __name__ == '__main__':
    main()


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::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==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

auto dp = make_v<int>(1, 1);

int dfs(const string& s, int l = 0, int r = -1) {
  if (r < 0) r = s.size();
  if (~dp[l][r]) return dp[l][r];
  if (r-l == 0) return 1;
  if (r-l < 3) return 0;
  int& res = dp[l][r];
  if (s[l] != 'm' || s[r-1] != 'w') return res = 0;
  res = 0;
  FOR(i, l+1, r-1) {
    if (s[i] == 'e') {
      res |= (dfs(s, l+1, i) && dfs(s, i+1, r-1));
    }
  }
  return res;
}

int main(void) {
  string s;
  cin >> s;
  dp = make_v<int>(s.size()+1, s.size()+1);
  fill_v<int>(dp, -1);
  cout << (dfs(s) ? "Cat" : "Rabbit") << endl;
}




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

int main(){
    string s;
    cin >> s;

    long long n=s.length();

    long long sum =0;

    for(long long i=0;i<n;i++){
        long long tmp=s[i]-'0';
        //cout << tmp << endl;
        for(long long j=0;j<=i;j++){
            tmp += s[j]-'0';
        }
        sum += pow(2,i-1)*pow(10,n-i-1)*tmp;
        //cout  << pow(2,i-1) << " " << pow(10,n-i-1) << endl;
        //cout  << tmp << " " << sum << endl;
    }
    cout << sum << endl;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

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

  int n;
  cin >> n;
  vector<int64> xs(n), ys(n), ps(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i] >> ys[i] >> ps[i];
  }

  vector<int64> ans(n + 1, INT64_MAX);
  for (int city_pattern = 0; city_pattern < 1 << n; city_pattern++) {
    vector<int> cs;
    for (int c = 0; c < n; c++) {
      if (city_pattern & (1 << c)) {
        cs.push_back(c);
      }
    }

    int num_roads = cs.size();

    vector<int64> r_xs;
    vector<int64> r_ys;
    for (int d_pattern = 0; d_pattern < 1 << num_roads; d_pattern++) {
      r_xs.clear();
      r_ys.clear();
      r_xs.push_back(0);
      r_ys.push_back(0);

      for (int r = 0; r < num_roads; r++) {
        if (d_pattern & (1 << r)) {
          r_ys.push_back(ys[cs[r]]);
        } else {
          r_xs.push_back(xs[cs[r]]);
        }
      }

      int64 cost = 0;
      for (int c = 0; c < n; c++) {
        if (city_pattern & (1 << c)) continue;
        int64 min_d = INT64_MAX;
        for (int64 r_x : r_xs) {
          UpdateMin(min_d, abs(xs[c] - r_x));
        }
        for (int64 r_y : r_ys) {
          UpdateMin(min_d, abs(ys[c] - r_y));
        }
        cost += min_d * ps[c];
      }

      UpdateMin(ans[num_roads], cost);
    }
  }

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

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

int remainAmount(int a, int b) {
   int counter = 0;
   while (a>=b){
      a-=b;
   }
   return a;
}

int main() {

  int X,A,B,newAmount;
  cin>>X>>A>>B;
  X=X-A;
  cout<<remainAmount(X,B)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/fenwicktree>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;
using namespace atcoder;

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

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

  fenwick_tree<ll> fw(N);
  rep(i,N) {
    int a;
    cin >> a;
    fw.add(i, a);
  }
  rep(qi,Q) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 0) {
      fw.add(x, y);
    } else {
      cout << fw.sum(x, y) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 8208
#include <iostream>
#define mod 1000000007
using namespace std;
typedef long long ll;
int main() {
    ll a;
    cin >> a;
    ll sum = 1;
    for(int i = 1 ; i <= a ; i++) {
        sum *= i;
        sum %= mod;
    }
    cout << (sum + mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

template <typename T> inline constexpr bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline constexpr bool chmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
template <typename ite> void scan_ite(ite start, ite end) {
  for (auto i = start; i != end; i++)
    cin >> (*i);
}
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

int main() {
  int n;
  cin >> n;
  vector<int> cnt(n, 0);
  for (int i = 0; i < n - 1; i++) {
    int a;
    cin >> a;
    a--;
    cnt[a]++;
  }
  for (auto i : cnt) {
    cout << i << endl;
  }
}


Measured memory_bytes: 3616