akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,l,r) for(ll i=(l); i<(r); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int inf = 1001001001;
const ll mod = 1000000007;
using pp=pair<ll,ll>;
 
// union by size + path having
class UnionFind {
public:
   vector <ll> par; // 各元の親を表す配列
   vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
   // Constructor
   UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
       for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
   }
   void init(ll sz_) {
       par.resize(sz_);
       siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
       for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
  }
 
   // Member Function
   // Find
   ll root(ll x) { // 根の検索
      while (par[x] != x) {
           x = par[x] = par[par[x]]; // x の親の親を x の親とする
       }
       return x;
  }
 
   // Union(Unite, Merge)
   bool unite(ll x, ll y) {
       x = root(x);
       y = root(y);
       if (x == y) return false;
       // merge technique（データ構造をマージするテク．小を大にくっつける)
       if (siz[x] < siz[y]) swap(x, y);
       siz[x] += siz[y];
       par[y] = x;
       return true;
  }
 
  bool same(ll x, ll y) { // 連結判定
       return root(x) == root(y);
  }
 
  ll size(ll x) { // 素集合のサイズ
      return siz[root(x)];
  }
};
 
ll modpow(ll x, ll n) {
   x = x%mod;
   if(n==0) return 1;  //再帰の終了条件
 
   else if(n%2==1) {
       return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
   }
   else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}
 
ll com(ll n, ll k) {
   ll x = 1;
   for(int i=n-k+1; i<=n; i++) {
      x = x*i%mod;
   }
 
   ll y = 1;
   for(int i=1; i<=k; i++) {
       y = y*i%mod;
   }
   y = modpow(y, mod-2);
 
   return x*y%mod;
}
 
bool is_prime(const unsigned n){
   switch(n){
       case 0: // fall-through
       case 1: return false;
       case 2: // fall-through
       case 3: return true;
  } // n > 3 が保証された
 
   if(n % 2 == 0 || n % 3 == 0) return false;
   // n は 2 と 3 のいずれの倍数でもないことが保証された
   // これより n は (6の倍数)-1 か (6の倍数)+1 である
 
   // 6の倍数前後の数を使って試し割りをする
   for(unsigned i = 5; i * i <= n; i += 6) {
       if(n % i     == 0) return false; // (6の倍数)-1
       if(n % (i+2) == 0) return false; // (6の倍数)+1
   }
 
   return true;
}
 
int digsum(int n) {
   int res = 0;
   while(n > 0) {
       res += n%10; //ここをres++;に変えたら桁数を求める関数になる
       n /= 10;
   }
   return res;
}
vector<ll> divisor(ll n){
   vector<ll> ret;
   for(ll i = 1 ; i*i <= n ; i++){
       if(n%i == 0){
           ret.push_back(i);
           if(i*i != n) ret.push_back(n/i);
       }
   }
   sort(ret.begin(),ret.end());
   return ret;
}
 
int main(){
    
    string S;
    cin >> S;
    cout << S.substr(0,3) << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b;
  cin >> a >> b;
  if(a <= 5) cout << 0 << endl;
  else if (a < 13) cout << b/2 << endl;
  else cout << b << endl;
}

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


def solve(N: int, S: "List[str]", P: "List[int]"):
    p = []
    for i in range(N):
        p.append([S[i], -P[i], i + 1])
    #p.sort(key=lambda x: [[0])
    p.sort()
    for x in p:
        print(x[2])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [str()] * (N)  # type: "List[str]" 
    P = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        S[i] = next(tokens)
        P[i] = int(next(tokens))
    solve(N, S, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
// trace works only with c++ 14

#include<bits/stdc++.h>

using namespace std;

//#pragma comment (linker, "/STACK:256000000")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define all(a) a.begin(), a.end()
#define endl '\n'
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define boost  ios_base::sync_with_stdio(false);
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long llint;
typedef long long ll ;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int mod = 1e9 + 7 ;
ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
ll gcd(ll a , ll b){return a==0?b:gcd(b%a,a);}
/*---------------------------------------------------------------------------------------------------------------------*/
const int maxn = 100010;
const int inf = INT_MAX;

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	ll l[8];
	for(int i = 1; i < 8; i++)
		cin >> l[i];
	ll ans2 = 0;
	if(l[1] && l[4] && l[5]) {
		ans2 += 6;
		l[1]--;
		l[5]--;
		l[4]--;
		ans2 += l[2] * 2;
		ans2 += (l[1] / 2) * 4;
		ans2 += (l[5] / 2) * 4;
		ans2 += (l[4] / 2) * 4;
		l[1]++;
		l[5]++;
		l[4]++;
	}
	ll ans = l[2] * 2;
	ans += (l[1] / 2) * 4;
	l[1] %= 2;
	ans += (l[5] / 2) * 4;
	ans += (l[4] / 2) * 4;
	l[5] %= 2;
	l[4] %= 2;
	if(l[1] & l[4] & l[5]) {
		ans += 6;
	}
	cout << max(ans2, ans) / 2;
	cin.get();
	cin.get();
	cin.get();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>

using namespace std;


int main(void){
	int n,q;
	vector<int> as;
	vector<int> vs;
	set<pair<int,int> > ranking;
	vector<int> fishes;
	vector<int> ansAs;
	vector<int> ansVs;

	cin >> n >> q;
	for(int i=0;i<q;i++){
		int a, v;
		cin >> a >> v;
		as.push_back(a-1);
		vs.push_back(v);
	}
	for(int i=0;i<n;i++){
		fishes.push_back(0);
	}

	for(int i=0;i<q;i++){
		ranking.insert(pair<int,int>(0,-as[i]));
	}

	for(int i=0;i<q;i++){
		pair<int,int> old = pair<int,int>(fishes[as[i]],-as[i]);
		fishes[as[i]] += vs[i];
		pair<int,int> now = pair<int,int>(fishes[as[i]],-as[i]);
		ranking.erase(old);
		ranking.insert(now);
		set<pair<int,int> >::iterator itr = ranking.end();
		--itr;
		ansAs.push_back(-(itr->second));
		ansVs.push_back(itr->first);
	}


	for(int i=0;i<q;i++){
		cout << ansAs[i] + 1 << " " << ansVs[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 11596
while(True):
    vals = input().split()
    a = int(vals[0])
    op = vals[1]
    b = int(vals[2])

    if op == '?': break
    if op == '+': print(a + b)
    if op == '-': print(a - b)
    if op == '*': print(a * b)
    if op == '/': print(a // b)

Measured memory_bytes: 7656
#include<bits/stdc++.h>
using namespace std;
int main(){
int  n;
cin >> n;
vector <int>a(n);
for(int i=0;i<n;i++){
cin >> a.at(i);
}
sort(a.begin(),a.end());
int sa = a.at(n/2)- a.at(n/2 -1);
 
cout<< sa <<endl;
}

Measured memory_bytes: 3732
(defun get-input-list (n)
  (loop for x to (- n 1)
        collect (read))
    )

(defun main (n)
  (let* ((rst 0)
         (inputs (get-input-list n))
         (temp (car inputs)))
    (loop for x in inputs
          if (<= x temp) 
          do (progn (setf temp x)
               (incf rst))
          )
    rst))

(format t "~A~%" (main (read)))


Measured memory_bytes: 59752
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define inf (int)(3e18)

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N,A[200005],cnt[200005];
signed main() {
	cin>>N;
	rep(i,N){
		cin>>A[i];
		A[i]--;
		cnt[A[i]]++;
	}
	int ans=0;
	rep(i,N){
		ans+=cnt[i]*(cnt[i]-1)/2;
	}
	rep(i,N){
		cout<<ans-cnt[A[i]]+1<<endl;
	}
}



Measured memory_bytes: 4736
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
//#include <stack>
//#include <queue>
#include <iomanip>

/*
#include <math.h>
*/
int standerd = 1000000007;
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 
int main(){

    int N;
    int M;
    cin >> N;
    cin >> M;

    vector<int> S;
    vector<int> T;
    int tmp;    
    for( int ni = 0 ; ni < N ; ni++ ){
        cin >> tmp;
        S.push_back(tmp);
    }
    for( int ni = 0 ; ni < M ; ni++ ){
        cin >> tmp;
        T.push_back(tmp);
    }

    long long dp[N][M]={};
    for( int ni = 0 ; ni < N ; ni++ ){
        for( int mi = 0; mi < M ; mi++ ){

            if(ni > 0 && mi > 0){
                dp[ni][mi]+= dp[ni][mi-1] + dp[ni-1][mi] - dp[ni-1][mi-1];

                if( S[ni]==T[mi] ){
                    dp[ni][mi]+= 1 + dp[ni-1][mi-1];
            }


            }else if(ni==0 && mi==0){
                if(S[ni]==T[mi]) dp[ni][mi]+= 1;

            }else if(ni==0){
                if(S[ni]==T[mi]){
                    dp[ni][mi]+= 1 + dp[ni][mi-1];
                }else{
                    dp[ni][mi]+= dp[ni][mi-1];
                }
            }else if(mi==0){
                if(S[ni]==T[mi]){
                    dp[ni][mi]+= 1 + dp[ni-1][mi];
                }else{
                    dp[ni][mi]+= dp[ni-1][mi];
                }
            }

            dp[ni][mi] = dp[ni][mi] % standerd;
            //cout << "ni:" << ni << "\tmi:" << mi   << "\t= " << dp[ni][mi] << endl;
        }
    }
    if(dp[N-1][M-1] < 0) dp[N-1][M-1] += standerd;
    cout << (dp[N-1][M-1] + 1) % standerd;

}

Measured memory_bytes: 31488
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(void)
{
	set<int> s;
	for (int i = 0; i < 3; i++)
	{
		int x; cin >> x;
		s.insert(x);
	}
	cout << s.size() << endl;
}


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

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;

  ll ans = 0;
  for (ll i = 0; i < 1000; ++i) {
    string nstr = to_string(i);
    while(nstr.size() < 3) {
      nstr = "0" + nstr;
    }
    ll digit = 0;
    for (auto str : S) {
      if (str == nstr[digit]) digit++;
      if (digit == 3) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3688
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define LL long long
#define PP std::pair<int,LL>
int N, M;
LL min = 1 << 30;
LL max = -(1 << 30);
bool D[100010];
LL X[100010];
std::vector<PP> R[100010][2];

int main() {
	std::cin >> N >> M;
	for (int i = 0; i < M; i++) {
		LL a, b, c;
		std::cin >> a >> b >> c;
		R[a][0].push_back({ b,c });
		R[b][1].push_back({ a,c });
	}
	std::queue<int> q;
	for (int i = 1; i <= N; i++) {
		if (D[i])continue;
		q.push(i);
		while (!q.empty()) {
			int s = q.front();
			q.pop();
			for (auto u : R[s][0]) {
				if (!D[u.first]) {
					X[u.first] = X[s] - u.second;
					min = std::min(min, X[u.first]);
					max = std::max(max, X[u.first]);
					q.push(u.first);
					D[u.first] = true;
				}
				else {
					if (X[u.first] != X[s] - u.second) {
						std::cout << "No" << std::endl;
						return 0;
					}
				}
			}
			for (auto u : R[s][1]) {
				if (!D[u.first]) {
					X[u.first] = X[s] + u.second;
					min = std::min(min, X[u.first]);
					max = std::max(max, X[u.first]);
					q.push(u.first);
					D[u.first] = true;
				}
				else {
					if (X[u.first] != X[s] + u.second) {
						std::cout << "No" << std::endl;
						return 0;
					}
				}
			}
		}
	}
	if (1000000000 < (LL)max - (LL)min) {
		std::cout << "No" << std::endl;
		return 0;
	}
	std::cout << "Yes" << std::endl;
}

Measured memory_bytes: 16256
#include <stdio.h>

int main(void)
{
	int a, b, c, d, l;
	int s, t;
	int day;
	
	scanf("%d %d %d %d %d", &l, &a, &b, &c, &d);
	s = a / c;
	t = b / d;
	if (a % c > 0) {
		s++;
	}
	if (b % d > 0) {
		t++;
	}
	day = (s > t) ? s : t;
	printf("%d\n", l - day);
	
	return (0);
}

Measured memory_bytes: 596
#include <iostream>
#include <queue>
#include <algorithm>
const int N = 200+5;

int n;
bool V[N][N];
bool C[N];
bool P[N];
int G[N];
int D[N];
int R[N];

int BFS(int v, int g)
{
    for (int i=0;i<n;++i)
        P[i] = false;
    std::queue<int> q; q.push(v);
    P[v] = true;
    C[v] = true;
    D[v] = 1;
    int max = 1;
    while (!q.empty())
    {
        int w = q.front();
        max = std::max(max, D[w]);
        G[w] = g;
        q.pop();
        for (int u=0;u<n;++u)
        {
            if (!V[w][u]) continue;
            if (P[u]) {
                if (C[u] == C[w])
                {
                    return -1;
                }
            }
            else {
                P[u] = true;
                C[u] = !C[w];
                D[u] = D[w] + 1;
                q.push(u);
            }
        }
    }
    return max;
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin >> n;
    for (int i=0;i<n;++i)
    {
        for (int j=0;j<n;++j)
        {
            char c;
            std::cin >> c;
            V[i][j] = c == '1';
        }
    }
    int g = 0, gg;
    for (int i=0;i<n;++i)
    {
        if (G[i] == 0) { ++g; gg = g; }
        else gg = G[i];
        int b = BFS(i, gg);
        if (b < 0)
        {
            std::cout << -1;
            return 0;
        }
        R[gg] = std::max(R[gg], b);
    }

    int result = 0;
    for (int i=0;i<n;++i)
        result += R[i];
    std::cout << result;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

a,b = map(int,input().split())
if a > 0:
    print("Positive")
elif a <= 0 <= b:
    print("Zero")
else:
    num = abs(a) - abs(b) + 1
    if num % 2:
        print("Negative")
    else:
        print("Positive")

    
    


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <queue>

struct process {
  std::string name;
  int time;
};

class Scheduler {
public:
  explicit Scheduler(std::queue<struct process>& process_queue, int quantum)
      : quantum{quantum}, process_queue{process_queue} {};

  void run();

private:
  const int quantum;
  int time_running;
  std::queue<struct process>& process_queue;
  std::vector<struct process> finished;

  void run_process();
};

void Scheduler::run_process() {
  auto proc = process_queue.front();
  process_queue.pop();
  if (proc.time > quantum) {
    time_running += quantum;
    proc.time -= quantum;
    process_queue.push(proc);
  } else {
    time_running += proc.time;
    proc.time = time_running;
    finished.push_back(proc);
  }
}

void Scheduler::run() {
  time_running = 0;

  while (!process_queue.empty()) {
    run_process();
  }
  for (auto& proc: finished) {
    std::cout << proc.name << ' ' << proc.time << '\n';
  }
}

int main() {
  std::queue<struct process> process_queue;
  int nproc, quantum;
  std::cin >> nproc >> quantum;
  for (auto i = 0; i < nproc; i++) {
    struct process proc;
    std::cin >> proc.name >> proc.time;
    process_queue.push(proc);
  }

  Scheduler sched{process_queue, quantum};
  sched.run();
  return 0;
}

Measured memory_bytes: 6876
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    char a[200];
    char s[20];
    cin>>s;
    int i,j,k,m,n;
    n=strlen(s);
    int y=0;
    int cnt=0;
    for(i=0; i<n; i++)
    {
        if(s[i]=='0')
        {
                a[y++]='0';
                cnt++;
        }
        else if(s[i]=='B')
        {
            if(cnt)
            {
                y--;
                cnt--;
            }
        }
        else
        {
                a[y++]='1';
                cnt++;
        }

    }
    for(i=0; i<y; i++)
        cout<<a[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
 int mothernum, mother[10000], kidsnum, kids[500]; 
 int i, j, kosuu=0;
 
 scanf("%d", &mothernum);
 for (i = 0; i < mothernum; i++) {
   scanf("%d", &mother[i]);
 }
  
 scanf("%d", &kidsnum);
 for(i = 0; i < kidsnum; i++) {
   scanf("%d", &kids[i]);
 }
 
 for (i = 0; i < kidsnum; i++){
   for (j = 0; j < mothernum; j++) {
     if (kids[i] == mother[j]) {
       kosuu++;
       break;
     }
   }
 }
 
 printf("%d\n",kosuu); 

 return 0;
}

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

int main() {
    string str1,str2;
    cin>>str1>>str2;
    for(int i=0;i<str1.length();i++) {
        if(str1[i]!=str2[i]) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

int main(){

        int a[3],N;
        int i;

        cin >> N;

        for(i=0;i<3;i++){
        a[i]=N%10;
        N=N/10;
        }

/*      for(i=0;i<3;i++){
        cout << a[i]<< endl;
        }
*/

        for(i=0;i<3;i++){
                if(a[i]==1){
                a[i]=9;
                }else{
                a[i]=1;
                }
        }

        N=100*a[2]+10*a[1]+a[0];

        cout << N <<endl;


        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a >= k) {
        cout << k << endl;
    } else if (a + b >= k) {
        cout << a << endl;
    } else {
        cout << a - (k - (a + b)) << endl;
    }
}


Measured memory_bytes: 3640
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner s=new Scanner(System.in);    
		int N=s.nextInt();		
		int K=s.nextInt();	
		int h[]=new int[N];
		for(int i=0;i<N;i++)
		{
			h[i]=s.nextInt();
		}
		int dp[]=new int[N];
		Arrays.fill(dp,-1);
		dp[0]=0;
		int i=0,d=0;
		while(i<N-1)
		{
			int j=1;
			while(j<=K)
			{
				if(i+j<N)
				{
					d=Math.abs(h[i]-h[i+j])+dp[i];
					if(dp[i+j]==-1)
						dp[i+j]=d;
					else
						if(dp[i+j]>d)
							dp[i+j]=d;
				}
				else
					break;
				j+=1;
			}
			i+=1;
		}
		System.out.print(dp[N-1]);

	}
}


Measured memory_bytes: 52092
#include<iostream>
#include<cstdio>
#include<string>
#define sb substr
#define FOF(i,a,b) for(int i=a;i< b;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(u) for(ull i=hd[u],v,w;v=e[i].v,w=e[i].w,i;i=e[i].n)
using namespace std;
typedef unsigned long long ull;
const int N=110,T=(1<<24)+1,M=500500,P=998244353;
const ull B=49999;
int n,fl,hd[T],b[N];
string s;
struct edge{int n;ull v;int w;}e[M];
void add(int u,ull v,int w){e[++fl]=(edge){hd[u],v,w};hd[u]=fl;}
int dfs(string s){
	int n=s.length(),u,r=0;ull h=0;
	string t;
	if(n==1) return (s[0]^48)+1;
	FOF(i,0,n) h=h*B+s[i]+1;
	u=h&(1<<24)-1;
	REP(u)if(v==h) return w;
	(r+=1ll*dfs(s.sb(0,1))*dfs(s.sb(1,n-1))%P)%=P;
	FOR(i,2,n)FOR(j,1,n/i){
		FOF(k,0,j) b[k]=1;
		FOF(k,0,i*j) b[k%j]&=s[k]^48;
		t="";
		FOF(k,0,j) t+=b[k]^48;
		(r+=1ll*dfs(t)*(i*j<n?dfs(s.sb(i*j,n-i*j)):1)%P)%=P;
	}//cout<<s<<' '<<"r="<<r<<'\n';
	return add(u,h,r),r;
}
int main(){
	//freopen("1.in","r",stdin);
	cin>>s;n=s.length();
	cout<<dfs(s)<<'\n';
}

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

using namespace std;
string a,b;
int main()
{
  
  cin>>a>>b;
  for(int i=0;i<a.size()+b.size();i++)
  {
  	if(i%2==0)cout<<a[i/2];
  	else cout<<b[i/2];
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100000
#define maxn (N + 10)
#define maxm (maxn * 2)
#define pb push_back
#define lc (id * 2)
#define rc (id * 2 + 1)
#define Mod(x) (((x) % mod + mod) % mod)
typedef long long ll;
const ll INF = (1e8);
const ll mod = (998244353);
int main(){
    int n;scanf("%d",&n);
    int ans = (1000 - n % 1000) % 1000;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3824
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val m = in.readLine().toInt

    out.println(48 - m)
    out.flush()
  }
}


Measured memory_bytes: 25400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  vl a(3);
  cin >> n >> a[0] >> a[1] >> a[2];
  vs s(n);
  rep(i, n) cin >> s[i];
  bool ok = true;
  vc ans(n);
  ll sum = a[0] + a[1] + a[2];
  if(sum == 0)
    ok = false;
  else if(sum == 1) {
    rep(i, n) {
      int x = s[i][0] - 'A';
      int y = s[i][1] - 'A';
      if(a[x] + a[y] == 0)
        ok = false;
      else {
        ans[i] = (a[y] > 0 ? x : y) + 'A';
        swap(a[x], a[y]);
      }
    }
  } else {
    rep(i, n) {
      int x = s[i][0] - 'A';
      int y = s[i][1] - 'A';
      if(a[x] + a[y] == 0)
        ok = false;
      else if(a[x] == 0) {
        ans[i] = x + 'A';
        a[x]++;
        a[y]--;
      } else if(a[y] == 0) {
        ans[i] = y + 'A';
        a[y]++;
        a[x]--;
      } else if(i < n - 1) {
        int nx = s[i + 1][0] - 'A';
        int ny = s[i + 1][1] - 'A';
        if(x == nx || x == ny) {
          ans[i] = x + 'A';
          a[x]++;
          a[y]--;
        } else {
          ans[i] = y + 'A';
          a[y]++;
          a[x]--;
        }
      } else {
        ans[i] = x + 'A';
        a[x]++;
        a[y]--;
      }
    }
  }
  if(ok) {
    cout << "Yes" << endl;
    rep(i, n) cout << ans[i] << endl;
  } else
    cout << "No" << endl;
}

Measured memory_bytes: 6432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
priority_queue<ll> que;
int x, y, z, k;
int main()
{
    cin >> x >> y >> z >> k;
    vector<ll> a(x);
    vector<ll> b(y);
    vector<ll> c(z);
    for (int i = 0; i < x; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < y; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < z; i++)
    {
        cin >> c[i];
    }
    vector<ll> d;
    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            d.push_back(a[i] + b[j]);
        }
    }
    sort(d.begin(), d.end(), greater<ll>());
    for (int i = 0; i < min(k, x * y); i++)
    {
        for (int j = 0; j < z; j++)
        {
            que.push(c[j] + d[i]);
        }
    }
    for (int i = 0; i < k; i++)
    {
        ll ans = que.top();
        que.pop();
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 43368
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

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

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

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e15 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

int give(int num) {
  int lo = -1000, hi = 1000;
  for(int i = 1; i <= 50; i++) {
    int mid = (hi+lo) >> 1;
    if((mid*mid*mid*mid*mid) > num) {
      hi = mid;
    }
    else {
      lo = mid;
    }
  }
  return lo;
}

void solve() {
  int x; cin >> x;
  for(int i = -1000; i <= 1000; i++) {
    int num = x + i*i*i*i*i;
    int temp = give(num);
    //cout << num << '\n';
    if((temp*temp*temp*temp*temp) == num) {
      cout << temp << " " << i << '\n'; return;
    }
  }
}   

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

    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    int t = 1; // cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }
}    


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
int n, a, b;
const ll mod =1000000007;

ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return pow(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = pow(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return pow(x, mod - 2);
}

int main(void)
{
	cin >> n >> a >> b;
	cout << min(a, b) << ' ';
	cout << max(0, a + b - n) << endl;
	int www;
	cin >> www;
}


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

int main() {
    int S, h, m, s;
    cin >> S;
    h = S / 3600;
    m = (S - h * 3600) / 60;
    s = S - h * 3600 - m * 60;

    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3092
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

n, m, l = map(int, input().split())
INF = 1 << 60

dist = [[INF] * n for _ in range(n)]

for i in range(n):
    dist[i][i] = 0

for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if c > l:
        continue
    dist[a][b] = c
    dist[b][a] = c


dist = floyd_warshall(csr_matrix(dist))

dist2 = np.full_like(dist, 1)
dist2[np.where(dist > l)] = INF
dist2 = floyd_warshall(dist2, directed=False)
dist2[dist2 == INF] = 0
dist2 = dist2.astype(int)

q = int(input())

ans = []
for _ in range(q):
    s, t = map(int, input().split())
    if dist[s - 1, t - 1] == -1:
        ans.append(-1)
    else:
        ans.append(dist2[s - 1, t - 1] - 1)

print(*ans, sep="\n")

Measured memory_bytes: 45832
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<set>
#include<algorithm>
using namespace std;
char s[100][100];
int vis[4][2]={0,1,0,-1,-1,0,1,0};
int n,m;
bool check(int a,int b)
{
	for(int i=0;i<4;i++)
	{
		int x=a+vis[i][0];
		int y=b+vis[i][1];
		if(x<0||x>=n||b<0||b>=m||s[x][y]=='.');
		else return false;
	}
	return true;
}
int main()
{
	int i,j,flag=0;
	cin>>n>>m;
	for(i=0;i<n;i++)
	scanf("%s",s[i]);
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(s[i][j]=='#')
			{
				if(check(i,j))
				{
					flag=1;
					break;
				}
			}
		}
		if(flag)break;
	}
	if(flag)printf("No\n");
	else printf("Yes\n");
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void err() {
  cout << "No" << endl;
  exit(0);
}
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, a, b, c, d; string s;
  cin >> n >> a >> b >> c >> d >> s;
  a--; b--; c--; d--;
  for (int t = 0; t < 2; t++) {
    for (int i = a + 1; i < c - 1; i++) {
      if (s[i] == '#' && s[i + 1] == '#') err();
    }
    swap(a, b);
    swap(c, d);
  }
  if (d < c) {
    bool flg = false;
    for (int i = b - 1; i <= d - 1; i++) {
      if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') flg = true;
    }
    if (!flg) err();
  }
   cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct box {
    int ball;
    bool pro;
};

int main() {
    cin >> n >> m;
    int x, y;
    vector<box> hako(n);
    for(int i = 0; i < n; ++i) {
        hako.at(i).ball = 1;
        hako.at(i).pro = false;
    }
    hako.at(0).pro = true;
    for(int i = 0; i < m; ++i) {
        cin >> x >> y;
        x--; y--;
        hako.at(x).ball--;
        hako.at(y).ball++;
        if(hako.at(x).pro) hako.at(y).pro = true;
        if(!hako.at(x).ball) hako.at(x).pro = false;
    }

    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        if(hako.at(i).ball > 0 && hako.at(i).pro == true) cnt++;
    }

    cout << cnt << endl;


}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main()
{
    int N,L,a=0,b=0;
    cin>>N>>L;
    if(L>=0){
        for(int i=2;i<=N;i++){
            a+=L+i-1;
        }
        cout<<a<<endl;
        exit(0);
    }else{
        for(int i=1;i<=N;i++){
            a+=L+i-1;
            if(L+i-1==0)a-=L+i-1;
        }
        if(L+N-1>=0){
            cout<<a<<endl;
            exit(0);
        }else{
            cout<<a-L-N+1<<endl;
            exit(0);
        }
    }
    

    
}


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

int main()
{
    int k;
    string s;
    cin>>k>>s;
    if(s.length()<=k)
        cout<<s<<endl;
    else
    {
        int z=s.length();
        s.erase(k,z-1);
        string s1="...";
        cout<<s+s1<<endl;
    }
    return 0;
}




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

int main() {
  int A,B,a,b;
  cin >> A >> B;
  if(A%100>10*((A/1000)%10)+A/10000){
    a = A/100;
  }
  else{
    a = A/100-1;
  }
  if(B%100>=10*((B/1000)%10)+B/10000){
    b = B/100;
  }
  else{
    b = B/100-1;
  }
  cout << b-a;
}


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

using namespace std;

int main(){
  long long int X,N,D;
  cin >> X >> N >> D;
  X=abs(X);
  long long int cnt;
  if(N<=X/D){
    cout << abs(X-D*N) << endl;
  }
  else{
    cnt=X/D;
    if((N-X/D)%2==0){
      cout << abs(X-cnt*D) << endl;
    }
    else{
      cout << abs(cnt*D+D-X) << endl;
    }
  }
  
  return 0;
}
  
  

Measured memory_bytes: 3496
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	n := getInt()
	_ = getInt()

	ss := make([]string, n)
	for i := range ss {
		ss[i] = getString()
	}
	sort.Strings(ss)

	ans := ""
	for _, s := range ss {
		ans += s
	}

	fmt.Println(ans)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}
int main(void){
    int n,i;
    scanf("%d",&n);
    int seq[n];
    for(i=0;i<n;i++) {
        scanf("%d", &seq[i]);
    }
    qsort(seq, n, sizeof(int), compare_int);
    int h=1;
    for(i=0;i<n-1;i++) {
        if(seq[i]!=seq[i+1])
            h++;
    }
    printf("%d\n",h);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = 0;
    int h = 0;
    for (int i = 0; i < n; i++) {
      String taro = sc.next();
      String hanako = sc.next();
      int judge = taro.compareTo(hanako);
      if (judge > 0) {
        t += 3;
      } else if (judge < 0) {
        h += 3;
      } else {
        t++;
        h++;
      }
    }
    System.out.println(t + " " + h);
  }
}


Measured memory_bytes: 29672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int N;
string s, t;
int main()
{
    cin >> N >> s >> t;
    int ans = 2 * N;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (s.substr(i, (N - i)) == t.substr(j, (N - i)))
            {
                ans -= N - i;
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871; 
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	string s;
	cin >> s;
	s = "#" + s;
	if(s[3] == s[4] && s[5] == s[6])
		cout << "Yes\n";
	else
		cout << "No\n";
	
	return 0;
}

Measured memory_bytes: 256
N,M,C = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

ret = 0
for i in range(N):
    A = [int(x) for x in input().split()]
    f = C
    for j in range(M):
        f += A[j] * B[j]
    if f > 0:
        ret += 1

print(ret)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=7+1e9;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}
ll getInv(ll x,ll p){return qpow(x,p-2,p);}
bool cmp(pair<ll,int> a,pair<ll,int> b){return a.first>b.first;}
const int N=5+2e3;
pair<ll,int> a[N];
ll dp[N][N];
int main(){
    int n; scanf("%d",&n);
    for(int i=0;i<n;i++){
        ll x; scanf("%lld",&x);
        a[i]={x,i};
    }
    sort(a,a+n);
    reverse(a,a+n);
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            if(i+j>=n) break;
            dp[i][j+1]=max(dp[i][j+1],dp[i][j]+a[i+j].first*abs(a[i+j].second-(n-j-1)));
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+a[i+j].first*abs(a[i+j].second-i));
        }
    ll mx=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            mx=max(mx,dp[i][j]);
    printf("%lld",mx);   
}

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

int main() {
  int r,d;
  long long x;
  cin >> r >> d >> x;
  
  for(int i = 0; i < 9; i++){
    x = r * x - d;
    cout << x << endl;
  }
  
  x = r * x - d;
  cout << x;
  
  return 0;
}

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

int main() {
    int n; cin >> n;
    vector<vector<int>> a(n+1, vector<int>(n+1,0));
    vector<vector<int>> s(n+1, vector<int>(n+1,0));
    for(int i=1; i<n+1; i++){
        for(int j=1; j<n+1; j++){
            cin >> a[i][j];
            s[i][j]=s[i][j-1]+a[i][j];
        }
        for(int j=1; j<n+1; j++){
            s[i][j]+=s[i-1][j];
        }
    }
    
    int ans=s[1][1];
    for(int i=1; i<n+1; i++){
        for(int j=1; j<n+1; j++){
            for(int k=i; k<n+1; k++){
                for(int l=j; l<n+1; l++){
                    ans=max(ans, s[k][l]-s[k][j-1]-s[i-1][l]+s[i-1][j-1]);
                }
            }
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n, a, b, c;
	cin >> n >> a >> b >> c;
	map<char, int> mp;
	mp['A'] = a;
	mp['B'] = b;
	mp['C'] = c;
	string ans = "";
	vector<string> choices(n);
	rep(i, n) {
		cin >> choices[i];
	}
	rep(i, n) {
		char c1 = choices[i][0], c2 = choices[i][1];
		if (mp[c1] == 0 and mp[c2] == 0) {
			cout << "No" << endl;
			return 0;
		} else if (mp[c1] == 1 and mp[c2] == 1 and i + 1 < n) {
			string next_choice = choices[i + 1];
			if (count(all(next_choice), c1)) {
				mp[c1]++;
				mp[c2]--;
				ans += c1;
			} else {
				mp[c1]--;
				mp[c2]++;
				ans += c2;
			}
		} else if (mp[c1] <= mp[c2]) {
			mp[c1]++;
			mp[c2]--;
			ans += c1;
		} else {
			mp[c2]++;
			mp[c1]--;
			ans += c2;
		}
	}
	cout << "Yes" << endl;
	for (char c : ans)
		cout << c << endl;
}

Measured memory_bytes: 6652
#include <iostream>
using namespace std;
int h,w;
char g[102][102];
bool visited[102][102];
int _x[4]={-1,0,0,1},_y[4]={0,-1,1,0};//先行后列
int nxt_x,nxt_y;//先行后列
int ans;
void dfs(int x,int y)
{
	visited[x][y]=true;
	for(int i=0;i<4;i++)
		{
			nxt_x=x+_x[i];
			nxt_y=y+_y[i];
			if(nxt_x>=1&&nxt_x<=h&&nxt_y>=1&&nxt_y<=w&&visited[nxt_x][nxt_y]==false&&g[nxt_x][nxt_y]==g[x][y])
			{
				
				dfs(nxt_x,nxt_y);
			}
		}
}
int main()
{
  cin>>h>>w;
	while(w&&h)
  {
		
	  for(int i=1;i<=h;i++)//行
		  for(int j=1;j<=w;j++)//列
		  {
			 visited[i][j]=false;
			  cin>>g[i][j];
		  }
	  ans=0;//the same character is the same part
	  for(int i=1;i<=h;i++)//行
		  for(int j=1;j<=w;j++)//列
		  {
			  if(!visited[i][j])
			  {
				  ans++;
				  dfs(i,j);
			  }
		  }
	  cout<<ans<<endl;
		cin>>h>>w;
  }
   return 0;
}


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

using namespace std;

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

    int h[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &h[i]);
    }

    sort(h, h+N);

    int dmin = INT_MAX;
    for (int i = 0; i <= N-K; i++) {
        if (h[i+K-1] - h[i] < dmin) {
            dmin = h[i+K-1] - h[i];
        }
    }
    printf("%d\n", dmin);
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[][] count = new int[4 * k + 1][4 * k + 1];

        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            char c = sc.next().charAt(0);
            // convert white into black to regard every wish to be black
            if (c == 'W') y += k;

            // want (x, y) to be black
            x %= 2 * k;
            y %= 2 * k;

            count[x][y]++;
            count[x][y + k]--;
            count[x + k][y]--;
            count[x + k][y + k] += 2;
            count[x + 2 * k][y + k]--;
            count[x + k][y + 2 * k]--;
            count[x + 2 * k][y + 2 * k]++;
        }

        for (int row = 0; row < count.length; row++) {
            for (int col = 1; col < count[0].length; col++) {
                count[col][row] += count[col - 1][row];
            }
        }
        for (int col = 0; col < count[0].length; col++) {
            for(int row = 1; row < count.length; row++) {
                count[col][row] += count[col][row - 1];
            }
        }

        for (int i = 0; i < count.length; i++) {
            for (int j = 0; j < count[0].length; j++) {
                if ( j < 2 * k && i < 2 * k) continue;
                count[i % (2 * k)][j % (2 * k)] += count[i][j];
            }
        }

        int ans = 0;
        for (int row = 0; row < count.length; row++) {
            for (int col = 0; col < count[0].length; col++) {
                //System.out.printf("%d ", count[col][row]);
                ans = Math.max(ans, count[col][row]);
            }
            //System.out.println();
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 162116
n,l = map(int,input().split(" "))
ans = 0

#すべて正の数の場合：最小の値を除けば良い
if l > 0:
    for i in range(n-1):
        ans += l + i + 1
#すべて負の数の場合：最大の値を除けば良い
elif l + n <= 0:
    for i in range(n-1):
        ans += l + i
#０を含む場合：０を除けば良い
else:
    for i in range(n):
        ans += l + i
        
print(ans)


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  int ans = 0;
  for(int i=0;i<B/A;i++){
    if(ans < C){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

double calc(int m, int d, int hh, int mm) {
    vector<int> days(13, 31);
    days[0] = 0;
    days[2] = 29;
    for(int i : {4, 6, 9, 11}) {
        days[i] = 30;
    }
    for(int i = 2; i <= 12; i++) {
        days[i] += days[i - 1];
    }
    d += days[m - 1];
    return (d - 1) + hh / 24.0 + mm / (24.0 * 60.0);
}

void rotate(double th, double &a, double &b) {
    double na =  cos(th) * a + -sin(th) * b;
    double nb =  sin(th) * a + cos(th) * b;
    a = na;
    b = nb;
}

double to_radian(double degree) {
    return degree / 180.0 * M_PI;
}
void make(double a, double b, double& x, double& y, double& z) {
    x = cos(a);
    y = sin(a);
    z = tan(b);
}

const double EPS = 1e-8;

int main(){
    int T;
    cin >> T;
    for(int casenum = 0; casenum < T; casenum++){
        int mon, day, hh, mm;
        scanf("%d/%d", &mon, &day);
        scanf("%d:%d", &hh, &mm);
        double theta = to_radian( (1.0 + 1.0 / 365.24) * 360.0 * calc(mon, day, hh, mm) );
        const double P = to_radian( 43.2 );
        int n;
        cin >> n;
        for(int i = 0; i < n; i++) {
            string name;
            int m;
            cin >> name >> m;
            bool ok = true;
            // cout << name << endl;
            for(int j = 0; j < m; j++) {
                double a, b;
                cin >> a >> b;
                double x, y, z;
                make(to_radian(a), to_radian(b), x, y, z);
                // printf("(%f, %f, %f)\n", x, y, z);
                rotate(-P, x, z);
                // printf("->(%f, %f, %f)\n", x, y, z);
                rotate(theta, y, z);
                // printf("->(%f, %f, %f)\n", x, y, z);
                rotate(P, x, z);
                // printf("->(%f, %f, %f)\n", x, y, z);
                if(z < 0.0 + EPS) {
                    ok = false;
                }
            }
            if(ok) {
                cout << name << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    string s;cin >> s;
    bool f=false,g=false,h=false;
    for(int i=0;i<n;i++){
        int t=n-1|i;
        int p=s[i]-'0';
        if(p==2){
            g=true;
        }
        if(t==n-1){
            f=(f^(p%2));
            h=(h^(p==3));
        }
    }
    if(f){
        cout << 1 << endl;
        return 0;
    }
    if(g){
        cout << 0 << endl;
        return 0;
    }
    if(h){
        cout << 2 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 1948
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

struct node{
	int s,e,m;
	int val=1e9;
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	
	void update(int i,int j,int k){
		if (s==i && e==j) val=min(val,k);
		else if (j<=m) l->update(i,j,k);
		else if (m<i) r->update(i,j,k);
		else l->update(i,m,k),r->update(m+1,j,k);
	}
	
	int query(int i){
		if (s==e) return val;
		else if (i<=m) return min(l->query(i),val);
		else return min(r->query(i),val);
	}
} *hor=new node(0,200005),*ver=new node(0,200005);

int n,q;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>q;
	
	ll ans=(ll)(n-2)*(n-2);
	
	hor->update(1,n,n);
	ver->update(1,n,n);
	
	int a,b;
	while (q--){
		cin>>a>>b;
		
		if (a==1){
			int temp=hor->query(b);
			ans-=temp-2;
			ver->update(1,temp,b);
		}
		else{
			int temp=ver->query(b);
			ans-=temp-2;
			hor->update(1,temp,b);
		}
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 41128
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

	int m,n;
	cin >> m >> n;
	if(n%2==0)
	{
		if(n<=m*4&&n>=m*2) cout<<"Yes";
		else cout<<"No";
	}
	else
	{
		cout<<"No";
	}
	
	return 0;
}

Measured memory_bytes: 3648