akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>
#include <utility>
#define INF 5000
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> maze;
  for(int i=0; i<h; i++){
    string str;
    cin >> str;
    maze.push_back(str);
  }
  vector<vector<int>> d(h, vector<int>(w, INF));
  d[0][0] = 1;
  int blackCount = 0;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(maze[i][j] == '#') blackCount++;
    }
  }
  queue<pair<int, int>> que;
  que.push(make_pair(0, 0));
  while(!que.empty()){
    int y = que.front().first;
    int x = que.front().second;
    que.pop();
    for(int dx=-1, dy=0, i=0; i<4; dx+=dy, dy=dx-dy, dx=dy-dx, ++i){
      if(x+dx<0 || x+dx>=w || y+dy<0 || y+dy>=h || maze[y+dy][x+dx] == '#' || d[y+dy][x+dx] != INF){
       	continue; 
      }else if(y+dy == h-1 && x+dx == w-1){
        cout << h * w - (blackCount + d[y][x] + 1) << endl;
        return 0;
      }else{
        que.push(make_pair(y+dy, x+dx));
        d[y+dy][x+dx] = d[y][x] + 1;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

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

using namespace std;

int main()
{
  
  long n;cin>>n; long arr[n+1]={0};unsigned long long sum=0;
 for(long i=1;i<=n;i++)
 {
   if(i%3==0 && i%5==0) arr[i]=0;
   else if(i%3==0) arr[i]=0;
   else if(i%5==0) arr[i]=0;
   else {
   arr[i]=i; sum+=i;
   }
 }
  cout<<sum<<"\n";
return 0;
}

Measured memory_bytes: 11432
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define endl "\n"

void solve(){
	int n; cin>>n;
	int a[n];
	f(i,n) cin>>a[i];
	int b[n];
	b[0]=0;
	b[1]=abs(a[1]-a[0]);
	ff(i,2,n-1) b[i] = min(b[i-1]+abs(a[i]-a[i-1]), b[i-2]+abs(a[i]-a[i-2]));
	//f(i,n) cout<<b[i]<<" "; cout<<endl;
	cout<<b[n-1]<<endl;
}

int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int maxn = 110;
int n, w, weight[maxn], value[maxn];
ll dp[100010];
int main()
{
    read(n), read(w);
    rep(i, 1, n) read(weight[i]), read(value[i]);
    memset(dp, 0x3f3f, sizeof(dp));
    dp[0] = 0;
    rep(i, 1, n)
        for(int j = 100000; j >= value[i]; j --)
            dp[j] = min(dp[j], dp[j - value[i]] + weight[i]);
    for(int i = 100000; i >= 0; i --) if(dp[i] <= w) {
        printf("%d\n", i);
        break;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (long long i = l; i < r; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
bool prime(int a) {
	if (a == 1) return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0) return false;
	}
	return true;
}
signed main() {
	int n,k;
	string s;
	cin>>n>>k>>s;
	rep(i,n){
		if(i!=k-1)cout<<s[i];
		else cout<<(char)((int)s[i]+32);
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

main(){
  double x1,y1,x2,y2,xq,yq;
  double mx,my,temp;
  double xa,ya,xb,yb,tx,ty,ansx,ansy;
  while(1){
    if(scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1,&y1,&x2,&y2,&xq,&yq)==EOF) break;

    xa=xq-x1;
    ya=yq-y1;
    xb=x2-x1;
    yb=y2-y1;
    temp=xa*xb+ya*yb;
    mx = x1 + xb * temp /(xb*xb+yb*yb);
    my = y1 + yb * temp /(xb*xb+yb*yb);
    
    tx=mx-xq;
    ty=my-yq;

    ansx=mx+tx;
    ansy=my+ty;

    printf("%f %f\n", ansx, ansy);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<sstream>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define strep(it,v) for(it=v.begin();it!=v.end();++it)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define s second
#define ll long long int
#define vi vector<int>
#define rs resize
int main()
{  ios::sync_with_stdio(false);
   string a,b,c;
   cin>>a>>b>>c;
   if(a[a.length()-1]==b[0] && b[b.length()-1]==c[0])
    cout<<"YES";
   else
    cout<<"NO";
   return 0;
}


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

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

    int m = 0;
    vector<int> b(n, 0);
    for(int i = n; i > 0; i--){
        int sum = a[i-1];
        for(int j = 2 * i; j <= n; j += i){
            if(b[j-1])sum++;
        }
        if(sum % 2 == 1){
            b[i-1]++;
            m++;
        }
    }
    cout << m << endl;
    if(m != 0){
        rep(i, n)if(b[i])cout << i + 1 << ' ';
        cout << endl;
    }
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

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

   ll a[n][3];

   for(ll i=0;i<n;i++)
   	cin>>a[i][0]>>a[i][1]>>a[i][2];

   ll dp[n][3];
  for(ll i=0;i<n;i++)
  	for(ll j=0;j<3;j++)
  		dp[i][j]=a[i][j];

   for(ll i=1;i<n;i++)
   {
   		for(ll j=0;j<3;j++)
   		{ ll x=0;
   			for(ll k=0;k<3;k++)
   			{
   				if(k!=j)
   					x=max(x,dp[i-1][k]);
   			}
   			dp[i][j]+=x;
   		}
   }

   cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;

}


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

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

    int n;
    cin >> n;
    int s = 1000;
    while (s < n) {
    	s += 1000;
    }

    cout << (s - n) << "\n";
    return 0;
}


Measured memory_bytes: 3648
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int n;
  cin >> n;
  ll a[100010];
  rep(i, n) cin >> a[i];
  ll b[100010];
  b[0] = 0;
  rep(i, n)
  {
    b[0] += a[i] * (i % 2 == 0 ? 1 : -1);
  }
  for (int i = 1; i < n; ++i)
  {
    b[i] = 2 * a[i - 1] - b[i - 1];
  }
  rep(i, n) cout << b[i] << (i == n - 1 ? "\n" : " ");
  return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	string s;
	cin >> s;
	if(s == "ani") cout << "square1001" << endl;
	else cout << "e869120" << endl;
	return 0;	
}



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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

int n;
int a[14];
int c[24];

void end(int x) {
	cout << x << endl;
	exit(0);
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i ++) {
		int x; cin >> x;
		a[x]++;
	}
	if (a[0]) end(0);
	for (int i = 1; i <= 11; i ++)
		if (a[i] >= 3) end(0);
	if (a[12] >= 2) end(0);
	int S = 0;
	for (int p = 0; p < (1<<11); p ++) {
		memset(c, 0, sizeof c);
		for (int i = 1; i <= 11; i ++) {
			if (a[i] == 2) c[i] = c[24-i] = 1;
			if (a[i] == 1) {
				if ((p>>(i-1))&1) c[i] = 1;
				else c[24-i] = 1;
			}
		}
		if (a[12]) c[12] = 1;
		c[0] = 1;
		int T = 12;
		for (int i = 0; i < 24; i ++)
			for (int j = i+1; j < 24; j ++)
				if (c[i] && c[j])
					T = min(T, min(j-i, 24-(j-i)));
		S = max(S, T);
	}
	cout << S << endl;
	return 0;
}

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

typedef long long ll;
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define endl '\n'
const int N = 1e5 + 5;
using namespace std;

int main() {
    IO;
    char c; cin>>c;
    if(isupper(c)){
        cout<<'A';
    }
    else cout<<'a';


}

Measured memory_bytes: 3604
def main():
    n,m=map(int,input().split())
    hh=list(map(int,input().split()))
    path={}
    for _ in range(m):
        a,b=map(int,input().split())
        if a not in path:
            path[a]={b}
        else:
            path[a].add(b)
        if b not in path:
            path[b]={a}
        else:
            path[b].add(a)
    c = 0
    for i,h in enumerate(hh,1):
        if all(h>hh[x-1] for x in path.get(i, set())):
            c += 1
    print(c)
main()

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI b(n + 1);
    FOR(i, 1, n - 1) cin >> b[i];
    b[0] = (int)1e9;
    b[n] = (int)1e9;

    int ans = 0;
    REP(i, n) ans += min(b[i], b[i + 1]);
    cout << ans << ln;
    return 0;
}


Measured memory_bytes: 3568
#include <stdio.h>
#include <ctype.h>
int main() {
 char ch[1200];
 int i,n;
 n=0;
 char a[1200];
 while(1) {
   scanf("%c",&a[n]);
   if(a[n] == '\n') {
     break;
   }
   ch[n] = a[n];
   if('A' <= a[n] && a[n] <= 'Z') {
     ch[n] = a[n] + 32;
   } else if(a[n] >= 'a' && a[n] <= 'z') {
     ch[n] = a[n] - 32;
   }
   
   
   n = n +1;
   
 }
 
 for(i=0; i<n ; i++) {
   printf("%c" ,ch[i]);
 }
 printf("\n"); 
 return 0;
 
}


Measured memory_bytes: 2040
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

Int cnt[300];

int main(){
    cin.tie(0);
    Int N; cin >> N;
    string s; cin >> s;

    for (int i = 0; i < N; i++){
        cnt[s[i]-'a']++;
    }
    Int ans = 1;
    for (int i = 0; i <= 'z' - 'a'; i++){
        ans = (ans * (cnt[i]+1)) % MOD; 
    }

    cout << (ans-1) << endl;




    return 0;
}



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

using namespace std;
using i32 = std::int_fast32_t;
using u64 = std::uint_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  u64 N = static_cast<u64>(S.size());
  vector<u64> cnt(26, 0);
  for (i32 i = 0; i < static_cast<i32>(N); i++) {
    cnt[S[i] - 'a']++;
  }
  u64 res = N * (N - 1) / 2;
  for (i32 i = 0; i < 26; i++) {
    res -= cnt[i] * (cnt[i] - 1) / 2;
  }
  cout << res + 1 << '\n';
  return 0;
}


Measured memory_bytes: 720
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

long long gcd(long long a, long long b){
    if (a < b) swap(a, b);
    return b ? gcd(b, a % b) : a;
}

const int MAX = 15000000;
long long MinFact[MAX];

void preprocess(long long N = MAX) {
    vector<long long> is_prime(N+1, true);
    fill(MinFact, MinFact+N, -1);
    is_prime[0] = is_prime[1] = false;
    MinFact[0] = 0; MinFact[1] = 1;
    for (long long i = 2; i <= N; i++) {
        if (is_prime[i]) {
            MinFact[i] = i;
            for (long long j = 2 * i; j <= N; j+=i) {
                is_prime[j] = false;
                if (MinFact[j] == -1) MinFact[j] = i;
            }
        }
    }
}

vector<pair<long long, long long>> osa_k(long long N) {
    vector<pair<long long, long long>> res;
    while (N != 1) {
        long long prime = MinFact[N];
        int ex = 0;
        while (MinFact[N] == prime) {
            ex++;
            N /= prime;
        }
        res.push_back(make_pair(prime, ex));
    }
    return res;
}

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<int> A(N);
    int g = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        g = gcd(g, A[i]);
    }
    if (g != 1) {
        cout << "not coprime" << '\n';
        return;
    }

    preprocess(1000000);
    vector<bool> primes(1000001); 
    for (int i = 0; i < N; i++) {
        auto pf = osa_k(A[i]);
        for (auto p : pf) {
            long long prime = p.first;
            if (primes[prime]) {
                cout << "setwise coprime" << '\n';
                return;
            }
            primes[prime] = true;
        }
    }

    cout << "pairwise coprime" << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 22620
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;
/////////
#pragma region Math
#pragma region
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
#pragma endregion // 最大公約数 gcd
#pragma region
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
#pragma endregion // 最小公倍数 lcm

void solve(){
	int N;
	cin >> N;
	vector<LL> T(N);
	for(int i=0;i<N;++i){
		cin >> T[i];
	}
	LL ans = 1;
	for(int i=0;i<N;++i){
		ans = ans/gcd(ans,T[i]) * T[i];
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

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

int main(){
 int n;cin>>n;
 int dp[n+1][3];
 for(int i=0;i<n;i++){
     for(int j=0;j<3;j++)cin>>dp[i][j];
 }
 int ans=max(dp[0][0],max(dp[0][1],dp[0][2]));
 for(int i=1;i<n;i++){
     for(int j=0;j<3;j++){
         if(j==0){
             dp[i][j]+=max(dp[i-1][j+1],dp[i-1][j+2]);
         }
         else if(j==2)dp[i][j]+=max(dp[i-1][j-1],dp[i-1][j-2]);
         else dp[i][j]+=max(dp[i-1][j+1],dp[i-1][j-1]);
     }
     if(i==n-1){
         for(int j=0;j<3;j++){
             ans=max(ans,dp[i][j]);
         }
     }
 }
 cout<<ans;
 return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		HashSet<String> list = new HashSet<String>();
		try {
		int n = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < n; i++) {
			String[] key = br.readLine().split(" ");
			
			if(key[0].equals("insert")) {
				list.add(key[1]);
				
			} else if (key[0].equals("find")){
				if(list.contains(key[1]) == true) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
				
			}
		}
		}catch(Exception e) {
			System.out.println("error");
		}
	}

}


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

signed main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int sum = 0;
  
  for (int i = 0; i <= a; i++){
    for (int j = 0; j <= b; j++){
      for (int k = 0; k <= c; k++){
        if((500 * i + 100 * j + 50 * k) == x){
          sum++;
        }
      }
    }
  }
  cout << sum << endl;
}

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

signed main(){
  int k,q,n,x,m;
  cin>>k>>q;
  vector<int> d(k);
  for(auto& i:d)cin>>i;
  while(q--){
    cin>>n>>x>>m;
    x%=m;
    --n;
    vector<int> e(k);
    int u=0,res,t,ps=0,s,pz=0,z;
    for(int i=0;i<k;++i)ps+=e[i]=d[i]%m,u+=(m-e[i])%m,pz+=!e[i];
    res=n/(k*m)*u;
    t=n%(k*m);
    s=ps*(t/k)+x;
    z=pz*(t/k);
    for(int i=0;i<t%k;++i)s+=e[i],z+=!e[i];
    res+=t-(s/m-x/m+z);
    cout<<res<<endl;
  }
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int MOD = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y, int md = MOD){x += y; if(x >= md) x -= md;}
void sub_self(int &x, int y, int md = MOD){x -= y; if(x < 0) x += md;}
void mul_self(int &x, int y, int md = MOD){x = x * 1LL * y % md;}
inline int mul(int x, int y, int md = MOD){return x * 1LL * y % md;}
inline int add(int x, int y, int md = MOD){x += y; if(x >= md) x -= md; return x;}
inline int sub(int x, int y, int md = MOD){x -= y; if(x < 0) x += md; return x;}

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

vector<int> read(int n, int k){
	vector<int> vec(n);
	for(int i = 0; i < k; ++i) cin >> vec[i];
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for(int i = k; i < n; ++i)
		vec[i] = (a * 1ll * vec[i - 2] + b * 1ll * vec[i - 1] + c) % d;
	return vec;
}


void solve(){

	int n;
	cin >> n;
	vector<array<int, 2>> vec(n);
	int res = 0;
	int mn1 = 2e9;
	int mx1 = 0;
	int mn2 = 1e9;
	int mx2 = -1e9;
	for(auto &[x, y] : vec){
		cin >> x >> y;
		mn1 = min(mn1, x + y);
		mx1 = max(mx1, x + y);
		mn2 = min(mn2, x - y);
		mx2 = max(mx2, x - y);
	}
	res = max(mx1 - mn1, mx2 - mn2);
	cout << res << '\n';
	return;
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	// freopen("input.in", "r", stdin);
	// freopen("output.out", "w", stdout);

	int t;
	t = 1;
	// cin >> t;
	// pre();
	for(int i = 1; i <= t; ++i){
		// cout << "Case #" << i << ": ";
		solve();
		// cout << '\n';
		// cout << endl;
	}

	return 0;
}


Measured memory_bytes: 4756
package main

import "fmt"

var divide = []string{"dream", "dreamer", "erase", "eraser"}

func main() {
	var S string
	fmt.Scan(&S)

	dp := make([]bool, 100010)
	dp[0] = true

	for i := 0; i < len(S); i++ {
		if !dp[i] {
			continue
		}

		for _, s := range divide {
			if len(S) < i+len(s) {
				continue
			}
			if S[i:i+len(s)] == s {
				dp[i+len(s)] = true
			}
		}
	}
	if dp[len(S)] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

signed main()
{
    int n, h[100000], dp[100000];

    cin >> n;

    for(int i=0 ;i<n ;i++ ){
        cin >> h[i];
    }

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i=2 ;i<n ;i++ ){
        dp[i] = min( abs(h[i] - h[i-2]) + dp[i-2], abs(h[i] - h[i-1]) + dp[i-1]);
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4376
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.*;
 
public class Main {
	String X;
	int s,ans;
	public void solve() {
		X = next();
		s = 0;
		ans = 0;
		for(int i = 0;i < X.length();i++){
			
			if(X.charAt(i) == 'S'){
				s++;
			}else{
				if(s > 0){
					s--;
					ans++;
				}
			}
		}
		
		out.println(X.length() - ans * 2);
	}
 
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}
 
	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;
 
	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}
 
	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}
 
	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}
 
	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}
 
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}
 
	public int nextInt() {
		return Integer.parseInt(next());
	}
 
	public long nextLong() {
		return Long.parseLong(next());
	}
 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

int main(){
	int a , b , c ;
	cin >> a >> b >> c ;
	
	if( a <= b && b <= c ){		
		cout << a << " " << b << " " << c << endl ;
		
	} else if( a <= c && c <= b ){		
		cout << a << " " << c << " " << b << endl;	
		
	} else if( c <= b && b <= a ){	
		cout << c << " " << b << " " << a << endl ;
		
	} else if( c <= a && a <= b ){
		cout << c << " " << a << " " << b << endl ;
		
	} else if( b <= a && a <= c ){
		cout << b << " " << a << " " << c << endl ;
		
	} else if( b <= c && c <= a ){
		cout << b << " " << c << " " << a << endl ;
		
	}
	
	return 0 ;
} 

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	cout << s.substr(0, 4) << ' ' << s.substr(4, 8) << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np

def yakusu(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

# A = input()
A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()

c = 0
for n in range(1, A+1):
    if n % 2 == 1 and len(yakusu(n)) == 8:
        c += 1

print(c)

Measured memory_bytes: 12496
//48
#include<iostream>
#include<vector>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    vector<int> v(n);
    for(int i=0;i<n;i++){
      cin>>v[i];
    }
    int ans;
    for(ans=0;;ans++){
      vector<int> temp(n);
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  temp[i]+=v[i]==v[j];
	}
      }
      if(v==temp)break;
      v=temp;
    }
    cout<<ans<<endl;
    for(int i=0;i<n;i++){
      cout<<v[i]<<((i+1==n)?'\n':' ');
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long int64;

// x <= upper
void printx(int n, int upper, list<int> &xs)
{
	if(n == 0) {
		
		for(list<int>::iterator it = xs.begin(); it != xs.end(); ++it)
			printf("%d%s", *it, (--xs.end() != it) ? " " : "\n");
	}		
	
	for(int x = min(upper, n); x > 0; --x) {
		
		xs.push_back(x);
		printx(n - x, x, xs);
		xs.pop_back();
	}
	
	return;
}

void printx(int n)
{
	list<int> xs;
	
	printx(n, n, xs);
}

int main()
{
	while(true) {
		
		int n;
		
		scanf("%d", &n);
		if(n == 0)
			break;
		
		printx(n);
	}
	
	return 0;
}

/* はやく人間になりたい */
/* 人権を得たい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */

Measured memory_bytes: 1188
# -*- coding: utf-8 -*-

from collections import Counter

def main(N,A):
    elements = sorted(set(A))
    A = Counter(A)
    count = 0
    for i in elements:
        if(A[i]%2==1):
            count += 1
    print(count)
    
if __name__ == '__main__':
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))
    main(N,A)

Measured memory_bytes: 20340
#include<bits/stdc++.h>
using namespace std;
int dist[220][220];
int n,m,r;
int a,b,c;
int ci[220];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m>>r;
	for(int i=1;i<=r;i++)
		cin>>ci[i];
	memset(dist,63,sizeof(dist));
	for(int i=1;i<=m;i++){
		cin>>a>>b>>c;
		dist[a][b]=dist[b][a]=c;
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	sort(ci+1,ci+r+1);
	int res=2e9;
	do{
		int cand=0;
		for(int i=1;i<r;i++)
			cand+=dist[ci[i]][ci[i+1]];
		res=min(res,cand);
	}while(next_permutation(ci+1,ci+r+1));
	cout<<res<<endl;
	return 0;
}



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

int main(){
  int x;
  cin >> x;
  
  if(x <= 599){
    cout << 8 << endl;
  }else if(x <= 799){
    cout << 7 << endl;
  }else if(x <= 999){
    cout << 6 << endl;
  }else if(x <= 1199){
    cout << 5 << endl;
  }else if(x <= 1399){
    cout << 4 << endl;
  }else if(x <= 1599){
    cout << 3 << endl;
  }else if(x <= 1799){
    cout << 2 << endl;
  }else if(x <= 1999){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3588
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  string S; cin>>S;
  
  vector<ll> cumw(N+1,0);
  vector<ll> cumb(N+1,0);
  rep(i,N) S[i]=='.'?cumw[i+1]++:cumb[i+1]++;
  rep(i,N) {cumw[i+1]+=cumw[i]; cumb[i+1]+=cumb[i];}
  
  ll ans=INF;
  rep(i,N+1) chmin(ans,cumb[i]-cumb[0]+cumw[N]-cumw[i]);
  
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 6752
package main

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

type node struct {
	key   int
	left  *node
	right *node
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextOperation() int {
	sc.Scan()
	if sc.Text() == "insert" {
		return 1
	} else {
		return 0
	}
}
func Print(nodes []int) {
	writer := bufio.NewWriter(os.Stdout)
	for _, v := range nodes {
		writer.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	writer.Write([]byte("\n"))
	writer.Flush()
}
func Insert(root *node, value int) *node {

	if root == nil {
		return &node{value, nil, nil}
	}

	var parent *node
	anode := root
	for anode != nil {
		parent = anode
		if anode.key > value {
			anode = anode.left
		} else {
			anode = anode.right
		}
	}

	if parent.key > value {
		parent.left = &node{value, nil, nil}
	} else {
		parent.right = &node{value, nil, nil}
	}
	return root
}
func Inorder(root *node, store []int) []int {
	if root != nil {
		store = Inorder(root.left, store)
		store = append(store, root.key)
		store = Inorder(root.right, store)
	}
	return store
}
func Preorder(root *node, store []int) []int {
	if root != nil {
		store = append(store, root.key)
		store = Preorder(root.left, store)
		store = Preorder(root.right, store)
	}
	return store
}
func main() {
	sc.Split(bufio.ScanWords)
	var root *node
	n := nextInt()
	for i := 0; i < n; i++ {
		if nextOperation() == 1 {
			key := nextInt()
			root = Insert(root, key)
		} else {
			Print(Inorder(root, []int{}))
			Print(Preorder(root, []int{}))
		}
	}
}



Measured memory_bytes: 49376
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

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

  int ans = 1, now = A[0];
  for (int i = 1; i < N; i++){
    if (now > A[i]){
      ans++; now = A[i];
    }
  }
  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    ll N; cin >> N;
    string ans, moji = "abcdefghijklmnopqrstuvwxyz";
    while(N) {
        N--;
        ans += moji[N % 26];
        N /= 26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(void) {
  string s;
  cin >>s;
  if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        double best=1000000,num;
        for(int i=0;i<n;i++){
            int x;
            double y,z;
            cin>>x>>y>>z;
            y/=100;
            if(fabs(z/(y*y)-22)<best)best = fabs(z/(y*y)-22),num = x;
        }
        cout<<num<<endl;
    }
}

Measured memory_bytes: 1284
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long k = sc.nextLong();
    long[] w = new long[n];
    long[] d = new long[n];
    for(int i = 0; i < n; i++) {
      w[i] = sc.nextLong();
      d[i] = sc.nextLong();
    }
    long ans = 0;
    long left = 0;
    long right = 2 * (long)Math.pow(10, 18);
    while(left < right) {
      long med = (left + right) / 2;
      long t = 0;
      for(int i = 0; i < n; i++) {
        if(w[i] <= med) {
          t += ((med - w[i]) / d[i] + 1);
        }
      }
      if(t >= k) {
        ans = med;
        right = med;
      } else {
        left = med + 1;
      }
    }
    System.out.println(ans);
  }
}

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

int main() {
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) {
    cin >> a[i];
  }
  
  sort(a.begin(), a.end());
  cout << (a[1] - a[0] + a[2] - a[1]) << endl;
}


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

int main() {
  int A,B,C,D;
  cin >>A >>B >>C >>D;
  if(A>B){
    if(C>D){
      cout <<B+D <<endl;
    }
    else{
      cout <<B+C <<endl;
    }
  }
  else{
    if(C>D){
      cout <<A+D <<endl;
    }
    else{
      cout <<A+C <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 gcd(i64 x, i64 y) {
  return x % y == 0 ? y : gcd(y, x % y);
}

i64 lcm(i64 x, i64 y) {
  return x * y / gcd(x, y);
}

i64 a, b, c, d;
i64 f(i64 x, i64 c, i64 d) {
//  cerr << x/c << '\t' << x/d << '\t' << x / (c * d) <<endl;
  return x / c + x / d - x / lcm(c, d);
}

int main() {
  cin >> a >> b >> c >> d;
  cout << b - a + 1 - (f(b, c, d) - f(a - 1, c, d)) << '\n';
  return 0;
}



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

int main(){
  long long N;
  cin >> N;
  long long sum = 0;
  for(int i = 1; i <= N; i++){
    if(i % 3 == 0 || i % 5 == 0) continue;
    else sum += i;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    int ct=0;
    for(int i=0;i<=x;i++){
           if(y==2*(x+i)){
                ct++;
                cout<<"Yes"<<endl;

           }
    }
    if(ct==0) cout<<"No"<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); ++i)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define INF ((1 << 30) - 1)

int main(){
    istream_iterator<int> itr(cin);
    int n = *itr, m = *(++itr);
    vector<int> a(m), b(m), c(m);
    //for(int i = 0; i < m; i++){
    rep(i, m){
        a[i] = *(++itr) - 1;
        b[i] = *(++itr) - 1;
        c[i] = *(++itr);
    }

    vector< vector<int> > p(n);
    //generate(p.begin(), p.end(), [n](){ return vector<int>(n, INF); });
    rep(i, n){
        p[i] = vector<int>(n, INF);
    }
    //for(int i = 0; i < n; i++)
    rep(i, n){
        p[i][i] = 0;
    }
    //for(int i = 0; i < m; i++){
    rep(i, m){
        p[a[i]][b[i]] = c[i];
        p[b[i]][a[i]] = c[i];
    }
    rep(k, n)
        rep(i, n)
            rep(j, n)
                p[i][j] = min(p[i][j], p[i][k] + p[k][j]);

    int sum = 0;
    rep(i, m){
        bool used = false;
        rep(j, n){
            if(p[j][a[i]] + c[i] == p[j][b[i]] || p[j][b[i]] + c[i] == p[j][a[i]]){
                used = true;
                break;
            }
        }
        if(!used){
            sum++;
            //cout << i << endl;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
package main
     
    import (
    	"bufio"
    	"fmt"
    	"math"
    	"os"
    	"strconv"
    )
     
    var sc = bufio.NewScanner(os.Stdin)
     
	const INF = int(1e9)
     
    func init() {
    	sc.Buffer([]byte{}, math.MaxInt64)
    	sc.Split(bufio.ScanWords)
    }
     
    func nextInt() int {
    	sc.Scan()
    	i, err := strconv.Atoi(sc.Text())
    	if err != nil {
    		panic(err)
    	}
    	return i
    }
    func nextStr() string {
    	sc.Scan()
    	if err := sc.Err(); err != nil {
    		panic(err)
    	}
    	return sc.Text()
    }
     
    func abs(a int) int {
    	return int(math.Abs(float64(a)))
    }
     
    func uniqIntSlice(a []int) []int {
    	m := make(map[int]struct{})
    	for _, v := range a {
    		m[v] = struct{}{}
    	}
    	u := []int{}
    	for k := range m {
    		u = append(u, k)
    	}
    	return u
    }
    func min(nums ...int) int {
    	if len(nums) == 0 {
    		panic("funciton min() requires at least one argument.")
    	}
    	res := nums[0]
    	for i := 0; i < len(nums); i++ {
    		res = int(math.Min(float64(res), float64(nums[i])))
    	}
    	return res
    }
     
    func max(nums ...int) int {
    	if len(nums) == 0 {
    		panic("funciton max() requires at least one argument.")
    	}
    	res := nums[0]
    	for i := 0; i < len(nums); i++ {
    		res = int(math.Max(float64(res), float64(nums[i])))
    	}
    	return res
    }
     
    //a:old b:new a>b -> a=b (update) more small
    func chmin(a *int, b int) bool {
    	if *a > b {
    		*a = b
    		return true
    	}
    	return false
    }
     
    //a:old b:new a<b -> a=b (update) more large
    func chmax(a *int, b int) bool {
    	if *a < b {
    		*a = b
    		return true
    	}
    	return false
    }
     
    func rec(dp, h []int, i int) int {
    	if dp[i] < INF {
    		return dp[i]
    	}
    	if i == 0 {
    		return 0
    	}
    	res := INF
    	chmin(&res, rec(dp, h, i-1)+abs(h[i]-h[i-1]))
    	if i > 1 {
    		chmin(&res, rec(dp, h, i-2)+abs(h[i]-h[i-2]))
    	}
    	dp[i] = res
    	return dp[i]
    }
     
    func main() {
    	n := nextInt()
    	k := nextInt()
     
    	h := make([]int, n)
    	for i := 0; i < n; i++ {
    		h[i] = nextInt()
    	}
    	dp := make([]int, n)
    	for i := range dp {
    		dp[i] = INF
    	}
    	dp[0] = 0
     
    	for i := 1; i < n; i++ {
    		for j := 1; i-j >= 0 && j<=k ; j++ {
    			chmin(&dp[i], dp[i-j]+abs(h[i]-h[i-j]))
    		}
    	}
    	fmt.Println(dp[n-1])
    }

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    ll n;cin>>n;
    ll s=n%60;n/=60;
    ll m=n%60;n/=60;
    cout<<n<<":"<<m<<":"<<s<<endl;
}

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



Measured memory_bytes: 3204
#include<stdio.h>
#define MAXN 100015

int a[MAXN],sum[MAXN],stk[MAXN];

int _find(int l,int r,int k){

    int mid,i=l-1;
    while(l<=r){
        mid=l+r>>1;
        if(sum[mid]-sum[i]<=k)l=mid+1;
        else r=mid-1;
    }
    return r;
}

int main(){

    int i,n,k,j,ans=0,top=0;
    scanf("%d%d",&n,&k);
    a[0]=-1;
    for(i=1;i<=n;i++){
        scanf("%1d",&a[i]);
        sum[i]=sum[i-1];
        if(a[i]!=a[i-1]){
            stk[++top]=i;
            if(!a[i])sum[i]++;
        }
    }
    for(i=1;i<=top;i++){
        j=_find(stk[i],n,k);
        ans=j-stk[i]+1>ans?j-stk[i]+1:ans;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define fi        first
#define se        second
#define pb        push_back
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
inline void solve()
{
	int a,b,c,k;cin>>a>>b>>c>>k;
	if(a>=k) cout<<k;
	else if(a+b>=k) cout<<a;
	else cout<<a-(k-a-b);

}
int main()
{
	IOS();
	solve();
	return 0;
}




Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int c = Integer.parseInt(str[2]);
    if(a==b)
      System.out.println(c);
    else if(b==c)
      System.out.println(a);
    else
      System.out.println(b);
  }
}

Measured memory_bytes: 32604
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = map(int, input().split())
c = [1]*n
r = set([0])
for i in range(m):
    x,y = map(int, input().split())
    x -= 1
    y -= 1
    if c[x]==1 and x in r:
        r.remove(x)
        r.add(y)
    elif c[x]>=2 and x in r:
        r.add(y)
    c[x] -= 1
    c[y] += 1
print(len(r))

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    const ll n = s.size();
    string ans = "";
    ll p = 1; rep(i, n) p *= 10;
    auto f = [&](const string& ns) {
        ll d = abs(stoll(s) - stoll(ns));
        return min(d, p-d);
    };
    vector<bool> used(10, false);
    vector<ll> v(n);
    function<void(ll)> dfs = [&](ll pos) {
        if (pos == n) {
            string a = "";
            rep(i, n) a += char('0'+v[i]);
            if (ans == "" || f(a) > f(ans)) ans = a;
            else if (f(a) == f(ans)) chmin(ans, a);
        }
        else {
            rep(i, 10) {
                if (used[i]) continue;
                used[i] = true;
                v[pos] = i;
                dfs(pos+1);
                used[i] = false;
            }
        }
    };
    dfs(0);
    cout << ans << endl;
}

Measured memory_bytes: 3196
#include<cstdio>
#define maxn 105
int n,a[maxn],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int cnt=0;
	for(int i=1;i<=n+1;i++)
		if(a[i]!=a[i-1])
		{
			ans+=cnt/2;
			cnt=1;
		}
		else cnt++;
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int b1, b2, b3;
    cin >> b1 >> b2 >> b3;
    if (b1 == 1 && b2 == 0 && b3 == 0)
        cout << "Close" << endl;
    else if (b1 == 0 && b2 == 1 && b3 == 0)
        cout << "Close" << endl;
    else if (b1 == 1 && b2 == 1 && b3 == 0)
        cout << "Open" << endl;
    else if (b1 == 0 && b2 == 0 && b3 == 1)
        cout << "Open" << endl;
    else if (b1 == 0 && b2 == 0 && b3 == 0)
        cout << "Close" << endl;
    else
        cout << "Close" << endl;

    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b, c, z = 1;
    cin >> a >> b >> c;
    if (a != b) z++;
    if (a != c && b != c) z++;
    cout << z;
}


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

int main(){
  int A,B,ans = 0;
  cin >> A >> B;
  ans += max(A,B);
  if(A>B){
    A--;
  }
  else{
    B--;
  }
  ans += max(A,B);

  cout << ans;
  
}


Measured memory_bytes: 256