akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c; cin >> a >> b >> c;
  cout << min({(a-(a/2)*2)*b*c, (b-(b/2)*2)*c*a, (c-(c/2)*2)*a*b}) << endk;
  return 0;
}


Measured memory_bytes: 3644
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    h1, m1, h2, m2, k = rli()
    mins = (h2-h1)*60+m2-m1
    print(mins-k)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
int n, a;
string s;
bool cmp(const pair<string, int> &a, const pair<string, int> &b){
  if(a.F.size() != b.F.size()) return a.F.size() < b.F.size();
  return a.F < b.F;
}
int main(){
  scanf("%d", &n);
  vector<pair<string, int> >v;
  rep(i, n){
    cin >> s >> a;
    int p = 0;
    while(v.size() > p){
      if(v[p].F == s){ v[p].S += a; break; }
      p++;
    }
    if(v.size() == p) v.PB(MP(s, a));
  }
  sort(v.begin(), v.end(), cmp);
  rep(i, v.size()) cout << v[i].F << ' ' << v[i].S << endl;
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------




int N;
string A,B,C;
int cnt = 0;
void _main() {
	cin >> N >> A >> B >> C;
	for (int i = 0; i < N; i++) {
		if (A[i] == B[i] && A[i] != C[i]) {
			cnt++;//C[i] == A[i];
		}
		if (A[i] == C[i] && A[i] != B[i]) {
			cnt++;//B[i] == A[i];
		}
		if (B[i] == C[i] && A[i] != C[i]) {
			cnt++;//A[i] == C[i];
		}
		if (A[i] != B[i] && A[i] != C[i] && B[i] != C[i]) {
			cnt += 2;//A[i] == B[i];C[i] == A[i];
		}
	}cout << cnt << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

const int N = 605;
const int mod = 1e9+7;
int n, m, cnt, vis[N], f[2][N][N], ans;

inline void add(int &x,int y) {
	x += y;
	x >= mod ? x -= mod : x;
}

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i){
		int x;
		scanf("%d", &x);
		int y;
		scanf("%d", &y);
		if (x != -1 && y != -1) 
			vis[x] = vis[y] = 2;
		else if (x != -1 || y != -1)
			vis[x != -1 ? x : y] = 1;
		else 
			++cnt;
	}
	for (int i = 1; i <= n << 1; ++i)
		if (vis[i] != 2)
			vis[++m] = vis[i];
	f[0][0][0] = 1; 
	for (int i = m, nxt = 1, lst = 0; i; --i, lst = nxt, nxt ^= 1) {
		memset(f[nxt], 0, sizeof(f[nxt]));
		for (int j = 0; j <= m; ++j)
			for (int k = 0; k <= m; ++k)
				if (f[lst][j][k])
					if (vis[i]) {
						add (f[nxt][j+1][k], f[lst][j][k]);
						if(k)
							add(f[nxt][j][k-1], f[lst][j][k]);
					}else{
						add(f[nxt][j][k+1], f[lst][j][k]);
						if (j)
							add(f[nxt][j-1][k], 1ll * f[lst][j][k] * j % mod);
						if (k)
							add(f[nxt][j][k-1], f[lst][j][k]);
					}
	}
	ans = f[m & 1][0][0];
	for (int i = 1; i <= cnt; ++i)
		ans = 1ll * ans * i % mod;
	printf("%d\n",ans);
}

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

from collections import deque

def main():
    N, M = map(int, input().split())
    path = [[] for _ in range(N)]

    for m in range(M):
        A, B = map(int, input().split())
        path[A-1].append(B-1)
        path[B-1].append(A-1)
    
    sign = [-1]*N
    q = deque()
    q.append(0)
    while q:
        u = q.popleft()
        for v in path[u]:
            if sign[v] == -1:
                sign[v] = u + 1
                q.append(v)
    
    print('Yes')
    print('\n'.join(map(str, sign[1:])))




if __name__ == '__main__':
    main()

Measured memory_bytes: 44764
#include <iostream>
using namespace std;
#define MOD 1000000007
typedef long long ll;

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

  ll a[n], p = 1;
  a[1] = 1;
  for (int i = 2; i < n; i++) {
    p = p * (i-1) % MOD;
    a[i] = (a[i-1] * i + p) % MOD;
  }

  ll b[n];
  b[n-1] = 1;
  for (int i = n-2; i > 0; i--) {
    b[i] = b[i+1] * (i+1) % MOD;
  }

  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ans += (x[i]-x[i-1]) * (a[i]*b[i]%MOD) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

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

template<class T> inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

long long n, a[2000005], stk[2000005], r[2000005], l[2000005];
long long ans, top;

inline void init() {
    read(n);
    for (int i = 1; i <= n; ++i)
        read(a[i]), r[i] = n + 1, l[i] = 0;
    return;
}

inline void solve() {
    for (int i = 1; i <= n; ++i) {
        while (top && a[stk[top]] > a[i])
            r[stk[top]] = i, top--;
        l[i] = stk[top];
        stk[++top] = i;
    }
    for (int i = 1; i <= n; ++i)
        ans += (r[i] - i) * (i - l[i]) * a[i];
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 14080
#include<stdio.h>
int main(void)
{
	char s[4];
	int n,i;
	scanf("%s",s);
	n=0;
	for(i=0;i<=2;i++){
		if(s[i]=='1'){
			n=n+1;
		}
	}
	printf("%d\n",n);
}

Measured memory_bytes: 128
#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; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    int p[n];
    for (int i=0;i<n;i++) cin>>p[i];
    sort(p,p+n);
    int ans=0;
    for (int i=0;i<k;i++) ans+=p[i];
    cout<<ans<<"\n";
	return 0;
}

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

int main(){
  string S;
  long Q;
  int T;
  bool check = true;

  cin >> S >> Q;
  for(int i=0;i<Q;++i){
    cin >> T;
    if(T == 1 && check){
      check = false;
    }else if(T == 1){
      check = true;
    }else{
      int F;
      char c;

      cin >> F >> c;
      if(check){
        if(F == 1){
          S.insert(S.begin(),c);
        }else{
          S.push_back(c);
        }
      }else{
        if(F == 2){
        S.insert(S.begin(),c);
      }else{
        S.push_back(c);
      }
    }
  }
}

if(check){
  cout << S << endl;
}else{
  reverse(S.begin(),S.end());
  cout << S << endl;
}
}

Measured memory_bytes: 900
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;

int main(){
	int n =0;
	vector<int> data;	//guusuu 
	vector<int> data2;	// kisuu
	int gu = 1;
	int ki = 1;
	int res = 0;
	
	cin >> n;
	int b;
	cin >> b;
	if(b %2 == 0){
		gu = 1;
		ki = 2;
	}else{
		gu = 2;
		ki = 1;
	}
	
	for(int i=1;i<n;++i){
		int a = 0;
		cin >> a;
		int tmpgu = gu;
		int tmpki = ki;
		if(a%2 == 0){
			gu = tmpgu *3 + ki;
			ki = tmpki * 2;
		}else{
			gu = tmpgu * 3 + ki * 2;
			ki = tmpki * 1;
		}
	}
	
	cout << gu <<endl;
	
	
	
	
	return 0;


}



Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;

namespace ARC073C
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var N = ss.Next(int.Parse);
            var T = ss.Next(long.Parse);
            var Tn = ss.Next(long.Parse, N);

            var ans = T;
            for (var i = 1; i < N; i++) ans += Math.Min(T, Tn[i] - Tn[i - 1]);
            sw.WriteLine(ans);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 32924
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    string str, x, y, z;
    int n, a, b;
    cin >> str >> n;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x == "print") {
            cin >> a >> b;
            y = str.substr(a, b - a + 1);
            cout << y << endl;
        }
        else if (x == "reverse") {
            cin >> a >> b;
            string u = str.substr(a, b - a + 1);
            int r = u.size();
            for (int j = 0; j<r;j++) {
                str[j+a] = u[r-j-1];
            }
        }
        else {
            cin >> a >> b >> y;
            z = str.replace(a, b - a + 1, y);
            str = z;
        }
    }
}


    



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

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

int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  if(N>=K){
    cout << K*X+(N-K)*Y << endl;
  }
  else
    cout << X*N << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

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

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

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

vector<bool> prime(int n){
  vector<bool> is_prime(n, true);
  is_prime[0] = is_prime[1] = false;
  REP(i, n){
    if(!is_prime[i]) continue;
    for(int j = 2; i*j < n; j++){
      is_prime[i*j] = false;
    }
  }
  return is_prime;
}

signed main() {
  int Q;
  cin >> Q;

  auto p = prime(200000);
  vector<int> ans(200000, 0);
  for(int i = 3; i < 200000; i += 2){
    if(p[i] && p[(i+1)/2]) ans[i] = 1;
  }

  FOR(i, 1, 200000) ans[i] += ans[i-1];

  while(Q--){
    int l, r;
    cin >> l >> r;
    cout << ans[r]-ans[l-1] << "\n";
  }
   

  return 0;
}

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

int main()
{
	int n , ans , x ;
	set<int> S;
	
	cin>>n;
	
	for( int i=0 ; i<n ; i++ ){
		cin>>x;
		S.insert(x);
	}
	ans=S.size();
	
	cout<<ans<<endl;
	return 0;
}


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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int, P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};

bool solve(){
    ll n, r;
    cin >> n;
    if(n == 0) return true;
    vector<P> v;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        v.push_back(P(a,0));
    }
    for(int i=0;i<n;i++){
        int b;
        cin >> b;
        v.push_back(P(b,1));
    }
    sort(v.rbegin(),v.rend());
    int ans = 0, cnt = 0, s = 0;
    for(int i=0;i<n*2;i++){
        if(v[i].second == 0){
            cnt++;
            s++;
            if(s > cnt/2){
                ans = cnt;
                break;
            }
        }else{
            s--;
        }
    }
    if(ans > 0 && ans < n){
        cout << ans << endl;
    }else{
        cout << "NA" << endl;
    }
    return false;
}

int main() {
    while(!solve());
    return 0;
}



Measured memory_bytes: 4428
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
int main(){
    ll N,M,K; cin >> N >> M >> K;
    ll A[N+1];
    ll B[M+1];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < M; i++)
    {
        cin >> B[i];
    }
    ll Ta[N],Tb[M];
    Ta[0] = A[0];
    for (int i = 1; i < N; i++)
    {
        Ta[i] = Ta[i-1] + A[i];
    }
    Tb[0] = B[0];
    for (int i = 1; i < M; i++)
    {
        Tb[i] = Tb[i-1] + B[i];
    }
    int a = 0;
    for (int i = 0; i < N; i++)
    {
        if(Ta[i] > K){
            a = i-1;
            break;
        }
        if(i == N-1) a = N-1;
    }
    int  b = 0;
    for (int i = 0; i < M; i++)
    {
        if(Tb[i] > K){
            b = i-1;
            break;
        }
        if(i == M-1) b = M-1;
    }
    if(a == -1 and b == -1){
        cout << 0 << endl;
        return 0;
    }
    else if(a == -1){
        cout << b+1 << endl;
        return 0;
    }
    else if(b == -1){
        cout << a+1 << endl;
        return 0;
    }
    int MAX = a+1;
    for (int i = 0; i < M; i++)
    {
        if(Ta[a] + Tb[i] <= K){
            MAX = max(a+i+2,MAX);
        }
        else{
            a--;
            if(a == -1){
                MAX = max(b+1,MAX);
                break;
            }
            i--;
        }
    }
    cout << MAX << endl;
}	


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

string a,b;
vector<int> M(200005),N(200005);

int main(){
    cin >> a >> b;

    for(int i=0;i<(int)a.length();i++){
        M[a[i]]++;
        N[b[i]]++;
    }

    sort(M.begin(),M.end());
    sort(N.begin(),N.end());

    for(int i=0;i<200005;i++){
        if(M[i]!=N[i]){
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 2436
a, b, c, d, e, f = map(int, input().split())
rec = (0, 0)
ma = 0
for i in range(31):
    for j in range(31):
        for k in range(100):
            t = i * a * 100 + j * b * 100 + c * k
            if t > f:
                break
            for l in range(100):
                s = i * a * 100 + j * b * 100 + c * k + d * l
                if s > f:
                    break
                if c * k + d * l > (a * i + b * j) * e:
                    break
                if (i * a + j * b + c * k + d * l) == 0:
                    continue
                q = (c * k + d * l) / (100 * i * a + 100 * j * b + c * k + d * l) * 100
                if q >= ma:
                    ma = q
                    rec = (s, c * k + d * l)

print(rec[0], rec[1])

Measured memory_bytes: 3064
#include<stdio.h>
#include<vector>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
const int N=1000005;
int n,T;
ll a[N];
char s[N];
vector<ll> v;
il ll Min(cll p,cll q){return p<q?p:q;}
int main(){ 
	scanf("%d",&T);it i;
	while(T--){
		scanf("%d",&n);
		for(i=1;i<=n;++i) scanf("%lld",&a[i]);
		scanf("%s",s+1),v.clear();it fl=0;
		for(i=n;i;--i){
			rll x=a[i];
			for(const ll &j : v) x=Min(x,x^j);
			if(s[i]=='0') v.push_back(x);
			if(s[i]=='1'&&x){fl=1;break;}
		}
		printf("%d\n",fl);
	}
	return 0;
}

Measured memory_bytes: 3164
<?php
fscanf(STDIN, "%d %d", $x, $y);

$a = array(1, 3, 5, 7, 8, 10, 12);
$b = array(4, 6, 9, 11);
$c = array(2);
$flag = array(false, false, false);
$count = 0;

for($i = 0 ; $i < count($a); $i++) {
	if ( $a[$i] === $x ) {
		$flag[0] = true;
	}
	if ( $a[$i] === $y ) {
		$flag[0] = true;
	}
}
for($i = 0 ; $i < count($b); $i++) {
	if ( $b[$i] === $x ) {
		$flag[1] = true;
	}
	if ( $b[$i] === $y ) {
		$flag[1] = true;
	}
}
for($i = 0 ; $i < count($c); $i++) {
	if ( $c[$i] === $x ) {
		$flag[2] = true;
	}
	if ( $c[$i] === $y ) {
		$flag[2] = true;
	}
}

for($i = 0 ; $i < count($flag); $i++) {
	if ( $flag[$i] === true ) {
		$count++;
	}
}

if ($count === 1)
	echo 'Yes';
else
	echo 'No';

Measured memory_bytes: 4856
N = int(input())
l = [int(input()) for _ in range(N)]

_min = l[0]
_max = 0
ans = -float("inf")

#print(l)
dp=[-float("inf")]*(N)

for i in range(1,N):
    pass
    dp[i] = max(dp[i-1]+l[i]-l[i-1],l[i]-l[i-1])
print(max(dp))


Measured memory_bytes: 21400
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	a := nextIntMat(2, n)
	maxc := 0

	for i := 0; i < n; i++ {
		nowc := 0
		for j := 0; j <= i; j++ {
			nowc += a[0][j]
		}
		for j := i; j < n; j++ {
			nowc += a[1][j]
		}
		maxc = max(maxc, nowc)
	}

	fmt.Println(maxc)

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

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
func nextIntMat(a int, b int) [][]int {
	mat := make([][]int, a)
	for i := 0; i < a; i++ {
		mat[i] = make([]int, b)
		for j := 0; j < b; j++ {
			mat[i][j] = nextInt()
		}
	}
	return mat
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}

template<typename T>
T gcd(T x, T y){
    if (x == 0 || y == 0) {
        return 0;
    }

    while (x != y){
        if (x > y) {
            x -= y;
        }else{
            y -= x;
        }
    }
    return x;
}

// }}}
/* vim:set foldmethod=marker: */

void solve(){
    string s;
    cin >> s;

    if (s[0] != 'A') {
        cout << "WA" << endl;
        return;
    }

    int c=0;
    for (int i = 2; i < (int)s.length()-1; i++) {
        if (s[i] == 'C') {
            c++;
        }
    }

    if (c != 1) {
        cout << "WA" << endl;
        return;
    }

    for (int i = 1; i < (int)s.length(); i++) {
        if (s[i] == 'C'){
            continue;
        }else if ('a' <= s[i] && s[i] <= 'z') {
            continue;
        }else{
            cout << "WA" << endl;
            return;
        }
    }

    cout << "AC" << endl;

    return;
}

int main(int argc, char const* argv[])
{
    // cout << ('a' <= 'h' && 'h' <= 'z' ) << endl;
    solve();
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


// map の key, value を全て抜き出す。
// for (auto itr = mp.begin(); itr != mp.end(); itr++) {
//     cout << "key" << itr->first << " value" << itr->second << endl;
// }

// 文字列の検索
// string s="abc";
// if (s.find('d') == string::npos){
//     cout << "find" << endl;
// }else{
//     cout << "not find" << endl;
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);++i)
#define rep1(i, n) for(int i=1;i<=(int)(n);++i)
#define irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


vector<lint> total, patty;

lint solve(int n, lint w)
{
  if(n == 0){
    return 1;
  }else if(w == 1){
    return 0;
  }else if(w <= total[n]/2){
    return solve(n-1, w-1);
  }else if(w == total[n]/2+1){
    return patty[n-1] + 1;
  }else if(w < total[n]){
    return solve(n-1, w-total[n]/2-1) + patty[n-1] + 1;
  }else{
    return patty[n-1] * 2 + 1;
  }
}

int main(void)
{
  int n; cin>>n;
  lint w; cin>>w;
  total.resize(n+1); patty.resize(n+1);
  total[0]=1; patty[0]=1;
  rep1(i,n){
    total[i]=total[i-1]*2+3;
    patty[i]=patty[i-1]*2+1;
  }
  cout << solve(n, w) << endl;
}


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


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


g = A[0]
for i in range(1, N):
    g = gcd(g, A[i])


for i in range(N):
    if A[i] == K:
        print('POSSIBLE')
        exit()
    elif A[i] > K and (A[i] - K) % g == 0:
        print('POSSIBLE')
        exit()

print('IMPOSSIBLE')


Measured memory_bytes: 14224
/*
I just got lost in thought. It was unfamiliar territory.
- Steven Wright
*/

#include <algorithm>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <vector>
//#include <boost/math/common_factor.hpp>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define Pi 3.14159265358979
#define A first
#define B second

typedef long long ll;
typedef vector <int> vi;
typedef vector<ll> vl;
typedef pair <int, int> pi;
typedef pair <ll, int> pl;
typedef pair <double, double> pd;

//change these according to prob constraints
const int INF = 1000000000;
const int MAX = 100005;
const int MAX1 = 2007;
const int MAX2 = 4007;
const int LEN = 21;
const int BASE = 1000000000;
const double EPS = 1e-7;
const int MOD = 1234567891;
//g++ -std=c++11 your_file.cpp -o your_program

bool arr[30][30];

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ifstream in("");
	ofstream out("");
	string s, t;
	cin >> s >> t;
	REP(i, SZ(s)){
	    int tmp1 = s[i] - 'a', tmp2 = t[i] - 'a';
	    arr[tmp1][tmp2] = 1;
	}
	REP(i, 26){
	    int ct = 0;
	    REP(j, 26){
	        if (arr[i][j]) ++ct;
	    }
	    if (ct >= 2) {
	        cout << "No" << endl;
	        return 0;
	    }
	}
	REP(i, 26){
	    int ct = 0;
	    REP(j, 26){
	        if (arr[j][i]) ++ct;
	    }
	    if (ct >= 2){
	        cout << "No" << endl;
	        return 0;
	    }
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 916
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = [inf]*100001

a[0] = 0
for i in range(1,100001):
    a[i] = min(a[i], a[i-1]+1)
    j = 1
    while i - 6**j >= 0:
        a[i] = min(a[i], a[i-6**j]+1)
        j += 1
    j = 1
    while i - 9**j >= 0:
        a[i] = min(a[i], a[i-9**j]+1)
        j += 1

print(a[n])

Measured memory_bytes: 10860
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <climits>
#include <cassert>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<string> VS;
typedef pair<int, int> pii;
typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int dx[] = {-1,1,0,0};
const int dy[] = {0,0,1,-1};

#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int N;
int a[100010];
int c[2];
int mn = 114514;

bool solve()
{
	rep(i, N) {
		if (a[i] > mn + 1) {
			return false;
		}
		++c[a[i] - mn];
	}

	if (c[1] == 0) {
		return mn == N - 1 || N >= mn * 2;
	} else {
		return c[0] < mn + 1 && (mn + 1 - c[0]) * 2 <= c[1];
	}
}

int main() {
	cin >> N;

	rep(i, N) {
		cin >> a[i];
		mn = min(mn, a[i]);
	}

	puts(solve() ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n,ans=0;
    string s;
    cin>>n>>s;
    rep(i,n){
        if(s.substr(i,3)=="ABC") ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
 
struct union_find{
    vector<ll> parent;
    vector<ll> nums;
    union_find(ll n){
        parent.resize(n);
        nums.resize(n, 1LL);
        rep(i, 0, n) parent[i] = i;
    }
 
    ll root(ll x){
        if(parent[x] == x) return x;
        parent[x] = root(parent[x]);
        return parent[x];
    }
 
    void unite(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx != ry){
            parent[rx] = ry;
            nums[ry] += nums[rx];
        }
    }
 
    bool same(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return true;
        return false;
    }
 
    ll size(ll x){
        return nums[root(x)];
    }
};  
 
int main(){
    ll n, m;
    cin >> n >> m;
    union_find t(n+1);
    rep(i, 0, m){
        ll x, y, z;
        cin >> x >> y >> z;
        t.unite(x, y);
    }
    set<ll> st;
    rep(i, 1, n+1) st.insert(t.root(i));
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 6528
//Author: Lixiang
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
struct A{
	unsigned long long Q,H,S,D,N;
	void init(){
		cin>>Q>>H>>S>>D>>N;
		//scanf("%I64d%I64d%I64d%I64d%I64d",&Q,&H,&S,&D,&N);
	}
	void work(){
		cout<<min((N%2ull==0)?N/2*D:((N-1ull)/2ull*D+min(S,min(H*2ull,Q*4ull))),min(N*S,min(N*H*2ull,N*Q*4ull)))<<endl;
	}
}sol;
int main(){
	sol.init();
	sol.work();
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int h, w;
    scanf("%d %d", &h, &w);
    char s[55][55];
    int i, j;
    int x;
    for (i = 0; i < h; i++)
        scanf("%s", s[i]);
    for (i = h; i > 0; i--)
        for (j = w; j > 0; j--)
            s[i][j] = s[i - 1][j - 1];
    for (i = 0; i <= h + 1; i++)
        s[i][0] = s[i][w + 1] = '.';
    for (j = 0; j <= w + 1; j++)
        s[0][j] = s[h + 1][j] = '.';
    for (i = 0; i <= h + 1; i++)
    {
        for (j = 0; j <= w + 1; j++)
        {
            x = 1;
            if (s[i][j] == '#')
            {
                x = 0;
                if (s[i][j - 1] == '#')
                    x++;
                if (s[i][j + 1] == '#')
                    x++;
                if (s[i - 1][j] == '#')
                    x++;
                if (s[i + 1][j] == '#')
                    x++;
            }
            if (x == 0)
                break;
        }
        if (x == 0)
            break;
    }
    if (x == 0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, m) = scan!(usize, usize);
    let vs = scan!(String;n);
    let ws = scan!(String;m);

    for i in 0.. {
        if i + m > n {
            break;
        }
        for j in 0.. {
            if j + m > n {
                break;
            }

            let mut valid = true;
            for k in i..i + m {
                for l in j..j + m {
                    if vs[k].chars().nth(l).unwrap() != ws[k - i].chars().nth(l - j).unwrap() {
                        valid = false;
                    }
                }
            }

            if valid {
                println!("Yes");
                return;
            }
        }
    }
    println!("No")
}


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

int main() {
    int N;
    cin >> N;
    vector<char> S(N);
    rep(i, N) {
        cin >> S[i];
    }
    set<char> s(S.begin(), S.end());
    if (s.size() == 3) cout << "Three" << endl;
    else cout << "Four" << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++)
    cin >> p.at(i);
  int a = 1;
  for (int i = 0; i < N; i++){
    a = p.at(a-1);
    if (a == 2){
      cout << i+1 << endl;
      break;
    }
    if (i == N-1){
      cout << -1 << endl;
    }
  }
  
}


Measured memory_bytes: 640
c,gx,gy,map[20][20],n,x,y;check(a,b){if(map[a][b]==1||a>gx||b>gy)return;if(a==gx&&b==gy){c++;return;}check(a+1,b);check(a,b+1);}
main(){for(;scanf("%d%d",&gx,&gy),gx;printf("%d\n",c)){scanf("%d",&n);for(x=0;x<20;x++)for(y=0;y<20;)map[x][y++]=0;for(c=0;n--;map[x][y]=1)scanf("%d %d",&x,&y);check(1,1);}exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define DIM 100007
#define INF 1000000000000000007
//#define endl "\n"
using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<long long, long long>  pairll;

ll a,b,i,k;


ll f(ll x){
    if(x%4==0) return x;
    if(x%4==1) return 1;
    if(x%4==2) return x+1;
    if(x%4==3) return 0;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b;
    cout << (f(a-1)^f(b)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int main () {

   int a;
   std::set<string> str;
   cin>>a;
   string s;  

   for (int i = 0; i <= a; i++) {
        cin>>s;
        str.insert(s);
   }

   cout << str.size();

}

Measured memory_bytes: 19104
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define INF 1<<24
using namespace std;
struct edge{
	int t,c;
	edge(){}
	edge(int tt,int cc){
		t=tt;
		c=cc;
	}
};

struct data{
	int v,z,c;
	data(){}
	data(int vv,int zz,int cc){
		v=vv;
		z=zz;
		c=cc;
	}
	bool operator<(const data &d)const{
		return c>d.c;
	}
};
int n,m,c;
vector<edge> G[101];
int dp[101][101];

int dijk(){
	priority_queue<data> que;
	for(int i=0;i<n;i++){
		for(int j=0;j<=n;j++){
			dp[i][j]=INF;
		}
	}
	que.push(data(0,0,0));
	dp[0][0]=0;
	while(que.size()){
		data q=que.top();
		que.pop();
		if(dp[q.v][q.z]<q.c)continue;
		for(int i=0;i<G[q.v].size();i++){
			edge e=G[q.v][i];
			if(dp[e.t][q.z]>q.c+e.c){
				dp[e.t][q.z]=q.c+e.c;
				que.push(data(e.t,q.z,q.c+e.c));
			}
			if(q.z<n && dp[e.t][q.z+1]>q.c){
				dp[e.t][q.z+1]=q.c;
				que.push(data(e.t,q.z+1,q.c));
			}
		}
	}
	for(int i=0;i<=n;i++){
		if(dp[n-1][i]<=c)return i;
	}
	return -1;
}

int main(void){
	while(1){
		scanf("%d%d%d",&n,&m,&c);
		if(n+m+c==0)break;
		for(int i=0;i<n;i++){
			G[i].clear();
		}
		for(int i=0;i<m;i++){
			int f,t,cost;
			scanf("%d%d%d",&f,&t,&cost);
			f--;
			t--;
			G[f].push_back(edge(t,cost));
		}
		printf("%d\n",dijk());
	}
	return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("input.in", "r", stdin);
    ll n, m;
    while(scanf("%lld%lld", &n, &m)!=EOF){
        if(abs(n-m)<2)
            printf("Brown\n");
        else printf("Alice\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);


int main(){
    std::ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    string c[105];
    rep(i,1,h)
        cin>>c[i];
    rep(i,1,h)
        rep(j,1,2)
            cout<<c[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
list_s = input().split(' ')
players = [int(d) for d in list_s]

# N = 2
# players = [5, 2, 8, 5, 1, 5]

players.sort()
players = players[::-1]
# print(players)

sum = 0
for i in range(1, 2*N+1, 2):
    sum += players[i]

print(sum)


Measured memory_bytes: 39516
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
   ll n,i,stocks=0;cin>>n;
   ll a[n],m=1000,mx=1000;
   fo(i,0,n)cin>>a[i];
   i=0;
   while(i<n-1)
   {
       while(i<n-1&&a[i]>=a[i+1])i++;
       stocks=(m/a[i]);m%=a[i];
       while(i<n-1&&a[i]<=a[i+1])i++;
       m+=stocks*a[i];stocks=0;
       mx=max(mx,m);
   }
   cout<<mx<<"\n";
   
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//**always check if you are not killing input in between
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//string2=string1.substr(pos,length);if len no specified then till end
//void fill (ForwardIterator first, ForwardIterator last, const T& val);
//The range filled is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.


//If wrong on pretest 2 means logically wrong
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 3640
a, b = map(int, open(0).read().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

prime_a = set(prime_factorize(a))
prime_b = set(prime_factorize(b))
print(len(prime_a&prime_b)+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int left = 0;
    int right = n - 1;
    int ans = 0;
    char x = 'x';
    while (left < right) {
        if (s[left] == s[right]) {
            left++;
            right--;
        } else if (s[left] == x and s[right] != x) {
            ans++;
            left++;
        } else if (s[left] != x and s[right] == x) {
            right--;
            ans++;
        } else {
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
}


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

int main(void){
	
	int n,Min=0;
	int  a[10];
	int tmp;
		
		
	for(int i=1;i<10;i++)
		a[i]=0;
		
		Min=0;
	cin>>n;
	while(n--){
		cin >> tmp;
		if(tmp < 400) a[1] = 1;
		else if(tmp < 800) a[2] = 1;
		else if(tmp < 1200) a[3] = 1;
		else if(tmp < 1600) a[4] = 1;
		else if(tmp < 2000) a[5] = 1;
		else if(tmp < 2400) a[6] = 1;
		else if(tmp < 2800) a[7] = 1;
		else if(tmp < 3200) a[8] = 1;
		else a[9]++;
	}	
		for(int i=1;i<9;i++){
			if(a[i]==1)
					Min++;	
			
	}
					
	

	
		
	cout<<max(1,Min)<<" "<<Min+a[9]<<endl;	



				return 0;			
			
			
}	

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N+1);
    rep(i,N) cin >> A[i+1];

    vector<ll> B(N+1),C(N+1);
    for (int i = 1; i <= N; i++) B[i] = A[i]+i;
    for (int i = 1; i <= N; i++) C[i] = A[i]-i;
    map<ll, ll> dic;
    for (int i = 1; i <= N; i++) dic[C[i]]++;
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        dic[C[i]]--;
        ans += dic[-B[i]];
    }

    cout << ans << ln;

    
}

Measured memory_bytes: 30656
s = []
a,b,n = map(int,input().split())
if (b-a+1)/2 < n:
  for i in range(a,b+1):
    print(i)
else:
  for j in range(a,a+n):
    s.append(j)
  for k in range(b,b-n,-1):
    s.append(k)
ts = sorted(s)
for item in ts:
  print(item)

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

const int mod = 1e9 + 7;
long long n, k, ans;

int main() {
	cin >> n >> k;
	for (int i = k; i < n + 2; i++) {
		ans = (ans + i * (n - i + 1) + 1) % mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int a, b, c;
  int ans[4] = {};
  while(cin>>a>>b>>c){
    if(!(c > b - a)) break;
    if(!(c > a - b)) break;
    if(!(c < a + b)) break;
    if(a > b) swap(a, b);
    if(b > c) swap(b, c);
    int D = a * a + b * b  - c * c;
    ans[0]++;
    if(D > 0) ans[1]++;
    if(D == 0) ans[2]++;
    if(D < 0) ans[3]++;
  }
  printf("%d %d %d %d\n", ans[0], ans[2], ans[1], ans[3]);
  return 0;
}

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

void solve(double w) {
  if(w <= 48.0) {
    cout << "light fly" << endl;
  } else if(w <= 51.0) {
    cout << "fly" << endl;
  } else if(w <= 54.0) {
    cout << "bantam" << endl;
  } else if(w <= 57.0) {
    cout << "feather" << endl;
  } else if(w <= 60.0) {
    cout << "light" << endl;
  } else if(w <= 64.0) {
    cout << "light welter" << endl;
  } else if(w <= 69.0) {
    cout << "welter" << endl;
  } else if(w <= 75.0) {
    cout << "light middle" << endl;
  } else if(w <= 81.0) {
    cout << "middle" << endl;
  } else if(w <= 91.0) {
    cout << "light heavy" << endl;
  } else {
    cout << "heavy" << endl;
  }
}

main() {
  double w;
  while((cin >> w)) {
    solve(w);
  }
}

Measured memory_bytes: 0