akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<set>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define maximize(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define yn(i) print((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}
// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
  for(const pair<S,T>& x: mp){
    cout << "[" << x.first << "]=" << x.second << " ";
  }
  return os;
}


int gcd(int a,int b){ return b?gcd(b,a%b):a; }
li lcm(li a,li b){ return a/gcd(a,b)*b; }

// [0,a]
li totient(li a,int c,int d){
  li l=lcm(c,d);
  return a-(a/c+a/d-a/l);
}

int main(){
  li a,b,c,d; cin >>a >>b >>c >>d;
  print(totient(b,c,d)-totient(a-1,c,d));
}





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

ll nCr(int n, int r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
        ans = ans/(n + 1 - i);
    }
    return ans;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    vector<ll> v(n);
    for(int i = 0; i < n; i++)cin >> v[i];
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    
    ll ans;
    
    if(v[0] == v[a-1]){
        cout << fixed << setprecision(10) << (double)v[0] << endl;
        int t = count(v.begin(), v.end(), v[0]);
        for(int i = a; i <= min(t,b); i++) ans += nCr(t, i);
        cout << ans<< endl;
    }else{
        double ave = 0;
        for(int i = 0; i < a; i++) ave += (double)v[i]/(double)a;
        cout << fixed << setprecision(10) << ave << endl;
        int t = 0;
        while(a - 1 - t >= 0 && v[a - 1 - t] == v[a -1]){
            t++;
        }
        cout << nCr(count(v.begin(), v.end(), v[a-1]),t) << endl;
    }
    
    return 0;
}

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

string s,b[10]={" ","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"};

string conv(int p,int t) {
    if(p==s.length()) return "";
    int c=0;
    while(p<s.length() && s[p]==t+'0')c++,p++;
    return string((t==0)?(c-1):1,b[t][(c-1)%(b[t].length())]) + conv(p,s[p]-'0');
}

int main() {
    while(cin>>s) cout<<conv(0,s[0]-'0')<<endl;
}

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N, M;
    cin>>N>>M;
    vector<bool> Used(N, false);
    vector<pint> Ans;
    int even1 = 1, even2 = N;
    int even3 = (N+1)/2+1, even4 = (N+1)/2-1;
    REP(i, 1, M+1){
        if(i%2 == 1){
            Ans.push_back({even1, even2});
            even1++; even2--;
        }
        else{
            Ans.push_back({even3, even4});
            even3++; even4--;
        }
    }

    for(auto x: Ans){
        cout << x.first << " " << x.second << endl;
    }
}

Measured memory_bytes: 4164
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 998244353;
const int INF = 9e18;

signed main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    cin >> a >> b;
    int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    for (int i = 0; i < M; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, a[x - 1] + b[y - 1] - c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    cout << a[1] - a[0] + a[2] - a[1] << endl;
    return 0;
}




Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if (n==0) {
				break;
			}
			double[] x = new double[n];
			double[] y = new double[n];
			double[] z = new double[n];
			double[] r = new double[n];
			for(int i=0;i<n;i++) {
				x[i] = sc.nextDouble();
				y[i] = sc.nextDouble();
				z[i] = sc.nextDouble();
				r[i] = sc.nextDouble();
			}
			ArrayList<Edge> graph = new ArrayList<Edge>();
			for(int i=0;i<n-1;i++) {
				for(int j=i+1;j<n;j++) {
					double dist = Math.sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i])+(z[j]-z[i])*(z[j]-z[i])) - r[i] - r[j];
					if (dist<0) {
						dist = 0;
					}
					graph.add(new Edge(dist,i,j));
				}
			}
			Collections.sort(graph);
			//System.out.println(graph.toString());

			UnionFind uf = new UnionFind(n);
			double ans = 0;
			int connected = 1;
			for(int i=0;i<graph.size();i++) {
				Edge e = graph.get(i);
				if (!uf.isConnected(e.from, e.to)) {
					uf.union(e.from, e.to);
					connected++;
					ans+=e.cost;
					if (connected==n) {
						break;
					}
				}
			}

			System.out.printf("%.3f\n", ans);
		}
	}

}
class Edge implements Comparable<Edge>{
	double cost;
	int from;
	int to;
	public Edge(double cost,int from,int to) {
		this.cost = cost;
		this.from = from;
		this.to = to;
	}
	@Override
	public int compareTo(Edge o) {
		if (this.cost == o.cost) {
			return 0;
		}else if(this.cost > o.cost) {
			return 1;
		}else{
			return -1;
		}
	}

	public String toString() {
		return this.cost + "," + this.from + "," + this.to;
	}
}

class UnionFind {
	private int[] data;
	public UnionFind(int size) {
		data = new int[size];
		Arrays.fill(data, -1);
	}
	public void union(int x,int y) {
		x = root(x);
		y = root(y);
		if (x!=y) {
			if (data[y] < data[x]) {
				int tmp = y;
				y = x;
				x = tmp;
			}
			data[x] += data[y];
			data[y] = x;
		}
	}
	public boolean isConnected(int x,int y) {
		return root(x)==root(y);
	}
	private int root(int x) {
		return data[x] < 0 ? x : (data[x] = root(data[x]));
	}
	public int size(int x) {
		return -data[root(x)];
	}
	public String toString() {
		return Arrays.toString(data);
	}
}

Measured memory_bytes: 66088
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll gcd(ll a, ll b) {
	return a % b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	cout<<"case #" << x << ": " << endl
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-15;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int main() {
	int n;	cin >> n;
	vector<int> a(n), b(n);
	rep(i, n)	cin >> a[i];
	rep(i, n)	cin >> b[i];
	sort(all(a));
	sort(all(b));
	int ret = 0;
	vector<int> amod(n), bmod(n);
	rep(i, 29) {

		int T = (1 << i);

		rep(j, n)	amod[j] = a[j] % (2*T);
		rep(j, n)	bmod[j] = b[j] % (2*T);
		sort(all(bmod));
		int cnt = 0;
		rep(j, n) {
			if (amod[j] & (1 << i)) {
				// ooxxxxxxoo
				cnt += lower_bound(all(bmod), 2*T - amod[j]) - bmod.begin();
				cnt += bmod.end() - lower_bound(all(bmod), (3*T - amod[j]));
			}
			else {
				// xxxxoooooxx
				auto s = lower_bound(all(bmod), T - amod[j]);
				auto t = lower_bound(all(bmod), 2*T - amod[j]);
				cnt += t - s;
			}
		}
		ret ^= ((cnt & 1) << i);
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3328
//Inbornhandsome
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define endl '\n'
#define int long long

const int N = 3007;
string s, t;
int m, n, cache[N][N];

int LCS(int a, int b)
{
    if(a == m || b == n) 
    return 0;

    int &ans = cache[a][b];
    if(ans != -1)
    return ans;

    if(s[a] == t[b]) 
        ans = 1 + LCS(a+1, b+1);
    else 
        ans = max(LCS(a+1, b), LCS(a, b+1));

    return ans;
}

void path(int a, int b)
{
    if(a == m || b == n) return;

    int ans = LCS(a, b);

    if(s[a] == t[b]) {
        cout << s[a];
        return path(a+1, b+1);
    }
    
    if(ans == LCS(a+1, b))  return path(a+1, b);
    else return path(a, b+1);
}

int32_t main()
{
    IOS;// FIO;
    memset(cache, -1, sizeof(cache));
    cin >> s >> t;
    m = s.length(), n = t.length();
    int path_len = LCS(0, 0);
    path(0, 0);
    return 0;
}

Measured memory_bytes: 71168
import java.io.*;
import java.io.IOException;
import java.util.*;


@SuppressWarnings({"rawtypes", "unchecked"})
class Main {
    final static int INF = 1 << 28;
    final static long LNF = 1L << 60;
    final static double EPS = 1e-9;
    final static double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

    static final long MOD = 1_000_000_007;

    public static void main(String[] args) throws Exception {
        final MyScanner sc = new MyScanner();
        long K;
        K = sc.nextLong();
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();
        solve(K, A, B);
    }

    static void solve(long K, long A, long B){
        long p = A; 
        while(p <= B) {
            if(p % K == 0) {
                System.out.println("OK");
                return;
            };
            p++;
        }
        System.out.println("NG");
    }


    static class MyScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
 
        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String next() {
            return nn();
        }

        String nextLine() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }
 
        char nextChar() {
            return nn().charAt(0);
        }
 
        int nextInt() {
            return Integer.parseInt(nn());
        }
 
        long nextLong() {
            return Long.parseLong(nn());
        }
 
        double nextDouble() {
            return Double.parseDouble(nn());
        }
 
        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
 
        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
    }

}


Measured memory_bytes: 32640
#include <iostream>

using namespace std;

int main(){
  int a,b,k;
  cin >> a >> b >>k;
  for ( int i = 1 ; i<= k; i++){
	if ( i % 2 == 1){
      if( a % 2 == 0){
        a = a/2;
        b += a;
      }
      else{
        a = (a-1)/2; 
        b += a;
      }
    }
    else{
      if ( b % 2 == 0){
        b = b/2;
        a += b;
      }
      else{
        b = (b-1)/2;
        a += b;
      }
    }
  }
  cout << a << " "<< b << endl;
  return 0;
}
        

Measured memory_bytes: 256
fn main() {
    let (n, m) = read_tuple();
    let mut num: Vec<Option<u8>> = vec![None; n];
    let mut ans = true;

    for _ in 0..m {
        let (s, c) = read_tuple::<u8>();
        num[(s-1) as usize] = match num[(s-1) as usize] {
            Some(v) => {
                if v == c {
                    Some(c)
                } else {
                    ans = false;
                    None
                }
            },
            None => {
                Some(c)
            }
        };
    }

    if ans && (n > 1 && num[0] != Some(0)) {
        if num[0].is_none() {
            num[0] = Some(1);
        }
        let mut x = 0;
        for (i, s) in num.iter().enumerate() {
            x += 10_i32.pow((n - i - 1) as u32) * s.or(Some(0)).unwrap() as i32;
        }
        println!("{:?}", x);
    } else if ans && n == 1 {
        println!("{}", num[0].or(Some(0)).unwrap());
    } else {
        println!("-1");
    }


}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second

int main() {

   int arr[3];
   
   for(int i=0;i<3;++i)
      cin>>arr[i];
      
    sort(arr,arr+3);
    
    cout<<(arr[1]-arr[0])+(arr[2]-arr[1]);
   
	return 0;
}

Measured memory_bytes: 256
n, k = map(int,input().split())

dice_num = 1

def get_prob(dice_num,k):
    i = 0
    while True:
        i += 1
        if i ==1:
            score = dice_num
        else:
            score *= 2
        if score >= k:
            prob = (1/2)**(i-1)
            break
    return prob

prob_all = 0
for i in range(n):
    prob_all += (get_prob(i+1,k))*(1/n)

print(prob_all)

Measured memory_bytes: 68572
#include <bits/stdc++.h>
using namespace std;
long long fac[2001000], finv[2001000], inv[2001000]; 
long long MOD = 1000000007;  
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 2000500; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long 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] % MOD) % MOD;
}
long long total(int a, int b){
	return (COM(a + b + 2, a + 1) + MOD - 1) % MOD; 
}
int main(){
	int R1, C1, R2, C2; 
	cin >> R1 >> C1 >> R2 >> C2; 
	COMinit(); 
	long long ans = (MOD * 2 + total(R2, C2) - total(R2, C1-1) - total(R1-1, C2) + total(R1-1, C1-1)) % MOD; 
	cout << ans << endl; 
}

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

int main() 
{
    int a, p;
    cin >> a >> p;

    int ans = (3*a + p) /2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
nokori = 0
for i in range(N):
    ans += min(A[i],B[i])
    nokori = max(0, B[i]-A[i])
    ans += min(A[i+1] , nokori)
    A[i+1] = max(0, A[i+1]-nokori)
print(ans)

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

using namespace std;

int N, ans, cA, cB;
bool any;
string s;

int main()
{
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        cin >> s;
        int len = s.length();
        for (int j = 0; j + 1 < len; j++)
            if (s[j] == 'A' && s[j + 1] == 'B') ans++;
        if (s[0] == 'B') cB++;
        if (s[len - 1] == 'A') cA++;
        if ((s[0] == 'B') ^ (s[len - 1] == 'A')) any = true;
    }
    ans += max(0, std::min(cA, cB) - (any ? 0 : 1));
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(long i=0;i<(n);i++)
long gcd(long a,long b){
    return b?gcd(b,a%b):a;
}
long n,m,a,b,c,ans=0;
int main(){
    cin>>n>>m;
    cout<<(n*3+m)/2<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long
int main() {

	int n, m;
	scanf("%d%d", &n, &m);
	char arr[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> arr[i][j];
	for (int i = 0; i < n; i++) {
		bool flag = 0;
		for (int j = 0; j < m && !flag; j++) {
			if (arr[i][j] == '#') {
				flag = 1;
			}
		}
		for (int j = 0; j < m && !flag; j++) {
			arr[i][j] = '1';
		}
	}

	for (int i = 0; i < m; i++) {
		bool flag = 0;
		for (int j = 0; j < n && !flag; j++) {
			if (arr[j][i] == '#')
				flag = 1;
		}
		for (int j = 0; j < n && !flag; j++) {
			arr[j][i] = '1';
		}
	}


	for (int i = 0; i < n; i++) {
		bool flag = 0;
		for (int j = 0; j < m; j++)
			if (arr[i][j] != '1') {
				flag = 1;
				cout << arr[i][j];
			}

		if (flag)
			cout << endl;
	}

}


Measured memory_bytes: 3760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  ull a, b, c;
  cin >> a >> b >> c;

  if (c + b > a) {
    cout << c + b - a << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


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

using namespace std;
//using namespace __gnu_pbds;

#define ll  long long
#define PR  pair<int, int>

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> f(n + 5, 1);
    for (int i = 2; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            f[j]++;
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        ans += (i * f[i]);
    }
    cout << ans << '\n';
    return 0;
}


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

int main(){
  int n,k,r,s,p;
  cin >>n>>k>>r>>s>>p;
  string t;
  cin >>t;
  int point=0;
  for (int i=0;i<n;i++){
    if(i<=k-1){
      if(t.at(i)=='r'){
        point+=p;
      }
      if(t.at(i)=='s'){
        point+=r;
      }
      if(t.at(i)=='p'){
        point+=s;
      }
    }
    else{
      if(i>k-1 && t.at(i)!=t.at(i-k)){
        if(t.at(i)=='r'){
        point+=p;
      }
      if(t.at(i)=='s'){
        point+=r;
      }
      if(t.at(i)=='p'){
        point+=s;
      }
      }
      else{t.at(i)='x';}
    }
  }
  
  cout <<point <<endl;
}



Measured memory_bytes: 512
import java.util.Scanner;
class Main {
	public static void main(String[] args){
		String[] str = new String[2];
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()){
			str = sc.nextLine().split(" ");
			System.out.println(Integer.valueOf(str[0])+Integer.valueOf(str[1]));
		}
	}
}

Measured memory_bytes: 17452
// AOJ DSL-DSL_2_H Range Query - RMQ and RAQ
// 2019.3.27 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {
		c = gc();
		do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) ob[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

#define MAX (1<<17) //segment tree のサイズ。この実装では2べきにする必要がある
#define MIN(a, b)  ((a)<=(b)?(a):(b))
#define INF  0x1fffffff

int segMin[2*MAX], segAdd[2*MAX];

// 区間[a, b)に値xを加算する
// int k = 0, int l = 0, int r = MAX
void add(int a, int b, int x, int k, int l, int r)
{
	if (r <= a || b <= l) return;    //もし交差しない区間であれば終える.

	if (a <= l && r <= b) { // もし今みている区間[l, r)が[a, b)に完全に内包されていれば
		segAdd[k] += x;     // 区間[l, r)にkを加算
		return;
	}

	add(a, b, x, (k<<1) + 1, l, (l+r) >> 1);  // 子の区間に(必要があれば)xを加算する.
	add(a, b, x, (k<<1) + 2, (l+r) >> 1, r);  // 〃

	//親の区間の最小値は, 子の区間の最小値 + 自分に一様に加算されている値である.一様に加算される値は更新しなくて良い.
	segMin[k] = MIN(segMin[(k<<1) + 1] + segAdd[(k<<1) + 1], segMin[(k<<1) + 2] + segAdd[(k<<1) + 2]);
}

//  int k = 0, int l = 0, int r = MAX
int getMin(int a, int b, int k, int l, int r)
{
	int le, ri;

	if (r <= a || b <= l) return INF;
	if (a <= l && r <= b) return segMin[k] + segAdd[k]; // 完全に内包されていれば,その区間の最小値を返す.

	le = getMin(a, b, (k<<1)+1, l, (l+r) >> 1);   // 子の区間の最小値を求める.
	ri = getMin(a, b, (k<<1)+2, (l+r) >> 1, r);   // 子の区間の最小値を求める

	return MIN(le, ri) + segAdd[k]; // 親の区間の最小値は, 子の区間の最小値 + 自分に一様に加算されている値
}

int main()
{
	int N, Q;
	int cmd, s, t, x;

	N = in(), Q = in();
	while (Q--) {
		cmd = in(), s = in(), t = in() + 1;
		if (cmd == 0) {
			x = in();
			add(s, t, x, 0, 0, MAX);
		}
		else out(getMin(s, t, 0, 0, MAX));
	}
}


Measured memory_bytes: 2736
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main(void)
{
	int W, H, x, y, r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if ((W >= x + r && 0 <= x - r) && (H >= y + r && 0 <= y - r)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 1012
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define taskname "A"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 3e2 + 5;
const int maxm = 1e7 + 5;

const int mod = 1e9 + 7;
string s;

int n , k , dp[maxn][maxn][maxn];
int cal(int l , int r , int k){
    if(l > r)return 0;
    if(l == r)return 1;
    int & res = dp[l][r][k];
    if(res != -1)return res;
    res = 0;
    res = max(cal(l+1,r,k),cal(l,r-1,k));
    if(s[l]==s[r])res = max(res,cal(l+1,r-1,k)+2);
    if(k > 0)res = max(res,cal(l+1,r-1,k-1)+2);
    return res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP" , "r"))
        freopen(taskname".INP","r",stdin),
        freopen(taskname".OUT","w",stdout);
    cin >> s >> k;memset(dp,-1,sizeof dp);
    cout << cal(0,(int)s.size()-1,k);
}


Measured memory_bytes: 111104
#include<iostream>
#include<complex>
#include<vector>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
typedef complex<double> Point;

double eps = 1e-9;
bool eq(double a,double b){ return (abs(a-b) < eps); };

int n,m,x,y,px,py;
 
double calc(Point a,Point b,Point p){
  p-=a;
  b-=a;
  Point rb=conj(b);
  rb/=abs(rb);
  p*=rb;
  if(real(p)<0){
    return abs(p);
  }else if(real(p)>abs(b)){
    return abs(p-Point(abs(b),0));
  }else{
    return abs(imag(p));
  }
}

void update(vector<double> &dist,vector<Point> &pos,Point a,Point b){
  rep(i,n){
    dist[i]=min(dist[i],calc(a,b,pos[i]));
  }
}

int main(){
  cin>>n>>m;
  n++;
  vector<Point> pos(n);
  vector<double> dist(n);
  
  for(int i=0;i<n;i++){
    cin>>px>>py;
    pos[i]=Point(px,py);
  }

  for(int i=0;i<n;i++){
    dist[i]=abs(pos[0]-pos[i]);
  }

  bool check[10000]={};
  check[0]=true;
  
  double s=1e9,ans=0;
  int nextid,fromid;
  
  for(int z=0;z<m;z++){

    s=1e9;
    rep(i,n)if(check[i]==false && s>dist[i])s=dist[i];    
    rep(i,n)if(check[i]==false && eq(s,dist[i]) ){nextid=i;break;}
    

    double mini=1e9;
    rep(j,n)if(check[j])mini=min(mini,abs(pos[nextid]-pos[j]));
    rep(j,n)if(check[j])if( eq(mini,abs(pos[nextid]-pos[j])) ){
        fromid=j;
        break;
      }

    ans+=abs(pos[fromid]-pos[nextid]);
    update(dist,pos,pos[fromid],pos[nextid]);
    
    check[nextid]=true;
  }
  
  printf("%.8f\n",ans);
  return 0;
}

Measured memory_bytes: 1380
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int n,m;
  cin >> n >> m;
  if(n>m){
    cout << "safe" << endl;
  }
  else {
    cout << "unsafe" << endl;
  }


return 0;
}
///....


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

ll gcd(ll a,ll b){
  if(a < b) return gcd(b, a);
    int r;
    while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){

  ll a,b,k;
  cin >> a >> b >> k;

  ll d=gcd(a,b);
  vector<ll> v;
  for(int i=1;i<d+1;i++)if(d%i==0)v.push_back(i);

  cout << v[v.size()-k] << endl;

}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a,a+n);
    int f=0;
    for(int i=0;i<n-1;i++)
        if(a[i]==a[i+1])
        {
            f=1;
            break;
        }
    if(f==0)
        cout << "YES";
    else
        cout << "NO";

    return 0;
}


Measured memory_bytes: 1024
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rep1n(i, n) for(int i=1;i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
int main() {

	int n;
	cin >> n;
	ll ans = 1;
	rep(i, n) {
		ans = (ans*(i + 1)) % ((ll)1e9 + 7);
	}
	cout << ans;
	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
using namespace std;
signed main(){
	string a;
	cin >> a;
	if(a[0]==a[1] && a[1] == a[2]){
		cout << "Yes" << endl;
	}
	else if(a[2]==a[3] && a[1] == a[2]){
		cout << "Yes" << endl;
	}else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vll a(n);rep(i,n)cin>>a[i];
    ll ans=(ll)0;int r=0;ll sum=(ll)0;
    rep(i,n){
        while(r<n&&(sum^a[r])==(sum+a[r])){
            sum+=a[r];
            r++;
        }
        ans+=r-i;
        sum-=a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
 
using namespace std ;
 
typedef tree<pair<pll,lli>,null_type,less<pair<pll,lli>>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
 
#define MAXN 200000

lli permute(vll v,lli p[],lli q[],lli n) 
{ 
    // Sort the string in lexicographically 
    // ascennding order 
    // Keep printing next permutation while there 
    // is next permutation 
    lli cnt1=-1,cnt2=-1,cnt=0;
    do { 
    	cnt++;
    	lli flag1=1,flag2=1;
       	loopl(i,0,n)
       	{
       		if(p[i]!=v[i])
       			flag1=0;
       	}

       	loopl(i,0,n)
       	{
       		if(q[i]!=v[i])
       			flag2=0;
       	}

       	if(flag1 == 1) cnt1 = cnt;
       	if(flag2 == 1) cnt2 = cnt;
       	
    } while (next_permutation(v.begin(), v.end())); 

    cout<<abs(cnt1-cnt2)<<endl;
} 

int main () 
{
/////////////////////////////////////
    
 
/////////////////////////////////////  
	
	lli n;
	cin>>n;

	lli p[n],q[n];
	loopl(i,0,n) cin>>p[i];
	loopl(i,0,n) cin>>q[i];

	vll v;
	loopl(i,1,n+1) v.pb(i);

	permute(v,p,q,n);


}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include <numeric>
#include<cmath>
#include<string>
using namespace std;
#define ll long long

int main(void){
    string a;
    cin >> a;
    bool flag = true;
    for(int i=0;i<a.length()-1;i++){
        if(a[i]==a[i+1]){
            cout << "Bad"<<endl;
            flag = false;
            break;
        }
    }
    if(flag == true){
        cout << "Good"<<endl;
    }
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define INF2 1000000000000000000
#define int long long
int mod = 0;
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
    mod = M;
    string S; cin >> S;
	int A[200010];
	rep(i, N) {
        A[i] = ((S[N - i - 1] - '0') * power(10, i)) % mod;
    }
    if (mod % 2 == 0 || mod % 5 == 0) {
        int ans = 0;
        int cnt = 0;
        rep(i, N) {
            int num = S[N - i - 1] - '0';
            if (num % mod == 0) cnt++;
            ans += cnt;
        }
        cout << ans << endl;
        return 0;
    }
	map<int, int> mp;
	int ans = 0;
	int sum[N + 1] = {};
	rep(i, N) {
		sum[i + 1] = sum[i] + A[i];
		mp[sum[i + 1] % M]++;
		if (sum[i + 1] % M == 0) ans++;
	}
	rep(i, N) {
        int tmp = mp[sum[i + 1] % M];
        ans += tmp * (tmp - 1) / 2;
        mp[sum[i + 1] % M] = 0;
    }
	cout << ans << endl;



    return 0;
}


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

pair<ll, ll> calc(ll n)
{
    ll sq = (ll)ceill(sqrtl(n));

    for(ll i = sq; i>0; i--)
    {
        if(n%i == 0)
        {
            return make_pair(i, n/i);
        }
    }
    return make_pair(0, 0);
}

int main()
{
    ll n;
    cin >> n;

    pair<ll, ll> ij = calc(n);

    cout << ij.first + ij.second - 2 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
    int res = a % MOD;
    if(res < 0) {
        return res + MOD;
    }
    return res;
}
int mul_mod(int a, int b)
{
    ll res = ((ll)a * (ll)b) % MOD;
    return mod((int)res);
}
int pow_mod(int a, int b)
{
    ll res = 1;
    while (b > 0) {
        if(b & 1) {
            res = res * (ll)a % (ll)MOD;
        }
        a = mul_mod(a, a);
        b >>= 1;
    }
    return (int)res;
}
int inv_mod(int a)
{
    return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
    return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 3000001;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < FAC_MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll com_mod(int a, int b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}


int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    ll ans = 0;
    rep (i, k, n + 2) {
        ll x = mod(1 + mul_mod(i, n - i + 1));
        ans = mod(ans + x);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;

const int N=1e6+5;
int n,cnt[26];
string s[N];

struct Tnode
{
    int sum[26];
    int child[26];
    int P;
};

Tnode Trie[N];
int nT=0;
int root;

int AddNode()
{
    nT++;
    for(int i=0;i<26;i++)
    {
        Trie[nT].child[i]=0;
        Trie[nT].sum[i]=0;
    }
    Trie[nT].P=0;
    return nT;
}

void AddWord(string s)
{
    memset(cnt,0,sizeof cnt);
    int r=root;
    for(int i=0;i<s.size();i++)
    {
        int k=s[i]-'a';
        int l;
        if (Trie[r].child[k]==0)
        {
            l=AddNode();
            Trie[r].child[k]=l;
            Trie[l].P=r;
        }
        r=Trie[r].child[k];
    }
    int cur=s.size()-1;
    while (r!=root)
    {
        r=Trie[r].P;
        if(cnt[s[cur]-'a']==0) cnt[s[cur]-'a']++;
        for(int i=0;i<26;i++) Trie[r].sum[i]+=cnt[i];
        cur--;
    }
}

void solve()
{
    cin>>n;
    vector<pii>order;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        order.push_back(mp(s[i].size(),i));
    }
    sort(order.rbegin(),order.rend());
    long long res=0;
    for(int i=0;i<n;i++)
    {
        string t=s[order[i].se];
        reverse(t.begin(),t.end());
        int cur=0;
        bool kt=true;
        for(int j=0;j<t.size()-1;j++)
        {
            if(!Trie[cur].child[t[j]-'a'])
            {
                kt=false;
                break;
            }
            cur=Trie[cur].child[t[j]-'a'];
        }
        if(kt)
        {
            int val=t.back()-'a';
            res+=1ll*Trie[cur].sum[val];
        }
        AddWord(t);
    }
    cout<<res;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    /*int t;
    cin>>t;
    while(t--)*/
        solve();
}


Measured memory_bytes: 242612
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "No" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  998244353
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll dp[310][90010];
ll modpow(ll a, ll n=MOD-2, ll mod=MOD){ // a^n % MOD の計算
    ll res = 1;
    while (n > 0){
        if(n & 1) res = res * a % mod;
        a = a * a  % mod;
        n >>= 1;
    }
    return res;
}
ll dp2[310][90100];
//--MAIN-----------------------------------
void Main(){
    ll N; cin>>N;
    vector<ll> A(N);
    ll sum=0;
    rep(i,N) {cin>>A[i]; sum+=A[i];}
    dp[0][0]=1;
    rep(i,N){
        rep(j,90005){
            (dp[i+1][j]+=dp[i][j]*2)%=MOD;
            if(j+A[i]<90003) (dp[i+1][j+A[i]]+=dp[i][j])%=MOD;
        }
    }
    ll ans=modpow(3,N);
    reps(i,(sum+1)/2,sum+1){
        ans-=(dp[N][i]*3)%MOD;
        (ans+=MOD)%=MOD;
    }
    if(sum%2==0){
        dp2[0][0]=1;
        rep(i,N){
            rep(j,90005){
                (dp2[i+1][j]+=dp2[i][j])%=MOD;
                if(j+A[i]<90003) (dp2[i+1][j+A[i]]+=dp2[i][j])%=MOD;
            }
        }
        ans+=dp2[N][sum/2]*3;
        ans%=MOD;
    }
    cout<< ans <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 425600
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  ll res = 0;
  ll maxv = 1;
  while(true){
    res++;
    maxv *= k;
    if(maxv > n) break;
  }
  cout << res << endl;

}


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


typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
/*--------------------------------------------*/

int main(){
 //cout.precision(10);
 cin.tie(0);
 ios::sync_with_stdio(false);
  
  int a,b,c,d;
  cin >> a >> b >> c >>d;
  
  cout << (a == c?0:1) << endl;
  

}


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

int n, k;
int a[100055];
int d[100055];
bool used[100055];
bool in[100055];
vector<int> rg[100055];
int tail[100055];

void dfs(int v, int dep = 0) {
	d[v] = dep;
	used[v] = true;

	for (auto u : rg[v]) {
		if (used[u]) continue;
		dfs(u, dep + 1);
	}
}
int rdfs(int v) {
	used[v] = true;

	int res = 0;

	for (auto u : rg[v]) {
		if (!used[u]) {
			res = max(res, rdfs(u) + 1);
		}
	}

	return res;
}
int go(int v, int &res) {
	int ret = 0;

	for (auto u : rg[v]) {
		ret = max(ret, go(u, res) + 1);
	}

	if (ret + 1 == k) {
		if (a[v] != 0) res++;
		return -1;
	}

	return ret;
}
int main() {
	scanf("%d %d", &n, &k);

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

		rg[a[i]].push_back(i);
	}

	dfs(0);

	int res = a[0] != 0;

	memset(used, false, sizeof(used));

	vector<int> cycle;

	int cur = 0;

	while (!used[cur]) {
		cycle.push_back(cur);
		used[cur] = in[cur] = true;
		cur = a[cur];
	}

	cur = 0;

	reverse(cycle.begin(), cycle.end());

	for (auto v : cycle) {
		cur++;

		if (v == 0) cur = 0;

		bool flag = false;

		if (v == 0) flag = true;
		
		if (cur > k) {
			flag = true;
			cur = 1;
		}
			
		for (auto u : rg[v]) {
			if (!in[u]) {
				int ret = go(u, res) + 1;
				if (ret + cur > k && flag) {
					res++;
				}  else if (ret + cur > k) {
					if (ret + 1 <= k) {
						flag = true;
						cur = 1;
					}
					else res++;
				}
			}
		}
		
		if (flag && v) {
			res++;
			cur = 1;
		}
	}

	printf("%d\n", res);

	return 0;
}

Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

//int f[105][15];
//int p[105][15];

int main(){
    int n;
    cin >> n;
    vector<vector<int>> f(n, vector<int>(10));
    vector<vector<int>> p(n, vector<int>(11));
    rep(i, n) {
        rep(j, 10) {
            cin >> f[i][j];
//            scanf("%d", &f[i][j]);
        }
    }
    rep(i, n) {
        rep(j, 11) {
            cin >> p[i][j];
//            scanf("%d", &p[i][j]);
        }
    }
    int risan = -1000000005;
    for ( int i = 1; i < 1<<10; ++i ) {
        int coba = 0;
        rep(j, n) {
            int ada = 0;
            rep(k, 10) if ( i & (1<<k)) ada += f[j][k];
            coba += p[j][ada];
        }
        risan = max(risan, coba);
    }
    cout << risan << endl;
    return 0;
}


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

void printA(int A[],int c)
{
    for (int i=0;i<c;i++){
        cout << A[i];
        if(i<(c-1)) cout << " ";
    }
    cout << endl;
}

int main()
{
    int c,key,j;
    cin >> c;

    int A[1000];
    for (int i=0; i<c; i++) {
        cin >> A[i];
    }
    printA(A,c);
    for (int i=1;i<c;i++)
    {
        key = A[i];
        j = i - 1;

        A[j+1]=key;
        
        while (j>=0 && A[j]>key)
        {
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=key;
        printA(A,c);
    }    
    return 0;
}


Measured memory_bytes: 3112