akhauriyash/Code-Regression huggingface dataset:
/*********************
*  Author: xuziyuan  * 
*********************/
 
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <LL,LL>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
LL n,m,x,y,re[60],ans=0;
vector <pii> g[60];
vector <LL> pass;
bool ok;
 
void dfs(LL pos,LL to,LL no)
{
  if(pos==to)
  {
    ok=true;
    return;
  }
  rep(i,g[pos].size())
  {
    if(g[pos][i].fi==no) continue;
    pass.pb(g[pos][i].se);
    dfs(g[pos][i].fi,to,pos);
    if(ok) return;
    pass.pop_back();
  }
}
 
int main()
{
  cin>>n;
  rep(i,n-1)
  {
    cin>>x>>y;
    g[x].pb(mpr(y,i));
    g[y].pb(mpr(x,i));
  }
  cin>>m;
  rep(i,m)
  {
    cin>>x>>y;
    ok=false;
    dfs(x,y,0);
    rep(j,pass.size()) re[i]|=(LL)pow(2,pass[j]);
    pass.clear();
  }
  repn(i,(1<<m)-1)
  {
    LL cnt=0,now=0;
    rep(j,m)
    {
      if((i&(1<<j))==0) continue;
      now|=re[j];
      cnt++;
    }
    LL c=0;
    while(now>0)
    {
      c+=now%2;
      now/=2;
    }
    if(cnt&1) ans+=(LL)pow(2,n-1-c);
    else ans-=(LL)pow(2,n-1-c);
  }
  cout<<(LL)pow(2,n-1)-ans<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <random>

using namespace std;

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

int main()
{
	int N;
	cin >> N;
	vector<int> P(N * N);
	for (auto& x : P) {
		cin >> x;
		--x;
	}

	vector<vector<bool>> f(N, vector<bool>(N));
	vector<vector<int>> d(N, vector<int>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			f[i][j] = true;
			d[i][j] = min({ i, j, N - 1 - i, N - 1 - j });
		}
	}

	long long ans = 0;
	for (int pos : P) {
		int r = pos / N;
		int c = pos % N;

		ans += d[r][c];
		f[r][c] = false;

		queue<int> q;
		q.push(r);
		q.push(c);
		q.push(d[r][c]);
		while (!q.empty()) {
			int y = q.front(); q.pop();
			int x = q.front(); q.pop();
			int c = q.front(); q.pop();
			for (int k = 0; k < 4; ++k) {
				int y2 = y + dy[k];
				int x2 = x + dx[k];
				if (0 <= y2 && y2 < N && 0 <= x2 && x2 < N) {
					int c2 = c + (f[y][x] ? 1 : 0);
					if (d[y2][x2] > c2) {
						d[y2][x2] = c2;
						q.push(y2);
						q.push(x2);
						q.push(c2);
					}
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5376
N = int(input())
dic = {}
s = []
for _ in range(N):
   s.append(input())

for i in s:
    if i in dic.keys():
        dic[i] += 1
    else:
        dic[i] = 1
result = []
num = 0
for i in dic.keys():
    if dic[i] > num:
        result = []
        result.append(i)
        num = dic[i]
    elif dic[i] == num:
        result.append(i)
result.sort()
for i in result:
    print(i)

Measured memory_bytes: 35216
#include <iostream>

 

using namespace std;

 

int main() 
{
    int i, a, b, T;
    for(i=1; i<=3000; i++)
    {
        cin >> a >> b;
        //Swap a & b
        if(a == 0 && b == 0)
        break;
        if(a > b) 
        {
           T = b;
           b = a;
           a = T;
        }
    
    
    
    
    cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 3096
#include <stdio.h>
#include <math.h>
#define rep(i,n) for(int i=0; i<n; i++)

int main() {
	int N,M,i,j,ans=0;
	scanf("%d%d", &N,&M);
	int s[M]={};
	int c[M]={};
	for(i=0;i<M;i++){
		scanf("%d%d", &s[i],&c[i]);
	}
	for(i=0;i<M;i++){
		if(s[i]==1){
			if(c[i]==0){
				if(N!=1){
					printf("-1\n");
					return 0;				
				}
			}
		}
	}
	for(i=0;i<M;i++){
		for(j=i+1;j<M;j++){
			if(s[i]==s[j]){
				if(c[i]!=c[j]){
					printf("-1\n");
					return 0;
				}else{
					s[j]=0;
					c[j]=0;
				}
			}
		}
	}
    bool ok=false;
    if(N>=2){
        rep(i,M){
            if(s[i]==1){
                ok=true;
            }
        }
    }
    if(ok==true){
        for(i=0;i<M;i++){
            ans+=pow(10,N-s[i])*c[i];
        }
    }else{
        if(N==2){
            ans+=10;
        }
        if(N==3){
            ans+=100;
        }
        for(i=0;i<M;i++){
            ans+=pow(10,N-s[i])*c[i];
        }
    }
	printf("%d\n", ans);
	return 0;
}


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

ll mod = 1e9+7;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

vector<ll> fact;
vector<ll> invfact;

void set_fact(int n){
    fact.resize(n+1, 1);
    invfact.resize(n+1, 1);
    for (int i = 2; i <= n; i++) {
        fact[i] = fact[i-1] * i % mod;
    }
    invfact[n] = modinv(fact[n]);
    for (int i = n-1; i >= 2; i--) {
        invfact[i] = invfact[i+1] * (i+1) % mod;
    }
    return;
}

ll comb(int n, int k) {
    if (k > n || k < 0) return 0;
    if (k == n || k == 0) return 1;
    return fact[n] * invfact[n-k] % mod * invfact[k] % mod;
}
int main(){
    ll n, k;
    cin >> n >> k;
    set_fact(200010);
    
    ll ans = 1;
    for (ll i = 1; i <= min(n-1, k); i++) {
        ans += comb(n, i) * comb(n-1, n-i-1) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

bool ip[50001];
int table[50002];
vector<int> vec;

int main() {

    for(int i=0;i<50001;i++){
        ip[i] = true;
    }

    ip[0] = ip[1] = false;

    table[0] = table[1] = 0;

    for(int i=2;i<=50001;i++){
        table[i] = 0;
        if(ip[i]){
            vec.push_back(i);
            for(int j = 2*i;j<=50001;j+=i){
                ip[j] = false;
            }
        }
    }

    int s = vec.size();

    for(int i=0;i<s;i++){
        for(int j=i;j<s;j++){
            if(vec[i]+vec[j] <= 50000) {
                table[vec[i] + vec[j]]++;
            }
        }
    }



    while(1){
        int n;

        cin >> n;

        if(n==0) break;

        cout << table[n] << endl;

    }

    return 0;
}

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

int main () {

  int a,b;
  int d,r;
  float f;

  cin >> a >> b;
  cout << a/b << " " << a%b << " " << fixed << setprecision(5) << (1.0 * a)/ static_cast<float>(b) << endl;

  return 0;
}



Measured memory_bytes: 3272
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
#include <utility>
#include <vector>
#include <math.h>

#define rep(i, n) for (auto i = 0; i < (n); i++)
#define MOD 1e9 + 7
typedef long long ll;

using namespace std;

int main() {
  int n;
  cin >> n;
  if (n % 1000 == 0)
    cout << 0 << endl;
  else
    cout << (1000 - (n % 1000)) << endl;

  return 0;
}



Measured memory_bytes: 3188
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
s = [input() for i in range(n)]
a = [[0]*26 for i in range(n)]

for i in range(n):
        for j in range(len(s[i])):
                a[i][ord(s[i][j])-ord('a')] += 1

ans = ""
for j in range(26):
        ans += chr(ord('a')+j)*min(a[i][j] for i in range(n))

print(ans)

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


void solve(long long X){
    long long n = 100;
    int ans = 0;
    while (n < X) {
        n *= 1.01;
        ans++;
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define maxn 200005

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
int ans,n,a[maxn],b[maxn],c[maxn],d[maxn*2],r,k,x,y;

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++) scanf("%d",&a[i]);
    for (int i=0;i<n;i++) scanf("%d",&b[i]);
    for (int i=0;i<30;i++)
    {
        r=(1<<(i+1)); k=0;
        for (int j=0;j<n;j++) c[j]=a[j]%r,d[j]=b[j]%r,d[j]^=(r-1);
        sort(c,c+n); sort(d,d+n);
        for (int j=0;j<n;j++) d[j+n]=d[j]+r;
        x=0; y=0; int j=0;
        if (d[0]>r/2) while (j<n&&c[j]+r/2<d[0]) j++;
        if (j==n) continue;
        while (y<n*2&&d[y]-c[j]<r/2) y++;
        while (x<n*2&&d[x]<c[j]) x++;
        k=(y-x)&1;
        for (j++;j<n;j++)
        {
            while (x<n&&d[x]<c[j]) x++;
            while (y<n*2&&d[y]-c[j]<r/2) y++;
            k^=(y-x)&1;
        }
        if (k) ans|=(r/2);
    }
    cout << ans << endl;
}



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

#define y1 aklsdja
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define pb push_back
#define t top()
#define fr front()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , x) for(int i = 0 ; i < x ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define oo 1e17 + 5
#define ll long long
#define int long long
#define pow poww

const int N = 1e2 + 5;
const int VAL = 1e5 + 5;
int n , W;
int w[N] , v[N];
int dp[N][VAL];

main()
{
    //freopen("E.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> W;
    FOR(i , 1 , n)
        cin >> w[i] >> v[i];
    memset(dp , 0x1f , sizeof(dp));
    dp[0][0] = 0;
    FOR(i , 1 , n)
    {
        FOR(j , 0 , 1e5)
        {
            dp[i][j] = dp[i - 1][j];
            if(j >= v[i])
                dp[i][j] = min(dp[i][j] , dp[i - 1][j - v[i]] + w[i]);
        }
    }
    FORD(j , 1e5 , 0)
        if(dp[n][j] <= W)
        {
            cout << j;
            exit(0);
        }
}


Measured memory_bytes: 82304
package main

import (
	"fmt"
)

func main() {
	var o, e string
	fmt.Scan(&o, &e)
	
	ocnt,ecnt := 0, 0
	for i := 0; i < len(o)+len(e); i++ {
		if i % 2 == 0 {
        	fmt.Printf("%v",string(o[ocnt]))
			ocnt++
		} else {
        	fmt.Printf("%v",string(e[ecnt]))
			ecnt++
		}
	}
}

Measured memory_bytes: 512
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)


def dfs(v, p, ccc, links, ans):
    ret_colors = defaultdict(int)
    ret_count = 1
    cv = ccc[v]
    for u in links[v]:
        if u == p:
            continue
        sub_colors, sub_count = dfs(u, v, ccc, links, ans)
        cc = sub_count - sub_colors[cv]
        ans[cv] -= cc * (cc + 1) // 2
        ret_count += sub_count

        if len(ret_colors) < len(sub_colors):
            ret_colors, sub_colors = sub_colors, ret_colors

        for c, cnt in sub_colors.items():
            ret_colors[c] += cnt

    ret_colors[cv] = ret_count

    return ret_colors, ret_count


def solve(n, ccc, links):
    if n == 1:
        return [1]

    all_pair = n * (n + 1) // 2
    ans = [all_pair] * (n + 1)

    colors, count = dfs(0, -1, ccc, links, ans)
    assert count == n

    for c in range(1, n + 1):
        cc = n - colors[c]
        ans[c] -= cc * (cc + 1) // 2

    return ans[1:]


n, *cab = map(int, sys.stdin.buffer.read().split())
ccc = cab[:n]
links = [set() for _ in range(n)]

for a, b in zip(cab[n + 0::2], cab[n + 1::2]):
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)

print('\n'.join(map(str, solve(n, ccc, links))))


Measured memory_bytes: 336288
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[][] graph = new int[n][n];
      String[] vInfo;
      int degree;

      for(int i=0,v=0; i<n; i++) {
        vInfo = br.readLine().split(" ");
        degree = Integer.parseInt(vInfo[1]);
        for(int j=0,k=2; j<degree; j++) {
          v = Integer.parseInt(vInfo[k++]);
          graph[i][v-1] = 1;
        }
      }

      StringBuilder buf = new StringBuilder(n*n*2);
      for (int[] vertex : graph) {
        for (int v : vertex) {
          buf.append(v).append(" ");
        }
        buf.setLength(buf.length()-1);
        buf.append("\n");
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.out.println("IOException!");
    }
  }
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

/*template*/

int main() {
	ll N, K; cin >> N >> K;
	ll a[100000] = { };
	rep(i, 0, N)cin >> a[i];

	if (N == K) {
		cout << 1 << endl;
		return 0;
	}

	ll x = (N - K) / (K - 1) + 1;
	if ((N - 1) % (K - 1) != 0)x++;
	cout << x << endl;

	return 0;
}

Measured memory_bytes: 1024
n = int(input())
A = []
for i in range(n):
    a, b = map(int, input().split())
    A.append([a + b, a, b])
A.sort(reverse = True)

ans = 0
for i in range(n):
    if i % 2 == 0:
        ans += A[i][1]
    else:
        ans -= A[i][2]
        
print(ans)

Measured memory_bytes: 23260
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl


using ll = long long;
const ll mod = LLONG_MAX;

string s;
int alpha[30];
int main(){
  bool flag=true;
  cin>>s;
  for(int i=0;i<s.size();i++){
    alpha[s[i]-'a']++;
  }
  for(int i=0;i<s.size();i++){
    if(alpha[i]>1){
      flag=false;
    }
  }
  if(flag)cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}


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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int dijkstra(vector<pair<int, int>> *adj, int s, int t, int N, int L) {
    pair<int, int> d[N+1]; // p, step, ene
    for(int i=0; i<N+1; i++) d[i] = make_pair(-1, -1);
    d[s] = make_pair(0, L);

    queue<int> q;
    q.push(s);

    int p, step, ene, next, cost;
    while(!q.empty()) {
        p = q.front();
        q.pop();

        if(d[t].first != -1 && d[p].first >= d[t].first) continue;

        step = d[p].first;
        ene = d[p].second;

        for(auto n: adj[p]) {
            next = n.first;
            cost = n.second;
            if(cost> L) continue;
            if(ene < cost) {
                if(d[next].first == -1 || (step+1 < d[next].first) || (step+1 == d[next].first && L-cost > d[next].second)) {
                    d[next] = make_pair(step+1, L-cost);
                    q.push(next);
                }
            } else {
                if(d[next].first == -1 || (step < d[next].first) || (step == d[next].first && ene-cost > d[next].second)) {
                    d[next] = make_pair(step, ene-cost);
                    q.push(next);
                }
            }
        }
    }
    return d[t].first;
}

int main() {
    int N, M, L, Q;
    cin >> N >> M >> L;

    int a, b, c;
    vector<pair<int, int>> adj[N+1]; // town, cost

    for(int i=0; i<M; i++) {
        cin >> a >> b >> c;
        adj[a].emplace_back(make_pair(b, c));
        adj[b].emplace_back(make_pair(a, c));
    }

    cin >> Q;

    pair<int, int> query[Q];
    int s, t;
    for(int i=0; i<Q; i++) {
        cin >> s >> t;
        query[i] = make_pair(s, t);
    }

    map<set<int>, int> dp;
    for(int i=0; i<Q; i++) {
        set<int> st{query[i].first, query[i].second};
        auto it = dp.find(st);
        if(it != dp.end()) cout << it->second << endl;
        else {
            int ans = dijkstra(adj, query[i].first, query[i].second, N, L);
            dp[st] = ans;
            cout << ans << endl;
        }
    }


    return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

ans = set()
def rec(i, S):
    if S in ans:
        return
    if i == N:
        ans.add(S)
        return
    for c in S:
        rec(i+1, S+c)
    if i == 0:
        rec(i+1, 'a')
    else:
        li = sorted(S)
        rec(i+1, S+chr(ord(li[-1])+1))
rec(0, '')
ans = sorted(ans)
[print(s) for s in ans]


Measured memory_bytes: 15852
// template {{{

#include <bits/stdc++.h>
using namespace std;

#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second

using ll = long long;
using ull = unsigned long long;

template<typename T, size_t H, size_t W>
using matrix = std::array<std::array<T, W>, H>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

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

template<typename T>
inline T sq(T x){ return x * x; }

template<typename T, typename U>
inline void chmax(T &x, U y){ x = std::max<T>(x, y); }

template<typename T, typename U>
inline void chmin(T &x, U y){ x = std::min<T>(x, y); }

template<typename T>
inline void sort(T &c){ std::sort(std::begin(c), std::end(c)); }

template<typename T>
inline void reverse(T &c){ std::reverse(std::begin(c), std::end(c)); }

template<typename T>
inline void unique(T &c){ std::sort(c); c.erase(std::unique(std::begin(c), std::end(c))); }

// }}}

int n, m;
double l;
double p[100], t[100], v[100];
double a[100][60], b[100][60];
double dp[60][60];

double calc(int i, int j, double p)
{
	if (i == 0) return j == 0 ? 1.0 : 0.0;
	if (dp[i][j] > -1.0) return dp[i][j];
	double vl = p * calc(i - 1, j - 1, p);
	double vr = (1.0 - p) * calc(i - 1, j, p);
	return dp[i][j] = vl + vr;
}

int main()
{
	cin >> n >> m >> l;
	rep(i, n){
		cin >> p[i] >> t[i] >> v[i];
		p[i] /= 100;
	}

	rep(i, n){
		fill_n(*dp, 60 * 60, -1.0);
		rep(j, m + 1) a[i][j] = calc(m, j, p[i]);
		rep(j, m + 1) b[i][j] = l / v[i] + t[i] * j;
	}

	rep(i, n){
		double s = 0.0;
		rep(j, m + 1){
			double t = 1.0;
			rep(x, n){
				if (i == x) continue;
				double u = 0.0;
				rep(y, m + 1){
					if (b[i][j] < b[x][y] - 1e-8){
						u += a[x][y];
					}
				}
				t *= u;
			}
			s += t * a[i][j];
		}
		printf("%.20f\n", s);
	}
}

Measured memory_bytes: 3344
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <queue>

using namespace std;

typedef unsigned long long ll;


int main() {

    int r, D, x2;
    cin >> r >> D >> x2;

    vector<int> arr (11);
    arr[0] = x2;

    for(int i = 1; i < 11; i++)
    {
        arr[i] = r*arr[i-1] - D;
        cout << arr[i] << endl;
    }

}

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

int main() {
  int N, m; cin >> N >> m;
  vector<int> F(N+1, 1);
  for(int i = 0; i < m; ++i) {
    int c, d; cin >> c >> d;
    for(int j = c; j < d; ++j) F[j] = 3;
  }
  cout << accumulate(F.begin(), F.end(), 0) << endl;
  return 0;
}

Measured memory_bytes: 1200
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

//#define DEBUG
#ifdef DEBUG
    #define IFD(...) __VA_ARGS__
    #define IFN(...)
    #define L cout<<__LINE__<<"\n";
    #define PRINT(...) __VA_ARGS__ cout<<__LINE__<<" : "<<#__VA_ARGS__<<"\n"
    #define PRT(x) cout<<__LINE__<<" : "<<#x<<" = "<<x<<"\n"
#else // DEBUG
    #define IFD(...)
    #define IFN(...) __VA_ARGS__
    #define L
    #define PRINT(...) __VA_ARGS__
    #define PRT(x)
#endif // DEBUG

#define it iterator
#define rit reverse_iterator
#define mp make_pair
#define mems(a,b) memset(a,b,sizeof(a))
#define mem0(a) mems(a,0)
#define mem1(a) mems(a,1)
#define mem255(a) mems(a,255)
#define halt(s) cout<<s,exit(0)IFD(,cout<<"\n\nTIME: "<<runtime<<" sec\n\n")
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front
#define fort0(i,a,b) for(ll i=a,i##_TO=b;i<i##_TO;i++)
#define for0(i,n) fort0(i,0,n)
#define fort1(i,a,b) for(ll i=a,i##_TO=b;i<=i##_TO;i++)
#define for1(i,n) fort1(i,1,n)
#define ford(i,a,b) for(ll i=a,i##_TO=b;i>=i##_TO;i--)
#define loop(n) for0(LOOP_COUNTER,n)
#define runtime (clock()*1.0/CLOCKS_PER_SEC)
#define x first
#define y second

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define int ll

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

template
<
    class key,
    class val=null_type, /// null_mapped_type
    class comp=less<key>
>
using ord_set=tree /// find_by_order(), order_of_key()
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

typedef trie
<
    string,
    null_type,
    trie_string_access_traits<>,
    pat_trie_tag,
    trie_prefix_search_node_update
>
pref_trie; /// insert(), prefix_range()

template<class T,class U>
ostream&operator<<(ostream&out,pair<T,U> p)
{
    return out<<"("<<p.x<<","<<p.y<<")";
}

template<class Iter>
struct rng
{
    Iter from,to;
    rng(Iter from,Iter to):from(from),to(to){}
};

template<class Iter>
rng<Iter> range(Iter from,Iter to)
{
    return rng<Iter>(from,to);
}

template<class Iter>
ostream&operator<<(ostream&out,rng<Iter> r)
{
    out<<distance(r.from,r.to)<<":";
    for(Iter i=r.from;i!=r.to;i++)
        out<<" "<<*i;
    return out;
}

ll ppow(ll x,ll y,ll mod)
{
    ll res=1;
    while(y)
    {
        if(y&1)
            res=res*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return res;
}

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

    int n;
    cin>>n;
    int s=-n;
    loop(n)
    {
        int t;
        cin>>t;
        s+=t;
    }
    cout<<s<<"\n";

    IFD(cout<<"\n\nTIME: "<<runtime<<" sec\n\n";)
}


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

#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e6 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (fat[i-1] * i) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

ll dp[maxn][2];
string s;

ll solve(int pos, int carry)
{
  if(pos == s.size())
    return carry;
  ll &ans = dp[pos][carry];
  if(ans != -1)
    return ans; 
  int val = s[pos] - '0' + carry;
  ans = 1LL << 60;
  ans = min(ans, solve(pos + 1, 1) + 10 - val);
  ans = min(ans, solve(pos + 1, 0) + val);
  return ans;
}

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

Measured memory_bytes: 82536
#!/usr/bin/perl

my ($n,$m) = map {$_ - 0} split(/\s+/o,<STDIN>);

my @d;
for(my $i=0;$i<$n;$i++){
  my @xyz1 = map {$_ - 0} split(/\s+/o,<STDIN>);
  push(@d,\@xyz1);
}

my @di_a = ([1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]);

my $max_tot = 0;
foreach my $di (@di_a){
  my @dd = ();
  for(my $i=0;$i<$n;$i++){
    push(@dd, $d[$i]->[0] * $di->[0] + $d[$i]->[1] * $di->[1] + $d[$i]->[2] * $di->[2]);
  }
  my @dd2 = sort { $b <=> $a } @dd;
  my $tot = 0;
  for(my $j=0;$j<$m;$j++){
    $tot += $dd2[$j];
  }
  $max_tot = $tot if $tot > $max_tot;
}
print "$max_tot\n";

exit(0);



Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

bool a[200],b[200];
int main(){
    int n,m;
    cin>>n>>m;
    string s[n];
    rep(i,n){
        cin>>s[i];
        rep(j,m){
            a[i]=a[i]||(s[i][j]=='#');
            b[j]=b[j]||(s[i][j]=='#');
        }
    }
    rep(i,n){
        rep(j,m){
        if(a[i]&&b[j])cout<<s[i][j];
        }
        if(a[i])cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INF 1000000000000 //10^12

int main(){
    ll x,score;
    cin >> x;
    score= (x/500*1000) + ((x%500)/5*5);
    cout << score<<endl;
}

Measured memory_bytes: 256
S = list(input())

A = []

for x in S[0::2]:
    if x in ['R', 'U', 'D']:
        A.append('Yes')
    else:
        A.append('No')

for y in S[1::2]:
    if y in ['L', 'U', 'D']:
        A.append('Yes')
    else:
        A.append('No')

# print(A)

if 'No' not in A:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
  	
  	int A, B;
  	cin >> A >> B;
  	if(A < 6){
  	    	cout << 0 << endl;
  	}else if(A < 13){
      	cout << B/2 << endl;
  	}
    else{
      	cout << B << endl; 	
    }
  
 	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void insertion_sort(int A[],int N) {
	for (int i = 1; i < N; i++) {
		int v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		for (int k = 0; k < N-1; k++) {
			cout << A[k] << " ";
		}
		cout << A[N - 1] << endl;;
	}
}
int main()
{
	int N;
	int a[100];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N - 1; i++) {
		cout << a[i] << " ";
	}
	cout << a[N - 1] << endl;
	insertion_sort(a, N);
	return 0;
}


Measured memory_bytes: 3136
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int a = GetInt();
		string s = GetString();
		Console.WriteLine(a >= 3200 ? s : "red");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
}


Measured memory_bytes: 11092
def main():
    MOD = 7 + 10**9
    S = tuple(input())
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0] += 1
    s=[1]
    for n in range(1,N):
        s.append((s[n-1]*10)%13)
    for i in range(N):
        for k in range(13):
            if S[-(i+1)] != '?':
                dp[i+1][(k+int(S[-(i+1)])*s[i])%13] += dp[i][k] 
                dp[i+1][(k+int(S[-(i+1)])*s[i])%13] %= MOD
            else:
                for l in range(10):
                    dp[i+1][(k+l*s[i])%13] += dp[i][k]
                    dp[i+1][(k+l*s[i])%13] %= MOD
    print(dp[-1][5])

if __name__ == '__main__':
    main()


Measured memory_bytes: 73948
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5+5;
int a[M][4];
int main(){
	int n;
	cin>>n;
	for(int j=0;j<n;j++){
		for(int i=0;i<3;i++){
			cin>>a[j][i];
		}
	}
	for(int i=1;i<n;i++){
		a[i][0] += max(a[i-1][1],a[i-1][2]);
		a[i][1] += max(a[i-1][2],a[i-1][0]);
		a[i][2] += max(a[i-1][0],a[i-1][1]);
	}
	cout<< max(max(a[n-1][0],a[n-1][1]),a[n-1][2]) << '\n';
	return 0;
}

Measured memory_bytes: 5084
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"

	"strconv"
	"strings"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}

func NewConsole() Console {
	return Console{bufio.NewWriter(os.Stdout)}
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

func PrintList(list []int) {
	con := NewConsole()
	defer con.Flush()
	for i := range list {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}

func Insert(m *map[string]int, key string, val int) {
	(*m)[key] = val
}
func Get(m *map[string]int, key string) int {
	v, ok := (*m)[key]
	if ok {
		return v
	} else {
		return 0
	}
}

func Delete(m *map[string]int, key string) {
	delete(*m, key)
}

func main() {
	con := NewConsole()
	defer con.Flush()

	// create list
	var n int
	fmt.Scanf("%d", &n)

	m := make(map[string]int)
	lines, _ := ReadLongLines(n)
	for i := range lines {
		args := strings.Split(lines[i], " ")
		command, _ := strconv.Atoi(args[0])

		switch command {
		case 0: //insert
			k := args[1]
			v, _ := strconv.Atoi(args[2])
			Insert(&m, k, v)
		case 1: //get
			k := args[1]
			v := Get(&m, k)
			con.Printf("%d\n", v)
		case 2: // delete
			k := args[1]
			Delete(&m, k)
			// case 3: // dump
			// 	l, _ := strconv.Atoi(args[1])
			// 	r, _ := strconv.Atoi(args[2])
			// 	result := set.Dump(l, r)
			// 	for i := range result {
			// 		con.Printf("%d\n", result[i])
			// 	}
		}

	}
}



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

int main(void){
    string s;
    cin >> s;
    int ans = 4;
    if(s=="RRS" || s=="SRR") ans = 2;
    else if(s=="RSS"||s=="SRS"||s=="SSR"||s=="RSR") ans = 1;
    else if(s=="SSS") ans = 0;
    else ans = 3;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int MAXN=305;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}int n,c,len[MAXN],id[MAXN];ll s,v,F[1<<5][MAXN];
inline ll dp(){
	memset(F,0,sizeof(F)),F[0][len[n]*n]=1;
	int r=n*c;
	Rep(i,0,c-1)Rep(j,1,n-1){
		int x=i*n+j,u=id[j]-1,nr=min(r,x+len[id[j]]*n);
		for(int k=0;k<(1<<n-1);k++)if(!(k>>u&1))
			Rep(l,x,r)if(F[k][l])F[k^(1<<u)][max(nr,l)]+=F[k][l];
	}return F[(1<<n-1)-1][r];
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),c=read();
	Rep(i,1,n)len[i]=read();
	sort(len+1,len+n+1);
	Rep(i,1,n-1)id[i]=i;
	do{s+=dp();}while(next_permutation(id+1,id+n));
	v=1;Rep(i,1,n-1)v*=i*c;printf("%.15lf",1.*s/v);
	return 0;
}




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

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
        while(a[i]%2 == 0){
            a[i] /= 2;
            cnt++; 
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100
int main(){

  int x[N],pl=0,digit_f;
  char c;

  while((c=getchar()) != '\n' ){
    if(isdigit(c)){
      if(digit_f){
	x[pl]=x[pl]*10+(c-'0');
      } else {
	x[pl]=(c-'0');
	digit_f++;
      }}
    if(isspace(c)){
      if(digit_f){
	pl++;
	digit_f=0;
      }}
    if ( c == '+' ){
      if(pl>1){
	pl--;
      }
      x[pl-1]+=x[pl];
      x[pl]=0;
    }
    if ( c == '-' ){
      if(pl>1){
	pl--;
      }
      x[pl-1]-=x[pl];
      x[pl]=0;
    }
    if ( c == '*' ){
      if(pl>1){
	pl--;
      }
      x[pl-1]*=x[pl];
      x[pl]=0;
    }
  }
  printf("%d\n",x[0]);
  return 0;
}

Measured memory_bytes: 524
n=int(input())
#Christmas if D=25, Christmas Eve if D=24, Christmas Eve Eve if D=23 and Christmas Eve Eve Eve if D=22.
if n==25:
    print('Christmas')
if n==24:
    print('Christmas Eve')
if n==23:
    print('Christmas Eve Eve')
if n==22:
    print('Christmas Eve Eve Eve')

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

int main() {
  int v, e;
  std::cin >> v >> e;
  std::vector <std::vector <int> > to(v);
  for (int i = 0; i < e; ++i) {
    int a, b;
    std::cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  std::vector <int> q;
  int fi = 0;
  q.push_back(0);
  std::vector <int> d(v, -1);
  d[0] = 0;
  std::vector <int> p(v, -1);
  while (fi < (int)q.size()) {
    int x = q[fi++];
    for (auto y: to[x]) {
      if (d[y] != -1) {
        continue;
      }
      d[y] = d[x] + 1;
      p[y] = x;
      q.push_back(y);
    }
  }
  std::cout << "Yes" << std::endl;
  for (int i = 1; i < v; ++i) {
    std::cout << p[i] + 1 << std::endl;
  }
  return 0;
}


Measured memory_bytes: 10932
X,Y = map(str,input().split())
L = ["A","B","C","D","E","F"]
for i in range(6) :
    if L[i] == X :
        lx = i
    if L[i] == Y :
        ly = i
if lx < ly :
    print("<")
elif lx > ly :
    print(">")
else :
    print("=")

    

Measured memory_bytes: 3060
#include <stdio.h>
long long t[2], a[2], b[2];
long long w, x, y, z, e, f;
long long ans;
int main() {
	scanf("%lld%lld", t, t + 1);
	scanf("%lld%lld", a, a + 1);
	scanf("%lld%lld", b, b + 1);
	if (t[0] * a[0] + t[1] * a[1] == t[0] * b[0] + t[1] * b[1]) {
		printf("infinity\n");
		return 0;
	}
	x = t[0]; y = t[1];
	if (t[0] * a[0] + t[1] * a[1] > t[0] * b[0] + t[1] * b[1]) {
		w = b[0] - a[0];
		z = b[1] - a[1];
	}
	else {
		w = a[0] - b[0];
		z = a[1] - b[1];
	}
	if (w < 0) {
		printf("0\n");
		return 0;
	}
	e = w * x + z * y;
	f = w * x;
	e = -e;
	ans = f / e * 2;
	if (f % e)ans++;
	printf("%lld\n", ans);
	//if (z < 0)printf("wa\n");
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

bool used[333333];
int mp[333333];

int main(){

	ll n;cin >> n;
	vector<ll> v(n);
	set<ll> s;
	REP(i,n){
		cin >> v[i];
		s.insert(v[i]);
	}

	if(s.size() == 1){
		if(s.count(1)){
			ll ans = 1;
			REP(i,n){
				ans *= i+1;
				ans %= MOD;
			}
			cout << ans << endl;
		}
		else{
			cout << 0 << endl;
		}
		return 0;
	}

	deque<int> deq;
	deque<int> ldeq;
	ll now = -1,pla = 0,st = -1,ans = 1,malen = 0,nlen = 0;
	bool flag = true;
	vector<pair<pair<ll,ll>,pair<ll,ll>>> seica;
	while(1){
		if(pla == st)break;
		if(v[pla] != now){
			now = v[pla];
			deq.push_back(now);
			ldeq.push_back(nlen);
			if(deq.size() > 3)deq.pop_front();
			if(ldeq.size() > 3)ldeq.pop_front();
			if(deq.size() == 3) {
				if(flag){
					st = pla;
					flag = false;
				}
				if(used[deq[1]]){
					cout << 0 << endl;
					return 0;
				}
				seica.PB(MP(MP(deq[1],ldeq[2]),MP(deq[0],deq[2])));
				used[deq[1]] = true;
				malen = max(malen,nlen);
			}
			nlen = 1;
		}
		else{
			nlen++;
		}
		pla = (pla + 1) % n;
	}
	sort(ALL(seica));
	if(seica[0].FI.FI != 1 || malen > seica[0].FI.SE){
		cout << 0 << endl;
		return 0;
	}

/*
	REP(i,seica.size()){
		cout << seica[i].FI.FI << " " << seica[i].FI.SE << " ";
		cout << seica[i].SE.FI << " " << seica[i].SE.SE << " ";
		cout << endl;
	}
*/

	deque<pair<int,int>> p_deq;
	pla = 0;
	REP(i,n){
		while(pla - i < malen){
			while(p_deq.size() && p_deq[p_deq.size()-1].FI < v[pla%n])p_deq.pop_back();
			p_deq.push_back(MP(v[pla%n],pla));
			pla++;
		}
		while(p_deq[0].SE < i)p_deq.pop_front();
		mp[p_deq[0].FI]++;
	}

	//cout << "mp" << endl;
	//REP(i,n)cout << mp[i+1] << " ";cout << endl;

	now = 0;
	pla = 0;
	for(ll i = 1;i <= n;i++){
		pla += mp[i];
		if(pla <= 0){
			cout << 0 << endl;
			return 0;
		}
		//cout << i << " " << pla << " " << endl;
		if(now < seica.size() && seica[now].FI.FI == i){
			if(i < seica[now].SE.FI && i < seica[now].SE.SE && seica[now].FI.SE != malen){
				cout << 0 << endl;
				return 0;
			}
			if(i > seica[now].SE.FI && i > seica[now].SE.SE){
				ans *= malen - seica[now].FI.SE + 1;
				ans %= MOD;
			}
			now++;
		}
		else{
			ans *= pla;
			ans %= MOD;
		}
		pla--;
		//cout << "ans is " << ans << endl;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 35432
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    string S; cin >> S;
    cout << S.substr(0, 3) << endl;
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	
	if (N % 10 == 7) {
		cout << "Yes";
		return 0;
	}


	N /= 10;
	if (N%10 == 7) {
		cout << "Yes";
		return 0;
	}

	N /= 10;
	if (N%10 == 7) {
		cout << "Yes";
		return 0;
	}

	cout << "No";

	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=20;
const int mod=1e9+7;
int n,m,q,hbit[1<<N];
int limit[N+1][N+1],dp[2][1<<N];

template <class T> inline void apadd(T &x,const T y){
	x+y<mod?x=x+y:x=x+y-mod;
}

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

void init(){
	for(int i=2; i<1<<n; ++i){
		hbit[i]=hbit[i>>1]+1;
	}
}

int main(){
#ifdef LOCAL
	//freopen("d.in","r",stdin);
#endif
	memset(limit,-1,sizeof(limit));
	n=nxi(),m=nxi(),q=nxi();
	--n;
	init();
	for(int i=1; i<=q; ++i){
		const int a=nxi(),b=nxi(),c=nxi();
		limit[a][b]=c;
	}
	dp[0][0]=1;
	for(int i=1; i<=m; ++i){
		for(int j=0; j<n; ++j){
			int p=j&1;
			memset(dp[p^1],0,sizeof(dp[p^1]));
			for(int k=0; k<1<<n; ++k){
				if(!dp[p][k]) continue;
				if((k>>j&1)==0&&limit[i][j+1]!=1){
					//apadd(dp[p^1][k],dp[p][k]);
					dp[p^1][k]=(dp[p^1][k]+dp[p][k])%mod;
				}
				if(limit[i][j+1]!=0){
					int lbit=((k>>j)&-(k>>j))<<j;
					int tgt=k^(1<<j)^lbit;
					dp[p^1][tgt]=(dp[p^1][tgt]+dp[p][k])%mod;
				}
			}
		}
		if(n&1){
			memcpy(dp[0],dp[1],sizeof(dp[1]));
		}
	}
	lint ans=0;
	for(int i=0; i<1<<n; ++i){
		ans+=dp[0][i];
	}
	printf("%lld\n",ans%mod);
	return 0;
}


Measured memory_bytes: 12544
n,q=map(int,input().split())
s=input()

lr=[list(map(int,input().split())) for _ in range(q)]

ss=[0]*(n+1)

for i in range(2,n+1):
    if s[i-2:i]=="AC":
        ss[i]=ss[i-1]+1
    else:
        ss[i] = ss[i - 1]

for i in range(q):
    print(ss[lr[i][1]] - ss[lr[i][0]])





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

int main() {
    std::string A, B;
    std::cin >> A >> B;
    
    if (A==B) std::cout << "=" << std::endl;
    else if (A<B) std::cout << "<" << std::endl;
    else std::cout << ">" << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX],color[MAX];
    
    for( int i = 0; i < n; i++ ){
        d[i] = INFTY;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    color[0] = GRAY;
    while(1){
        minv = INFTY;
        int u = -1;
        for( int i = 0; i < n; i++ ){
            if(minv > d[i] && color[i] != BLACK ){
                u = i;
                minv = d[i];
            }
        }
        if( u == -1 ) break;
        color[u] = BLACK;
        for( int v = 0; v < n; v++ ){
            if( color[v] != BLACK && M[u][v] != INFTY ){
                if( d[v] > d[u] + M[u][v] ){
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for( int i = 0; i < n; i++ ){
        cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }
}

int main(){
    cin >> n;
    for( int i = 0; i < n; i++ ){
        for( int j = 0; j < n; j++ ){
            M[i][j] = INFTY;
        }
    }
    
    int k, c, u, v;
    for( int i = 0; i < n; i++ ){
        cin >> u >> k;
        for( int j = 0; j < k; j++ ){
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    
    dijkstra();
    
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=100005;

struct edge{int to,cost;};

int n,m,s;
int d[maxn];
int qh,qt,q[maxn];
bool ok=1,inq[maxn];
vector<edge>G[maxn];

int main() {
	cin>>n>>m>>s;
	for (int i=0;i<m;i++) {
		int u,v,w; cin>>u>>v>>w;
		G[u].pb(edge{v,w});
	}
	memset(d,0x3f,sizeof(d));
	d[s]=0;
	q[qt++]=s; inq[s]=1;
	while (qh!=qt) {
		int u=q[qh++]; if (qh>=maxn) qh=0;
		inq[u]=0;
		for (edge e:G[u]) {
			if (d[e.to]>d[u]+e.cost) {
				d[e.to]=d[u]+e.cost;
				if (!inq[e.to]) {
					q[qt++]=e.to; if (qt>=maxn) qt=0;
					inq[e.to]=1;
				}
			}
		}
	}
    for (int i=0;i<n;i++) 
		if (d[i]==INF) cout<<"INF"<<'\n';
		else cout<<d[i]<<'\n';
}



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

int main(){
    int X, A, B, N;
    cin >> X >> A >> B >> N;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        if(s[0] == 'n') X += A;
        if(s[0] == 't') X += B;
        if(s[0] == 'k' || X < 0) X = 0;
    }
    cout << X << endl;
    return 0;
}



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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::string S){
    string ans="q";
    if(N%2!=0){
        cout<<"No"<<endl;
        return;
    }
    else{
    (S.substr(0,N/2)==S.substr(N/2,N/2))? ans="Yes":ans="No";
    }
    cout<<ans<<endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::cout<<std::fixed<<std::setprecision(10);//誤差小数10桁まで
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=110000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  ll n;
  cin >> n;
  UnionFind tree(MAX*2);
  vector<ll>x(n),y(n);
  rep(i,n){
    cin >> x[i] >> y[i];
    tree.merge(x[i],y[i]+MAX);
  }
  map<ll,ll>mx,my;
  rep(i,MAX)mx[tree.root(i)]++;
  for(int i=MAX;i<MAX*2;i++)my[tree.root(i)]++;
  ll ans=0;
  rep(i,MAX*2)ans+=mx[i]*my[i];
  cout << ans-n << endl;
  
}


Measured memory_bytes: 30260