akhauriyash/Code-Regression huggingface dataset:
import fractions
from functools import reduce

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_ls(num):
    return reduce(lcm, num, 1)


n = int(input())
ls = list(map(int, input().split()))

m = lcm_ls(ls)

ans = 0

for i in range(n):
    ans += m // ls[i]

print(ans % (10 ** 9 + 7))

Measured memory_bytes: 6140
# https://atcoder.jp/contests/arc097/tasks/arc097_b
# Pについてp_xとp_yでuniteしていくと、スワップできる集合が獲得できる
# 1,2,3...i...Nにできるかだが, iについてp_iとiがスワップできるかはunion-findで探せばよい


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        # 親ノードをしめす。負は自身が親ということ。
        self.parent = [-1] * N  # idxが各ノードに対応。

    def root(self, A):
        # print(A)
        # ノード番号を受け取って一番上の親ノードの番号を帰す
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])  # 経由したノードすべての親を上書き
        return self.parent[A]

    def size(self, A):
        # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
        return -self.parent[self.root(A)]

    def unite(self, A, B):
        # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
        # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
        A = self.root(A)
        B = self.root(B)

        # すでにくっついている場合
        if (A == B):
            return False

        # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
        if (self.size(A) < self.size(B)):
            A, B = B, A

        # くっつける
        self.parent[A] += self.parent[B]  # sizeの更新
        self.parent[B] = A  # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる

        return True

    def is_in_same(self, A, B):
        return self.root(A) == self.root(B)


# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right


N, M = read_ints()
P = [p - 1 for p in read_ints()]
uf = UnionFind(N)
for _ in range(M):
    x, y = read_ints()
    uf.unite(P[x - 1], P[y - 1])

ans = 0
for i in range(N):
    ans += uf.is_in_same(i, P[i])

print(ans)


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

int comp_str(string s1, int pos, string s2) {
    int ret = 0;    // 0: s2の方が順序が小さい
    int size = s2.size();
    
    for ( int ii = 0; ii < size; ii++ ) {
        if ( s1[pos + ii] < s2[ii] ) {
            ret = 1;
            break;
        } else if ( s1[pos + ii] > s2[ii] ) {
            break;
        }
    }
    return ret;
}

int main() {
    int     N, L;
    string  s = "";
    string  tmp;
    int     ret;
    int     ii, jj;
    
    cin >> N >> L;
    
    for ( ii = 0; ii < N; ii++ ) {
        cin >> tmp;
        
        for ( jj = 0; jj < ii; jj++ ) {
            ret = comp_str(s, jj * L, tmp);
            if ( ret == 0 ) {
                s = s.insert(jj * L, tmp);
                break;
            }
        }
        if ( jj == ii ) {
            s.insert(s.size(), tmp);
        }
    }

    cout << s << endl;
    
    return 0;
}


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

int main() {
	int n; cin >> n;
	map<string, int>s;
	
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		string tmp; cin >> tmp;
		sort(tmp.begin(), tmp.end());
		s[tmp]++;
		ans += s[tmp] - 1;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 11136
import java.util.*;


public class Main{
  public static void main(String[] arg){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int ans;

    ans = (A+B)*C/2;
    System.out.println(ans);
  }
}


Measured memory_bytes: 21716
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    
    int count = 0;
    int i;
    for(i=a;i<=b;i++){
        if(c%i == 0){
            count++;
        }
    }
    
    printf("%d\n",count);
    
    return 0;
}

Measured memory_bytes: 596
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.Aising2018
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int h = ReadInt();
            int w = ReadInt();
            Console.WriteLine((n - h + 1) * (n - w + 1));
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;
const int N=60;
bool mt[N][N],mr[5][N][N],gg[N][N],res[N][N],t[N];
int n,m,step[5],ans,v[N];
void mul(bool a[N][N],bool b[N][N])
{
    bool c[N][N],d[N][N];
    for(int i=1;i<=n;++i)
      for(int j=1;j<=n;++j) c[i][j]=a[i][j],d[i][j]=b[i][j],a[i][j]=0;
    for(int k=1;k<=n;++k)
      for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
          a[i][j]|=c[i][k]&d[k][j];
}
void mpow(int a)
{
    memset(res,0,sizeof(res));
    for(int i=1;i<=n;++i) res[i][i]=1;
    for(int i=1;i<=n;++i)
      for(int j=1;j<=n;++j)
        gg[i][j]=mt[i][j];
    for(;a;a>>=1,mul(gg,gg))
      if(a&1) mul(res,gg);
}
bool ok(int a,int b)
{
    for(int j=1;j<=n;++j)
      if(t[j]&&mr[b][a][j]) return 1;
    return 0;
}
int work()
{
    memset(t,0,sizeof(t)); t[n]=1;
    for(int i=1;i<n;++i)
    {
        int tot=0;
        for(int j=1;j<=n;++j)
          if(!t[j]&&ok(j,1)&&ok(j,2)&&ok(j,3))
          {
              if(j==1) return i;
              v[++tot]=j;
          }
        for(int j=1;j<=tot;++j) t[v[j]]=1;
    }
    return -1;
}
int main()
{
    while(scanf("%d%d%d%d%d",&n,&m,&step[1],&step[2],&step[3])!=EOF)
    {
        memset(mt,0,sizeof(mt));
        for(int i=1;i<=m;++i)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            mt[u][v]=1;
        }
        for(int i=1;i<=3;++i)
        {
            mpow(step[i]);
            for(int j=1;j<=n;++j)
              for(int k=1;k<=n;++k)
                mr[i][j][k]=res[j][k];
        }
        ans=work();
        if(ans>=0) printf("%d\n",ans);
        else printf("IMPOSSIBLE\n");
    }
    return 0;
}

Measured memory_bytes: 1220
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(N):
  cnt+=max(0, (b[i]-a[i])//2+(b[i]-a[i])%2)
if sum(b)-sum(a)<cnt:
  print('No')
  exit()

print('Yes')

Measured memory_bytes: 4596
n = int(raw_input())
id_set = set()
key_status = True
for i in range(n):
	id_set.add(raw_input())
m = int(raw_input())
for i in range(m):
	ic_id = raw_input()
	if ic_id in id_set:
		key_status = not key_status
		print "Closed" if key_status else "Opened", "by", ic_id
	else :
		print "Unknown", ic_id

Measured memory_bytes: 4208
import heapq

n,m=map(int,input().split())
a=list(map(int,input().split()))
a=list(map(lambda x: int(x)*(-1) , a))
heapq.heapify(a)
for i in range(m):
  x=heapq.heappop(a)*(-1)
  heapq.heappush(a,-1*(x//2))
print(-sum(a))


Measured memory_bytes: 14180
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int a;
  cin >> a;
  int ans = 8 - (a - 400) / 200;
  cout << ans << endl;
}


Measured memory_bytes: 3652
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<pair<bool,int>> H(N,make_pair(false,0));

  string ans="Yes";
  for(int i=0;i<N;++i) cin >> H.at(i).second;
  for(int i=N-1;i>0;--i){
    if(H.at(i).second>=H.at(i-1).second) continue;
    else if(H.at(i-1).second-H.at(i).second!=1){
      ans="No";
      break;
    }
    else{
      H.at(i-1).second--;
      H.at(i-1).first=true;
    }
  }

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


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

string s;
int n, pos;
bool vis[27];

int main() {
	cin>>s;
	n = s.size();
	if(s == "zyxwvutsrqponmlkjihgfedcba") {
		cout<<-1<<endl;
		return 0;
	}
	if(n < 26) {
		for(int i = 0; i < n; i++)
			vis[s[i] - 'a' + 1] = 1;
		cout<<s;
		for(int i = 1; i <= 26; i++) 
			if(!vis[i]) {
				cout<<(char) (i + 'a' - 1)<<endl;
				return 0;
			}
	}
	for(int i = 25; i >= 0; i--) {
		vis[s[i] - 'a' + 1] = 1;
		for(int j = s[i] - 'a' + 2; j <= 26; j++)
			if(vis[j]) {
				for(int k = 0; k < i; k++)
					cout<<s[k];
				cout<<(char) (j + 'a' - 1)<<endl;
				return 0;
			}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int cntBlack(vector<vector<char>> vec, int h, int w,set<int> row,set<int> col){
    int ans = 0;
    for (int i = 0; i < h; i++)
    {
        if(row.count(i) == 1) continue;
        for (int j = 0; j < w; j++)
        {
            if(col.count(j) == 1) continue;
            if(vec[i][j] == '#') ans++;
        }
    }
    return ans;
}
int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<vector<char>> grid(h,vector<char>(w));
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> grid[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < 1<<h; i++)
    {
        set<int> row;
        for(int ii = 0;ii < h; ii++){
            if((i>>ii)&1) row.insert(ii);
        }
        for (int j = 0; j < 1<<w; j++)
        {
            set<int> col;
            for(int jj = 0; jj < w; jj++){
                if((j>>jj)&1) col.insert(jj);
            }            
            int cnt = cntBlack(grid,h,w,row,col);
            if(cnt == k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<double,string> a, pair<double,string> b){
	if( a.first > b.first ) return true;
	else if( a.first < b.first ) return false;
	return a.second < b.second;
}
int main(){
	int n,A,B,C,D,E,F,S,M,P;
	string name;
	
	while(cin>>n,n){
		vector< pair<double,string> > vp;
		for(int i=0; i<n; i++){
			cin>>name>>P>>A>>B>>C>>D>>E>>F>>S>>M;
			double d = (double)(F*M*S-P)/((double)A+B+C+(D+E)*M);
			vp.push_back( make_pair( d, name) );
		}
		sort(vp.begin(),vp.end(),cmp);
		for(int i=0; i<vp.size(); i++){
			cout << vp[i].second << endl;
		}
		puts("#");
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    int a = 1;
    while(1)
    {
        if(a*t %360 ==0)
            break;
        a++;
    }
    cout<<a;


}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MMST(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl;
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#define R freopen("at.in", "r", stdin);
///////////////////////////
const int N = 5 +  1e5;
int  a[N];
int n, ans;
int main() {
   
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <=n; i++) {
        cin >> a[i];
    }
    for(int i=1;i<=n+1;i++)
    {
        ans+=abs(a[i]-a[i-1]);
    }
    for(int i=1;i<=n;i++)
    {
        cout<<ans-(abs(a[i]-a[i-1])+abs(a[i]-a[i+1])-abs(a[i+1]-a[i-1]))<<endl;
    }



    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int* a = new int[100];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  cout << a[n-1]-a[0] << endl;
  return 0;
}


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

int n;
int dp[40];

int main() {
  while (cin >> n) {
    if (n == 0) break;
    for (int i=0; i<40; i++) dp[i] = 0;
    dp[0] = 1;
    dp[1] = 1;
    dp[2] = 2;
    for (int i=3; i<n+1; i++) {
      dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
    }
    cout << ceil(dp[n] / 3650.0) << "\n";
  }
  return 0;
}

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

int main() 
{
	ll N;
	cin >> N;
	vector<ll> X, Y;
	for (ll i = 0; i < N; i++) {
		ll x, y;
		cin >> x >> y;
		X.push_back(x);
		Y.push_back(y);
	}
	bool even = (X[0] + Y[0]) % 2 == 0 ? true : false;
	for (ll i = 0; i < N; i++) {
		bool e = (X[i] + Y[i]) % 2 == 0 ? true : false;
		if (even ^ e) {
			cout << -1 << "\n";
			return 0;
		}
		if (even) X[i]--;
	}
	vector<ll> sections;
	if (even) sections.push_back(1ll);
	for (ll i = 31; i >= 0; i--) {
		sections.push_back(1ll << i);
	}
	cout << sections.size() << "\n";
	for (ll len: sections) cout << len << " "; cout << "\n";
	const ll dx[] = {1ll, -1ll, 0, 0};
	const ll dy[] = {0, 0, 1ll, -1ll};
	const char dir[] = {'R', 'L', 'U', 'D'};
	for (ll i = 0; i < N; i++) {
		string ans = "";
		if (even) ans += "R";
		for (ll j = 31; j >= 0; j--) {
			ll mind = 10000000000;
			ll idx;
			for (ll k = 0; k < 4; k++) {
				ll cur = abs(X[i] - dx[k] * (1ll << j)) + abs(Y[i] - dy[k] * (1ll << j));
				if (cur < mind) {
					mind = cur;
					idx = k;
				}
			}
			X[i] = X[i] - dx[idx] * (1ll << j); 
			Y[i] = Y[i] - dy[idx] * (1ll << j);
			ans += dir[idx];
		}				
		cout << ans << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll h,w,a,b; cin >> h >> w >> a >> b;
    rep(i,h){
        ll cnt = a;
        rep(j,w){
            if(b>0){
                if(cnt>0){
                    cout << "1";
                    cnt--;
                }else{
                    cout << "0";
                }
            }else{
                if(cnt>0){
                    cout << "0";
                    cnt--;
                }else{
                    cout << "1";
                }
            }
        }
        cout << endl;
        b--;
    }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define u first
#define ty second
#define mp make_pair
#define pb push_back
#define enum(i,x,y) for(int i=(x);i<=(y);++i)
#define try(i,x,y) for(int i=(x);i>=(y);--i)
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=200005;

int n,f1[MAXN],f2[MAXN];
char s[MAXN];

int main()
{
	int ans=0,cur=0;
	scanf("%s",s+1);n=strlen(s+1);
	f1[1]=f2[2]=1;
	if(s[1]!=s[2])f1[2]=2;
	f2[1]=-(1<<30);
	enum(i,3,n)
	{
		f2[i]=f1[i-2]+1;
		if(s[i]!=s[i-2] || s[i-1]!=s[i-3])chkmax(f2[i],f2[i-2]+1);
		f1[i]=f2[i-1]+1;
		if(s[i]!=s[i-1])chkmax(f1[i],f1[i-1]+1);
	}
	printf("%d\n",max(f1[n],f2[n]));
    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n;
ll bag;
map<ll, vector<ll>> mp; // weight -> value

ll ans;

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &bag);

  for (int i = 0; i < n; ++i) {
    ll w, v;
    scanf("%lld %lld", &w, &v);
    mp[w].push_back(v);
  }

  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    sort((itr->second).begin(), (itr->second).end(), greater<ll>());
  }

  queue<pair<ll, ll>> last_que; // weight, value
  queue<pair<ll, ll>> cur_que; // weight, value

  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    ll key_weight = itr->first;
    auto values = itr->second;

    ll cur_weight = 0LL;
    ll cur_value = 0LL;

    vector<pair<ll, ll>> cur_acc_weight_values;

    cur_acc_weight_values.push_back(make_pair(cur_weight, cur_value));

    for (auto e: values) {
      cur_weight += key_weight;
      cur_value += e;
      cur_acc_weight_values.push_back(make_pair(cur_weight, cur_value));
    }

    if (last_que.empty()) {
      for (auto e: cur_acc_weight_values) {
        cur_que.push(e);
      }
    }
    else {
      while (!last_que.empty()) {
        auto last_front = last_que.front();
        last_que.pop();

        ll last_weight = last_front.first;
        ll last_value = last_front.second;

        for (auto e: cur_acc_weight_values) {
          cur_que.push(make_pair(last_weight + e.first, last_value + e.second));
        }
      }
    }

    last_que = cur_que;
    cur_que = queue<pair<ll, ll>>();
  }

  ans = -1;

  while (!last_que.empty()) {
    auto last_front = last_que.front();
    if (last_front.first <= bag) {
      ans = max(ans, last_front.second);
    }
    last_que.pop();
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 15248
#include<iostream>
#include<algorithm>
 
using namespace std;
typedef long long Int;
#define INF (1LL<<60)
#define rep(i,n) for(Int (i)=0;(i)<(n);(i)++)
Int dp[20][54000];
Int table[54000];
Int A[5][500];

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

	Int N;
	cin >> N;

	rep(i,N) cin >>A[0][i];
	rep(i,N) cin >>A[1][i];

	rep(i,N){
		if (i == 0){
			dp[0][i] = A[0][i];
			continue;
		}
		dp[0][i] = dp[0][i-1]+A[0][i];
	}

	rep(i,N){
		if (i == 0){
			dp[1][i] = dp[0][i] + A[1][i];
			continue;
		}
		dp[1][i] = max(dp[0][i],dp[1][i-1])+A[1][i];
	}

	cout << dp[1][N-1] <<endl;
	return 0;
}

Measured memory_bytes: 256
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
t = [int(input()) for i in range(d)]
contest_types = 26


# 最後にコンテストを行った日
last_days = {}
for c_type in range(contest_types):
    last_days[c_type] = 0


ans = 0
for i in range(d):
    day = i + 1
    c_type = t[i] - 1
    ans += s[i][c_type]

    last_days[c_type] = day
    for c_type in range(contest_types):
        ans -= c[c_type] * (day - last_days[c_type])
        
    print(ans)

Measured memory_bytes: 74388
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    d = defaultdict(lambda : [])
    for i in range(n):
        a,b = input().split()
        b = int(b)
        d[a].append(b)
    for i in d.keys():
        d[i].sort()
    m = I()
    s = 0
    for i in range(m):
        o = input()
        if not d[o]:
            print("No")
            return
        j = bisect.bisect_right(d[o],s)
        if j == len(d[o]):
            print("No")
            return
        s = d[o][j]
    print("Yes")
    return

#Solve
if __name__ == "__main__":
    solve()



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


string s;

void read() {
    cin >> s;
}


void work() {
    for (int i = 3; i >= 0; --i) {
        if (s.find(string(i, 'R')) != string::npos) {
                cout << i << endl;
                return;
            }
    }
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 3672
using System;
using System.Data;
using System.Globalization;

namespace HandV
{
	class Program
	{

		private int h;
		private int w;
		private int k;

		static void Main(string[] args)
		{
			Program p = new Program();

			p.HandV();

		}

		private void HandV()
		{
			string str = Console.ReadLine();
			string[] strs = str.Split(' ');

			h = int.Parse(strs[0]);
			w = int.Parse(strs[1]);
			k = int.Parse(strs[2]);

			int[,] initField = new int[h, w];

			for (int row = 0; row < h; row++)
			{
				str = Console.ReadLine();
				for (int col = 0; col < w; col++)
				{
					initField[row, col] = ((str[col] == '.') ? 0 : 1);

				}
			}

			
			int rtnCount = 0;
			
			for (int i = 0; i < Math.Pow(2, h); i++)
			{
				for (int j = 0; j < Math.Pow(2, w); j++)
				{
					int[,] field = (int[,])initField.Clone();

					for (int row = 0; row < h; row++)
					{
						if ((i & (1 << row)) != 0)
						{
							for (int col = 0; col < w; col++)
							{
								field[row, col] = 2;
							}
						}
					}
					for (int col = 0; col < w; col++)
					{
						if ((j & (1 << col)) != 0)
						{
							for (int row = 0; row < h; row++)
							{
								field[row, col] = 2;
							}
						}
					}

					//Console.WriteLine("{0}, {1}", i, j);
					//for (int row = 0; row < h; row++)
					//{
					//	for (int col = 0; col < w; col++)
					//	{
					//		Console.Write(field[row, col]);
					//	}
					//	Console.WriteLine();
					//}
					//Console.WriteLine();

					int count = 0;
					for (int row = 0; row < h; row++)
					{
						for (int col = 0; col < w; col++)
						{
							if (field[row, col] == 1) count++;
						}
					}
					if (count == k) rtnCount++;

				}
			}

			Console.WriteLine(rtnCount);
		}

	}
}


Measured memory_bytes: 28684
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::min;
using std::max;
using std::fill;

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

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

const long long MOD = 1e9 + 7;

string s;
int n;
vector<char> c;
int lefter_open[500000];
int lefter_close[500000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cin >> s;
    int counter = 0;
    for (int i = 0; i < 2 * n; i++)
    {
        if (counter % 2 == 0 && s[i] == 'B')
        {
            counter++;
            c.push_back('(');
        } else
        if (counter % 2 == 1 && s[i] == 'B')
        {
            counter--;
            c.push_back(')');
        } else
        if (counter % 2 == 0 && s[i] == 'W')
        {
            if (counter == 0)
            {
                cout << 0;
                return 0;
            }
            counter--;
            c.push_back(')');
        } else
        if (counter % 2 == 1 && s[i] == 'W')
        {
            counter++;
            c.push_back('(');
        }
    }
    if (counter != 0)
    {
        cout << 0;
        return 0;
    }
    for (int i = 0; i < 2 * n; i++)
    {
        if (i > 0) lefter_open[i] = lefter_open[i - 1];
        if (c[i] == '(') lefter_open[i]++;
    }
    for (int i = 0; i < 2 * n; i++)
    {
        if (i > 0) lefter_close[i] = lefter_close[i - 1];
        if (c[i] == ')') lefter_close[i]++;
    }
    long long ans = 1;
    for (int i = 1; i <= n; i++) ans = i * ans % MOD;
    for (int i = 0; i < 2 * n; i++)
    {
        if (c[i] == ')')
        {
            ans = ans * (lefter_open[i] - lefter_close[i] + 1) % MOD;
        }
    }
    cout << ans;
}


Measured memory_bytes: 6420
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	//入力
	ll N;
	cin >> N;
	int i, tmp_A, tmp_N_A, count, tmp_count, min_count = INF;
	for (int A = 0; A <= N; A++) {
		i = 1;
		count = 0;
		tmp_A = A;
		while (true) {
			tmp_count = (tmp_A / int(pow(6, i))) % 6;
			if (tmp_A / int(pow(6, i)) == 0) {
				break;
			}
			count += tmp_count;
			tmp_A -= tmp_count * int(pow(6, i));
			i++;
		}
		tmp_N_A = N - A;
		i = 1;
		while (true) {
			tmp_count = (tmp_N_A / int(pow(9, i))) % 9;
			if (tmp_N_A / int(pow(9, i)) == 0) {
				break;
			}
			count += tmp_count;
			tmp_N_A -= tmp_count * int(pow(9, i));
			i++;
		}

		count += (tmp_A + tmp_N_A);

		if (min_count > count) {
			min_count = count;
		}

	}
	cout << min_count;
	return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

y = 0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if 500*a+100*b+50*c == X:
        y += 1

print(y)

Measured memory_bytes: 3060
N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]

s_h = sorted(h,reverse=True)

i = 0
minD = 1000000000
while i+K <= N:
    diff = s_h[i] - s_h[i+K-1]
    minD = min(diff,minD)

    i = i + 1

print(minD)

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

public class Main {
	
    public static void main(String[] args) {
    	FastScanner sc = new FastScanner();
    	
    	int a = sc.nextInt();
    	int b = sc.nextInt();
    	int c = sc.nextInt();
    	
    	System.out.println(Math.min(b/a,c));
    	
    }
}
    

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

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

signed main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i<N ; i++){
    cin >> d.at(i);
  }
  int s = 1;
  for(int i=1; i<N ;i++){
    int sum = 0;
    for(int j=0; j<i ;j++){
      if(d.at(i) != d.at(j)){
        sum++;
      }
    }
    if (sum == i){
      s++;
    }
  }
  cout << s << endl;
}
    
    
    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  int k,n;
  cin >> k >> n;
  int edgea = 0;
  int mae = 0;
  int count = 0;
  for(int i = 0;i <= n - 1;i++){
    int num = 0;
    cin >> num;
    if(i == 0)edgea = num;
    else count = max(count,num - mae);
    if(i == n - 1)count = max(count,edgea + k - num);
    mae = num;
  }
  cout << k - count << endl;
  return 0;
}

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


int isprime(ll p)
{
	for (int i = 2; i <= sqrt(p); ++i)
	{
		if(p%i==0)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
   
  
   		int n,k;
   		cin>>n>>k;

   		int a[n];

   		for (int i = 1; i <=n; ++i)
   		{
   			cin>>a[i];
   		}

   		int dp[n];
         for (int i = 1; i <=n; ++i)
         {
            dp[i]=INT_MAX;
         }
   		dp[1]=0;
   		dp[2]=abs(a[2]-a[1]);

   		for (int i = 3; i <=n; ++i)
   		{
   			for (int j = i-1,jump=1; j >=1 && jump<=k; --j,jump++)
            {
               dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
            }

   		}

         // for (int i = 1; i <=n; ++i)
         // {
         //    cout<<dp[i]<<" ";
         // }

   		cout<<dp[n];
   	
   	
   

}



Measured memory_bytes: 1024
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        if i%2==0:
            if W%2==0:
                print(('#'+'.')*(W//2))
            else:
                print(('#'+'.')*(W//2)+'#')
        else:
            if W%2==0:
                print(('.'+'#')*(W//2))
            else:
                print(('.'+'#')*(W//2)+'.')
    print('')


Measured memory_bytes: 5608
#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

int n, k;
int niz[100100];
int memo[100100];

int rek(int i){

    if (i == n - 1)return 0;
    if (i > n - 1)return -1;
    if (memo[i] != -1)return memo[i];
    int mi = 1100000000;
    for (int j = 1; j <= k; j++){
        int rekt = rek(i + j);
        if (rekt == -1)continue;
        int x = abs(niz[i] - niz[i+j]) + rekt;
        if (x < mi)mi = x;
    }

    memo[i] = mi;
    return mi;
}

int main (){

    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> niz[i];
    }
    memset(memo, -1, sizeof memo);

    cout << rek(0) << "\n";

    return 0;
}


Measured memory_bytes: 5760
def main():
    a, b, c = map(int, input().split())
    if c - a - b < 0:
        print('No')
        return

    res = 'Yes' if 4 * a * b < (c - a - b) * (c - a - b) else 'No'
    print(res)


if __name__ == '__main__':
    main()


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

using namespace std;

const int N = 100 + 2;
const int V = 1e5 + 3;
const int64_t LINF = 1e18;

int n, w, weight[N], value[N];
int64_t dp[N][V];

int main()
{
//    freopen("input.inp", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> w;
    for (int i = 1; i <= n; ++i)
        cin >> weight[i] >> value[i];
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j < V; ++j)
            dp[i][j] = LINF;
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < V; ++j)
            if (dp[i][j] != LINF)
            {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
                if (j + value[i + 1] < V)
                    dp[i + 1][j + value[i + 1]] = min(dp[i + 1][j + value[i + 1]],
                                                      dp[i][j] + weight[i + 1]);
            }
    int ans = 0;
    for (int i = 0; i < V; ++i)
        if (dp[n][i] <= w)
            ans = i;
    cout << ans;
    return 0;
}


Measured memory_bytes: 79232
#include<cstdio>
#include<cstring>
#include<algorithm>
int a[100010];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int s=0;
        a[0]=10000;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]==i)
            {
                if(a[i-1]==i-1)
                    a[i]=i-1;
                else
                    s++;
            }
        }
        printf("%d\n",s);
    }
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vector<vector<P>> v(n);
    rep(i,m) {
        int l,r,d;
        cin >> l >> r >> d;
        l--; r--;
        v[l].emplace_back(r,d);
        v[r].emplace_back(l,-d);
    }
    vector<int> dist(n,inf);
    auto bfs = [&](int i) {
        queue<int> q;
        q.push(i);
        while(!q.empty()) {
            int now = q.front();
            q.pop();
            for(auto p : v[now]) {
                if(dist[p.first] != inf) {
                    if(dist[p.first] != dist[now]+p.second) {
                        cout << "No" << endl;
                        exit(0);
                    }
                } else {
                    dist[p.first] = dist[now]+p.second;
                    q.push(p.first);
                }
            }
        }
    };
    rep(i,n) {
        if(dist[i] != inf) continue;
        dist[i] = 0;
        bfs(i);
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 9344
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashSet;
fn main() {
    input! {
        n: usize,
        s: chars,
    }
    let mut res = 0;
    for i in 1..s.len() {
        let mut hspre = HashSet::new();
        // s[0..i].iter().map(|x| hs.insert(x));
        for c in s[0..i].iter() {
            hspre.insert(c);
        }
        let mut hssuf = HashSet::new();
        // s[0..i].iter().map(|x| hs.insert(x));
        for c in s[i..].iter() {
            hssuf.insert(c);
        }
        let count = hssuf.iter().filter(|&x| hspre.contains(x)).count();
        // println!("i={} count={}", i, count);
        res = std::cmp::max(res, count);
    }

    println!("{}", res);
}


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

int main() {
    ll k,a,b;
    cin >> k >> a >> b;
    //交換する意味なし
    if(b-a<=2){
        cout << 1+k << endl;
        return 0;
    }
    ll x = a;
    k -= a-1;
    x += (k/2) * (b-a) + k%2;
    cout << x << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
using namespace std;
typedef long long ll;
const ll MAXN=500005;
const ll M=MAXN*100;
ll n,q,tot;
ll a[MAXN];
ll T[MAXN],lson[M],rson[M],c[M];
ll build(ll l,ll r)
{
    ll root=tot++;
    c[root]=0;
    if(l!=r)
    {
        ll mid=(l+r)>>1;
        lson[root]=build(l,mid);
        rson[root]=build(mid+1,r);
    }
    return root;
}

ll update(ll root,ll pos,ll val)
{
    ll newroot=tot++,tmp=newroot;
    c[newroot]=c[root]+val;
    ll l=1,r=n;
    while(l<r)
    {
        ll mid=(l+r)>>1;
        if(pos<=mid)
        {
            lson[newroot]=tot++;
            rson[newroot]=rson[root];
            newroot=lson[newroot];
            root=lson[root];
            r=mid;
        }
        else
        {
            rson[newroot]=tot++;
            lson[newroot]=lson[root];
            newroot=rson[newroot];
            root=rson[root];
            l=mid+1;
        }
        c[newroot]=c[root]+val;
    }
    return tmp;
}

ll query(ll root,ll pos)
{
    ll ret=0;
    ll l=1,r=n;
    while(pos<r)
    {
        ll mid=(l+r)>>1;
        if(pos<=mid)
        {
            r=mid;
            root=lson[root];
        }
        else
        {
            ret+=c[lson[root]];
            root=rson[root];
            l=mid+1;
        }
    }
    return ret+c[root];
}
int main()
{
    scanf("%lld %lld",&n,&q);
    tot=0;
    for(ll i=1; i<=n; i++)
        scanf("%lld",&a[i]);
    T[n+1]=build(1,n);
    map<ll,ll> mp;
    for(ll i=n; i>=1; i--)
    {
        if(mp.find(a[i])==mp.end())
        {
            T[i]=update(T[i+1],i,1);
        }
        else
        {
            ll tmp=update(T[i+1],mp[a[i]],-1);
            T[i]=update(tmp,i,1);
        }
        mp[a[i]]=i;
    }
    while(q--)
    {
        ll l,r;
        scanf("%lld%lld",&l,&r);
        printf("%lld\n",query(T[l],r));
    }

    return 0;
}


Measured memory_bytes: 503060
import java.util.Scanner;

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

    int b;
    int capacity;
    int passedCount;
    int lastOverseasRank;

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int a = sc.nextInt();
        b = sc.nextInt();

        capacity = a + b;
        passedCount = 0;
        lastOverseasRank = 0;

        char[] s = sc.next().toCharArray();
        for (char c : s) {
            switch (c) {
            case 'a':
                processForA();
                break;
            case 'b':
                processForB();
                break;
            case 'c':
                processForC();
            }
        }
    }

    void processForA() {
        if (passedCount < capacity) {
            outputYesOrNo(true);
            passedCount++;
        } else {
            outputYesOrNo(false);
        }
    }

    void processForB() {
        lastOverseasRank++;
        if (passedCount < capacity && lastOverseasRank <= b) {
            outputYesOrNo(true);
            passedCount++;
        } else {
            outputYesOrNo(false);
        }
    }

    void processForC() {
        outputYesOrNo(false);
    }

    void outputYesOrNo(boolean isYes) {
        System.out.println(isYes ? "Yes" : "No");
    }
}


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

using namespace std;

int main(){
  int N;
  cin >> N;
 N = N % 10;
    if(N == 2 || N == 4 || N ==5 || N == 7 || N == 9)
    {
      cout << "hon" << endl;
    }if(N == 0 || N == 1 || N == 6 || N == 8)
    {
      cout << "pon" << endl;
    }
    if( N == 3)
    {
      cout << "bon" << endl;
    }
  return 0;
}


Measured memory_bytes: 3616
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
   public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		Point2D.Double a = new Point2D.Double(0.0, 0.0);
		Point2D.Double b = new Point2D.Double(100.0, 0.0);
		
		Print(a);
		kock(n, a, b);
		Print(b);
	}
	
	public static void kock(int n, Point2D.Double p1, Point2D.Double p2){
		if(n == 0){
			return;
		}
		Point2D.Double s = new Point2D.Double();
		Point2D.Double u = new Point2D.Double();
		Point2D.Double t = new Point2D.Double();
		
		double s1 = (2.0 * p1.getX() + 1.0 * p2.getX()) / 3.0;
		double s2 = (2.0 * p1.getY() + 1.0 * p2.getY()) / 3.0;
		s.setLocation(s1, s2);
		
		double t1 = (1.0 * p1.getX() + 2.0 * p2.getX()) / 3.0;
		double t2 = (1.0 * p1.getY() + 2.0 * p2.getY()) / 3.0;
		t.setLocation(t1, t2);
		
		double u1 = (t.getX() - s.getX()) * Math.cos(Math.toRadians(60)) - (t.getY() - s.getY()) * Math.sin(Math.toRadians(60)) + s.getX();
		double u2 = (t.getX() - s.getX()) * Math.sin(Math.toRadians(60)) + (t.getY() - s.getY()) * Math.cos(Math.toRadians(60)) + s.getY();
		u.setLocation(u1, u2);
		
		kock(n - 1, p1, s);
		Print(s);
		
		kock(n - 1, s, u);
		Print(u);
		
		kock(n - 1, u, t);
		Print(t);
		
		kock(n - 1, t, p2);
	}
	
	public static void Print(Point2D.Double print){
		
		System.out.println(String.format("%.8f", print.getX()) + " " + String.format("%.8f", print.getY()));
		
	}
}

Measured memory_bytes: 41904
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 100020
#define mod 1000000007
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int n,a[N],du[N],col[N],len[N],cnt[N];
ll ans=1,dp[N];
bool cir[N];
inline int calc(int l1,int l2){
    return (l1<l2)+(l1<=l2);
}
int main(){
//    freopen("a.in","r",stdin);
    n=read();for(int i=1;i<=n;++i) a[i]=read(),du[a[i]]++;
    for(int i=1;i<=n;++i){
        if(col[i]) continue;int x=i;
        for(;!col[x];x=a[x]) col[x]=i;
        if(col[x]!=i) continue;//成环了，标记下环上的点
        for(;!cir[x];x=a[x]) cir[x]=1;
    }for(int i=1;i<=n;++i) if((!cir[i]&&du[i]>1)||(cir[i]&&du[i]>2)){puts("0");return 0;}
    for(int i=1;i<=n;++i){//计算foot的长度
        if(du[i]) continue;int x=i,res=0;
        while(!cir[x]) ++res,x=a[x];len[x]=res;
    }for(int i=1;i<=n;++i){//处理基环内向树
        if(!cir[i]) continue;int x=i,fir=0,firlen=0,k=0,last=0;
        while(cir[x]){
            ++k;cir[x]=0;
            if(len[x]){
                if(!fir){fir=last=k;firlen=len[x];x=a[x];continue;}
                ans=ans*calc(len[x],k-last)%mod;if(!ans){puts("0");return 0;}last=k;
            }x=a[x];
        }if(!fir) cnt[k]++;else ans=ans*calc(firlen,fir+k-last)%mod;
    }if(!ans){puts("0");return 0;}
    for(int i=1;i<=n;++i){//处理大小为i的所有环
        if(!cnt[i]) continue;dp[0]=1;int op=(i&1)+(i>1);//奇环且大于1有两种
        for(int j=1;j<=cnt[i];++j){
            dp[j]=dp[j-1]*op%mod;
            if(j>1) dp[j]=(dp[j]+(ll)(j-1)*i*dp[j-2]%mod)%mod;
        }ans=ans*dp[cnt[i]]%mod;
    }printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n,a[200005]={0},b[200005]={0},c[200005]={0},ct[40][40]={0},ans;
    cin >> n;
    rep(i,0,n-1){
        string s;
        ll pk=0;
        bool ik=false;
        cin >> s;
        rep(j,0,s.size()-1){
            if(s[j]=='.'){
                ik=true;
            } else if(ik){
                pk++;
                a[i]=a[i]*10+(s[j]-'0');
            } else {
                a[i]=a[i]*10+(s[j]-'0');
            }
        }
        while(a[i]%2==0){
            b[i]++;
            a[i]/=2;
        }
        while(a[i]%5==0){
            c[i]++;
            a[i]/=5;
        }
        b[i]+=(9-pk);
        c[i]+=(9-pk);
      	if(b[i]>18) b[i]=18;
        if(c[i]>18) c[i]=18;
        ct[b[i]][c[i]]++;
        if(b[i]>=9&&c[i]>=9) ans--;
    }
    rep(i,0,18){
        rep(j,0,18){
            rep(k,0,18){
                rep(l,0,18){
                    if(i+k<18||j+l<18) continue;
                    ans+=(ct[i][j]*ct[k][l]);
                }
            }
        }
    }
    cout << ans/2 << endl;
    return 0;
}


Measured memory_bytes: 8284