akhauriyash/Code-Regression huggingface dataset:
use std::vec::Vec;
use::std::collections::VecDeque;
use std::cmp::*;
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let n: usize = read();

    let mut tree = vec![vec![]; n];
    let mut edges = Vec::new();
    for _ in 0..n-1 {
      let (a, b) = read_touple::<usize>();
      edges.push((a-1, b-1));
      tree[a-1].push(b-1);
      tree[b-1].push(a-1);
    }
    let num = count_children(n, &tree, 0);
    let m = draw_color(n, &tree, 0, num);
    println!("{}", num);
    for &(a, b) in &edges {
      if let Some(color) = m.get(&(a, b)) {
        println!("{}", color);
      } else if let Some(color) = m.get(&(b, a)) {
        println!("{}", color);
      } else {
        panic!()
      }
    }
}


fn count_children(n: usize, tree: &Vec<Vec<usize>>, start: usize) -> usize {
  let mut visit = vec![false; n];
  let mut q = VecDeque::new();
  let mut count = tree[start].len();

  //init
  visit[start] = true;
  q.push_back(start);

  while let Some(now) = q.pop_front() {

    for &e in &tree[now] {
      if !visit[e] {
          visit[e] = true;
          count = max(count, tree[e].len());
          q.push_back(e);
      }
    }
  }
  return count
}

fn draw_color(n: usize, tree: &Vec<Vec<usize>>, start: usize, color: usize) -> HashMap<(usize, usize), usize> {
  let mut color_map = HashMap::new();
  let mut visit = vec![false; n];
  let mut q = VecDeque::new();
  let mut count = tree[start].len();

  //init
  visit[start] = true;
  q.push_back((start, color+1));

  while let Some((now, pre_color)) = q.pop_front() {

    let mut alloc_color = 1; 

    for &e in &tree[now] {

      if pre_color == alloc_color { alloc_color += 1; }

      if !visit[e] {
          visit[e] = true;
          color_map.insert((now, e), alloc_color);
          q.push_back((e, alloc_color));
          alloc_color += 1;
      }
    }
  }
  return color_map
}

Measured memory_bytes: 22780
x,y=map(int,input().split())
k=0
if x==1 and y==1:
    print("1000000")
else:
    if x==1:
       k+=300000
    else:
       if x==2:
          k+=200000
       else:
           if x==3:
               k+=100000
    if y==1:
        k+=300000
    else:
        if y==2:
            k+=200000
        else:
            if y==3:
                k+=100000
    print(k)

Measured memory_bytes: 3064
N = int(input())
H_list = list(map(int, input().split()))

tmp_cnt = 0
max_cnt = 0
for i in range(N - 1):
    if H_list[i] >= H_list[i + 1]:
        tmp_cnt += 1
        if tmp_cnt > max_cnt:
            max_cnt = tmp_cnt
    else:
        tmp_cnt = 0

print(max_cnt)

Measured memory_bytes: 14252
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b){
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b){
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b){
	int res=1;
	while(b){
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=100002;

vector<int>rv[200005];
 
void solve(){
	ll n;
	cin>>n;
	if(n&1){
		cout<<0;
		return;
	}
	ll ev=n,ev2;
	if(n&1){
		ev--;
	}
	ev/=2;
	debug(ev);
	ev2=ev;
	ll calc=0,calc2=0;
	while(ev){
		ev/=5;
		calc+=ev;
	}
	calc2=(ev2);
	while(ev2){
		ev2/=2;
		calc2+=ev2;
	}
	ll calc2al=0,calc5al=0;
	ll n2=n;
	while(n){
		n/=5;
		calc5al+=n;
	}
	while(n2){
		n2/=2;
		calc2al+=n2;
	}
	debug(calc2al,calc2);
	cout<<min(calc2,calc);
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 4992
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int B;

int main() {
    while (true) {
        cin >> B;
        if (B == 0) break;

        int S = B, N = 1;
        for (int i = 2; i * i < 2 * B; i++) {
            int r = 2 * B / i;
            if (r * i != 2 * B) continue;
            if (i % 2 == r % 2) continue;
            S = (r - i + 1) / 2;
            N = i;
        }

        cout << S << ' ' << N << endl;
    }
    return 0;
}



Measured memory_bytes: 3076
#include<stdio.h>
using namespace std;

void trace(int A[], int N) {
    int i;
    for (i = 0; i < N; i++) {
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

void insertionsort(int A[], int n) {
    int i, j, v;
    for (i = 1; i < n; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A, n);
    }
}

int main() {
    int n, i;
    int A[100];
    
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);
    
    trace(A, n);
    insertionsort(A, n);
    
    return 0;
}


Measured memory_bytes: 2756
letter = str(input())
a = int(input())
for i in range(a):
    command = input().split()
    if command[0] == "print":
        print(letter[int(command[1]): int(command[2])+1])
    elif command[0] == "replace":
        letter = letter[:int(command[1])] + command[3] + letter[int(command[2])+1:]
    elif command[0] == "reverse":
        if command[1] == "0":
            letter = letter[:int(command[1])] + letter[int(command[2])::-1] + letter[int(command[2])+1:]
        else:
            letter = letter[:int(command[1])] + letter[int(command[2]):int(command[1])-1:-1] + letter[int(command[2])+1:]



Measured memory_bytes: 5612
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#define reg register
#define LL long long
inline LL read(){
	LL x=0,y=1;
	char c=std::getchar();
	while(c<'0'||c>'9'){if(c=='-') y=0;c=std::getchar();}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
	return y?x:-x;
}
char s[1000006];
int main(){
	std::scanf("%s",s+300001);
	int head=300001,tail=std::strlen(s+300001)+300000;
	reg int q=read(),rev=0;
	while(q--){
		int op=read();
		if(op==1) rev^=1;
		else{
			op=read();char c;std::scanf("%c",&c);
			if(op==1) rev?s[++tail]=c:s[--head]=c;
			else rev?s[--head]=c:s[++tail]=c;
		}
	}
	if(!rev) for(reg int i=head;i<=tail;i++) std::putchar(s[i]);
	else for(reg int i=tail;i>=head;i--) std::putchar(s[i]);
    return 0;
}

Measured memory_bytes: 896
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,a,b,c,d,j,k;
    cin>>a>>b>>c;


    cout<<max(a+b,max(a*b,a-b));

    return 0;
}





Measured memory_bytes: 3652
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  1000000007;

     signed main(){
       int n;
       cin>>n;
       pair<int,int> a[n];int b;
       for(int i=0;i<n;i++){
            cin>>b;
            a[i]=make_pair(b,i);
       }
       sort(a,a+n,greater<pair<int,int>>());
       int dp[n][n];
       for(int i=0;i<n;i++)fill(dp[i],dp[i]+n,-1);
       dp[0][0]=0;
       for(int i=1;i<n;i++){
            if(a[i-1].second>=i-1)if(dp[i-1][0]!=-1)dp[i][0]=dp[i-1][0]+(a[i-1].second-(i-1))*a[i-1].first;
            for(int j=1;j<i;j++){
                 if(a[i-1].second>=i-1-j)if(dp[i-1][j]!=-1)dp[i][j]=dp[i-1][j]+(a[i-1].second-(i-1-j))*a[i-1].first;
                 if(a[i-1].second<=n-j)if(dp[i-1][j-1]!=-1)dp[i][j]=max(dp[i][j],dp[i-1][j-1]+(n-j-a[i-1].second)*a[i-1].first);
            }
            if(a[i-1].second<=n-i)if(dp[i-1][i-1]!=-1)dp[i][i]=dp[i-1][i-1]+(n-i-a[i-1].second)*a[i-1].first;
       }
       int ans=dp[n-1][0]+abs(n-1-a[n-1].second)*a[n-1].first;
       for(int i=1;i<n;i++)ans=max(ans,dp[n-1][i]+abs(n-1-i-a[n-1].second)*a[n-1].first);
       cout<<ans<<endl;



      }

        


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


int main() {
    long n;
    cin>>n;
    long num[n];
    for (int i = 0; i < n; ++i) {
        cin>>num[i];
    }
    long count=n;
    sort(num,num+n);
    long now=num[0];
    for (int j = 0; j < n-1; ++j) {
        //cout<<now<<endl;
        if(num[j+1]>now*2)count=n-j-1;
        now+=num[j+1];
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
#define TIME (chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
bool is(string a){
    int i = 0;
    int j = a.length() -1;
    while(i < j){
        if(a[i] != a[j])return false;
        i++;
        j--;
    }
    return true;
}

void solve(){

    string s;cin >> s;

    int len = s.length()/2;
    if(is(s) && is(s.substr(0, len)) && is(s.substr(len+1, len))){
        cout << "Yes";

    }else cout << "No";




}

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




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

typedef long long ll;
typedef unsigned long long ull;

#define FRO freopen("in.txt","r",stdin);

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


      int n,i,j,k;
      cin>>n>>k;
      int arr[n+2],dp[n+2];

      for(i=1;i<=n;i++) cin>>arr[i];
      dp[0]=0;
      dp[1]=0;
      arr[0]=0;

      for(i=2;i<=n;i++)
      {
            int tmp=INT_MAX;
            int lo=max(1,i-k);
            for(j=i-1;j>=lo;j--)
            {
                  tmp=min(tmp,dp[j]+abs(arr[i]-arr[j]));
            }
            dp[i]=tmp;
      }

      cout<<dp[n]<<endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const ll INF = 1e18;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

struct edge {
    int from, to, cost;
};

bool reachableFrom1[1005];
bool reachableToN[1005];
vector<int> g[1005];
vector<int> rg[1005];

void dfs(int v) {
    if (reachableFrom1[v]) return;
    reachableFrom1[v] = true;
    for (int nv : g[v]) {
        dfs(nv);
    }
}

void rdfs(int v) {
    if (reachableToN[v]) return;
    reachableToN[v] = true;
    for (int nv : rg[v]) {
        rdfs(nv);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<edge> edges;
    rep(i, 0, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        c *= -1;
        edge tmp = {a, b, c};
        edges.push_back(tmp);
        g[a].push_back(b);
        rg[b].push_back(a);
    }

    dfs(0);
    rdfs(n - 1);

    vector<ll> dist(n, INF);
    dist[0] = 0;
    rep(i, 0, n) {
        for (auto e : edges) {
            if (!reachableFrom1[e.from] || !reachableToN[e.from]) continue;
            if (!reachableFrom1[e.to] || !reachableToN[e.to]) continue;
            if (dist[e.from] == INF) continue;
            if (dist[e.to] > dist[e.from] + e.cost) {
                if (i == n - 1) {
                    cout << "inf" << endl;
                    return 0;
                }
                dist[e.to] = dist[e.from] + e.cost;
            }
        }
    }
    cout << -dist[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll r,g,b,n;
ll ans=0,tmp=0;

int main(void){
    double n,k;
    cin>>n>>k;
    double m[100010];
    double tmp=0;
	double res = 0;
    if(n<k){
		for(ll i=1;i<n+1;i++){
			if(i%2==0){
				m[i] = m[i/2]-1;
			}else{
				tmp = i;
				ll cnt=0;
				while(1){
					tmp *= 2;
					cnt++;
					if(tmp>=k)break;
				}
				m[i]=cnt;
			}
		}
		for(ll i=1;i<=n;i++){
			res += (1/n * pow((double)1/2,m[i]));
			//res += double(1/n);
			//cout<<"res:"<<res<<" tmp:"<<m[i]<<(double)pow(1/2,(double)m[i])<<endl;
		}
    }else{
		for(ll i=1;i<k+1;i++){
			if(i%2==0){
				m[i] = m[i/2]-1;
			}else{
				tmp = i;
				ll cnt=0;
				while(1){
					tmp *= 2;
					cnt++;
					if(tmp>=k)break;
				}
				m[i]=cnt;
			}
		}
		for(ll i=1;i<k;i++){
			//cout<<"i:"<<i<<" m:"<<m[i]<<endl;
			res += (1/n * (1-(pow((double)1/2,m[i]))));
			//res += double(1/n);
			//cout<<"res:"<<res<<" tmp:"<<m[i]<<(double)pow(1/2,(double)m[i])<<endl;
		}
		res = 1-res;
    }
    cout<<setprecision(12)<<res<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
 
char s[10001];
int n,count=0,i;
 
int dfs();
int cmp(const void *p1,const void *p2){
  return *(int*)p1-*(int*)p2;
}
 
int main(void){
  int a,ans=0;
  scanf("%d",&n);
  scanf("%c",&s[0]);
  for(a=0;a<n;a++){
    i=0;
    count=0;
    while(1){
      scanf("%c",&s[count]);
      if(s[count]=='\n')break;
      count++;
    }
    i=0;
    ans = dfs();
    printf("%d\n",ans);
  }
  return 0;
}
 
int dfs(){
  int ca=0,j,ans=0;
  int ab[4000];
  i++;
  if(s[i]>='0'&&s[i]<='9'){
    int x=0;
    while(s[i]>='0'&&s[i]<='9'){
      x = x*10+s[i]-'0';
      i++;
    }
    i++;
    return (x/2)+1;
  }
 
  else  while(s[i]=='['){
      ab[ca]=dfs();
      ca++;
    }
  qsort(ab,ca,sizeof(int),cmp);
  for(j=0;j<(ca/2)+1;j++)ans+=ab[j];
  i++;
  return ans;
}



Measured memory_bytes: 2064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;
typedef std::vector< int > VI;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = 1 << 30;

ll gdb_exec(ll a, ll b) {
  if (b == 0) return a;
  return gdb_exec(b, a % b);
}

ll gdb(ll a, ll b) {
  if (a < b) std::swap(a, b);
  if (a == 0 || b == 0) return -999999999;
  return gdb_exec(a, b);
}

ll lcm(ll a, ll b) {
  ll gdb_val = gdb(a, b);
  if (a % gdb_val == 0) {
    return (a / gdb_val) * b;
  }
  return (b / gdb_val) * a;
}

int main(int argc, char* argv[])
{
  int r, g, b;
  std::cin >> r >> g >> b;

  std::string judge = "NO";
  if ((r*100+g*10+b)%4==0) {
    judge = "YES";
  }

  std::cout << judge << std::endl;
  return 0;
}


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

int main(void){
   string S;
   cin>>S;
   rep(0,i,3){
       if(S.substr(i,1)==S.substr(i+1,1)){
           cout<<"Bad"<<endl;
           return 0;
       }
   }
   cout<<"Good"<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>


int main(){
  long N;
  std::cin >> N;
  long L[100];
  for(long i=0; i<N; i++){
    std::cin >> L[i];
  }
  long count=0;
  for(long i=0; i<N; i++){
    for(long j=i+1; j<N; j++){
      for(long k=j+1; k<N; k++){
        if(L[i]<L[j]+L[k] &&L[j]<L[i]+L[k] && L[k]<L[i]+L[j] && L[i]!=L[j] && L[j]!=L[k] && L[k]!=L[i]){
          count++;
        }
      }
    }
  }  
  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll a,b,n;
    cin >>a >> b >> n;
    ll range;
    if( n < b )
    cout << a*n/b;
    else
    cout << a*(b - 1)/b;
    
    
    
}









Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 70;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, k;

ll adj[MAXN][MAXN];
ll res[MAXN][MAXN];
ll temp[MAXN][MAXN];
void mulp1(){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            temp[i][j] = res[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            res[i][j] = 0;
            for(int k = 0; k < n; k++){
                res[i][j] = (res[i][j] + adj[i][k]*temp[k][j]);
                res[i][j] %= mod;
            }
        }
    }
}

void mulp(){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            temp[i][j] = adj[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            adj[i][j] = 0;
            for(int k = 0; k < n; k++){
                adj[i][j] = (adj[i][j] + temp[i][k]*temp[k][j]);
                adj[i][j] %= mod;
            }
        }
    }
}


void bp(ll a){
    while(a){
        if(a % 2){
            mulp1();
        }
        mulp();
        a /= 2;
    }
}


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

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n>>k;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j)
            res[i][j] = 1;
            cin>>adj[i][j];
        }
    }
    bp(k);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            ans += res[i][j];
            ans %= mod;
        }
    }
    cout<<ans<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using LL = long long;
using P = pair<int,int>;
const int mx = 10000000;
vector<int> a(mx);

int clllats(int N){
	if(N%2==0) return N / 2;
	else return 3 * N + 1;
}

int main(){
	cin >> a[0];
	for(int i = 1;i<mx;i++) {
		a[i] = clllats(a[i-1]);
	}
	int ans = mx;
	rep(i,mx-2){
		int tmp = 100;
		for(int j = i + 1;j <= mx -1; j++){

			if(a[i] == a[j]){
				tmp = j + 1;
				ans = min(ans, tmp);
				break;
			}
		}
	}	
	cout << ans << endl;
	return 0;
}













Measured memory_bytes: 42136
import heapq
INFTY = 10**4
N,X,Y = map(int,input().split())
G = {i:[] for i in range(1,N+1)}
for i in range(1,N):
    G[i].append(i+1)
    G[i+1].append(i)
G[X].append(Y)
G[Y].append(X)
dist = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
for i in range(N+1):
    dist[i][i] = 0
for i in range(1,N+1):
    hist = [0 for _ in range(N+1)]
    heap = [(0,i)]
    hist[i] = 1
    while heap:
        d,x = heapq.heappop(heap)
        if d>dist[i][x]:continue
        hist[x] = 1
        for y in G[x]:
            if hist[y]==0:
                if dist[i][y]>d+1:
                    dist[i][y] = d+1
                    heapq.heappush(heap,(d+1,y))
C = {k:0 for k in range(1,N)}
for i in range(1,N):
    for j in range(i+1,N+1):
        C[dist[i][j]] += 1
for k in range(1,N):
    print(C[k])

Measured memory_bytes: 111244
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p%i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL a, b;
	cin >> a >> b;
	string ans = "No";
	FOR(i, 1, 4) {
		if ((a*b*i) % 2 != 0) {
			ans = "Yes";
		}
	}
	O(ans);

	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
  	// N 個 K 色
	int N, K;
  	cin >> N >> K;
  	int ans = K;
  	if(N == 1){ 
      	cout << ans << endl;
        return;
    }
  	else{
		rep(i,N-1){      	
  		ans *= (K-1);
        }
    }
  	cout << ans << endl;
    return;
}

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

Measured memory_bytes: 256
N = gets.to_i
ans = {
  "AC" => 0,
  "WA" => 0,
  "TLE" => 0,
  "RE" => 0
}

N.times do
  ans[gets.chomp] += 1
end

ans.each do |k, v|
  puts "#{k} x #{v}"
end


Measured memory_bytes: 14308
#include <cstdio>
using namespace std;
int main(){
    int N,M;
    scanf("%d",&N);
    int T[N];
    for(int n=0;n<N;n++){
        scanf("%d",&T[n]);
    }
    scanf("%d",&M);
    int P[M],X[M];
    for(int n=0;n<M;n++){
        scanf("%d %d",&P[n],&X[n]);
    }
    int sum = 0;
    for(int n=0;n<N;n++){
        sum+=T[n];
    }
    for(int n=0;n<M;n++){
        printf("%d\n",sum-T[P[n]-1]+X[n]);
    }
    return 0;
}

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

using namespace std;

int main() {
  int N;
  int T;
  cin >> N >> T;
  long long t;
  cin >> t;
  long long sum = 0;
  long long previous = 0;
  for (int i = 1; i < N; ++i) {
    cin >> t;
    long long diff = t - previous;
    previous = t;
    sum += min((long long)T, diff);
  }
  sum += T;
  cout << sum << endl;
  return 0;
}



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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct SegmentTree {
  vector<Pi> data;
  int sz;
  SegmentTree(){}
  SegmentTree(int n) {
    sz = 1; while(sz < n) sz <<= 1;
    data.resize(2*sz-1, Pi(-inf, -inf));
  }
  void update(int k, int x) {
    k += sz-1;
    data[k] = Pi(x, k-sz+1);
    while(k > 0) {
      k = (k-1)/2;
      data[k] = max(data[2*k+1], data[2*k+2]);
    }
  }
  Pi query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return Pi(-inf, -inf);
    if(a <= l && r <= b) return data[k];
    Pi vl = query(a, b, 2*k+1, l, (l+r)/2);
    Pi vr = query(a, b, 2*k+2, (l+r)/2, r);
    return max(vl, vr);
  }
  Pi query(int a, int b) {
    return query(a, b, 0, 0, sz);
  }
};

int a[5050];
int b[5050][202];
int dp[5050][5050];
SegmentTree seg;

void dfs(int l, int r) {
  if(l >= r) return;
  Pi p = seg.query(l, r);
  dp[l][p.second] += p.first;
  dp[p.second+1][p.second] -= p.first;
  dp[l][r] -= p.first;
  dp[p.second+1][r] += p.first;
  dfs(l, p.second);
  dfs(p.second+1, r);
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  cin >> n >> m;
  reps(i, 1, n) {
    cin >> a[i];
    a[i] += a[i-1];
  }

  rep(i, n) rep(j, m) cin >> b[i][j];

  rep(i, m) {
    seg = SegmentTree(n);
    rep(j, n) seg.update(j, b[j][i]);
    dfs(0, n);
  }

  rep(i, n) rep(j, n) dp[i][j+1] += dp[i][j];
  rep(j, n) rep(i, n) dp[i+1][j] += dp[i][j];

  int ans = -inf;
  rep(i, n) {
    reps(j, i, n) chmax(ans, dp[i][j]-a[j]+a[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 208000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 5e5 + 5;
const int MOD = 1e9 + 7;
int fat[MAX];

inline int add(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    return a;
}

inline int add(initializer_list<int> l) {
    int total = 0;
    for (auto &e : l) total = add(total, e);
    return total;
}

inline int sub(int a, int b) {
    a -= b;
    if (0 > a) a += MOD;
    return a;
}

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

inline int mult(initializer_list<int> l) {
    int total = 1;
    for (auto &e : l) total = mult(total, e);
    return total;
}

int f_exp(int x, int e) {
    if (e == 0) return 1;
    if (e & 1) return mult(x, f_exp(x, e - 1));
    return f_exp(mult(x, x), e / 2);
}

inline int inv(int x) {
    return f_exp(x, MOD - 2);
}

inline int comb(int n, int k) {
    if (k > n) return 0;
    return mult(fat[n], mult(inv(fat[n - k]), inv(fat[k])));
}

void preprocess() {
    fat[0] = 1;
    fori (i, 1, MAX) {
        fat[i] = mult(fat[i - 1], i);
    }
}

void solve() {
    preprocess();
    int n, m;
    cin >> n >> m;
    int a = mult(fat[m], inv(fat[m - n]));
    int b = 0;
    fori (i, 0, n + 1) {
        int x = comb(n, i);
        int y = mult(fat[m - i], inv(fat[m - n]));
        int z = mult(x, y);
        if (i % 2 == 0) b = add(b, z);
        else b = sub(b, z);
    }
    cout << mult(a, b) << endl;
}

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



Measured memory_bytes: 5576
#include <stdio.h>

//  A... Z  a... z
// 65...90 97...122

int main() {
    char ch;
    while ((ch = getchar()) != EOF) {
        if (ch == '\n') break;
        else if (ch >= 97 && ch <= 122) printf("%c", ch - 32);
        else if (ch >= 65 && ch <= 90) printf("%c", ch + 32);
        else printf("%c", ch);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 2612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
const int MOD = 1000000007;

int main() {
  ll Ans = 0;  // 回答：
 	map<string,int> M;   // 値と個数のマップ
  int N; cin >> N;  // 回数

  string wk_S;
  rep(i,N){
    cin >> wk_S;
    M[wk_S]++;
  }
  Ans = M.size();

  cout << Ans << endl;
}


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

using namespace std;

int n,a[100010],ans;

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for(int i=1; i<=n; i++)
	{
		if(i+1>a[i+1])
		{
			for(int j=i+1; a[j]==i; j++)ans^=1;
			ans|=(a[i]-i)&1;
			puts(ans?"First":"Second");
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 640
n,k = list(map(int, input().split()))
s = input()
if s[k-1] == "A":
    a = s[:k-1] + "a" + s[k:]
elif s[k-1] == "B":
    a = s[:k-1] + "b" + s[k:]
else:
    a = s[:k-1] + "c" + s[k:]

print(a)

Measured memory_bytes: 3060
//url:https://atcoder.jp/contests/abc138/tasks/abc138_c
//problem name:C - Alchemist

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
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;
}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

vector<double> res;
int N;

int main() {
    cin >> N;
    rep(i,N) {
        double v; cin >> v;
        res.push_back(v);
    }
    rep(i,N-1) {
        sort(res.begin(),res.end());
        double new_v = (res.at(0)+res.at(1))/2;
        res.erase(res.begin());
        res.erase(res.begin());
        res.push_back(new_v);
    }
    cout << res.at(0) << endl;
}


Measured memory_bytes: 384
N = int(input())
lst = sorted([int(x) for x in input().split() if x != "1"], reverse=True)

if len(lst) == 0:
    print(1)
    exit()
if lst[-1] == 0:
    print(0)
    exit()

ret = 1
for x in lst:
    ret *= x
    if ret > 10 ** 18:
        print(-1)
        exit()

print(ret)

Measured memory_bytes: 21656
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

ll n,m;

int main(){
  cin >> n >> m;
  ll ans;
  if(n * 2 >= m) ans = m / 2;
  else ans = n + ((m - 2 * n) / 4);
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
using vi = vector<int>;
using Tree = vector<map<int,int>>;
#define LEFT 0
#define RIGHT 1

typedef string::const_iterator State;

int number(State &begin){
  int res = 0;
  while(isdigit(*begin)){
    res *= 10;
    res += *begin - '0';
    ++begin;
  }
  return res;
}

int parse(State &begin, Tree &t, vi &mp){
  if(*begin == ')') return -1;

  ++begin; // '('
  int l = parse(begin, t, mp); // ノード番号
  ++begin; // ')'
  ++begin; // '[';
  int p = number(begin); // ノードの数
  ++begin; // ']';
  ++begin; // '(';
  int r = parse(begin, t, mp); // ノード番号
  ++begin; // ')';

  mp.push_back(p);
  t.resize(t.size()+1);
  if(l != -1) t.back()[LEFT] = l;
  if(r != -1) t.back()[RIGHT] = r;

  return t.size()-1;
}

string syncDFS(int ap, Tree at, vi amp, int bp, Tree bt, vi bmp){
  string res;

  res += "(";
  if(at[ap].count(LEFT) and bt[bp].count(LEFT))
    res += syncDFS(at[ap][LEFT], at, amp, bt[bp][LEFT], bt, bmp);
  res += ")[";
  res += to_string(amp[ap] + bmp[bp]);
  res += "](";
  if(at[ap].count(RIGHT) and bt[bp].count(RIGHT))
    res += syncDFS(at[ap][RIGHT], at, amp, bt[bp][RIGHT], bt, bmp);
  res += ")";

  return res;
}

int main(){
  string a, b;
  cin >> a >> b;

  Tree at, bt;
  vi amp, bmp;
  State begin = a.begin();
  int aroot = parse(begin, at, amp);
  begin = b.begin();
  int broot = parse(begin, bt, bmp);

  cout << syncDFS(aroot, at, amp, broot, bt, bmp) << endl;
}


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

int main(){
    ll D;
    cin >> D;
    vector<ll> c(26), t(D), last(26, -1);
    vector< vector<ll> > s(365, vector<ll> (26));
    rep(i, 0, 26) cin >> c[i];
    rep(i, 0, D){
        rep(j, 0, 26) cin >> s[i][j];
    }
    srand((unsigned int)time(NULL));
    rep(i, 0, D){
        t[i] = (ll) (rand() % 26);
    }
    ll M = 1e5;
    vector<ll> d(M), q(M), rec(26, 0);
    rep(i, 0, M){
        d[i] = (ll) (rand() % D);
        q[i] = (ll) (rand() % 26);
    }
    ll res = 0;
    rep(d, 0, D){
        res += s[d][t[d]];
        last[t[d]] = d;
        rep(j, 0, 26) {
            res -= c[j] * (d - last[j]);
            rec[j] += c[j] * (d - last[j]);
        }
    }
    // t[d[m]] := 0 - 25
    rep(m, 0, M){
        ll prev_res = res;
        res -= s[d[m]][t[d[m]]];
        res += s[d[m]][q[m]];
        res += rec[t[d[m]]];
        res += rec[q[m]];
        ll tdrec = 0, qrec = 0;
        ll lst = -1;
        rep(i, 0, D){
            if(i != d[m] && t[i] == t[d[m]]){
                lst = i;
            }
            res -= c[t[d[m]]] * (i - lst);
            // rec[t[d[m]]] +=  c[t[d[m]]] * (i - lst);
            tdrec +=  c[t[d[m]]] * (i - lst);
        }
        lst = -1;
        rep(i, 0, D){
            if(i == d[m] || t[i] == q[m]){
                lst = i;
            }
            res -= c[q[m]] * (i - lst);
            // rec[q[m]] += c[q[m]] * (i - lst);
            qrec += c[q[m]] * (i - lst);
        }
        if(res > prev_res){
            rec[t[d[m]]] = tdrec;
            rec[q[m]] = qrec;
            t[d[m]] = q[m];
        }else{
            res = prev_res;
        }
        // cout << res << endl;
    }
    rep(i, 0, D) cout << t[i]+1 << endl;
    return 0;
}

Measured memory_bytes: 4848
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <unordered_set>
#include <stack>
#include <iomanip>
using namespace std;

struct Node{
    bool c[26];
    Node() {
        memset(c, 0, sizeof(c));
    }
    Node(char ch) {
        memset(c, 0, sizeof(c));
        c[ch-'a'] = 1;
    }
};

class SegTree{
public:
    vector<Node> ST;
    string S;
    int N;
    int left(int i) { return i << 1; }
    int right(int i) { return (i << 1) + 1; }
    void merge(Node& n1, Node& n2, Node& ret) {
        for(int i=0; i<26; i++)
            ret.c[i] = n1.c[i] || n2.c[i];
    }
    void build(int p, int L, int R) {
        if(L==R) {
            ST[p] = Node(S[L]);
            return;
        }
        build(left(p), L, (L+R)/2);
        build(right(p), (L+R)/2+1, R);
        merge(ST[left(p)], ST[right(p)], ST[p]);
    }
    void update(int p, int L, int R, int ind, char ch) {
        if(ind < L || ind > R)
            return;
        if(L==R) {
            ST[p].c[S[ind]-'a'] = 0;
            S[ind] = ch;
            ST[p].c[ch-'a'] = 1;
            return;
        }
        update(left(p), L, (L+R)/2, ind, ch);
        update(right(p), (L+R)/2+1, R, ind, ch);
        merge(ST[left(p)], ST[right(p)], ST[p]);
    }
    Node query(int p, int L, int R, int qL, int qR) {
        if(qR<L || qL>R)
            return Node();
        if(qL<=L && R<=qR)
            return ST[p];
        Node n1 = query(left(p), L, (L+R)/2, qL, qR);
        Node n2 = query(right(p), (L+R)/2+1, R, qL, qR);
        Node ret;
        merge(n1, n2, ret);
        return ret;
    }
    void update(int ind, char ch) {
        if(S[ind] == ch)
            return;
        update(1, 0, N-1, ind, ch);
    }
    int query(int qL, int qR) {
        Node ret = query(1, 0, N-1, qL, qR);
        int ans = 0;
        for(int i=0; i<26; i++)
            ans += ret.c[i];
        return ans;
    }
    SegTree(string s) {
        N = s.length();
        S = s;
        ST.resize(4*N);
        build(1, 0, N-1);
    }
};

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

    int n, q, t;
    string s;
    cin >> n >> s >> q;
    SegTree ST(s);
    for(int i=0; i<q; i++) {
        cin >> t;
        if(t==1) {
            int ind;
            string ch;
            cin >> ind >> ch;
            ST.update(ind-1, ch[0]);
        } else {
            int l, r;
            cin >> l >> r;
            cout << ST.query(l-1, r-1) << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 52252
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
ll mod = 998244353;
long long power(long long m,long long n){
    long long res = 1;
    if(n > 0){
        res = power(m,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }
        else{
            res = (((res * res) % mod) * m) % mod;
        }
    }
    return res;
}
int main(){
  ll n = 0;
  cin >> n;
  ll res = 0;
  res = 1;
  vector<ll> count(n);
  for(int i = 0;i < n;i++){
    ll in;
    cin >> in;
    count[in]++;
    if((i == 0 && in != 0) || (i != 0 && in == 0)){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i = 1;i < n;i++){
    if(count[i] > 0){
      res *= power(count[i - 1],count[i]);
      res %= mod;
    }
  }
  if(n == 1){
    if(count[0] == 1)res = 1;
    else res = 0;
  }
  if(count[0] != 1)res = 0;
  cout << res << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int a,b,c,i,ans=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++){
		if(c%i==0){
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 596
import scala.collection.mutable
import java.io.{BufferedReader, InputStreamReader}

object Main extends App {

  val in = new BufferedReader(new InputStreamReader(System.in))
  val Array(a, b, c, d, e, f) = in.readLine.split(" ").map(_.toInt)
  // 入れる水の量 100a 100b
  // 入れる砂糖の量 c d
  // 100gあたりとける量 e
  // ビーカーに入る量 f
  // 濃度 0% の砂糖水 : water > 0 , sugar >= 0
  val water = {
    val set = mutable.HashSet[Int]()
    for {
      i <- 0 to f/(a*100)
      j <- 0 to f/(b*100)
      w = 100 * a * i + 100 * b * j
      if 0 < w && w <= f
    } set += w
    set.toArray
  }
  val sugar = {
    val set = mutable.HashSet[Int]()
    for {
      i <- 0 to (f-100)/c
      j <- 0 to (f-100)/d
      w = c * i + d * j
      if w <= f
    } set += w
    set.toArray
  }

  // println(water.length + " " + sugar.length)

  val ans = {
    var max = (-1d, 0, 0)
    for {
      w <- water
      wd = w.toDouble/100d
      s <- sugar
      weight = w + s
      concent = s.toDouble / wd
      if w + s <= f && concent <= e
    } {
      if(concent > max._1) {
        // println(weight + " " + concent)
        max = (concent, weight, s)
      }
    }
    max
  }
  
  println(ans._2 + " " + ans._3)
}

Measured memory_bytes: 38064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int n = s.size(), sum = 0;
  for(int i =0; i< n; i++)
  {
    sum+=(s[i]-'0');
  }
  if(sum%9==0)
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }
}

Measured memory_bytes: 3756
import math

n, k = map(int, input().split())
ans = 0
for i in range(1, n + 1):
    if k/i > 1:
        l = math.log2(k / i)
        a = math.ceil(l)
        ans += (1 / n) * ((1 / 2) ** a)
    else:
        ans += 1/n

print(ans)


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

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int h,w,k;cin>>h>>w>>k;
  vector<string> m(h);
  for(int i=0;i<h;i++){
    cin>>m[i];
  }
  int ans=0;
  for(int path=0;path<(1<<h);path++){
    for(int patw=0;patw<(1<<w);patw++){
      int cnt=0;
      cerr<<"H : "<<path<<", W : "<<patw<<endl;
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(((path&(1<<i))!=0)||((patw&(1<<j))!=0)){
            continue;
          }
          if(m[i][j]=='#'){
            cerr<<i<<" ,"<<j<<endl;
            cnt++;
          }
        }
        cerr<<endl;
      }
      if(cnt==k){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

const double EPS = 1e-10;
double add(double a, double b) {
    if(abs(a+b) < EPS*(abs(a)+abs(b))) return 0;
    return a+b;
}
struct Vector {
    double x, y;
    Vector() {}
    Vector(double x, double y):x(x), y(y) {}
    Vector operator+(Vector v) {return Vector(add(x, v.x), add(y, v.y));}
    Vector operator-(Vector v) {return Vector(add(x, -v.x), add(y, -v.y));}
    Vector operator*(double d) {return Vector(x*d, y*d);}
    Vector operator/(double d) {return Vector(x/d, y/d);}
    double dot(Vector v) {return add(x*v.x, y*v.y);}
    double cross(Vector v) {return add(x*v.y, -y*v.x);}
};
double dist(Vector v, Vector u) {return ((v-u).dot(v-u));}
bool on_seg(Vector v1, Vector v2, Vector p) {
    return (v1-p).cross(v2-p) == 0 && (v1-p).dot(v2-p) <= 0;
}
//v1-v2とu1-u2の交点
Vector intersection(Vector v1, Vector v2, Vector u1, Vector u2) {
    assert((v1-v2).cross(u1-u2)); //2直線が平行だとだめ
    return v1 + (v2-v1)*((u2-u1).cross(u1-v1)/(u2-u1).cross(u2-v1));
}
bool cmp_x(const Vector &v, const Vector &u) {
    if(v.x != u.x) return v.x < u.x;
    return v.y < u.y;
}
//頂点数nの頂点集合vv
vector<Vector> convex_hull(vector<Vector> &vv, int n) {
    sort(vv.begin(), vv.end(), cmp_x);
    int k = 0;
    vector<Vector> res(n*2);
    for(int i = 0; i < n; i++) {
        while(k > 1 && (res[k-1]-res[k-2]).cross(vv[i]-res[k-1]) <= 0) k--;
        res[k++] = vv[i];
    }
    for(int i = n-2, t = k; i >= 0; i--) {
        while(k > t && (res[k-1]-res[k-2]).cross(vv[i]-res[k-1]) <= 0) k--;
        res[k++] = vv[i];
    }
    res.resize(k-1);
    return res;
}
istream &operator>>(istream &is, Vector &v) {return is >> v.x >> v.y;}
ostream &operator<<(ostream &os, const Vector &v) {return os << v.x << ' ' << v.y;}

signed main() {
    cout << fixed << setprecision(15);
    Vector p1, p2;
    cin >> p1 >> p2;
    int q;
    cin >> q;
    while(q--) {
        Vector Q;
        cin >> Q;
        cout << p1+(p2-p1)*(Q-p1).dot(p2-p1)/dist(p1, p2) << '\n';
    }
}


Measured memory_bytes: 3288
S = list(input())
N = len(S)

ans = 'AC'
if S[0] != 'A' or 'C' not in S[2:-1]:
    ans = 'WA'

tmp = 0
for i in range(1,N):
    if S[i].isupper():
        tmp += 1

if tmp > 1:
    ans = 'WA'

print(ans)


Measured memory_bytes: 9056
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String b = sc.next();
		if(b.equals("A"))System.out.println("T");
		else if(b.equals("T"))System.out.println("A");
		else if(b.equals("C"))System.out.println("G");
		else System.out.println("C");
	}
}

Measured memory_bytes: 21844