akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<ll> primenum;
void get_prime_nembers(ll n)
{
    ll m = n;
    FOR(i,2,m+1) {
        bool flag = true;
        REPALL(j,primenum) {
            if (i % primenum[j] == 0) {
                flag = false;
                break;
            }
        }
        if (flag) {
            primenum.push_back(i);
            while (m % i == 0) {
                m /= i;
            }
        }
        if (i > sqrt(n)+1) {
            primenum.push_back(m);
            break;
        }
    }
}

vector<pair<int, int>> prime_factorization(ll n)
{
    if (primenum.empty())
        get_prime_nembers(n);

    vector<pair<int, int>> rtn;
    REPALL(i,primenum) {
        int num = 0;
        ll tmpn = n;
        while(tmpn % primenum[i] == 0) {
            num++;
            tmpn /= primenum[i];
        }
        if (num > 0)
            rtn.push_back(make_pair(primenum[i],num));
    }
    return rtn;
}

vector<vector<ll>> comb(111111, vector<ll>(100, -1));
ll Combination(ll a, ll b)
{
    if (comb[a][b] != -1) {
        return comb[a][b];
    }

    if (b > a / 2) {
        return Combination(a, a - b);
    }

    if (a == b || b == 0) {
        return 1;
    }

    if (comb[a-1][b-1] == -1) {
        comb[a-1][b-1] = Combination(a-1, b-1);
    }

    if (comb[a-1][b] == -1) {
        comb[a-1][b] = Combination(a-1, b);
    }

    comb[a][b] = (comb[a-1][b-1] + comb[a-1][b]) % MOD;

    return comb[a][b];
}

int main()
{
    int n, m;
    cin>>n>>m;
    vector<pair<int, int>> pf(prime_factorization(m));
    ll ans = 1ll;
    REPALL(i,pf) {
        ans *= Combination(n + pf[i].second - 1, pf[i].second);
        ans %= MOD;
    }
    cout<<ans<<endl;
    //REPALL(i,primenum) cout<<primenum[i]<<" ";

    return 0;
}


Measured memory_bytes: 97792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{

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

  sort(a.rbegin(),a.rend());
  ll x=0,y=0;
  rep(i, n-1) {
    if (a[i] == a[i+1]) {
      if (x == 0) {
        x = a[i];
        i++;
      } else {
        y = a[i];
        break;
      }
    }
  }
  cout << x*y << endl;

  return 0;
}


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

int main()
{
    string S;
    cin >> S;
    if (S == "AAA" || S == "BBB")
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
int main(){
	int N,r,s,i;
	for(;~scanf("%d",&N)&&N;printf("%d\n",r)){
		std::vector<int>a(N);
		for(s=i=0;i<N;i++)scanf("%d",&a[i]),s+=a[i];
		for(r=i=0;i<N;i++)r+=a[i]*N<=s;
	}
}


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


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int res = 0;
  int cnt = 1;
  rep(i,n-1) {
    if (a[i] == a[i+1]) cnt++;
    else res += cnt / 2, cnt = 1;
  }
  res += cnt / 2;
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(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 rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 28;
constexpr lint   INFL = 1LL << 60;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  string n;
  cin >> n;
  const int len = n.length();
  // dp[桁][3出た][5出た][7出た][nと一致][上位桁が全て0]
  int dp[11][2][2][2][2][2] = {0};
  dp[len][0][0][0][1][1] = 1;
  vector<int> num{3, 5, 7, 0};
  rrep (i, len) {
    int digit = n[len - i - 1] - '0';
    rep (j, 4) {
      vector<bool> next(4);
      next[j] = true;
      const int x = num[j];
      bool big = x > digit, same = x == digit;
      rep (a, 2) {
        rep (b, 2) {
          rep (c, 2) {
            rep (d, 2) {
              if (d && big) continue;
              rep (e, 2) {
                if (next[3] && !e) continue;
                int na = a | next[0];
                int nb = b | next[1];
                int nc = c | next[2];
                int nd = d & same;
                int ne = next[3];
                dp[i][na][nb][nc][nd][ne] += dp[i + 1][a][b][c][d][e];
              }
            }
          }
        }
      }
    }
  }
  int sum = 0;
  rep (i, 2) sum += dp[0][1][1][1][i][0];
  cout << sum << endl;
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i++){
    if(s[i] + n <= 'Z'){ 
      s[i] = s[i] + n;
    }
    else{
      s[i] = 'A' + n - ('Z' - s[i]) - 1;
    }
  }
  for(int i = 0; i < s.length(); i++) cout << s[i];
  cout << endl;
}

Measured memory_bytes: 888
a=int(input())
n = 0
for i in range(9,0,-1):
    if(a % i == 0):
        a = a/i
        if(a < 10):
            print("Yes")
            n = 1
            break
        else:
            print("No")
            n = 1
            break
if(n == 0):
    print("No")

Measured memory_bytes: 3060
//shahil_005
//Some basic pre-written functions might have been copied from www.geeksforgeeks.org or cp-algorithms.com//

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int N = 1e5 + 5;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

int32_t main()
{
    int n;
    cin >> n;
    int a[n+1];
    a[0] = 0;
    for(int i=1;i<=n;i++)
    {
        cin>> a[i];
    }
    int b[n+1];
    b[0] =0;
    for(int i=1;i<=n;i++)
    {
        b[i] = a[i];
    }

    sort(b,b+n+1);

    int x = b[1];
    int y = b[n];
    int ans=INT_MAX;
    int k=x;
    while(k<y+1)
    {
        int sum=0;
        int p = 1;
        while(p<n+1)
        {
            int i = b[p];
            sum+= pow(abs(i-k),2);
            p++;
        }


        //cout << sum << endl;
        if(sum < ans)
        {
            ans = sum;
        }
        k++;
    }

    cout << ans;
    return 0;
}



Measured memory_bytes: 256
import numpy as np

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

_a = np.array(a)
max_index = np.argmax(_a)
max_val_1 = np.max(_a)
_a[max_index] = 0
max_val_2 = np.max(_a)

for i in range(n):

    if max_val_1 == max_val_2:
        print(max_val_1)
        
    elif max_val_1 != max_val_2 and a[i] == max_val_1:
        print(max_val_2)
    
    else:
        print(max_val_1)


Measured memory_bytes: 23288
#include<iostream>
#include<vector>
using namespace std;
int n,m,k;
vector<int> card;

vector<int> cut(int x){
	vector<int> ans;
	for(int i=x;i<2*n;i++){
		ans.push_back(card[i]);
	}
	for(int i=0;i<x;i++){
		ans.push_back(card[i]);
	}
	return ans;
}

vector<int> ref(){
	vector<int> ans;
	for(int i=0;i<n;i++){
		ans.push_back(card[i]);
		ans.push_back(card[n+i]);
	}
	return ans;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=2*n;i++)card.push_back(i);
	for(int i=0;i<m;i++){
		scanf("%d",&k);
		if(k==0)card=ref();
		else card=cut(k);
	}
	for(int i=0;i<2*n;i++){
		printf("%d\n",card[i]);
	}
}

Measured memory_bytes: 1196
#include<stdio.h>
#include<string.h>

int main(){
	
	char a[15];
	char b[15];
	char c[15];
	
	int x, y;
	
	scanf ("%s %s", &a, &b);
	getchar ();
	scanf ("%d %d", &x, &y);
	getchar();
	scanf("%s", &c);
	
	if (strcmp(a,c)==0){
		printf("%d %d", x-1, y);
	}else if (strcmp(b,c)==0){
		printf("%d %d",x,y-1);
	}
	
	return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include<stdio.h>
#include<algorithm>

using namespace std;

long long  dataArray[2000];

int main()
{
	long long  n, z, w;
	cin >> n >> z >> w;
	for (int i = 1; i <= n; i++)
		cin >> dataArray[i];
	if (n == 1)
		cout << abs(w- dataArray[1]) << endl;
	else
		cout << max(abs(w - dataArray[n]), abs(dataArray[n] - dataArray[n - 1])) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector<ll> a(N);
  vector<ll> b(N);
  vector<ll> c(M);
  vector<ll> d(M);
  rep(i,N){
    cin >> a[i] >> b[i];
  }
  rep(i,M){
    cin >> c[i] >> d[i];
  }

  vector<ll> ans;

  rep(i,N){
    ll tmp = mod;
    ll tmpans=0;
    rep(j,M){
      if(tmp>abs(a[i]-c[j])+abs(b[i]-d[j])){
        tmp = abs(a[i]-c[j])+abs(b[i]-d[j]);
        tmpans = j;
      }
    }
    ans.pb(tmpans);
  }
  rep(i,(int)ans.size()){
    cout << ans[i]+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
     public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);

         int n = sc.nextInt();
         ArrayList<Integer> list = new ArrayList<>();
         for(int i = 0; i < n; i++) {
             list.add(sc.nextInt());
         }
              
        Integer max = list.stream().max(Comparator.naturalOrder()).get();;
        Integer min = list.stream().min(Comparator.naturalOrder()).get();;
        System.out.println(max - min);
    } 
}

Measured memory_bytes: 28628
n = int(input())
f = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]

ans = -(10 ** 18)
for op in range(1, 2 ** 10):
  overlaps = [0] * n
  for k,v in enumerate(f):
    overlap = 0
    for j in range(10):
      if ((op >> j) & 1) and v[j]:
        overlap += 1
    overlaps[k] = overlap
  tmp = 0
  for k,v in enumerate(overlaps):
    tmp += p[k][v]
  ans = max(ans, tmp)
print(ans)

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

using namespace std;

int main()
{
  int N; cin >> N;
  int mx=0, mn=1001;
  for (int i = 0; i < N; ++i) {
    int x; cin >> x;
    mx = max(mx, x);
    mn = min(mn, x);
  }

  cout << mx-mn;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <cstring>
#include <string>
#include <bitset>
#include <stdlib.h>
#include <time.h>  
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define st first
#define sd second
#define mkp make_pair
#define pb push_back
void wenjian(){freopen("xxx.in","r",stdin);freopen("xxx.out","w",stdout);}
void tempwj(){freopen("hash.in","r",stdin);freopen("hash.out","w",stdout);}
ll gcd(ll a,ll b){return b == 0 ? a : gcd(b,a % b);}
ll qpow(ll a,ll b,ll mod){a %= mod;ll ans = 1;while(b){if(b & 1)ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;}
struct cmp{bool operator()(const pii & a, const pii & b){return a.second > b.second;}};
int lb(int x){return  x & -x;}

const double inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;
const int maxn = 2e5+5;
const int M = 1e8;

int a[maxn];
ll s[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	ll sum = 0;
	for (int i = 0; i<= n; i ++ )
	{
		scanf("%d",&a[i]);
		sum += a[i];
	}
	if(n > 0 && a[0] > 0)
	{
		printf("-1\n");
		return 0;
	}
	else if(n == 0 && a[0] > 1)
	{
		printf("-1\n");
		return 0;
	}
	ll s =  1;
	ll ans = 1;
	for (int i = 1; i <= n; i ++ )
	{
		s = min(s * 2, sum);
		ans += s;
		s -= a[i];
		sum -= a[i];
		// printf("%lld %lld %d\n",s,sum,a[i]);
		if(s < 0)
		{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n",ans);
}


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

using namespace std;

template <class T> inline bool chmax(T &a, T b) { /* {{{ */
  if (a < b) {
    a = b;
    return true;
  }
  return false;
} /* }}} */

int main() {
  string S, T;
  cin >> S >> T;
  vector<vector<int>> dp(3005, vector<int>(3005));
  for (int i = 0; i < S.length(); i++) {
    for (int j = 0; j < T.length(); j++) {
      if (S[i] == T[j]) {
        chmax(dp[i + 1][j + 1], dp[i][j] + 1);
      }
      chmax(dp[i + 1][j + 1], dp[i + 1][j]);
      chmax(dp[i + 1][j + 1], dp[i][j + 1]);
    }
  }
  string ans = "";
  int s = S.length();
  int t = T.length();
  while (s > 0 and t > 0) {
    if (dp[s][t] == dp[s - 1][t]) {
      s--;
    } else if (dp[s][t] == dp[s][t - 1]) {
      t--;
    } else {
      s--;
      t--;
      ans += S[s];
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 35712
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String ins = sc.next();
		int length = ins.length();
		int pre_char = 'A';
		int cnt = 0;
		for (int i=0;i<length;i++) {
			int c = ins.charAt(i);
			if (c > pre_char) cnt = cnt + (c - pre_char);
			else cnt = cnt + (c - pre_char) + 26;
			pre_char = c;
		}
		System.out.println(cnt / 26);
	}
}



Measured memory_bytes: 26312
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define LL long long
#define maxn 205
int num[maxn],num1[maxn];
void init()
{
	for(int i=1;i<105;++i) num[i]=0;
	num[105]=1;
	for(int i=106;i<=200;++i)
	{
		for(int j=1;j<=i;++j) 
		{
			if(i%j==0) num1[i]++;
		}
		if(num1[i]==8&&i&1) {num[i]=num[i-1]+1;}
		else num[i]=num[i-1];
	}
}
int main()
{
   int n;
   init();
   while(cin>>n)
   cout<<num[n]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
#define rep1(i,n) for(int i = 1 ; i <= n ; ++i)
using namespace std;
const int INF = 1e+9;
int n,k;
int h[100010];
int dp[100010];
int main()
{
  cin >> n >> k;
  rep(i,n) cin >> h[i];
  rep(i,n) dp[i] = INF;
  dp[0] = 0;
  rep(i,n){
    rep1(j,k){
      if(i+j > n-1) break;
      dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j]-h[i]) );
    }
  }
  cout << dp[n-1] << "\n";
  return 0;
}


Measured memory_bytes: 1024
def main():
    N, M = map(int, input().split(" "))
    left = 0
    right = N
    for _ in range(M):
        l, r = map(int, input().split(" "))
        left = max(left, l)
        right = min(right, r)
    if right - left < 0:
        print(0)
    else:
        print(right - left + 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
N = int(input())
A = []
for i in range(2):
  A.append(list(map(int, input().split())))
X = A[0][0] + sum(A[1])
ans = X
for i in range(N-1):
  X = X - A[1][i] + A[0][i+1]
  ans = max(ans, X)
print(ans)

Measured memory_bytes: 61888
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
using namespace std;
const int MAX = 1e5 + 10; //N
const ll MOD = 1e9 + 7;
int N, M, K, Q;
vector<string> vec;

int main()
{
	int i, j;
	string s;
	cin >> s >> K;
	for (i = 0; i < s.size(); ++i) {
		for (j = 1; j <= 5; ++j) {
			if (i + j - 1 >= s.size()) break;
			vec.push_back(s.substr(i, j));
		}
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	cout << vec[K-1];

}

Measured memory_bytes: 1660
#include <stdio.h>
#include <string.h>

int main(void)
{
  int a, b;
  char temp[16];

  while (scanf("%d %d", &a, &b) != EOF) {
    sprintf(temp, "%d", a+b);
    printf("%d\n", strlen(temp));
  }

  return 0;
}

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

int n, sum;
vector<int> a;
vector<char> sign;

bool solve(){
  sum = a[0];
  rep(j, n-1){
    if(sign[j] == '+'){
      sum += a[j+1];
    }else{
      sum -= a[j+1];
    }
  }
  if(sum == 7) return true;
  return false;
}

void print(){
  rep(j, n){
    if(j) cout << sign[j-1];
    cout << a[j];
  }
  cout << '=' << 7 << endl;
}

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

  n = s.size();
  a.resize(n, 0);
  rep(i, n){
    a[i] = s[i] - '0';
  }

  sign.resize(n-1, '+');
  if(solve()){
    print(); return 0;
  }

  rep(i, n-1){
    sign[i] = '-';
    if(solve()){
      print(); return 0;
    }else{
      sign.assign(n-1, '+');
    }
  }

  sign[0] = '-'; sign[1] = '-';
  if(solve()){
    print(); return 0;
  }
  sign.assign(n-1, '+');

  sign[1] = '-'; sign[2] = '-';
  if(solve()){
    print(); return 0;
  }
  sign.assign(n-1, '+');

  sign[2] = '-'; sign[0] = '-';
  if(solve()){
    print(); return 0;
  }

  sign.assign(n-1, '-');
  if(solve()){
    print(); return 0;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll max_N = 400 + 50, INF = 1e15, MOD = 1e9 + 7;
ll N, arr[max_N], DP[max_N][max_N], presum[max_N];

ll min_cost_combine(ll s, ll e)
{
    if (s == e)
        return 0;
    ll &res = DP[s][e];
    if (res != -1)
        return res;
    res = INF;
    for (int i = s; i < e; ++i)
        res = min(res, presum[e] - presum[s-1] + min_cost_combine(s, i) + min_cost_combine(i + 1, e));
    return res;
}

int main()
{
    cin >> N;
    for (int i = 1; i <= N; ++i)
        cin >> arr[i];
    presum[0] = 0;
    for (int i = 1; i <= N; ++i)
        presum[i] = presum[i - 1] + arr[i];
    memset(DP, -1, sizeof(DP));
    cout << min_cost_combine(1, N) << "\n";
    return 0;
}

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

void print( vector<int> &A, int N )
{
	for( int k = 0; k < N; k++ ) {
		cout << A[k];
		if( k < N - 1 ) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
}

int sort( vector<int> &A, int N )
{
	int sw = 0;
	int flag = 1;
	while( flag ) {
		flag = 0;
		for( int i = N - 1; i > 0; i-- ) {
			if( A[i] < A[i - 1] ) {
				swap( A[i], A[i - 1] );
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

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

	int sw = sort( A, N );

	print( A, N );
	cout << sw << endl;

}



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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

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

	int b[100005] = {};

	rep(i,n){
		b[a[i]]++;
		b[a[i]+1]++;
		b[a[i]+2]++;
	}

	int mxb = -1;

	rep(i,100005){
		if(b[i] >= mxb) mxb = b[i];
	}

	cout << mxb << endl;
}

Measured memory_bytes: 1024
# AOJ 1006: Boring Commercials
# Python3 2018.7.5 bal4u

import sys
from sys import stdin
input = stdin.readline

def d2t(d):	return (d//100)*60 + (d%100)

while True:
	n, p, q = map(int, input().split())
	if n == 0: break
	tbl = [0]*1500
	p, q = d2t(p), d2t(q)
	for i in range(n):
		k = 2*int(input())
		a = list(map(int, input().split()))
		for j in range(0, k, 2):
			t1, t2 = d2t(a[j]), d2t(a[j+1])
			for t in range(t1, t2): tbl[t] += 1
	ans = k = 0
	for t in range(p, q):
		if tbl[t] < n: k += 1
		elif k > 0: 
			if k > ans: ans = k
			k = 0
	if k > ans: ans = k
	print(ans)



Measured memory_bytes: 5624
#include <stdio.h>

int main(void)
{
	int n, i;
	int a;
	int max = -1000000;
	int min = 1000000;
	long long int sum = 0;

	scanf("%d", &n);

	
	for (i = 1; i <= n; i++) {
		scanf("%d", &a);
		if (min > a) {
			min = a;
		}
		if (max < a) {
			max = a;
		}
		sum += a;
	}

	printf("%d %d %lld\n", min, max, sum);
	
	return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

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

const int INF = 1 << 24;

int main(void){
    for(int b, r, g, c, s, t; cin >> b >> r >> g >> c >> s >> t, t; cout << 100 + 3 * (s - t) + 2 * c + 7 * g + 15 * (b + r) + 16 * (5 * b + 3 * r) << endl);
 
    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

#include <stdlib.h>

int main() {
    int i, j, k, key;
    int array_num = 0;
    scanf("%d", &array_num);

    //dynamic scan
    int* array;
    array = (int*)malloc(array_num * sizeof(int));
    for (i = 0; i != array_num; i++) {
        scanf("%d", &array[i]);
    }

    //initial print
    for (k = 0; k < array_num; k++) {
        if (k == array_num - 1)printf("%d\n", array[k]);
        else printf("%d ", array[k]);
    }

    for (i = 1; i < array_num; i++) {

        //insertion sort
        key = array[i];
        j = i - 1;
        while (j >= 0 && array[j] > key) {
            array[j + 1] = array[j];
            j--;
        }
        array[j + 1] = key;

        //printing
        for (k = 0; k < array_num; k++) {
            if (k == array_num - 1)printf("%d\n", array[k]);
            else printf("%d ", array[k]);
        }
    }

    return 0;

}



Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

llint n;
llint a[100005], b[100005];
bool usea[100005], useb[100005];
vector<pair<llint, pair<llint, llint> > > vec;

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
	for(int i = 1; i <= n; i++){
		vec.push_back(make_pair(a[i], make_pair(i, 0)));
		vec.push_back(make_pair(b[i], make_pair(i, 1)));
	}
	sort(vec.begin(), vec.end());
	vec.resize(n);
	
	llint sum = 0;
	for(int i = 0; i < vec.size(); i++) sum += vec[i].first;
	
	for(int i = 0; i < vec.size(); i++){
		if(vec[i].second.second == 0) usea[vec[i].second.first] = true;
		else useb[vec[i].second.first] = true;
	}
	bool flaga = false, flagb = false;
	for(int i = 1; i <= n; i++){
		if(usea[i] && useb[i]){
			cout << sum << endl;
			return 0;
		}
	}
	for(int i = 1; i <= n; i++){
		if(usea[i]) flaga = true;
		if(useb[i]) flagb = true;
	}
	if(!flaga || !flagb){
		cout << sum << endl;
		return 0;
	}
	
	llint ans = inf, mn = inf, mx = 0, mn_i, mx_i;
	for(int i = 1; i <= n; i++){
		llint x;
		if(usea[i]) x = b[i];
		else x = a[i];
		if(x < mn){
			mn = x;
			mn_i = i;
		}
	}
	for(int i = 1; i <= n; i++){
		if(i == mn_i) continue;
		llint x;
		if(usea[i]) x = a[i];
		else x = b[i];
		mx = max(mx, x);
	}
	ans = min(ans, sum+mn-mx);
	
	mn = inf, mx = 0, mn_i;
	for(int i = 1; i <= n; i++){
		llint x;
		if(usea[i]) x = a[i];
		else x = b[i];
		if(x > mx){
			mx = x;
			mx_i = i;
		}
	}
	for(int i = 1; i <= n; i++){
		if(i == mx_i) continue;
		llint x;
		if(usea[i]) x = b[i];
		else x = a[i];
		mn = min(mn, x);
	}
	ans = min(ans, sum+mn-mx);
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10096
//Twitter@KonoLv1 2020年春卒で現在就職活動中！
 
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

int main(void){
    int i,j;            //  ループ文に使用
    int x,y,z;
    int count1,count2,count;   //  カウント用に使用
    int box[256] = {};
    char s[200001] = {};        //  文字列
    char s2[200001] = {};        //  文字列
    int a,b,c;
    a = b = c = i = 0;
    int mode = 0;
    count = count1 = count2 = 0;

    //  入力処理
    
    scanf("%s",s);

    //  計算処理
    if (s[1] != '\0'){
        i = 1;
        while(s[i] != '\0'){
           if (s[i] == s[i - 1]){
               if (s[i + 1] == '\0'){
                   count = count + 1;
                   break;
               }else if (s[i + 2] == '\0'){
                   count = count + 2;
                   break;
               }else if(s[i + 3] == '\0'){
                    i = i + 1;
                    count = count + 3;
                    break;
               }else{
                i = i + 3;
                count = count + 2;
               }
           }else{
               if (s[i + 1] == '\0'){
                   count = count + 2;
                   break;
               }
               i = i + 1;
               count++;
           }
          // count++;
          
        }
    }else{
        count = 1;
    }
    //  出力処理

    printf("%d",count);
 
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

void solve(){

    ll n;
    cin >> n;
    ll a,b;
    cin >> a >> b;
    cout << n/(a+b)*a + min(a, n%(a+b)) << endl;

}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;

const int N_MAX = 500000;
int N;
bool used[N_MAX];
int idx[N_MAX];
vector<int> vs;
vector<int> buf;
vector<int> G[N_MAX];
vector<int> G_inv[N_MAX];
vector<vector<int>> ans;

void clear(){
    for(int i = 0; i < N; i++) used[i] = false;
}

void dfs1(int v){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]) dfs1(G[v][i]);
    }
    vs.push_back(v);
}

void dfs2(int v, int k){
    used[v] = true;
    idx[v] = k;
    for(int i = 0; i < G_inv[v].size(); i++){
        if(!used[G_inv[v][i]]) dfs2(G_inv[v][i], k);
    }
    buf.push_back(v);
}

void scc(){
    for(int i = 0; i < N; i++){
        if(!used[i]) dfs1(i);
    }
    clear();
    int cur = 0;
    for(int i = vs.size()-1; i >= 0; i--){
        if(!used[vs[i]]) {
            dfs2(vs[i], cur);
            cur++;
            ans.push_back(buf);
            buf.clear();
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b; cin >> a >> b;
        if(a == b) continue;
        G[a].push_back(b);
        G_inv[b].push_back(a);
    }
    scc();
    cout << ans.size() << endl;
    for(auto v : ans){
        cout << v.size() << ' ';
        for(int i : v) cout << i << ' ';
        cout << endl;
    }
}

Measured memory_bytes: 80520
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
   int a;
   cin>>a;
   double b;
   double k;
   for(int i = 0;i<a;i++){
     double dd;
     cin >> dd;
     b+=1/dd;
   }
   cout<<1/b;
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    mod=10**9+7
    stone_last_pos=[-1]*(2*10**5+1)
    dp=[0]*(n+1)
    dp[0]=1
    for i in range(1,n+1):
        c=int(input())
        place=stone_last_pos[c]
        if place==i-1 or place==-1:
            dp[i]=dp[i-1]
        else:
            dp[i]=(dp[i-1]+dp[place])%mod
        stone_last_pos[c]=i
    print(dp[n])


if __name__=='__main__':
    main()

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

using namespace std;

int main()
{
    int n,m;
    cin >> n>>m;
    vector<int> tmp(n,-1);
    int s[m],c[m];
    bool flg=true;
    for(int i=0;i<m;i++){
        cin >>s[i]>>c[i];
        if(tmp[s[i]-1]==-1||tmp[s[i]-1]==c[i]){
                tmp[s[i]-1]=c[i];
            }
            else flg=false;
    }
    if(n==1){
         if(tmp[0]==-1)cout<<0;
                else if(flg) cout << tmp[0];
                else cout << -1;
    }
   else if(flg==true&&tmp[0]!=0){
      for(int i=0;i<n;i++){
            if(i==0){
                if(tmp[i]==-1)cout<<1;
                else cout << tmp[i];
            }
             else {
                if(tmp[i]==-1)cout<<0;
                else cout << tmp[i];
             }
      }
    }
    else cout << -1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
void dfs(vector<int> *to,int v, int p = -1){
	for(int u : to[v]){
		if(u == p) continue;
		ans[u] += ans[v];
		dfs(to,u,v);
	}
}
int main(int argc, char** argv){
	int n,q;
	cin >> n >> q;
	vector<int> to[n];
	for(int i = 0; i < n-1; i++){
		int a, b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b); 
		to[b].push_back(a);
	}
	ans.resize(n);
	for(int i = 0; i < q; i++){
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	dfs(to,0);
	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 27136
n,m,q = map(int,input().split())
abcd = []
for i in range(q):
    abcd.append(list(map(int,input().split())))
ans = 0

def dfs(s):
    if len(s) == n:
        global ans
        count = 0
        for a,b,c,d in abcd:
            a -= 1
            b -= 1
            if s[b] - s[a] == c:
                count += d
        ans = max(ans, count)
        return
    for i in range(s[-1], m+1):
        dfs(s + [i])
for i in range(1,m+1):
    dfs([i])
print(ans)


Measured memory_bytes: 9176
n = int(input())
l = list(map(int,input().split()))
A = [0]*(n)
A[0] = 0
A[1] = abs(l[1] - l[0])
for i in range(2,n):
    
    dis1 = A[i-1] + abs(l[i]-l[i-1])
    dis2 = A[i-2] + abs(l[i]-l[i-2])
    A[i] = min(dis1,dis2)

print(A[n-1])

Measured memory_bytes: 13980
a,b,k=map(int,input().split())

ans=[]

for i in range(a,a+k):
  if i<=b:
    ans.append(i)
  
for i in range(b-k+1,b+1):
  if i>=a and i not in ans:
    ans.append(i)
    
ans.sort()

for a in ans:
  print(a)

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

# debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    S = SI()
    K = II()
    N = len(S)

    same_cnt = 0
    for c in S:
        if c == S[0]:
            same_cnt += 1

    if same_cnt == N:
        print((N*K)//2)
        return

    chunks = []
    prev = ''
    chunk_len = 0
    in_chunk = False
    for i, c in enumerate(S):
        dprint(c, in_chunk, prev, c)
        if prev == c:
            if in_chunk:
                chunk_len += 1
            else:
                chunk_len = 2
                chunk_start = i-1
                in_chunk = True
        else:
            if in_chunk:
                in_chunk = False
                chunks.append((chunk_start, chunk_len))
        prev = c

    if in_chunk:
        chunks.append((chunk_start, chunk_len))

    # start end chunk
    if S[0] == S[N-1]:
        start_chunk_head = chunks[0][0]
        end_chunk_tail = chunks[len(chunks)-1][0] + chunks[len(chunks)-1][1] - 1
        start_n, end_n = 1, 1
        start_chunk_i = 0
        cnt_for_end_chunk = 0
        cnt_for_start_chunk = 0
        end_chunk_i = len(chunks) - 1
        if start_chunk_head == 0:
            start_n = chunks[0][1]
            start_chunk_i = 1
            cnt_for_start_chunk = start_n // 2
        if end_chunk_tail == N-1:
            end_n = chunks[len(chunks)-1][1]
            end_chunk_i = len(chunks) - 2
            cnt_for_end_chunk = end_n // 2

        start_end_chunk_n = start_n + end_n

        dprint(chunks, start_n, end_n, start_end_chunk_n)
        dprint(start_chunk_i, end_chunk_i)
        cnt = 0
        for chead, clen in chunks[start_chunk_i:end_chunk_i+1]:
            cnt += clen //2
        dprint(cnt)
        cnt = cnt*K + start_end_chunk_n//2 * (K-1) + cnt_for_end_chunk + cnt_for_start_chunk

        print(cnt)
        return


    else:
        cnt = 0
        for chead, clen in chunks:
            cnt += clen //2
        print(cnt * K)
        return


solve()

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

import sys
import os
import math

for s in sys.stdin:
    n = int(s)
    if n == -1:
        break

    v = [1, 0]
    for i in range(n-1):
        w = [-v[1], v[0]]
        l = math.sqrt(w[0]**2 + w[1]**2)
        normalized = [w[0] / l, w[1] / l]

        vx = v[0] + normalized[0]
        vy = v[1] + normalized[1]
        v = [vx, vy]

    print(v[0])
    print(v[1])

Measured memory_bytes: 7644
N = int(input().strip())

if N % 2 == 1:
  print(0)
  exit()

ans = 0
n_2 = N//2
now_p = 1
while True:
  tmp = n_2 // (5**now_p)
  if tmp == 0: break
  ans += tmp
  now_p += 1
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define REP(i,n) for(i=0; i<n; i++)
#define REP1(i,n) for(i=1; i<n; i++)
#define IREP(i,n) for(i=n-1; i>=0; i--)
#define ALL(c) (c).begin(), (c).end() 
#define X first
#define Y second;
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,W,H,i,ix,iy,iw;
	cin >> N >> W >> H;
	W++;
	H++;
	int coverX[W];
	int coverY[H];
	memset(coverX, 0, sizeof(coverX));
	memset(coverY, 0, sizeof(coverY));
	// REP(ix,W) cout << coverX[ix] << endl; 
	REP(i,N) {
		int x,y,w;
		cin >> x >> y >> w;
		coverX[max(0,x-w)]++;
		coverX[min(W-1,x+w)]--;
		coverY[max(0,y-w)]++;
		coverY[min(H-1,y+w)]--;
	}
	int thickness = 0;
	bool coverAllX = true;
	REP(ix,W-1) {
		thickness += coverX[ix];
		if(!thickness) {
			coverAllX = false;
			break;
		}
	}
	thickness = 0;
	bool coverAllY = true;
	REP(iy,H-1) {
		thickness += coverY[iy];
		if(!thickness) {
			coverAllY = false;
			break;
		}
	}
	if(coverAllX || coverAllY) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1980
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define maxn 100000005
#define LL long long
#define INF 0x3f3f3f3f
#define mset(p,v) memset(p,v,sizeof(p))
using namespace std;

long double a,b,c;

int main()
{
    while(cin>>a>>b>>c)
    {
        if(a+b+2*sqrt(a*b)<c)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

string d[4] = {"maerd", "remaerd", "esare", "resare"};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    int n = s.length();
    int i = 0;
    bool isexist = true;
    while(i < n) {
        int t = 0;
        rep(j, 4) {
            int k = d[j].length();
            bool ok = false;
            if (s.substr(i, k) == d[j]) ok = true;
            if (ok) chmax(t, k);
        }
        if (t == 0) {
            isexist = false;
            break;
        }
        i += t;
    }

    if (isexist) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <array>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>

int main()
{
    int n, m;
    std::array<int, 1005> as;

    std::cin >> n >> m;
    int all_vote = 0;
    for (size_t i = 0; i < n; ++i)
    {
        std::cin >> as[i];
        all_vote += as[i];
    }

    int selected = 0;
    for (size_t i = 0; i < n; ++i)
    {
        auto a = as[i];
        if (a * 4 * m >= all_vote)
        {
            selected++;
        }
    }

    if (selected >= m)
    {
        std::cout << "Yes\n";
    }
    else
    {
        std::cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 384
#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) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int N;
  while(cin>>N && N){
    int p, q;
    cin>>p>>q;
    assert(p < q && p >= 0 && q <= 2400);
    bool show[2400] = {};
    REP(i, N){
      bool cm[2400] = {};
      int k; cin>>k;
      while(k--){
        int b, e; cin>>b>>e;
        FOR(t, b, e) cm[t] = true;
      }
      REP(t, 2400) if(!cm[t]) show[t] = true;
    }
    int ans = 0;
    int con_t = 0;
    for(int t = p; t < q; t += ((t % 100 == 59) ? 41 : 1) ){
      if(show[t]) con_t++;
      else con_t = 0;
      ans = max(ans, con_t);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
N = int(input())
a = list(map(int, input().split()))

mode = 0
count = 1

for i in range(1, N):
    d = a[i] - a[i - 1]
    if mode == 0:
        mode = d
        continue
    if d > 0:
        if mode < 0:
            count += 1
            mode = 0
    elif d < 0:
        if mode > 0:
            count += 1
            mode = 0

print(count)        



Measured memory_bytes: 14252
N = int(input())

st = [[0]*10 for _ in range(10)]
for n in range(1,N+1):
    if n%10==0:
        continue
    u = n%10
    d = int(str(n)[0])
    st[u][d] += 1

ans = 0
for n in range(1, N+1):
    if n%10==0:
        continue
    u = n%10
    d = int(str(n)[0])
    ans += st[d][u]

print(ans)

Measured memory_bytes: 3064
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<string> s(2);
	rep(i, 2) cin >> s[i];
	vector<int> n(2);
	rep(i, 2) cin >> n[i];
	string s0;
	cin >> s0;
	if (s0 == s[0]) n[0]--;
	else n[1]--;
	cout << n[0] << " " << n[1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	ll n;
	cin >> n;
	string ans = "";
	 while (n) { 
        int rem = n % 26; 
        if (rem == 0) { 
            ans += "z"; 
            n = (n / 26) - 1; 
        } 
        else { 
            ans += char((rem - 1) + 'a'); 
            n = n / 26; 
        } 
    } 
	reverse(all(ans));
	cout << ans;
}


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

using namespace std;

int main() {

    int num, member[4] = {0};
    char split;
    string blood;

    while(cin >> num >> split >> blood) {
        if(blood == "A") {
            ++member[0];
        } else if(blood == "B") {
            ++member[1];
        } else if(blood == "AB") {
            ++member[2];
        } else {
            ++member[3];
        }
    }

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

}

Measured memory_bytes: 1204
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


/////////////////////////////////////////////////////////////////////////////////////////
#define MAX 10000100
ll inv[MAX];
ll finv[MAX];
ll fac[MAX];

ll beki(ll a,ll b){
    a %= mod;
    if (b == 0){
        return 1;
    }
    ll ans = beki(a,b / 2);
    ans = ans * ans % mod;
    if (b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

void cominit(){
    const int MA = 10000002;
    fac[0] = 1;
    inv[0] = 1;
    for (int i = 1;i <= MA;i++){
        fac[i] = fac[i-1] * i % mod;
    }
    finv[MA] = beki(fac[MA],mod - 2);
    for (ll i = MAX - 1;i >= 0;i--){
        finv[i] = finv[i+1] * (i + 1) % mod;
    }
    for (int i = 1;i <= MA;i++){
        inv[i] = finv[i] * fac[i - 1] % mod;
    }
}

ll com(ll a,ll b){
    if ((a == b) or (b == 0)){
        return 1;
    }
    if (a < b) return 0;
    ll ret = 1;
    for (ll i = 0;i < b;i++){
        ret *= (a - i);
        ret %= mod;
        ret *= beki(i + 1,mod - 2);
        ret %= mod;
    }
    return ret;
}


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

    int n,m;
    cin >> n >> m;

    cominit();

    cout << com(n,2) + com(m,2) << endl;
}


Measured memory_bytes: 234624
def BF(v, start, edges):
    INF = 10**18
    nega = False
    d = [INF] * v
    d[start] = 0
    for _ in range(v):
        f = False
        for a, b, c in edges:
            cost = d[a] + c
            if cost < d[b]:
                d[b] = cost
                f = True
        if not f:
            break
    else:
        nega = True
    return d, nega

from collections import deque
def BFS(N, graph, start):
    d = [-1 for i in range(N)]
    Q = deque([])
    Q.append(start)
    d[start] = 0
    while Q:
        v = Q.popleft()
        for u in graph[v]:
            if d[u] == -1:
                d[u] = d[v] + 1
                Q.append(u)
    return d

N, M, P = (int(i) for i in input().split())
graph = [[] for i in range(N)]
graphr = [[] for i in range(N)]
edges = []
for i in range(M):
    A, B, C = (int(i) for i in input().split())
    graph[A-1].append(B-1)
    graphr[B-1].append(A-1)
    edges.append((A-1, B-1, P-C))
d_start = BFS(N, graph, 0)
d_end = BFS(N, graphr, N-1)
nodes_start = [i for i in range(N) if d_start[i] >= 0]
nodes_end = [i for i in range(N) if d_end[i] >= 0]
new_edges = []
for A, B, C in edges:
    if A in nodes_start and B in nodes_start and A in nodes_end and B in nodes_end:
        new_edges.append((A, B, C))
d, Nega = BF(N, 0, new_edges)
if Nega == True:
    print(-1)
else:
    print(max(-d[N-1], 0))

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

int main() {
  int i,n,mod;
  long long ans;
  cin >> n;
  ans=1;
  mod=1000000007;
  
  for(i=1;i<=n;i++){
      ans=ans*i;
      ans=ans%mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x);
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

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

    //start from here

    readb(n, k) readarr(a, n)

    int x[n+1] = {}, y[n+1] = {}, ans = 0;

    fori (i, 1, n)
    {
    	fori (j, 1, n) if(a[i] > a[j]) x[i]++;

    	fori (j, i+1, n) if(a[i] > a[j]) y[i]++;
    }

    fori (i, 1, n)
    {
    	int z = (k*(k-1)/2) % mod;
    	ans += (y[i]*k % mod + x[i]*z % mod);
    	ans %= mod;
    }

    print(ans)

    return 0;
}


Measured memory_bytes: 256