akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 310
using namespace std;
map<string,int>mp;
queue<string>q;
string now,net;
string s;
//移动方向，右，左，上，下（给定一维数组，要向上（下），就是往前（后）推四张牌）
int dt[]= {1,-1,4,-4};
void bfs()
{
    q.push("01234567");
    while(!q.empty())
    {
        now=q.front();
        q.pop();
        int pos=now.find('0');
        for(int i=0; i<4; i++)
        {
            int tpos=pos+dt[i];
            if(tpos>=0&&tpos<8&&(!((pos==3||pos==7)&&i==0)&&!((pos==4||pos==0)&&i==1)))
            {
                net=now;
                swap(net[pos],net[tpos]);
                if(mp[net]==0)
                {
                    mp[net]=mp[now]+1;
                    q.push(net);
                }
            }
        }
    }
    return;
}
int main()
{
    bfs();
    mp["01234567"] = 0;//预处理完以后mp["01234567"]=2,所以要加一个赋值
    while(1)
    {
        s="";
        int a = 8,b;
        while(a--)
        {
            if(!(cin >> b))
                return 0;//这一行的处理是加了个结尾，不加的话死循环
            s += b+'/0';
        }
        cout <<mp[s] << endl;
    }
    return 0;
}





Measured memory_bytes: 5388
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

using ll = long long;
template <ll MOD = 1000000007>
struct Mint{
    ll x;

    Mint() : x(0) {}
    Mint(ll t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(ll n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        ll a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    Mint & operator *= (Mint a){
        x = 1LL * x * a.x % MOD;
        return *this;
    }
    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        ll t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main(){
    string s;
    cin >> s;
    int n = s.size();
    Mint<> dp[n + 1][4];
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 4; j++){
            if(s[i] == '?') dp[i + 1][j] = dp[i][j] * 3;
            else dp[i + 1][j] = dp[i][j];
        }
        if(s[i] == 'A' || s[i] == '?') dp[i + 1][1] += dp[i][0];
        if(s[i] == 'B' || s[i] == '?') dp[i + 1][2] += dp[i][1];
        if(s[i] == 'C' || s[i] == '?') dp[i + 1][3] += dp[i][2];
    }
    cout << dp[n][3] << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	long long N,A,B;
	cin>>N>>A>>B;
  	if(A==0){
      cout<<0<<endl;
      return 0;
    }
  else if(B==0){
    	cout<<N<<endl;
    	return 0;
  }
	long long tmp=N/(A+B);
	long long ans=tmp*A;
	long long mod=N%(A+B);
	if(mod<=A)ans+=mod;
	if(mod>A) ans+=A;
  	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,s[10000000],ans=0;
int main()
{
	cin>>n>>a>>b;
	for(int i=1;i<=n;++i)
		cin>>s[i];
	for(int i=2;i<=n;++i)
	{
		ans+=min(a*(s[i]-s[i-1]),b);
	}
	cout<<ans;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    long long N, a[101], b[101], color[8], i, overred=0, ans=0, min, max;

    cin >> N;

    for(i=0; i<8; i++){
        color[i] = 0;
    }

    for(i=1; i<=N; i++){
        cin >> a[i];

        b[i] = a[i] / 400;

        if(b[i] < 8){
            color[b[i]]++;
        }

        else{
            overred++;
        }
    }

    for(i=0; i<8; i++){
        if(color[i] > 0){
            ans++;
        }
    }

    max = ans + overred;

    if(ans >= 1){
        min = ans;
    }

    else{
        min = 1;
    }

    cout << min << " " << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<set>
using namespace std;
int main(){
  multiset<int,greater<int> > m;
  for(int i=0;i<5;i++){
    int n; scanf("%d",&n);
    m.insert(n);
  }
  int count=0;
  for(int const& a:m)
    printf(++count==5?"%d\n":"%d ",a);
}

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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define endl "\n"

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _i64 q, query, element; list<_i64> L; cin >> q;
        list<_i64>::iterator cursor = L.end();
        _rep(i, q) {
            cin >> query;
            switch(query) {
                case 0:
                    cin >> element;
                    cursor = L.insert(cursor, element);
                    break;
                case 1:
                    cin >> element;
                    _rep(j, abs(element)) {
                        if(element > 0) { ++cursor; }
                        else if(element < 0) { --cursor; }
                    }
                    break;
                case 2:
                    cursor = L.erase(cursor);
                    break;
            }
        }
        _foreach(e, L) { cout << e << endl; }
    }
    return 0;
}


Measured memory_bytes: 18688
#include <iostream>

using namespace std;

int abs(int a){
	return a>0?a:-a;
}

int main(){
	int n,p;
	cin>>n;
	cin>>p;
	for(int i=0;i<p;i++){
		int x,y;
		cin>>x>>y;
		if(x<=n/2){
			x=abs(x-n/2-1);
		} else {
			x=abs(x-n/2);
		}
		if(y<=n/2){
			y=abs(y-n/2-1);
		} else {
			y=abs(y-n/2);
		}
		cout<<(n/2-max(x,y))%3+1<<endl;
	}
	return 0;
}

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

int main()
{
  int kupc_num[4] = { 0, 0, 0, 0, };

  while(true)
  {
    char ch;
    cin >> ch;
    if ( cin.eof() ) break;

    switch(ch)
    {
    case 'K':
      kupc_num[0]++;
      break;
    case 'U':
      kupc_num[1]++;
      break;
    case 'P':
      kupc_num[2]++;
      break;
    case 'C':
      kupc_num[3]++;
      break;
    }
  }
  int min = 300;
  for (int i=0; i<4; i++)
  {
    if ( min > kupc_num[i] )
    {
      min = kupc_num[i];
    }
  }

  cout << min << endl;
}

Measured memory_bytes: 1144
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 n;
  cin >> n;
  cout << (n - 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
a = list(map(int,input().split()))
n,m = max(a),min(a)
mod = 10**9+7
if n - m == 0:
  ans = 2
elif n - m == 1:
  ans = 1
else:
  ans = 0
for i in range(1,n+1):
  ans *= i
  ans %= mod
for i in range(1,m+1):
  ans *= i
  ans %= mod
print(ans)

Measured memory_bytes: 3064
// #include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
string solve(){
    ll n;
    string s;
    cin>>n;
    while(n>0){
      n--;
      s+=n%26+'a';
      n/=26;
    }
    reverse(s.begin(), s.end());
    return s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << solve() << "\n";
  return 0;
} 

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


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(20)<<fixed;

	string s;
	cin>>s;
	int n=s.size();
	if(s[n-1]=='s')
		s+="es";
	else
		s+='s';
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include<cstdio>
#include<iomanip>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <map>
#include <bitset>

int main()
{
    long long a{};
    double b{};
    std::cin >> a >> b;
    std::cout << a * static_cast<long long>(b * 100.01) / 100 << std::endl;
    return 0;
}


Measured memory_bytes: 3692
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

void swap(int &a, int &b){
	int tmp = a;
	a = b;
	b = tmp;
}

int main(){
	int n;
	int a[101];
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}

	int cnt = 0;
	for(int i=0; i<n; i++){
		int mn= a [i];
		int mni = i;
		for(int j=i; j<n; j++){
			if(mn>a[j]){
				mn = a[j];
				mni = j;
			}
		}
		if(i!=mni){
			swap(a[i], a[mni]);
			cnt++;
		}
	}

	for(int i=0; i<n-1; i++){
		cout << a[i] << " ";
	}
	cout << a[n-1] << endl;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1164
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int d = int.Parse(input[0]);
		int t = int.Parse(input[1]);
        int s = int.Parse(input[2]);

		Console.WriteLine(d <= t * s ? "Yes" : "No");
	}
}

Measured memory_bytes: 27368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  if (a <= x && x <= a + b) YES();
  else NO();
}

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

using namespace std;

int main()
{
    long long n,q;
    cin>>n>>q;
    vector < vector<int> > a(n);
    while(q--)
    {
        int b;
        cin>>b;
        if(b==0)
        {
           long long t,x;
           cin>>t>>x;
           a[t].push_back(x);
        }
        else if(b==1)
        {
            long long t;
            cin>>t;
            if(!a[t].empty())
            {
                long long i;
                for(i=0;i<a[t].size()-1;i++)
                {
                    cout<<a[t][i]<<" ";
                }
                cout<<a[t][i]<<endl;
            }
            else
                cout<<endl;
        }
        else
        {
            long long t;
            cin>>t;
            a[t].clear();
        }
    }
    return 0;
}



Measured memory_bytes: 5796
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int N=1505;
vector<int> C[N],D[N];
int val[N][N],b[N][N],S[N],n,u[N][N],l[N],r[N];
char A[N][N];
bool flag[N][N];
int main(){
	scanf("%d",&n);
	for (register int i=1;i<=n;++i)scanf("%s",A[i]+1);
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)flag[i][j]=A[i][j]>='0'&&A[i][j]<='9',b[i][j]=A[i][j]-'0';
	for (register int i=1;i<=n;++i)
		for (register int j=n;j;--j)
			if (flag[i][j])C[i].push_back(j);
			else D[i].push_back(j);
	for (register int i=0;i<=n;++i)
		for (register int j=0;j<=n;++j)u[i][j]=flag[i][j]?min(i,min(u[i-1][j],u[i][j-1])):1<<30;
	long long ans=0;
	for (register int x=1;x<=n;++x){
		for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x][j]<=x?b[x][j]:0);
		for (register int j=n+1;j;--j){
			if (flag[x][j]){
				l[j]=j-1;
				r[j]=max(r[j+1],j);
				val[x][j]+=(S[r[j]]-S[l[j]]-b[x][j]);
			}
			else l[j]=n+1,r[j]=0;
		}
		for (register int i=x-1;i;--i){
			for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x][j]<=i?b[x][j]:0);
			for (int j:D[i])l[j]=n+1,r[j]=0;
			for (int j:C[i]){
				val[i][j]+=S[r[j]=max(r[j+1],r[j])];
				val[i][j]-=S[l[j]=min(l[j+1],l[j])];
			}
		}
	}
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)ans+=val[i][j]*b[i][j];
	printf("%lld\n",ans);
}


Measured memory_bytes: 49280
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    k,t = list(map(int, input().split()))
    a = list(map(int, input().split()))
    s = sum(a)
    m = max(a)
    return max((m-(s-m)-1), 0)

print(f())


Measured memory_bytes: 5424
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  startupcpp();
  ll i,N;
  cin>>N;
  double ans=0,wa=1;
  vector<ddatas> a(N);
  vector<double> p;
  rep(i,N){
    cin>>a[i].first>>a[i].second;
    p.pb(i);
    wa*=i+1;
  }
  do{
    rep1(i,N){
      ans+=distance(a[p[i]],a[p[i-1]]);
    }
  } while(next_permutation(all(p)));
  ans=ans/wa;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
  input! {
    n: usize,
    k: usize,
  }
  
  let mut sunuke: Vec<bool> = Vec::new();
  sunuke.resize(n, true);
  
  for i in 0..k {
    input!{
      d: usize,
      a: [usize; d]
    }
    
    for aa in a {
      sunuke[aa - 1] = false;
    }
  }
  
  let mut ans = 0;
  for s in sunuke {
    if s {
      ans += 1;
    }
  }
  
  println!("{}", ans);
}

Measured memory_bytes: 2188
//  g++ -g -std=gnu++14 -I . main.cpp -o main
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    (v).begin(), (v).end()
#define in        ([]{int n; cin>>n; return n;}())
using namespace std;
using lint = int64_t;


int main() { cin.tie(0); ios::sync_with_stdio(false);
    int X = in, A = in;
    if ( X < A ) {
        cout << 0 << "\n";
    } else {
        cout << 10 << "\n";
    }
}


Measured memory_bytes: 256
import sys, os
import collections

class Dectation:
  def __init__(self, target, is_honest):
    super().__init__()
    self.target = target
    self.is_honest = is_honest

def solve(input_stream):
  number_of_people = read_int(input_stream)
  dectation_list = [[] for i in range(number_of_people)]

  for people_index in range(number_of_people):
    number_of_dectation = read_int(input_stream)
    for dectate_index in range(number_of_dectation):
      target_people, is_honest = read_ints(input_stream)
      dectation_list[people_index].append(Dectation(target_people, is_honest))
  ans = 0
  for bits in range(1, 1 << number_of_people):
    ok = True
    for index in range(number_of_people):
      if not ok:
        continue
      if ( ( (bits >> index) & 1 ) & 1) == 0:
        continue
      for dectation in dectation_list[index]:
        if (( bits >> (dectation.target - 1) ) & 1 ) ^ dectation.is_honest:
          ok = False
          break
    if ok:
      ans = max(ans, count(bits, 0))
  return [str(ans)]

def count(bits, ans):
  if bits == 0:
    return ans
  ans += bits & 1
  return count(bits >> 1, ans)

def read_ints(input_stream):
  return  map(int, input_stream.readline().strip().split())

def read_int(input_stream):
  return int(input_stream.readline().strip())

if __name__ == "__main__":
    outputs = solve(sys.stdin)
    for line in outputs:
      print(line)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, Q;
ll A[MAX_N], B[MAX_N]; //[0, 2 * N) !!
multiset<ll> S;

void solve() {
	cin >> N >> Q;
	rep(i, 0, 2 * N) cin >> A[i];
	rep(i, 0, 2 * N) cin >> B[i];

	ll ans = 0; bool odd = false;
	ans += A[0] + A[2 * N - 1];
	rep(i, 1, 2 * N - 1) {
		ans += max(A[i], B[i]);
		odd ^= (A[i] > B[i]);
		S.insert(abs(A[i] - B[i]));
	}
	while(Q--) {
		ll a, x, y;
		cin >> a >> x >> y; a--;
		if(a == 0 || a == 2 * N - 1) {
			ans += x - A[a];
			A[a] = x;
		}
		else {
			odd ^= (A[a] > B[a]);
			odd ^= (x > y);
			ans += max(x, y) - max(A[a], B[a]);
			S.erase(S.lower_bound(abs(A[a] - B[a])));
			S.insert(abs(x - y));
			A[a] = x; B[a] = y;
		}
		cout << (!odd ? ans : ans - (*S.begin())) << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 14208
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"
#define MOD 1000000007

typedef long lint;
typedef pair<lint, lint> P;
bool lessPair(const P& l, const P& r){return l.second < r.second;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint N; cin >> N;
    lint M; cin >> M;

    vector<lint> A(N);
    vector<lint> B(M);

    REP(i, N) {
      lint x; cin >> x; A[i] = x;
    }

    SORT(A);

    REP(i, N-1) {
      if(A[i] == A[i+1]) {
        PRINT(0);
        return 0;
      }
    }
    REP(i, M) {
      lint x; cin >> x; B[i] = x;
    }
    SORT(B);

    REP(i, M-1) {
      if(B[i] == B[i+1]) {
        PRINT(0);
        return 0;
      }
    }

    lint n = N-1;
    lint m = M-1;

    lint res = 1;
    lint current = N*M;

    while(current > 0) {
      while(A[n] > current && n >= 0) {
        n--;
      }
      while(B[m] > current && m >= 0) {
        m--;
      }

      if(n >= 0 && A[n] == current && m >=0 && B[m] == current) {
        current--;
        continue;
      }
      if(n>=0 && A[n] == current) {
        res *= -m+M-1;
        res %= MOD;
        
        current--;
        continue;
      }
      if(m>=0 && B[m] == current) {
        res *= -n+N-1;
        res %= MOD;

        current--;
        continue;
      }

      lint area = (-n+N-1)*(-m+M-1) - (M*N - current);

      if(area <= 0) {
        res = 0;
        break;
      }

      res *= area;
      res %= MOD;
      current--;
    }

    PRINT(res);
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int D;
  scanf("%d",&D);
  if(D==22){
    printf("Christmas Eve Eve Eve");
  }
  if(D==23){
    printf("Christmas Eve Eve");
  }
  if(D==24){
    printf("Christmas Eve");
  }
  if(D==25){
    printf("Christmas");
  }
  return 0;
}


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

#define ll long long

const int MAXW = 10'000;
const int MAXK = 100'000;

int load(int p, int k, const std::vector<int> &w) {
  // p トラック一台分の積載量
  // k トラックの数
  // w 荷物
  // return 積載できた荷物の数 0 <= n
  int i{}, n = w.size();
  for (int j = 0; j < k; j++) {
    ll s{}; // 積み込み中の荷物
    while (s + w[i] <= p) {
      s += w[i++];
      if (i == n) {
        return n;
      }
    }
  }
  return i;
}

int main() {
  // n 荷物の数
  // k トラックの数
  int n, k;
  std::cin >> n >> k;

  // w 荷物の配列
  std::vector<int> w(n);
  for (int i = 0; i < n; i++) {
    std::cin >> w[i];
  }

  ll l = 0, r = MAXW * MAXK, m;
  while (r - l > 1) {
    m = (r + l) / 2;
    if (load(m, k, w) >= n) // n個の荷物が詰めたらちょうどいいか、トラックの台数が多い
      r = m;
    else
      l = m;
  }

  std::cout << r << std::endl;
}



Measured memory_bytes: 3132
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n;
    cin>>n;

    vi v(n-1);
    for(int i=0;i<n-1;++i)
        cin>>v[i];

    sort(all(v));

    int cur=1,cnt=0;
    for(int i=0;i<n-1;++i)
    {
        if(cur!=v[i])
        {
            cout<<cnt<<"\n";
            ++cur;
            while(cur<v[i])
                cout<<"0\n",++cur;
            cnt=1;
        }
        else
            ++cnt;
    }

    cout<<cnt<<"\n";
    ++cur;
    while(cur<=n)
        cout<<"0\n",++cur;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        //cout<<"Case #"<<z<<": ";
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 4788
package main

import "fmt"

var N int
var M int

func main() {
	fmt.Scanf("%d %d", &N, &M)

	flip := (N - 2) * (M - 2)

	fmt.Println(Abs(flip))
}

func Abs(n int) int {
	if n > 0 {
		return n
	}
	return -n
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n, m; cin >> n >> m;
    int ttl = 0;
    vector<int> v(n, 0);
    rep(i, 0, n) {
        int t; cin >> t;
        ttl += t;
        v[i] = t;
    }
    int cnt = 0;
    rep(i, 0, n) if (v[i] * 4 * m >= ttl) cnt++;
    if (cnt >= m) cout << "Yes" << endl; else cout << "No" << endl;
}

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

int main() {
  int X ; 
  cin >> X ; 
  
  if(X == 7 || X == 5 || X ==3){
   cout << "YES" << endl ;  
  }
  else{
   cout << "NO" << endl ; 
  }
  
}


Measured memory_bytes: 3548
import Foundation
 
let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")
 
let a = Int(split[0])!
let b = Int(split[1])!
let c = Int(split[2])!

if (a==b && b==c){
    print("1")
}else if (a==b && b != c || a==c && c != b || b==c && a != c){
    print("2")
}else{
    print("3")
}


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

int main() {
  int n,k;
  cin >>n>>k;
  vector<int> h(n);
  for (int i=0; i<n; ++i) cin >> h.at(i);
  
  sort(h.begin(), h.end());
  int ans=1000000000; 
  
  for (int i=0; i<n-k+1; ++i) {
    if (h.at(i+k-1) - h.at(i) < ans) ans = h.at(i+k-1) - h.at(i);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;

const int MaxN = 1e5 + 5;

char S[MaxN];
int a[MaxN];
int q;
int w;
int main()
{
	q = 0;
	scanf("%s",&S);
	int len = strlen(S);
	for(int i = 0;i < len;i++){
		a[S[i] - '0' - 48] = 1;
	}
	for(int i = 1;i <= 26;i++){
		if(a[i] != 1){
			i = i + 96;
			printf("%c\n",i);
			q = 1;
			break;
		}
	}
	if(q == 0)printf("None\n");
		//scanf("%c",&w);
		//printf("%d",w);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A + B > C + D) cout << "Left" << endl;
    if (A + B == C + D) cout << "Balanced" << endl;
    if (A + B < C + D) cout << "Right" << endl;
    return 0;
}


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

import static java.lang.System.in;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        long ans = (long) Math.pow(3,n);
        long sub = 1;
        for(int i=0;i<n;i++){
            if(a[i]%2==0) sub *=2;
        }
        System.out.println(ans-sub);
    }
}


Measured memory_bytes: 21716
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)


for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]

print(ans)      

Measured memory_bytes: 3064
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val A = Array.fill(N)(sc.nextLong)
    val As = A.zipWithIndex.map { case (a, i) => a - (i + 1) }.sorted

    if (N % 2 == 1) {
      val b = As(N / 2)
      As.map(a => (a - b).abs).sum.toString
    } else {
      val b1 = As(N / 2 - 1)
      val b2 = As(N / 2)
      Array(
        As.map(a => (a - b1).abs).sum,
        As.map(a => (a - b2).abs).sum
      ).min.toString
    }
  }
}


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

int main(){
  string S,T="CODEFESTIVAL2016";
  cin >> S;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i)){
      count++;
    }
  }
  cout << count << endl;  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <sstream>
using namespace  std;
#define  ll long long
#define memsetINF(a) memset(a,INF,sizeof(a))
#define memset0(a) memset(a,0,sizeof(a))
#define memsetf1(a) memset(a,-1,sizeof(a))
#define lson i<<1,l,l+r>>1
#define rson i<<1|1,((l+r)>>1)+1,r
typedef pair<ll,ll>P;
static const ll INF=1e18;
static const ll len=1e5+7;
vector<P>G[len];
ll n;
ll d[len];
void short_path(ll ss)
{
	fill(d,d+n+1,INF);
	priority_queue<P,vector<P>,greater<P>>qu;
	d[ss]=0;
	qu.push(P(0,ss));
	while(!qu.empty())
	{
		P p=qu.top();qu.pop();
		ll u=p.second;ll dis=p.first;
		if(d[u]<dis)continue;
		for(ll v=0;v<G[u].size();++v)
		{
			P x=G[u][v];
			if(d[x.second]>dis+x.first)
			{
				d[x.second]=dis+x.first;
				qu.push(P(d[x.second],x.second));
			}
		}
	}
}
int main()
{
	while(cin>>n)
	{
		for(ll i=0;i<=n;++i)
		{
			G[i].clear();
		}
		ll u,v,w;
		for(ll i=1;i<n;++i)
		{
			scanf("%lld%lld%lld",&u,&v,&w);
			P p;
			p.first=w;p.second=v;
			G[u].push_back(p);
			p.second=u;
			G[v].push_back(p);  
		}
		ll q,ss;
		cin>>q>>ss;
		ll a,b;
		short_path(ss);
		for(ll i=0;i<q;++i)
		{
			scanf("%lld%lld",&a,&b);
			printf("%lld\n",d[a]+d[b]);
		}
	}
    return 0;
}

Measured memory_bytes: 11120
from sys import stdin


def main():
    K = int(stdin.readline().rstrip())

    def check(x):
        s = str(x)
        for i in range(len(s) - 1):
            if 1 < abs(int(s[i]) - int(s[i + 1])):
                return False
        return True

    if K <= 100:
        count = 0
        i = 1
        while True:
            if check(i):
                count += 1
            if count == K:
                print(i)
                return
            i += 1
    else:
        def inner(n):
            s = str(n)
            for idx in range(len(s) - 1, 0, -1):
                c1 = int(s[idx])
                c2 = int(s[idx - 1])
                if c1 != 9 and ((c2 - 1) == c1 or c2 == c1):
                    c1 += 1
                    new_s = s[:idx] + str(c1)
                    for _ in range(len(s) - len(new_s)):
                        new_s += str(max(int(new_s[-1]) - 1, 0))
                    return int(new_s)
            if int(s[0]) != 9:
                new_s = str(int(s[0]) + 1)
                for _ in range(len(s) - len(new_s)):
                    new_s += str(max(int(new_s[-1]) - 1, 0))
                return int(new_s)
            else:
                new_s = '1'
                for _ in range(len(s)):
                    new_s += str(max(int(new_s[-1]) - 1, 0))
                return int(new_s)

        ans = 878
        for i in range(101, K + 1):
            ans = inner(ans)
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int N;
    string S;
    cin >> N >> S;
    int ans=0;
    rep(i,N-2) if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') ans++;
    cout << ans << endl;
}


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

int dp[MAX];

bool playgame(int currentplayer,int n,int k,int steps[])
{
 
  if(dp[k]!=-1 )  
  {
      return  (dp[k]==0? false:true);
  }
    
    
  int nextplayer = (currentplayer==0 ? 1 : 0);
  
  for(int i=0;i<n;i++)
  {
      if(k-steps[i]>=0)
      {
          bool cannextplayerwin=playgame(nextplayer,n,k-steps[i],steps);
          
          if(cannextplayerwin==false)
          
          {
              dp[k]=true;
              return true;
          }
          
      }
     
  }
  dp[k]=0;
  return false;
  
    
}


void findit(int n,int k,int steps[])
{
    //1 denotes Taro
    //2 denotes Jiro
    
    //map<pair<int,int>,int> v;
    
    for(int i=0;i<=MAX;i++)
    {
        
         dp[i]=-1;   
        
    }
    int answer=playgame(0,n,k,steps);
    
    if(answer)
    {
        cout<<"First";
    }
    
    else cout<<"Second";
    
  
}


int main()
{

    int n;
    cin>>n;
    
    int k;
    cin>>k;
    
    int steps[n];
    
    for(int i=0;i<n;i++)
    {
        cin>>steps[i];
    }
    
    findit(n,k,steps);

	return 0;
}


Measured memory_bytes: 6912
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    val dp = Array.ofDim[Long](N + 1, N + 1)
    dp(0)(0) = 0
    dp(N)(N) = 0

    REP_r(N + 1) { l =>
      REP(N + 1) { r =>
        if (l <= r) {
          if (l + 1 <= r) {
            dp(l)(r) = max(-dp(l + 1)(r) + A(l), -dp(l)(r - 1) + A(r - 1))
          } else {
            dp(l)(r) = 0
          }
        }
      }
    }

    val ans = dp(0)(N)
    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}


Measured memory_bytes: 112684
#include<bits/stdc++.h>
using namespace std;
int main(){
	int y=700;
	string s;
	cin>>s;
	if(!s.compare("ooo"))y+=300;
	if(!s.compare("oox"))y+=200;
	if(!s.compare("oxx"))y+=100;
	if(!s.compare("oxo"))y+=200;
	if(!s.compare("xoo"))y+=200;
	if(!s.compare("xxo"))y+=100;
	if(!s.compare("xox"))y+=100;
	cout<<y<<endl;
}


Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()
    s = list(input())
    q = ni()

    alphabet_idx = {}
    for i in range(26):
        alphabet_idx[i] = []

    for i, si in enumerate(s):
        alphabet_idx[ord(si) - ord("a")].append(i)

    for _ in range(q):
        qi, a, b = input().split()
        qi, a = int(qi), int(a)

        if qi == 1:
            a -= 1
            if s[a] == b:
                continue
            current_char = ord(s[a]) - ord("a")
            del_idx = bisect.bisect_left(alphabet_idx[current_char], a)
            del alphabet_idx[current_char][del_idx]

            insert_idx = bisect.bisect_left(alphabet_idx[ord(b) - ord("a")], a)
            alphabet_idx[ord(b) - ord("a")].insert(insert_idx, a)

            s[a] = b

        if qi == 2:
            b = int(b)
            a -= 1
            b -= 1
            ans = 0

            for i in range(26):
                a_idx = bisect.bisect_left(alphabet_idx[i], a)
                if a_idx < len(alphabet_idx[i]):
                    if alphabet_idx[i][a_idx] <= b:
                        ans += 1

            print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 36616
module Main where

import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM

--for Primitive
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

-- import qualified Data.Foldable                 as F

-- Basic
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Maybe
import Data.Char
import Data.Ord

count n = f $ n `mod` 10 
    where
        f x 
            | x  == 3 = "bon"
            | x `elem` [0,1,6,8] = "pon"
            | otherwise = "hon"

main :: IO ()
main = do
    n <- fst . fromJust <$> ( BS.readInt <$> BS.getLine ) :: IO Int
    putStr $  count n

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>prime;
  prime.push_back(2);
  int i,j;
  for(i=3;i<=55555;i+=2){
    bool chk = true;
    for(j=0;j<prime.size()&&chk;j++){
      if(i%prime[j]==0)chk=false;
    }
    if(chk)prime.push_back(i);
  }
  vector<int>a(n);
  j = 0;
  for(i=0;i<n;i++){
    while(prime[j]%5!=1)j++;
    a[i] = prime[j];
    j++;
  }
  for(i=0;i<n;i++){
    cout << a[i] << " ";
  }

}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *A = map(int, read().split())
out_deg = [0] * (N + 1)
for x in A:
    out_deg[x] += 1

print('\n'.join(map(str, out_deg[1:])))


Measured memory_bytes: 34044
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using ll = long long;
using namespace std;        
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define ar array
#define pi pair<int,int>


void solve(){
	string a,b;
	cin>>a>>b;
	int n=a.size();
	int m=b.size();
	int ans=1e9;
	for(int i=0;i<n;i++){
		if(i+m-1>=n) break;
		int l=0;
		for(int j=0;j<m;j++){
			if(a[i+j]!=b[j]) l++;
		}
		ans=min(ans,l);
	}	
	cout<<ans<<endl;
	

}

int main(){
	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
//	freopen("input.txt",r,"stdin");
	int t=1;
// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}





Measured memory_bytes: 3656
use std::io::Read;

const INF: i64 = 1000000000000000;

#[derive(Default)]
struct Solver {
    a: Vec<i64>,
    g: Vec<Vec<usize>>,
    ans: Vec<usize>,
    lis: Vec<i64>,
}

#[test]
fn test_lower_bound() {
    let mut s: Solver = Default::default();
    s.lis = vec![INF; 120];
    s.lis[0] = 5;
    for i in 1..99 {
        s.lis[i] = s.lis[i - 1] + (i as i64 % 3);
    }
    for i in 0..400 {
        let mut exp = 0;
        for j in 0..100 {
            if s.lis[j] >= i {
                exp = j;
                break;
            }
        }
        s.lower_bound(i);
        assert_eq!(exp, s.lower_bound(i))
    }
}

impl Solver {
    fn lower_bound(&self, target: i64) -> usize {
        let mut low = 0;
        let mut high = self.lis.len();
        if target <= self.lis[0] {
            return 0;
        }
        // target <= liw[low]
        while low + 1 < high {
            let mid = (low + high) / 2;
            if self.lis[mid] >= target {
                high = mid;
            } else {
                low = mid;
            }
        }
        return high;
    }
    fn recur(&mut self, vec: usize, parent: usize, g: &Vec<Vec<usize>>) {
        let target = self.a[vec];
        let id = self.lower_bound(target);
        let backup = self.lis[id];
        self.lis[id] = target;

        self.ans[vec] = self.lower_bound(INF);
        for &nv in &g[vec] {
            if nv == parent {
                continue;
            }
            self.recur(nv, vec, g);
        }
        self.lis[id] = backup;
    }

    fn solve(&mut self) {
        self.ans = vec![0; self.a.len()];
        self.lis = vec![INF; self.a.len() + 2];
        self.recur(0, self.a.len(), &self.g.clone());
        for ans in &self.ans {
            println!("{}", ans);
        }
    }
}

fn main() {
    let mut line = String::new();
    std::io::stdin().read_to_string(&mut line);
    let mut iter = line.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<i64> = iter.by_ref().take(n).map(|a| a.parse().unwrap()).collect();
    let mut g: Vec<Vec<usize>> = vec![Default::default(); n];
    for uv in iter.by_ref().take(2 * (n - 1)).map(|a| a.parse().unwrap()).collect::<Vec<usize>>().chunks(2) {
        g[uv[0] - 1].push(uv[1] - 1);
        g[uv[1] - 1].push(uv[0] - 1);
    }
    let mut solver = Solver { a, g, ..Default::default() };
    solver.solve();
}

Measured memory_bytes: 45920