akhauriyash/Code-Regression huggingface dataset:
import heapq
N,M=map(int,input().split())
R=[]
G=[[] for i in range(N)]
for i in range(M):
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    G[a].append((b,c))
    G[b].append((a,c))
    R.append((a,b,c))
Q=[[0]*N for i in range(N)]
INF=10**9
for i in range(N):
    stack=[]
    g=[INF for i in range(N)]
    g[i]=0
    n=1
    for b,c in G[i]:
        heapq.heappush(stack,(g[i]+c,i,b))
    used=[[0]*N for i in range(N)]
    while(stack):
        if n==N:
            break
        c,a,b=heapq.heappop(stack)
        g[b]=min(g[b],c)

        used[a][b]=1
        used[b][a]=1
        for j in G[b]:
            if used[b][j[0]] or g[j[0]]!=INF:
                continue
            if g[j[0]]<=g[b]+j[1]:
                continue
            heapq.heappush(stack,(g[b]+j[1],b,j[0]))
    for j in range(i+1,N):
        Q[i][j]=g[j]
ans=0
for a,b,c in R:
    if b<a:
        a,b=b,a
    if Q[a][b]<c:
        ans+=1
print(ans)


Measured memory_bytes: 59100
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

long gcd(long a, long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

long lcm(long a, long b)
{
   return a * b / gcd(a, b);
}

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

   if(a>b){

   cout<<lcm(a,b)<<endl;
   }
   else{
       cout<<lcm(b,a)<<endl;
   }
   
   return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int STOP = 100;

bool search(int l, int r, int* a){
	bool f = false;
	int buf = *a;
	if(buf == STOP) return true;
	if(buf < l && buf < r) return false;
	if(buf > l) f = f || search(buf, r, a + 1);
	if(buf > r) f = f || search(l, buf, a + 1);
	return f;
}

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int l[11];
		for (int j = 0; j < 10; j++) {
			cin >> l[j];
		}
		l[10] = STOP;
		if(search(0, 0, l)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

int main() {
  int n, k; cin >> n >> k;
  int R, S, P; cin >> R >> S >> P;
  string t; cin >> t;
  int ans = 0;

  vector<string> mods(k);
  rep(i,n){
    mods[(i+1)%k] += t[i];
    switch(t[i]){
      case 'r': ans+=P; break;
      case 'p': ans+=S; break;
      case 's': ans+=R; break;
    }
    //cout << ans << endl;
  }



  /*rep(i,k){
    cout << mods[i] << endl;
  }*/

  rep(i,k){
    int streak =1;
    char now;
    rep(j,mods[i].size()-1){
      if(mods[i][j] == mods[i][j+1]){
        streak++;
        now = mods[i][j];
        //cout << "streak: " << streak << "  hand: " << mods[i][j] << endl;
      }
      else{
        //cout << "else!!!  " << "streak: " << streak << "  hand: " << mods[i][j] << endl;
        switch(now){
          case 'r': ans-=P*(streak/2); break;
          case 'p': ans-=S*(streak/2); break;
          case 's': ans-=R*(streak/2); break;
        }
        streak = 1;
      }
      if(j == mods[i].size()-2){
        //cout << "end!!!   "  << "streak: " << streak << "  hand: " << mods[i][j] << endl;
        switch(now){
          case 'r': ans-=P*(streak/2); break;
          case 'p': ans-=S*(streak/2); break;
          case 's': ans-=R*(streak/2); break;
        }
        streak = 1;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5972
H, W = map(int, input().split())
S = ["."*(W+2)] + ["." + input() + "." for _ in range(H)] + ["."*(W+2)] #塗りたし

for y in range(1, H+1):
    for x in range(1, W+1):
        if S[y][x] == '#' and (S[y-1][x] + S[y+1][x] + S[y][x-1] + S[y][x+1]).count('#') == 0:
            print("No")
            exit()
print("Yes")

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

int main()
{
	ios::sync_with_stdio(false);
	
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	int ans=0;
	
	for(int i=1;i<=n;i++)
	{
		if(i<=k)
			ans+=x;
		else
			ans+=y;
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int x,a,b;cin>>x>>a>>b;
  if(b<=a){
    P("delicious");
  }else if(a<b && b<=a+x){
    P("safe");
  }else{
    P("dangerous");
  }
  return 0;
}


Measured memory_bytes: 256
var
  a,b,c:longint;
begin
  readln(a,b,c);
  if(a=b)and(a<>c)then writeln('Yes')
   else if(b=c)and(a<>b)then writeln('Yes')
    else if(a=c)and(a<>b)then writeln('Yes')
     else writeln('No');
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

int gcd(int a,int b){
	return (a%b==0?b:gcd(b,a%b));
}

signed main() {
  INIT;
	VAR(int,n);
	VEC(int,t,n);
	sort(ALL(t));
	int _gcd=t[0],ans=t[0];
	FOR(i,1,n){
		_gcd = gcd(ans, t[i]);
		ans *= t[i]/_gcd;
	}
	OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MA 20
int M[MA][MA];
int best[1<<MA][MA];
int shortestHamiltonPath(int s,int n) {
	int N = 1 << n;
	int S,i,j;
	for(S=0;S<N;S++)for(i=0;i<n;i++)best[S][i]=0;
	best[1<<s][s]=1;
	for(S=0;S<N;S++)for(j=0;j<n;j++)if(!(S&(1<<j)))for(i=0;i<n;i++){
			if(M[i][j])best[S|(1<<j)][j] += best[S][i];
	}
	for(i=j=0;i<n;i++)j+=best[N-1][i];
	return j;
}

int main(){
	int n,m,a,b;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		M[a-1][b-1]=M[b-1][a-1]=1;
	}
	printf("%d\n",shortestHamiltonPath(0,n));
}

Measured memory_bytes: 128
sa = list(input())
sb = list(input())
sc = list(input())
s = sa.pop(0)
ans = ""

while(True):
  if s == "a" and len(sa) != 0:
    s = sa.pop(0)
  elif s == "a" and len(sa) == 0:
    ans = "A"
    break
  if s == "b" and len(sb) != 0:
    s = sb.pop(0)
  elif s == "b" and len(sb) == 0:
    ans = "B"
    break
  if s == "c" and len(sc) != 0:
    s = sc.pop(0)
  elif s == "c" and len(sc) == 0:
    ans = "C"
    break

print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple {
    int K, S;
    void Solve() {
        //input
        K = io.Int;
        S = io.Int;
        //cal
        int ans = 0;
        for (int x = 0; x <= K; ++x)
            for (int y = 0; y <= K; ++y)
                if (0 <= S - (x + y) && S - (x + y) <= K)
                    ans++;
        //res
        Console.WriteLine(ans);
    }

    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}

class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int n; cin >> n;
	ll x[105], y[105], h[105];
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i] >> h[i];
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			ll H = 0;
			bool flag = true;
			for(int k=0;k<n;k++){
				if(h[k]>0){
					H = h[k]+abs(x[k]-i)+abs(y[k]-j);
					break;
				}
			}
			for(int k=0;k<n;k++){
				if(h[k]!=max((H-abs(x[k]-i)-abs(y[k]-j)), 0LL)){
					flag = false;
					break;
				}
			}
			if(flag){
				cout << i << ' ' << j << ' ' << H << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
l, r = map(int, input().split())
dif = r - l
ans = 30000
if dif >= 2019:
    ans = 0
else:
    mod_l = l % 2019
    mod_r = r % 2019
    if mod_l < mod_r:
        if 3 >= mod_l and mod_r >= 673:
            ans = 0
        else:
            for i in range(mod_l, mod_r + 1):
                for j in range(i + 1, mod_r + 1):
                    ans = min(ans, (i * j) % 2019)
    else:
        ans = 0
#print(dif, mod_l, mod_r)
print(ans%2019)

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

using namespace std;

int n, ans;

char c[1000055];

int main () {
    cin >> n;
    for (int i = 1;i <= n;i ++) {
        cin >> c[i];
    }
    for (int i = 1;i <= n;i ++) {
        if (c[i] != c[i - 1])ans ++;
    }cout << ans;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    string s; cin >> s;
    int ans = 0;
    int n = s.size();
    for(int i = n-2; i < n; i -= 2){
        string t = s.substr(0,i/2),u = s.substr(i/2,i/2);
        if(t == u){
            ans = t.size() + u.size();
            break;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func main() {
	sc := NewScanner()
	A1, A2, A3 := sc.nextInt(), sc.nextInt(), sc.nextInt()
	arr := make([]int, 3)
	arr[0] = abs(A1 - A2)
	arr[1] = abs(A1 - A3)
	arr[2] = abs(A2 - A3)
	sort.Ints(arr)
	fmt.Println(arr[0] + arr[1])
}


Measured memory_bytes: 640
a, b, c = (int(x) for x in input().split())
if(a < c < b or a == c < b):
    print(a, c, b)
elif(b < a < c or a == c > b):
    print(b, a, c)
elif(b < c < a):
    print(b, c, a)
elif(c < a < b):
    print(c, a, b)
elif(c < b < a or a == b > c or b == c < a):
    print(c, b, a)
else:
    print(a, b, c)


Measured memory_bytes: 5604
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

int main() {
	int N;
	cin >> N;
	int A;
	A = N % 10;
	if (A == 2 || A == 4 || A == 5 || A == 7 || A == 9) cout << "hon" << endl;
	if (A == 0 || A == 1 || A == 6 || A == 8 ) cout << "pon" << endl;
	if (A == 3) cout << "bon" << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    unsigned long long s = 0;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            int g = __gcd(i,j);
            for (int k = 1; k <= n; k++) {
                s += __gcd(g, k);
            }
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3632
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑


int main() {

	int sum = 0, ans, a, b, k[105];
	cin >> a >> b;
	for (int i = 0; i < b; ++i) {
		cin >> k[i];
		sum += k[i];
	}
	ans = sum / (a + 1);

	if (sum - sum / (a + 1) * (a + 1) != 0) { ++ans; }

	cout << ans << endl;

}


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

const int C=100010, N=200010;
int a[N], b[N];

int main()
{
	int n;
	scanf ("%d", &n);
	a[C]++, b[C]++;
	
	while (n--){
		int l, r;
		scanf ("%d%d", &l, &r);
		l += C, r += C;
		a[l]++, b[r]++;
	}
	
	for (int i=N-2; i>=0; i--)
		a[i] += a[i+1];
		
	for (int i=1; i<N; i++)
		b[i] += b[i-1];
		
	long long ans=0;
	for (int i=0; i<N-1; i++)
		ans += min (b[i], a[i+1]);
		
		
	printf ("%lld\n", ans*2);
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	int n = s.size(), count = 0;
	for (int i = 0; i < n; i++)
		if (s[i] & 1 ^ i & 1)
			count++;
	cout << min(count, n - count) << endl;
}



Measured memory_bytes: 512
S = input()
MOD = 10**9 + 7

A = 0
AB = 0
Q = 1
ans = 0

for s in S:
    if s == '?':
        ans = (3 * ans + AB) % MOD
        AB = (3 * AB + A) % MOD
        A = (3 * A + Q) % MOD
        Q = Q * 3 % MOD
    elif s == 'A':
        A = (A + Q) % MOD
    elif s == 'B':
        AB = (AB + A) % MOD
    elif s == 'C':
        ans = (ans + AB) % MOD

print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <cstring>

int main() {
  int n, capacity;
  std::cin >> n >> capacity;
  std::vector<int> w(n), v(n);
  for (int i = 0; i < n; ++i)
    std::cin >> w[i] >> v[i];
  std::vector<std::vector<uint64_t>> dp(n + 1);
  for (int i = n - 1; i >= 0; --i) {
    int len = dp[i + 1].size() + v[i];
    dp[i].resize(len);
    for (int j = 0; j < v[i]; ++j) {
      if (j < dp[i + 1].size())
        dp[i][j] = std::min(static_cast<uint64_t>(w[i]),
                            dp[i + 1][j]);
      else
        dp[i][j] = w[i];
    }
    for (int j = v[i]; j < len; ++j) {
      if (j < dp[i + 1].size())
        dp[i][j] = std::min(dp[i + 1][j - v[i]] + w[i],
                            dp[i + 1][j]);
      else
        dp[i][j] = dp[i + 1][j - v[i]] + w[i];
    }
    // for (const auto &it : dp[i])
    //   std::cout << ' ' << it;
    // std::cout << std::endl;
  }
  int val;
  for (val = dp[0].size() - 1; val >= 0; --val) {
    if (dp[0][val] <= capacity) {
      break;
    }
  }
  std::cout << val + 1 << std::endl;
  return 0;
}


Measured memory_bytes: 39936
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> p;
    int A;
    for(int i = 0;i < N;i++) {
        cin >> A;
        p.push_back(make_pair(A,i + 1));
    }
    sort(p.begin(),p.end());
    for(int i = 0;i < N;i++) {
        if(i != N - 1) cout << p.at(i).second << " ";
        else cout << p.at(i).second << endl;
    }
}


Measured memory_bytes: 1780
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
//const long long mod = 1000000007;
//const long long mod = 998244353;

int main() {
	int N;
	scanf("%d", &N);
	double res = 1.0 - (double)(N / 2) / N;
	printf("%f", res);
	return 0;
}

Measured memory_bytes: 128
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

long long int A, B, C, D, N;
long long int ans;

int main()
{
	scanf("%lld %lld %lld %lld %lld", &A, &B, &C, &D, &N);
	ans = (N / 2) * min(min(8 * A, 4 * B), min(2 * C, D)) + (N % 2) * min(min(4 * A, 2 * B), C);
	printf("%lld", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner sc =new Scanner(System.in);
    public static void main(String[] args) {
        String n = sc.next();
        if(n.charAt(n.length()-1) == '2'||
                n.charAt(n.length()-1) == '4'||
                n.charAt(n.length()-1) == '5'||
                n.charAt(n.length()-1) == '7'||
                n.charAt(n.length()-1) == '9'
        ) {
            System.out.println("hon");
        } else if (n.charAt(n.length()-1) == '0'||
                n.charAt(n.length()-1) == '1'||
                n.charAt(n.length()-1) == '6'||
                n.charAt(n.length()-1) == '8'){
            System.out.println("pon");
        } else {
            System.out.println("bon");
        }
    }
}

Measured memory_bytes: 35620
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
typedef long long ll ;
#define pll pair<ll , ll >
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
using namespace std;
const int maxn = 1000*1000+5 ;
const ll inf = 9223372036854775807 ;
const ll mod = 1e9 + 7 ;
ll ps[maxn] , n , m , x  , a[maxn] , mark[maxn] , ans  ;  
int main()
{
	migmig ;
	cin>>n>>x>>m ; 
	a[1] = x ; 
	ps[1] = x;
	for(int i = 2 ; i <= 25 * ( m + 1 ) ; i ++ )
	{
		a[i] = (a[i-1] * a[i-1]) % m ; 
		ps[i] = ps[i-1] + a[i] ; 
		if(mark[a[i]])
		{
			ll j = mark[a[i]] ; 
			ans += ps[j-1] ; 
			n -= (j - 1) ; 
			ans += n / (i - j) * (ps[i-1] - ps[j-1]) ; 
			ans += ps[j + n % (i - j) - 1] - ps[j-1] ; 
			cout<<ans ; 
			return 0 ;
 		}
 		mark[a[i]] = i ; 
 		if(i == n)
 		{
 			cout<<ps[i] ; 
 			return 0 ; 
		 }
	}
}








Measured memory_bytes: 5248
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#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 lu unsigned long long int
#define pi pair<ll, ll>
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for (ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define be begin
#define sz(a) (ll)(a.size())
#define INF 1e18
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

ll gcd(ll a, ll b){
	return b == 0 ? a : gcd(b, a % b);
}

// ll mod = 1e9+7;

// ll mult(ll x, ll y){
//     ll rem=1;
//     while(y){
//         if(y&1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y>>=1;
//     }
//     return rem;
// }

ll mod = 998244353;
ll dp[3005][3005];

void solve(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	c-=a; d-=b;
	dp[0][0] = 1;
	for(ll i=1;i<=c;i++){
		dp[i][0] = dp[i-1][0] * b % mod;
	}
	for(ll j=1;j<=d;j++){
		dp[0][j] = dp[0][j-1] * a % mod;
	}
	for(ll i=1;i<=c;i++){
		for(ll j=1;j<=d;j++){
			dp[i][j]=(dp[i][j-1]*(a+i)%mod+dp[i-1][j]*(b+j)%mod-(i-1+a)*(j-1+b)%mod*dp[i-1][j-1]%mod+mod)%mod;
		}
	}
	cout << dp[c][d] << "\n";
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 74036
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[]#偶数だけ
C=[]#奇数だけ

if N%2==0:
  for i in range(0,int(N/2)):
    B+=[2*i,2*i]
    C+=[2*i+1,2*i+1]
  if A==B or A==C:
    n=int(N/2)
    ans=2**n
    print(ans%(10**9+7))
  else:
    print(0)
else:
  B+=[0]
  C+=[1]
  for i in range(0,int(N/2)):
    B+=[2*i+2,2*i+2]
    C+=[2*i+3,2*i+3]
  if A==B or A==C:
    n=int((N-1)/2)
    ans=2**n
#    ans=2**((N-1)/2)
    print(ans%(10**9+7))
  else: 
    print(0)

Measured memory_bytes: 16256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<long long> a(n);
    std::vector<int> id(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    std::iota(id.begin(), id.end(), 0);
    std::sort(id.begin(), id.end(), [&](int i, int j) {
        return a[i] < a[j];
    });
    std::set<int> s;
    s.insert(-1); s.insert(n);
    long long ans = 0;
    for (int i : id) {
        auto iter = s.lower_bound(i);
        int r = *iter;
        int l = *(--iter);
        ans += a[i] * (r - i)*(i - l);
        s.insert(i);
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 12032
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	int l;
	cin>>l;
	vector<int> v;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		v.push_back(a);
	}
	for(int i=0;i<n-1;i++)
	{
		if((v[i]+v[i+1])>=l)
		{
			cout<<"Possible"<<endl;
			for(int j=1;j<=i;j++)
				cout<<j<<endl;
			for(int j=n-1;j>=i+2;j--)
				cout<<j<<endl;
			cout<<i+1<<endl;
			return 0;
		}
	}
	cout<<"Impossible"<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222





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

  
  cin >> n;
  priority_queue<ll> pq1;
  priority_queue<ll, vll, greater<ll>> pq2;
  pq1.push(-inf);
  pq2.push(inf);
  while (n--) {
    cin >> tmp;
    if (tmp == 1) {
      ll a, b;
      cin >> a >> b;
      ans += b;
      ll x, y;
      x = pq1.top();
      y = pq2.top();
      if (x == -inf) x = a;
      if (pq1.size() > pq2.size()) pq2.push(a);
      else pq1.push(a);
      if (pq1.top() > pq2.top()) {
        ll p1 = pq1.top(), p2 = pq2.top();
        pq1.pop(); pq2.pop();
        pq1.push(p2); pq2.push(p1);
      }
      if (pq1.size() == pq2.size()) ans += abs(x - a);
      else if(a<x || a>y)ans += min(abs(a - x), abs(a - y));
    }
    else cout << pq1.top() << " " << ans << endl;
  }



  return 0;
}

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  vector<int> a(5);
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  int k;
  cin >> k;
  bool ok = true;
  for (int i = 0; i < 5; i++) 
    for (int j = 0; j < 5; j++) 
      if (abs(a[i] - a[j]) > k)
        ok = false;
  cout << (ok ? "Yay!" : ":(");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>

using namespace std;

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

  double t = A / D;
  double a = C / B;

  cout << ((ceil(t) >=  a)? "Yes" : "No")  << endl;
  return 0;
}


Measured memory_bytes: 3260
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a[] = new int[n];

		long front = 0;
		long back = 0;
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
			if (i != n - 1) {
				front += a[i];
			} else {
				back += a[i];
			}
		}

		long min = Math.abs(front - back);
		for (int i = n - 2; i > 0; i--) {
			front -= a[i];
			back += a[i];
			min = Math.min(min, Math.abs(front - back));
		}

		System.out.println(min);

	}
}


Measured memory_bytes: 82900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string solve(ll k, ll n) {
    ll a = powl(26, k);
    string res = "";
    if (n > a) {
        n -= a;
        return solve(k+1, n);
    }
    ll b = a/26;
    if (n % b == 0) {
        res += 'a'+(n/b)-1;
        res += string(k-1, 'z');
        return res;
    }
    res += 'a'+(n/b);
    res += solve(k-1, n%b);
    return res;
}
int main() {
    ll N;
    cin >> N;
    cout << solve(1, N) << endl;
}

Measured memory_bytes: 3716
nums = list(map(int, input().split()))
table = []
for i in range(nums[0]):
    table.append(list(map(int, input().split())))
    table[i].append(sum(table[i][:]))
table.append([])
for i in range(nums[1]+1):
    t = 0
    for j in range(nums[0]):
        t += table[j][i]
    table[nums[0]].append(t)
for i in range(nums[0]+1):
    for j in range(nums[1]+1):
        if j < nums[1]:
            print(table[i][j], end = ' ')
        else:
            print(table[i][j])


Measured memory_bytes: 6224
def readinput():
    n,k=map(int,input().split())
    return n,k

def main(n,k):
    if n>k:
        n=n%k+k
        n=min(n,abs(n-k))
    return min(n,abs(n-k))

if __name__=='__main__':
    n,k=readinput()
    ans=main(n,k)
    print(ans)


Measured memory_bytes: 9128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	int a,b,c,d; cin >> a >> b >> c >> d;
	if(a != c) puts("1");
	else puts("0");
}

Measured memory_bytes: 768
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int N;
  cin >> N;
  vector<int> d;
  rep(i, N) {
    int di;
    cin >> di;
    d.pb(di);
  }

  int maxGo = 0;
  for (int i = 0; i < N; i++) {
    // DEBUG(i);
    // DEBUG(maxGo);
    if(maxGo < i) break;
    maxGo = max((d[i] / 10) + i, maxGo);
  }

  if (maxGo < (N - 1)) {
    cout << "no" << endl;
    return 0;
  }

  int minBack = N - 1;
  for(int i = N - 1; i > 0 ; i--) {
    // DEBUG(i);
    // DEBUG(minBack);
    if(i < minBack) break;
    minBack = min(minBack, i - (d[i] / 10));
  }

  if (minBack > 0) {
    cout << "no" << endl;
    return 0;
  }

  cout << "yes" << endl;
}



Measured memory_bytes: 5016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
    int n;
    cin >> n;
    int h[n];
    rep (i, 0, n) cin >> h[i];
    bool chk = 1;
    int ans = 0;
    while (chk) {
        int cnt = 0;
        int now = 0;
        int sum = inf;
        rep (i, 0, n) {
            if (h[i] == 0) {
                if (sum != inf) {
                    rep (j, now, i) h[j] -= sum;
                    ans += sum;
                }
                now = i + 1;
                sum = inf;
            } else {
                sum = min (sum, h[i]);
            }
        }
        if (sum != inf) {
            rep (j, now, n) h[j] -= sum;
            ans += sum;
        }
        chk = 0;
        rep (i, 0, n) {
            if (h[i] > 0) chk = 1;
            // cout << h[i] << " ";
        }
        cout << "\n";
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3632
import java.util.*;
public class Main {
    public static void main(final String[] args){
        final Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        final int K = sc.nextInt();
        sc.close();

        int cnt = 1;
        while (N >= K) {
            N /= K;
            cnt++;
        }

        System.out.println(cnt);
    }
}

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

int main(void) {
    int x, y;
    while(true) {
        cin >> x >> y;
        if(x == 0 && y == 0) {
            break;
        } else {
            if(x > y) {
                cout << y << " " << x << endl;
            } else {
                cout << x << " " << y << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
#define ll long long 
#define all(v) v.begin() , v.end()
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define tr(con) for(auto it = con.begin(); it!= con.end() ; it++)
#define INF 1e9+7   // 1 * 10^9+ 7
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;

int main(){
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);


	long long m,count=0;
	cin >> m;
	for(ll i=0;;i++){
       if(m==0){
 	   break;
     }
     
        if(((long long )log10(m))%2==0){
 	        count++;
 	
               }
        m--;
	}

	cout << count;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
main(){int a,b,c,k,i,x[1000][4],p[500];
while(true){for(i=0;i<500;i++){p[i]=2;}
std::cin>>a>>b>>c;
if(a==0){break;}std::cin>>k;
for(i=0;i<k;i++){std::cin>>x[i][0]>>x[i][1]>>x[i][2]>>x[i][3];
if(x[i][3]==1){p[x[i][0]]=1;p[x[i][1]]=1;p[x[i][2]]=1;}
}
for(i=0;i<k;i++){
if(p[x[i][0]]==1&&p[x[i][1]]==1&&x[i][3]==0)
p[x[i][2]]=0;
if(p[x[i][0]]==1&&p[x[i][2]]==1&&x[i][3]==0)
p[x[i][1]]=0;
if(p[x[i][1]]==1&&p[x[i][2]]==1&&x[i][3]==0)
p[x[i][0]]=0;
}
for(i=1;i<=a+b+c;i++){printf("%d\n",p[i]);}
}
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k, p, m, y;
string s, t;
ld w;
ll a,b;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	ll dp[90];
	dp[0] = 2;
	dp[1] = 1;
	cin >> n;
	for(ll i=2;i<=n;i++) dp[i] = dp[i-1] + dp[i-2];
	cout<<dp[n];
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
struct edge{
	double cost;
	int to;
};
D inf=1e10,eps=1e-10;
bool eq(D a, D b) { return abs(a-b)<eps;}
bool eq(P a, P b) { return abs(a-b)<eps;}
int sig(D a) { return eq(a,0) ? 0 : (a>0 ? 1 : -1);}
inline D cro(P a, P b) { return imag(conj(a)*b);};
inline int ccw (P a, P b, P c){
//	cout << cro(b-a,c-a) << endl;
	if(sig(cro(b-a,c-a))==1) return 1;
	if(sig(cro(b-a,c-a))==-1) return -1;
	if(eq(abs(a-c)+abs(c-b),abs(a-b))) return 0;
	if(eq(abs(a-b)+abs(b-c),abs(a-c))) return -2;
	if(eq(abs(c-a)+abs(a-b),abs(c-b))) return 2;
}
inline bool iSS(L a, L b){		//intersect(including endpoint) or overload
	return ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0 && ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0;
}
P pa[1000],pb[1000];
vector<edge> G[1000];
double d[1000];
typedef pair<double,int> Pa;
void dijkstra(int s){
	rep(i,1000) d[i]=inf;
	priority_queue<Pa,vector<Pa>,greater<Pa> > que;
	d[s]=0;
	que.push(Pa(0,s));
	while(!que.empty()){
		Pa p=que.top();
		que.pop();
		int v=p.sc;
		if(d[v]<p.fs) continue;
		rep(i,G[v].size()){
			edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(Pa(d[e.to],e.to));
			}
		}
	}
}
int main(){
	int a,b;
	cin>>a>>b;
	rep(i,a){
		int x,y;
		cin>>x>>y;
		pa[i]=P(x,y);
	}
	rep(i,b){
		int x,y;
		cin>>x>>y;
		pb[i]=P(x,y);
	}
	L lb=L(pb[0],pb[1]);
	rep(i,a) rep(j,i){
		if(!iSS(L(pa[i],pa[j]),lb)){
			G[i].pb({abs(pa[i]-pa[j]),j});
			G[j].pb({abs(pa[i]-pa[j]),i});
		}
	}
	double ans=inf;
	dijkstra(0);
	ans=min(ans,d[1]+abs(pb[0]-pb[1]));
	L la=L(pa[0],pa[1]);
	rep(i,b) G[i].clear();
	rep(i,b) rep(j,i){
		if(!iSS(L(pb[i],pb[j]),la)){
			G[i].pb({abs(pb[i]-pb[j]),j});
			G[j].pb({abs(pb[i]-pb[j]),i});
		}
	}
	dijkstra(0);
	ans=min(ans,d[1]+abs(pa[0]-pa[1]));

	if(ans==inf) ans=-1;
	printf("%.13f\n",ans);
}

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

using namespace std;

int main()
{
    long long int N, x, a[100010], b[100010];

    cin >> N >> x;

    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        b[i] = a[i];
    }

    long long int y;

    long long int ans1 = 0;

    for (int i = 1; i < N; i++)
    {
        y = a[i] + a[i-1] - x;

        a[i] = a[i] - max(0LL, y);
        ans1 = ans1 + max(0LL, y);
    }

    y = a[0] - x;

    ans1 = ans1 + max(0LL, y);

    long long int ans2 = 0;


    for (int i = N-2; i >= 0; i--)
    {
        y = b[i] + b[i+1] - x;

        b[i] = b[i] - max(0LL, y);
        ans2 = ans2 + max(0LL, y);
    }

    y = a[N-1] - x;
    
    ans2 = ans2 + max(0LL, y);

    cout << min(ans1, ans2) << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
#include<bits/stdc++.h>
#include<queue>
using namespace std;

int main(){
    int n, k;
    vector<int> a(200000);
    vector<int> d(200000);
    priority_queue<int,vector<int>> ma;
    priority_queue<int,vector<int>,greater<int>> mi;
    cin >> n >> k;
    for(int i=0; i<n; i++){
        cin >> a[i];
        d[a[i]] = i;
    }
    for(int i=0; i<k; i++){
        ma.push(a[i]);
        mi.push(a[i]);
    }
    int re = 0;
    int same = 0;
    for(int i=0; i<n-1; i++){
        if(a[i]<=a[i+1]){
            re += 1;
            if(i==n-2){
                if(re>=k-1){
                    same += 1;
                }
            }
        }else{
            if(re>=k-1){
                same += 1;
            }
            re = 0;
        }
    }

    int count = 1;
    int l, r;
    for(int i=1; i<n-k+1; i++){
        l = a[i-1];
        r = a[i+k-1];
        //top を決定
        while(d[mi.top()]<i-1){
            mi.pop();
        }
        while(d[ma.top()]<i-1){
            ma.pop();
        }
        if(l!=mi.top() or r<=ma.top()){
            count += 1;
        }
        mi.push(r);
        ma.push(r);
    }
    cout << count - max(0,(same-1)) << endl;
}

Measured memory_bytes: 3572
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
fn=sorted(Counter(f).items(),key=lambda x:x[1],reverse=True) + [(0, 0)]
sn=sorted(Counter(s).items(),key=lambda x:x[1],reverse=True) + [(0, 0)]
if fn[0][0]!=sn[0][0]:
  ans=n-fn[0][1]-sn[0][1]
else:
  ans=n-max(fn[1][1]+sn[0][1],fn[0][1]+sn[1][1])
print(ans)

Measured memory_bytes: 21212
#include <bits/stdc++.h>
 
#define rep( i, n, m ) for (int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for (int i = ( n ); i < ( m ); i--)
 
int main( void ){
	int n, y;
	if(!scanf( "%d%d", &n, &y ))
		return -1;
	y /= 1000;
	rep( k, 0, n+1 ){
		rep( j, 0, n+1 ){
			int i = n - j - k;
			if (i < 0)
				break;
			if (y == i * 10 + j * 5 + k){
				printf( "%d %d %d\n", i, j, k );
				return 0;
			}
		}
	}
	printf( "-1 -1 -1\n" );
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 101

int main(void){
  int r, c, table[N][N];
  int i, j;

  scanf("%d%d", &r, &c);
  for(i = 0; i <= r; i++){
    for(j = 0; j <= c; j++){
      if(i == r || j == c){
	table[i][j] = 0;
      }else{
	scanf("%d", &table[i][j]);
      }
    }
  }

  for(i = 0; i < r; i++){
    for(j = 0; j < c; j++){
      table[i][c] += table[i][j];
    }
  }
  for(i = 0; i < r; i++){
    for(j =0; j <= c; j++){
      table[r][j] += table[i][j];
    }
  }

  for(i = 0; i <= r; i++){
    for(j = 0; j <= c; j++){
      printf("%d", table[i][j]);
      if(j != c){
	printf(" ");
      }else{
	printf("\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int factrial(int n){
//   if(n == 0) return 1;
//   return n*factrial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }

string s;

int main(){
  int N;
  
  cin >> N;
  if(N == 0) s = '0';
  while(N){
    if(N % (-2) == 0) s = '0' + s;
    else{
      N -= 1;
      s = '1' + s;
    } 
    N /= (-2);
  }
  cout << s << endl;
}
  




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<cstdio>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007

#define ARRAY_MAX 10005


int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> mp;
    REP(i,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(a.begin(),a.end(),greater<int>());
    int ans = 0;

    for(int i = 0;i < n;i++){

        if(mp[a[i]] > 0){
            mp[a[i]]--;
            int tmp = 1;
            while(tmp <= a[i]){
                tmp *= 2;
            }
            if(mp[tmp-a[i]] > 0){
                ans++;
                mp[tmp-a[i]]--;
            }
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 19840
N, K = map(int,input().split())
cost= input().split()
cost = [int(i) for i in cost]
ans_list = [0]*N
ans_list[1] = abs(cost[0] - cost[1])
temp = 10 **10

for i in range(2,N):
    temp = 10**10
    for j in range(1,K+1):
        if i-j >=0:
            compare = ans_list[i-j] + abs(cost[i-j]-cost[i])
            temp2 = min(compare, temp)
            temp = temp2
    if temp != 10 ** 10:
        ans_list[i] = temp
print(ans_list.pop())


Measured memory_bytes: 52448
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  s=S()

  r=[0]*(n+1)
  g=[0]*(n+1)
  b=[0]*(n+1)

  for i,x in enumerate(s):
    if x=='R':
      r[i+1]+=1
    elif x=='G':
      g[i+1]+=1
    else:
      b[i+1]+=1
    r[i+1]+=r[i]
    g[i+1]+=g[i]
    b[i+1]+=b[i]

  # print(r)
  # print(g)
  # print(b)

  ans=0
  for i,x in enumerate(s):
    for j in range(i+1,n):
      y=s[j]

      k=j+(j-i)
      if k<n:
        # print(x,y,i,j,k,s[k])
        if x=='R' and y=='G':
          ans+=b[k]-b[j]+b[n]-b[k]
        elif x=='R' and y=='B':
          ans+=g[k]-g[j]+g[n]-g[k]
        elif x=='G' and y=='B':
          ans+=r[k]-r[j]+r[n]-r[k]
        elif x=='G' and y=='R':
          ans+=b[k]-b[j]+b[n]-b[k]
        elif x=='B' and y=='R':
          ans+=g[k]-g[j]+g[n]-g[k]
        elif x=='B' and y=='G':
          ans+=r[k]-r[j]+r[n]-r[k]
        
        z=s[k]
        if j-i==k-j and len(set([x,y,z]))==3:
          ans-=1

      else:
        if x=='R' and y=='G':
          ans+=b[n]-b[j]
        elif x=='R' and y=='B':
          ans+=g[n]-g[j]
        elif x=='G' and y=='B':
          ans+=r[n]-r[j]
        elif x=='G' and y=='R':
          ans+=b[n]-b[j]
        elif x=='B' and y=='R':
          ans+=g[n]-g[j]
        elif x=='B' and y=='G':
          ans+=r[n]-r[j]

  return ans

# main()
print(main())


Measured memory_bytes: 80352
s =input()
count = 0
count_list = [0]
for i in range(len(s)):
  if s[i] == "A" or s[i] =="T" or s[i] == "C" or s[i] == "G":
    count+= 1
    count_list.append(count)
  else:
    count = 0
    
print(max(count_list))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,s=0,mx=0;
    cin>>n;
    vector<int>v;
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        v.push_back(a);
        s+=a;
    }
    sort(v.begin(),v.end());
    for(int i=0; i<n; i++)
    {
        if(s%10==0)
        {
            s-=v[i];
            if(s%10)
                mx=max(mx,s);
            s+=v[i];

        }
        if(s%10)
            mx=max(mx,s);
    }
    cout<<mx<<endl;

    return 0;
}


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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int n; cin >> n;
	int h[105];
	int ans = 0;
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	for(int i=1;i<=100;i++){
		bool flag = false;
		int cnt = 0;
		for(int j=0;j<n;j++){
			if(flag){
				if(h[j]<i){
					flag = false;
				}
			}else{
				if(h[j]>=i){
					cnt++;
					flag = true;
				}
			}
		}
		ans += cnt;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3552