akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    REP(i,5){
        int x;
        cin >> x;
        if(x==0){
            cout << i+1 << "\n";
            return 0;
        }
    }
    return 0;
}

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

int main() {
	int n;
	string str;
	int min;
	int white, black;

	cin >> n;
	cin >> str;

	white = 0;
	black = 0;

	for (int i = 0; i < n; i++) {
		if (str[i] == '#') {
			black++;
		}
		else {
			white++;
		}
	}

	int black_l;
	int white_l;
	black_l = 0;
	white_l = 0;
	//左を全部白、右を全部黒にする
	min = white;

	for (int i = 0; i < n; i++) {
		if (str[i] == '#') {
			black_l++;
		}
		else {
			white_l++;
		}

		int temp;
		temp = black_l + (white - white_l);

		if (temp < min) {
			min = temp;
		}
	}

	cout << min << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        
        while(true) {
            String input = scanner.nextLine();
            if ("0 0".equals(input)) {
                break;
            }
            
            String[] numbers = input.split(" ");
            int h = Integer.parseInt(numbers[0]);
            int w = Integer.parseInt(numbers[1]);
            
            for (int i=0; i<h; i++) {
                for (int j=0; j<w; j++) {
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 32812
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            Stack<int> stk = new Stack<int>();

            foreach (var item in input)
            {
                switch (item)
                {
                    case "+":
                        stk.Push(stk.Pop() + stk.Pop());
                        break;
                    case "-":
                        stk.Push(-stk.Pop() + stk.Pop());
                        break;
                    case "*":
                        stk.Push(stk.Pop() * stk.Pop());
                        break;
                    default:
                        stk.Push(int.Parse(item));
                        break;
                }
            }

            Console.WriteLine(stk.Pop());
        }
    }
}

Measured memory_bytes: 10156
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int ans=a*x+b*y;
    int ans2,ans3;
    if(x<y){
        ans2=2*c*x+(y-x)*b;
        ans3=2*c*y;
    }
    else{
        ans2=a*(x-y)+2*y*c;
        ans3=2*c*x;
    }
    ans=min(ans, ans2);
    ans=min(ans, ans3);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,w[110],a=110,s1=0,s2=0; cin>>n;
  for(int i=0;i<n;i++) cin>>w[i],s2+=w[i];
  for(int i=0;i<n-1;i++) s1+=w[i],s2-=w[i],a=min(a,abs(s1-s2));
  cout<<a;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=15,M=1e9+7;
int n,m,x,y,a[N][1<<N],f[1<<N],fac[N+1];
signed main(){
	scanf("%lld%lld",&n,&m);
	int sum=1;
	for (int i=1;i<=m;i++)(sum*=2)%=M;
	while (m--){
		scanf("%lld%lld",&x,&y);
		x--;y--;
		a[x][1<<y]++;
	}
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			for (int k=0;k<1<<n;k++)
				if ((1<<j)&k)a[i][k]+=a[i][k^(1<<j)];
	fac[0]=1;
	for (int i=1;i<=n;i++)fac[i]=fac[i-1]*2;
	f[0]=1;
	for (int i=0;i<1<<n;i++)
		if ((i&3)==0||(i&3)==3)
			for (int j=i;j;j=(j-1)&i){
				int k=i^j,S=f[k];
				for (int l=0;l<n;l++)
					if ((1<<l)&j)(S*=fac[a[l][k]])%=M;
				for (int l=0;l<n;l++)
					if ((1<<l)&k)(S*=fac[a[l][j]]-1)%=M;
				(f[i]+=S)%=M;
			}
	printf("%lld\n",(sum+M-f[(1<<n)-1])%M);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod = 1e9+7;
 
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};






 
int32_t main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
 

  
  
int n;
cin>>n;
vector<int>v(n+1);


for(int i=2;i<=n;i++)
{
	int x;
	cin>>x;
	v[x]++;
}
  for(int i=1;i<=n;i++)cout<<v[i]<<"\n";

}




Measured memory_bytes: 4756
#include <stdio.h>

int main(){
  int n,h,w;
  scanf("%d%d%d",&n,&h,&w);
  int ans;
  if (n < h || n < w){
    ans = 0;
  }else{
    ans = (n - h + 1) * (n - w + 1);
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    long long int N,K;
    cin >> N >> K;
    vector<long long int> hp(N);
    for(int i=0; i<N; i++){
        cin >> hp.at(i);
    }
    sort(hp.begin(),hp.end());

    if(K>=N){
        cout << 0 << endl;
    }
    else{
        long long int sum = 0;
        for(int i=0; i<N-K; i++){
            sum += hp.at(i);
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main() {
	int n,q;
	vector<int> S, T;
	cin >> n;
	int i,j;
	int ans = 0;
	for (i = 0; i < n; i++) {
		int s;
		cin >> s;
		S.push_back(s);
	}
	cin >> q;
	for (i = 0; i < q; i++) {
		int t;
		cin >> t;
		T.push_back(t);
	}
	for (i = 0; i < q; i++) {
		for (j = 0; j < n; j++) {
			if (S.at(j) == T.at(i)) {
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
}


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

AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
  A = str(input())
  if A == 'AC':
    AC += 1
  elif A == 'WA':
    WA += 1
  elif A == 'TLE':
    TLE += 1
  elif A == 'RE':
    RE += 1

print(f'''AC x {AC}''')
print(f'''WA x {WA}''')
print(f'''TLE x {TLE}''')
print(f'''RE x {RE}''')

Measured memory_bytes: 9128
import java.util.Scanner;

public class Main{

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

        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int x = scan.nextInt();

        int cnt = 0;
        for(int i=0; i<=a; i++){
            for(int j=0; j<=b; j++){
                for(int k=0; k<=c; k++){
                    if((i*500 + j*100 + k*50) == x) cnt++;
                }
            }
        }

        System.out.println(cnt);

        scan.close();
    
    }

}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(gcd(a, b));
    }

    public static int gcd(int a, int b) {
        if (a < b) {
            return gcd(b, a);
        }
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
}


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

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

	sort(S.begin(), S.end());
	for (int i = 0; i < 25; i++) {
		if (count(S.begin(), S.end(), char(97 + i)) % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		long n=sc.nextLong();
		long k=sc.nextLong();
		long ans=n%k;
		
		ans=Math.min(ans,k-ans);
		
		System.out.println(ans);
	}
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

int main() {
	int M; cin >> M;
	int p = 0;
	ll ans = 0;
	ll sum = 0;
	rep(i, M) {
		int d; ll c;
		cin >> d >> c;
		ans += c;
		sum += c * d;
	}
	--ans;
	ans += (sum - 1) / 9;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
var lines = []; var result = Infinity;
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var S = lines[1].split("");

    var dp = Array(N).fill(0)
    var sharp = Array(N).fill(0);

    sharp[0] = (S[0] === "#" ? 1 : 0);
    dp[0] = (S[0] === "." ? 1 : 0);

    for (var i = 1; i < N; i++) {
        // "#"の数を数えているだけ
        sharp[i] = sharp[i - 1] + (S[i] === "#" ? 1 : 0);
        
        // i番目の文字の時点で，dotとsharpを入れ替えの組み合わせの最小を計算
        dp[i] = Math.min(sharp[i - 1], dp[i - 1] + (S[i] === "." ? 1 : 0));
    }
    
    console.log(Math.min(sharp[N - 1], dp[N - 1]));
});


Measured memory_bytes: 13484
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
fun solve(N: Long){
    println(N*N*N)
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    solve(N)
}



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

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

int main(){
  int N,ans;
  cin>>N;
  ans=0;
  for(int i=1;i<N+1;i++){
    for(int j=1;j<N+1;j++){
      for(int k=1;k<N+1;k++){
        int gcd2=gcd(i,j);
        ans+=gcd(gcd2,k);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3644
function compareNumbers(a, b) {
  return a - b;
}

function main(input) {
  const input_array = input.split("\n");
  const cards = input_array[1].split(' ').map(x => parseInt(x, 10)).sort(compareNumbers).reverse();
  
  var alice = 0;
  var bob = 0;
  
  for(i=0; i<cards.length; i++){
    if(i%2==0){
      alice+=cards[i];
    }else{
      bob+=cards[i];
    }
  }
  
  console.log(alice-bob);
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define endl "\n"
#define INF (int)1e9
#define ll long long
#define ull unsigned long long

using namespace std;

int main()
{
    int n;
    cin >> n;

    int ok = 0;
    for (int i = 1; i <= 9; i++)
    {
        if (n % i == 0 and n / i < 10)
        {
            ok = 1;
            break;
        }
    }
    cout << (ok == 1 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;

class Main{
        public static void main(String args[]){
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int A = sc.nextInt();
                int B = sc.nextInt();
                int ans = 0,x,y;

                for(int i=1; i<=N; i++){
                        x = i;
                        y = 0;
                        while(x != 0){
                                y += x % 10;
                                x /= 10;
                        }
                        if(y >= A && y <= B){
                                ans += i;
                        }
                }
                System.out.println(ans);
        }
}


Measured memory_bytes: 21844
import java.io.*;
import java.util.*;

public class Main {
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int p = reader.nextInt();
    out.println((3 * a + p) / 2);
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Algorithm {
  private static void swap(Object[] list, int a, int b) {
    Object tmp = list[a];
    list[a] = list[b];
    list[b] = tmp;
  }
  
  public static <T extends Comparable<? super T>> boolean nextPermutation(T[] ts) {
    int rightMostAscendingOrderIndex = ts.length - 2;
    while (rightMostAscendingOrderIndex >= 0 &&
        ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostAscendingOrderIndex + 1]) >= 0) {
      rightMostAscendingOrderIndex--;
    }
    if (rightMostAscendingOrderIndex < 0) {
      return false;
    }
    
    int rightMostGreatorIndex = ts.length - 1;
    while (ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostGreatorIndex]) >= 0) {
      rightMostGreatorIndex--;
    }
    
    swap(ts, rightMostAscendingOrderIndex, rightMostGreatorIndex);
    for (int i = 0; i < (ts.length - rightMostAscendingOrderIndex - 1) / 2; i++) {
      swap(ts, rightMostAscendingOrderIndex + 1 + i, ts.length - 1 - i);
    }
    return true;
  }
}



Measured memory_bytes: 20308
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans = a*c;
  max_self(ans, a*d);
  max_self(ans, b*c);
  max_self(ans, b*d);
  cout<<ans<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 3636
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = nm[0];
			int m = nm[1];

			var map1 = new HashSet<int>();
			var mapN = new HashSet<int>();
			for (int i = 0; i < m; i++) {
				var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				int a = ab[0];
				int b = ab[1];
				if (a == 1) {
					map1.Add(b);
				}

				if (b == n) {
					mapN.Add(a);
				}
			}

			foreach (int i in map1) {
				if (mapN.Contains(i)) {
					Console.WriteLine("POSSIBLE");
					return;
				}
			}

			Console.WriteLine("IMPOSSIBLE");
		}
	}
}

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

int main(){
	ll K, X;
	cin >> K >> X;
	for (ll i = X - K + 1;i <= X + K - 1;i++) {
		cout << i;
		if (i == X + K - 1)cout << endl;else cout << " ";
	}
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]

if n == 1:
    print(1)
    exit()

b = sorted(a)
sb = []
for i in range(n-1):
    for j in range(i+1, n):
        sb.append((b[i][0] - b[j][0], b[i][1] - b[j][1]))
        
c = Counter(sb)
print(n-c.most_common()[0][1])

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};



int main()
{
  int n;
  ll a, b;
  cin >> n >> a >> b;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  ll l = 0, r = 5000000000ll;
  while(r-l > 1) {
    ll mid = l+(r-l)/2;
    ll k = 0;
    rep(i, n) if(h[i]-b*mid > 0) k += (ll)ceil((double)(h[i]-b*mid)/(a-b));
    if(k <= mid) r=mid;
    else l=mid;
  }
  cout << r << endl;
}

Measured memory_bytes: 4112
import sys
from heapq import heapify, heappop, heappush
from collections import defaultdict

def main():
    finput=lambda :sys.stdin.readline().strip()
    n,a,b=map(int,finput().split())
    h=[int(finput()) for _ in range(n)]
    gs=lambda a,b:a//b+(a%b>0)
    def enough(t):
        s=sum([max(x-t*b,0)//(a-b)+(max(x-t*b,0)%(a-b)>0) for x in h])
        if s<=t:
            return True
        else:
            return False
    #def biser(t,l):
    #    if l==0:
    #        return t
    #    t=t+l//2
    #    if enough(t):
    #        return biser(t-l//2,l//2)
    #    else:
    #        return biser(t+1,l-l//2)
    l=max(h)//b+1
    t=0
    while l>0:
        t=t+l//2
        if enough(t):
            t=t-l//2
            l=l//2
        else:
            t+=1
            l=l-l//2
    print(t)

if __name__=='__main__':
    main()



Measured memory_bytes: 17032
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> p(N);
  for(int i=0; i<N; i++){
    cin >> p[i];
    p[i]--;
  }
  vector<int> A(N),B(N);
  int suzu = 30000;
  for(int i=0; i<N; i++){
    A[i] = (i+1)*suzu;
    B[i] = (N-i)*suzu;
  }
  for(int i=0; i<N; i++){
    A[p[i]] += i;
  }
  for(int i=0; i<N; i++){
    cout << A[i] << " \n"[i+1==N];
  }
  for(int i=0; i<N; i++){
    cout << B[i] << " \n"[i+1==N];
  }
  return 0;
}

Measured memory_bytes: 3780
import java.util.*;

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

      int n = Integer.parseInt(sc.next());
      int k = Integer.parseInt(sc.next());
      int q = Integer.parseInt(sc.next());

      int[] a = new int[q];
      for(int i=0;i<q;i++){
        a[i] = Integer.parseInt(sc.next());
      }

      int[] fin = new int[n];

      //before
      for(int i=0;i<q;i++){
        fin[a[i]-1]++;
      }

      //after
      for(int i=0;i<n;i++){
        if(fin[i]>=q-k+1){
          System.out.println("Yes");
        }
        else{
          System.out.println("No");
        }
      }

    }
}


Measured memory_bytes: 60092
#include <iostream>
#define llint long long
#define inf (int)1e18

using namespace std;

int N, M;

int parent[100005];
llint difW[100005];

void init(){
	for(int i = 1; i <= N; i++){
		parent[i] = i;
		difW[i] = 0;
	}
}

int root(int i){
	if(parent[i] == i) return i;
	int pre_parent = parent[i];
	parent[i] = root(parent[i]);
	difW[i] += difW[pre_parent];
	return parent[i];
}

bool same(int i, int j){
	return root(i) == root(j);
}

void unite(int i, int j){
	int root_i = root(i);
	int root_j = root(j);
	if(root_i == root_j) return;
	parent[root_j] = root_i;
}

int difRoot(int i){
	if(root(i) == i) return 0;
	return difRoot(parent[i]) + difW[i];
}

int main(void)
{
	while(1){
		cin >> N >> M;
		if(N == 0 && M == 0) break;
		init();
		
		char c; int a, b, w;
		for(int i = 0; i < M; i++){
			cin >> c;
			if(c == '?'){
				cin >> a >> b;
				if(!same(a, b)) cout << "UNKNOWN" << endl;
				else cout << difRoot(b) - difRoot(a) << endl;
			}
			else{
				cin >> a >> b >> w;
				if(!same(a, b)){
					int root_b = root(b);
					int dif = difRoot(a) - difRoot(b) + w;
					unite(a, b);
					difW[root_b] = dif;
				}
			}
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 6328
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX 11

int main(){
    int n,mat[MAX][MAX];
    
    while(true){
        for(int i = 0 ; i < MAX ; i++)
            for(int j = 0 ; j < MAX ; j++)
                mat[i][j] = 0;
        
        cin >> n;
        if(!n) break;
        
        for(int i = 0 ; i < n ; i++)
            for(int j = 0 ; j < n ; j++)
                cin >> mat[i][j];
        
        int sum = 0;
        for(int i = 0 ; i <= n ; i++){
            for(int j = 0 ; j <= n ; j++){
                sum += mat[i][j];
                if(j == n){
                    mat[i][j] = sum;
                    sum = 0;
                }
                
            }
        }
        
        for(int j = 0 ; j <= n ; j++){
            for(int i = 0 ; i <= n ; i++){
                sum += mat[i][j];
                if(i == n){
                    mat[i][j] = sum;
                    sum = 0;
                }
            }
        }
        
        int e = 0;
        for(int i = 0 ; i < n ; i++){
            e += mat[n][i];
            if(i == n-1) mat[n][n] = e;
        }
        
        for(int i = 0 ; i <= n ; i++){
            for(int j = 0 ; j <= n ; j++){
                 printf("%5d" ,mat[i][j]);
            }
            cout << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<stack>
#include<iterator>
#include<functional>
#include<string.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//namespace mp = boost::multiprecision;

int main(){
 
  string s; cin>>s;
 vector<int>a(s.size());
 for(int i=0; i<s.size();i++){
  int num = s[i]-'0';
  a[i]=num;
  
  }
  int tmp=753;
  for(int i=0; i<s.size()-2; i++){
  	int v=a[i]*100+a[i+1]*10+a[i+2];
  	if(tmp>abs(753-v)){
  		tmp=abs(753-v);
  	}
  	}
  	cout<<tmp<<endl;
  	
  }


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    long double a;
    cin>>a;
    cout << a*6.28318530717958623200;
}

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

int N,M;
pair<pair<int,int>,pair<int,int>> p[100000];


string makeString(int i){
  string temp="";
  int num=i;
  while (num < 100000){
      temp += "0";
      num *= 10;
    }
  temp += to_string(i);
  return temp;
}
int main(){
  cin >> N >> M;
  for (int i=0; i<M;i++){
    cin >> p[i].first.first >> p[i].first.second;
    p[i].second.first = i;//brilliant idea
  }
  sort(p,p+M);
  int count = p[0].first.first,rank=1;
  for (int i=0;i<M;i++){
    if (p[i].first.first==count){
      p[i].second.second = rank;
      rank += 1;
    }
    else{
      count = p[i].first.first;
      rank = 1;
      p[i].second.second = rank;
      rank +=1;
    }
  }
  for (int i=0;i<M;i++){
    pair<int,int> &item1 = p[i].first;
    pair<int,int> &item2 = p[i].second;
    swap(item1, item2);
  }
  sort(p,p+M);
  
  for (int j=0;j<M;j++){
    int num = p[j].second.first;
    int num2 = p[j].first.second;
    cout << makeString(num) << makeString(num2);
    cout << "\n";
  }
    
  
  return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

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

int solve (int h, int w, vs g) {
  queue<pii> q;
  vector<vi> dis(h, vi(w, INF));

  rep(i, h) {
    rep(j,w) {
      if (g[i][j] == '#') {
	q.em(i, j);
	dis[i][j] = 0;
      }
    }
  }

  int max_dis = 0;
  while(q.size()) {
    pii p = q.front(); q.pop();
    int y = p.fs, x = p.sc;
    rep(d, 4) {
      int ny = y + dy[d], nx = x + dx[d];
      if (!in_range(ny, 0, h) or !in_range(nx, 0, w)) {
	continue;
      }
      if (dis[ny][nx] != INF) {
	continue;
      }
      dis[ny][nx] = dis[y][x] + 1;
      max_dis = dis[ny][nx];
      q.em(ny, nx);
    }
  }
  return max_dis;
}

int main(){
  int h, w;
  cin >> h >> w;
  vs g(h);
  rep(i, h) cin >> g[i];

  cout << solve(h, w, g) << endl;
}


Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9

int N, A, B, C, l;
vector<int> L;
int dfs(int cur, int a, int b, int c) {
  if (cur == N) {
    return a>=1 && b>=1 && c>=1 ? abs(a - A) + abs(b - B) + abs(c - C) - 30 : INF;
  }
  int result = INF;
  result = min(result, dfs(cur + 1, a, b, c));
  result = min(result, dfs(cur + 1, a + L[cur], b, c) + 10);
  result = min(result, dfs(cur + 1, a, b + L[cur], c) + 10);
  result = min(result, dfs(cur + 1, a, b, c + L[cur]) + 10);

  return result;
}

int main(){
  cin >> N >> A >> B >> C;
  L.reserve(N);
  for (int i = 0; i < N; i++) {
    cin >> l;
    L.emplace_back(l);
  }
  
  cout << dfs(0, 0, 0, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 int main(){
 	long long n,a;
 	cin>>n>>a;
 	if(n>=500){
 		if(n%500<=a){
 			cout<<"Yes"<<"\n";
 		    return 0;
 		}
 }
 else
 	if(a>=n){
 		cout<<"Yes"<<"\n";
 		return 0;
 	}
 	cout<<"No"<<"\n";
 	return 0;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int dp[100001][4][4];
int check(int a[],int b[],int c[],int last,int cur,int day){
  if(dp[day][last][cur]!=-1)return dp[day][last][cur];
  if(day==n+1)return 0;
  if(cur==1){
     dp[day][last][cur]=a[day]+max(check(a,b,c,cur,2,day+1),check(a,b,c,cur,3,day+1));
  }
  else if(cur==2){
     dp[day][last][cur]=b[day]+max(check(a,b,c,cur,1,day+1),check(a,b,c,cur,3,day+1));
  }
  else{
     dp[day][last][cur]=c[day]+max(check(a,b,c,cur,2,day+1),check(a,b,c,cur,1,day+1));
  }
  return dp[day][last][cur];
}

int main(){
  cin>>n;
  int a[n+1],b[n+1],c[n+1];
  for(int i=1;i<=n;i++){
  	cin>>a[i]>>b[i]>>c[i];
  }
  memset(dp,-1,sizeof(dp));
  int maxx=check(a,b,c,0,1,1);
  maxx=max(maxx,check(a,b,c,0,2,1));
  maxx=max(maxx,check(a,b,c,0,3,1));
  cout<<maxx<<"\n";
}


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

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i, N) cin >> L.at(i);
  
  sort(L.begin(), L.end());
  int ans = 0;
  
  rep(i, N){
   for(int j=i; j<N; j++){
     if(L.at(i) != L.at(j)){ 
      for(int k=j; k<N; k++){
       if(L.at(i) != L.at(k) && L.at(j) != L.at(k) && L.at(i)+L.at(j) > L.at(k))
         ans++;
      }
     }
   }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

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

int main() {
        int n;
        while (scanf("%d", &n), n) {
                vector<pair<int, int>> p(n);
                p[0] = make_pair(0, 0);
                for (int i = 1; i < n; i ++) {
                        int a, d;
                        scanf("%d%d", &a, &d);
                        int y = p[a].first + dy[d];
                        int x = p[a].second + dx[d];
                        p[i] = make_pair(y, x);
                }
                int xma = -500, xmi = 500, yma = -500, ymi = 500;
                for (int i = 0; i < n; i ++) {
                        int y = p[i].first, x = p[i].second;
                        xma = max(xma, x);
                        xmi = min(xmi, x);
                        yma = max(yma, y);
                        ymi = min(ymi, y);
                }
                printf("%d %d\n", xma - xmi + 1, yma - ymi + 1);
        }
        return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int A[100000], B[100000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];
    unsigned long long ans = 0;
    for(int i=N-1; i>=0; i--){
        unsigned long long tmp = (A[i]+ans) % B[i];
        if(tmp == 0) continue;
        else{
            unsigned long long tmp2 = (A[i] + ans) / B[i];
            ans += (tmp2+1)*B[i] - (A[i] + ans);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1e9 + 5;
int main(){
	int N, K;
    cin >> N >> K;
    vector<int> heights(N); 
    vector<int> dp(N, INF);
  for(int i = 0 ;i < N; i++){
  	cin >> heights[i];
  }
  dp[0] = 0;
  for(int i = 0; i < N; i++){
  	for(int j = i + 1; j <= i + K; j++){
    	if(j < N){
        	 dp[j] = min(dp[j], abs(heights[i] - heights[j]) + dp[i]);
        }
    }
   
    
    
  }
  
  cout << dp[N-1] << endl;
  
  
}


Measured memory_bytes: 1024
#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 Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll, ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const int sz=1e3+100;
bool cmp(PII a,PII b)
{
    if(a.s==b.s) return a.f<b.f;
    return a.s<b.s;
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n)
    { 
        PII ara[n];
        for(i=0;i<n;i++) cin>>ara[i].f>>ara[i].s;
 
    sort(ara,ara+n,cmp);
    ll time=0;
    bl=true;
    for(i=0;i<n;i++)
    {
        if(time+ara[i].f<=ara[i].s){
            time+=ara[i].f;
        }
        else{
            bl=false;
            break;
        }
    }
 
    if(bl) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    }
 
 
 
}

Measured memory_bytes: 3328
# https://atcoder.jp/contests/abc110/tasks/abc110_b
n, m, x, y = [int(x) for x in input().split()]
xc = [int(x) for x in input().split()]
yc = [int(x) for x in input().split()]
if min(yc) - max(xc) < 1:
    print("War")
    exit()
if (y - max(xc) < 1) or (min(yc) - x < 1):
    print("War")
    exit()
print("No War")


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();

        int count = 0;
        for (int i = 0; i < n - 2; i++) {
            if (s.substring(i, i + 3).equals("ABC")) {
                count++;
            }
        }

        System.out.println(count);
    }
}


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

#define ll long long int
#define ld long double
#define pb push_back

ll mod = 1000000007;

using namespace std;

int main()
{
	
	 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	 
	int n;
	int l;
	cin>>n>>l;
	int arr[n];
	ll sum = 0;
	for (int i = 0; i < n; ++i)
	{
		arr[i] = l + i;
		sum += arr[i];
	}

	int mini = INT_MAX;
	ll ans ;

	for (int i = 0; i < n; ++i)
	{
		ll temp = sum - arr[i];
		ll diff = abs(sum - temp);
		if(mini > diff)
		{
			ans =  temp;
			mini = diff;
		}
	}

	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = []
for i in range(n):
    d.append(list(map(int, input().split())))
judge = 'No'
c = 0
for j in range(n):
    if d[j][0] == d[j][1]:
        c += 1
    else:
        c = 0
    if c >= 3:
        judge = 'Yes'
print(judge)

Measured memory_bytes: 9188
import Control.Monad
import qualified Data.Map as M

main = do
 n <- read <$> getLine :: IO Int
 aList <- replicateM n (read <$> getLine) :: IO [Int]
 let l = M.fromList $ zip [0..] $ scanl max 0 aList
 let r = M.fromList $ zip [0..] $ scanr max 0 aList
 mapM_ print $ [ max (l M.! i) (r M.! (i+1)) | i <- [0..(n-1)] ]

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

int main() {
    char s[2*100001], t[2*100001];
    int i;
    int ans=0;
    scanf("%s", s);
    scanf("%s", t);
    for (i=0;i<strlen(s);i++) {
        if (s[i]!=t[i]) ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2120
// https://atcoder.jp/contests/abc123/tasks/abc123_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> v(6);
    bool flag = true;

    for (int i = 0; i < 6; i++) {
        cin >> v[i];
    }
    if (v[4] - v[0] <= v[5]) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#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 INF 2e+9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    int n;  cin >> n;

    vector<int> x(n);
    REP(i, n)
    {
        cin >> x[i];
    }

    ll sum_hp=INF;

    for(int p=1; p<=100; p++)
    {
        ll reg=0;
        REP(i, n)
        {
            reg += (x[i]-p)*(x[i]-p);
        }
        sum_hp = min(sum_hp, reg);
 //       cout << "sum_hp = " << sum_hp <<endl;
    }

    cout << sum_hp << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void call( int x );

int main( void )
{
	int x;
	
    scanf("%d", &x);
    
	call( x );
	
    return 0;
}

void call( int n )
{
	int x;
	int i = 1;
	
	do{
		x = i;
		
		if( x % 3 == 0 ){
			printf(" %d", i);
		}
		else{
			do{
				if( x % 10 == 3 ){
					printf(" %d", i);
					break;
				}
				x /= 10;
			}while( x );
		}
	}while( ++i <= n );
	
	printf("\n");
}

Measured memory_bytes: 600
import java.util.*;
public class Main {
	static int A[],Big[],Small[];
	static boolean bi=false,sm=false;
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=Integer.parseInt(in.next());A=new int[n];
		for(int i=0;i<n;i++)A[i]=Integer.parseInt(in.next());
		Big=A.clone(); Small=A.clone();
		if(smaller(n-2)){
			for(int i=0;i<n-1;i++)System.out.print(Small[i]+" ");
			System.out.println(Small[n-1]);
		}
		
		for(int i=0;i<n-1;i++)System.out.print(A[i]+" ");
		System.out.println(A[n-1]);
		
		if(bigger(n-2)) {
			for(int i=0;i<n-1;i++)System.out.print(Big[i]+" ");
			System.out.println(Big[n-1]);
		}
	}
	
	static boolean smaller(int p) {
		//System.out.println(p);
		if(p<0)return false;
		int min=A[A.length-1];
		for(int i=A.length-2;i>p;i--) {
			min=Math.min(min, A[i]);
		}
		//System.out.println(min+" "+A[p]);
		if(min>A[p])return smaller(--p);
		else {
			List<Integer> T=new ArrayList<>();
			for(int i=A.length-1;i>=p;i--)T.add(A[i]);
			Collections.sort(T,Collections.reverseOrder());
			for(int i=0;i<T.size();i++) {
				if(T.get(i)==A[p]) {
					Small[p]=T.get(i+1); T.remove(i+1);
				}
			}
			for(int i=0;i<T.size();i++)Small[p+1+i]=T.get(i);
			return true;
		}
	}
	
	static boolean bigger(int p) {
		//System.out.println(p);
		if(p<0)return false;
		int max=A[A.length-1];
		for(int i=A.length-2;i>p;i--) {
			max=Math.max(max, A[i]);
		}
		//System.out.println(max+" "+A[p]);
		if(max<A[p])return bigger(--p);
		else {
			List<Integer> T=new ArrayList<>();
			for(int i=A.length-1;i>=p;i--)T.add(A[i]);
			Collections.sort(T);
			for(int i=0;i<T.size();i++) {
				if(T.get(i)==A[p]) {
					Big[p]=T.get(i+1); T.remove(i+1);
					break;
				}
			}
			for(int i=0;i<T.size();i++)Big[p+1+i]=T.get(i);
			return true;
		}
	}

}



Measured memory_bytes: 26340
//It's really tough
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mem(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
const int N = 2e5 + 5;
const ll inf = 9e18 + 9;
const int mod = 1e9+7;
ll res;

void solve()
{
     long long n;
	int x, m;
	cin >> n >> x >> m;
	int prv = x;
	vector<bool> vis(m);
	vector<int> rep; rep.reserve((int) 1e6);
	while (!vis[prv]) {
		vis[prv] = 1;
		rep.push_back(prv);
		prv = (long long) prv * prv % m;
	}
	int i = 0;
	long long ans = 0;
	for (; i < (int) rep.size() && n; ++i) {
		if (rep[i] == prv) break;
		ans += rep[i];
		--n;
	}
	int period = (int) rep.size() - i;
	long long divs = n / period;
	int left = n % period;
	ans += ((long long) divs * accumulate(rep.begin() + i, rep.end(), (long long) 0) +
		accumulate(rep.begin() + i, rep.begin() + i + left, (long long) 0));
	cout << ans << endl;
}
 
int main()
{
    IOS;ll t = 1;
    // cin>>t;
    for(int i=1;i<=t;i++)
    {
        solve();
    }
}

Measured memory_bytes: 3656
Imports System.Collections.Generic
Imports System.Console
Imports System.Math  
Module Program
 	Sub Main()
 	    Dim inputs as String()
        inputs = Console.ReadLine().Split(" ")
	    Dim N As Integer = inputs(0)
	    Dim M As Integer = inputs(1)
	    Dim X As Integer = inputs(2)
	    Dim Y As Integer = inputs(3)

	    Dim maxX As Integer = X
	    Dim minY As Integer = Y
	    
 	    Dim xs as String()
        xs = Console.ReadLine().Split(" ")
        For i As Integer = 0 to N-1
     	    Dim x as Integer = xs(i)
            maxX = Math.Max(maxX, x)
        Next

 	    Dim ys as String()
        ys = Console.ReadLine().Split(" ")
        For i As Integer = 0 to M-1
            Dim y as Integer = ys(i)
            minY = Math.Min(minY, y)
        Next
	    
        Console.WriteLine(IIf(maxX >= minY, "War", "No War"))
    End Sub
End Module


Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int C[4] = {0, 4, 6, 8};
string A = "AKIHABARA";

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    vector<string> T;
    int K = pow(2, 4) + 0.5;
    rep(i, K) {
        int bit = i;
        string R;
        rep(j, 9) {
            bool conclude = false;
            rep(k, 4) if (C[k] == j) conclude = true;
            if(conclude) {
                if (bit % 2 == 1)  R.push_back(A[j]);
                bit /= 2;
            }
            else R.push_back(A[j]);
        }
        T.push_back(R);
    }
    rep(i, T.size()) {
        //cout << T[i] << endl;
        if (S == T[i]) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <functional>
#include "math.h"
#include <set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MB 1000000007
#define NB 1000000000
#define N5 100007
#define ll long long int
int N;
int H[N5],dp[N5];

int main()
{

	cin >>N;
	REP(i,N){
		cin >> H[i];
	}
	dp[0] = 0;
	dp[1] = abs(H[1] - H[0]);
	FOR(i,2,N){
		dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]));
	}

	cout << dp[N-1];
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
class Solution
{
    static void Main(string[] args)
    {
        List<int> data = new List<int>();
        int n = int.Parse(System.Console.ReadLine().Trim()),sum=0;
        for (int i = 0; i < n; i++) 
        {
            int x =int.Parse(System.Console.ReadLine().Trim());
            data.Add(x);
            sum += x;
        }
        data.Sort((a, b) => a-b);
        int pos = -1,kai=0;
        if (sum % 10 == 0)
        {
            for(int i = 0;i<data.Count;i++)
            {
                if (data[i] % 10 != 0) { pos = i; break; }
            }
            if (pos == -1) kai = 0;
            else kai = sum - data[pos];
        }
        else
        {
            kai = sum;
        }
        System.Console.WriteLine(kai);
        System.Console.ReadLine();
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;long long int b=0,K;cin>>T>>K;
  S=T;
  for(int i=1;i<S.size();i++)if(S.at(i-1)==S.at(i)){
    S.at(i)='-';b++;
  }
  S=T;
  sort(S.begin(),S.end());
  if(S.at(0)==S.at(S.size()-1))cout<<T.size()*K/2<<endl;
  else if(T.at(0)!=T.at(T.size()-1))cout<<b*K<<endl;
  else{
    long long int i=1,j=1,x,y,z;
    while(i<T.size()&&T.at(0)==T.at(i))i++;
    while(j<T.size()&&T.at(0)==T.at(T.size()-j-1))j++;
    x=i/2,y=j/2,z=(i+j)/2;
    cout<<b*K-(x+y-z)*(K-1)<<endl;
  }
}

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

int n,a[200010]; 

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	set<int> s;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		s.insert(a[i]);
	}
	if(s.size()==n) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 10368