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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<ll,P>;
using PP = pair<P, P>;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-9;

bool chmin(ll &a, ll b){
    if(a > b){
        a = b;
        return true;
    }else{
        return false;
    }
}

ll n, m, s;
vector<vector<P> > g;
vector<P> es;
vector<vector<ll> > dist;
vector<ll> c,d;

int main(){
    cin >> n >> m >> s;
    g.resize(n);
    for(int i=0;i<m;i++){
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        g[u].emplace_back(v,i);
        g[v].emplace_back(u,i);
        es.emplace_back(a,b);
    }
    c.resize(n);
    d.resize(n);
    for(int i=0;i<n;i++){
        cin >> c[i] >> d[i];
    }
    ll MAX_S = n*50;
    s = min(s, MAX_S);
    dist.resize(n,vector<ll>(MAX_S+1,INF));
    dist[0][s] = 0;
    priority_queue<P3,vector<P3>,greater<P3> > que;
    que.push(P3(0,P(0,s)));
    while(!que.empty()){
        auto tmp = que.top();
        que.pop();
        auto now = tmp.second.first, slv = tmp.second.second;
        if(tmp.first > dist[now][slv]) continue;
        for(auto &e : g[now]){
            auto nxt = e.first, idx = e.second;
            auto a = es[idx].first, b = es[idx].second;
            if(slv >= a && chmin(dist[nxt][slv-a],dist[now][slv]+b)){
                que.push(P3(dist[nxt][slv-a],P(nxt,slv-a)));
            }
            ll ns = min(slv+c[now], MAX_S);
            if(chmin(dist[now][ns], dist[now][slv]+d[now])){
                que.push(P3(dist[now][ns],P(now,ns)));
            }
        }
    }
    for(int i=1;i<n;i++){
        ll ans = INF;
        for(int j=0;j<=MAX_S;j++){
            chmin(ans,dist[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 7312
#include "bits/stdc++.h"
using namespace std;

int main() {
	
	int h, w;
	cin >> h >> w;
	set<int> hor, ver;
	string grid[h];
	for (int i=0; i<h; i++) {
		string s;
		cin >> s;
		for (int j=0; j<w; j++) {
			if (s[j] == '#') {
				hor.insert(i);
				ver.insert(j);
			}
		}
		grid[i] = s;
	}
	
	vector<int> f(hor.begin(), hor.end());
	vector<int> g(ver.begin(), ver.end());
	
	for (int i=0; i<f.size(); i++) {
		for (int j=0; j<g.size(); j++) {
			cout << grid[f[i]][g[j]];
		}
		cout << endl;
	}
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int n,l;
    cin>>n>>l;
    vector<int> a(n);
    rep(i,n) a[i]=l+i;
    if(a[0]<=0 && a[n-1]>=0) cout<<accumulate(ALL(a),0)<<endl;
    else if(a[0]>0 && a[n-1]>0) cout<<accumulate(ALL(a),0)-a[0]<<endl;
    else cout<<accumulate(ALL(a),0)-a[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def main():
    N, L = map(int, readline().rstrip().split())
    A = [L+i-1 for i in range(1, N+1)]
    A_abs = [abs(a) for a in A]
    mi_idx = A_abs.index(min(A_abs))
    print(sum(A) - A[mi_idx])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

ll gcd(ll x, ll y){
  return y ? gcd(y, x%y) : x;
}

ll lcm( ll m, ll n ){
	if ( ( 0 == m ) || ( 0 == n ) ) return 0;
    return ((m / gcd(m, n)) * n);// lcm = m * n / gcd(m,n)
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
}

Measured memory_bytes: 256
n = int(input())
f = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]
ans = -float("inf")
for i in range(1, 2**10):
    tf = [False]*10
    for j in range(10):
        if (i>>j)&1:
            tf[j] = True
    cnt1 = 0
    for j in range(n):
        cnt2 = 0
        for k in range(10):
            if tf[k] and f[j][k]:
                cnt2 += 1
        cnt1 += p[j][cnt2]
    ans = max(ans, cnt1)
print(ans)

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

using namespace std;

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

    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;

    cout<<-((h1*60)+m1)+((h2*60)+m2)-k<<"\n";


    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define endl '\n'
#define inf 9223372036854775807
#define maxn 3000001
#define mod (ll)(1e9+7)
#define int ll
 
using namespace std;
 
void io(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

int t,a,b,c,n,d,l,r,k;
int h[maxn];
int dp[maxn];

int32_t main(){
io();
IOS;    
		cin>>n;
		cin>>k;
		for(int i=1;i<=n;i++)cin>>h[i];

		dp[0]=0;
		dp[1]=0;
		h[0]=inf;
		for(int i=2;i<=n;i++){
			dp[i]=inf;
			for(int j=i-1;j>=1 && j>=i-k;j--){
				dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
			}
		}
		cout<<dp[n]<<endl;

       



        

        


        
    
        
        
                


 
        
 
 
 
        
 
 
 
 
        
        
 
        
        
 
    
    
    
    
 
 
       
 
 
 
 
      
   
 
 
 
 
}

Measured memory_bytes: 5188
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef set <int> st;
typedef set <char> stc;
typedef vector<int>::iterator itr;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sq(a) a*a
#define cu(a) (sq(a)*a)
#define sf1(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d", &a , &b)
#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n", a , b)
#define Last(i) ( (i) & (-i) )
 
const int mod = 1000000007;
const int maxn = (int)1e5+30;
const ll nnn = (ll)5e7+5;
const int inf = 1e9+9;
const ll INF = 1e18;

int main() {
   
	ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);	
    
    int n,a,b,c;
    int d[maxn];
    
    cin >> a >> b;
    
    ll ans = 0;
    
    for(int i = a-1; i >=0;i-- ) ans += i;
     for(int i = b-1; i >=0;i-- ) ans += i;\
     
     cout << ans ;
    
    
    return 0;
    
}


Measured memory_bytes: 256
package main

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

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

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

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

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

var abc [200][200]int

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

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

	n := getNextInt(scanner)
	imm := IntMapMap{}

	for i := 0; i < n-1; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		c := getNextInt(scanner)
		imm.set(a, b, c)
		imm.set(b, a, c)
	}
	distance := make([]int64, n)
	color := make([]int, n)
	q := getNextInt(scanner)
	k := getNextInt(scanner) - 1

	queue := []int{k}
	color[k] = 1

	for len(queue) > 0 {
		p := queue[0]
		queue = queue[1:]
		for to, cost := range imm[p] {
			if color[to] != 0 {
				continue
			}
			color[to] = 1
			distance[to] = distance[p] + int64(cost)
			queue = append(queue, to)
		}
	}

	for i := 0; i < q; i++ {
		x := getNextInt(scanner) - 1
		y := getNextInt(scanner) - 1

		fmt.Fprintln(writer, distance[x]+distance[y])
	}

	writer.Flush()
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}

func (m IntMap) set(key, n int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key] = n
}

func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

// IntMapMap ...
type IntMapMap map[int]IntMap

func (m IntMapMap) get(key1, key2 int) int {
	if _, ok := m[key1][key2]; ok {
		return m[key1][key2]
	}
	return 0
}

func (m IntMapMap) set(key1, key2, n int) {
	if _, ok := m[key1]; ok == false {
		m[key1] = make(IntMap, 0)
	}
	m[key1].set(key2, n)
}

func (m IntMapMap) increment(key1, key2 int) {
	if _, ok := m[key1]; ok == false {
		m[key1] = make(IntMap, 0)
	}
	m[key1].increment(key2)
}


Measured memory_bytes: 42112
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
    FOR(i,2,p) {
      if (p%i==0) return false;
    }
  return true;
}

int main(){
  string s;
  REP(i,3){
    cin >> s;
    cout << s[i];
  }
  return 0;
}

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

int main(){
int N;
cin>>N;
vector<int> d(N);
for(int i=0;i<N;i++){
   cin>>d[i];
}
sort(d.begin(),d.end());
int a=d[N/2]-d[N/2-1];
cout<<a<<endl;


return 0;
}


Measured memory_bytes: 3768
function spilitInput(input) {
  var splited = [];
  var rows = input.split('\n');
  for (var i = 0; i < rows.length; i += 1) {
    splited.push(rows[i].split(' '));
  }
  return splited;
}
function Main(input) {
  var splited = spilitInput(input);
  var n = splited[0][0];
  var a = splited[0][1];
  var b = splited[0][2];
  var s_total = 0;
  for (var i = 1; i <= n; i += 1) {
    var sum = 0;
    String(i).split('').forEach(function(i_n){ sum += parseInt(i_n,10); });
    if (a <= sum && sum <= b) {
      s_total+=i;
    }
  }
  
  console.log(s_total);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 33516
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define CASET           \
    int ___T;           \
    scanf("%d", &___T); \
    for (int __CS = 1; __CS <= ___T; __CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
LL bin(LL x, LL n, LL MOD)
{
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1)
            ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const int maxn = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9 + 7;
int main()
{
    int a, b;
    cin >> a >> b;
    cout << (max(a + b, max(a * b, a - b))) << endl;
}

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

int main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  int a=(n/x)*(m/y);
  int b=n*m-a;
  if(n%x==0&&m%y==0){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
    int c=1e9;
    for(int i=1;i<=n;i++){
      for(int j=1;j<=m;j++){
        if(i%x==0&&j%y==0){
          cout << -c;
        }
        else{
          cout << (c-1)/(x*y-1);
        }
        cout << " ";
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, n; cin >> h >> n;
  	vector<int> moves;
  	for (int i = 1; i <= n; i++) {
      	int k; cin >> k;
      	moves.push_back(k);
    }
  	int sum = 0;
  	for (int i: moves) {
    	sum+=i;
    }
  	if (sum < h) cout << "No";
  	else cout << "Yes";
}

Measured memory_bytes: 892
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}
fn main() {
    input!{ n: usize, a: [i32;n] }
    let mut max = -1;
    let mut max_index = 200001;
    for i in 0..n {
        if max < a[i] {
            max = a[i];
            max_index = i;
        }
    }
    for i in 0..n {
        if max_index == i {
            let mut local_max = -1;
            for j in 0..n {
                if i == j {
                    continue;
                } else {
                    if local_max < a[j] {
                        local_max = a[j];
                    }
                }
            }
            println!("{}", local_max);
        } else {
            println!("{}", max);
        }
    }

}

Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    int t,i,j,n,m,k,x,y;
    cin>>n>>m>>k;
    int r[n+1],c[m+1];
    memset(r,0,sizeof(r));
    memset(c,0,sizeof(c));
    map<pi,int>mp;
    for(i=0;i<k;i++)
    {
        cin>>x>>y;
        r[x]++,c[y]++;
        mp[{x,y}]=1;
    }
    x=*max_element(r,r+n+1);
    y=*max_element(c,c+m+1);
    vector<int>p;
    vector<int>q;
    for(i=0;i<=n;i++)
    {
        if(r[i]==x)
        {
            p.pb(i);
        }
    }
    for(i=0;i<=m;i++)
    {
        if(c[i]==y)
        {
            q.pb(i);
        }
    }
    int l1=p.size();
    int l2=q.size();
    for(i=0;i<l1;i++)
    {
        for(j=0;j<l2;j++)
        {
            x=p[i];
            y=q[j];
            if(mp[{x,y}]==0)
            {
                cout<<r[x]+c[y]<<"\n";
                return 0;
            }
        }
    }
    cout<<r[p[0]]+c[q[0]]-1<<"\n";
    return 0;
}



Measured memory_bytes: 28428
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s;
	cin >> n >> s;
	int maxv = 0;
	reps(i,n-1){
		string t(s,0,i);
		string k(s,i,n-i);
		int cnt = 0;
		unordered_map<char,bool> mp,mp2;
		rep(j,t.size()){
			mp[t[j]] = true;
		}
		rep(j,k.size()){
			cnt += (mp[k[j]] && !mp2[k[j]]);
			mp2[k[j]] = true;
		}
		maxv = max(maxv,cnt);
	}
	cout << maxv << '\n';

	return 0;
}


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

void Main() {
  string d[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  string s;
  cin >> s;
  for (int i = 0; i < 7; i++) {
    if (d[i] == s) {
      cout << 7 - i << endl;
      return;
    }
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; k < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,M;
  cin  >> N >> M;
  vi L(N),R(N);

  rep(i,M) {
    int l,r;
    cin >> l >> r;
    L[l-1]++;
    R[r-1]++;
  }
  int lm = INF,rm = INF;
  int a = 0,b= 0;
  rep(i,N) {
    a += L[i];
    if(a == M) {
      lm = i;
      break;
    }
  }
  drep(i,N) {
    b += R[i];
    if(b == M) {
      rm = i;
      break;
    }
  }
  cout << max(rm - lm + 1,0) << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
char alp[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

int num_alp (char letter){
    return letter-'a';
}

int vec[26];

int main(){
    int M =pow(10,9)+7;
    int N; cin >> N;
    string S; cin >> S;

    for(int i=0; i<N; i++){
        vec[num_alp(S.at(i))]++;
    }

    long long ans =1;
    for(int i=0; i<26; i++){
        ans *= (vec[i]+1);
        ans = ans %M;
    }
    cout << ans-1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    // 整数の入力
	int n;
    int a[100000];
  	bool flag[100000];
    int count,count_s;
    unsigned int ans=0;
    int counts=0;

    cin >> n;
    for(int i=0;i<n;i++){
       cin >> a[i];
    }
	
    for(int i=0;i<n-1;i++){
       if(a[i]>a[i+1]){
         	if(flag[i]==false){
              a[i] -= 1;
              flag[i]=true;
              i = i-2;
            }else{
			  cout << "No" << endl;
              return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
//#include <queue>

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

using namespace std;

typedef long long int llint;

const long long int INF = 1 << 30; //10^10
const llint MOD = 998244353;

inline void maxch(int& a, int b) {if (a < b) a = b;}

int bs(vector<int>& h, llint l, llint r,int a, int b) {
	//[l,r)
while (r - l > 1) {
	llint mid = l + (r - l) / 2;
	llint t = mid, attcnt = 0;

	rep(i, h.size()) {
		if (h[i] - t * b > 0) attcnt += (h[i] - t * b - 1) / (a - b) + 1;
		if (attcnt > t) break;
	}
	if (attcnt > t) l = mid;
	else r = mid;
}

return r;
}

int main() {
int n, a, b;
cin >> n >> a >> b;
vector<int> h(n);
int maxh = 0;
rep(i,n) {cin >> h[i]; maxch(maxh,h[i]); }

int l = 0, r = (maxh-1)/b + 1; 
cout << bs(h, l, r, a, b) << endl;
}


Measured memory_bytes: 640
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from bisect import bisect_left

def getNearstValue(lst, num):
    idx = bisect_left(lst, num+1)
    if abs(lst[idx]-num) > abs(lst[idx-1]-num):
        idx -= 1
    return idx

def main():
    n = II()
    aa = MII()
    if n == 2: print(*aa); exit(0)
    aa.sort()
    ans_n = aa[-1]
    m = ans_n/2
    idx = getNearstValue(aa, m)
    ans_r = aa[idx]
    print(ans_n, ans_r, end= ' ')

if __name__ == '__main__':
    main()


Measured memory_bytes: 14428
n=int(input())
F = n+5
mod = 10**9+7
fact = [1]*F
inv = [1]*F
for i in range(2,F):
    fact[i]=(fact[i-1]*i)%mod
inv[F-1]=pow(fact[F-1],mod-2,mod)
for i in range(F-2,1,-1):
    inv[i] = (inv[i+1]*(i+1))%mod

#invnum[0] cant be used
invnum=[fact[i-1]*inv[i] for i in range(n)]

graph=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

stack=[0]
order=[0]
parent=[-1]*n
comb=[0]*n
size=[1]*n

# BFS order
while stack:
    node = stack.pop()
    for neib in graph[node]:
        if neib!=parent[node]:
            stack.append(neib)
            order.append(neib)
            parent[neib]=node

#calc size including self
for node in order[n-1:0:-1]:
    size[parent[node]]+=size[node]

#calc root comb
comb[0]=fact[n-1]
for node in range(1,n):
    comb[0]*=invnum[size[node]]
    comb[0]%=mod

#calc all comb
for node in order[1:]:
    comb[node]=comb[parent[node]]*size[node]*invnum[n-size[node]]%mod

print(*comb,sep="\n")

Measured memory_bytes: 123956
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    ll n; cin>>n;
    ll a[n+1],b[n];
    for(ll i=0; i<n+1; i++)
        cin >> a[i];
    for(ll i=0; i<n; i++)
        cin >> b[i];
    ll ans = 0;
    for(ll i=0; i<n; i++){
        ll tmp = min(a[i], b[i]);
        ans += tmp;
        a[i] -= tmp;
        b[i] -= tmp;
        if(b[i]){
            tmp = min(b[i], a[i+1]);
            ans += tmp;
            a[i+1] -= tmp;
            b[i] -= tmp;
        }
    }
    OUT(ans);
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
using ll = long long int;

ll a, b;
string s;
int main(void) {
	cin >> a >> b;
	if (0 < a)
		s = "Positive";
	else if (a == 0) {
		s = "Zero";
	}
	else {
		if(b>=0)
			s = "Zero";
		else {
			if ((b - a + 1) % 2 == 0)
				s = "Positive";
			else
				s = "Negative";
		}
	}

	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
// This is the start of the template//
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
void input(){
#ifndef ONLINE_JUDGE 
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout); 
#endif
}
#define mod 1000000007
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define sortall(a) sort(a.begin(),a.end())
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
//this is the end of my template //
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	input();
	ll a,b,c,k,req=0;
	cin>>a>>b>>c>>k;
//	cout<<k<<endl;
	while(a>=b)
	{
		b*=2;
		req++;
	}

	while(b>=c)
	{
		c*=2;
		req++;
	}
	//cout<<a<<" "<<b<<" "<<c<<endl;
	//cout<<req<<" ";
	if(req>k)
		cout<<"No\n";
	else
		cout<<"Yes\n";
	
}	




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


using namespace std;

int main(){
	long int N, A, B;
	cin >> N >> A >> B;
	long int ans, cnt;

	cnt = N / (A + B);
	ans = cnt * A;
	if (N % (A + B) > A) {
		ans += A;
	}
	else {
		ans += N % (A + B);
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in();
    map<int, int> m;
    rep(i, n)
    {
        int a = in();
        m[a]++;
    }
    int ans = 0;
    for (auto x : m)
    {
        if (x.second % 2 == 1)
            ++ans;
    }
    cout << ans << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define int long long
#define ll long long
const int maxn=2e5+1000;
using namespace std;
int n,m,q,fa[maxn],check[maxn];
vector<pair<int,int> >one,zero;
pair<int,int>add;
int get(int x) {
    if(fa[x]==x)return x;
    fa[x]=get(fa[x]);
    return fa[x];
}
void uni(int u,int v){fa[get(u)]=get(v);}
signed main() {
    scanf("%lld%lld%lld",&n,&m,&q);
    for(int i=1;i<=n;i++)fa[i]=i;
    for(int i=1;i<=q;i++) {
        int u,v,c;scanf("%lld%lld%lld",&u,&v,&c);u++,v++;
        add.first=u,add.second=v;
        if(c==1) one.push_back(add);
        else zero.push_back(add);
    }
    for(int i=0;i<zero.size();i++) {
        if(get(zero[i].first)==get(zero[i].second)) {
           continue;
        }
        uni(zero[i].first,zero[i].second);
    }

    for(int i=0;i<one.size();i++) {
        if(get(one[i].first)==get(one[i].second)) {
            printf("No");return 0;
        }
    }

    int block=0;for(int i=1;i<=n;i++)if(!check[get(i)]){check[get(i)]=1;block++;}
    int p=m-(n-block);ll lim=(ll)block*(block-1);lim/=2;


   // cerr<<block<<' '<<p<<' '<<lim<<endl;
    if(one.size()==0&&block-1<=p&&p<=lim) {
        printf("Yes");return 0;
    }
    if(one.size()&&block<=p&&p<=lim) {
        printf("Yes");return 0;
    }
    printf("No");return 0;
}

Measured memory_bytes: 3572
<?php
# B - Bite Eating

fscanf(STDIN, "%d %d", $N, $L);

$array = [];
for ( $i = 0 ; $i < $N ; $i++ ) {
    $array[] = ($L + $i);
}

$a = 100;
foreach ($array as $value) {
    if (abs($a) > abs($value)) {
        $a = $value;
    }
}

$sum = 0;
foreach ($array as $value) {
    $sum += $value;
}

echo ($sum - $a) . PHP_EOL;


Measured memory_bytes: 4728
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int n;
    cin>>n;
    ll curr=0;
    rep(i,1,1e6){
        if((10*curr+7)%n==0) return cout<<i,0;
        curr=(curr*10+7)%n;
    }
    cout<<-1;
    return 0;
}


Measured memory_bytes: 3648
def resolve():
	import math
	X, K, D = map(int, input().split())
	X, K, D = abs(X), abs(K), abs(D)
	n = math.floor(X/D)
	A = X - n*D
	k = K - n
	if k < 0:
		print(X - (K*D))
	elif k%2 == 0:
		print(A)
	else:
		print(abs(A-D))
resolve()


Measured memory_bytes: 9160
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	string s;
	scan(N);
	scan(s);
	rep(i,4){
		char kind[100000];
		if(i==0) kind[0]='S',kind[1]='S';
		else if(i==1) kind[0]='S',kind[1]='W';
		else if(i==2) kind[0]='W',kind[1]='S';
		else if(i==3) kind[0]='W',kind[1]='W';
		int consistent;
		for(int j=1;j<=N-2;j++){
			if((kind[j]=='S')^(s[j]=='o')) kind[j+1]=(kind[j-1]=='S' ? 'W' : 'S');
			else kind[j+1]=kind[j-1];
		}
		if(((kind[0]=='S')^(s[0]=='o')^(kind[1]==kind[N-1]))&&((kind[N-1]=='S')^(s[N-1]=='o')^(kind[N-2]==kind[0]))){
			consistent=1;
		}
		else{
			consistent=0;
		}
		if(consistent){
			rep(j,N) printf("%c",kind[j]);
			kaigyo;
			return 0;
		}
		else continue;
	}
	prin(-1);
	return 0;
}


Measured memory_bytes: 640
//prepared by dumb
#include<bits/stdc++.h>
using namespace std;
#define   ll long long int
#define   dl double  
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scld(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   Pi acos(-1.0)
#define   INF 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ll a, b, c=1, d, e, f = 0, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
ll cnt = 0, ans = 0, l1, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
    string  str1, str2;

      scll(n);
      l1=(n%1000);
      if(l1>0)
     cout<<abs(l1-1000)<<'\n';
   else
    cout<<0<<'\n';
return 0;
}

Measured memory_bytes: 3684
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    n = len(s)
    Llis = [0] * (n + 1)
    Rlis = [0] * (n + 1)
    for i in range(n):
        if s[i] == "<":
            Llis[i + 1] = 1
        else:
            Rlis[i] = 1
    for i in range(n):
        if Llis[i + 1] == 0:
            continue
        Llis[i + 1] += Llis[i]
    for i in range(n):
        if Rlis[-i - 2] == 0:
            continue
        Rlis[-i - 2] += Rlis[-i - 1]
    ans = 0
    for i in range(n + 1):
        ans += max(Rlis[i], Llis[i])
    print(ans)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 99804
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
typedef long long ll;
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; }
using namespace std;

int main(){
	int n, ans = 0, ab = 0, a = 0, b = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < s.size()-1; j++) {
			if(s[j]=='A' && s[j+1]=='B') ans++;
		}
		if(s[0] == 'B' && s[s.size()-1] == 'A') ab++;
		else if(s[0] == 'B') b++;
		else if(s[s.size()-1] == 'A') a++;
	}
	if(ab==0) ans += min(a,b);
	else{
		if(a+b==0) ans += ab - 1;
		else ans += ab + min(a,b);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

template <typename T>
class BIT {
 public:
  BIT(int n) : v_(n) {}
  T Sum(int i) const {
    T ret = 0;
    while (i >= 0) {
      ret += v_[i];
      i = (i & (i + 1)) - 1;
    }
    return ret;
  }
  T Get(int i) const { return Sum(i) - Sum(i - 1); }
  void Add(int i, T v) {
    while (i < v_.size()) {
      v_[i] += v;
      i |= i + 1;
    }
  }

 private:
  std::vector<T> v_;
};

struct Q {
  int l, r, i, v;
};

int main() {
  in(int, n, q);
  V<int> c(n);
  rep(i, n) cin >> c[i];
  V<Q> qs;
  rep(i, q) {
    in(int, l, r);
    --l, --r;
    qs.push_back({l, r, i, 0});
  }
  sort(all(qs), [](const Q& a, const Q& b) { return a.r < b.r; });
  V<int> seen(n, -1);
  int seen_cnt = 0;
  BIT<int> bit(n);
  auto qit = qs.begin();
  V<int> ans(q);
  rep(i, n) {
    int& s = seen[c[i] - 1];
    if (s == -1) {
      ++seen_cnt;
    } else {
      bit.Add(s, -1);
    }
    s = i;
    bit.Add(i, 1);
    while (qit != qs.end() && qit->r == i) {
      ans[qit->i] = seen_cnt - bit.Sum(qit->l - 1);
      ++qit;
    }
  }
  rep(i, q) out(ans[i]);
}

Measured memory_bytes: 19396
#include <iostream>
#include<queue>
using namespace std;
int main()
{
	int num;
	cin >> num;
	priority_queue<int> p[num];//默认是降序则弹出的第一个则为最大数
	int oper;
	cin >> oper;
	while(oper--)
	{
		int opr;
		cin >> opr;
		switch (opr)
		{
			int num;
		case 0:
			cin >> num;
			int integrate;
			cin >> integrate;
			p[num].push(integrate);
			break;
		case 1:
			cin >> num;
			if (p[num].empty() == false)
			{
				cout << p[num].top() << endl;
			}
			break;
		case 2:
			cin >> num;
			if (p[num].empty() == false)
				p[num].pop();
			break;
		}

		}

}



Measured memory_bytes: 4016
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, k = map(int, readline().split())
  h = list(int(readline()) for i in range(n))
  h.sort()
  ans = INF
  for i in range(n-k+1):
    ans = min(ans,h[i+k-1]-h[i])
  print(ans)
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 17512
#include <stdio.h>

int main (void)
{
    int n, x, m, i, min = 1000;

    scanf("%d %d", &n, &x);
    for (i = 0; i < n; i++) {
        scanf("%d", &m);
        x -= m;
        if (m < min) min = m;
    }

    printf("%d\n", n + (x / min));
}


Measured memory_bytes: 128
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    less = sum(A) - sum(B)
    if less < 0:
        return print(-1)
    D = [a - b for a, b in zip(A, B)]
    D.sort()
    ans = 0
    cur_sum = 0
    for d in D:
        if d < 0:
            ans += 1
            cur_sum += d
        else:
            break
    for d in D[::-1]:
        if cur_sum >= 0:
            break
        ans += 1
        cur_sum += d
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84784
import sys
from copy import deepcopy
def input(): return sys.stdin.readline().strip()

def main():
    N, x = map(int, input().split())
    A = list(map(int, input().split()))
    if x == 0:
        print(sum(A))
        return

    B = deepcopy(A)
    ans1 = 0
    for i in range(1, N):
        ans1 += max(0, (A[i - 1] + A[i]) - x)
        if A[i] + A[i - 1] > x:
            if A[i] < (A[i - 1] + A[i]) - x:
                A[i] = 0
            else:
                A[i] -= (A[i - 1] + A[i]) - x
    ans2 = 0
    for i in range(N - 2, -1, -1):
        ans2 += max(0, (B[i] + B[i + 1]) - x)
        if B[i] + B[i + 1] > x:
            if B[i] < (B[i] + B[i + 1]) - x:
                B[i] = 0
            else:
                B[i] -= (B[i] + B[i + 1]) - x
    ans = min(ans1, ans2)
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 89980
#include <iostream>
#include <vector>
#include <map>

using namespace std;

long long gcd(long long a, long long b);

long long gcd(long long a, long long b)
{
	if (a < b) {
		long long t = a;
		a = b;
		b = t;
	}

	if (b == 0) {
		return a;
	}

	long long r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

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

	int b[1001];
	fill(b, b + 1001, 1);
	b[0] = b[1] = 0;
	for (int i = 2; i * i <= 1000; i++) {
		if (b[i] == 1) {
			for (int j = i + i; j <= 1000; j += i) {
				b[j] = 0;
			}
		}
	}
	vector<int> v;
	for (int i = 2; i <= 1000; i++) {
		if (b[i] == 1) {
			v.emplace_back(i);
		}
	}
	
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < v.size(); j++) {
			if (d[i] % v[j] == 0) {
				mp[v[j]]++;
				while (d[i] % v[j] == 0) {
					d[i] /= v[j];
				}
			}
		}
		if (d[i] != 1) {
			mp[d[i]]++;
		}
	}
	
	bool f = true;
	for (auto & i : mp) {
		if (i.second != 1) {
			f = false;
			break;
		}
	}
	if (f) {
		cout << "pairwise coprime" << endl;
		return 0;
	}

	int g = a[0];
	for (int i = 1; i < n; i++) {
		g = gcd(g, a[i]);
	}

	if (g == 1) {
		cout << "setwise coprime" << endl;
	} else {
		cout << "not coprime" << endl;
	}

	return 0;
}

Measured memory_bytes: 14752
import java.util.*;
public class Main {
	public static void main(String[] args){
	   Scanner sc = new Scanner(System.in);
	   String str = sc.next();
      
      if(str.length()==1 && !str.equals("@")){
 
      if(Character.isUpperCase(str.charAt(0))){
      	str = "A";
      }else{
        str = "a";
      }
		// 出力
		System.out.println(str);     
	}
        
      }
}

Measured memory_bytes: 35704
import java.util.*;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String s = sc.next();
      char x = s.charAt(0);
      int count=1;
      for(int i=0;i<n;i++){
        if(x!=s.charAt(i)){
          x = s.charAt(i);
          count++;
        }
      }     
        System.out.println(count);
    }
}

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

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

  string s;
  cin >> s;

  regex re(R"(.+(?=FESTIVAL$))");
  smatch m;

  regex_search(s, m, re);

  cout << m.str() << endl;

  return 0;
}

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

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

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

    int far_index = 1;
    int far_dist = 0;
    for (int i = 1; i <= n; i++) {
        int dist;
        if (i == n) dist = k - a[i] + a[1];
        else dist = a[i + 1] - a[i];

        if (far_dist < dist) {
            far_index = i;
            far_dist = dist;
        }
    }

    cout << k - far_dist << endl;

    return 0;
}

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

int pow(int a, int b)
{
    int res = 1;
    while (b > 0)
    {
        res *= a;
        b--;
    }
    return res;
}

int main()
{
    int d, n;
    cin >> d >> n;
    if (n == 100)
    {
        n = 101;
    }
    cout << n * pow(100, d);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt(),S=sc.nextInt();
		int count = 0;
		for(int i=0;i<=K;i++) {
			for(int j=0;j<=K;j++) {
				int l=S-i-j;
				//System.out.println(l);
				if(l>=0 && l<=K && i+j+l==S) {
					count++;
				}
			}
		}
		System.out.println(count);


	}
	public static int sample(int n) {
		return n;
	}

}


Measured memory_bytes: 23892