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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

const long double pi = 3.14159265358979323846;

long double a, b, x;

long double calc(long double t) {
    t = t * M_PI / (long double)180.0;
    if (a * sin(t) >= b * cos(t)) {
        return a * b * b * cos(t) / sin(t) / (long double)2.0;
    } else {
        return a * a * b - a * a * a * tan(t) / (long double)2.0;
    }
}

int main() {


    cout.precision(10);
    cout << fixed;

    cin >> a >> b >> x;
    
    long double hi = 90, lo = 0;
    // while (hi - lo >= 0.0000001) {
    rep(i, 1000) {
        long double mid = (hi + lo) / (long double)2.0;

        long double capacity = calc(mid);
        // cout << lo << " " << hi << " " << capacity << endl;
        if (capacity < x) hi = mid;
        else lo = mid;
    }

    cout << lo << endl;

    return 0;
}


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

int main()

{

    int n;
    cin>>n;

    string s="";
     char a='1';
    for(int i=1;i<=n;i++){

        s.push_back(a);
        a=a+1;
    }


    string z="",x="";
    for(int i=1;i<=n;i++)
    {
        int c;
        cin>>c;

        z+=(c+'0');
    }

     for(int i=1;i<=n;i++)
    {
        int c;
        cin>>c;

        x+=(c+'0');
    }



      int j=0;
      int k,l;
      int f=0,e=0;
      if(s==x)
         {
             k=j;
             f=1;

         }

    if(s==z)
    {
        l=j;
        e=1;
    }


    while(1){
        if(f==1 && e==1)
            break;


        if(next_permutation(s.begin(),s.end())){
            j++;
            if(s==x)
            {
                k=j;
                f=1;
            }

            if(s==z){
                l=j;
                e=1;
            }
        }
    }

    cout<<abs(k-l)<<endl;

    return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,cnt=0,cmp;
    vector<int> q;
    int w[6]={500,100,50,10,5,1};
    while(1){
        cin >> a;
        if(a==0){break;}
        q.push_back(a);
    }
    int g=q.size();
    for(int j=0;j<g;j++){
        cmp=1000-q[j];
        for(int i=0;i<6;i++){
            cnt+=cmp/w[i];
            cmp-=w[i]*(cmp/w[i]);
        }
        cout << cnt << endl;
        cnt=0;
    }

    return 0;
}


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

int main() {
  ll n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;
  ll mn = min({a, b, c, d, e});
  cout << (n + mn - 1) / mn + 4 << endl;
}


Measured memory_bytes: 256
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                a[i][j] = 0
ans = 'No'
for i in range(3):
    if a[i][0] + a[i][1] + a[i][2] == 0: ans = 'Yes'
    if a[0][i] + a[1][i] + a[2][i] == 0: ans = 'Yes'
if a[0][0] + a[1][1] + a[2][2] == 0: ans = 'Yes'
if a[0][2] + a[1][1] + a[2][0] == 0: ans = 'Yes'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll h, w, n;
    cin >> h >> w >> n;
    vector<ll> a(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    map<ll, ll> mp;
    for(int k = 0; k < n; k++){
        for(int i = a[k]-1; i <= a[k]+1; i++){
            for(int j = b[k]-1; j <= b[k]+1; j++){
                if(0<=i && i<=h-1 && 0<=j && j<=w-1){
                    mp[w*i+j]++;
                }
            }
        }
    }

    vector<ll> ans(10,0);
    ans[0] = (h-2)*(w-2);
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        int i = itr->first/w;
        int j = itr->first%w;
        if(0<i && i<h-1 && 0<j && j<w-1){
            ans[itr->second]++;
            ans[0]--;
        }
    }


    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << endl;
    }


    return 0;

}


Measured memory_bytes: 58112
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();

		int a = D + D + 1;
		int ans = 0;

		ans = N / a + 1;
		if (N % a == 0) ans--;

		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
<?php
fscanf(STDIN, "%d %d %d %d", $A, $B, $C, $D);
$T = intdiv($C, $B) + ($C % $B !== 0);
$A = intdiv($A, $D) + ($A % $D !== 0);
echo $T <= $A ? "Yes" : "No";


Measured memory_bytes: 16200
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int l = 0;
    for(int i = x; i >= 0; i--) {
        bool t = false;
        rep(j, n) {
            if(i == p[j]) t = true;
        }
        if(t == false) {
            l = i;
            break;
        }
    }
    int ans = l;
    for(int i = x; i < 2 * x - l; i++) {
        bool t = false;
        rep(j, n) {
            if(i == p[j]) t = true;
        }
        if(t == false) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  string s; cin >> s;
  int ans=0;
  int cnt=0;
  rep(i,s.size()){
    cnt=0;
    for(int j=i;j<s.size();j++){
      if((s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')&&(s[j]=='A'||s[j]=='C'||s[j]=='G'||s[j]=='T')){
        cnt++;
        chmax(ans,cnt);
      }
      else break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def move(X,N,A,B):
    output = 0
    for i in range(N-1):
        output += min(A*(X[i+1]-X[i]),B)

    return output

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

    print(move(X,N,A,B))

if __name__ == "__main__":
    main()


Measured memory_bytes: 15020
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

const int MAX_N = 3000;
const int MAX_T = 3000;
const int MAX_A = 3000;
const int MAX_B = 3000;

// {cost, profit}
vector<pair<int, int>> dish;

vector<vector<int>> dp;

void solve(const int max_cost, const int N, const int T) {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < max_cost; j++) {
            if (j < T + dish[i].first) {
                chmax(dp[i + 1][j], dp[i][j]);
            }
            if (j <= T + dish[i + 1].first && j >= dish[i + 1].first) {
                chmax(dp[i + 1][j], dp[i][j - dish[i + 1].first] + dish[i + 1].second);
            }
        }
    }
}

int main(void) {
    int N, T;
    cin >> N >> T;

    int max_A = 0;

    dish.resize(N + 1, {0, 0});
    for (int i = 0; i < N; i++) {
        cin >> dish[i + 1].first >> dish[i + 1].second;
        chmax(max_A, dish[i + 1].first);
    }
    sort(dish.begin(), dish.end());

    int max_cost = T + max_A;
    dp.resize(N + 1, vector<int>(max_cost, 0));

    solve(max_cost, N, T);

    int ans = 0;
    for (int i = 0; i < max_cost; i++) {
        chmax(ans, dp[N][i]);
    }
    cout << ans << endl;

    // printf("dp: \n");
    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j <= max_cost; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a;
	for(int i = 0; i < m; i++) {
		int aa, b;
		cin >> aa >> b;
		a.emplace_back(aa, b);
	}
	sort(a.begin(), a.end(), cmp);
	int crr = 0;
	int ans = 0;
	for(int i = 0; i < m; i++) {
		if(crr <= a[i].first) {
			crr = a[i].second;
			ans++;
			
		}
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 1400
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)


def input(): return sys.stdin.readline().rstrip()

K = int(input())
queue = deque(range(1, 10))
for _ in range(K):
    i = queue.popleft()
    if i % 10 >= 1:
        queue.append(i * 10 + (i % 10) - 1)
    queue.append(i * 10 + i % 10)
    if i % 10 <= 8:
        queue.append(i * 10 + (i % 10) + 1)
print(i)

Measured memory_bytes: 40816
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
using namespace std;

int cnt;
string s;

int main(){
	cin>>s;
	for(int i=0;i<s.size()/2;i++){
		if(s[i]==s[s.size()-i-1]) continue;
		if(s[i]=='x') s=s+'x';
		else if(s[s.size()-i-1]=='x') s='x'+s;
		else{
			cout<<-1<<endl;
			return 0;
		}
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}

int main()
{
	string s;
	cin >> s;
	int tr=0;
	ll res=0;
	for(int i=0;i<s.size();i++)
    {
        if(s[i]=='W')
            res+=i-tr,tr++;
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 644
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}


vector<pll> zahyou;

ll esum[100005], osum[100005], sum[100005];

int main() {
	ll N, Q;
	vector<ll> A;
	cin >> N >> Q;
	
	rep(i, N) {
		ll a;
		cin >> a;
		A.push_back(a);
		if (i % 2 == 1) {
			esum[i] = esum[i-1] + a;
			osum[i] = osum[i - 1];
		}
		else {
			if (i != 0)
				osum[i] += osum[i - 1] + a;
			else
				osum[i] = a;

			esum[i] = esum[i - 1];
		}

		if (i != 0)
			sum[i] = sum[i - 1] + a;
		else
			sum[i] = a;
	}

	rep(i, Q) {
		ll X;
		cin >> X;

		ll r = N, l = 0;
		while (r - l > 1) {
			ll mid = (r + l) / 2;

			if (A[mid] < X || 2*mid - N + 1 < 0 || abs(A[2*mid-N + 1] - X) > abs(A[mid] - X)) {

				l = mid;
			}

			else if (abs(A[2 * mid - N + 1] - X) <= abs(A[mid] - X)) {
				r = mid;
			}


		}


		cerr << l << endl;

		ll ans = 0;

		ans += sum[N - 1] - sum[l];


		if ((2 * l - N + 1) % 2 == 0 && 2 * l - N + 1 >= 0)
			ans += osum[2 * l - N + 1];
		else if((2 * l - N + 1) >= 0)
			ans += esum[2 * l - N + 1];


		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 4980
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int T = sc.nextInt();
		final int X = sc.nextInt();
		System.out.println((double) T / X);
		sc.close();
	}
}

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

int main(void){
    ll N;
    cin >> N;
    vector<string> S(N);
    REP(i,N) cin >> S[i];
    ll ans = 1;
    sort(S.begin(),S.end());
    FOR(i,1,N){
        if(S[i-1] == S[i]) continue;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

struct element {
	int size;
	int addres[2];
};

const int MAXN = 3 * 1E3 + 2;
element answer[MAXN][MAXN];

int main () {
	// input
	string s;
	string t;
	cin >> s >> t;
	int ss = s.size(), ts = t.size(); 
	// make the ones that needs to be 0, 0
	for (int i = 0; i <= ss; i ++) {
		answer[i][0].size = 0;
		answer[i][0].addres[0] = 0;
		answer[i][0].addres[1] = 0;
	}
	for (int i = 0; i <= ts; i ++) {
		answer[0][i].size = 0;
		answer[0][i].addres[0] = 0;
		answer[0][i].addres[1] = 0;
	}
	
	
	
	// final calculation	
	for (register int i = 0; i < ss; i ++) {
		for (register int j = 0; j < ts; j ++) {
			// if equal
			if (s[i] == t[j]) {
				answer[i + 1][j + 1].size = answer[i][j].size + 1;
			//	cout << "( " << answer[i + 1][j + 1].size << ", ";
				answer[i + 1][j + 1].addres[0] = -1;
				answer[i + 1][j + 1].addres[1] = -1;
			//	cout << -1 << " " << -1 << ")" << "   ";
				continue;
			}
			// if not equal
			if (answer[i][j + 1].size > answer[i + 1][j].size) {
				answer[i + 1][j + 1].addres[0] = -1;
				answer[i + 1][j + 1].addres[1] = 0;
				answer[i + 1][j + 1].size = answer[i][j + 1].size;
			//	cout << "( " << answer[i + 1][j + 1].size << ", ";
			//	cout << -1 << " " << 0 << ")" << "   ";
				continue;
			}
			answer[i + 1][j + 1].addres[0] = 0;
			answer[i + 1][j + 1].addres[1] = -1;
			answer[i + 1][j + 1].size = answer[i + 1][j].size;
		//	cout << "( " << answer[i + 1][j + 1].size << ", ";
			//	cout << 0 << " " << -1 << ")" << "   ";
		}
	//	cout << endl;
	}
	// output
	string ans = "";
	ss --;
	ts --;
	while (ss >= 0 && ts >= 0) {
		if (answer[ss + 1][ts + 1].addres[0] == -1 && answer[ss + 1][ts + 1].addres[1] == -1)
			ans += s[ss];
		//cout << "ss is " << ss << endl;
		//cout << "ts is " << ts << endl;
		//cout << "ss will get " << answer[ss + 1][ts + 1].addres[0] << endl;
		//cout << "ts will get " << answer[ss + 1][ts + 1].addres[1] << endl;
		int changess = answer[ss + 1][ts + 1].addres[0];
		int changets = answer[ss + 1][ts + 1].addres[1];
		ss += changess;
		ts += changets;
		//cout << "ss is " << ss << endl;
		//cout << "ts is " << ts << endl << "______________________" << endl;
	}
	if (ans.size() == 0) {
		cout << ' ' << endl;
		return 0;
	}
	for (int i = ans.size() - 1; i >= 0; i --)
		cout << ans[i];
	return 0;
}


Measured memory_bytes: 109168
#include <stdio.h>
#include <string.h>

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  else return 0;
}

// 文字列から数値へ変換してkeyを生成する
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ) {
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for ( i = 0; ; i++ ) {
    h = (h1(key) + i * h2(key)) % M;
    if ( strcmp(H[h], str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); // 文字列を数値に変換
  for ( i = 0; ; i++ ) {
    h = (h1(key) + i * h2(key)) % M;
    if ( strcmp(H[h], str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    scanf("%s %s", com, str);
    
    if ( com[0] == 'i' ) {
      insert(str);
    } else {
      if ( find(str) ) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


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

using namespace std;
#define PI 3.1415926535897932384626
#define ll long long
#define ull unsigned long long

#define all(x) x.begin(), x.end()
#define fo(i, n) for (i = 0; i < n; i++)
#define sortall(x) sort(all(x))

#define vi vector<int>
#define vs vector<string>
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, int> pii;
typedef vector<psi> vpsi;
typedef vector<psi> vpci;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
//=======================

const int MOD = 1'000'000'007;
const int N = 2e6 + 13;

//=======================
vi g[N];
int a[N];
int n, m, k;
//=======================

void solve()
{
    cin >> n;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string t;
    cin >> n >> t;
    for (char x : t)
    {
        if (x == 'R')
            k++;
    }
    fo(n, k)
    {
        if (t[n] == 'W')
            m++;
    }
    cout << m << endl;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// {{{ Modint
// using mint = modint<1000000007>;
// mint x = 2;
// std::cout << x.a << std::endl;
template <std::int64_t M>
class modint {
 public:
  int64_t a;

  explicit constexpr modint(const int64_t x = 0) noexcept :
    a((x % M + M) % M) {}
  constexpr int64_t &value() noexcept { return a; }
  constexpr const int64_t &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= M) {
      a -= M;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += M;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % M;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int64_t exp = M - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  constexpr modint pow(ll t) const {
    if (!t) return modint(1);
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};
// }}}
using mint = modint<1000000007>;

signed main() {
  ll N, K;
  cin >> N >> K;
  mint cand[300000]; // cand[s]: gcdがsの倍数となる組み合わせ数
  mint exact[300000]; // exact[s]: gcdが厳密にsとなる組み合わせ数
  mint ans;
  for (int s = K; s >= 1; s--) {
    cand[s] = mint(K/s).pow(N);
    exact[s] = cand[s];
    for (int i=2; i <= K/s; i++) {
      exact[s] -= exact[i*s];
    }
    ans += exact[s] * mint(s);
  }
  cout << ans.value() << endl;
  return 0;
}


Measured memory_bytes: 8292
# 現在の時刻aと何時間後にコンテストが始めるかbを整数で入力
a,b = map(int,input().split())
# a+bが24以上なら-24して表示
start_time = a + b
if start_time >=24:
    print(start_time - 24)
# a+bが24より小さければそのまま表示
else:
    print(start_time)

Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
main()
{
	int n;
	cin>>n;
	set<string> se;
	set<string>::iterator it1,it2;
	pair< set<string>::iterator,bool> ptr; 
	string s[n];
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		ptr=se.insert(s[i]);
	}
	cout<<se.size();
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	
	n *= 2;
	int a[200100];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	sort(a, a + n);
	
	long long ans = 0;
	for (int i = 0; i < n; i += 2) {
		int x = a[i];
		ans += x;
	}
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 210000
#define mod 924844033
#define ll long long
#define g 5
int n,tot,len;
int head[N],nex[N<<1],to[N<<1];
int size[N],jc[N],njc[N],ans[N];
int a[N<<2],b[N<<2],c[N<<2];
int qpow(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=(ll)ret*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}
	return ret;
}
void init()
{
	jc[0]=njc[0]=1;
	for(int i=1;i<=n;i++)jc[i]=(ll)jc[i-1]*i%mod;
	njc[n]=qpow(jc[n],mod-2);
	for(int i=n-1;i>=1;i--)njc[i]=(ll)njc[i+1]*(i+1)%mod;
	for(len=1;len<(n+1)*2;len<<=1);
}
void add(int x,int y)
{
	tot++;
	nex[tot]=head[x];head[x]=tot;
	to[tot]=y;
}
void dfs(int x,int y)
{
	size[x]=1;
	for(int i=head[x];i;i=nex[i])
		if(to[i]!=y)
		{
			dfs(to[i],x);
			size[x]+=size[to[i]];
		}
}
int C(int x,int y){return (ll)jc[x]*njc[y]%mod*njc[x-y]%mod;}
void NTT(int *a,int len,int type)
{
	for(int i=0,t=0;i<len;i++)
	{
		if(i<t)swap(a[i],a[t]);
		for(int j=len>>1;(t^=j)<j;j>>=1);
	}
	for(int i=2;i<=len;i<<=1)
	{
		int wn=qpow(g,(mod-1)/i);
		for(int j=0;j<len;j+=i)
		{
			int w=1,t;
			for(int k=0;k<i>>1;k++,w=(ll)w*wn%mod)
			{
				t=(ll)w*a[j+k+(i>>1)]%mod;
				a[j+k+(i>>1)]=(a[j+k]-t+mod)%mod;
				a[j+k]=(a[j+k]+t)%mod;
			}
		}
	}
	if(type==-1)
	{
		for(int i=1;i<len>>1;i++)swap(a[i],a[len-i]);
		int t=qpow(len,mod-2);
		for(int i=0;i<len;i++)a[i]=(ll)a[i]*t%mod;
	}
}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d",&n);
	init();
	for(int i=1,x,y;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		ans[i]=(ll)n*C(n,i)%mod;
	for(int i=2;i<=n;i++)(a[size[i]]+=jc[size[i]])%=mod;
	for(int i=0;i<=n;i++)b[i]=njc[n-i];
	NTT(a,len,1);NTT(b,len,1);
	for(int i=0;i<len;i++)c[i]=(ll)a[i]*b[i]%mod;
	NTT(c,len,-1);
	for(int i=1;i<=n;i++)
	{
		c[n+i]=(ll)c[n+i]*njc[i]%mod;
		ans[i]=(ans[i]-c[n+i]+mod)%mod;
	}

	memset(a,0,sizeof(a));
	for(int i=2;i<=n;i++)
	{	
		size[i]=n-size[i];
		(a[size[i]]+=jc[size[i]])%=mod;
	}
	NTT(a,len,1);
	for(int i=0;i<len;i++)c[i]=(ll)a[i]*b[i]%mod;
	NTT(c,len,-1);
	for(int i=1;i<=n;i++)
	{
		c[n+i]=(ll)c[n+i]*njc[i]%mod;
		ans[i]=(ans[i]-c[n+i]+mod)%mod;
	}
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 27264
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs            v.size()
#define ss            s.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii            pair<int, int>
#define int           long long
#define ull           unsigned long long
#define pb            push_back
#define mpp           make_pair
#define Okay          0
#define pi            3.14159

const int inf = 1e8;
const int cont = 1e18;
const int mod = 1e5;
using namespace std;


void solve(){
    int a, b, c;
    int n;
    cin>>n;
     int cnt =0;
    bool f =0;
    while(n--){
    cin>>a>>b;
    if(a == b)cnt ++;
    else cnt = 0;
    if(cnt ==3)f = 1;
    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

int32_t main() {
   Fast;
//   int tst;
//   cin>>tst;
//   for(int i=1; i<=tst; i++){
     solve();
//   }
    return Okay;
}



Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=300010;
int N,a[maxn],b[maxn],c[maxn],d[maxn],e[maxn];
int main(){
	//freopen("in","r",stdin);
	N=read();
	for(int i=1;i<=N;i++)
		a[read()]++;
	for(int i=1;i<maxn;i++)
		b[a[i]]++;//b:occur times
	for(int i=1;i<=N;i++){
		c[i]=c[i-1]+b[i]*i;//c:sum of occur times <= i
		d[i]=d[i-1]+b[i];//d:prefix sum
	}
	for(int i=1;i<=N;i++)
		e[i]=c[i]/i+d[N]-d[i];
	for(int i=1,j=N;i<=N;i++){
		for(;j;j--)
			if(e[j]>=i){
				printf("%d\n",j);
				break;
			}
		if(!j)
			printf("%d\n",j);
	}
	return 0;
}


Measured memory_bytes: 5888
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// template<class... Args>
// auto create(size_t n, Args&&... args) {
// 	if constexpr(sizeof...(args) == 1)
// 		return vector(n, args...);
// 	else
// 		return vector(n, create(args...));
// }

// template<typename... T>
// void read(T&... args) {
// 	((cin >> args), ...);
// }

// template<typename... T>
// void write(T&&... args) {
// 	((cout << args), ...);
// }

void solve() {
	int n, q, bi, ci;
	cin >> n;
	vector<int> arr(n);
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	cin >> q;
	int ans = 0LL;
	unordered_map<int, int> mp;
	for(auto ele : arr){
		mp[ele]++;
        ans += ele;
    }
	while(q--) {
		cin >> bi >> ci;
		cout << ans - (bi * mp[bi]) + (ci * mp[bi]) << "\n";
		ans = ans - (bi * mp[bi]) + (ci * mp[bi]);
		mp[ci] += mp[bi];
		mp[bi] = 0;
	}	
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 7940
#! /usr/bin/env python3

import sys
import numpy as np
from collections import defaultdict
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
S = list(read().decode().split())

dicts = defaultdict(int)

for s in S:
    dicts[s] += 1

for t in ["AC", "WA", "TLE", "RE"]:
    print(f'{t} x {dicts[t]}')


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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



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

	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[0]) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}



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

#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
    int a, b, c, d, e, f;
    cin>>a>>b>>c>>d>>e>>f;
    int water=-1;
    int sugar=0;
    double cct = 0;
    for(int w1=0; 100*w1<=f; w1+=a){
        for(int w2=0; 100*(w1+w2) <= f; w2+=b){
            for(int s1 = 0; 100*(w1+w2)+s1 <= f; s1+=c){
                for(int s2 = 0; 100*(w1+w2)+s1+s2 <= f; s2+=d){
                    double s = s1 + s2;
                    double w = 100*(w1+w2) + s;
                    if(cct <= 100*s/w && (w1+w2)*e >= s){
                        sugar = int(s);
                        water = int(w);
                        cct = 100*s/w;
                    }
                }
            }
        }
    }
    cout << water << " " << sugar << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>
using namespace std;
int main(){
	double r,a,b;
	cin >> r;

	a = r*r*3.141592653589;
	b = 2*r*3.141592653589;
		
	printf("%5f %5f",a,b);

	return 0;
	
}

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

const long long MOD = 1000000007;

int main()
{
  int n, m;
  long long ans = 0;
  cin >> n >> m;

  if (n - m != -1 && n - m != 0 && n - m != 1)
  {
    cout << ans << endl;
    return 0;
  }

  if (n - m == 0) ans = 2;
  else ans = 1;

  for (int i = 1; i <= n; i++)
  {
    ans = (ans * i) % MOD;
  }

  for (int i = 1; i <= m; i++)
  {
    ans = (ans * i) % MOD;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define imprime(v) for(int X=0;X<v.size();X++) printf("%d ", v[X]); printf("\n");
#define endl "\n"
const int INF= 0x3f3f3f3f;
const long double pi= acos(-1);
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
const int MOD=1e9+7;
const ll LINF=0x3f3f3f3f3f3f3f3f;

vi get_v(ll n) {
  vi ret;
  while(n > 0) {
    ret.pb(n % 10);
    n = n / 10LL;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}

int dp[20][5];


int main() {
  ll n;
  cin >> n;
  vi v = get_v(n);
  bool menor = false;
  int resp = 0;
  dp[0][0] = v[0];
  dp[0][1] = v[0] - 1;
  for(int i = 1; i < v.size(); i++) {
    dp[i][0] = dp[i - 1][0] + v[i];
    dp[i][1] = dp[i - 1][1] + 9;
    if(v[i] != 0) dp[i][1] = max(dp[i][1], dp[i - 1][0] + v[i] - 1);
  }
  cout << max(dp[v.size() - 1][0], dp[v.size() - 1][1]) << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    int M = 1 << N;
    vector<int> A(M);
    rep(i, M) cin >> A[i];

    vector<int> subset = A;
    for (int i = 0; i < N; ++i) {
        for (int t = 0; t < M; ++t) {
            if ((t >> i & 1) == 0) continue;
            subset[t] = max(subset[t], subset[t ^ (1 << i)]);
        }
    }
    vv<int> bitsub = vvec(N, M, 0);
    for (int i = 0; i < N; ++i) {
        for (int t = 0; t < M; ++t) {
            if ((t >> i & 1) == 0) continue;
            bitsub[i][t] = A[t];
            for (int j = 0; j < N; ++j) {
                if (j == i) continue;
                bitsub[i][t] = max(bitsub[i][t], bitsub[i][t ^ (1 << j)]);
            }
        }
    }

    vector<int> ans(M);
    for (int i = 0; i < N; ++i) {
        for (int t = 0; t < M; ++t) {
            if ((t >> i & 1) == 0) continue;
            ans[t] = max(ans[t], subset[t ^ (1 << i)] + bitsub[i][t]);
        }
    }
    for (int t = 1; t < M; ++t) {
        ans[t] = max(ans[t], ans[t - 1]);
    }

    for (int t = 1; t < M; ++t) write(ans[t]);
}

Measured memory_bytes: 24700
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans = (double)w*h/2;
    int num = (w==x*2 && h==y*2) ? 1 : 0;
    printf("%.10f %d\n", ans, num);
    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

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

    int n, m, p;
    while (1)
    {
        cin >> n >> m >> p;
        m--;
        if (n == 0)
            break;
        int sum = 0, num;
        rep(i, n)
        {
            int a;
            cin >> a;
            sum += a;
            if (i == m)
                num = a;
        }
        sum *= (100 - p);
        cout << (num != 0 ? sum / num : 0) << endl;
    }
}


Measured memory_bytes: 3120
# Typical Stairs
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    n, m, *a = map(int, read().split())
    MOD = 10**9 + 7

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

    dp = [0 for _ in range(n+1)]
    dp[0] = 1
    is_broken = [False] * (n+1)
    for i in a:
        is_broken[i] = True
    if 1 in a:
        dp[1] = 0
    else:
        dp[1] = 1

    for i in range(2, n + 1):
        if is_broken[i]:
            continue
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

    print(dp[-1])

if __name__ == '__main__':
    main()



Measured memory_bytes: 11620
#include <bits/stdc++.h>
using namespace std;
inline char Get(){
	static char ch; ch = getchar();
	while (ch != '\n' && ch != '0' && ch != '1' && ch != '?') ch = getchar();
	if (ch == '\n') return '*';
	return ch;
}
const int P = 1e9 + 7;
inline void upd(int &x,int v){ x = (x+v>=P)?(x+v-P):(x+v); }
int f[9],g[9],nxt[9][2];
inline int getnxt(int s,int v){
	int cnt1 = s / 3,cnt0 = s % 3;
	if (v == 1){ if (!cnt0) cnt1 = min(2,cnt1+1); else --cnt0; }
	else{ if (cnt0 == 2) cnt0 = 0; ++cnt0; }
	return cnt1 * 3 + cnt0;
}

inline void DP(char c){
	int i;
	for (i = 0; i < 9; ++i) g[i] = f[i],f[i] = 0;
	for (i = 0; i < 9; ++i) if (g[i]){
		if (c != '1') upd(f[nxt[i][0]],g[i]);
		if (c != '0') upd(f[nxt[i][1]],g[i]);
	}
}

int main(){
	int i,j;
	for (i = 0; i < 9; ++i) for (j = 0; j < 2; ++j) nxt[i][j] = getnxt(i,j);
	f[0] = 1;
	char c; while ((c=Get())!='*') DP(c);
	int ans = 0;
	for (i = 0; i < 9; ++i) if (i / 3 >= i % 3) upd(ans,f[i]);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 384
import math

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

cost_list = [math.inf for _ in range(n)]

cost_list[0]=0
cost_list[1]=abs(list_[1]-list_[0])

for i in range(2,n):
  one = cost_list[i-1] + abs(list_[i]-list_[i-1])
  two = cost_list[i-2] + abs(list_[i]-list_[i-2])
  
  cost_list[i]=min(one,two,)
  
print(cost_list[-1])

Measured memory_bytes: 20712
#include <stdio.h>
#include <stdlib.h>
const int N = 305;
const int M = 305;

int main (void)
{
	int a , b ;
	int i , n ;
	while(scanf("%d %d" , &a , &b))
	{
		if(a == 0 && b == 0)
		{
			return 0;
		}
		for(n = 0 ; n < b ; n++)
		{
			printf("#");
		}
		printf("\n");
			for(i = 0 ; i < a - 2; i++)
			{
				printf("#");
				for(n = 0 ; n < b - 2; n++)
				{
					printf(".");
				}
				printf("#");
				printf("\n");
			}
		for(n = 0 ; n < b ; n++)
		{
			printf("#");
		}
		printf("\n\n");
	}
	return 0;
}


Measured memory_bytes: 2036
<?php
fscanf(STDIN,"%d%d",$N,$K);
$A=[];
for ($i=1; $i <=$N ; $i++) {
  // code...
  $A[]=$i;
}
for ($i=0; $i <$K ; $i++) {
  // code...
  fscanf(STDIN,"%d",$d);
  $R=explode(" ",trim(fgets(STDIN)));
  $A=array_diff($A,$R);
}
echo count($A);



 ?>


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N;int Q; cin >> N >>Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21720
def solve(xs, n):
    for i in range(1, n):
        xs[i] += xs[i - 1]
    l, r = (0, 2)
    xs_last = xs[n - 1]
    ans = xs_last
    for c in range(1, n - 2):
        xs_center = xs[c]
        while l < c - 1:
            if xs_center < 2 * xs[l + 1]:
                if (xs[l + 1] + xs[l]) < xs_center:
                    l += 1
                break
            l += 1
        while r < n - 2:
            if xs_last + xs_center < 2 * xs[r + 1]:
                if (xs[r + 1] + xs[r]) < xs_last + xs_center:
                    r += 1
                break
            r += 1
        pqrs = (xs[l], xs_center - xs[l], xs[r] - xs_center, xs_last - xs[r])
        ans = min(ans, max(pqrs) - min(pqrs))
    return ans

if __name__ == "__main__":
    n = int(input())
    xs = [int(s) for s in input().split()]
    print(solve(xs, n))


Measured memory_bytes: 24684
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;


signed main(){
    int num;
    cin >> num;
    vi abc(4);
    rep(i,4)
    {
        abc[i]=num%10;
        num/=10;
    }
    reverse(all(abc));
    int a,b,c,d;
    a=abc[0];
    b=abc[1];
    c=abc[2];
    d=abc[3];
    int opt1,opt2,opt3;
    opt1=opt2=opt3=1;

    rep(i,2)
    {
        rep(j,2)
        {
            rep(k,2)
            {
                if(k==0)opt1=1;
                else opt1=-1;
                if(j==0)opt2=1;
                else opt2=-1;
                if(i==0)opt3=1;
                else opt3=-1;
                if(a+b*opt1+c*opt2+d*opt3==7)
                {
                    char one,two,three;
                    if(opt1==-1)one='-';
                    else one='+';
                    if(opt2==-1)two='-';
                    else two='+';
                    if(opt3==-1)three='-';
                    else three='+';
                    cout << a << one << b << two << c << three << d << "=7" << endl;
                    return 0;
                }
            }
        }
    }
}

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

int main(){
  int W, H, x, y;
  cin >> W >> H >> x >> y;
  double ans = ((double)W*(double)H/2.00);
  if (W/2 == x && H/2 == y && !(W&1) && !(H&1)) cout << ans << " " << 1;
  else cout << ans <<" "<< 0;
}


Measured memory_bytes: 256
def ggt(a, b):
    if b == 0:
        return a

    return ggt(b, a % b)

N = int(input())

erg = int(input())

for i in range(N-1):
    t = int(input())

    g = ggt(erg, t)
    erg = (erg // g) * t

print(erg)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
string N;
int K;
ll dp[110][3][4];

int main()
{
    cin >> N;
    cin >> K;
    for (int i = 1; i <= N.length(); i++)
    {
        int n = N[i - 1] - '0';
        if (i == 1)
        {
            // n != 0
            dp[i][0][1] = 1;
            dp[i][1][1] = n - 1;
            dp[i][1][0] = 1;
            continue;
        }

        if (n == 0)
        {
            for (int k = 0; k <= 3; k++)
            {
                dp[i][0][k] = dp[i - 1][0][k];
                if (k >= 1)
                {
                    dp[i][1][k] = dp[i - 1][1][k] + dp[i - 1][1][k - 1] * 9;
                }
                else
                {
                    dp[i][1][0] = dp[i - 1][1][0];
                }
            }
        }
        else
        {
            dp[i][0][1] = dp[i - 1][0][0];
            dp[i][0][2] = dp[i - 1][0][1];
            dp[i][0][3] = dp[i - 1][0][2];
            dp[i][1][0] = dp[i - 1][1][0];
            for (int k = 1; k <= 3; k++)
            {
                /*
                dp[i][1][k] = dp[i - 1][0][1] + dp[i - 1][1][1];
                dp[i][1][k] += dp[i - 1][0][k - 1] * (n - 1);
                dp[i][1][k] += dp[i - 1][1][k - 1] * n;
                */
                dp[i][1][k] = dp[i - 1][0][k - 1] * (n - 1);
                dp[i][1][k] += dp[i - 1][0][k];
                dp[i][1][k] += dp[i - 1][1][k - 1] * 9;
                dp[i][1][k] += dp[i - 1][1][k];
            }
        }
    }
    cout << dp[N.length()][0][K] + dp[N.length()][1][K] << endl;
}


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

string s;
int cnt[26];

int main()
{
    cin >> s;
    if(s.size() < 26) {
        for(int i = 0; i < s.size(); i ++)
            cnt[s[i] - 'a'] ++;
        for(int i = 0; i < 26; i ++) {
            if(!cnt[i]) {
                s += 'a' + i;
                break;
            }
        }
        cout << s;
    } else if(s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1;
    } else {
        for(int i = 25; i >= 0; i --) {
            memset(cnt, 0, sizeof(cnt));
            for(int j = i - 1; j >= 0; j --) {
                cnt[s[j] - 'a'] ++;
            }
            for(int j = s[i] - 'a' + 1; j < 26; j ++) {
                if(!cnt[j]) {
                    s[i] = 'a' + j;
                    cout << s.substr(0, i + 1);
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
main :: IO()
main = do
    a <- getLine
    b <- getLine
    putStrLn $ getsolve a b

getsolve :: String -> String -> String
getsolve a b
    | aLen > bLen									= "GREATER"
    | aLen < bLen									= "LESS"
    | head a > head b								= "GREATER"
    | head a < head b								= "LESS"
    | aLen == 1										= "EQUAL"
    | otherwise										= getsolve (tail a) (tail b)
    where aLen = length a
          bLen = length b

Measured memory_bytes: 380
#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>

//定数
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl fact(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,O(logN)



signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl l[n];
    rep(i,n)cin >> l[i];
    intl ans = 0;
    rep(i, n){
        repi(j,i + 1, n){
            repi(k, j + 1, n){
                intl a[3];
                a[0] = l[i];
                a[1] = l[j];
                a[2] = l[k];
                sort(a, a + 3);
                if((a[0] == a[1])||(a[1] == a[2]))continue;
                if(a[0] + a[1] > a[2])ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636