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

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();
		int result,x,result2,y;
		int mov = 0;
		int ikisaki[][] = new int[n][2];
		for(int i = 0; i < n; i++){
			for(int k = 0; k < 2; k++){
				ikisaki[i][k] = sc.nextInt();
			}
		}
		for(int i = 1; i < n; i++){
			result = ikisaki[i][0] - ikisaki[i-1][0];
			x = Math.abs(result);
			result2 = ikisaki[i][1] - ikisaki[i-1][1];
			y = Math.abs(result2);
			mov = mov + x + y;
			if(result > 0 && result2 > 0 || result < 0 && result2 < 0){
				if(x <= y){
					mov = mov - x;
				}else{
					mov = mov - y;
				}
			}
		}
		System.out.println(mov);
	}
}

Measured memory_bytes: 25488
//
//  main.swift
//  AtCoder
//
//  Created by s on 2018/05/06.
//  Copyright © 2018年 s. All rights reserved.
//  created by Xcode 7.3.1

#if os(Linux)
    import Glibc
#else
    import Darwin
#endif


extension String: CollectionType {}


//var N: Int = Int(readLine()!)!
var a: [Int] = readLine()!.split(" ").map { Int($0)! }

if a[0] > a[1] {
    print(a[0]-1)
}else{
    print(a[0])
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back

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

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

pair<P,int> t[50];
int wrong[50][50];

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


    int a,b,c;
    while(cin>>a>>b>>c,a)
    {
        REP(i,a){
            t[i]=make_pair(P(0,0),i);
            REP(j,b) wrong[i][j]=0;
        }
        REP(i,c){
            int tID,pID,time;
            string s;
            cin>>tID>>pID>>time>>s;
            tID--,pID--;
            if(s[0]=='W'){
                wrong[tID][pID]++;
            }else{
                t[tID].first.first--;
                t[tID].first.second+=1200*wrong[tID][pID]+time;
            }
        }
        sort(t,t+a);
        REP(i,a) cout<<t[i].second+1<<" "<<-t[i].first.first<<" "<<t[i].first.second<<endl;
    }

}



Measured memory_bytes: 3240
x1, y1, x2, y2 = map(int, input().split())
x3 = x2 + (y1 - y2)
y3 = y2 - (x1 - x2)
x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)
ans = (x3, y3, x4, y4)
print(*ans, sep=' ')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,a,b;
  cin>>n>>a>>b;
  if(n*a<b)
  cout<<n*a;
  else
    cout<<b;
}

Measured memory_bytes: 256
H, W = list(map(int, input().split()))

a = [list(input()) for i in range(H)]

for i in reversed(range(len(a))):
  if '#' not in a[i]:
    del a[i]

a = list(zip(*a))
for i in reversed(range(len(a))):
  if '#' not in a[i]:
    del a[i]

a = list(zip(*a))
         
for i in a:
  print(''.join(i))

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

int main(){
int n,d,x;
cin>>n>>d>>x;
int cnt=0;
for(int i=0;i<n;i++){
int a;cin>>a;
int b=1;
while(b<=d){
cnt++;
b+=a;
}
}
cout<<x+cnt<<endl;
return 0;
}

Measured memory_bytes: 256
#include <cstdio>

void print_array(int* a, int n) {
    printf("%d", a[0]);
    for (int i=1; i<n; i++) { printf(" %d", a[i]); }
    printf("\n");
}

int swap(int* a, int* b) {
    if (a == b or *a == *b) { return 1; }
    int tmp = *a;
    *a = *b;
    *b = tmp;
    return 0;
}

int selectionSort(int* a, int n) {
    int count = 0;
    for (int i = 0; i < n; i++) {
        int min_j = i;
        for (int j = i; j < n; j++) {
            if (a[j] < a[min_j]) {
                min_j = j;
            }
        }
        if (swap(&a[i], &a[min_j]) == 0) {
            count++;
        }
    }
    return count;
}

int main() {
    int n;
    scanf("%d", &n);

    int* a = new int[n];
    scanf("%d", &a[0]);
    for (int i=1; i<n; i++) { scanf(" %d", &a[i]); }

    int count = selectionSort(a, n);
    print_array(a, n);
    printf("%d\n", count);

    return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back

int main()
{
    int n;
    scanf("%i",&n);
    int lim=1e5;
    for(int i=2;i<lim;i++)
    {
        if(i*(i-1)/2==n)
        {
            printf("Yes\n");
            vector<set<int> > sets(i);
            int tr=1;
            for(int l=0;l<i;l++)
            {
                for(int r=l+1;r<i;r++)
                {
                    sets[l].insert(tr);
                    sets[r].insert(tr);
                    tr++;
                }
            }
            printf("%i\n",i);
            for(int l=0;l<i;l++)
            {
                printf("%i ",sets[l].size());
                for(auto p:sets[l])
                {
                    printf("%i ",p);
                }
                printf("\n");
            }
            return 0;
        }
        if(i*(i-1)/2>n)
        {
            printf("No\n");
            return 0;
        }
    }
    return 0;
}


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

int main() {
	string c;
	cin >> c;
	
	if (c =="a" || c =="i" || c =="u" ||c =="e" ||c =="o"){
		cout << "vowel"<< endl;
	}
	
	else 
		cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
 
#define ll long long
 
#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));
 
int main(){
	ll N,count1 = 0,sum = 0,min = 99999999999;
  cin >> N;
  vec(a,ll,N,0);
  froop1(0,N){
   cin >> a.at(i); 
    if(a.at(i) < 0){
      count1++;
    }
    sum += abs(a.at(i));
    if(abs(a.at(i)) < min){
      min = abs(a.at(i));
    }
  }
  if(count1 % 2 == 0){
    cout << sum << endl;
  }else{
    cout << sum - 2*min << endl;
  }
}

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

int main() {
	// your code goes here
	long long int a, b, k;
	cin >> a >> b >> k;
	if(a == b)
    {
        //cout << "0 0\n";
        //return 0;
    }

    long long c = min(a, k);
    a -= c;
    k -= c;
    b -= min(b, k);

    cout << a << ' ' << b;
	return 0;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FIntervalsOnTree solver = new FIntervalsOnTree();
        solver.solve(1, in, out);
        out.close();
    }

    static class FIntervalsOnTree {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            long answer = 0;

            for (int i = 0; i < n - 1; i++) {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                if (u > v) {
                    int t = u;
                    u = v;
                    v = t;
                }

                answer -= (long) (u - 0 + 1) * (n - 1 - v + 1);
            }
            for (int i = 1; i <= n; i++) {
                answer += (long) i * (n + 1 - i);
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 46240
N,K = map(int,input().split())
S = input()

X = [] #直立 0
Y = [0] #逆立ち 1

prev = '1'
for c in S:
    if c == '1':
        if prev == '0':
            Y.append(1)
        else:
            Y[-1] += 1
    else: #c == '0'
        if prev == '1':
            X.append(1)
        else:
            X[-1] += 1
    prev = c
Y.append(0)

tmp = sum(X[0:K]) + sum(Y[0:K+1])
ans = tmp
for i in range(0,len(X)-K):
    tmp += X[i+K] - X[i] + Y[i+K+1] - Y[i]
    ans = max(tmp,ans)

print(ans)

Measured memory_bytes: 4456
import heapq


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


N, M = inpl()
AB = [inpl() for i in range(N)]

job = {i: [] for i in range(1, M + 1)}
q = []
heapq.heapify(q)
ans = 0

for a, b in AB:
    if a > M:
        continue
    job[a].append(b)

for i in range(1, M + 1):
    for b in job[i]:
        heapq.heappush(q, -b)

    if len(q) != 0:
        ans -= heapq.heappop(q)

print(ans)


Measured memory_bytes: 48272
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
struct P {
    int x, y, i;
};

int dist(P c, P d){
    return min(abs(c.x - d.x), abs(c.y - d.y));
}

struct edge {
    int from, to;
    ll cost;
};

ll prim(vector<vector<edge>> &edges, int V) {
    using Pi = pair<ll, int>;

    ll res = 0;
    vector<bool> used(V, false);
    priority_queue<Pi, vector<Pi>, greater<>> priorityQueue;
    priorityQueue.emplace(0, 0);
    while (!priorityQueue.empty()) {
        Pi p = priorityQueue.top();
        priorityQueue.pop();
        if (used[p.second]) continue;
        used[p.second] = true;
        res += p.first;
        for (edge &e : edges[p.second]) {
            if (!used[e.to]) priorityQueue.push({e.cost, e.to});
        }
    }
    return res;
}

int main(){
    int n; cin >> n;
    vector<P> a(n), b(n);
    rep(i, n){
        cin >> a[i].x >> a[i].y;
        a[i].i = i;
        b[i] = a[i];
    }

    sort(ALL(a), [](const P &s, const P &t){
        return s.x < t.x;
    });
    sort(ALL(b), [](const P &s, const P &t){
        return s.y < t.y;
    });

    // rep(i, n){
    //     cout << "(" << a[i].x << ", " << a[i].y << ") " << a[i].i << endl; 
    // }
    // pr("");
    // rep(i, n){
    //     cout << "(" << b[i].x << ", " << b[i].y << ")" << b[i].i << endl; 
    // }

    vector<vector<edge>> edges(n);
    rep(i, n-1){
        P c, d;
        c = a[i];
        d = a[i+1];
        edges[c.i].push_back({c.i, d.i, dist(c, d)});
        edges[d.i].push_back({d.i, c.i, dist(c, d)});
        // printf("%d %d\n", c.i, d.i;
        c = b[i];
        d = b[i+1];
        edges[c.i].push_back({c.i, d.i, dist(c, d)});
        edges[d.i].push_back({d.i, c.i, dist(c, d)});
    }

    rep(i, n){
        // cout << i << ": ";
        rep(j, edges[i].size()){
            edge e = edges[i][j];
            // printf("%d ", e.to);
        }
        // pr("");
    }

    ll ans = prim(edges, n);

    pr(ans);
    return 0;
}

Measured memory_bytes: 18572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

        vector<vector<int>> ok(n,vector<int>(n));
        rep(i,n-1) ok[i][i+1] = (abs(w[i]-w[i+1]) <= 1);

        for(int b=4; b<=n; b+=2){
            for(int l=0; l+b-1<n; ++l){
                int r = l+b-1;
                for(int i=l+1; i<r; ++i) ok[l][r] |= (ok[l][i] & ok[i+1][r]);
                ok[l][r] |= ((abs(w[l]-w[r])<=1) & ok[l+1][r-1]);
            }
        }

        vector<int> dp(n+1,-n);
        dp[0] = 0;
        rep(i,n){
            for(int j=i; j<n; ++j){
                if(ok[i][j]) dp[j+1] = max(dp[j+1], dp[i]+(j-i+1));
            }
            dp[i+1] = max(dp[i+1],dp[i]);
        }
        cout << dp[n] << endl;
    }
    return 0;
}



Measured memory_bytes: 3236
#include <stdio.h>

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  long max;
  long remainder;
  for (max = m/n; max >= 1; max--) {
    remainder = m-n*max;
    if (remainder%max == 0) {
      printf("%ld\n", max);
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
#define MAX_N 999999
bool notPrime[MAX_N+2];
int main()
{
    map<int,int> count;
    for (int i = 2 ; i <= MAX_N ; i++)
    {
        if (!notPrime[i])
        {
            for (int g = i+i ; g <= MAX_N ; g += i)
            {
                notPrime[g] = true;
            }
        }
    }
    int cnt = 0;
    count[1] = 0;
    for (int g = 2 ; g <= MAX_N ; g++)
    {
        if (!notPrime[g])
            cnt ++;
        count[g] = cnt;
    }
    for(int n;cin>>n;n++){
        cout<<count[n]<<endl;
    }
    return 0;
}

Measured memory_bytes: 49048
from itertools import combinations

N, M, X = map(int, input().split())

L = []
for _ in range(N):
    L.append(list(map(int, input().split())))

s = float('inf')
r = False

for i in range(1, N + 1):
    C = combinations(range(0, N), i)
    for c in C:
        _s = 0
        t = [0 for _ in range(M)]
        for _c in c:
            _s += L[_c][0]
            for k in range(M):
                t[k] += L[_c][k + 1]
        _r = True
        for _t in t:
            if _t < X:
                _r = False
                break
        if _r and _s < s:
            r = True
            s = _s
if r:
    print(s)
else:
    print(-1)


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

int main() {
 int N;
 cin >> N;
 int X;
 cin >> X;
 int L;
 L = 0;
 int M;
 int K;
 K = 0;
 for (int i = 0; i < N; i++) {
   cin >> M;
   L =  L + M;
   if ( L <= X ) {
     K = K + 1;
     }
   }
 K = K + 1;
 cout << K << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    vector<int> csa(n + 1);
    csa[0] = 0;
    for (int i = 0; i < n; i++) csa[i + 1] = csa[i] + a[i];
    vector<int> csb(n + 1);
    csb[0] = 0;
    for (int i = 0; i < n; i++) csb[i + 1] = csb[i] + b[i];

    int ans = 0;
    for (int i = 0; i < n; i++) {
        const int candies = csa[i + 1] + csb[n] - csb[i];
        ans = max(candies, ans);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using li = unsigned long long int;
using namespace std;

int div_time(int n) {
    int cnt = 0;
    while (n > 0) {
        if (n % 2 == 0) {
            cnt++;
            n /= 2;
        } else {
            break;
        }
    }
    return cnt;
}

int main() {
    fastIO;

    int n;
    cin >> n;

    int maxv = 1, max_cnt = 0;
    for (int i = n; i >= 0; --i) {
        int div_cnt = div_time(i);
        if (max_cnt < div_cnt) {
            maxv = i;
            max_cnt = div_cnt;
        }
    }
    cout << maxv << endl;
}

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

int main(){
    int A,B,C; cin >> A >> B >> C;
    for (int i=1; i<=B; i++){
        if((i*A)%B==C){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if (a==1&&b==2||a==2&&b==1){
        cout<<"3"<<endl;
    }else if (a==1&&b==3||a==3&&b==1){
        cout<<"2"<<endl;
    }else cout<<"1"<<endl;
    }

Measured memory_bytes: 256
import math
from fractions import gcd

def factorization(n):
    arr = []
    tmp = n
    for div in range(2, int(math.sqrt(n)) + 2):
        if tmp % div == 0:
            cnt = 0
            while tmp % div == 0:
                cnt += 1
                tmp //= div
            arr.append([div, cnt])

    if tmp != 1:
        arr.append([tmp, 1])

    if len(arr) == 0:
        arr.append([n, 1])

    return arr

if __name__ == '__main__':
    A, B = map(int, input().split())
    g = gcd(A, B)
    if g == 1:
        print(1)
        exit()
    facts = factorization(g)
    print(len(facts) + 1)

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	int count=1,count2=1;
	vector<char>kioku(2,'a');
	string b="Yes";
  	for(int i=0;i<4;i++){
     	if(kioku[0]=='a'){
          kioku[0]=a[i];
        }else if(kioku[0]==a[i]){
          count++;
        }else{
          if(kioku[1]=='a'){
            kioku[1]=a[i]; 
          }else if(kioku[1]==a[i]){
            count2++;
          }
        }
    }
  if(count!=2||count2!=2)b="No";
  cout<<b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(ll, N);
	if (N == 10 || N == 100 || N == 1000 || N == 10000 || N == 100000) {
		cout << 10 << endl;
	} else {
		ll a = 0;
		while (N) {
			a += N % 10;
			N /= 10;
		}
		cout << a << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

int main() {
	ll A, B, N;
	cin >> A >> B >> N;
	cout << A * min(B - 1, N) / B << endl;
}

Measured memory_bytes: 3636
n = int(input())
x = list(map(int,input().split()))

sum = 0
numList = []
p = 0
for pi in range(100):
    for xi in range(len(x)):
        sum += (x[xi] - pi ) ** 2
    numList.append(sum)
    sum = 0
print(min(numList))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<int, pair<int, int>>PP;
typedef long long ll;
ll inf = -1;

int main() {
	int n; cin >> n;
	ll mod = 1000000007;
	string s1, s2;
	cin >> s1 >> s2;
	int j;
	ll ans = 1;
	int type;
	if (s1[0] == s2[0]) {
		type = 0;
		ans *= 3;
		j = 1;
	}
	else {
		type = 1;
		ans *= 6;
		j = 2;
	}
	while (j < n) {
		if (s1[j] == s2[j]) {
			if (type == 0) {
				ans *= 2;
			}
			ans %= mod;
			type = 0;
			j++;
		}
		else {
			if (type == 0) {
				ans *= 2;
			}
			else {
				ans *= 3;
			}
			ans %= mod;
			type = 1;
			j += 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

int a[100000];
int b[100000];
int c[100000];

bool comp_b(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main(void) {
  int n, m;
  vector<pair<int, int> > v;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    v.push_back(make_pair(1, a[i]));
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    cin >> c[i];
    v.push_back(make_pair(b[i], c[i]));
  }

  sort(v.begin(), v.end(), comp_b);

  int cnt = 0;
  long sum = 0;
  while(true) {
    if (cnt >= n) break;
    pair<int, int> p = v.back();
    sum += (long)p.second * min(p.first, n - cnt);
    cnt += min(p.first, n - cnt);
    //sum %= 1000000007;
    v.pop_back();
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3188
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

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

    size_t N;
    cin >> N;

    int64_t res = 0, norm = 0;
    for (size_t i = 0; i < N; ++i) {
        int64_t a; cin >> a;
        if (a == 0) {
            res += norm / 2;
            norm = 0;
        } else {
            norm += a;
        }
    }

    res += norm / 2;

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N), countAB(N, 0), countBC(N, 0);
  vector<pair<int, int>> part;

  rep(i, N)
  {
    int A;
    cin >> A;
    part.push_back(make_pair(A, 3));
  }
  rep(i, N)
  {
    int B;
    cin >> B;
    part.push_back(make_pair(B, 2));
  }
  rep(i, N)
  {
    int C;
    cin >> C;
    part.push_back(make_pair(C, 1));
  }
  sort(part.begin(), part.end());
  map<int, long long> part_count;
  long long ans = 0;
  rep(i, part.size())
  {
    int part_id = part[i].second;
    if (part_id == 3)
      part_count[part_id]++;
    else if (part_id == 2)
      part_count[part_id] += part_count[3];
    else if (part_id == 1)
    {
      ans += part_count[2];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8432
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

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

	int l,r,d;
	cin >> l >> r >> d;
	int cnt = 0;
	for (int c = 1; c<=100;++c) {
		if (l <= c*d && c*d <= r) ++cnt;
	}
	cout << cnt << "\n";
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
using namespace std;
int main(){
    int N, K;
    string S;
    cin >> N >> K >> S;
    if(S[K-1]=='A')S[K-1]='a';
    else if(S[K-1]=='B')S[K-1]='b';
    else S[K-1]='c';
    cout<< S <<endl;
}

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

int main(){
    int n;
    cin >>n;
    int ans=n-1;
    bool pri=true;
    while(1){
        ans++;
        pri=true;
        for(int i=2;i*i<=ans;i++){
            if(ans%i==0){
                pri=false;
                break;
            }
        }
        if(pri==true){
            break;
        }
    }
    
    cout<<ans<<endl;
}


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

const int MAXN=100005 ;
int n , A[MAXN] , T ;

int main(){
	scanf("%d%d",&n,&T) ;
	for(int i=1;i<=n;++i) scanf("%d",&A[i]) ;
	int maxn=0 , now_max=0 ;
	for(int i=n;i>=1;--i){
		now_max=max(now_max,A[i]) ;
		maxn=max(maxn,now_max-A[i]) ;
	}
	now_max=0 ;
	int ans=0 ;
	for(int i=n;i>=1;--i){
		now_max=max(now_max,A[i]) ;
		if(now_max-A[i]==maxn) ans ++ ;
	}
	cout << ans << '\n' ;
	return 0 ;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] ca = sc.next().toCharArray();
		String ans = "";

		for (char c : ca) {
			if (c == '0'){
				ans = ans + "0";
			}else if (c == '1'){
				ans = ans + "1";
			}else if (c == 'B'){
				ans = ans.substring(0, Math.max(ans.length()-1, 0));
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {
	static int r = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}
		sc.close();
		int r = 0;
		for(int i = 1; i < N - 1; i++) {
			int min = Math.min(Math.min(p[i - 1], p[i]), p[i + 1]);
			int max = Math.max(Math.max(p[i - 1], p[i]), p[i + 1]);
			if(min < p[i] && p[i] < max) r++;
		}
		System.out.println(r);
	}
}	


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

ll dp[200005];

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

  for (ll i = 0; i < str.length(); i++) {
    if (str[i] == '?') {
      str[i] = 'D';
    }
  }

  cout << str << endl;

}


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

int main(){
    int N;
    cin >> N;
    set<string> S;
    string str_tmp;
    for(int i=0; i<N; i++){
        
        cin >> str_tmp;
        S.insert(str_tmp);
    }
    cout << S.size() << endl;
}

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

template <typename T>
struct SegmentTree{ // 1-indexed
  T m_id;
  T op(const T &a, const T &b) const{
    return max(a, b);
  }
  vector<T> m_SegT;

  SegmentTree(int N): m_id(0), m_SegT(2*N, m_id){}
  SegmentTree(const vector<T> &data): m_id(0), m_SegT(2*data.size()){
    size_t N= m_SegT.size() >> 1;
    for(size_t i=0; i<N; i++){
      m_SegT.at(i+N)= data.at(i);
    }
    for(size_t i=N-1; i>0; i--){
      m_SegT.at(i)= op(m_SegT.at(i << 1), m_SegT.at((i << 1) | 1));
    }
  }

  void set_val(size_t idx, T val){
    idx+= m_SegT.size() >> 1;
    m_SegT.at(idx)= val;
    while((idx >> 1) > 0){
      idx >>= 1;
      m_SegT.at(idx)= op(m_SegT.at(idx << 1), m_SegT.at((idx << 1) | 1));
    }
  }

  T range(size_t left, size_t right) const{// [left, right)
    left += m_SegT.size() >> 1;
    right+= m_SegT.size() >> 1;
    T calc_l= m_id;
    T calc_r= m_id;

    while(left < right){
      if(left&1){
        calc_l= op(calc_l, m_SegT.at(left));
        left++;
      }
      if(right&1){
        calc_r= op(m_SegT.at(right-1), calc_r);
      }

      left >>= 1;
      right>>= 1;
    }

    return op(calc_l, calc_r);
  }
};

int main() {
  int N,K;
  cin >> N >> K;

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  constexpr int Vmax= 300'000; // '
  SegmentTree<int> st(Vmax+1);
  for(int i=0; i<N; i++){
    int left = max(0   , data.at(i)- K);
    int right= min(Vmax, data.at(i)+ K);
    int len_prev= st.range(left, right+1);
    st.set_val(data.at(i), len_prev+1);
  }

  int ans= st.range(0, Vmax+1);
  cout << ans << endl;
}

Measured memory_bytes: 6664
(* --------------Encoder-------------- *)
(* -----function----- *)
(*
let encoder = 0
*)

(* -------test------- *)
(* ----------------------------------- *)

(* --------------Decoder-------------- *)
(* -----function----- *)
(*
let decoder ans = ""
*)

(* -------test------- *)
(* ----------------------------------- *)

(* --------------Processor-------------- *)
(* -----function----- *)
(*
let processor dat = 0
*)

(* -------test------- *)
(* ----------------------------------- *)


(* ----------------main---------------- *)
(*
let () = print_endline (decoder (processor encoder))
*)
(* ------------------------------------ *)
let () = Scanf.scanf "%d\n" (fun n -> 
        List.init n (fun _ -> 
                Scanf.scanf "%s\n" (fun s -> s)
        ) |> List.sort_uniq compare
        |> List.length
) |> Printf.printf "%d\n"


Measured memory_bytes: 27888
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; 

#define     int                 ll
#define     pb                  push_back
#define     mp                  make_pair
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     init(x, a)          memset(x, a, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     cpy(a,b)            memcpy(a,b,sizeof(b))
#define     is(a)               to_string(a)
#define     ci(a,c)             a-c
#define     debug(i)            cout<<"point :"<<i<<'\n';
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
 	string ans = "1";
 	int k; cin>>k;
 	for(int i = 1; i < k; ++i){
 		if(ans==string((int)ans.size(),'9')){
 			ans = string((int)ans.size(),'0');
 			ans="1"+ans;
 		}
 		else{
 			int i = ans.length()-1;
 			while(i!=0 && (ans[i]=='9' || ans[i]==ans[i-1]+1))i--;
 			ans[i]++;
 			for(int j = i+1; j < ans.length(); j++){
 				if(ans[j-1]-'0'-1<0) ans[j]='0';
 				else ans[j]=ans[j-1]-1;
 			}
 		}
 	}
 	cout<<ans<<'\n';
}

signed main() { 
    IO();
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}

Measured memory_bytes: 256
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
	freopen("filename.in", "r", stdin);
	freopen("filename.out", "w", stdout);
}

int n, m;

int main() {
	//file_put();

	scanf("%d%d", &n, &m);
	printf("%d\n", (n + m) % 24);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
// #include<string>
#include<algorithm>
using namespace std;
int main() {
  int n;
  int k;
  int sum = 0;
  cin >> n;
  cin >> k;

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

  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());

  for (int i = 0; i < k; i++) {
    sum += l[i];
  }

  cout << sum << endl;

}


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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long N;
	cin >>N;
	if (N % 2 ==1 )
		cout << 0 <<"\n";
	else{
		long long sum=0;
		for (long long i=10; N/i>0; i*=5){
			sum+= N/i;
		}
		cout << sum<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int q,w;
	scanf("%d %d",&q,&w);
	if(q>w){
		printf("a > b\n");
	}else if(q<w){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 2580
from collections import *

N = int(input())
v_list = input().split()

if len(set(v_list)) == 1:
    print(len(v_list) // 2)
    exit()

v1_list = v_list[::2]
v2_list = v_list[1::2]

v1_count_list = Counter(v1_list).most_common()
v2_count_list = Counter(v2_list).most_common()

if v1_count_list[0][0] != v2_count_list[0][0]:
    print(len(v_list) - v1_count_list[0][1] - v2_count_list[0][1])
else:
    countor1 = len(v_list) - v1_count_list[1][1] - v2_count_list[0][1]
    countor2 = len(v_list) - v1_count_list[0][1] - v2_count_list[1][1]
    print(min(countor1, countor2))

Measured memory_bytes: 23404
#include<iostream>
#include<stdlib.h>
int main(void){
    int n=0;
    int* p;
    std::cin >> n;
    p=(int*)malloc(n*sizeof(int));

    for(int i=0; i<n; i++){
        std::cin >> *(p + i); 
    }
    int cnt=0;
    for(int i=1;i+1<n;i++){
        if(*(p+i) < *(p+i+1) && *(p+i) > *(p+i-1) ){cnt++;}
        else if(*(p+i) > *(p+i+1) && *(p+i) < *(p+i-1) ){cnt++;}
    }
    std::cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define N 100005

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

const long double Pi = 3.14159265358979323846l;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return (x += y) - (x >= mod ? mod : 0); }
inline void inc(int &x, int y) { (x += y) -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = mul(res, x);
		x = mul(x, x), y >>= 1;
	} return res;
}

template <class T> inline T	input() {
	T x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

template <class T> inline void chkmin(T &x, T &y) { x = x < y ? x : y; }
template <class T> inline void chkmax(T &x, T &y) { x = x > y ? x : y; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

int n, cnt;
int a[N];
long long sum;
bool flag, flag2;

int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }

void work() {
	int G = a[1];
	for (int i = 2; i <= n; ++i) G = gcd(G, a[i]);
	for (int i = 1; i <= n; ++i) a[i] /= G;
}

int main() {
	read(n);
	for (int i = 1; i <= n; ++i)
		read(a[i]), sum += a[i], cnt += a[i] & 1, flag2 |= a[i] == 1;
	if (n == 1) {
		if (a[1] & 1) return puts("Second"), 0;
		else return puts("First"), 0;
	}

	if ((sum - n) & 1) return puts("First"), 0;
	while (cnt == 1 && !flag2) {
		cnt = 0, flag ^= 1;
		for (int i = 1; i <= n; ++i)
			if (a[i] & 1) --a[i];
		while (!cnt) {
			flag2 = false, work();
			for (int i = 1; i <= n; ++i)
				cnt += a[i] & 1, flag2 |= a[i] == 1;
		}

		sum = 0;
		for (int i = 1; i <= n; ++i) sum += a[i];
		if ((sum - n) & 1) return puts(flag ? "Second" : "First"), 0;
	}

	puts(flag ? "First" : "Second");
	return 0;
}


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

int main(){

    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int t=0;
    int first,last;

    last = B<D ? B : D;

    first = A<C ? C : A;

    t = last - first;
    if(t<0)
    {
        std::cout << "0";
    }else{
        std::cout << t;
    }

    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
string a;
int main(){
    int left,right;
    
    
    
    
    
    
    cin>>a;
    for(int i=0;i<a.length();i++)
        if(a[i]=='A'){
            left=i;
            break;
        }
    for(int i=a.length()-1;i>=0;i--)
        if(a[i]=='Z'){
            right=i;
            break;
        }
    cout<<right-left+1<<endl;
    return 0; 
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
} 

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int ans_water = 100, ans_sugar = 0;

    for (int i = 0; 100*A*i <= F; i++) {
        for (int j = 0; 100*A*i + 100*B*j <= F; j++) {
            for (int k = 0; 100*A*i + 100*B*j + C*k <= F; k++) {
                if (C*k >= (A*i + B*j)*E) continue;

                int max_sugar = max(0, (A*i + B*j)*E - C*k);
                int rem = F - 100*A*i - 100*B*j - C*k;
                int cnt = min(max_sugar/D, rem/D);
                int water = 100*A*i + 100*B*j;
                int sugar = C*k + D*cnt;

                if (water != 0) {
                    if (ans_sugar*(water + sugar) <= (ans_water + ans_sugar)*sugar) {
                        ans_water = water;
                        ans_sugar = sugar;
                    }
                }
            }
        }
    }

    cout << ans_water + ans_sugar << ' ' << ans_sugar << endl;
    return 0;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<vector<int>> dp(N, vector<int>(2, 1 << 30));

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

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
 
int main() {
    int a, b;
    scanInt(a);
    scanInt(b);
    bool ans[3];
    rep(i, 3) ans[i] = true;
    ans[a - 1] = false;
    ans[b - 1] = false;
    rep(i, 3) {
        if (ans[i]) {
            printInt(i + 1);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3648
////////////
//||||| ||//
//   || ||//
//||||||||//
//|| ||   //
//|| |||||//
////////////
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   ll  long long int
#define   dl double
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scld(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   ump  unordered_map
#define   mp   map         
#define   Pi acos(-1.0)
#define   inf 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
#define   MAX 1000000
#define   eps 1e-8
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset;
// Creates a min heap
//priority_queue <int, vector<int>, greater<int> > pq;
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
//S.order_of_key(x)[Give me the position of x]
//S.find_by_order(x)[Give me the x th element in set]
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll lcm(ll a, ll b) {return (a * b) / __gcd(a, b);}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll a, b, c = 0, d, e, f = 0, g, h, i, j, k, m, n, o, p, s, t, v, w, x = 0, y, z, l;
    ll cnt = 0, l1 = 0, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
    ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
    string str, str1, str2, str3 = "", str4 = "";
    ll ide = 0, idx = 0, Q;
    
scll(h);
scll(w);
scll(m);
ump<ll,ll>ur;
ump<ll,ll>uc;
ump<ll,ump<ll,ll> >pos;
for(i=0;i<m;i++)
{
     scll(x);
     scll(y);
     ur[x]++;
     uc[y]++;
     pos[x][y]=1;
}
for(i=1;i<=300005;i++)
{
	c1=max(c1,ur[i]);
}
for(i=1;i<=300005;i++)
{
	c2=max(c2,uc[i]);
}
vector<ll>vec1,vec2;
for(i=1;i<=300005;i++)
{
	if(c1==ur[i])
	{                                                                                                                                                                                                                                    
     vec1.pb(i);    
	}
}
for(i=1;i<=300005;i++)
{
	if(c2==uc[i])
	{
        vec2.pb(i);
	}
}

for(i=0;i<vec1.size();i++)
{
	for(j=0;j<vec2.size();j++)
	{
		if(pos[vec1[i]][vec2[j]]==0)
		{
			cout<<ur[vec1[i]]+uc[vec2[j]];
			return 0;
		}
	}
}
 cout<<ur[vec1[0]]+uc[vec2[0]]-1;
    return 0;
}

Measured memory_bytes: 84780
#!/usr/bin/env python3

import sys, bisect
sys.setrecursionlimit(300000)

def solve(N: int, S: str):
    tmp = {'R': [], 'G': [], 'B': []}
    for i, c in enumerate(S):
        tmp[c].append(i)

    ret = 0
    x = len(tmp['R'])
    y = len(tmp['G'])
    z = len(tmp['B'])
    ret = x * y * z
    for r in tmp['R']:
        for g in tmp['G']:
            d = abs(g - r)
            if g > r:
                t = g + d
            else:
                t = r + d
            idx = bisect.bisect_left(tmp['B'], t)
            if idx < z and tmp['B'][idx] == t:
                ret -= 1
    for r in tmp['R']:
        for b in tmp['B']:
            d = abs(b - r)
            if b > r:
                t = b + d
            else:
                t = r + d
            idx = bisect.bisect_left(tmp['G'], t)
            if idx < y and tmp['G'][idx] == t:
                ret -= 1
    for g in tmp['G']:
        for b in tmp['B']:
            d = abs(b - g)
            if b > g:
                t = b + d
            else:
                t = g + d
            idx = bisect.bisect_left(tmp['R'], t)
            if idx < x and tmp['R'][idx] == t:
                ret -= 1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 75188