akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{    
    class DisjoinSet
    {

        public DisjoinSet() { }

        static int[] rank;  
        static int[] p; 

        public DisjoinSet(int n)
        {
            MakeSet(n);
        }

        static void MakeSet(int n)
        {
            p = new int[n];
            rank = new int[n];
            for(int i = 0; i < n; i++)
            {
                p[i] = i;  
            }           
        }

        public void Unite(int x, int y)
        {
            Linke(FindSet(x), FindSet(y));
        }


        
        public void Linke(int x, int y)
        {
            if(rank[x] < rank[y])
            {
                p[x] = y;
            }
            else
            {
                p[y] = x;
                if(rank[x] == rank[y])
                {
                    rank[x]++;
                }
            }

        }


       
        public bool Same(int x, int y)
        {
            return FindSet(x) == FindSet(y);
        }


        
        public int FindSet(int x)
        {
            
            if(x != p[x])
            {
                p[x] = FindSet(p[x]);
            }
            return p[x];
        }

    }


    
    class Program
    {
        
       
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int q = int.Parse(input[1]);
            int x;
            int y;
            int order;

            DisjoinSet a = new DisjoinSet(n);

            for(int i = 0; i < q; i++)
            {
                input = Console.ReadLine().Split(' ');
                order = int.Parse(input[0]);
                x = int.Parse(input[1]);
                y = int.Parse(input[2]);

                if(order == 0)
                {
                    a.Unite(x, y);
                }
                else if(order == 1)
                {
                    if(a.Same(x, y))
                    {
                        Console.WriteLine(1);
                    }
                    else
                    {
                        Console.WriteLine(0);
                    }
                }
            }



        }
    }
}



Measured memory_bytes: 22128
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int maxn = 505, mod = 924844033;
int n, a[maxn], ans[maxn*maxn];
vector<pair<int, int>> add[maxn*maxn];
multiset<pair<int, int>> x;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		if(ans[a[i]]) return cout << "No", 0;
		ans[a[i]] = i;
		for(int j = 1; j < i; j++) add[1].pb({a[i], i});
		for(int j = i; j < n; j++) add[a[i]].pb({1<<30, i});
	}
	for(int i = 1; i <= n*n; i++) {
		for(auto j : add[i]) x.insert(j);
		if(ans[i]) continue;
		if(x.empty()) return cout << "No", 0;
		ans[i] = x.begin()->second;
		x.erase(x.begin());
	}
	for(int i = 1; i <= n; i++) {
		int cnt = 0;
		for(int j = 1; j <= a[i]; j++) {
			cnt += ans[j] == i;
		}
		if(cnt != i) return cout << "No", 0;
	}
	cout << "Yes\n";
	for(int i = 1; i <= n*n; i++) cout << ans[i] << " ";
}


Measured memory_bytes: 21236
//#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>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T> V<T> prefix_sum(const V<T>& v) {
  int n = v.size();
  V<T> ret(n + 1);
  rep(i, 0, n) ret[i + 1] = ret[i] + v[i];
  return ret;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  V<ll> v(4);
  rep(i,0,4)cin>>v[i];

  ll ans=-LINF;
  rep(i,0,2)rep(j,2,4)chmax(ans,v[i]*v[j]);
  cout<<ans<<ENDL;
  
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3652
#include<stdio.h>
int n,A[50];
int solve(int i,int m){
 if(m==0)return 1;
 if(i>=n)return 0;
 return solve(i+1,m)||solve(i+1,m-A[i]);
}
int main(){
 int q,M,i;
 scanf("%d",&n);
 for(i=0;i<n;i++)scanf("%d",&A[i]);
 scanf("%d",&q);
 for(i=0;i<q;i++){
  scanf("%d",&M);
  if(solve(0,M))printf("yes\n");
  else printf("no\n");
 }
 return 0;
}


Measured memory_bytes: 2072
#include<stdio.h>

int main(){
  long N,M,ans=0;
  scanf("%ld%ld",&N,&M);

  if (N<M)
  {
    while (N>0){ N--; M-=2; ans++;}
    if(M>3){ ans+=M/4; }
  }else{
    ans+=M/2;
  }

  printf("%ld",ans);

  return 0;
}

Measured memory_bytes: 1664
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (x, a) = {
    let v: Vec<u64> = read_vec();
    (v[0], v[1])
  };

  if x < a {
    println!("{}", 0);
  } else {
    println!("{}", 10);
  }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double N;
  cin >> N;
  
  if(int(N) % 2 == 0){
  	cout << (N/2) / N << endl;
  }else{
  	cout << ((N+1)/2) / N << endl;
  }
}

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

#define int long long

signed main()
{
	int x,y,a,b,c,s=0;
	cin >> x >> y >> a >> b >> c;
	priority_queue<pair<int,int> > h;
	
	while(a--)
	{
	    int war;
	    cin >> war;
	    h.push(make_pair(war,1));
	}
	
	while(b--)
	{
	    int war;
	    cin >> war;
	    h.push(make_pair(war,2));
	}
	while(c--)
	{
	    int war;
	    cin >> war;
	    h.push(make_pair(war,3));
	}
	int z=x+y;
	int san=0;
	while (z)
	{
		pair<int,int> f=h.top();
		h.pop();
		if (f.second==3){
			san+=f.first;
			--z;
		}
		else if (f.second==1 && x){
			san+=f.first;
			--x;
			--z;
		}
		else if (f.second==2 && y){
			san+=f.first;
			--y;
			--z;
		}
	}
	cout << san;
	return 0;
}



Measured memory_bytes: 10604
n = int(input())
a = list(map(int, input().split()))
L = len(format(max(a), 'b'))
x = [0 for i in range(L)]
ans = 0
MOD = 10 ** 9 + 7
for i in a:
    i_str = list(format(i, '0' + str(L) + 'b'))[::-1]
    for j, s in enumerate(i_str):
        if s == '1':
            x[j] += 1
b = 1
for i, xi in enumerate(x):
    ans += xi * (n - xi) * b % MOD
    ans %= MOD
    b *= 2
    b %= MOD
print(ans)


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

int modpow(int a, int n) {
    int mod = 1e9+7;
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


signed main(void){
    int MOD = 1000000007;
    int n; cin >> n;
    vector<int>one(100,0),zero(100,0);
    for(int i=0;i<n;i++){
        int a; cin >> a;
        int j=0;
        // cout << "ok" << endl;
        while(0<(a>>j)){
            if(((a>>j)&1)==1){
                one[j]++;
            }else{
                zero[j]++;
            }
            j++;
        }
    }
    int ans = 0;
    for(int i=0;i<100;i++){
        if (one[i]!=0) zero[i] = n - one[i];
        // cout << one[i] << ' ' << zero[i] <<' ' << ans <<  endl;
        ans = (ans + (((one[i]*zero[i])%MOD)*modpow(2,i))%MOD)%MOD;
        // if(ans < 0) cout << ((one[i]*zero[i])%MOD) <<' ' <<  (int)pow(2,i) << ' ' << (((one[i]*zero[i])%MOD)*(int)pow(2,i))%MOD<< endl;
    }
    cout << ans << endl;
    return 0;
}

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

signed main() {
	cout << "square1001" << endl;

	return 0;
}



Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const LL MOD = 1000000007LL;
int dp[300][301][301];
int main() {
	string S;
	cin >> S;
	int K;
	cin >> K;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j <= K; j++) dp[i][i + 1][j] = 1;
	}
	for (int len = 2; len <= S.size(); len++) {
		for (int i = 0; i + len <= S.size(); i++) {
			for (int j = 0; j <= K; j++) {
				if (S[i] == S[i + len - 1]) {
					dp[i][i + len][j] = max(dp[i][i + len][j], dp[i + 1][i + len - 1][j] + 2);
				}
				dp[i][i + len][j] = max(dp[i][i + len][j], dp[i + 1][i + len][j]);
				dp[i][i + len][j] = max(dp[i][i + len][j], dp[i][i + len - 1][j]);
				if (j > 0) {
					dp[i][i + len][j] = max(dp[i][i + len][j], dp[i + 1][i + len - 1][j - 1] + 2);
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <= K; i++) ans = max(ans, dp[0][S.size()][i]);
	cout << ans << endl;
}

Measured memory_bytes: 104832
n,k,s=map(int,input().split())

if s!=10**9:
    a=[]
    for i in range(k):
        a.append(s)
    for g in range(n-k):
        a.append(10**9)
else:
    a=[]
    for i in range(k):
        a.append(s)
    for g in range(n-k):
        a.append(1)

print(*a)

Measured memory_bytes: 6720
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;



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

	int num = (s[0] - '0') *100 + (s[1]- '0') * 10 + (s[2]- '0');
	int l = s.length();
	int min_diff =  753;
	rep(i,3, l - 1)
	{
		min_diff = min(min_diff, abs(753 - num));
		num = num - 100 * (s[i-3] - '0');
		num = num * 10 + (s[i] - '0');
	}
	cout<< min(min_diff, abs(753 - num));

}


Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main(){
  string S;
  cin >> S;
  string ans;
  bool a, b, c;
  int cnt = 0;
  a = (S[0] == 'A');
  int cu = 0;

  for(int i=2;i<S.size()-1;i++){
    if(S[i] == 'C'){
      cnt++;
      cu = i;
    }
  }
  if(cnt == 1){
    c = true;
  }else{
    c = false;
  }

  for(int i=1;i<S.size();i++){
    if((S[i]<'a' || 'z'<S[i]) && i !=cu){
      b = false; 
      break;
    }
    if(i == S.size() - 1){
      b = true;
    }
  } 

  if(a && b && c){
    ans = "AC";
  }else{
    ans = "WA";
  }
  cout << ans <<"\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))

    li = [0]*N

    for a in A:
        li[a-1] += 1
    
    for l in li:
        print(l)


if __name__ == '__main__':
    main()

Measured memory_bytes: 92472
#include<algorithm>
#include<string.h>
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	
	for(int i=0;i<s.size();++i)
		cout<<(s[i]+n<='Z' ? char(s[i]+n) : char(s[i]+n-26));
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
while True:
    max_p = 0
    x = 0
    n = int(input())
    if n == 0:
        break
    y = int(input())
    l = [list(map(int,input().split())) for i in range(n)]

    for i in range(n):

        if l[i][2] == 1:
            p = 1 + ( y * l[i][1]/100)
        else:
            p = (1 + l[i][1]/100) ** y

        if p > max_p:
            max_p = p
            x = l[i][0]

    print(x)


Measured memory_bytes: 5688
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	
	public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);
		Queue<Integer> queue = new ArrayDeque<Integer>();
		Queue<String> name = new ArrayDeque<String>();
		int N = sc.nextInt();
		int q = sc.nextInt();
		int tlen = 0;
		for (int i=0; i<N; i++) {
			name.add(sc.next());
			queue.add(sc.nextInt());
		}
		
		while (queue.size()!=0) {
			
			if (queue.element() > q){
				tlen += q;
				queue.add(queue.element() - q);
				queue.remove();
				name.add(name.element());
				name.remove();
			} else {
				tlen += queue.element();
				System.out.println(name.element()+" "+tlen);
				queue.remove();
				name.remove();
			}
		}
	}	
}


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

const long long MOD = 1e9 + 7;
const long long MAX = 1e6;
long long fact[MAX + 1] = {0};

void fact_init(){
    for(long long i = 1;i <= MAX;i++){
        fact[i] = (fact[i - 1] * i % MOD) % MOD;
    }
}

long long repeat_fact(long long N,long long P){
    if(P == 0) return 1;
    if(P % 2 == 0){
        long long t = repeat_fact(N,P/2);
        return (t%MOD * t % MOD ) % MOD;
    }else return (N % MOD * repeat_fact(N,P-1)) %MOD;
}

void solve(long long X, long long Y){
    long long a = (X + Y) / 3;
    long long x = X - a;
    long long y = Y - a;
    if(x >= 0 and y >= 0){
        long long fact1 = fact[x + y];
        long long fact2 = repeat_fact(fact[x],MOD - 2);
        long long fact3 = repeat_fact(fact[y],MOD - 2);
        long long ans = ((fact1 * fact2) % MOD * fact3) % MOD;
        cout << ans << endl;
        return;
    }else{
        cout << 0 << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    fact[0] = 1;
    fact_init();
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    if((X + Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 8064
#include<stdio.h>

int main(void) {
int H,W;
int x,y;

while(scanf("%d %d", &H, &W), (H+W) != 0) {
for (x = 0; x < H; x++) {
for (y = 0; y < W; y++) {
printf("#");
}
printf("\n");
}
printf("\n");
}

return (0);
}

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

int cost[11][11];
int arr[2000][2000];

int main(){

    int n, m, i, j, k, x, y, sum=0;

    cin>>n>>m;
    for(i=1; i<=10; i++){
        for(j=1; j<=10; j++){
            cin>>cost[i][j];
        }
    }
    for(i=1; i<=n; i++){
        for(j=1; j<=m; j++){
            cin>>arr[i][j];
        }
    }

      for(k=1; k<=10; k++){
        for(i=1; i<=10; i++){
            for(j=1; j<=10; j++){
                    if(cost[i][j]>cost[i][k]+cost[k][j]){
                        cost[i][j]=cost[i][k]+cost[k][j];
                    }
                }
            }
        }

    for(i=1; i<=n; i++){
        for(j=1; j<=m; j++){
            if(arr[i][j]!=-1)
                sum+=cost[arr[i][j]+1][2];
        }
    }
    cout<<sum<<endl;




    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int ans = a * b;
    if(ans % 2 == 0){
        cout << "Even" << endl;
    }
    else{
        cout << "Odd" << endl;
    }
    
}

Measured memory_bytes: 256
Dice = Struct.new(:top, :front, :right, :left, :back, :bottom) do
    def roll(x)
        case x
        when "E"
            k = self.top
            self.top = self.left
            self.left = self.bottom
            self.bottom = self.right
            self.right = k
        when "N"
            k = self.top
            self.top = self.front
            self.front = self.bottom
            self.bottom = self.back
            self.back = k
        when "S"
            k = self.top
            self.top = self.back
            self.back = self.bottom
            self.bottom = self.front
            self.front = k
        when "W"
            k = self.top
            self.top = self.right
            self.right = self.bottom
            self.bottom = self.left
            self.left =k
        end
    end
    
    def twist
        k = self.front
        self.front = self.right
        self.right = self.back
        self.back = self.left
        self.left = k
    end
end

dice_ary = []
dice_tmp = Dice.new

n = gets.to_i

n.times{|i|
    tmp = Dice.new
    tmp.top, tmp.front, tmp.right, tmp.left, tmp.back, tmp.bottom = gets.split
    dice_ary.push(tmp)
}

founded = false

ary = ["","N","W","E","S","NN"]

for i in 1..(dice_ary.length - 1)
    for c in ary 
        dice_tmp = dice_ary[i].dup
        if c != "" then
            for x in c.split("")
                dice_tmp.roll(x)
            end
        end
        4.times{
            dice_tmp.twist
            if dice_ary[0] == dice_tmp then
                founded = true
                break
            end
        }
    end
end

if !founded then
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 7260
#include <stdio.h>
#include <math.h>

int main(void){
    int n;
    int t[100005],x[100005],y[100005];
    int can=1;
    scanf("%d",&n);
    t[0]=0,x[0]=0,y[0]=0;
    for(int i=1; i<=n; i++){
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
    }

    for(int i=1; i<=n; i++){
        if((t[i]-t[i-1]) < (abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))){
            can=0;
            break;
        }
        if((t[i]-t[i-1])%2 != (abs(x[i]-x[i-1]+abs(y[i]-y[i-1])))%2 ){
            can=0;
            break;
        }
    }
    if(can)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

pi expr(), term();
string s;
int p;
pi digit(){
	int d = 0;
	while(p < s.size() && isdigit(s[p])){
		d *= 2; d += s[p++] - '0';
		if(d >= 1 << 10) throw "bigdigit";
	}
	return mp(d, 0);
}
pi expr(){
	pi a = term();
	while(p < s.size() && (s[p] == '+' || s[p] == '-')){
		bool pr = s[p++] == '+';
		pi b = term();
		a.first = a.first + (pr ? b.first : -b.first);
		a.second = 1;
		if(a.first < 0 || a.first >= 1 << 10) throw "overflow";
	}
	return a;
}
pi term(){
	pi a = mp(1, 0);
	int fac = 0;
	p--;
	do{
		if(++p >= s.size()) throw "syntaxerorr";
		
		pi b;
		if(isdigit(s[p])) b = digit();
		else if(s[p] == '('){
			p++;
			b = expr();
			if(!b.second) throw "(())";
			if(s[p++] != ')') throw "closep";
		}
		else throw "syntaxerror";
		a.first *= b.first;
		if(a.first >= 1 << 10) throw "overflow";
		fac++;
	}while(p < s.size() && s[p] == '*');
	return mp(a.first, fac > 1);
}

int main(){
	cin >> s;
	vi v;
	rep(i, s.size()) if(s[i] == '.') v.pb(i);
	int pw[10], ans = -1;
	pw[0] = 1;
	rep(i, 9) pw[i + 1] = pw[i] * 7;
	
	rep(i, pw[v.size()]){
		rep(j, v.size()) s[v[j]] = "01+-*()"[i / pw[j] % 7];
		p = 0;
		try{
			pi res = expr();
			if(p < s.size()) throw "syntaxerror";
			ans = max(ans, res.first);
		}catch(const char *e){
			
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b, c, d, e ,f;
    cin >> a >> b >> c >> d >> e >> f;

    double per = 0.0;
    int wa = a * 100;
    int su = 0;

    double lim = double(e) / (100 + e);
    for(int ia = 0; ia*a*100 <= f; ia++){
        for(int ib = 0; ia*a*100 + ib*b*100 <= f; ib++){
            for(int ic = 0; ic*c+ ia*a*100 + ib*b*100 <= f; ic++){
                for(int id = 0; id*d+ic*c+ia*a*100+ib*b*100 <= f; id++){
                    int w = ia*a*100 + ib*b*100;
                    int s = id*d+ic*c;
                    double p = double(s) /(w+s);
                    if(p > per && p <= lim){
                        per = p;
                        wa = w + s;
                        su = s;
                    }
                }
            }
        }
    }

    cout << wa << " " << su << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	x := getNextInt(scanner)
	y := getNextInt(scanner)

	mx := -101
	my := 101

	for i := 0; i < n; i++ {
		xx := getNextInt(scanner)
		if mx < xx {
			mx = xx
		}
	}

	for i := 0; i < m; i++ {
		yy := getNextInt(scanner)
		if my > yy {
			my = yy
		}
	}

	ans := "War"
	if mx < y && mx < my && x < my {
		ans = "No War"
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string>

long long solve(std::string str)
{
  long long ans = 0;
  int cnt = 0;
  int len = str.size();
  for (int i = 0; i < len; i++) {
    if (str[i] == 'W') {
      ans += (i - cnt);
      cnt++;
    }
  }
  return ans;
}

int main()
{
  std::string S = "";
  std::cin >> S;
  printf("%lld\n", solve(S));
  return 0;
}


Measured memory_bytes: 772
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
#define itn int
#define all(c) c.begin(),c.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;
 
const ll MAX_N = 2e5 + 5, inf = 1e18, mod = 1000000007;
const double PI = 3.1415926536;
int days[13] = {0, 31, 28, 31, 30, 31,30, 31, 31, 30, 31, 30, 31};
 
template<typename T>
ostream& operator <<(ostream& out, const vector<T>& mas) {
    for (const auto& x : mas) {
        out << x << ' ';
    }
    return out;
}
 
void ok() {
    cout << "Yes" << '\n';
}
 
void no() {
    cout << "No" << '\n';
}
 
inline ll nxt() {
    ll x;
    cin >> x;
    return x;
} 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int a = nxt(), b = nxt();
    for (int i = 1; i <= 1000000; i++) {
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            cout << i;
            return 0;
        } 
    }
    cout << -1;
    return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int M = N;
        int S = 0;
        while (M > 0)
        {
            S += M % 10;
            M /= 10;
        }
        if (N % S == 0)
        {
            WriteLine("Yes");
        }
        else
        {
            WriteLine("No");
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11092
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
A,B,H,M = map(int, input().split())

time = H*60 + M
Arad = (M%60) * 2*math.pi/60
Brad = time * 2*math.pi/720

h = ((A*math.cos(Arad) - B*math.cos(Brad))**2 + (A*math.sin(Arad) - B*math.sin(Brad))**2)**0.5
print(h)

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

int N;
const int MAX_N = 1.0e5 + 100;
int t[MAX_N], x[MAX_N], y[MAX_N];

int main() {
    cin >> N;
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    for (int i = 1; i <= N; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    
    bool f = true;
    for (int i = 1; i <= N; i++) {
        int dt = t[i] - t[i-1];
        int dx = x[i] - x[i-1];
        int dy = y[i] - y[i-1];

        if (dt % 2 != abs(dx + dy) % 2 || dt < abs(dx + dy)) {
            f = false;
            break;
        }
    }

    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s, t;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s >> t;
    rep(i, 0, 3) {
        if (s[i] != t[3-i-1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

void solve() {
        int n; cin >> n;
        vector<string> v= {"AC", "WA", "TLE", "RE"};
        map<string, int> mp;
        while (n--) {
                string an; cin >> an;
                mp[an]++;
        }
        lp(i, v.size()) {
                cout << v[i]<< " x "<< mp[v[i]]<< "\n";
        }
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int t = 1;
        //cin >> t;
        while ( t-- ) {
                solve();
        }
return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
 
int main(){
    long long int a;
    scanf("%lld",&a);
 
    char name[100];
    int i = 0;
    
    while(a != 0) {
        a--;
        int b = a % 26;
        name[i] ='a' + b;
        a /= 26;
        i++;
    }
    for(int j = i - 1; j >= 0; j--) {
        printf("%c", name[j]);
    }   
    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prd(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 2e18+10;
const int Mod = 1e9+7;
const int MAXN = 1000010;
const int N=2e5+10;
const int M=210;
const int M1=1e9+7;
const int M2=1e9+9;
const int base=131;
int parent[N],n,m;

int find(int x)
{
  int root=x;
  //identify the root
  while(parent[root]>=0) root=parent[root];
  //path compression
  while(x!=root)
  {
    int old=x;
    x=parent[x];
    parent[old]=root;
  }
  return root;
}
bool merge(int x,int y)
{
  //identify roots
  x=find(x);
  y=find(y);
  if(x==y) return false;
  //parent[x] is the negated size of set containing x.
  if(parent[x]>parent[y]) swap(x,y);
  parent[x]+=parent[y];
  parent[y]=x;
  return true;
}

int main()
{
  ios::sync_with_stdio(0), cin.tie(0); cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  memset(parent,-1,sizeof(parent));
  cin>>n>>m;
  for(int i=1;i<=m;i++)
  {
    int u,v;
    cin>>u>>v;
    merge(u,v);
  }
  int ans=inf;
  for(int i=1;i<=n;i++)
  {
    if(parent[i]<0)
    {
      ans=min(ans,parent[i]);
    }
  }
  ans=-1*ans;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4384
#include<iostream>
using namespace std;
int main(){
	long long n;
	cin>>n;
	n%=10;
	if(n==2||n==4||n==5||n==7||n==9) cout<<"hon"<<endl;
	else if(n==0||n==1||n==6||n==8) cout<<"pon"<<endl;
	else cout<<"bon"<<endl;
} 

Measured memory_bytes: 3564
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	string s;cin>>s;
	ll n=s.size();
	ll dp[n][13]={0};
	if(s[0]=='?'){
		for(ll i=0;i<10;i++)dp[0][i]=1;
	}
	else{
		dp[0][s[0]-'0']=1;
	}
	for(ll i=1;i<n;i++){
		if(s[i]=='?'){
		for(ll j=0;j<13;j++){
			for(ll k=0;k<10;k++){
				dp[i][(j*10+k)%13]=(dp[i][(j*10+k)%13]+dp[i-1][j])%hell;
			}
		}}
		else{
			for(ll j=0;j<13;j++){
				dp[i][(j*10+s[i]-'0')%13]=(dp[i][(j*10+s[i]-'0')%13]+dp[i-1][j])%hell;
			}
		}
	}
//	for(ll i=0;i<10;i++)cout<<dp[1][i]<<" ";cout<<endl;	
	cout<<dp[n-1][5]<<endl;
}

Measured memory_bytes: 10624
from collections import deque

S = input()
Q = int(input())
Queries = [input().split() for i in range(Q)]

def start(S):
    state = {
        "S": S,
        "is_reversed": False,
        "left": deque(),
        "right": deque(),
    }

    return state


def T1(state, Query):
    state['is_reversed'] = not state['is_reversed']


def T2(state, Query):
    F = Query[1]
    C = Query[2]

    if not state['is_reversed']:
        if F == '1':
            state['left'].appendleft(C)
        else:
            state['right'].append(C)
    else:
        if F == '1':
            state['right'].append(C)
        else:
            state['left'].appendleft(C)


def output(state):
    output = ''.join(state['left']) + state['S'] + ''.join(state['right'])
    if state['is_reversed']:
        output = ''.join(list(reversed(output)))

    return output

def fetch(Query):
    operations = {
        '1': T1,
        '2': T2,
    }

    index = Query[0]
    operation = operations[index]

    return operation

def operate(state, Query):
    T = fetch(Query)
    T(state, Query)


def execute(state, Queries):
    for Query in Queries:
        operate(state, Query)

    return state


state = start(S)
execute(state, Queries)

answer = output(state)

print(answer)


Measured memory_bytes: 44336
#include <stdio.h>

#define INV 1000000000
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

#define MAXINV(a, b) (a == INV) ? ((b == INV) ? INV : b) : ((b == INV) ? a : MAX(a, b))
#define MININV(a, b) (a == INV) ? ((b == INV) ? INV : b) : ((b == INV) ? a : MIN(a, b))

int xmaxv = INV, xminv = INV, xmaxl = INV, xmaxr = INV, xminl = INV, xminr = INV;
int ymaxh = INV, yminh = INV, ymaxu = INV, ymaxd = INV, yminu = INV, ymind = INV;

double eval(double t) {
	double xmax = xmaxv;
	if (xmaxr != INV) xmax = MAXINV(xmax, xmaxr+t);
	if (xmaxl != INV) xmax = MAXINV(xmax, xmaxl-t);

	double xmin = xminv;
	if (xminr != INV) xmin = MININV(xmin, xminr+t);
	if (xminl != INV) xmin = MININV(xmin, xminl-t);

	double ymax = ymaxh;
	if (ymaxu != INV) ymax = MAXINV(ymax, ymaxu+t);
	if (ymaxd != INV) ymax = MAXINV(ymax, ymaxd-t);

	double ymin = yminh;
	if (yminu != INV) ymin = MININV(ymin, yminu+t);
	if (ymind != INV) ymin = MININV(ymin, ymind-t);

	return (xmax-xmin) * (ymax-ymin);
}

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

	while (n--) {
		int x, y;
		char c;
		scanf("%d%d %c", &x, &y, &c);
		switch (c) {
			case 'U':
				if (xmaxv == INV || xmaxv < x) xmaxv = x;
				if (xminv == INV || xminv > x) xminv = x;
				if (ymaxu == INV || ymaxu < y) ymaxu = y;
				if (yminu == INV || yminu > y) yminu = y;
				break;
			case 'D':
				if (xmaxv == INV || xmaxv < x) xmaxv = x;
				if (xminv == INV || xminv > x) xminv = x;
				if (ymaxd == INV || ymaxd < y) ymaxd = y;
				if (ymind == INV || ymind > y) ymind = y;
				break;
			case 'L':
				if (ymaxh == INV || ymaxh < y) ymaxh = y;
				if (yminh == INV || yminh > y) yminh = y;
				if (xmaxl == INV || xmaxl < x) xmaxl = x;
				if (xminl == INV || xminl > x) xminl = x;
				break;
			case 'R':
				if (ymaxh == INV || ymaxh < y) ymaxh = y;
				if (yminh == INV || yminh > y) yminh = y;
				if (xmaxr == INV || xmaxr < x) xmaxr = x;
				if (xminr == INV || xminr > x) xminr = x;
				break;
		}
	}

	double min = eval(0);
	if (xmaxv != INV) {
		if (xmaxl != INV && xmaxv < xmaxl) min = MIN(min, eval(xmaxl-xmaxv));
		if (xmaxr != INV && xmaxv > xmaxr) min = MIN(min, eval(xmaxv-xmaxr));
	}
	if (xmaxl != INV && xmaxr != INV && xmaxl > xmaxr) min = MIN(min, eval(((double) xmaxl-xmaxr)/2));

	if (xminv != INV) {
		if (xminl != INV && xminv < xminl) min = MIN(min, eval(xminl-xminv));
		if (xminr != INV && xminv > xminr) min = MIN(min, eval(xminv-xminr));
	}
	if (xminl != INV && xminr != INV && xminl > xminr) min = MIN(min, eval(((double) xminl-xminr)/2));

	if (ymaxh != INV) {
		if (ymaxu != INV && ymaxh > ymaxu) min = MIN(min, eval(ymaxh-ymaxu));
		if (ymaxd != INV && ymaxh < ymaxd) min = MIN(min, eval(ymaxd-ymaxh));
	}
	if (ymaxu != INV && ymaxd != INV && ymaxd > ymaxu) min = MIN(min, eval(((double) ymaxd-ymaxu)/2));

	if (yminh != INV) {
		if (yminu != INV && yminh > yminu) min = MIN(min, eval(yminh-yminu));
		if (ymind != INV && yminh < ymind) min = MIN(min, eval(ymind-yminh));
	}
	if (yminu != INV && ymind != INV && ymind > yminu) min = MIN(min, eval(((double) ymind-yminu)/2));

	printf("%.9f\n", min);
}


Measured memory_bytes: 128
import java.util.*;import java.io.*;import java.math.*;
public class Main
{
    public static void process()throws IOException
    {
        int n=ni();
        int x=ni();
        int y=ni();
        int[][]A=new int[n+1][n+1];
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                A[i][j]=j-i;
                    A[i][j]=Math.min(A[i][j],Math.abs(x-i)+1+Math.abs(j-y));
            }
        }
        // pn(Arrays.deepToString(A));
        int[]dis=new int[n];
        for(int i=1;i<=n;i++)
            for(int j=i+1;j<=n;j++)
                dis[A[i][j]]++;
        for(int i=1;i<n;i++)
            pn(dis[i]);
    }

    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        boolean oj = true;
        if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
        else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
        int t=1;
        // t=ni();
        while(t-->0) {process();}
        out.flush();out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

Measured memory_bytes: 55380
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int n, q, ans, a[N], b[N], say[N];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&n ,&q);
	for(int i = 1; i <= n; i++){
		scanf("%d", a + i);
		say[a[i]]++;
	}

	for(int i = 1; i <= n; i++)
			if(say[i])
				for(int j = i - say[i] + 1; j <= i; j++)
					b[j]++;

	for(int i = 1; i <= n; i++)
		if(!b[i])
			ans++;

	while(q--){
		int x, y;
		scanf("%d %d",&x ,&y);
		if(a[x] - say[a[x]] + 1 >= 1)
			b[a[x] - say[a[x]] + 1]--;
		if(a[x] - say[a[x]] + 1 >= 1 and !b[a[x] - say[a[x]] + 1])
			ans++;
		say[a[x]]--;
		a[x] = y;
		say[y]++;
		if(a[x] - say[a[x]] + 1 >= 1)
			b[a[x] - say[a[x]] + 1]++;
		if(a[x] - say[a[x]] + 1 >= 1 and b[a[x] - say[a[x]] + 1] == 1)
			ans--;
		printf("%d\n", ans);
	}
	return 0;
}

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

std::string next(std::string n) {
  std::string str1;
  std::string str2;
  long max = -1;
  for(int i = 1; i < n.size(); ++i) {
    str1 = str2 = "";
    for(int j = 0; j < i; ++j) {
      str1 += n[j];
    }
    for(int j = i; j < n.size(); ++j) {
      str2 += n[j];
    }
    max = std::max(max, stol(str1) * stol(str2));
  }
  return std::to_string(max);
}                   

int main() {
  int Q;
  std::cin >> Q;
  for(int i = 0; i < Q; ++i) {
    std::string N;
    std::cin >> N;
    int count = 0;
    for(;;) {
      if( N.size() == 1 ) {
        std::cout << count << std::endl;
        break;
      }
      std::string t = next(N);
      N = t;
      count += 1;
    }
  }
  return 0;
}
  

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    string x;
    cin >> x;
    vector<char> stk;
    for (int i = 0; i < x.length(); i++) {
        if (stk.size() == 0) {
            stk.push_back(x[i]);
            continue;
        }
        if (stk.at(stk.size() - 1) == 'S' && x[i] == 'T') stk.erase(stk.end() - 1);
        else stk.push_back(x[i]);
    }
    
    cout << stk.size() << endl;
    return 0;
}

Measured memory_bytes: 772
n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

for i in range(1000):
  num_str = str(i)
  num_keta = len(num_str)
  
  if num_keta != n:
    continue
    
  flg = True
  for j in range(m):
    pos = sc[j][0] - 1
    val_str = str(sc[j][1])
    if num_str[pos] != val_str:
      flg = False

  if flg:
    print(num_str)
    exit(0)
print('-1')


Measured memory_bytes: 9108
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace _0254
{
    class Program
    {
        static void Main(string[] args)
        {

            //var exStdIn = new System.IO.StreamReader("stdin.txt");
            //Console.SetIn(exStdIn);

            while (true)
            {
                int[] nm = RArInt();
                if (nm.Sum() == 0) break;
                int m = nm[1];

                long[] cumSumMod = new long[nm[0] + 1];
                int[] ks = RArInt();
                cumSumMod[0] = 0;
                for (int i = 0; i < ks.Length; i++)
                {
                    cumSumMod[i + 1] = (cumSumMod[i] + ks[i]) % m;
                }

                long res = 0;
                SortedList<long, long> ss = new SortedList<long, long>();
                ss.Add(cumSumMod[0], cumSumMod[0]);
                for (int i = 1; i < cumSumMod.Length; i++)
                {
                    long j = UpperBound(ss, cumSumMod[i]);
                    res = Math.Max(res, (cumSumMod[i] - j + m) % m);
                    if (res == m - 1) break;
                    if(!ss.ContainsKey(cumSumMod[i])) ss.Add(cumSumMod[i], cumSumMod[i]);
                }
                Console.WriteLine(res);
            }
        }

        public static long UpperBound(SortedList<long, long> arr, long value)
        {
            int low = 0;
            int high = arr.Count();
            int mid;
            while (low < high)
            {
                mid = ((high - low) >> 1) + low;
                if (arr.Keys[mid] <= value)
                    low = mid + 1;
                else
                    high = mid;
            }
            return low != arr.Count() ? arr.Keys[low] : 0;
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



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

using namespace std;


int main()
{
	long long x;
	cin >> x;

	for (long long i = -118; i <= 119; i++) {
		for (long long j = -119; j <= 118; j++) {
			if (x == i * i * i * i * i - j * j * j * j * j) {
				cout << i << " " << j << " " << endl;
				return 0;
			}
		}
	}
}

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

int a[200000];
int pos[200000];
int check[200000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif


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

	int maxlen = 0;
	for(int i = 0; i < N; i++){
		if(check[i]) continue;
		int len = 1, cur = i;
		check[cur] = 1;
		while(cur != N - 1 && pos[cur] < pos[cur + 1]){
			cur++;
			len++;
			check[cur] = 1;
		}
		maxlen = max(maxlen, len);
	}

	cout << N - maxlen << endl;
}


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

int x;

void solve() {
    int q1 = x / 500;
    x -= 500 * q1;
    int q2 = x / 5;
    cout << q1 * 1000 + q2 * 5 << endl;
}

int main() {
    cin >> x;
    solve();
}

Measured memory_bytes: 256