akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] colors = new int[N];

        for (int i = 0; i < N; i++) {
            colors[i] = sc.nextInt();
        }

        int ret = 0;

        int j = 0;
        while (j < N) {
            int topNum = colors[j];
            int sucCount = 1;

            while (j+1 < N && topNum == colors[j+1]) {
                j++;
                sucCount++;
            }

            if (sucCount % 2 == 0) {
                ret += sucCount / 2;
            } else {
                ret += (sucCount - 1) / 2;
            }

            j++;
        }

        System.out.println(ret);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

long long f(long long t, long long x){
  if(t == -1) return 0;
  else return t/x + 1;
}

int main(){
 long long a,b,x; cin >> a >> b >> x;
 cout << f(b,x)-f(a-1,x) << "\n";
}


Measured memory_bytes: 256
n = input()

if int(n[0]) <= int(n[1]):
    if int(n[0]) == int(n[1]) and int(n[0]) >= int(n[2]):
        temp=int(n[0])
        print(temp*100+temp*10+temp)
    else:
        temp=int(n[0])+1
        print(temp*100+temp*10+temp)
else:
    temp=int(n[0])
    print(temp*100+temp*10+temp)

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

ll f(ll x){
  if (x == 1) return 1;
  ll a = f(x/2);
  return a*2+1;
}

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

  cout << f(h) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin >> n >>k;
  int ans = 1;
  REP(i,n){
      if (ans > k)ans+=k;
      else ans*=2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n-2):
    if p[i] < p[i+1] and p[i+1] < p[i+2]:
        ans += 1
    elif p[i] > p[i+1] and p[i+1] > p[i+2]:
        ans += 1
print(ans)





Measured memory_bytes: 9100
ans = []
while True:
    n,r = map(int,input().split())
    if n == 0 and r == 0:
        break
    x = [i for i in range(1,n+1)]
    for i in range(r):
        p,c = map(int,input().split())
        x = x[:n-(p-1+c)] + x[n-(p-1):] + x[n-(p-1+c):n-(p-1)]
    ans.append(x[-1])
print("\n".join(map(str,ans)))


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

using namespace std;
typedef long long ll;

constexpr ll MOD = 1e9 + 7;

ll calc_pow(ll x, ll pow) {
    if (pow == 0) return 1;
    ll a = calc_pow(x, pow / 2);
    a = a * a % MOD;
    if (pow % 2 == 1) a *= x;
    return a % MOD;
}

ll calc_div(ll a, ll b) {
    return a * calc_pow(b, MOD - 2) % MOD;
}

vector<ll> fact;

void init_fact(int n) {
    fact = vector<ll>(n);
    fact[0] = 1;
    for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * i % MOD;
}

ll calc_comb(ll n, ll r) {
    if (n < r)return 0;
    return calc_div(fact[n], fact[r] * fact[n - r] % MOD);
}

int main() {
    init_fact(10000);
    int s;
    cin >> s;

    ll ret = 0;
    for (int i = 1; i * 3 <= s; i++) {
        int remain = s - 3 * i;
        ret += calc_comb(remain + (i - 1), i - 1), ret %= MOD;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define PAUSE \
    int t;    \
    cin >> t
#define int long long
#define vi vector<long long>
#define mapii map<long long, int>
#define mapci map<char, int>
#define append(x) push_back(x)
#define tcase          \
    long long t;       \
    scanf("%lld", &t); \
    while (t--)
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int>>
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
// #define debug(x, y) cout << "case #" << x << " at itr #" << y << endl
#define debug(x) cout << "case #" << x << endl
#define ff first
#define ss second
#define range(ini, x) for (int itr = ini; itr < x; itr++)
#define takearr(x)    \
    for (auto &i : x) \
    cin >> i
#define print(x)     \
    for (auto i : x) \
        cout << i << " ";
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define foreach(i, x) for (auto i : x)
#define setbitcount __builtin_popcount
#define mtx vector<vector<int>>
// #define range(ini, x, step) for( int itr = ini, i < x; itr += step )
using namespace std;
// using namespace __gnu_pbds;
// template < class type > using oset=tree<type, null_type,less<type>, rb_tree_tag,tree_order_statistics_node_update>;
const int mmx = 1e5 + 1;
const int mnx = 1e4 + 1;
const int mmod = 1e9 + 7;

int dp[mmx][3];

int solve(int arr[][3], int n, int current_task, int idx)
{
    int maxi = INT_MIN;

    if (idx == n)
    {
        return 0;
    }

    if (dp[idx][current_task] != -1)
    {
        return dp[idx][current_task];
    }

    for (int nxt_task = 0; nxt_task < 3; ++nxt_task)
    {
        if (nxt_task != current_task)
            maxi = max(maxi, arr[idx][current_task] + solve(arr, n, nxt_task, idx + 1));
    }

    return dp[idx][current_task] = maxi;
}

signed main()
{

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

    int N;

    cin >> N;

    int arr[N][3];

    memset(dp, -1, sizeof dp);

    for0(i, N)
    {
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    }

    int maxi = INT_MIN;

    for0(i, 3)
    {
        maxi = max(maxi, solve(arr, N, i, 0));
    }

    cout << maxi << endl;

    return 0;
}


Measured memory_bytes: 17640
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main() {
    int n;
    cin>>n;
    int k = (int)ceil(sqrt(2*n));
    if(k*(k-1)/2!=n) {
        cout << "No" << endl;
        exit(0);
    }
    else {
        cout << "Yes" << endl;
        cout<< k<<endl;
    }
    int init = 1;
    int q = init;
    cout<<k-1<<" "<<q<<" ";
    for(int d = 2;d<k;d++){
        q+=d;
        cout<<q<<" ";
    }
    cout<<endl;
    int i = 0;
    for(;i<k-1;i++){
        init = init+i;
        vector<int> temp;
        int temp_init = init;
        temp.push_back(temp_init);
        for(int j = i;j>0;j--) {
            temp_init++;
            temp.push_back(temp_init);
        }
        for(int m = i+1;m<k-1;m++){
            temp_init+=m;
            temp.push_back(temp_init);
        }
        cout<<k-1<<" ";
        for(int p = 0;p<k-1;p++)
            cout<<temp[p]<<" ";
        cout<<endl;
    }

}



Measured memory_bytes: 1408
#include <iostream>
#include <cmath>

int main()
{
	int n;

	int inputMaximum = (int)std::pow(10, 9);

	std::cin >> n;
	int minimumValue = inputMaximum + 1;
	int nextValue;
	int maxProfit = -inputMaximum - 1;

	for (int i = 0; i < n; i++)
	{
		std::cin >> nextValue;
		if (i >= 1 && nextValue - minimumValue > maxProfit)//????????´??°
		{
			maxProfit = nextValue - minimumValue;
		}
		if (nextValue < minimumValue)//????°??????´??°
		{
			minimumValue = nextValue;
		}
	}
	std::cout << maxProfit << std::endl;
}

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

int main(){
    int t[4],n[4];
    cin >>t[0]>>n[0]>>t[1]>>n[1]>>t[2]>>n[2]>>t[3]>>n[3];
    int s,a,b,c;
    if(t[0]==1){
        s=n[0]*6000;
    }else if(t[0]==2){
        s=n[0]*4000;
    }else if(t[0]==3){
        s=n[0]*3000;
    }else{
        s=n[0]*2000;
    }
    if(t[1]==1){
        a=n[1]*6000;
    }else if(t[1]==2){
        a=n[1]*4000;
    }else if(t[1]==3){
        a=n[1]*3000;
    }else{
        a=n[1]*2000;
    }   
    if(t[2]==1){
        c=n[2]*6000;
    }else if(t[2]==2){
        b=n[2]*4000;
    }else if(t[2]==3){
        b=n[2]*3000;
    }else{
        b=n[2]*2000;
    }   
    if(t[3]==1){
        c=n[3]*6000;
    }else if(t[3]==2){
        c=n[3]*4000;
    }else if(t[3]==3){
        c=n[3]*3000;
    }else{
        c=n[3]*2000;
    }   
    cout <<s<<endl<<a<<endl<<b<<endl<<c<<endl;

return 0;
}

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

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

    sort(str.begin(), str.end());
    decltype(str)::iterator tmp = unique(str.begin(), str.end());
    str.erase(tmp, str.end());

    if(str[0] != 'a'){
        cout << "a" << endl;
        return 0;
    }

    //cout << str << endl;
    int i = 0;
    bool flag = false;
    /*
    cout << str[1] - str[0] << endl;
    if(str[1] - str[0] == 1){
        cout << "unko" << endl;
    }
    */
    while(str[i + 1] != '\0'){
        if(str[i + 1] - str[i] == 1){
            i++;
            //cout << str[i + 1] - str[i] << endl;
        }
        else{
            flag = true;
            break;
        }
    }

    if(flag){
        cout << (char)(str[i] + 1) << endl;
    }
    else{
        if(str.size() != 26){
            cout << (char)(str[i] + 1) << endl;
        }
        else{
            cout << "None" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
    int i, j, n;
    int num[105][105];
    while(scanf("%d", &n), n){
	for(i = 0;i < n;i++)
	    for(j = 0;j < n;j++)
		scanf("%d", &num[i][j]);
	num[n][n] = 0;
	for(i = 0;i < n;i++){
	    num[i][n] = num[n][i] = 0;
	    for(j = 0;j < n;j++){
		num[i][n] += num[i][j];
		num[n][i] += num[j][i];
	    }
	    num[n][n] += num[i][n];
	}
	for(i = 0;i <= n;i++){
	    for(j = 0;j <= n;j++){
		printf("%5d", num[i][j]);
	    }
	    puts("");
	}
    }
    return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
    int n;
    std::cin >> n;
    long sum  = 0, min = 1e7, max = -1e7;
    for (int i = 0; i < n; ++i)
    {
        long a;
        std::cin >> a;
        sum += a;
        min = a < min ? a : min;
        max = a > max ? a : max;
    }
    std::cout << min << ' ' << max << ' ' << sum << std::endl;
        
    return 0;
}



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

int main() {
    ll H, W;
    cin >> H >> W;

    if (H == 1 || W == 1) {
        cout << 1 << endl;
    } else if (H % 2 == 0 || W % 2 == 0) {
        cout << H * W / 2 << endl;
    } else {
        cout << H * W / 2 + 1 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


ll cn[10][10];//A,Bによらず先頭がiで末尾がjの個数

int main(){
   
    int N;
    cin >> N;
    rrep(i,N){
        //1~Nまでで個数をあらかじめカウントしておく
        //いったんstringがして先頭と末尾をとってしまうのがいい
        string s = to_string(i);
        int size = s.size();
        int start = s[0] - '0';//intに戻す
        int end = s[s.size()-1] - '0';
        cn[start][end]++;
    }
    ll ans=0;
    rrep(i,9){
        rrep(j,9){
            ans += cn[i][j] * cn[j][i];
        }
    }

    fin(ans);

}
  

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
 
int main(){
	int a;scanf("%d",&a);
	for(int i=1;i<=3500;i++){
		for(int j=1;j<=3500;j++){
			long long bb=(long long)i*j*a;
			long long bs=(long long)4*i*j-a*i-a*j;
			if(bs<=0)continue;
			if(bb%bs==0){
				printf("%d %d %lld\n",i,j,bb/bs);return 0;
			}
		}
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
  
// Driver program to test above function 
int main() 
{ ll n;
 cin>>n;
 ll a[n],i,s=0;
 for(i=0;i<n;i++) cin>>a[i];
 for(i=1;i<n;i++){
 if(a[i]>=a[i-1]) continue;
   else{ s+=abs(a[i-1]-a[i]);
   a[i]=a[i-1];
       
   }
 }
 cout<<s;
    return 0; 
}

Measured memory_bytes: 5052
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;

using ll = long long;
using boost::irange;

int main(){
    int A, B;
    cin >> A >> B;

    if(B == 1){
        cout << "0" << endl;
        return 0;
    }

    int ans = A;
    int cnt = 1;
    for (int i : irange(0,100000)){
        if(ans >= B){
            break;
        }
        ans += (A-1);
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
GC.disable

N, Q = gets.split.map(&:to_i)
Cs = [nil] + gets.split.map(&:to_i)
LRs = Q.times.map{gets.split.map(&:to_i)}

class BIT
  def initialize(n)
    @n, @b = n, Array.new(n + 1, 0)
  end

  def querry(i)
    r = 0
    while i > 0
      r += @b[i]
      i -= i & -i
    end
    r
  end

  def add(i, v)
    while i <= @n
      @b[i] += v
      i += i & -i
    end
  end
end

i, m, ans, b = 0, [], [], BIT.new(N)
LRs.map.with_index.sort_by{|(l, r), i| r}.each do |(l, r), q|
  (i + 1 .. r).each do |j|
    c = Cs[j]
    b.add(m[c], 1) if m[c]
    m[c] = j
  end
  i = r
  ans[q] = (r - l + 1) - b.querry(r) + b.querry(l - 1)
end
puts ans

Measured memory_bytes: 295780
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,M,Q;
	vint adj[100001];
	int v[100001],d[100001],c[100001];
	scan(N);scan(M);
	rep(i,M){
		int a,b;
		scan(a);scan(b);
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	scan(Q);
	rep(q,Q){
		scan(v[q]);scan(d[q]);scan(c[q]);
		v[q]--;
	}
	int color[100001];
	fill(color,color+N,-1);
	rep(t,11){
		int colorb[100001];
		rep(i,N) colorb[i]=color[i];
		rep(u,N){
			rep(j,adj[u].size()){
				int u2=adj[u][j];
				colorb[u2]=max(colorb[u2],color[u]);
			}
		}
		rep(i,N) color[i]=colorb[i];
		rep(q,Q){
			if(d[q]+t==10){
				color[v[q]]=max(color[v[q]],q);
			}
		}
	}
	rep(u,N){
		if(color[u]==-1) prin(0);
		else prin(c[color[u]]);
	}
	return 0;
}


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

class Cube{
public:
  int f[6];
  Cube(){}
  void roll_z(){ roll(1, 2, 4, 3);} //
  void roll_y(){ roll(0, 2, 5, 3);} // to W
  void roll_x(){ roll(0, 1, 5, 4);} // to N
  void roll(int i, int j, int k, int l){
    int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
  }
  void move(char ch){
    if ( ch == 'E' ) for ( int i = 0; i < 3; i++ ) roll_y();
    if ( ch == 'W' ) roll_y();
    if ( ch == 'N' ) roll_x();
    if ( ch == 'S' ) for ( int i = 0; i < 3; i++ ) roll_x();
  }
};

int main(){
  Cube c;
  string com;

  for ( int i = 0; i < 6; i++ ) cin >> c.f[i];
  cin >> com;

  for ( int i = 0; i < com.size(); i++ ) c.move(com[i]);

  cout << c.f[0] << endl;

  return 0;
}


Measured memory_bytes: 3220
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define fi first
#define se second
#define pb push_back
 
#define ll long long
#define pii pair<int, int>
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll tot = 0;
    int n; cin >> n;
    vector<int> p;
    rep(i, n) {
        ll k; cin >> k;
        p.pb(k);
    }
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    deque<pii> sl;
    sl.push_front({p[0], 1});
    iter(i, 1, n) {
        if(p[i] == sl.back().fi) sl.back().se += 2;
        else sl.push_back({p[i], 2});
        sl.front().se--;
        tot += sl.front().fi;
        if(!sl.front().se) sl.pop_front();
    }
    cout << tot << endl;
}



Measured memory_bytes: 4784
/*input
20 1
19
*/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define trace1(x) cout<<#x<<": "<<x<<endl
#define trace2(x, y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cout<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
 
//typedef long long ll;
#define int long long
#define ll long long

 
#define PI 3.141592653589793
#define MOD 1000000007
#define INF 1e15
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; a=a%m; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
/*prime m*/ template<typename T> T modInv(T a, T m){return pow(a,m-2,m);} 

#define MAX 505 
int32_t main() {
	IOS
	int k, n; cin>>k>>n; 
	//k is perimeter
	//n is number of houses
	vector<int> a; for(int i = 0; i<n; i++){int x; cin>>x; a.push_back(x);}

	int maxD = 0; 
	for(int i = 0; i<n-1; i++){
		maxD = max(maxD, abs(a[(i+1)%n] - a[i]));
	}
	maxD = max(maxD, abs(a[0]+k - a[n-1]));

	//trace1(maxD);
	cout<<k - maxD<<endl; 


 
return 0;
}
 


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

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

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int K;
    cin >> K;
    int even = K / 2;
    int odd = (K + 1) / 2;
    PRINT(even * odd);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long A[100001];
long long max1(long long a,long long b){
	return a>b?a:b;
}
int main(){
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;++i)
		scanf("%lld",A+i);
	sort(A+1,A+N+1);
	long long sum1=0,sum2=0;
	if(N&1){
		for(int i=1;i<N/2;++i)
			sum1-=A[i];
		for(int i=1;i<=(N/2+1);++i)
			sum1-=A[i];
		for(int i=(N/2+2);i<=N;++i)
			sum1+= 2*A[i];
			
		for(int i=1;i<=N/2;++i)
			sum2-= 2*A[i];
		for(int i=(N/2+1);i<=N;++i)
			sum2+=A[i];
		for(int i=(N/2+3);i<=N;++i)
			sum2+=A[i];
		printf("%lld\n",max1(sum1,sum2));
	}else{
		for(int i=1;i<N/2;++i)
			sum1-=A[i];
		for(int i=1;i<=N/2;++i)
			sum1-=A[i];
		for(int i=(N/2+1);i<=N;++i)
			sum1+=A[i];
		for(int i=(N/2+2);i<=N;++i)
			sum1+=A[i];
		printf("%lld\n",sum1);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<queue>
#include<stack>
	

int main(){
	int n;
	int ans=0;
	std::vector<int> aList;

	std::cin>>n;

	aList.resize(n);
	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	std::sort(aList.begin(), aList.end(), [](int x, int y){return x>y;});

	ans+= aList[0]/2;
	for(int i=1; i<aList.size(); i++)
		ans+=aList[i]; 


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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
    int n;
    cin>>n;
    int a[1000000];
    REP(i,n){
        cin>>a[i];
    }
    int ans[1000000];
    REP(i,n+1){
        ans[i]=0;
    }
    for (int i = 0; i <n; i++)
    {
        /* code */
        int t=a[i];
        ans[t]++;
    }
    for (int i = 1; i < n+1; i++)
    {
        /* code */
        cout<<ans[i]<<endl;
    }
    
}



Measured memory_bytes: 5176
#include <stdio.h>

int calcGCD(int a, int b) {
  int r = a % b;
  while (r) { a = b; b = r; r = a % b; }
  return b;
}

int main() {
  int a, b, g;
  scanf("%d %d", &a, &b);
  if (a < b) { g = calcGCD(b, a); } else { g = calcGCD(a, b); }
  printf("%ld\n", (long)a * b / g);
}



Measured memory_bytes: 128
main :: IO ()
main = do
  s' <- getLine
  t <- getLine
  putStrLn $ solve s' t

solve :: String -> String -> String
solve s' t = let ans = filter (isConvertible s') $ candidates s' t
             in if null ans
                then "UNRESTORABLE"
                else toAns . last $ ans


toAns [] = []
toAns (s:ss)
  | s == '?' = 'a':toAns ss
  | otherwise = s:toAns ss

isConvertible :: String -> String -> Bool
isConvertible s candidate = all (\(x,y) -> x == y || x == '?') $ zip s candidate

candidates :: String -> String -> [String]
candidates s' t = encode s' t 0
encode :: String -> String -> Int -> [String]
encode s' t i
  | slength < tlength + i = []
  | otherwise = (top ++ t ++ bottom):encode s' t (i+1)
  where
    slength = length s'
    tlength = length t
    (top, middle) = splitAt i s'
    (_, bottom) = splitAt tlength middle


Measured memory_bytes: 892
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;

int main()
{
    int mcount,count;
    mcount = 0;
    count = 0;
    string mojiretsu;
    cin >> mojiretsu;
    for (int i=0; i < mojiretsu.size() ; i++){
        if (mojiretsu[i] == 'A' ||mojiretsu[i] == 'C' ||mojiretsu[i] == 'G' ||mojiretsu[i] == 'T' ){
            count ++;
            if (count > mcount){mcount = count;}
        }else{
            count = 0;
        }
    }
    cout << mcount;
    
}

Measured memory_bytes: 256
#abc173d.py
#これって大きい順に並び替えて、最大の人と２ばン目の人の間に入ればいいだけなのではないのか？

N=int(input())
Alist=list(map(int,input().split()))
Alist.sort(reverse=True)
kokochiyosa=Alist[0]
for i in range(1,N-1):
    kokochiyosa+=Alist[(i+1)//2]

print(kokochiyosa)



Measured memory_bytes: 94176
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  lint n, x; cin >> n >> x;
  V<lint> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  lint s = accumulate(a.begin(), a.end(), 0LL);
  if (x == s) return cout << n << '\n', 0;
  if (x > s) return cout << n - 1 << '\n', 0;
  sort(a.begin(), a.end());
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (x >= a[i]) {
      x -= a[i];
      res++;
    }
    else break;
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
from itertools import permutations
n = int(input())
s = sorted([int(input()) for _ in range(n)])
ans = sum(s)
if ans % 10:
    print(ans)
else:
    m = ans
    for i in range(n):
        if s[i] % 10:
            m = s[i]
            break
    print(ans - m)


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

int main()
{
  int n,ans=1;
  cin >> n;
  vector<string> S(n);
  for(string &e:S)cin >> e;
  sort(S.begin(),S.end());
  for(int i=1;i<n;i++){
    if(S[i-1]!=S[i])ans++;
  }
  cout << ans << endl;
      return 0;
}


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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	int ans=1;
	while(ans<=n){
		ans*=2;
	}
	cout<<ans/2<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<iomanip>
#include<numeric>
using namespace std;
typedef long long ll;

int main(){
    int n, m, k;
    while(cin >> n >> m >> k, n+m+k){
        vector<vector<double>> v(2, vector<double>(n*m+1, 0));
        for(int j = 0; j <= n*m; j++)   v[1][j] = 1.0;
        for(int i = 0; i < n; i++){
            v[i%2][0] = 0;
            for(int j = 1; j <= n*m; j++){
                v[i%2][j] = (v[(i+1)%2][j-1]-(j-1-m >= 0 ? v[(i+1)%2][j-1-m] : 0))/m;
                v[i%2][j] += v[i%2][j-1];
            }
        }
        double ans = 0;
        for(int j = 1; j <= n*m; j++)   ans += (v[(n+1)%2][j]-v[(n+1)%2][j-1]) * max(j-k, 1);
        cout << fixed << setprecision(12) << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define per(i,a,n) for(int i=(a);i>=(n);--i)
#define pb push_back
using namespace std;
const int N=5e5+10;
typedef long long ll;
int n,q,op,l,r,x,y,tr[26][N];
char s[N],t[3];
void add(int *tr,int x,int v){
	for(int i=x;i<=n;i+=i&-i){
		tr[i]+=v;
	}
}
int ask(int *tr,int x){
	int ans=0;
	for(int i=x;i;i-=i&-i){
		ans+=tr[i];
	}
	return ans;
}
bool cal(int *tr,int l,int r){
	if(l>r)return 0;
	return (ask(tr,r)-ask(tr,l-1))>=1;
}
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	rep(i,1,n){
		x=s[i]-'a';
		add(tr[x],i,1);
	}
	scanf("%d",&q);
	rep(i,1,q){
		scanf("%d",&op);
		if(op==1){
			scanf("%d%s",&l,t);
			x=s[l]-'a';y=t[0]-'a';
			add(tr[x],l,-1);add(tr[y],l,1);
			s[l]=t[0];
		}
		else{
			scanf("%d%d",&l,&r);
			int res=0;
			rep(j,0,25){
				res+=cal(tr[j],l,r);
			}
			printf("%d\n",res);
		}
	}
	return 0;
}

Measured memory_bytes: 51584
N = int(input())
n_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(n_list[N-1])

Measured memory_bytes: 38384
import sys
input = sys.stdin.readline
from collections import *
from math import gcd

N = int(input())
cnt = defaultdict(int)
abzero = 0
azero = 0
bzero = 0

for _ in range(N):
    A, B = map(int, input().split())
    
    if A==0 and B==0:
        abzero += 1
        continue
    elif A==0:
        azero += 1
        continue
    elif B==0:
        bzero += 1
        continue
        
    G = gcd(abs(A), abs(B))
    A //= G
    B //= G
    
    if (A<0 and B>0) or (A<0 and B<0):
        A *= -1
        B *= -1
    
    cnt[(A, B)] += 1

ans = 1
MOD = 10**9+7
visited = set()

for k in cnt.keys():
    if k in visited:
        continue
    
    if k[0]>0 and k[1]>0:
        k2 = (k[1], -k[0])
    else:
        k2 = (-k[1], k[0])
    
    if k2 not in cnt:
        ans *= pow(2, cnt[k], MOD)
    else:
        ans *= pow(2, cnt[k], MOD)+pow(2, cnt[k2], MOD)-1
        visited.add(k2)

ans *= pow(2, azero, MOD)+pow(2, bzero, MOD)-1
ans %= MOD
ans += abzero-1
ans %= MOD
print(ans)


Measured memory_bytes: 115640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 2;
constexpr ll B_I_MAX = 1000000000;

ll N;
vector<pair<ll,ll>> a,b;

void input() {
	scanf("%lld", &N);
	a.assign(N,pair<ll,ll>());
	rep(i, N) cin>>a[i].first>>a[i].second;
}

void solve() {
	sort(a.begin(), a.end(), [](const pair<ll,ll> &x, const pair<ll,ll> &y) {
		return x.second < y.second;
	});

	ll t=0;
	rep(i,N){
		t+=a[i].first;
		if(t>a[i].second){
			p("No");
			return;
		}
	}

	p("Yes");


}

signed main() {
	input();
	solve();
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18;
const int iINF = 1e9;
int main(){
    string s,t;
    vector<string> ans;
    cin>>s>>t;
    rrep(i,s.size()){
        int st = i-t.size()+1;
        if(st<0){
            break;
        }
        string h = s.substr(st,t.size());
        rep(j,s.size()){
            if(!(t[j] == h[j] || h[j] == '?'))break;

            if(j == t.size()-1){
                rep(k,s.size())if(s[k] == '?')s[k] = 'a';
                ans.push_back(s.substr(0,st)+t+s.substr(st+t.size(),s.size()-st-t.size()));
            }
        }
    }
    if(ans.size() == 0)cout<<"UNRESTORABLE"<<endl;
    else{
        sort(ans.begin(),ans.end());
        cout<<ans[0]<<endl;
    }
}




Measured memory_bytes: 256
"use strict"
function main(arg) {
    let str = arg.trim().split("\n")[0].split("").reverse()[0]
    let list = {
        '0' : 'pon',
        '1' : 'pon',
        '2' : 'hon',
        '3' : 'bon',
        '4' : 'hon',
        '5' : 'hon',
        '6' : 'pon',
        '7' : 'hon',
        '8' : 'pon',
        '9' : 'hon',
    }
    console.log(list[str])
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int k;
	cin>>k;
	queue<string>q;
	for(string i="1"s;i<="9"s;++i.front())q.push(i);
	string s;
	for(int i=1;i<=k;++i){
		s=q.front();
		q.pop();
		if(s.back()!='0'){
			char c=s.back()-1;
			q.push(s+c);
		}
		q.push(s+s.back());
		if(s.back()!='9'){
			char c=s.back()+1;
			q.push(s+c);
		}
	}
	cout<<s<<"\n"s;
}

Measured memory_bytes: 13824
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n = s.trim().parse::<i64>().unwrap();
    let mut v: Vec<i64> = Vec::new();
    for x in 1..(n as f64).sqrt() as i64 + 1 {
        let y = n / x;
        if x * y == n {
            v.push(x + y - 2);
        }
    }
    v.sort();
    println!("{}", v[0]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector

int main(void)
{
    int n;
    int dp[10];
    rep(i, 10) dp[i] = 0;

    rep(i, 4) {
        cin >> n;
        dp[n]++;
    }
    if (dp[1] * dp[9] * dp[7] * dp[4] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 200005
vector<int> v[N];
int fa[N],du[N],sg[N];
int n;
void calc(int u){
	sort(v[u].begin(),v[u].end());
	sg[u]=0;
	for(int i:v[u]) i==sg[u]? sg[u]++:0;
}
void tp(int u){
	calc(u);
	du[fa[u]]--;du[u]=-1;
	v[fa[u]].push_back(sg[u]);
	if(du[fa[u]]==0) tp(fa[u]);
}
vector<int> temp;
void DFS(int u,int top){
	temp.push_back(sg[u]);du[u]=-1; 
	if(fa[u]!=top) DFS(fa[u],top);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&fa[i]),du[fa[i]]++;
	for(int i=1;i<=n;i++)
		if(du[i]==0) tp(i);
	for(int i=1;i<=n;i++)
		if(du[i]==1) calc(i);
	for(int i=1;i<=n;i++)
		if(du[i]==1){
			DFS(i,i);
			sort(temp.begin(),temp.end());
			if(temp[0]==temp[temp.size()-1]&&temp.size()%2==1)
				return puts("IMPOSSIBLE"),0;
			temp.clear();
		}
	return puts("POSSIBLE"),0;
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
static const int N=1000;
int lcs(string X,string Y){
    int c[N+1][N+1];
    int m=X.size();
    int n=Y.size();
    int maxl=0;
    for(int i=0;i<n+1;i++) c[0][i]=0;
    for(int i=0;i<m+1;i++) c[i][0]=0;
    for(int i=1;i<m+1;i++){
        for(int j=1;j<n+1;j++){
            if(X[i-1]==Y[j-1]) c[i][j]=c[i-1][j-1]+1;
            else c[i][j]=max(c[i][j-1],c[i-1][j]);
            maxl=max(maxl,c[i][j]);
        }
    }
    return maxl;
}
int main(void){
    int q;
    string X,Y;
    cin >> q;
    for(int i=0;i<q;i++){
        cin >> X >> Y;
        cout << lcs(X,Y) << endl;
    }
}



Measured memory_bytes: 7080
A,B = map(int, input().split())

cnt=0
for i in range(A,B+1,1):
    i = str(i)
    len_i = len(i)
    tmp=0
    for j in range(len_i//2):
        if i[j]==i[-j-1]:
            tmp+=1
        else:
            break
    if tmp==len_i//2:
        cnt+=1
print(cnt)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,k,s,i;
  string ans="Yes";
  cin>>n;
  k=(1<<n);
  multiset<int> ms1,ms2,ms3;
  for(i=0;i<k;i++){
    cin>>s;
    ms1.insert(s);
  }
  ms2.insert((-1)*(*prev(ms1.end(),1)));
  ms1.erase(prev(ms1.end(),1));
  for(i=0;i<n;i++){
    ms3.clear();
    for(auto j:ms2){
      auto lb=ms1.lower_bound(-j);
      if(ms1.begin()==lb){
        ans="No";
        break;
      }
      else{
        ms3.insert((-1)*(*prev(lb,1)));
        ms1.erase(prev(lb,1));
      }
    }
    if(ans=="No") break;
    else for(auto j:ms3) ms2.insert(j);
  }
  cout<<ans<<endl;
}

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



int main()
{
ll n,r=0,g=0,b=0;
cin>>n;

cin>>s;

ll ans=0;
for(ll i=0;i<n;i++)
{
	if(s[i]=='R')r++;
	if(s[i]=='G')g++;
	if(s[i]=='B')b++;
	
	
}
ans=r*g*b;
for(ll i=0;i<n;i++)
{
	for(ll j=0;j<n;j++)
	{
		ll k;
		k=2*j-i;
		if(s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i]&&i<j&&j<k&&k<n)ans--;
	}
}
cout<<ans;


}



Measured memory_bytes: 3644
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<cstring>
#include<sstream>
#include<cassert>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()

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

const int MAX_N = 1e5;

int main()
{
    int n;
    static int a[MAX_N];
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    
    int ans = 0, count = 0;
    
    while (true) {
        if (a[count] == a[count+1]) {
            ++count;
            if (count == n-1) {
                ++ans; goto LOOP_OUT;
            }
        }
        if (a[count] > a[count+1]) {
            ++ans;
            if (count == n-1) goto LOOP_OUT;
            while (a[count] >= a[count+1]) {
                ++count;
                if (count == n-1) goto LOOP_OUT;
            }
            ++count;
        }
        if (a[count] == a[count+1]) {
            ++count;
            if (count == n-1) {
                ++ans;
                goto LOOP_OUT;
            }
        }
        if (a[count] < a[count+1]) {
            ++ans;
            if (count == n-1) goto LOOP_OUT;
            while (a[count] <= a[count+1]) {
                ++count;
                if (count == n-1) goto LOOP_OUT;
            }
            ++count;
        }
    }
LOOP_OUT:
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
if __name__ == '__main__':
    N, X = map(int, input().split())
    L_list = list(map(int, input().split()))


    answer = 0
    for i in range(1, N+2):
       if i == 1:
           D = 0
       else:
           D = D + L_list[i-2]

       if D <= X:
            answer += 1

    print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e7+5;
ll f[N],n,ans;
int main(){
   for(int i=1;i<N;i++) for(int j=i;j<N;j+=i) f[j]++;
   cin>>n; for(int i=1;i<=n;i++) ans+=f[i]*i; cout<<ans;
}

Measured memory_bytes: 81756
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		if( S.equals("ABC") ){
			System.out.println("ARC");
		}else{
			System.out.println("ABC");
		}
	}
}

Measured memory_bytes: 35664
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	string s;
	cin >> s;
	int n = s.length(), i, j, k, a = 0, b = n - 1, ans = 0;
	bool valid = true;
	while (a < b) {
		if (s[a] == s[b]) a++, b--;
		else {
			if (s[a] == 'x') ans++, a++;
			else if (s[b] == 'x') ans++, b--;
			else {
				valid = false;
				break;
			}
		}
	}

	if (!valid) ans = -1;
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 760
N = int(input())
B = [int(x) for x in input().split()]

ans = [0] * N

ans[0] = B[0]
for i in range(N - 1):
    if ans[i] > B[i]:
        ans[i] = B[i]
    ans[i + 1] = B[i]

print(sum(ans))


Measured memory_bytes: 3060
import sys

while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break;
    x = {}
    for i in range(n):
        k,v = sys.stdin.readline().rstrip().split()
        x[k] = v
    n = int(sys.stdin.readline().rstrip())
    y = []
    for i in range(n):
        a = sys.stdin.readline().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

Measured memory_bytes: 8632
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MAXN = 5000 + 15;

ll p[MAXN], c[MAXN];
vector <ll> v;
int main() {

    ll n, k;
    scanf("%lld %lld", &n, &k);

    for(int i = 1; i <= n; i++) scanf("%lld", &p[i]);
    for(int i = 1; i <= n; i++) scanf("%lld", &c[i]);

    ll res = -1e18;
    for(int i = 1; i <= n; i++) {
        v.clear();
        ll sum = c[i];
        v.push_back(sum);

        int j = p[i];
        while(j != i) {
            sum += c[j];
            v.push_back(sum);
            j = p[j];
        }

        int len = (int)v.size();
        for(j = 0; j < len; j++) {
            ll rest = k - 1 - j;
            if(rest < 0) break;
            res = max(res, v[j] + (rest / len) * max(sum, 0ll));
        }
    }

    printf("%lld\n", res);

    return 0;
}

Measured memory_bytes: 4004
//organize and stay in moment - Abhinav IIIT-A
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,x,n) for(int i=x;i<n;++i)
#define ar array
#define MAXN (int)2e5+5
#define pb push_back
int mod= 998244353;
int arr[MAXN];
int as;
void input(){
  cin>>as;
  f(i,0,as) cin>>arr[i];
}
void q1(){
  string s; cin>>s;
  int a=0,b=0;
  f(i,0,3)
  s[i]=='A'  ? ++a : ++b;
  if(a&&b)
    cout<<"Yes";
  else cout<<"No";
}
void q2(){
  int n,a,b;
  cin>>n>>a>>b;
  int t=a+b;
  int q=n/t;
  int ans=q*a;
  int r=n%t;
  ans+=min(r,a);
  cout<<ans;
}
void q3(){
  int a,b; cin>>a>>b;
  for(int i=1;i<=100000;++i){
    int x=i*8; x/=100;
    int y=i*10; y/=100;
    if(x==a && y==b){
      cout<<i;
      return ;
    }
  }
  cout<<-1;
}
void q4(){
  string s; cin>>s;
  deque<int> q;
  f(i,0,s.size())
  q.push_back(s[i]);
  int Q; cin>>Q;
  int curr=0; 
  //wtf....
  while(Q--){
    int t;
    cin>>t;
    if(t==1){
      curr=1-curr;
    }else{
      int f;char c; cin>>f>>c;
      if(curr==0 && f==1)
        q.push_front(c);
      else if(curr==0 && f==2)
        q.push_back(c);
      else if(curr==1 && f==1)
        q.push_back(c);
      else q.push_front(c);
    }
    //cout<<curr<<" ";
    
  }
  string ret="";
  while(!q.empty()){
    ret+=q.front();
    q.pop_front();
  }
//  cout<<curr<<" ";
  if(curr)
     reverse(ret.begin(),ret.end());
   cout<<ret;
   return ;
}
void q5(){
  int n,p; cin>>n>>p;
  string s; cin>>s;
  int ans=0;
  if(p==2 || p==5){
    f(i,0,n)
    if((s[i]-'0')%p==0)
      ans+=i+1;
  }else {
    int tt=1;
    int curr=0;
     map<int,int> mp;
     mp[0]++;
     for(int i=n-1;i>=0;--i){
        curr+=(s[i]-'0')*tt;
        tt*=10;
        tt%=p; curr%=p;
        ans+=mp[curr];
        ++mp[curr];
     }
  }
  cout<<ans;
}
int mod2=998244353;
void solve(){
 
}
int32_t main()
{
  int t; t=1; //cin>>t;
  while(t--) q5();
  return 0;
}


Measured memory_bytes: 1028
#include<stdio.h>

int main()
{

	int a,b,c,d,e;
	scanf("%d%d",&a,&b);
	c=(a*2)-1;
	d=(b*2)-1;
	if(c>d){
		printf("%d",c);
	}
	else if(d>c){
		printf("%d",d);
	}
	else {
		printf("%d",a+b);
	}



	return 0;
}

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

using namespace std;
int main(){
  int n;
  std::cin >> n;

  int ans=0;
  int m=1000;
  rep(i,n){
    int now;
    std::cin >> now;
    ans+=now;
    if(now%10!=0 && m>now)m=now;
  }

  if(ans%10==0 && m!=1000)std::cout << ans-m << '\n';
  else if(ans%10 !=0)std::cout << ans << '\n';
  else std::cout << 0 << '\n';



  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct Node{
	int key;
	struct Node *r,*l,*p;
}Node;

struct Node *root , *NIL;

void insert( int k ){
	struct Node *y = NIL;
	struct Node *x = root;
	struct Node *z;
	
	z = ( struct Node *)malloc( sizeof(struct Node) );
	z->key = k;
	z->l = NIL;
	z->r = NIL;
	
	while( x != NIL ){
		y = x;
		if( z->key < x->key ){
			x = x->l;
		}else{
			x = x->r;
		}
	}
	z->p = y;
	
	if( y == NIL ){
		root = z;
	}else{
		if( z->key < y->key ){
			y->l = z;
		}else{
			y->r = z;
		}
	}
}

void preorder( struct Node *u ){
	
	if( u == NIL ){
		return;
	}
	printf( " %d" , u->key );
	preorder( u->l );
	preorder( u->r );
}

void inorder( struct Node *u ){
	
	if( u == NIL ){
		return;
	}
	inorder( u->l );
	printf( " %d" , u->key );
	inorder( u->r );
}

int main( void ){
	
	int n , i , x;
	char com[10];
	
	scanf( "%d" , &n );
	
	for( i = 0; i < n; i++ ){
		
		scanf( "%s" , com );
		if( strcmp(com ,"insert") == 0 ){
			scanf( "%d" , &x );
			insert(x);
		}else if( strcmp(com ,"print") == 0 ){
			inorder(root);
			printf( "\n" );
			preorder(root);
			printf( "\n" );
		}
	}
	
	return 0;
}
		


Measured memory_bytes: 25168
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<stw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;

int main(void){
    int N;cin>>N;
    vector<int> X(N);
    for(int i=0;i<N;i++){
        cin >> X[i];
    }
    int ans = 100000000,count;
    for(int P=0;P<100;P++){
        count = 0;
        for(int i=0;i<N;i++){
            count += pow(X[i]-P,2);
        }
        if(ans>=count){
            ans = count;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
require 'rexml/document'

class REXML::Element
    def check(x, y)
        init if !@initialized
        return nil if x < @x1 || @x2 < x || y < @y1 || @y2 < y
        children = elements
        puts "#{name} #{children.size}" if !children.any? {|c| c.check(x, y)}
        return true
    end

    def init
        @x1, @y1, @x2, @y2 = text.split(?,).map(&:to_i)
        @initialized = true
    end
end

loop do
    n = gets.to_i
    break if n == 0
    xml = REXML::Document.new(gets.chomp)
    main_panel = xml.elements['/main']

    n.times do
        x, y = gets.split.map(&:to_i)
        puts "OUT OF MAIN PANEL 1" if !main_panel.check(x, y)
    end
end

Measured memory_bytes: 10740
N, L = map(int, input().split())
aji=[]
for i in range(N):
    aji.append(L+i)


if 0 in aji:
    ans=sum(aji)
else:
    if aji[0]>0:
        del aji[0]
    else:
        del aji[-1]
    ans=sum(aji)
print(ans)

Measured memory_bytes: 38256