akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
#define dump(x) cerr << '[' << #x << " = " << x << ']' << endl;
using namespace std;

int n1(int a, int j) {
    if(a <= 0)
        return 0;
    int ans = 0, T = 1ll << j + 1;
    a   += 1;
    ans += (a / T) * (T >> 1);
    ans += max(0ll, a % T - T / 2);
    return ans;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int j = 0; j < 50; ++j) {
        int nj = n1(b, j) - n1(a - 1, j);
        nj %= 2;
        if(nj) ans |= (1ll << j);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = 0
mn = 10**10
cnt =0
for i in a:
    mn = min(mn,abs(i))
    ans += abs(i)
    if i<0:
        cnt+=1
        cnt%=2
if cnt:
    print(ans-mn*2)
else:
    print(ans)

Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    VI h(n);
    REP(i,n)cin >> h[i];
    int res=0;
    REP(i,n){
        if(k <= h[i])res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//useful library
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数

int main(){
    int long long N, K, A;
    cin >> N >> K;
    int long long t = N % K;
    A = min(t, (K - t));
    cout << A << endl;
    return 0;
}
//https://img.atcoder.jp/abc161/editorial.pdf

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h1 = sc.nextInt();
		int m1 = sc.nextInt();
		int h2 = sc.nextInt();
		int m2 = sc.nextInt();
		int k = sc.nextInt();
		int start = h1 * 60 + m1;
		int end = h2 * 60 + m2;
		System.out.println(Math.max(end - start - k, 0));
	}
}


Measured memory_bytes: 35784
N, K = (int(i) for i in input().split())

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

from collections import deque
def BFS(N, K, graph, start):
    c = [-1 for i in range(N)]
    Q = deque([])
    Q.append(start)
    c[start] = K
    while Q:
        v = Q.popleft()
        if v == start:
            lc = K - 1
        else:
            lc = K - 2
        for u in graph[v]:
            if c[u] == -1:
                if lc == 0:
                    print(0)
                    exit()
                c[u] = lc
                lc -= 1
                Q.append(u)
    return c

c = BFS(N, K, graph, 0)

MOD = 10**9+7
ans = 1
for i in c:
    ans *= i
    ans %= MOD
print(ans)

Measured memory_bytes: 27064
N=gets.to_i

l = N.to_s.length
n = ['3','5','7']
m = ['3','5','7']
2.upto(l) do |i|
    tmp = []
    m.each do |j|
        n.each do |k|
            tmp << k + j
        end
    end
    n += tmp
end
n.uniq!

ans = 0
n.each do |v|
    if v.include?('3') && v.include?('5') && v.include?('7')
        if v.to_i <= N
            ans += 1
        end
    end
end
puts ans


Measured memory_bytes: 18528
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    char s[5];
    cin >> s;
    bool f=0;
    for(int i=0;i<5;i++){
        if(s[i]=='A' && s[i+1]=='C'){
            f=1;
        }
    }
    cout << (f==1?"Yes":"No") << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import bisect
import collections

n=int(input())
a = [int(i) for i in input().split()]
a.sort()
#print(a)

checked=collections.Counter(a)

ans=0

while(a):
    c=a.pop()
    if checked[c]==0:
        continue
    checked[c]-=1
    d=c
    keta=0
    while(d!=0):
        d=d//2
        keta +=1
    x = 2**keta - c
#    print(c,x)
    i = bisect.bisect_right(a, x)
    if i and a[i-1] == x and checked[x]>0:
        ans += 1
        checked[x]-=1
        
#    print(checked)
#        print(checked)
#        print(a[i],c,"xxx")




print(ans)



Measured memory_bytes: 33216
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long            ll;
typedef unsigned long long   ull;
typedef vector<int>          vi;
typedef vector<ll>           vl;
typedef pair<int, int>       pi;
typedef pair<ll, ll>         pl;
typedef vector<pi>           vpi;
typedef vector<pl>           vpl;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define read        freopen("in.c", "r", stdin)
#define write       freopen("out.c", "w", stdout)
#define all(a)      a.begin(), a.end()
#define bye         exit(0)
#define mp          make_pair
#define ff          first
#define ss          second
#define L(x)        ((x) << 1)
#define R(x)        ((x) << 1 | 1)
#define SZ(a)       (ll)(a).size()
#define pb          push_back
#define eb          emplace_back
#define eps         1e-9
#define inf         (1000000000)
#define infl        (1000000000000000000LL)
#define cs(p)       printf("Case %d:", (p)++)
#define ptc(c)      putchar(c)
#define gtc()       getchar()
#define nl          puts("")
#define sp          printf(" ")
#define out(a)      printf("%lld", (ll)(a))
#define SET(a, x)   memset((a), x, sizeof(a))
#define dbg(x)      cout << "--- " << #x << " = " << (x) << '\n'

ll bgm(ll a, ll b, ll m) {
    b = (b == -1) ? (m - 2) : b;
    a %= m;
    ll rem = 1;
    while(b != 0) {
        if(b&1)
            rem = (rem * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return rem;
}

inline ll in() {
    ll a;
    assert(scanf("%lld", &a) != EOF);
    return a;
}

const int MAX = 1000000 + 5;
const int LEN = 50;
const ll MOD = 1000000007;

int ara[5][4][11];
int b,f,r,v;



int main() {
    //read,write;
    int n,m;
    cin >> n >> m;
    int a[n+5][m+5],b[m+5],ans[n+5]={0};
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
        }
    }
    for(int i=1;i<=m;i++){
        cin >> b[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            ans[i]+=a[i][j]*b[j];
        }
    }
    for(int i=1;i<=n;i++) cout << ans[i] << endl;


    return 0;
}



Measured memory_bytes: 3112
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	int32_t res = N / 1.08;
	for (int32_t i = res - 10; i <= res+10; i++)
	{
		if ((i * 108) / 100 == N) {
			out << i << endl;
			return 0;
		}
	}
	out << ":(" << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[]){
    long a = readLong(),b=readLong(),c=readLong(),d=readLong();
    long max = a*c;
    if(max<a*d){
      max = a*d;
    }
    if(max<b*c){
      max = b*c;
    }
    if(max<b*d){
      max = b*d;
    }
    pl(max+"");
  }

  public static void sortA(int n[]){
    Arrays.sort(n);
  }

  static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
  public static String read(){
    try{
      return ctos((char)br.read());
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static char readC(){
    try{
      return (char)br.read();
    }catch(IOException e){
      e.printStackTrace();
      return (char)-1;
    }
  }
  public static String readL(){
    try{
      return br.readLine();
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static String readS(){
    StringBuilder sb = new StringBuilder();
    while(true){
      try{
        int k = br.read();
        if(k==-1||(char)k==' '||(char)k=='\n'){break;}
        sb.append((char)k);
      }catch(IOException e){
        e.printStackTrace();
      }
    }
    return sb.toString();
  }
  public static long readLong(){
    return stol(readS());
  }
  public static long stol(String s){
    return Long.parseLong(s);
  }
  public static int readI(){
    return stoi(readS());
  }
  public static String[] readSs(){
    return readL().split(" ");
  }
  public static int[] readIs(){
    return stoi(readSs());
  }
  public static int stoi(String s){
    return Integer.parseInt(s);
  }
  public static int[] stoi(String s[]){
    int a[]=new int[s.length];
    for(int i=0;i<s.length;i++){
      a[i]=stoi(s[i]);
    }
    return a;
  }
  public static String itos(int i){
    return String.valueOf(i);
  }
  public static String[] itos(int[] a){
    String s[]=new String[a.length];
    for(int i=0;i<a.length;i++){
      s[i]=itos(a[i]);
    }
    return s;
  }
  public static String ctos(char c){
    return String.valueOf(c);
  }
  public static String cstos(char[] c){
    return new String(c);
  }
  public static char stoc(String s){
    return s.charAt(0);
  }
  public static char[] stocs(String s){
    return s.toCharArray();
  }
  public static int[] Itoi(Integer a[]){
    int[]result=new int[a.length];
    for(int i=0;i<a.length;i++){
      result[i]=a[i];
    }
    return result;
  }
}


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

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<int> A;
    vector<int> B;
    int in;
    for (int i = 0; i < N + 1; i++)
    {
        cin >> in;
        A.emplace_back(in);
    }
    for (int i = 0; i < N; i++)
    {
        cin >> in;
        B.emplace_back(in);
    }
    
    long long cnt = 0;
    if (B[0] >= A[0])
    {
        cnt += A[0];
        B[0] -= A[0];
    }else
    {
        cnt += B[0];
        B[0] = 0;
    }
    
    
    for (int i = 1; i < N + 1; i++)
    {
        if (B[i - 1] >= A[i])
        {
            cnt += A[i];
        }else
        {
            if (B[i - 1] + B[i] > A[i])
            {
                cnt += A[i];
                B[i] -= A[i] - B[i - 1];
            }else
            {
                cnt += B[i - 1] + B[i];
                B[i] = 0;
            }
            
        }
        
    }
    
    cout << cnt << endl;

    return 0;
}

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

using namespace std;

#define all(x) begin(x), end(x)

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

constexpr int MOD = 1e9 + 7;
int sum(int a, int b, int mod=MOD) {
    int c = a + b;
    if (c >= mod) {
        c -= mod;
    }

    return c;
}

inline int prod(int a, int b, int mod=MOD) {
    return (1LL * a * b) % mod;
}

constexpr int MAXN = 1e5 + 5;
int n;
string s;
int dp[MAXN][13];

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

    cin >> s;
    n = s.size();

    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 13; ++j) {
            if (!dp[i][j]) continue;
            if (s[i] == '?') {
                for (int k = 0; k < 10; ++k) {
                    int v = (10 * j + k) % 13;
                    dp[i + 1][v] = sum(dp[i + 1][v], dp[i][j]);
                }
            } else {
                int v = (10 * j + s[i] - '0') % 13;
                dp[i + 1][v] = sum(dp[i + 1][v], dp[i][j]);
            }
        }
    }

    cout << dp[n][5] << '\n';
    
    return 0;
}


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

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

    int sum = 0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        sum += a;
    }

    if(sum >= h) cout << "Yes" << endl;
    if(sum <  h) cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);



int main()
{
    unsigned long long int L, R;
    std::cin >> L >> R;
    if(R-L>10000)
    {
        std::cout << 0 << std::endl;
        return 0;
    }
    unsigned long long int mi = 2019 * 2019;
    for(unsigned long long int i=L; i<=R; i++)
    {
        for(unsigned long long int j=i+1; j<=R; j++)
        {
            mi = std::min(mi, i*j%2019);
        }   
    }

    std::cout << mi << std::endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	s := scanString()

	for i := 0; i < len(s); i++ {
		fmt.Print("x")
	}

	fmt.Println()
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#define RG register
using namespace std;
const int N=1e5+10, M=2e5+10;
const long long mod=1e5+7;
struct dabt{
	int next,to,dis;
}e[M*6],hsh[M*2];
struct node{
	int u,dis;
	bool operator < (const node&x)const{return x.dis<dis;}
};
int n,m,head[N+2*M],k,dist[N+2*M],st[2*M],ed[2*M],cnt,kk;
int kh,h[mod+1];
bool vis[N+2*M];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
inline void add(int from,int to,int d){
	e[++k]=(dabt){head[from],to,d}; head[from]=k;
	e[++k]=(dabt){head[to],from,d}; head[to]=k;
}
inline void adde(int from,int to,int d){hsh[++kh]=(dabt){h[from],to,d}; h[from]=kh;}
inline int id(int a,int b){
	int ss=((long long)a*n%mod+b)%mod;
	for(int i=h[ss];i;i=hsh[i].next)
	{
		int v=hsh[i].to;
		if(st[v]==a && ed[v]==b) return hsh[i].dis;
	}
	st[++kk]=a; ed[kk]=b;
	adde(ss,kk,++cnt);
	return cnt;
}
/*
map<pair<int,int>,int> P;
int id(int u,int c) {
    if(P.find(make_pair(u,c))!=P.end())
        return P[make_pair(u,c)];
    return P[make_pair(u,c)]=++cnt;
}*/
inline void dij()
{
	priority_queue<node> pn;
	while(!pn.empty()) pn.pop();
	for(int i=1;i<=n+m*2;i++) dist[i]=2e9;
	pn.push((node){1,0}); dist[1]=0;
	while(!pn.empty())
	{
		node u=pn.top(); pn.pop();
		int x=u.u; vis[x]=1;
		for(int i=head[x];i;i=e[i].next)
		{
			int v=e[i].to;
			if(dist[v]>dist[x]+e[i].dis)
			{
				dist[v]=dist[x]+e[i].dis;
				if(!vis[v]) pn.push((node){v,dist[v]});
			}
		}
	}
}
int main()
{
//	freopen("Snuke's Subway Trip.in","r",stdin);
//	freopen(". out","w",stdout);
	read(n,m); cnt=n;
	for(int i=1,a,b,c;i<=m;i++)
	{
		read(a,b,c);
		int id1=id(a,c), id2=id(b,c);
		add(a,id1,1); add(id1,id2,0); add(id2,b,1);
	}
	dij();
	printf("%d\n",dist[n]==2e9 ? -1 : dist[n]/2);
//	for(int i=1;i<=9;i++) printf("%d\n",dist[i]);
	//fclose(stdin); fclose(stdout);
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}


const int MAX_N = 112345;
vector<int> g[MAX_N];

int ord[MAX_N]; // 訪れた順につける番号
int low[MAX_N]; // DFS 木の葉方向の辺を 0 回以上、後退辺を 1 回以下でたどり着ける ord の最小値
bool isArticulation[MAX_N];

void dfs(int u, int p, int &ordc) {
  low[u] = ord[u] = ordc++;
  int deg = 0;
  bool isa = false;
  for (int v : g[u]) if (v != p) {
    if (ord[v] == -1) { // まだ訪れてない
      deg++;
      dfs(v, u, ordc);
      low[u] = min(low[u], low[v]);
      if (ord[u] <= low[v]) isa = true;
    } else { // まだ (u,v) を使ってない
      // このとき (u,v) は後退辺
      low[u] = min(low[u], ord[v]);
    }
  }

  // 頂点 u が関節点 <=> u が DFS 木の根なら次数 > 1 かどうか、uがそれ以外なら ord[u] <= low[v] なる u の子 v が存在するかどうか
  isArticulation[u] = (p == -1 ? deg >= 2 : isa);
}
void lowlink(int N) {
  CLR(ord, -1);
  CLR(isArticulation, 0);
  int ordc = 0;
  REP(u, N) if (ord[u] == -1) {
    dfs(u, -1, ordc);
  }
}
// DFS 木の辺 e(u, v) が橋 <=> ord[u] < low[v]
bool isBridge(int u, int v) {
  if (ord[u] > ord[v]) swap(u, v);
  return ord[u] < low[v];
}

int main2() {
  REP(i, MAX_N) g[i].clear();
  int N = nextInt();
  int M = nextInt();
  REP(i, M) {
    int a = nextInt();
    int b = nextInt();
    g[a].push_back(b);
    g[b].push_back(a);
  }

  lowlink(N);

  vector<pair<int,int>> bridges;
  REP(i, N) {
    for (int j : g[i]) if (i < j) {
      if (isBridge(i, j)) bridges.push_back({i, j});
    }
  }
  sort(ALL(bridges));
  for (auto b : bridges) printf("%d %d\n", b.first, b.second);

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 8024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	d := nextInt()
	t := nextInt()
	s := nextInt()

	if s*t >= d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main() {
  int n, m;
  cin >> n >> m;
  auto d = atcoder::dsu(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    d.merge(a - 1, b - 1);
  }
  cout << d.groups().size() - 1;
  return 0;
}


Measured memory_bytes: 8948
n = int(input())
x = list(map(int, input().split()))

x_diff = []
for i in range(n-1):
    x_diff.append(x[i+1] - x[i])



def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

base = 1
for i in range(1, n):
    base *= i
    base %= 10**9+7

frac = []
for i in range(1, n):
    frac.append(base*modinv(i) % (10**9+7))

import itertools
frac = list(itertools.accumulate(frac))

ans = 0
for i in range(n-1):
    ans += frac[i]*x_diff[i]
    ans %= 10**9+7

print(ans)


Measured memory_bytes: 20008
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n = readint()

a = ord('a')-1
ans = []
i = 1
while n:
    if n%26==0:
        ans.append('z')
        n = n//26-1
    else:
        ans.append(chr(n%26+a))
        n//=26

ans.reverse()
print(''.join(ans))


Measured memory_bytes: 61948
import sys, math

if(__name__ == "__main__"):
    X = int( input().strip() )
    #map(int, input().strip() )
    if(X < 600):
        print("8")
    elif(X < 800):
        print("7")
    elif(X < 1000):
        print("6")
    elif(X < 1200):
        print("5")
    elif(X < 1400):
        print("4")
    elif(X < 1600):
        print("3")
    elif(X < 1800):
        print("2")
    else:
        print("1")


Measured memory_bytes: 9180
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int N,M;
ll F[1005][1005],Mx,A[1005],B[1005],C[1005];
inline ll DP(int _a,int _b,int _c){
	memset(F,192,sizeof F),Mx=**F;
	for (int i=0;i<=N;++i) F[i][0]=0;
	for (int i=1;i<=N;++i)
		for (int j=1;j<=i&&j<=M;++j)
			F[i][j]=max(F[i-1][j],F[i-1][j-1]+A[i]*_a+B[i]*_b+C[i]*_c);
	for (int i=M;i<=N;++i) Mx=max(Mx,F[i][M]);
	return Mx;
}
int main(){
	scanf("%d%d",&N,&M);
	for (int i=1;i<=N;++i) scanf("%lld%lld%lld",A+i,B+i,C+i);
	printf("%lld",max(max(max(DP(1,1,1),DP(1,1,-1)),max(DP(1,-1,1),DP(1,-1,-1))),max(max(DP(-1,1,1),DP(-1,1,-1)),max(DP(-1,-1,1),DP(-1,-1,-1)))));
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;
typedef long long int lli;


void solve(){
	lli n,w;
	cin>>n>>w;
	lli wt[n+1], val[n+1];
	for(int i=1; i<=n; i++){
		cin>>wt[i]>>val[i];
	}
	vector< vector<lli> > dp(n+1, vector<lli>(100001));
	for(int i=0; i<=n; i++){
		for(int j=0; j<=100000; j++){
			if(j==0){
				dp[i][j]=0;
				continue;
			}
			if(i==0){
				dp[i][j]=w+1;
				continue;
			}
			if(j-val[i]>=0){
				dp[i][j]=min(dp[i-1][j], dp[i-1][j-val[i]]+wt[i]);
			}
			else{
				dp[i][j]=min(wt[i], dp[i-1][j]);
			}
			//cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}
	int i=0;
	int ans=0;
	for(int i=0; i<=100000; i++){
		if(dp[n][i]<=w){
			ans=max(ans,i);
		}
		//cout<<dp[n][i]<<" ";
	}
	//cout<<endl;
	cout<<ans<<endl;
}

signed main(){
	//#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    //#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool etmin(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    char a;
    cin>>a;
    char ans = a + 1;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }




int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) {
		cin >> h[i];
	}
	int ans = 0;
	rep(i, n) {
		rep(j, i) {
			if (h[j] > h[i]) {
				break;
			}
			if (j == i - 1) {
				ans++;
			}
		}
	}
	cout << ans + 1 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll A,B,K;
  cin>>A>>B>>K;
  if(K<=A){
    cout<<A-K<<" "<<B<<endl; 
  }
  else{
    cout<<0<<" "<<max((ll)0,B+A-K)<<endl; 
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define all(x) x.begin(), x.end()
#define ll long long int
#define INF 2e9
#define fir first
#define sec second
using namespace std;
const int MOD = 1e9 + 7;

void Main() {
    int N, M;
    cin >> N >> M;

    vector<int> ok(N + 1, true);
    rep(i, 0, M) {
        int a;
        cin >> a;
        ok[a] = false;
    }

    vector<long long int> dp(N + 1);
    dp[0] = 1;
    rep(now, 0, N) {
        rep(next, now + 1, min(N, now + 2) + 1) {
            if (ok[next]) {
                dp[next] += dp[now];
                dp[next] %= MOD;
            }
        }
    }
    cout << dp[N] << endl;
    return;
}

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

Measured memory_bytes: 1408
#include <iostream>
    using std::cin;
    using std::cout;
    using std::endl;
#include <queue>
    using std::queue;
#include <utility>
    using std::pair;
#include <string>
    using std::string;

int main(){
    int time_sum=0;
    queue< pair<string, int> > Q;

    int n, q;

    cin >> n >> q;

    pair<string, int> tmp;

    for (int i = 0; i < n; ++i) {
        cin >> tmp.first >> tmp.second;

        if (tmp.second > q){
            time_sum += q;
            tmp.second -= q;
            Q.push(tmp);
        }else{
            time_sum += tmp.second;
            cout << tmp.first << " " << time_sum << endl;
        }
    }

    while (Q.size() > 0){
        tmp = Q.front(); Q.pop();

        if (tmp.second > q){
            time_sum += q;
            tmp.second -= q;
            Q.push(tmp);
        }else{
            time_sum += tmp.second;
            cout << tmp.first << " " << time_sum << endl;
        }
    }
}



Measured memory_bytes: 4276
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int mod =1e9+7;
int power(int x,int y,int p)
{ 
    int res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if((y & 1)==1) 
            res = (res * x) % p; 
        y = y >> 1;  
        x = (x * x) % p;  
    } 
    return res; 
} 
int32_t main()
{
    IOS;
    map<pair<int,int>,int>mp;
    int n;
    cin>>n;
    int twopow[n+5]={};
    twopow[0]=1;
    for(int i=1;i<n+3;i++)
        twopow[i]=(2*twopow[i-1])%mod;
    int arr[n][2]={};
    int ans=1;
    int restans=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i][0]>>arr[i][1];
        if(arr[i][0]==0 && arr[i][1]==0)
        {
            restans++;
            continue;
        }
        int gcd = __gcd(abs(arr[i][0]),abs(arr[i][1]));
        gcd=max(gcd,1ll);
        int a=arr[i][0]/gcd;
        int b=arr[i][1]/gcd;
        if(a==0)
        {
            mp[{0,1}]++;
            continue;
        }
        if(b==0)
        {
            mp[{1,0}]++;
            continue;
        }
        if(a<0 && b<0)
            a*=-1,b*=-1;
        if(a>0 && b<0)
            a*=-1,b*=-1;
        mp[{a,b}]++;
    }
    map<pair<int,int>,int>used;
    for(auto i:mp)
    {
        if(used.find(i.first)!=used.end())
            continue;
        used[i.first]=1;
        int a=abs(i.first.first);
        int b=abs(i.first.second);
        int sign=1;
        if(i.first.first<0)
            sign=-1;
        if(i.first.first==0 || i.first.second==0)
            sign=-1;
        if(mp.find({-1*sign*b,a})!=mp.end())
        {
            int val1=i.second;
            int val2=mp[{-1*sign*b,a}];
            used[{-1*sign*b,a}]=1;
            ans=(ans*((twopow[val1]+twopow[val2]-1+mod)%mod))%mod;
        }
        else
            ans=(ans*twopow[i.second])%mod;
    }
    cout<<(ans-1+restans+5*mod)%mod<<endl;
}

Measured memory_bytes: 33244
#include <algorithm>
#include <cstring>
#include <cstdio>
using ll = long long;
int lst[3005], to[20005], pre[20005], cap[20005], cost[20005], que[2000005], tot;
ll dis[3005];
bool in[3005], vis[3005];
inline void add_edge(int u, int v, int _cap, int _cost)
{
	auto _add = [&] (int x, int y, int ca, int co)
	{
		to[tot] = y;
		pre[tot] = lst[x];
		cap[tot] = ca;
		cost[tot] = co;
		lst[x] = tot++;
	};
	_add(u, v, _cap, _cost);
	_add(v, u, 0, -_cost);
}
int dfs(int u, int t, int rem)
{
	if (u == t)
		return rem;
	vis[u] = true;
	int ans = 0;
	for (int i = lst[u]; ~i; i = pre[i])
	{
		if (vis[to[i]] || !cap[i] || dis[to[i]] != dis[u] + cost[i])
			continue;
		int v = to[i], res = dfs(v, t, std::min(rem - ans, cap[i]));
		cap[i] -= res;
		cap[i ^ 1] += res;
		ans += res;
		if (ans == rem)
			return ans;
	}
	return ans;
}
inline ll min_cost_max_flow(int s, int t)
{
	ll res = 0;
	while (true)
	{
		memset(dis, 0x3f, sizeof(dis));
		memset(in, false, sizeof(in));
		int he = 0, ta = 0;
		que[ta++] = s;
		dis[s] = 0;
		in[s] = true;
		auto update = [&] ()
		{
			if (he < ta && dis[que[he]] > dis[que[ta - 1]])
				std::swap(que[he], que[ta - 1]);
		};
		while (he < ta)
		{
			int u = que[he++];
			in[u] = false;
			update();
			for (int i = lst[u]; ~i; i = pre[i])
			{
				if (cap[i] && dis[to[i]] > dis[u] + cost[i])
				{
					dis[to[i]] = dis[u] + cost[i];
					if (!in[to[i]])
					{
						in[to[i]] = true;
						que[ta++] = to[i];
						update();
					}
				}
			}
		}
		if (dis[t] >= 1e9)
			break;
		while (true)
		{
			for (int i = 0; i < ta; i++)
				vis[que[i]] = false;
			int mn = dfs(s, t, 1e9);
			if (!mn)
				break;
			res += (ll)mn * dis[t];
		}
	}
	return res;
}
int main()
{
	// freopen("AGC034-D.in", "r", stdin);
	memset(lst, -1, sizeof(lst));
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x, y, k;
		scanf("%d%d%d", &x, &y, &k);
		add_edge(0, i + 1, k, 0);
		add_edge(i + 1, 2 * n + 1, k,  x + y);
		add_edge(i + 1, 2 * n + 2, k, -x + y);
		add_edge(i + 1, 2 * n + 3, k,  x - y);
		add_edge(i + 1, 2 * n + 4, k, -x - y);
	}
	for (int i = 0; i < n; i++)
	{
		int x, y, k;
		scanf("%d%d%d", &x, &y, &k);
		add_edge(n + i + 1, 2 * n + 5, k, 0);
		add_edge(2 * n + 1, n + i + 1, k, -x - y);
		add_edge(2 * n + 2, n + i + 1, k,  x - y);
		add_edge(2 * n + 3, n + i + 1, k, -x + y);
		add_edge(2 * n + 4, n + i + 1, k,  x + y);
	}
	printf("%lld\n", -min_cost_max_flow(0, 2 * n + 5));
	return 0;
}


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

int main(){
	string s;
	while( cin >> s ){
		int a=0,b=0;
		for(int i=2 ; i < s.size() ; i++ ){
			if( s[i-2] == 'J' && s[i-1] == 'O' && s[i] == 'I' ) a++;
			if( s[i-2] == 'I' && s[i-1] == 'O' && s[i] == 'I' ) b++;
		}
		cout << a << endl << b << endl;
	}
}

Measured memory_bytes: 0
from sys import exit, stdin
N = int(stdin.readline().rstrip())
F = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
P = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

ans = -2000000000
 
for bit in range(1, 1<<10):
    cc = 0
    for i in range(N):
        c = 0
        for j in range(10):
            if bit >> j & 1 and F[i][j]:
                c += 1
        cc += P[i][c]
    if ans < cc:
        ans = cc
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>

#define MAX_PROCESSES 100000

typedef struct {
  char name[16];
  int time;
} Process;

Process *queue[MAX_PROCESSES];
int p = 0, q = 0;

void push(Process *proc) {
  queue[p++] = proc;
  if (p >= MAX_PROCESSES) p = 0;
}

Process *unshift() {
  Process *proc = queue[q++];
  if (q >= MAX_PROCESSES) q = 0;
  return proc;
}

int main(int argc, char *argv[]) {
  int n, qu;
  int time = 0;
  scanf("%d %d", &n, &qu);
  for (int i = 0; i < n; i++) {
    Process *proc = malloc(sizeof(Process));
    scanf("%s %d", proc->name, &proc->time);
    push(proc);
  }
  while (p != q) {
    Process *proc = unshift();
    if (proc->time <= qu) {
      time += proc->time;
      printf("%s %d\n", proc->name, time);
      free(proc);
      continue;
    }
    proc->time -= qu;
    time += qu;
    push(proc);
  }
}

Measured memory_bytes: 4084
import itertools

N, M, Q = map(int, input().split())
qs = [list(map(int, input().split())) for _ in range(Q)]

ans = 0
for A in itertools.combinations_with_replacement(range(1, M + 1), N):
    ans = max(sum([d for (a, b, c, d) in qs if A[b - 1] - A[a - 1] == c]), ans)

print(ans)


Measured memory_bytes: 9040
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define RG register
using namespace std;
const int N=1e5+10;
int n,a[N],b[N],ans;
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
	return x*f;}
inline int abss(int x){return x>0 ? x : -x;}
int fnd(int x)
{
	int l=1, r=n;
	while(l<=r)
	{
		int mid=l+(r-l)/2;
		if(a[mid]==x) return mid;
		if(a[mid]<x) l=mid+1;
		else r=mid-1;
	}
}
int main()
{
	//freopen("BBuBBBlesort.in","r",stdin);
	n=read();
	for(RG int i=1;i<=n;i++) a[i]=b[i]=read();
	sort(a+1,a+1+n);
	for(RG int i=1;i<=n;i++)
	{
		int pos=fnd(b[i]);
		ans+=(abss(pos-i)&1);
	}
	printf("%d\n",ans>>1);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	string s;
  	cin >> s;
  	string ans;
  	for(int i = 0; i < s.size(); i++) {
    	ans += 'x';
    }
  	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b; cin >> a >> b;
    if(a%2 ==0 or b%2 == 0)cout << "No" << endl;
    else cout << "Yes"<< endl;
}




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

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

using namespace std;

int main(){
	int n,m,x; cin>>n>>m>>x;
	int l=0,r=0;
	rep(i,m){
		int a; cin>>a;
		if(a<x) l++; else r++;
	}
	cout<<min(l,r)<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int n;
    static long k;
    static long[] dp;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextLong();
        dp = new long[100000+1];

        for (int i = 0; i < n; i++) {
            dp[sc.nextInt()] += sc.nextLong();
        }
        int ans = 0;
        for (int i = 0; i < dp.length; i++) {
            if (k - dp[i] <= 0) {
                ans = i;
                break;
            } else {
                k -= dp[i];
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 77344
mod=1000000007

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

ans=1
c1=c2=c3=0
for Ai in A:
    if c1==c2==c3==Ai:
        c1+=1
        ans=ans*3%mod
    elif c1==c2==Ai:
        c1+=1
        ans=ans*2%mod
    elif c2==c3==Ai:
        c2+=1
        ans=ans*2%mod
    elif c1==Ai:
        c1+=1
    elif c2==Ai:
        c2+=1
    elif c3==Ai:
        c3+=1
    else:
        ans=0
        break

print(ans)

Measured memory_bytes: 52916
//構成の方針まではすぐだけど、正確に詰めるのは難しい。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int n;
string s;
int fc[200002];	//fc[i] = sの前からi文字を取り除いたとき、(abc…z)のアナグラムをn個連結した文字列を見つけられたとする。nの最大値をfc[i]とおく。ただし、fc[|s|+1] = -1とおく。
vector<int> posList[26];

void calcFc() {
	bool used[26] = {false}; int uCnt = 0, findCnt = 0;
	int i, j;
	
	fc[n + 1] = -1;
	for (i = n - 1; i >= 0; i--) {
		if (!used[s[i] - 'a']) {
			used[s[i] - 'a'] = true;
			uCnt++;
		}
		if (uCnt == 26) {
			findCnt++;
			uCnt = 0;
			for (j = 0; j < 26; j++) used[j] = false;
		}
		fc[i] = findCnt;
	}
}

int main() {
	int i, j;
	
	cin >> s; n = s.length();
	calcFc();
	
	for (i = 0; i < n; i++) {
		posList[s[i] - 'a'].push_back(i);
	}
	for (i = 0; i < 26; i++) {
		posList[i].push_back(n);
	}
	
	string ans;
	int lastPos = -1;
	for (i = 0; i < fc[0] + 1; i++) {
		for (j = 0; j < 26; j++) {
			int id = upper_bound(posList[j].begin(), posList[j].end(), lastPos) - posList[j].begin();
			int pos = posList[j][id];
			if (fc[pos + 1] == fc[0] - i - 1) {
				//文字'a' + jを答えに追加する
				ans += (char)('a' + j);
				lastPos = pos;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	for (int i = 0; i < n; i++)cin >> s.at(i);
	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++)cout << s.at(i);
	cout << endl;
}

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

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007
const int N = 2e5 + 5;
vector<int> adj[N];
int vis[N];
void dfs(int node){
    vis[node] = 1;
    for(auto child : adj[node]){
        if(!vis[child]){
            dfs(child);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n , m;
    cin>>n>>m;
    ll cnt = 0;
    for(int i = 0; i < m; i++){
        ll u , v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            dfs(i);
            ans++;
        }
    }
    cout<<ans - 1<<"\n";
    return 0;
}

Measured memory_bytes: 12332
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	boolean[] sieve;
	Scanner sc;
	
	int ni(){
		return sc.nextInt();
	}
	
	void makeSieve(int max){
		sieve=new boolean[max+1];
		Arrays.fill(sieve,true);
		sieve[0]=false;
		for(int i=2;i<=max;++i){
			if(sieve[i-1]){
				for(int j=i*2;j<=max;j+=i){
					sieve[j-1]=false;
				}
			}
		}
	}
	
	void solve(int n){
		for(int i=n;i>4;--i){
			if(sieve[i-1]&&sieve[i-3]){
				System.out.println((i-2)+" "+i);
				break;
			}
		}
	}
	
	void io(){
		sc=new Scanner(System.in);
		int n;
		makeSieve(10000);
		while((n=ni())!=0){
			solve(n);
		}
		sc.close();
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().io();
	}

}

Measured memory_bytes: 31916
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	static long long a,b[3]={0};
	cin>>a;
	for (int A=0;A<a;A++){
		cin>>b[0]>>b[1]>>b[2];
		sort(b,b+3);
		b[0]*=b[0];
		b[1]*=b[1];
		b[2]*=b[2];
		if (b[2]!=b[0]+b[1]) cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}
	return 0;
}
		
		

Measured memory_bytes: 3000
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    int n; cin >> n;
    ll a[n], b[n];
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }

    ll sum_a = accumulate(a, a+n, 0LL);
    ll sum_b = accumulate(b, b+n, 0LL);

    if(sum_a > sum_b){
        cout << "No" << endl;
        return 0;
    }

    ll dif[n];
    rep(i, n){
        dif[i] = a[i] - b[i];
    }

    ll pos = 0, neg = 0;
    rep(i, n){
        if(dif[i] > 0){
            pos += dif[i];
        }
        else{
            neg += (-dif[i]/2);
        }
    }

    if(neg >= pos){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long  a[200000+5];
long long b[200000+5];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<=n;i++)
	cin>>b[i];
	for(int i=0;i<n;i++)
	cin>>a[i];
long long sum=0;
	for(int i=0;i<n;i++){
		if(b[i]<a[i]){
			if((b[i]+b[i+1])>a[i]){
				sum=sum+a[i];
				b[i+1]=b[i+1]-(a[i]-b[i]);
			}
			else{
				sum=sum+b[i]+b[i+1];
				b[i+1]=0;
			}
		}
		else{
			sum=sum+a[i];
		}
	}
	cout<<sum;
}


Measured memory_bytes: 1792
S = input()
T = input()
N = len(S)

start = {chr(i):-1 for i in range(97,97+26)}
goal = {chr(i):-1 for i in range(97,97+26)}
ans = 'Yes'
for i in range(N):
    s = S[i]
    t = T[i]
    if start[s] != -1 and start[s] != t:
        ans = 'No'
    if goal[t] != -1 and goal[t] != s:
        ans = 'No'
    start[s] = t
    goal[t] = s

print(ans)


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

int n,q,k;
char s[1000010];
long long ans,d,m,cnt;
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d",&k);
		ans=0;
		d=0;
		cnt=0;
		m=0;
		for(int i=1;i<=n;++i)
		{
			if(s[i]=='D')
			++d;
			if(s[i]=='M')
			{
				++m;
				cnt+=d;
			}
			if(s[i]=='C')
			ans+=cnt;
			if(i>=k)
			{
				if(s[i-(k-1)]=='D')
				{
					--d;
					cnt-=m;
				}
				if(s[i-(k-1)]=='M')
				--m;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int tot = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        tot += a[i];
    }
    tot     = (tot + 4 * m - 1) / (4 * m);
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] >= tot)
            cnt++;
    }
    if (cnt >= m)
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";

    return 0;
}

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int kotae;
    kotae=min(n*a,b);
    cout << kotae << endl;
    
    return 0;
}











Measured memory_bytes: 256
N = input()
if int(N[-1]) == 2 or int(N[-1]) == 4 or int(N[-1]) == 5 or int(N[-1]) == 7 or int(N[-1]) == 9:
  print('hon')
elif int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8:
  print('pon')
elif int(N[-1]) == 3:
  print('bon')

Measured memory_bytes: 9148
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  	int N, K;
  	cin >> N >> K;
  	int ans = 0;
  	int h;
  	for(int i=0;i<N;i++){
  		cin >> h;
  		if(h>=K) ans++;
  	}

  	cout << ans <<endl;

    
  	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>


using namespace std;


int main()
{
	string t, input;
	int count = 0;

	cin >> t;

	for (int i = 0; i < t.size(); i++)
	{
		t[i] = tolower(t[i]);
	}

	while (true)
	{
		cin >> input;

		if (input == "END_OF_TEXT")
			break;
		
		for (int i = 0; i < input.size(); i++)
		{
			input[i] = tolower(input[i]);
		}

		

		if (input == t)
			count++;
	}

	cout << count << endl;
}

Measured memory_bytes: 3160