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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();

		int[] priceArr = new int[num];

		for (int i = 0; i < num; i++) {
			priceArr[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(priceArr);

		int total = 0;

		for (int i = 0; i < priceArr.length; i++) {

			if (i == priceArr.length - 1) {
				total += priceArr[i] / 2;
			} else {
				total += priceArr[i];
			}
		}

		System.out.println(total);
	}

}


Measured memory_bytes: 21716
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int N,i,t;
char x[1005],d[10];
int main()
{
	scanf("%d",&N);
	for(i=0;i<N;x[i++]=t+'0')scanf("%d",&t);
	for(i=0;i<100000;i++)
	{
		sprintf(d,"%d",i);
		if(strstr(x,d)==NULL)
		{
			puts(d);
			return 0;
		}
	}
}

Measured memory_bytes: 624
cnt=0
def merge_sort(S):
    l=len(S)
    mid=int(l/2)
    Left=S[0:mid]
    Right=S[(mid):l]
    global cnt
    if l>=2:
        merge_sort(Left) and merge_sort(Right)
    Left.append(float('inf'))
    Right.append(float('inf'))
    p=0
    q=0
    for i in range(l):
        if Left[p]<Right[q]:
            S[i]=Left[p]
            p+=1
        else:
            S[i]=Right[q]
            q+=1
            if l>1 and len(Left)-1>=p and Left[p]!=float('inf'):
                cnt+=len(Left)-p-1
    return S



n=int(input())
A=list(map(int,input().split()))

merge_sort(A)
print(cnt)



Measured memory_bytes: 27468
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, l[N], r[N], s[N];
string a;
int main()
{
	ll i;
	cin >> a;
	n = a.size();
	for (i = n - 1; i >= 0; i--) {
		if (a[i] == 'L') r[i] = i;
		else r[i] = r[i + 1];
	}
	for (i = 0; i < n; i++) {
		if (a[i] == 'R') l[i] = i;
		else l[i] = l[i - 1];
	}
	for (i = 0; i < n; i++) {
		if (a[i] == 'L') {
			if ((i - l[i]) % 2 == 0) s[l[i]]++;
			else s[l[i] + 1]++;
		} else {
			if ((r[i] - i) % 2 == 0) s[r[i]]++;
			else s[r[i] - 1]++;
		}
	}
	for (i = 0; i < n; i++) printf("%d ", s[i]);
    return 0;
}


Measured memory_bytes: 2972
let () = Scanf.scanf "%d %d\n" @@ fun n q ->
  let es = Array.make n [] in
  for i = 0 to n - 2 do
    Scanf.scanf "%d %d\n" @@ fun a b ->
      es.(a - 1) <- b - 1 :: es.(a - 1);
      es.(b - 1) <- a - 1 :: es.(b - 1)
  done;
  let acc = Array.make n 0 in
  for i = 0 to q - 1 do
    Scanf.scanf "%d %d\n" @@ fun p x ->
      acc.(p - 1) <- acc.(p - 1) + x
  done;
  let visited = Array.make n false in
  let rec visit prev v =
    if not visited.(v) then begin
      visited.(v) <- true;
      acc.(v) <- acc.(v) + prev;
      List.iter (visit acc.(v)) es.(v)
    end in
  visit 0 0;
  Array.iter (Printf.printf "%d ") acc;
  print_newline ()


Measured memory_bytes: 35988
#include <bits/stdc++.h>
#define INF 1e7
#define mod 1000000007

using namespace std;
typedef long long int ll;
typedef tuple<int,int,int> tii;
typedef tuple<long long int,long long int,long long int> tll;
typedef tuple<double,double,double> tdd;


int main()
{
    int N; cin >> N;
    vector<ll>x(N),y(N),z(N),w(N);
    for(int i = 0; i < N; i++) 
    {
        cin >> x[i] >> y[i];
        z[i] = x[i]+y[i];
        w[i] = x[i]-y[i];
    }
    sort(z.begin(),z.end());
    sort(w.begin(),w.end());
    ll ans = max(z[N-1]-z[0],w[N-1]-w[0]);
    cout << ans << endl;
}

Measured memory_bytes: 9596
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	int n;cin>>n;
     if(n%10==7){cout<<"Yes"<<endl;return 0;}
     n=n/10;
     if(n%10==7){cout<<"Yes"<<endl;return 0;}
     n=n/10;
     if(n%10==7){cout<<"Yes"<<endl;return 0;}
     cout<<"No"<<endl;
	
	
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;

using ll = long long;

#define say(s) cout << s << endl
#define rep(i, n) for(int i=0; i<(int)(n); i++)

#define vec vector

const ll INF = ll(1e18)+1;

int main() {
  int n;
  cin >> n;
  vec<int> x(n);
  rep(i, n) cin >> x[i];
  sort(x.begin(), x.end());
  int ans = 1000000;
  int s = x[0], e = x[x.size()-1];
  for (int p=s; p<=e; p++) {
    int s = 0;
    rep (j, n) {
      s += (x[j] - p) * (x[j] - p);
    }
    /* cout << "p: " << p << " sum: " << s << endl; */
    ans = min(ans, s);
  }
  say(ans);
  return 0;
}


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

int main(){
	int a, b;
	cin >> a >> b;
	
	cout << a/b << " " << a%b << " " << flush;
	cout << fixed << setprecision(6) << (double)a/(double)b << endl;

	return 0;
}

Measured memory_bytes: 1248
using System;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] x = s.Split(' ');
            int a, b;
            a = int.Parse(x[0]);
            b = int.Parse(x[1]);

            if(b%a == 0)
            {
                Console.WriteLine(a + b);
            }

            else
            {
                Console.WriteLine(b - a);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Q, H, S, D, N, ans;

ll calc(ll x){
	ll ret = Q * (1LL << x);
	x--;
	if(x < 0)	return ret;
	ret = min(ret, H * (1LL << x));
	x--;
	if(x < 0)	return ret;
	ret = min(ret, S * (1LL << x));
	x--;
	if(x < 0)	return ret;
	ret = min(ret, D * (1LL << x));
	return ret;
}

int main(){
	cin >> Q >> H >> S >> D >> N;
	N *= 4;
	for(int i = 40; i >= 0; i--){
		if(N & (1LL << i)){
			ans = (ans + calc(1LL * i));
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
// type a
//a...いけそう
//b...自信がない
//c...お試し
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma endregion

string s;
lint k;

int main(void) {
	cin >> s >> k;
	if ((int)s.size() == 1) {
		cout << (int)s.size() * k / 2 << endl; return 0;
	}
	for (int i = 0; i < (int)s.size() - 1; i++) {
		if (s[i] != s[i + 1]) 
			break;
		if (i == (int)s.size() - 2) {
			cout << (lint)s.size() * k / 2 << endl;
			return 0;
		}
	}
	if (s[0] != s[(int)s.size() - 1]) {
		lint ans = 0;
		int cnt = 1;
		for (int i = 1; i < (int)s.size(); i++) {
			if (s[i] == s[i - 1]) cnt++;
			else {
				ans += cnt / 2;
				cnt = 1;
			}
			if (i == (int)s.size() - 1 && cnt != 1) ans += cnt / 2;
		}
		cout << ans * k << endl;
	}
	else {
		lint a = 1;
		lint b = 1;
		for (int i = 1; i < (int)s.size(); i++) {
			if (s[i] == s[i - 1]) a++;
			else break;
		}
		for (int i = (int)s.size() - 1; i > 0; i--) {
			if (s[i] == s[i - 1]) b++;
			else break;
		}
		//
		lint ans = 0;
		lint cnt = 1;
		for (int i = 1; i < (int)s.size(); i++) {
			if (s[i] == s[i - 1]) cnt++;
			else {
				ans += cnt / 2;
				cnt = 1;
			}
			if (i == (int)s.size() - 1 && cnt != 1) ans += cnt / 2;
		}
		cout << ans * k - ((a / 2ll + b / 2ll - (a + b) / 2ll) * (k - 1)) << endl;
		return 0;
	}

	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
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; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    rep(i,5){
        ll x;
        cin >> x;
        if(x==0){
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  int n,m,a[2000];
  cin >> n >> m;
  int sum = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int cnt = 0;
  for(int i = 0; i < n; i++) {
    if(a[i]*4*m >= sum) cnt++;
  }
  if(cnt >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int N, K;

	cin >> N >> K;
	vector<int> a(N);

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

	int min_value = 999999999;
	for(int i = 0; i + K - 1 < N; i++) {
		int left = i;
		int right = i + K - 1;
		int lv = a[left];
		int rv = a[right];


		if (lv < 0 && rv <= 0) {
			min_value = min(min_value, lv * -1);
		} else if (lv >= 0 && rv > 0) {
			min_value = min(min_value, rv);
		} else {
			min_value = min(min_value, lv * -1 + rv * 2);
			min_value = min(min_value, lv * -2 + rv);
		}
	}
	cout << min_value << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 100100;
int n, a[N];
vector <int> v;
map <int, int> m;

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		m[a[i]]++;
	}

	for(auto i : m) {
		if(i.nd >= 2) v.push_back(i.st);
		if(i.nd >= 4) v.push_back(i.st);
	}

	v.push_back(0);
	v.push_back(0);
	sort(v.begin(), v.end(), greater<int>());
	cout << 1LL * v[0] * v[1];
}	

	

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
bool check(string str){
    //COUT(str.substr(0,str.size()/2));
    //COUT(str.substr(str.size()/2,str.size()));
    if(str.substr(0,str.size()/2)==str.substr(str.size()/2,str.size())){
        return false;
    }else{
        return true;
    }
}
int main(){
    string str;cin>> str;
    do{
        str.pop_back();
    }while(check(str));
    COUT(str.size());
    return 0;
}


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

# mod で分類
mod_lst = [N // K for _ in range(K)]
for i in range(N % K):
	mod_lst[-(i + 1)] += 1
ans = 0

ans += mod_lst[0] ** 3

if K % 2 == 0:
	ans += mod_lst[K // 2] ** 3
	
print(ans)

Measured memory_bytes: 52208
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#define N 1005
#define F first
#define S second
using namespace std;

int n, en, a[N][N], c[N][N];
vector<pair<int, int> > gr[N][N];
queue<pair<int, int> > qu;
queue<int> qc;
pair<int, int> fu, ne;
int main()
{
	int i, j, t, t1, t2, t3, t4, fc;
	cin >> n;
	for (i = 1; i <= n; i++) {
		for (j = 0; j < n - 1; j++) scanf("%d", &a[i][j]);
		for (j = 0; j < n - 2; j++) {
			t1 = min(a[i][j], i);
			t2 = max(a[i][j], i);
			t3 = min(a[i][j + 1], i);
			t4 = max(a[i][j + 1], i);
			gr[t1][t2].push_back({t3, t4});
			c[t3][t4]++;
		}
	}
	for (i = 1; i <= n; i++) {
		for (j = i + 1; j <= n; j++) {
			if (c[i][j] == 0) qu.push({i, j}), qc.push(1);
			en++;
		}
	}
	while (!qu.empty()) {
		fu = qu.front(), qu.pop();
		fc = qc.front(), qc.pop();
		en--;
		if (en == 0) {cout << fc; return 0;}
		for (i = 0; i < gr[fu.F][fu.S].size(); i++) {
			ne = gr[fu.F][fu.S][i];
			c[ne.F][ne.S]--;
			if (c[ne.F][ne.S] == 0) {
				qu.push({ne.F, ne.S});
				qc.push(fc + 1);
			}
		}
	}
	cout << "-1";
    return 0;
}

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

typedef long long int ll;
using ii= pair<ll,ll>;
#define all(o) (o).begin(),(o).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ld long double
#define eps 0.00000000001

class prioritize{
    public: bool operator() (ii &p1,ii &p2){
        return p1.F<p2.F;
    }
};

int main()
{
    
    #ifndef ONLINE_JUDGE
        freopen("input1.txt","r", stdin);
        freopen("output1.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    ll n;
    cin>>n;

    ll arr[n];
    map<ll,ll> m;
    //arrector<ii> arr;
    for(ll i=0;i<n;i++)
    {
    	cin>>arr[i];
    	m[arr[i]]++;
    }

    ll x=m.size();
    if(x<3){
    	cout<<0<<"\n";
    	return 0;
    }
    ll cc=0;
    
   
    //sort(arr,arr+n);
    for(ll i=0;i<n-2;i++)
    {  
        
    	for(ll j=i+1;j<n-1;j++)
    	{
    		
    		for(ll k=j+1;k<n;k++)
    		{
    			
    			if(((arr[i]+arr[j]>arr[k])&&(arr[i]+arr[k]>arr[j])&&(arr[j]+arr[k]>arr[i]))&&((arr[i]!=arr[j])&&(arr[j]!=arr[k])&&(arr[k]!=arr[i])))
    			{
    				cc++;
    				//cout<<i<<" "<<j<<" "<<k<<"\n";
    			}
    		}
    	}
    }

    cout<<cc<<"\n";



}

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

int main(){

    string s1,s2;
    cin>>s1>>s2;
///string m="";
    int i,c=0,j;
   for(i=0;i<s1.size();i++)
   {
       if(s1[i]==s2[i])
        c++;
   }
cout<<c<<endl;


    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().split(" ");
        String a = s[0];
        String b = s[1];
        String c = s[2];
        int max = 0;
        max = max < getInt(a+b)+getInt(c) ?getInt(a+b)+getInt(c) : max;
        max = max < getInt(a+c)+getInt(b) ?getInt(a+c)+getInt(b) : max;
        max = max < getInt(b+a)+getInt(c) ?getInt(b+a)+getInt(c) : max;
        max = max < getInt(b+c)+getInt(a) ?getInt(b+c)+getInt(a) : max;
        max = max < getInt(c+a)+getInt(b) ?getInt(c+a)+getInt(b) : max;
        max = max < getInt(c+b)+getInt(a) ?getInt(c+b)+getInt(a) : max;
        println(max);
    }
    static long getLong(String val) {return Long.parseLong(val);}
    static int getInt(String val) {
        return Integer.parseInt(val);
    }

    static void println(String val){System.out.println(val);};
    static void println(int val){System.out.println(val);};
    static void println(long val){System.out.println(val);};
}

Measured memory_bytes: 22736
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,k; cin>>n>>k;
    const int m = 2000010;
    vector<ll> a(n),s(m);
    rep(i,n) cin>>a[i];

    rep(i,200002) {
        s[i+1] = s[i]+i+1;
    }

    vector<long double> p(n);

    rep(i,n) {
        p[i] = (long double)s[a[i]]/(long double)a[i];
    }

    long double ans = 0.0;


    vector<long double> t(n+1);
    rep(i,n) {
        t[i+1] += (t[i]+p[i]);
    }

    for (int i = k; i <= n; ++i) {
        chmax(ans, t[i]-t[i-k]);
    }


    cout << fixed  << setprecision(13);

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
#define PI  3.14159265358979323846

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    ll X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
    return 0;
}

Measured memory_bytes: 3604
S = gets.chomp

a = S[0, 2].to_i
b = S[2, 2].to_i
if a == 0
  if b > 12 || b == 0
    puts "NA"
  else
    puts "YYMM"
  end
elsif a <= 12
  if b > 12 || b == 0
    puts "MMYY"
  else
    puts "AMBIGUOUS"
  end
else
  if b > 12 || b == 0
    puts "NA"
  else
    puts "YYMM"
  end
end

Measured memory_bytes: 14328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

bool continuous1(int m, int n, string str);
bool continuous2(int m, int n, string str);

int main(){
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    
    bool judge = continuous1(A - 1, C - 1, S) && continuous1(B - 1, D - 1, S);

    if(C < D)       ;
    else{       // C > D
        judge &= continuous2(B - 1, D - 1, S);
    }
        
    if(judge){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

bool continuous1(int m, int n, string str){
    bool flag = true;
    
    for(int i = m; i <= n; i++){
        if(!flag && (str[i] == '#')){
            return false;
        }
        if(str[i] == '.'){
            flag = true;
        }
        else{
            flag = false;
        }
    }
    
    return true;
}

bool continuous2(int m, int n, string str){
    for(int i = m; i <= n; i++){
        if(str[i] == '#')       continue;
        
        if(str[i - 1] == '.' && str[i + 1] == '.'){
            return true;
        }
    }
    
    return false;
}

Measured memory_bytes: 900
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

const int maxn = 2e6 + 10;
typedef long long int ll;
ll mod = 998244353;
ll s[maxn * 4];
ll ans[maxn * 4],add[maxn * 4];

#define mid (l + r) / 2
#define lson (rt * 2)
#define rson (rt * 2) + 1

void pushdown(int rt,int l,int r){
    if(add[rt]){
        ans[lson] = (s[mid] - s[l - 1] + mod) % mod * add[rt] % mod;
        ans[rson] = (s[r] - s[mid] + mod) % mod * add[rt] % mod;
        add[lson] = add[rson] = add[rt];
        add[rt] = 0;
    }
}
void update(int rt,int ql,int qr,int l,int r,int v){
    if(l >= ql && r <= qr){
        ans[rt] = (s[r] - s[l - 1] + mod) % mod * v % mod;
        add[rt] = v;
        return ;
    }
    pushdown(rt,l,r);
    if(ql <= mid)update(lson,ql,qr,l,mid,v);
    if(qr > mid)update(rson,ql,qr,mid + 1,r,v);
    ans[rt] = (ans[lson] + ans[rson])% mod;
}
void solved(){
    int n,q;cin>>n>>q;
    s[n] = 1;
    for(int i = n - 1;i >= 1; i--)
        s[i] = ((s[i + 1] % mod) * 10) % mod;
    for(int i = 1; i <= n; i++)
        s[i] = ((s[i - 1] % mod) + s[i]) % mod;
    for(int i = 1; i <= n; i++)
        update(1,i,i,1,n,1);
    while(q--){
        int l,r,v;cin>>l>>r>>v;
        update(1,l,r,1,n,v);    
        printf("%lld\n",ans[1]);
    }
}
int main(){
    solved();
    return 0;
}

Measured memory_bytes: 13016
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
const long long int exa = 1000000000000000000;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;


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

	cin >> N >> K;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	sort(v.begin(), v.end());
	v.push_back(0);
	reverse(v.begin(), v.end());
	vector<vector<long long int>>dp(N + 1, vector<long long int>(K + 1));
	dp[0][K] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = K; j >= 0; j--) {
			dp[i][j] += dp[i - 1][j] * (N - i);
			dp[i][j] %= MOD;
			dp[i][j%v[i]] += dp[i - 1][j];
			dp[i][j%v[i]] %= MOD;
		}
	}
	long long int ans = 0;
	for (int i = 0; i <= K; i++) {
		ans += dp.back()[i] * i;
		ans %= MOD;
	//	cout << i << " " << dp.back()[i] << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 158592
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

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

  int L;
  cin >> L;

  cout << std::fixed << (double)(L*L*L) / 27 << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int N;

struct edge{
  int to;
  int len;
};

vector<vector<edge>> G;

vector<int> color;
vector<int> seen;


void dfs(int v){
  if(seen[v]) return;

  seen[v] = 1;
  
  for(edge n:G[v]){
    if(n.len % 2 == 1){
      color[n.to] = !color[v];
    }else{
      color[n.to] = color[v];
    }

    dfs(n.to);
  }
}

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    G.resize(N);
    color.assign(N,0);
    seen.assign(N,0);

    rep(i,N-1){
      int u,v,w;
      cin >> u >> v >> w;
      --u;--v;

      G[u].PB(edge{v,w});
      G[v].PB(edge{u,w});

    }

    dfs(0);

    rep(i,N){
      cout << color[i] << endl;
    }
}


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

int main() {
  string c;
  cin >> c;
  int res = 0;
  for (int i = 0; i < 4; i++) {
    if (c.at(i) == '+') {
      res++;
    }
    else {
      res--;
    }
  }
  cout << res << endl;
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

const int N=1e7+1;
vll st(N, 0);
vll ans(N, 0);

void init(){
	for(int i=1 ; i<N ; ++i){
		for(int j=i ; j<N ; j+=i){
			st[j]++;
		}
	}
	ans[1] = 1;
	for(int i=2 ; i<N ; ++i){
		ans[i] = ans[i-1] + i*st[i];
	}
}

void solve(){
	int n;
	cin >> n;
	
	cout << ans[n];
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	init();
	
	while(tt--){
		solve();
	}
}


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

int main(){
	double a, b, c, d, e, f;
	while(cin >> a >> b >> c >> d >> e >> f){
		double x, y;
		y = (a * f - d * c) / (a * e - d * b);
		x = (c - b * y) / a;

		//小数点以下４桁で四捨五入して表示
		cout << fixed << setprecision(3) << x << " " << y << endl;
	}

	return 0;
}



Measured memory_bytes: 3088
line = int(input())

upper_2 = int(line / 100)
lower_2 = line % 100

if 1 <= upper_2 <= 12:
    if 1 <= lower_2 <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif 1 <= lower_2 <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
 
int main(void){
   int m,f,r;
 
   while(true){
       cin >> m >> f >> r;
       if(m == -1 && f == -1 && r == -1){
           break;
       }
       if(m == -1 || f ==-1){
           cout << "F" ;
       }
       else if(m+f >= 80){
           cout << "A" ;
       }
       else if(65 <= m+f && m+f < 80){
           cout << "B" ;
       }
       else if(50 <= m+f && m+f < 65){
           cout << "C" ;
       }
       else if(30 <= m+f && m+f < 50){
           if(r >= 50){
               cout << "C" ;
           }
           else{
               cout << "D" ;
           }
       }
       else{
           cout << "F" ;
       }
       cout << endl;
   }
}


Measured memory_bytes: 3096
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        n:i32,
        m:i32,
    }

    println!("{}", n*(n-1)/2 + m*(m-1)/2);
}


Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
template <typename T>void read(T &x){
	x = 0; int f(1); char c = getchar();
	for(;!isdigit(c);c = getchar()) if(c == '-') f = -1;
	for(;isdigit(c);c = getchar()) x = x*10+c-'0';
	x *= f;
}
int n,m,h[100005];
int ok[100005];
vector<int> e[100005];
int main(){
	read(n); read(m);
	for(int i(1);i <= n;++i)	read(h[i]);
	for(int i(1);i <= m;++i){
		int u,v; read(u); read(v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	memset(ok,-1,sizeof ok);
	for(int i(1);i <= n;++i){
		if(ok[i] != -1)	continue;
		for(int j(0);j < e[i].size();++j){
			int k = e[i][j];
			if(h[k] >= h[i]){
				ok[i] = 0;break;
			}
			else
				ok[k] = 0;
		}
		if(ok[i] == -1)	ok[i] = 1;
	} int ans = 0;
	for(int i(1);i <= n;++i)
		if(ok[i] == 1)	++ans;
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
  int x, h;
  
  while (cin >> x >> h, x + h){
    double s = 0;
    s += x * x * 1.0;
    double y = sqrt(pow(x / 2.0, 2.0) + pow((double)h, 2.0));
    s += (y * x) / 2.0 * 4.0;
    printf("%.10f\n", s);
  }
  return (0);
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n;
    cin >> n;
    char s[n][n];
    for(int i =0;i<n;i++){
        for(int j =0;j<n;j++){
            cin >> s[i][j];
            
        }
    }
    int t =0;
    int ans =0;
    for(int i =0;i<n;i++){
        for(int j =0;j<n;j++){
            for(int k =0;k<n;k++){
                if(s[j][(k+i)%n]!=s[k][(j+i)%n]){
                    t =1;
                    break;
                }
            }
            if(t==1)break;
        }
        if(t==0){
            ans+=n;
            
        }
        t =0;
    }
    cout << ans ;
    return 0;
} 

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    ll money=1000;
    ll stock=0;
    for (int i = 0; i < n; i++)
    {
        money+=stock*a[i];
        stock=0;
        if(i==n-1) break;
        if(a[i]<a[i+1])
        {
            stock=money/a[i];
            money%=a[i];
        }
    }
    cout<<money<<endl;
    
    return 0;
}

Measured memory_bytes: 3636
{-# LANGUAGE PartialTypeSignatures #-}
module Main (main) where

import qualified Data.Vector as V
import qualified Data.Vector.Generic.Mutable as MV
import qualified Data.Vector.Algorithms.Merge as V
import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.List as L

main :: IO ()
main = do
  [n] <- readInts
  vec <- MV.replicateM n readString
  V.sort vec
  V.unsafeFreeze vec >>= output . solve

solve :: V.Vector String -> _
solve = V.length . V.uniq

output :: _ -> IO ()
output = print

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine

readString :: IO String
readString = C8.unpack <$> C8.getLine

Measured memory_bytes: 81408
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 0
A.sort()
M = len(bin(A[-1])) - 2

p = 1
for i in range(M):
  z = 0
  t = 1 << i
  for j in range(N):
    if A[j] & t == 0:
      z += 1
  o = N - z
  ans = (ans + z * o * p) % MOD
  p *= 2

print(ans)

Measured memory_bytes: 122808
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int ans=0;

typedef string::const_iterator State;


ll andop(ll l,ll r){
	if(l==0||r==0)return 0;
	if(l==1||r==1)return 1;
	return 2;
}

ll orop(ll l,ll r){
	if(l==2||r==2)return 2;
	if(l==1||r==1)return 1;
	return 0;
}

ll notop(ll l){
	if(l==0)return 2;
	if(l==2)return 0;
	return 1;
}

ll exp(State &begin){
	if(*begin=='('){
		begin++;
		ll left = exp(begin);
		char op = *begin;
		begin++;
		ll right= exp(begin);
		begin++;	//read ')'
		if(op=='*'){
			return andop(left,right);
		}else if(op=='+'){
			return orop(left,right);
		}
	}else if(*begin=='-'){
		begin++;
		return notop(exp(begin));
	}else{
		assert(isdigit(*begin));
		ll ret = *begin-'0';
		begin++;
		return ret;
	}
	
	assert(1);
	return -1;
}


int main(){
	string s;
	while(cin>>s&&s!="."){
		ans=0;
		rep(i,3){
			rep(j,3){
				rep(k,3){
					string tmp = s;
					rep(l,tmp.size()){
						if(tmp[l]=='P')tmp[l]='0'+i;
						if(tmp[l]=='Q')tmp[l]='0'+j;
						if(tmp[l]=='R')tmp[l]='0'+k;
					}
					State begin = tmp.begin();
					if(exp(begin)==2)ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

int main(){
  int n,k,r,s,p; cin >> n >> k >> r >> s >> p;
  string t; cin >> t;

  char tmpk;

  ll sum = 0;

  for(int i = k; i < n; i++) {
    if(t.at(i) == t.at(i - k)) t.at(i) = 'a';
  }

  rep(i,n) {
    if(t.at(i) == 'r') sum += p;
    else if(t.at(i) == 'p') sum += s;
    else if(t.at(i) == 's') sum += r;
  }
  
  cout << sum << endl;
}



Measured memory_bytes: 512
from functools import lru_cache, reduce
import itertools
import math
import sys


sys.setrecursionlimit(10**6)

N = input()

def main():
    a = [list(i) for i in itertools.product(["", "+"], repeat=len(N)-1)]
    [i.append("") for i in a]
    b = list(map(lambda ops: [N[i]+ops[i] for i in range(len(N))], a))
    print(sum(list(map(lambda x: eval("".join(x)), b))))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3940
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=Integer.parseInt(in.next());
		List<goods> ls=new ArrayList<>();
		for(int i=0;i<n;i++){
			int v=Integer.parseInt(in.next()),w=Integer.parseInt(in.next());
			char t=in.next().charAt(0);
			long d=Long.parseLong(in.next());
			String str=in.next();
			ls.add(new goods(v,w,t,d,str));
		}
		ls.sort(Comparator.comparing(goods::getValue)
				.thenComparingInt(goods::getWeight)
				.thenComparing(goods::getType)
				.thenComparingLong(goods::getDate)
				.thenComparing(goods::getName));
		
		for(int i=0;i<n;i++){
			goods g=ls.get(i);
			System.out.println(g.value+" "+g.weight+" "+g.type+" "+g.date+" "+g.name);
		}
	}

}

class goods{
	int value,weight;
	char type;
	long date;
	String name;
	
	goods(int v,int w,char t,long d,String str){
		value=v;
		weight=w;
		type=t;
		date=d;
		name=str;
	}
	
	int getValue(){
		return value;
	}
	
	int getWeight(){
		return weight;
	}
	
	char getType(){
		return type;
	}
	
	long getDate(){
		return date;
	}
	
	String getName(){
		return name;
	}
}


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

#include <atcoder/all>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int, int>;

class Main {
    int N, Q;
    vector<ll> a;
    void input() {
        cin >> N >> Q;
        a.resize(N);
        REP(i, N) { cin >> a[i]; }
    }
    void output() {
        fenwick_tree<ll> fw(N);
        REP(i, N) { fw.add(i, a[i]); }
        REP(q, Q) {
            int a, b, c;
            cin >> a >> b >> c;
            if (a == 0) {
                fw.add(b, c);
            } else {
                cout << fw.sum(b, c) << endl;
            }
        }
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 12156
import java.util.*;

public class Main {

    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        for (int i = 0; i < m; i++) {
            n -= scan.nextInt();
        }
        if (n >= 0) System.out.println(n);
        else System.out.println(-1);
    }
}

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

const int INF = 1001001001;

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

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> num(n);
    int max_num = 0;
    int max_cnt = 1;
    int next_max = 0;

    rep(i, n) {
        cin >> a[i];

        if (i == 0) {
            max_num = a[i];
        }
        else if (i == 1) {
            next_max = min(a[i], max_num);
            max_num = max(a[i], max_num);
        }
        else if (max_num < a[i]) {
            next_max = max_num;
            max_num = a[i];
            max_cnt = 1;
        }
        else if (max_num == a[i])
            max_cnt++;
        else if (next_max < a[i])
            next_max = a[i];

    }

    rep(i, n){
        if (a[i] == max_num && max_cnt == 1)
            cout << next_max << endl;
        else
            cout << max_num << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
n = int(input())
s = list(str(input().rstrip()))
q = int(input())


class SSQ:
    def __init__(self, n, e):
        # 単位元
        self.e = e
        # num_min:n以上の最小の2のべき乗
        self.num_min = 2**(n-1).bit_length()
        self.seg_min = [self.e]*2*self.num_min

    def update(self, k, x):
        k += self.num_min-1
        self.seg_min[k] = x
        while k:
            k = (k-1)//2
            self.seg_min[k] = self.seg_min[k*2+1] or self.seg_min[k*2+2]

    def query(self, p, q):
        q += 1
        if q <= p:
            return self.e
        p += self.num_min-1
        q += self.num_min-2
        res = self.e
        while q-p > 1:
            if p & 1 == 0:
                res = res or self.seg_min[p]
            if q & 1 == 1:
                res = res or self.seg_min[q]
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = res or self.seg_min[p]
        else:
            res = res or self.seg_min[p] or self.seg_min[q]
        return res

ssqs = [SSQ(n, False) for i in range(26)]

for i in range(n):
    ssqs[ord(s[i]) - ord('a')].update(i, True)

out = []
for i in range(q):
    com, x, y = list(input().split())
    if com == '1':
        idx = int(x) - 1
        pre_alph = ord(s[idx]) - ord('a')
        ssqs[pre_alph].update(idx, False)
        s[idx] = y
        alph = ord(y) - ord('a')
        ssqs[alph].update(idx, True)
    else:
        x, y = int(x) - 1, int(y) - 1
        cnt = 0
        for i in range(26):
            cnt += 1 if ssqs[i].query(x, y) else 0
        out.append(str(cnt))
print("\n".join(out))


Measured memory_bytes: 287656
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
nl = lambda: list(map(int, stdin.readline().split()))


while True:
    ct = 0
    n, x = na()
    if n == 0 and x == 0:
        break
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            k = x - i - j
            if k > j and k <= n:
                #print(i, j, k)
                ct += 1
    print(ct)


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

int main(){
  int t[110]={};
  int N;
  cin >> N;
  int a,b,c,d;
  //得点
  for(int i = 0; i < N*(N-1)/2; i++){
    cin >> a >> b >> c >> d;
    if(c > d) t[a-1] += 3;
    else if(c < d) t[b-1] += 3;
    else if(c == d){
      t[a-1]++;
      t[b-1]++;
    }
  }
  //順位
  int p = 0,rank[110]={};
  for(int j = 1; j < N+1; j+=p){
    int max = -1;
    for(int i = 0; i < N; i++){
      if(max < t[i]){
	max = t[i];
      }
    } 
    p = 0;
    for(int i = 0; i < N; i++){
      if(max == t[i]){
	rank[i] = j;
	p++;
	t[i] = -1;
      }
    }
    
  }
  for(int i = 0; i < N; i++){
    cout << rank[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

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

    ll sum = 0;

    REP(i, N) {
        ll tmp;
        cin >> tmp;
        sum += tmp;
    }

    if(sum >= H) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

struct edge { int to, cap, rev; };

const int MAX_SIZE = 202;

vector<edge>G[MAX_SIZE];

void add_edge(int from, int to, int cap) {
	G[from].push_back(edge { to, cap, (int)G[to].size() });
	G[to].push_back(edge { from, 0, (int)G[from].size() - 1 });
}

bool used[MAX_SIZE];
int dfs(int p, int t, int f) {
	if (p == t)return f;
	used[p] = true;

	for (int i = 0; i<G[p].size(); i++) {
		edge &e = G[p][i];
		if (used[e.to] || e.cap == 0)continue;
		int _f = dfs(e.to, t, min(f, e.cap));
		if (_f) {
			e.cap -= _f;
			G[e.to][e.rev].cap += _f;
			return _f;
		}
	}

	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	while (true) {
		fill_n(used, MAX_SIZE, false);
		int f = dfs(s, t, INF);
		if (f)flow += f;
		else return flow;
	}
}

vector<pair<int, int>>r, b;
int n;
int main() {
	cin >> n;
	int s = 2 * n, t = s + 1;
	REP(i, n) {
		int c, d;
		cin >> c >> d;
		r.emplace_back(mp(c, d));
		add_edge(s, i, 1);
	}
	REP(i, n) {
		int c, d;
		cin >> c >> d;
		b.emplace_back(mp(c, d));
		add_edge(n + i, t, 1);
	}
	REP(i, n)REP(j, n) {
		if (r[i].first < b[j].first&&r[i].second < b[j].second)add_edge(i,j+n,1);
	}
	cout << max_flow(s,t) << endl;
}

Measured memory_bytes: 384
// 2020-09-26 21:09:00
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
#include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
using namespace atcoder;

// clang-format on
using S = int;
S op(S l, S r) { return max(l, r); }
S e() { return 0; }
const int MX = 300030;
void answer() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  segtree<S, op, e> st(MX + 10);
  rep(i, n) {
    int x = st.prod(max(0, a[i] - k), min(MX, a[i] + k + 1));
    st.set(a[i], x + 1);
  }
  cout << st.all_prod() << '\n';
}

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

Measured memory_bytes: 9800