akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ABC143
{
    class C
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            string S = Console.ReadLine() + ".";

            int count = 0;
            char temp;
            for (int i = 0; i < S.Length - 1; i++)
            {
                temp = S[i];

                while (i < S.Length - 1 && temp == S[i + 1])
                {
                    i++;
                }
                count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13208
import java.io.*;

class Main{
    static int[] dp = new int[100010];
    public static void main(String[] args) throws IOException{
        dp[0] = 0;
        int aom;
        for (int i=1;i<=100_000;i++){
            aom = 1;
            dp[i] = Integer.MAX_VALUE;
            while (aom<=i){
                dp[i] = Math.min(dp[i],dp[i-aom]+1);
                aom *= 6;
            }
            aom = 1;
            while (aom<=i){
                dp[i] = Math.min(dp[i],dp[i-aom]+1);
                aom *= 9;
            }
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int N = Integer.parseInt(str);
        System.out.println(dp[N]);
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


ll dp[3100][6600][3];

int main() {
    ll n, s;
    cin >> n >> s;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];

    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    rep(i, 0, n) rep(j, 0, s+1) {
        // from 0
        (dp[i+1][j][0] += dp[i][j][0] ) %= MOD;
        (dp[i+1][j+a[i]][1] += dp[i][j][0] * (i+1)) %= MOD;
        (dp[i+1][j+a[i]][2] += dp[i][j][0] * (i+1) * (n-i)) %= MOD;

        // from 1
        (dp[i+1][j][1] += dp[i][j][1]) %= MOD;
        (dp[i+1][j+a[i]][1] += dp[i][j][1]) %= MOD;
        (dp[i+1][j+a[i]][2] += dp[i][j][1] * (n-i)) %= MOD;

        // from 2
        (dp[i+1][j][2] += dp[i][j][2]) %= MOD;
    }

    cout << dp[n][s][2] % MOD << endl;
}


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

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  
  for (int i = 0; i < a + b + 1; i++) {
    if (i == a) {
      if (s.at(i) != '-') {
        cout << "No" << endl;
        break;
      }
    }
    else if (i != a + b) {
      if (s.at(i) == '-') {
        cout << "No" << endl;
        break;
      }
    }
    else {
      if (s.at(i) != '-') {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define in insert
#define ff first
#define ss second
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
int main()
{
    int k;
       cin>>k;
       if(k%2==0)
       {
           cout<<(k*k)/4;
       }
       else

       {

           cout<<(k/2)*(k/2+1);
       }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int a,b; cin >>a >>b;
  cout <<(a <= b ? "unsafe": "safe") <<endl;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			int m=in.nextInt();
			int max=0;
			for(int i=0;i<n;i++)
			{
				 m+=in.nextInt()-in.nextInt();
				 if(m<0)
					 break;
				 max=Math.max(max, m);
			}
			System.out.println(m<0 ? 0:max);
			break;
		}
	}
	
	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 42120
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

#define DEBUG(x) cerr << #x << ": " << x << endl

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

vector<llong> lunlun;
void go(llong x) {
   if (x >= 10000000000LL)
      return;
   lunlun.push_back(x);
   int d = x % 10;
   if (d-1 >= 0)
      go(x*10 + (d-1));
   go(x*10+d);
   if (d+1 <= 9)
      go(x*10 + (d+1));
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   FOR(start,1,9)
      go(start);

   sort(lunlun.begin(), lunlun.end());

/*
   cerr << lunlun.size() << endl;
   for (llong x : lunlun)
      cerr << x << endl;
*/

   int K;
   cin >> K;

   cout << lunlun[K-1] << endl;

   return 0;
}


Measured memory_bytes: 2420
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		Obj[] arr = new Obj[n];
		for (int i = 0; i < n; i++) {
			Obj o = new Obj();
			o.i = i;
			arr[i] = o;
		}
		for (int i = 1; i < n; i++) {
			int a = Integer.parseInt(br.readLine()) - 1;
			arr[a].list.add(arr[i]);
		}
		br.close();

		dfs(arr, arr[0]);
		System.out.println(arr[0].d);
	}

	static void dfs(Obj[] arr, Obj cur) {
		List<Obj> list = cur.list;
		if (!list.isEmpty()) {
			for (Obj next : list) {
				dfs(arr, next);
			}
			Collections.sort(list);
			int d = 0;
			for (int i = 0; i < list.size(); i++) {
				d = Math.max(d, list.get(i).d);
				d++;
			}
			cur.d = d;
		}
	}

	static class Obj implements Comparable<Obj> {
		int i, d;
		List<Obj> list = new ArrayList<>();

		@Override
		public int compareTo(Obj o) {
			return d - o.d;
		}
	}
}


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

using namespace std;
using Graph = vector<vector<int>>;
int main(){
    int n;cin >> n;
    Graph g(n);
    vector<pair<int,int>> vp;

 for (int i = 0; i < n-1; ++i)
 {
    int a,b;cin >> a >> b;a--;b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
    vp.emplace_back(a,b);
 }
int k=0;
map<pair<int,int>,int> I;
vector<int> cs(n,0);
vector<int> used(n,0);
queue<int> que;
used[0] = 1;
que.emplace(0);
while(!que.empty()){
    int v = que.front();que.pop();
    if (k < g[v].size()) k = g[v].size();

    int cur=1;
    for (int u : g[v])
    {
        if(used[u]) continue;
        if (cur==cs[v]) cur++;
        cs[u] = I[make_pair(u,v)] = I[make_pair(v,u)] = cur++;
        used[u] = 1;
        que.emplace(u);
    } 
}
    
cout << k << "\n";
for(auto p:vp) cout << I[p]<<"\n";
return 0;
}



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

int main() {
    string s , t ;
    cin >> s >> t;
	
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
   
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

ll getrndll(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2>
inline bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
inline bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 2e5 + 3;

int c[N], sz[N], path[N], dp[N], s[N], cnt[N];
ll res[N];
stack<int> lst[N];
vector<int> graph[N];

void dfs(int v, int p, int d = 0) {
    path[d] = v;
    lst[c[v]].push(d);
    sz[v] = 1;
    for (int to : graph[v]) {
        if (to == p) continue;
        dfs(to, v, d + 1);
        
        sz[v] += sz[to];
        
        ll temp = sz[to] - dp[to];
        res[c[v]] -= (temp + 1) * temp / 2;
        s[c[v]] += temp;
    }
    lst[c[v]].pop();
    
    if (!lst[c[v]].empty()) {
        int u = path[lst[c[v]].top() + 1];
        dp[u] += sz[v];
    }
}

void solve() {
    int n;
    cin >> n;
    
    for (int i = 0; i < n; ++i)
        cin >> c[i], ++cnt[--c[i]];
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        
        --x; --y;
        graph[x].emplace_back(y);
        graph[y].emplace_back(x);
    }
    
    fill(res, res + N, 1LL * (n + 1) * n / 2);
    dfs(0, 0);
    
    for (int i = 0; i < n; ++i) {
        ll temp = n - (s[i] + cnt[i]);
        res[i] -= (temp + 1) * temp / 2;
    }
    for (int i = 0; i < n; ++i)
        cout << res[i] << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}



Measured memory_bytes: 173900
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	string s;
	cin >> s;
	if(s.substr(0,4) == "YAKI")P("Yes");
	else P("No");
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
int main(){
	int e[10];
	int a,b,c,d;
	memset(e,0,sizeof(e));
	cin>>a>>b>>c>>d;
	e[a]++;
	e[b]++;
	e[c]++;
	e[d]++;
	if(e[1]>0 && e[4]>0 && e[7]>0 && e[9]>0){
		printf("YES\n");
	}
	else cout<<"NO\n";
    return 0;
}

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

bool is_rev(string &s1, string &s2) {
    assert(s1.size() == s2.size());
    for (int i = 0, j = s2.size()-1; j >= 0; i++, j--)
        if (s1[i] != s2[j]) return false;
    return true;
}

bool check1(int H, int W, string *s, vector<int> &row_indices) {
    vector<string> cols(W, string(H, 0));
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            cols[j][i] = s[row_indices[i]][j];
    vector<bool> used(W, false);
    bool middle_used = false;
    for (int j = 0; j < W; j++) {
        if (used[j]) continue;
        for (int k = j+1; k < W; k++) {
            if (used[k]) continue;
            if (is_rev(cols[j], cols[k])) {
                used[j] = used[k] = true;
                break;
            }
        }
        if (!used[j]) {
            if (W % 2 == 0 || !is_rev(cols[j], cols[j]) || middle_used)
                return false;
            else
                middle_used = true;
        }
    }
    return true;
}

bool check(int H, int W, string *s, int a, int b) {
    vector<int> rows;
    for (int i = 0; i < H; i++)
        if ((a >> i) & 1) rows.push_back(i);
    for (int i = 0; i < H; i++)
        if ((b >> i) & 1) rows.push_back(i);
    auto l = rows.begin() + __builtin_popcount(a), r = rows.end();
    do {
        if (check1(H, W, s, rows)) return true;
    } while (next_permutation(l, r));
    return false;
}


int main() {
    int H, W; cin >> H >> W;
    string s[H]; for (int i = 0; i < H; i++) cin >> s[i];
    int ALL = (1 << H) - 1;
    for (int a = 0; a <= ALL; a++) {
        if (__builtin_popcount(a) == H/2)
            if (check(H, W, s, a, ALL^a)) { cout << "YES\n"; return 0; }
    }
    cout << "NO\n";
}


Measured memory_bytes: 3168
def digital_gifts(n, xuli):

    ans = 0

    for i in xuli:
        if i[1] == "JPY":
            ans += float(i[0])
        else:
            ans += float(i[0])*380000

    return ans

def main():
    n = int(input())
    xuli = [list(map(str, input().split())) for i in range(n)]
    print(digital_gifts(n, xuli))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

 int mod[6]={1,10,9,12,3,4};
  int dp[100000][13];
signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  if(s[s.size() -1]!='?'){
    dp[0][s[s.size() -1]-48]++;
  }
  else{
    rep(j,10){
      dp[0][j]++;
    }
  }
  repi(i,1,s.size()){
    if(s[s.size() -1-i]!='?'){
      //cout<<mod[i%6]<<" "<<s.size()-1-i<<endl;
      //cout<<s[i]-48<<endl;
      rep(j,13){
	dp[i][(j+(s[s.size() -1-i]-48)*mod[i%6])%13]+=dp[i-1][j];
	dp[i][(j+(s[s.size() -1-i]-48)*mod[i%6])%13]%=MOD;
      }
    }
    else{
      rep(k,10){
	rep(j,13){
	  dp[i][(j+(mod[i%6]*k))%13]+=dp[i-1][j];
	  dp[i][(j+(mod[i%6]*k))%13]%=MOD;
	}
      }
    }
  }
  
  cout<<dp[s.size()-1][5]<<endl;
  return 0;
}


Measured memory_bytes: 10604
package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
)

type IOTp struct {
	iBuffer []byte
	iPos int
}
func (this *IOTp) GetChar() byte {
	res:=this.iBuffer[this.iPos]
	this.iPos++
	return res
}
func (this *IOTp) ReadInt() int {
	res:=0
	k:=1
	for ch:=this.iBuffer[this.iPos]; !(ch>='0' && ch<='9'); ch=this.iBuffer[this.iPos]{
		if ch=='-' {
			k=-1
		}
		this.iPos++
	}
	for ch:=this.iBuffer[this.iPos]; ch>='0' && ch<='9'; ch=this.iBuffer[this.iPos]{
		res=res*10+int(ch-'0')
		this.iPos++
	}
	res*=k
	return res
}
func NewIOTp() *IOTp {
	now:=new(IOTp)
	//inputFile,_:=os.Open("in.txt")
	inputFile:=os.Stdin
	now.iBuffer,_=ioutil.ReadAll(inputFile)
	now.iBuffer=append(now.iBuffer, '\n')
	now.iPos=0
	return now
}
var cin *bufio.Reader
var cout *bufio.Writer
var p [MAXN+10]Point
type PointComp []Point
func (s PointComp) Len() int {return len(s)}
func (s PointComp) Swap(i,j int) {s[i],s[j]=s[j],s[i]}
func (s PointComp) Less(i,j int) bool {return s[i].x<s[j].x}
type Comp []int
func (s Comp) Len()int{ return len(s) }
func (s Comp) Swap(i,j int) {s[i],s[j]=s[j],s[i]}
func (s Comp) Less(i,j int) bool {return p[s[i]].v<p[s[j]].v}
type Point struct {
	x,v int
}
const MAXN=200000
const kcz=1000000007
func min(x,y int) int {
	if x<y {
		return x
	}
	return y
}
func max(x,y int) int {
	if x>y {
		return x
	}
	return y
}
func main() {
	IO:=NewIOTp()
	cout=bufio.NewWriter(os.Stdout)
	n:=IO.ReadInt()
	for i:=1; i<=n; i++ {
		p[i].x=IO.ReadInt()
		p[i].v=IO.ReadInt()
	}
	sort.Sort(PointComp(p[1:n+1]))
	var id [MAXN+10]int
	for i:=1; i<=n; i++ {
		id[i] = i
	}
	sort.Sort(Comp(id[1:n+1]))
	var l,r,f,sum [MAXN+10]int
	for i:=1; i<=n; i++ {
		l[id[i]],r[id[i]]=i,i
	}
	for i:=2; i<=n; i++ {
		r[i]=max(r[i],r[i-1])
	}
	for i:=n-1; i>=1; i-- {
		l[i]=min(l[i],l[i+1])
	}
	f[0],sum[0]=1,1
	for i,j:=1,1; i<=n; i++ {
		sum[i]=sum[i-1]
		for ;j<=n && r[j]==i; j++ {
			x:=sum[i]
			if l[j]>1 {
				x=x-sum[l[j]-2]+kcz
				x%=kcz
			}
			f[i]=(f[i]+x)%kcz
			sum[i]=(sum[i]+x)%kcz
		}
	}
	fmt.Fprint(cout,f[n])
	cout.Flush()
}


Measured memory_bytes: 18944
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		String s = sc.next();
		int[] r = new int[n];
		int[] g = new int[n];
		int[] b = new int[n];
		if (s.charAt(n - 1) == 'R') {
			r[n - 1] = 1;
		} else if (s.charAt(n - 1) == 'G') {
			g[n - 1] = 1;
		} else {
			b[n - 1] = 1;
		}
		for (int i = n - 2; i >= 0; i--) {
			r[i] = r[i + 1];
			g[i] = g[i + 1];
			b[i] = b[i + 1];
			switch (s.charAt(i)) {
				case 'R':
					r[i]++;
					break;
				case 'G':
					g[i]++;
					break;
				case 'B':
					b[i]++;
					break;
			}
		}
		long ans = 0;
		for (int i = 0; i < n - 2; i++) {
			for (int j = i + 1; j < n - 1; j++) {
				if (s.charAt(i) == s.charAt(j)) {
					continue;
				}
				int minus = 0;
				if (j + (j - i) < n) {
					if (s.charAt(i) != s.charAt(j + (j - i)) && s.charAt(j) != s.charAt(j + (j - i))) {
						minus = -1;
					}
				}
				if ('R' != s.charAt(i) && 'R' != s.charAt(j)) {
					ans += r[j + 1] + minus;
				} else if ('G' != s.charAt(i) && 'G' != s.charAt(j)) {
					ans += g[j + 1] + minus;
				} else {
					ans += b[j + 1] + minus;
				}
			}
		}
		System.out.println(ans);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 33840
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n;string s;
    cin>>n>>s;
    int ans = 0;
    for(int bar = 1; bar<n; ++bar){
        map<char,bool> p;
        rep(i,bar){
            p[s[i]] = false;
        }
        int tmp = 0;
        for(int i = bar; i<n; ++i){
            if(p.count(s[i]))if(p[s[i]] == false){
                tmp ++;p[s[i]] = true;
            }
        }
        ans = max(ans,tmp);
    }
    cout<<ans<<endl; return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces

def make_tree_0index(N):
    edge_dic = {}
    for _ in range(N-1):
        x, y = na()
        x -= 1
        y -= 1
        if x in edge_dic:
            edge_dic[x].append(y)
        else:
            edge_dic[x] = [y]
        if y in edge_dic:
            edge_dic[y].append(x)
        else:
            edge_dic[y] = [x]
    return edge_dic


N = ni()

edge_dic = make_tree_0index(N)

parent_array = [-2] * N
depth_array = [-1] * N

node = deque([0])
parent_array[0] = -1
depth_array[0] = 0

while(len(node)):
    n = node.popleft()
    for nn in edge_dic[n]:
        if nn == parent_array[n]:
            continue
        parent_array[nn] = n
        depth_array[nn] = depth_array[n] + 1
        node.append(nn)

# print(parent_array,depth_array)

now_depth = depth_array[-1]
max_node = N - 1
for i in range((now_depth-1)//2):
    max_node = parent_array[max_node]

cnt = 1
node.append(max_node)
while(len(node)):
    n = node.popleft()
    for nn in edge_dic[n]:
        if nn == parent_array[n]:
            continue
        node.append(nn)
        cnt += 1

# print(cnt)

if cnt * 2 >= N:
    print("Snuke")
else:
    print("Fennec")

Measured memory_bytes: 96044
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

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

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
#define int long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}
#define N 105
int a[N];
int sol(int x,int n)
{
	if(x==n) return 0;
	int ans=0;
	for(int i=x+1;i<n;i++) ans+=9*(n-i)*9;
	ans+=(a[x]-1)*9*(n-x);
	int cur=x+1;
	while(cur<=n&&a[cur]==0) cur++;
	if(cur!=n+1)
	{
		ans+=(n-cur)*9;
		ans+=a[cur];
	}
	return ans;
}
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	string s;
	cin>>s;
	int n=s.length();
	for(int i=1;i<=n;i++) a[i]=s[i-1]-'0';
	int k=read();
	if(k==1)
	{
		int ans=9*(n-1);
		ans+=a[1];
		cout<<ans<<endl;
	}
	if(k==2)
	{
		int ans=0;
		if(n==1)
		{
			cout<<"0\n";
			return 0;
		}
		for(int i=2;i<n;i++) ans+=9*(i-1)*9;
		ans+=(a[1]-1)*9*(n-1);
		int cur=2;
		while(cur<=n&&a[cur]==0) cur++;
		if(cur!=n+1)
		{
			ans+=(n-cur)*9;
			ans+=a[cur];
		}
		cout<<ans<<endl;
	}
	if(k==3)
	{
		if(n<=2)
		{
			cout<<"0\n";
			return 0;
		}
		int ans=0;
		for(int i=3;i<n;i++) ans+=9*9*9*(i-1)*(i-2)/2;
		ans+=(a[1]-1)*9*9*(n-1)*(n-2)/2;
		int cur=2;
		while(cur<=n&&a[cur]==0) cur++;
		{
			ans+=sol(cur,n);
		}
		cout<<ans<<endl;
	}
#ifdef __LOCAL__
	cout<<"Time Used : "<<clock()<<endl;
#endif
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
    return 0;
};


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const ll MAX = 1e15 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


#define int ll

typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int m, k;
main() {
    file("rmq");
    ios;
    cin >> m >> k;
    if ((1 << m) - 1 < k) return !(cout << -1);
    if (k == 0) {
        for (int mask = 0; mask < (1 << m); ++mask) {
            cout << mask << " " << mask << " ";
        }
        return 0;
    }
    vector <int> v;
    int x = 0;
    for (int mask = 0; mask < (1 << m); ++mask) {
        v.eb(mask);
        if (mask != k) x ^= mask;
    }
    if (x != k) return !(cout << -1);
    for (int it : v) if (it != k) cout << it << " ";
    cout << k << " ";
    reverse(all(v));
    for (int it : v) if (it != k) cout << it << " ";
    cout << k;
    return 0;
}
/**

*/


Measured memory_bytes: 2932
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;

struct edge{int to,cost;};

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

	int n;
	cin >> n;

	int s[n],sm[n],sum=0,non0min=101;
	bool non0=false;
	for(int i=0;i<n;i++){
		cin >> s[i];
		sum += s[i];
		sm[i] = s[i]%10;
		if(sm[i] != 0) {
			non0=true;
			non0min = min(non0min,s[i]);
		}
	}
	if(non0){
		cout << (sum%10 == 0?sum-non0min:sum) << "\n";
	}
	else cout << "0\n";

	return 0;
}

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

int g(int a,int b){
    if(b==0){
        return a;
    }else{
        return g(b,a%b);
    }
}

int main() {
int n,k,m,l;
cin>>n>>k>>m;
l=m;
for(int i=1;i<n;i++){
    int a;
    cin>>a;
    m=g(m,a);
    l=max(l,a);
}
if(k<=l&&k%m==0){
    cout<<"POSSIBLE"<<endl;
}else{
    cout<<"IMPOSSIBLE"<<endl;
}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
bool sortDescByFirst(const pair<int,int>&a, const pair<int,int>&b){
    return a.first>=b.first;
}
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c;
    while(cin>>a>>b>>c){
        (a+b>=c && !(a>c))?cout<<"YES"<<endl:cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
// C++ program to find count of divisors in n!
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;


// allPrimes[] stores all prime numbers less
// than or equal to n.
vector<ull> allPrimes;

// Fills above vector allPrimes[] for a given n
void sieve(int n)
{
    // Create a boolean array "prime[0..n]" and
    // initialize all entries it as true. A value
    // in prime[i] will finally be false if i is
    // not a prime, else true.
    vector<bool> prime(n+1, true);

    // Loop to update prime[]
    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it
        // is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Store primes in the vector allPrimes
    for (int p=2; p<=n; p++)
        if (prime[p])
            allPrimes.push_back(p);
}

// Function to find all result of factorial number
ull factorialDivisors(ull n)
{
    sieve(n);  // create sieve

    // Initialize result
    ull result = 1;

    // find exponents of all primes which divides n
    // and less than n
    for (int i=0; i < allPrimes.size(); i++)
    {
        // Current divisor
        ull p = allPrimes[i];

        // Find the highest power (stored in exp)'
        // of allPrimes[i] that divides n using
        // Legendre's formula.
        ull exp = 0;
        while (p <= n)
        {
            exp = exp + (n/p);
            p=((p%1000000007)*(allPrimes[i]%1000000007))%1000000007;
        }

        // Multiply exponents of all primes less
        // than n
        result=((result)%1000000007*(((exp%1000000007)+1%1000000007)%1000000007)%1000000007)%1000000007;
    }

    // return total divisors
    return result%1000000007;
}

// Driver program to run the cases
int main()
{  ull n;
    scanf("%llu",&n);
    printf("%llu",factorialDivisors(n));
    return 0;
}


Measured memory_bytes: 256
S = list(input())
S_re = S[::-1]
#print(S_re)
ans = "Yes"
for i in range(len(S)):
    if S[i]!=S_re[i]:
        ans = "No"
        break
S_re1 = S[0:(len(S)-1)//2][::-1]
S_re2 = S[len(S)//2+1:len(S)][::-1]
#print(S_re1, S_re2)
for i in range(len(S_re1)):
    if S[i]!=S_re1[i]:
        ans = "No"
        break
for i in range(len(S)//2+1, len(S_re2)):
    if S[i]!=S_re2[i]:
        ans = "No"
        break
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int N,maxi,mid,sa=1e9;

int main(){
    cin>>N;
    int A[N];
    rep(i,N){
        cin>>A[i];
    }
    sort(A,A+N);
    maxi=A[N-1];
    rep(i,N){
        if(abs(maxi/2-A[i])<sa){
            mid=A[i];
            sa=abs(maxi/2-A[i]);
        }
        else if(abs(maxi/2+1-A[i])<sa){
            mid=A[i];
            sa=abs(maxi/2+1-A[i]);
        }
    }
    if(mid==100){
        printf("%d %d\n",maxi,0);
        return 0;
    }
    printf("%d %d\n",maxi,mid);
    
}


Measured memory_bytes: 640
a,b,c = list(map(int,input().split()))
k = int(input())
while b <= a and k > 0:
    b*=2
    k-=1
while c <= b and k > 0:
    c*=2
    k-=1
if c > b and b > a:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61616
H, W = gets.split.map(&:to_i)
S = H.times.map { gets.chomp.chars }
H.times do |h|
  W.times do |w|
    if S[h][w] != "#"
      S[h][w] = S[[0, h - 1].max..h + 1].flat_map { |t| t[[0, w - 1].max..w + 1] }.count("#")
    end
  end
end
puts S.map(&:join)


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

class Main
{
  public static void main(String[] args) 
  {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int t = sc.nextInt();
    int sandRemain = X - t;
    if (sandRemain < 0)
    {
      sandRemain = 0;
    }
    System.out.println(sandRemain);
  }
}


Measured memory_bytes: 35688
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var n = parseInt(input[0][0], 10);
    tmp1 = 1;
    tmp2 = 1; 
    ans = 1;
    for (var i = 2; i <= n; i++){
        ans = tmp1 + tmp2;
        tmp1 = tmp2;
        tmp2 = ans;
    }
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 


Measured memory_bytes: 15404
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define M 20
#define N 100
#define INF 100000000
#define MIN(A,B) \
  ( (B) < (A) ? (B) : (A) )
#define MAX(A,B) \
  ( (B) > (A) ? (B) : (A) )

static int k_operafan[ M + 1 ][ N ];

static int d[ N ];

static int
dpFSA (
  int m,
  int n
  )
{
  int i;

  if ( n < 0 )  return ( 0 );
  if ( m == 0 ) return ( INF );

  if ( ~k_operafan[ m ][ n ] ) ;
  else
  {
    int width = 0;

    k_operafan[ m ][ n ] = INF;
    for ( i = n; i >= 0; --i )
    {
      width += d[ i ];
      k_operafan[ m ][ n ] = MIN( k_operafan[ m ][ n ]
                                , MAX( width, dpFSA ( m - 1, i - 1 ) ) );
    }
  }

  return ( k_operafan[ m ][ n ] );
}

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int m, n;

    scanf ( "%d%d", &m, &n );
    if ( m == 0 && n == 0 )
      break ;

    for ( i = 0; i < n; ++i )
      scanf ( "%d", &d[ i ] );

    memset ( k_operafan, -1, sizeof ( k_operafan ) );
    printf ( "%d\n", dpFSA ( m, n - 1 ) );
  }

  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 616
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
	int n;
		while(cin>>n)
		{
		int d=n/2;
		if(d*2==n){
			cout<<d-1<<endl;
		}
		else{
			cout<<d<<endl;
		}		
	}

	return 0;
}

Measured memory_bytes: 256
//by xiqiao
#include<bits/stdc++.h>
#define maxn 200005
#define MOD 1000000007
using namespace std;
typedef long long ll;
int n,X,Y;
int fac[maxn],inv[maxn];
vector <pair<int,int> > r[maxn];
vector <pair<int,int> > p;
vector <int> v[maxn],tmp;
void add(int x,int y){
	v[x].push_back(y);v[y].push_back(x);
}
int cnt,vis[maxn],c[maxn],ge[maxn],zh[maxn];
void dfs(int x){
	cnt++;vis[x]=1;ge[c[x]]++;tmp.push_back(c[x]);
	for(int i=0;i<(int)v[x].size();i++){
		if(!vis[v[x][i]]){
			dfs(v[x][i]);
		}
	}
}
int cal(int x,int y){
	return 1ll*fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
void jia(int x){
	for(int i=1;i<=n;i++){
		if(c[i]==c[x])continue;
		if(zh[i]+zh[x]<=Y)add(i,x);
	}
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d%d",&n,&X,&Y);
	inv[0]=1;fac[0]=1;inv[1]=1;fac[1]=1;
	for(int i=2;i<=n;i++){
		fac[i]=1ll*fac[i-1]*i%MOD;
		inv[i]=1ll*(MOD-MOD/i)*inv[MOD%i]%MOD;
	}
	for(int i=2;i<=n;i++){
		inv[i]=1ll*inv[i-1]*inv[i]%MOD;
	}
	for(int i=1;i<=n;i++){
		int C,w;scanf("%d%d",&C,&w);
		c[i]=C;zh[i]=w;
		r[C].push_back(make_pair(w,i));
	}
	for(int i=1;i<=n;i++){
		if(r[i].size()==0)continue;
		sort(r[i].begin(),r[i].end());
		p.push_back(r[i][0]);
		for(int j=1;j<(int)r[i].size();j++){
			if(r[i][j].first+r[i][0].first<=X){
				add(r[i][j].second,r[i][0].second);
			}
		}
	}
	sort(p.begin(),p.end());
	if(p.size())jia(p[0].second);
	if(p.size()>1)jia(p[1].second);
	int res=1;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			cnt=0;tmp.clear();
			dfs(i);
			for(int j=0;j<(int)tmp.size();j++){
				if(ge[tmp[j]]==0)continue;
				res=1ll*res*cal(cnt,ge[tmp[j]])%MOD;
				cnt-=ge[tmp[j]];
				ge[tmp[j]]=0;
			}
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 28568
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    println((math.pow(sc.nextInt, 2) - sc.nextInt).toInt)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}


Measured memory_bytes: 27456
N, M = map(int, input().split())
load = {}
for i in range(N):
  load[i] = 0
for i in range(M):
  a, b = map(int, input().split())
  load[a-1] += 1
  load[b-1] += 1
for i in range(N):
  print(load[i])

Measured memory_bytes: 3060
class SegmentTree
  
  def initialize
    @N=2**17
    @INF=2**31-1
    @seg=Array.new(2*@N-1){@INF}
    @lazy=Array.new(2*@N-1){-1}
  end
  
  def refresh(i, l, r)
    unless @lazy[i]==-1
      @seg[i]=@lazy[i]
      if r-l>1
        @lazy[2*i+1]=@lazy[i]
        @lazy[2*i+2]=@lazy[i]
      end
      @lazy[i]=-1
    end
  end
  
  def update(a, b, x, i=0, l=0, r=@N)
    refresh(i, l, r)
    if b<=l or r<=a
      return
    elsif a<=l and r<=b
      @lazy[i]=x
      refresh(i, l, r)
    else
      m=(r+l)/2
      update(a, b, x, 2*i+1, l, m)
      update(a, b, x, 2*i+2, m, r)
      @seg[i]=[@seg[2*i+1], @seg[2*i+2]].min
    end
  end
  
  def min(a, b, i=0, l=0, r=@N)
    refresh(i, l, r)
    if b<=l or r<=a
      @INF
    elsif a<=l and r<=b
      @seg[i]
    else
      m=(r+l)/2
      vl=min(a, b, 2*i+1, l, m)
      vr=min(a, b, 2*i+2, m, r)
      [vl, vr].min
    end
  end
  
end

st=SegmentTree.new
n, q=gets.split.map(&:to_i)
q.times do
  query=gets.chomp
  case query[0].to_i
  when 0
    c, s, t, x=query.split.map(&:to_i)
    st.update(s, t+1, x)
  when 1
    c, s, t=query.split.map(&:to_i)
    puts st.min(s, t+1)
  end
end

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

class Node:
    def __init__(self,key):
        self.key=key
        self.parent=self.left=self.right=None

def insert(z):
    global root
    x=root
    y=None
    while x:
        y=x
        if z<x.key:
            x=x.left
        else:
            x=x.right
    
    if y==None:
        root=Node(z)
    elif z<y.key:
        y.left=Node(z)
    else:
        y.right=Node(z)

def preorder(x):
    print(" "+str(x.key),end="")
    if x.left != None:
        preorder(x.left)
    if x.right != None:
        preorder(x.right)
        
def inorder(x):
    if x.left != None:
        inorder(x.left)
    print(" "+str(x.key),end="")
    if x.right != None:
        inorder(x.right)
    

root=None

n=int(input())
for i in range(n):
    tmp=input().split()
    if tmp[0]=="insert":
        insert(int(tmp[1]))
    else:
        inorder(root)
        print("")
        preorder(root)
        print("")



Measured memory_bytes: 104996
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {

  char str[20];
  int t[110];
  int p[110];
  int q[110];
  int c[110];
  int dp[2][110000];
      int a;
        while(cin >> a && a) { //N(??¢?????????????????°)???????????????

                //N???????????¢???????????????HP(??????)???????????????
                for(int i=0; i<a; i++) cin >> c[i];
                int b;
                cin >> b; //M(????????????????????°)???????????????
                //Name(???????????????), MP(?¶????MP), Target(Single or All), Damage(????????????????????????)???????????????
                for(int i=0; i<b; i++) {
                        cin >> str >> p[i] >> str >> q[i]; //???????????????????????????Name???????????????????????????
                        if(str[0]=='S') t[i]=1;
                        else t[i]=0;
                }

                //????????? dp[Single -> 1 or All -> 0][????¨?????????????] = ????¨??¶????MP
                for(int i=0; i<110000; i++) dp[0][i]=dp[1][i]=1999999999;
                dp[0][0]=dp[1][0]=0;
                for(int i=0; i<b; i++) {
                        for(int j=0; j<110000; j++) {
                                /**
                                  * min??§109999??¨???????????????100000??\?????§????????°?????¢???????????????????????§????????????????????????
                                  * ?????????????????????(???????????????j+i?????????????????????????????????)?????¨??????MP?¶????????????¨
                                  * (????????????j?????¨??????MP?¶???????+i??????????????????MP?¶???????)?????????
                                  * ????????????i????????????????????????????????¨?????????MP?¶???????????°????????????°???
                                  * ????????????????¶????MP???????´??????????
                                **/
                                dp[t[i]][min(109999,j+q[i])]=min(dp[t[i]][min(109999,j+q[i])],dp[t[i]][j]+p[i]);
                        }
                }

                //??????????????¨??¨????????????????????§?????????????????????????????????????°?MP??????????±??????????
                for(int i=109998; i>=0; i--) {
                        dp[0][i]=min(dp[0][i],dp[0][i+1]);
                        dp[1][i]=min(dp[1][i],dp[1][i+1]);
                }

                /**
                  * ????????¢????????????1????????????????????¨????????????
                  *
                **/
                long long ret=1999999999;
                for(int i=0; i<110000; i++) {
                        long long val=dp[0][i];
                        for(int j=0; j<a; j++) {
                                if(i>=c[j]) continue; //????????¢??????????????????????????????i(?????????????????????)?????§????????´???(???????????´??????)?????????????????????
                                val+=dp[1][c[j]-i]; //?????£?????????????????????????????§????????¨????????????????°?MP???val????¶???????
                        }
                        ret=min(ret,val);//???????¶??????????MP????°????????????????????´?
                }
                cout << ret << endl;
        }
}

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

int main()
{
    int k,a,b;
    cin>>k;
    cin>>a>>b;
    if(a/k==b/k)
    {
        if(a==k*(a/k))
        {
            cout<<"OK";
        }

        else
        {
            cout<<"NG";
        }
    }

    else
    {
        cout<<"OK";
    }


    cout<<endl;
}


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

int main() {
	long long int n, a, b, ans = 0,mini,maxi;

	cin >> n >> a >> b;
	mini = a * (n - 1) + b;
	maxi = b * (n - 1) + a;
	cout << max((long long int)0, maxi - mini + 1) << endl;

}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    ll base = 0;
    REP(i,n){
        ll a;
        cin >> a;
        if(i==0){
            ans += a-1;
            base=1;
            continue;
        }
        if(a<=base+1){
            base = max(base,a);
            continue;
        }
        ans += (a-1)/(base+1);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
n,q = [int(i) for i in input().split()]
s = input()
l = []
r = []
for i in range(q):
  l_tmp, r_tmp = [int(j) for j in input().split()]
  l.append(l_tmp-1)
  r.append(r_tmp-1)
  
ac_cnt = s.count('AC')
r_cnt = [ac_cnt]
l_cnt = [0]
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    r_cnt.append(r_cnt[i-1]-1)
    l_cnt.append(l_cnt[i-1]+1)
  else:
    r_cnt.append(r_cnt[i-1])
    l_cnt.append(l_cnt[i-1])
    
for i in range(q):
  ans = r_cnt[l[i]] + l_cnt[r[i]] - ac_cnt
  print(ans)

Measured memory_bytes: 16548
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    #左から見て，できるだけ右できる
    N,M=MI()
    ab=[[0,0]for _ in range(M)]
    for i in range(M):
        ab[i][0],ab[i][1]=MI()
        
    ab.sort(key=lambda x:(x[0],-1*x[1]))
    ans=0
    
    left=-1
    right=N+1
    for i in range(M):
        if ab[i][0]>=right:
            left=ab[i][0]
            right=ab[i][1]
            ans+=1
        else:
            left=ab[i][0]
            right=min(right,ab[i][1])
            
    print(ans+1)
            

main()


Measured memory_bytes: 57556