akhauriyash/Code-Regression huggingface dataset:
#include <functional>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
#include <type_traits>
namespace loquat {
template <int MOD>
class modulus_integer {
public:
	typedef modulus_integer<MOD> self_type;
private:
	int m_value;
	static self_type unsafe_construct(int x) noexcept {
		self_type y;
		y.m_value = x;
		return y;
	}
public:
	modulus_integer() noexcept
		: m_value(0)
	{ }
	modulus_integer(int x) noexcept
		: m_value(x % MOD)
	{
		if(m_value < 0){ m_value += MOD; }
	}
	int operator*() const noexcept { return m_value; }
	self_type& operator=(const self_type& x) noexcept {
		m_value = x.m_value;
		return *this;
	}
	self_type operator+(const self_type& x) const noexcept {
		const int y = m_value + x.m_value;
		return unsafe_construct(y >= MOD ? y - MOD : y);
	}
	self_type operator*(const self_type& x) const noexcept {
		return unsafe_construct(
			static_cast<long long>(m_value) * x.m_value % MOD);
	}
	self_type& operator+=(const self_type& x) noexcept {
		return (*this = *this + x);
	}
	self_type& operator*=(const self_type& x) noexcept {
		return (*this = *this * x);
	}
};
template <int MOD>
inline std::ostream& operator<<(
	std::ostream& os, const modulus_integer<MOD>& x)
{
	os << *x;
	return os;
}
}
using namespace std;
static const int MOD = 1000000007;
using mint = loquat::modulus_integer<MOD>;
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	vector<int> b(n);
	b[0] = a[0];
	for(int i = 1; i < n; ++i){ b[i] = b[i - 1] ^ a[i]; }
	vector<int> c(n + 1);
	for(int i = 0; i < n; ++i){ c[i + 1] = c[i] + (b[i] == 0 ? 1 : 0); }
	vector<mint> dp0(1 << 20), dpx(1 << 20);
	vector<int> last(1 << 20);
	for(int i = 0; i < n; ++i){
		const int k = c[i] - c[last[b[i]]];
		dp0[b[i]] += dpx[b[i]] * k;
		dpx[b[i]] += dp0[b[i]] + 1;
		last[b[i]] = i;
	}
	mint answer = 0;
	if(b.back() == 0){
		for(int i = 1; i < (1 << 20); ++i){ answer += dpx[i]; }
		mint z = 1;
		for(int i = 1; i < c.back(); ++i){ z *= 2; }
		answer += z;
	}else{
		answer = dp0[b.back()] + 1;
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 18432
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <limits>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <iterator>
#include <functional>

using namespace std;

typedef unsigned                    ui;
typedef int                         si;
typedef long                        sl;
typedef long long                   ll;
typedef unsigned long long          ull;

#ifdef LOCALHOST
std::ifstream in("input.txt", std::ifstream::in);
#endif // LOCALHOST

#ifdef LOCALHOST
#define is in
#else
#define is cin
#endif // LOCALHOST


vector<vector<int>> graph;
vector<int> order;
vector<int> color;

void top_sort(int v) {
    if (color[v] != 0) {
        return;
    }

    // cerr << "in " << v << endl;

    color[v] = 1;
    for (int u : graph[v]) {
        top_sort(u);
    }

    color[v] = 2;

    order.push_back(v);
}

int global_length = 0;
vector<char> used;
vector<int> max_length_from;
void dfs(int v, int length) {
    if (used[v]) {
        return;
    }

    // cerr << "in " << v << " length " << length << endl;

    global_length = max(global_length, length);
    used[v] = true;
    for (int u : graph[v]) {
        dfs(u, length + 1);
        max_length_from[v] = max(max_length_from[v], max_length_from[u] + 1);
    }

    global_length = max(max_length_from[v], global_length);
}

int main(int argc, char *argv[])
{
    std::ios_base::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;

    graph.resize(n);
    for (int i = 0; i < m; ++i) {
        ll v1, v2;
        cin >> v1 >> v2;

        --v1, --v2;
        graph[v1].push_back(v2);
    }

    color.assign(n, 0);
    used.assign(n, 0);
    for (int i = 0; i < n; ++i) {
        if (color[i] != 0) {
            continue;
        }
        top_sort(i);
    }
    reverse(order.begin(), order.end());

    // cerr << "Top sort: " << endl;
    // for (int i = 0; i < order.size(); ++i) {
    //     cerr << order[i] << " ";
    // }
    // cerr << endl;

    used.assign(n, 0);
    max_length_from.assign(n, 0);

    int answer = 0;
    for (int i : order) {
        if (used[i]) {
            continue;
        }

        global_length = 0;
        dfs(i, 0);

        answer = max(answer, global_length);
        // cerr << global_length << endl;
    }

    cout << answer << endl;

    return 0;
}


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

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

    long long ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] + a[i + 1] <= x) continue;
        ans += a[i] + a[i + 1] - x;
        a[i + 1] -= a[i] + a[i + 1] - x;
        if (a[i + 1] < 0) a[i + 1] = 0;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int x=1;
    for(int i=0;i<=20;i++)
    {
        if(x>=b)
        {
            cout<<i<<endl;
            return 0;
        }
        x--;
        x+=a;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <iostream>
#include <fstream>

using namespace std;

const int DIV = 1000000007;

void solve(int test, istream &in) {
    string s, t;
    in >> s >> t;
    bool yes = true;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            yes = false;
            break;
        }
    }
    printf("%s\n", yes ? "Yes" : "No");
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
	//FILE *f = fopen("in.txt", "r");
    ifstream f("in.txt");
#else
	//FILE *f = stdin;
    istream &f = cin;
#endif
    int tests = 1;
    //f >> tests;
    for (int test = 0; test < tests; test++) {
        solve(test, f);
    }
	return 0;
}



Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		final int c = 1000005;

		int n = sc.nextInt();
		int[] a = new int[n];
		int[] cnt = new int[c];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());

			if (cnt[a[i]] != 0) {
				cnt[a[i]] = 2;
				continue;
			}
			for (int j = a[i]; j < c; j += a[i]) {
				cnt[j]++;
			}
		}

		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (cnt[a[i]] == 1)
				ans++;
		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 63580
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int DP[100005]; // BFSの際にどこから伝播してきたかを記憶
int DP1[100005]; // BFSの際にどこから伝播してきたかを記憶

int main() {
    int N;
    cin>>N;
    for(int i=0;i<N;++i){
        DP[i] = -1;
    }
    vector<vector<int> > edge(N);
    int a, b;
    for(int i=0;i<N-1;++i){
        cin>>a>>b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    queue<int> que;
    queue<int> numque;
    que.push(0);
    numque.push(0);
    DP[0] = 0;
    int state, num;
    while(!que.empty()){
        state = que.front();que.pop();
        num = numque.front();numque.pop();
        if(state==N-1){
            break;
        }
        for(int i=0;i<edge[state].size();++i){
            if(DP[edge[state][i]]>-1) continue;
            DP[edge[state][i]] = state;
            que.push(edge[state][i]);
            numque.push(num+1);
        }
    }
    while(!que.empty()) que.pop();
    state = N-1;
    num = 0;
    while(DP[state]!=state){
        DP1[state] = 1;
        que.push(state);
        state = DP[state];
        num++;
    }
    DP1[0] = 1;
    que.push(0);
    num++;
    for(int i=0;i<num/2;++i){
        que.pop();
    }
    int ans = 0;
    while(!que.empty()){
        state = que.front();que.pop();
        ans++;
        for(int i=0;i<edge[state].size();++i){
            if(DP1[edge[state][i]]>0) continue;
            DP1[edge[state][i]] = 1;
            que.push(edge[state][i]);
        }
    }
    if(ans>N/2) cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
}


Measured memory_bytes: 6912
#include <stdio.h>

int main( void )
{
	char str;
	int sum = 0;
	
	while( 1 ){
		scanf("%c", &str);
		
		if(str == '\n'){
			if(sum == 0){
				break;
			}
			else{
				printf("%d\n", sum);
				sum = 0;
			}
		}
		else{
			sum += str - '0';
		}
	}
	
	return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> p(A), q(B), r(C);
    vector<P> AL(A + B + C);

    rep(i, A) {
        cin >> p[i];
        AL[i] = P(p[i], 0);
    }
    rep(i, B) {
        cin >> q[i];
        AL[i + A] = P(q[i], 1);
    }
    rep(i, C) {
        cin >> r[i];
        AL[i + A + B] = P(r[i], 2);
    }

/*
    sort(all(p));
    reverse(all(p));
    sort(all(q));
    reverse(all(q));
    sort(all(r));
    reverse(all(r));
*/
    sort(all(AL));
    reverse(all(AL));

    ll cnt = 0, ans = 0, index = 0;
    vector<int> num(3);
    num[0] = X; num[1] = Y; num[2] = C;
    while (cnt < X + Y) {
        P p = AL[index];
        if (num[p.second] != 0) {
            num[p.second]--;
            ans += p.first;
            cnt++;
        }
        index++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3712
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;

    tuple<int, int, int> C[N];

    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        C[i] = make_tuple(a + b, a, b);
    }

    sort(C, C + N, greater<tuple<int, int, int>>());

    int ret = 0;

    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            ret += get<1>(C[i]);
        } else {
            ret -= get<2>(C[i]);
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 2560
import numpy as np
n,d=map(int,input().split())
zahyo=[0]*n
count=0

# 入力受けて多次元アレイ作成
for i in range(n):
    zahyo[i]=list(map(int,input().split()))
arr=np.array(zahyo)

# 
for i in range(n):
    for j in range(i+1,n):
        dis=sum((arr[i]-arr[j])**2)
        if (dis**0.5).is_integer():
            count+=1
print(count)


Measured memory_bytes: 21516
import sys
sys.setrecursionlimit(2*10**5+5)


def dfs(_v, _u):
  for u in v[_v]:
    if u==_u: continue;
    ans[u]+=ans[_v]
    dfs(u, _v)
        
  
def main():
  for i in range(n-1):
    a,b=map(lambda x:int(x)-1, input().split())
    v[a].append(b)
    v[b].append(a)
  
  for i in range(q):
    p,x=map(lambda x:int(x)-1, input().split())
    ans[p]+=x+1
  
  dfs(0,-1)
  
  print(*ans, sep=' ')
  
if __name__=='__main__':
  n,q=map(int,input().split())
  ans=[0]*n
  v=[[]*n for i in range(n)]
  main()

Measured memory_bytes: 234312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
const int M = 1e9+7;
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin >> n;
    vector<int> a(n);
    int sum = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans = (ans+(1LL*a[i]*sum)%M)%M;
        sum = (sum+a[i]) % M;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3996
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String in = sc.nextLine();

        if (in.equals("A")) {
            System.out.println("T");
        }
        if (in.equals("T")) {
            System.out.println("A");
        }
        if (in.equals("C")) {
            System.out.println("G");
        }
        if (in.equals("G")) {
            System.out.println("C");
        }

    }

}


Measured memory_bytes: 19796
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    for i in range(n):
        if i % 2 == 0 and A[i] % 2 != 0:
            res += 1
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9176
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>
#include <functional>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define PI 3.141592


using namespace std;

int main() {
	int N;
	cin >> N;

	cout << pow(N, 2);
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void a_expired(void) {
	int x, a, b;
	cin >> x >> a >> b;

	if (b >= (a + x + 1)) cout << "dangerous" << endl;
	else if (b > a) cout << "safe" << endl;
	else             cout << "delicious" << endl;

}

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

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,ans=0,k=0;
	cin>>n;
	cin>>k;
	for(ll i=0; i<n-1; i++){
		ll a; cin>>a;
		//cout<<k-a<<endl;
		if(k>a){
			ans+=k-a;
		}else{
			k=a;
		}
		//cout<<k;
	}
	cout<<ans<<endl;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(2*n);
  for(int i=0; i<2*n; i++) a[i]=i+1;
  while(m--) {
    int k;
    cin >> k;
    vector<int> b;
    if(k) {
      for(int i=k; i<a.size(); i++) b.push_back(a[i]);
      for(int i=0; i<k; i++) b.push_back(a[i]);
    } else {
      for(int i=0; i<n; i++) {
	b.push_back(a[i]);
	b.push_back(a[n+i]);
      }
    }
    a=b;
  }
  for(int i=0; i<a.size(); i++) {
    cout << a[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 1224
#include <stdio.h>

#define Mod 1000000007

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int i, j, N, M, S[2001], T[2001];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= N; i++) scanf("%d", &(S[i]));
	for (j = 1; j <= M; j++) scanf("%d", &(T[j]));

	list *pos[100001] = {}, d[2001];
	for (j = 1; j <= M; j++) {
		d[j].v = j;
		d[j].next = pos[T[j]];
		pos[T[j]] = &(d[j]);
	}
	
	long long dp[2][2001], tmp;
	list *p;
	for (j = 0; j <= M; j++) dp[0][j] = 1;
	for (i = 1; i <= N; i++) {
		for (j = 0; j <= M; j++) dp[i%2][j] = 0;
		for (p = pos[S[i]]; p != NULL; p = p->next) dp[i%2][p->v] += dp[1-i%2][p->v-1];
		for (j = 0, tmp = 0; j <= M; j++) {
			tmp += dp[i%2][j];
			dp[i%2][j] = (tmp + dp[1-i%2][j]) % Mod;
		}
	}
	
	printf("%lld\n", dp[N%2][M]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2592
import java.util.*;
public class Main{
    public static void main(String[]args) {
        Scanner sc = new Scanner(System.in);
        
        int max = 123456*2+1;
        
        int[] p = new int[max];
        for(int i=2; i<p.length; i++)p[i] = 1;
        for(int i=2; i<Math.sqrt(max)+1; i++){
            for(int j=i*2; j<max; j+=i){
                p[j] = 0;
            }
        }
        
        int n = sc.nextInt();
        while(n!=0){
            
            int ans = 0;
            for(int i=n+1; i<=n*2; i++){
                if(p[i]==1)ans++;
            }
            
            System.out.println(ans);
            
            n = sc.nextInt();
        }   
    }
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=1e9+7;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll solve(ll a){
    if(a<=1)return 0;
    else return 1+solve(a/2);
    }
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll h;
    cin>>h;
    ll ans=solve(h);
    ll res=pow(2,ans+1)-1;
    cout<<res<<endl;
    return 0;
    }


Measured memory_bytes: 256
import std.stdio,std.math,std.string,std.conv,std.typecons,std.format;
import std.algorithm,std.range,std.array;

T[] readarr(T=long)(){return readln.chomp.split.to!(T[]);}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}

//END OF TEMPLATE

void main(){
    long n,k;
    scan(n,k);
    min(n%k,abs(n%k-k)).writeln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define REP(i,s,N) for (int i=s;i<(N); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


ll ans=1;

int main(){
	ll N;
	cin >> N;
	char s[N];
	char s_in;
	ll D = 0;
	REP(i,0,N){
		cin >> s_in;
		s[i] = s_in;
	}
	REP(i,0,N-1){
		if(s[i]!=s[i+1]){
		ans ++;
        }
	}
	
	cout << ans << endl;

	return 0;
}

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

const int MAX_N = (int)(1e5 + 10);
const int MAX_T = (int)(2e5 + 10);

int n, cha;
int s[MAX_N], t[MAX_N], c[MAX_N];
int tab[MAX_T];
int ans[MAX_T];

int mx = -1;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &cha);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", &s[i], &t[i], &c[i]);
  }

  for (int i = 1; i <= cha; ++i) {
    fill(tab, tab + MAX_T, 0);
    for (int j = 0; j < n; ++j) {
      if (c[j] == i) {tab[2 * s[j] - 1]++; tab[2 * t[j]]--;}
    }

    for (int j = 0; j < MAX_T - 1; ++j) {tab[j + 1] += tab[j];}
    for (int j = 0; j < MAX_T; ++j) {
      if (tab[j] > 0) ans[j]++;
    }
  }

  for (int j = 0; j < MAX_T; ++j) {
    mx = max(ans[j], mx);
  }

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

  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
string s;
cin>>s;
for(int i=0;i<s.size();i++){
    if(i%2==0){
        cout<<s.at(i);
    }
}
}












Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
string s;
int ans;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(s[i]!=s[s.size()-i-1])
			s[s.size()-i-1]=s[i],ans++;
	cout<<ans;
}

Measured memory_bytes: 256
M,D = map(int, input().split())
ans = 0
for i in range(1,M+1):
  for j in range(2, D//10 + 1):
    for k in range(2, 10):
      if j*10 + k > D:
        break
      else:
        if j*k == i:
          ans += 1
print(ans)

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

int tax08(int i){
  int t;
  t = 0.08*i;
  return t;
}

int tax10(int i){
  int t;
  t = 0.1*i;
  return t;
}

int main(){
  int A,B,i;
  cin >> A >> B;
  
  for(i=0;i<1200;i++){

    if( tax08(i)==A && tax10(i)==B){
      cout << i << endl;
      break;
    }
    
  }
if(i==1200)cout << "-1" << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a;

int main() {
	cin >> n >> a;
	cout << n*n - a << ln;
}

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

using namespace std;

#define INF (1ll << 62)
#define pb push_back
#define ii pair<int,int>
#define OK cerr <<"OK"<< endl
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define endl '\n'

signed main () {
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int a, b ,c;

  cin >> a >> b >> c;

  a -= b;
  c -= a;

  cout << max(0ll, c) << endl;

}

Measured memory_bytes: 256
S = input()
N = len(S)

flag = True

for i in range(int(len(S)/2)):
  if S[i]!=S[-1-i]:
    flag = False
    break

if flag==True:
  right = int((N-1) / 2)
  subS = S[0:right]
  for i in range(int(len(subS)/2)):
    if subS[i]!=subS[-1-i]:
      flag = False
      break

if flag==True:
  left = int((N+3) / 2)
  subS = S[left-1:N]
  for i in range(int(len(subS)/2)):
    if subS[i]!=subS[-1-i]:
      flag = False
      break

if flag:
  print("Yes")
else:
  print("No")



Measured memory_bytes: 3064
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	string s,t;
	ll ans=0;
	cin >> s >> t;
	for(ll i=0;i<s.size();i++){
		if(s[i]!=t[i]){
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
string s[105];
set<string> S;
int n;
int main()
{
	cin>>n>>s[1]; S.insert(s[1]);
	bool ok=1;
	for(int i=2;i<=n;i++){
		cin>>s[i];
		if(s[i][0]!=s[i-1][s[i-1].size()-1]) ok=0;
		if(S.find(s[i])!=S.end()) ok=0;
		S.insert(s[i]);
	}
	if(ok) puts("Yes");
	else puts("No"); 
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())
a = [int(x) for x in input().split(" ")]

rate = [0 for _ in range(8)]
xx = 0

for x in a:
    if x<400:
        rate[0] += 1
    elif 400<=x and x<800:
        rate[1] += 1
    elif 800<=x and x<1200:
        rate[2] += 1
    elif 1200<=x and x<1600:
        rate[3] += 1
    elif 1600<=x and x<2000:
        rate[4] += 1
    elif 2000<=x and x<2400:
        rate[5] += 1
    elif 2400<=x and x<2800:
        rate[6] += 1
    elif 2800<=x and x<3200:
        rate[7] += 1
    else:
        xx += 1

cnt = 0
for r in rate:
    if r>0:
        cnt += 1
if xx==0:
    print(str(cnt)+" "+str(cnt))
else:
    if cnt<2:
        print("1 "+str(xx+cnt))
    else:
        print(str(cnt)+" "+str(xx+cnt))


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

int main(void) {
    int N;
    cin >> N;

    vector<int> P(N);
    for(int i=0;i<N;i++) cin >> P.at(i);

    int min, cnt=0;
    for(int i=0;i<N;i++) {
        if(i==0) {
            min=P.at(i);
            cnt++;
        }
        else {
            if(min>P.at(i)) {
                min=P.at(i);
                cnt++;
            }
            else ;
        }
    }

    cout << cnt << endl;

    return (0);
}


Measured memory_bytes: 1024
fun c97(args: Array<String>) {
    val s = args[0]
    val K = args[1].toInt()

    val strSet = mutableSetOf<String>()
    (1..K).forEach { len ->
        (0..s.length - len).forEach { start ->
            strSet.add(s.substring(start, start + len))
        }
    }

    println(strSet.sorted().drop(K - 1).first())
}

fun main(args: Array<String>) {
    c97(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 41220
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int a,b;
   cin >> a >> b;
   for (int i = 1;i < 100001;i++){
      if (i*8/100 == a && i/10 == b){
         cout << i << endl;
         return 0;
      } 
   }
   cout << -1 << endl;

   return 0; 

}


Measured memory_bytes: 256
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe\n";
    }
    else cout<<"safe\n";
}


Measured memory_bytes: 3636
//***********************************************************************************************************//
//    TOPIC :
//***********************************************************************************************************//
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define ll long long int
#define ull unsigned long long int
#define INF 99999999
ll mod = 1e9 + 7;

// int mod = 1e9 + 7;
#define fr(a, b, c) for (int a = b; a < c; a++)
#define fre(a, b, c) for (int a = b; a <= c; a++)

class Timer
{
public:
    clock_t starting;
    Timer()
    {
        cout << "**..** Timer clock init **..**" << endl;
    }
    void start()
    {
        starting = clock();
    }
    void end()
    {
        double duration = (clock() - this->starting) / (double)CLOCKS_PER_SEC;
        cout << "**..** Time taken is " << duration << endl;
    }
};

void the_martian()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
}

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll powm(ll a, ull b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

int dp[3001][3001];
vector<string> word;
int main()
{
    
    string a, b;
    cin >> a >> b;
    string l = a.length() >= b.length() ? a : b;
    string s = a.length() >= b.length() ? b : a;

    int rows = s.length(), cols = l.length();
    for (int i = 0; i <= rows; i++)
    {
        for (int j = 0; j <= cols; j++)
        {
            if (i == 0 || j == 0)
            {
                dp[i][j] = 0;
            }
            else
            {
                if (s[i - 1] == l[j - 1])
                {

                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }
                else
                {

                    if (dp[i - 1][j] < dp[i][j - 1])
                    {
                        dp[i][j] = dp[i][j - 1];
                    }
                    else
                    {
                        // cout << i << " " << j << endl;
                        dp[i][j] = dp[i - 1][j];
                    }
                }
            }
        }
    }

    int i = rows, j = cols;
    string ans = "";
    while (i > 0 && j > 0)
    {

        if (dp[i][j] == (dp[i - 1][j - 1] + 1) && (dp[i - 1][j] == dp[i][j - 1]))
        {

            ans = ans + s[i - 1];
            i = i - 1;
            j = j - 1;
        }
        else if (dp[i][j] == (dp[i][j - 1]))
        {
            i = i;
            j = j - 1;
        }
        else
        {
            i = i - 1;
            j = j;
        }
    }

    string rev_str = "";
    for (int i = ans.length() - 1; i >= 0; i--)
    {

        rev_str = rev_str + ans[i];
    }

    cout << rev_str << endl;
}

Measured memory_bytes: 35456
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
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; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
typedef pair<double,long long> pair_t;
bool comp(const pair_t& a, const pair_t& b) {
	if (a.first == b.first)return  a.second > b.second;
	else {
		return a.first > b.first;
	}
}

int main() {
	string s;
	cin >> s;
	ll cnta, cntb, cntc;
	cnta = count(all(s), 'a');
	cntb = count(all(s), 'b');
	cntc = count(all(s), 'c');
	cout << (max(cnta, max(cntb, cntc)) - min(cnta, min(cntb, cntc)) <= 1 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var x, k, d int
	fmt.Scan(&x, &k, &d)
	if x < 0 {
		x = -x
	}
	// from 0 to x
	// 0, D, 2D, 3D, ..., nD, x, (n+1)D
	n := x / d
	if k <= n {
		fmt.Println(x - k*d)
		return
	}
	if k%2 == n%2 {
		fmt.Println(x - n*d)
		return
	}
	fmt.Println((n+1)*d - x)
}


Measured memory_bytes: 1772
/*
    C - Be Together
    https://atcoder.jp/contests/abc043/tasks/arc059_a
*/

#include <iostream>

using namespace std;

#define ll long long
#define forn(i, s, n) for (int i = s; i < n; i++)
#define whilen(val, n) while(n-- && cin >> val)
#define r_1(v) cin >> v
#define r_2(v1, v2) cin >> v1 >> v2

int main() {
    int n, x, ns[101];
    r_1(n);
    int sum = 0;
    forn(i, 0, n) {
        r_1(x);
        ns[i] = x;
    }
    int min = 0;
    forn(i, -100, 101) {
        int result = 0;
        forn(j, 0, n) {
            if (i != ns[j]) result += ((ns[j] - i) * (ns[j] - i));
        }
        if (i == -100) min = result;
        else {
            if (min > result) min = result;
        }
    }
    cout << min;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

#define MAX 200000
#define INF 1e9

int main(){
  int N,a[MAX],mini[MAX],i,ans;

  scanf("%d" ,&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d" ,a + i);
  }

  mini[0] = a[0];
  ans = -INF;
  for(i = 1 ; i < N ; i++){
    ans = fmax(ans,a[i]-mini[i-1]);
    mini[i] = fmin(a[i],mini[i-1]);
  }
  printf("%d\n" ,ans);

  return 0;
}

Measured memory_bytes: 2164
N, C = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]

ans, value = 0, 0
for i in L:
    cost = i[0]
    value += i[1]
    ans = max(ans, value - cost)

value = 0
for i in L[::-1]:
    cost = C - i[0]
    value += i[1]
    ans = max(ans, value - cost)

rList = [0] * (N + 1)
value = 0
for i in range(N):
    sushi = L[i]
    cost = sushi[0]
    value += sushi[1]
    rList[i + 1] = max(rList[i], value - cost)

lList = [0] * (N + 1)
value = 0
for i in range(N):
    sushi = L[-1-i]
    cost = C - sushi[0]
    value += sushi[1]
    lList[i + 1] = max(lList[i], value - cost)

value = 0
for i in range(N):
    sushi = L[i]
    cost = sushi[0]
    value += sushi[1]
    ans = max(ans, value - cost * 2 + lList[N - (i + 1)])

value = 0
for i in range(N):
    sushi = L[-1-i]
    cost = C - sushi[0]
    value += sushi[1]
    ans = max(ans, value - cost * 2 + rList[N - (i + 1)])

print(ans)

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int main() {

  int K; cin >> K;
  rep (_, K) {
    int n, k;
    cin >> n >> k;
    if (!cin) break;
    vi xs(n);
    rep (i, n) cin >> xs[i];

    if (k == 1) {
      cout << (xs[xs.size()-1] - xs[0]) << endl;
      continue;
    }

    int ans = 0;
    vector<int>difs;
    rep (i, n - 1) {
      difs.push_back(xs[i+1] - xs[i]);
    }

    sort(all(difs));

    for (int i = 0; i < n - k; ++i) {
      ans += difs[i];
    }
    cout << ans << endl;

  }

  return 0;
}

Measured memory_bytes: 2392
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1180
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  char a;
  cin >> a;
  if(islower(a)) {
    cout << 'a' << endl;
  }
  else {
    cout << 'A' << endl;
  }
  return 0;
}


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

using namespace std;
#define X first
#define Y second
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=1e5+10;
struct edge{int nxt,to,w;}e[MAXN<<2];
ll res=0,cnt[5];bool f;
int n,m,x,y,head[MAXN],col[MAXN],tot,ne,nd;

void add(int x,int y,int w)
{e[++tot]=(edge){head[x],y,w};head[x]=tot;}
void dfs(int x)
{
	cnt[col[x]]++;nd++;
	for(int i=head[x];i;i=e[i].nxt)
	{
		ne+=(e[i].w==1);
		if(col[e[i].to]==-1)
			col[e[i].to]=(col[x]+e[i].w)%3,dfs(e[i].to);
		else if(col[e[i].to]!=(col[x]+e[i].w)%3) f=false;
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	memset(col,-1,sizeof(col));
	for(int i=1;i<=m;i++)
		scanf("%d%d",&x,&y),add(x,y,1),add(y,x,2);
	for(int i=1;i<=n;i++)
	{
		if(~col[i]) continue;
		cnt[0]=cnt[1]=cnt[2]=0;
		col[i]=0;nd=ne=0;f=true;dfs(i);
		
//		assert(nd==cnt[0]+cnt[1]+cnt[2]);
		if(!f) res+=1ll*nd*nd;
		else if(!cnt[0]||!cnt[1]||!cnt[2]) res+=ne;
		else res+=cnt[0]*cnt[1]+cnt[1]*cnt[2]+cnt[2]*cnt[0];
	}
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <cstdio>
#define MN 262144
#define mod 1000000007
using namespace std;
int H, p[MN + 5], ans, root[MN + 5], cnt;
struct Tree {
  int l, r, val, tag;
}T[MN * 18 + 5];

inline void Mark(int x, int v) {
  if (!T[x].tag) T[x].tag = 1;
  T[x].val = 1LL * T[x].val * v % mod;
  T[x].tag = 1LL * T[x].tag * v % mod;
}

inline void pushdown(int x) {
  Mark(T[x].l, T[x].tag);
  Mark(T[x].r, T[x].tag);
  T[x].tag = 0;
}

int Build(int x, int b, int val, int multiplier) {
  int k = ++cnt; 
  if (x == val) {
    T[k].val = 1LL * x * multiplier % mod;
    return k;
  }
  if (val & (1 << b)) {
    T[k].r = Build(x << 1 | 1, b - 1, val, multiplier);
    T[k].val = 1LL * T[T[k].r].val * x % mod;
  } else {
    T[k].l = Build(x << 1, b - 1, val, multiplier);
    T[k].val = 1LL * T[T[k].l].val * x % mod;
  }
  return k;
}

int Merge(int x, int y, int k, int multiplier) {
  //cout << "Merge" << x << " " << y << " " << k << endl;
  if (!x || !y) {
    int r = x + y;
    Mark(r, multiplier);
    return r;
  }
  if (T[x].tag) pushdown(x);
  if (T[y].tag) pushdown(y);
  ans = (ans + (1LL * T[T[x].l].val * T[T[y].r].val + 1LL * T[T[x].r].val * T[T[y].l].val) % mod * k % mod * multiplier) % mod;
  //cout << "MMMMM" << (1LL * T[T[x].l].val * T[T[y].r].val + 1LL * T[T[x].r].val * T[T[y].l].val) % mod * k % mod * multiplier % mod << endl;
  T[x].l = Merge(T[x].l, T[y].l, k << 1, multiplier);
  T[x].r = Merge(T[x].r, T[y].r, k << 1 | 1, multiplier);
  T[x].val = 1LL * (T[x].val + T[y].val) * multiplier % mod;
  return x;
}

void Dfs(int x) {
  if ((x << 1) >= (1 << H)) {
    root[x] = Build(1, H - 2, p[x], x);
    //cout << "root[" << x << "]=" << root[x] << endl;
    return;
  }
  Dfs(x << 1);
  Dfs(x << 1 | 1);
  root[x] = Merge(root[x << 1], root[x << 1 | 1], 1, x);
}

int main() {
  scanf("%d", &H);
  for (int i = 1 << H - 1; i < 1 << H; ++i) {
    scanf("%d", &p[i]);
    p[i] += (1 << H - 1) - 1;
  }
  Dfs(1);
  cout << ans;
  return 0;
}

Measured memory_bytes: 42148
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
deque< pair<long long,long long> >Que;
int H,T;
bool Visit[100050];
long long K;
int main(){
	scanf("%lld",&K);
	Que.push_back(make_pair(1,1));
	while(!Que.empty()){
		pair<long long,long long> Now=Que.front();
		Que.pop_front();
		if(Visit[Now.second]){
			continue;
		}
		Visit[Now.second]=1;
		
		if(Now.second%K==0){
			printf("%lld\n",Now.first);
			break;
		}
		Que.push_front(make_pair(Now.first,(Now.second*10)%K));
		Que.push_back(make_pair(Now.first+1,(Now.second+1)%K));
	}
	return 0;
	//AC!
}

Measured memory_bytes: 1920
#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 DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
ll a[L];
void fff()
{
	ll n;
	cin >> n;
	FOR(i,0,n)cin >> a[i];
	ll cur = 2, ans = a[0]-1;
	FOR(i,1,n)
	{
		a[i]--;
		ans += a[i]/cur;
		if(a[i]+1==cur)cur++;
	}
	cout<<ans<<ln;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  string S[N];
  for(int i=0;i<N;i++) cin>>S[i];
  int M;
  cin>>M;
  string T[M];
  for(int i=0;i<M;i++) cin>>T[i];
  int A[N+1]={0};
  for(int i=0;i<N;i++){
    if(S[i]!="0"){
      A[i]=1;
      for(int j=i+1;j<N;j++){
        if(S[i]==S[j]){
          A[i]++;
          S[j]="0";
        }
      }
      for(int j=0;j<M;j++){
        if(S[i]==T[j]) A[i]--;
      }
    }
  }
  sort(A,A+N+1);
  cout<<A[N]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#define FL "a"
using namespace std;
typedef long long ll;
typedef long double dd;
const int N=1e5+10;
const int mod=1e9+7;
inline ll read(){
  ll d=0,w=1;char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  if(ch=='-')w=-1,ch=getchar();
  while(ch<='9'&&ch>='0')d=d*10+ch-48,ch=getchar();
  return d*w;
}
inline void file(){
  freopen(FL".in","r",stdin);
  freopen(FL".out","w",stdout);
}

int n,X,dp[205][N],s[N],ans;
inline void upd(int &a,int b){a+=b;if(a>=mod)a-=mod;}
inline void dec(int &a,int b){a-=b;if(a<0)a+=mod;}

int main()
{
  n=read();X=read();dp[0][X]=1;
  for(int i=1;i<=n;i++)s[i]=read();
  sort(s+1,s+n+1);reverse(s+1,s+n+1);
  for(int i=0;i<n;i++)
    for(int j=0;j<=X;j++){
      upd(dp[i+1][j%s[i+1]],dp[i][j]);
      upd(dp[i+1][j],1ll*dp[i][j]*(n-i-1)%mod);
    }
  for(int j=1;j<=X;j++)upd(ans,1ll*dp[n][j]*j%mod);
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 79360
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        char[] arr=s.toCharArray();
        
        for(int i=0;i<s.length();i++) {
            if(i%2==0) {
                System.out.print(arr[i]);
            }
        }
    }
}


Measured memory_bytes: 29340
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
const int N = 10'000;
bool can[N+1][N+1];
vector<int> sticks = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
void build(int n, int d, vector<int>& a) {
    for(int x : a) {
        if(sticks[x] <= n and can[n - sticks[x]][d - 1]) {
            cout << x;
            build(n - sticks[x], d - 1, a);
            break;
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    cin >> a;
    sort(a.begin(), a.end(), greater<int>());
    can[0][0] = true;
    for(int d = 1; d <= n; d++) {
        for(int i = 1; i <= n; i++) {
            for(int x : a) {
                if(sticks[x] <= i) {
                    can[i][d] |= can[i - sticks[x]][d - 1];
                }
            }
        }
    }
    for(int d = n; d >= 0; d--) {
        if(can[n][d]) {
            build(n, d, a);
            cout << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 97920