akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>

typedef long long LL;

LL ceil(LL a, LL b) {
    if (a % b == 0) return a / b;
    return 1 + (a / b);
}

int main() {
    LL A = 1, B = 1;
    int t; std::cin >> t;
    while (t--) {
        LL a, b; std::cin >> a >> b;
        LL c = ceil(A, a);
        LL d = ceil(B, b);
        LL e = std::max(c, d);
        A = a * e;
        B = b * e;
    }
    std::cout << A + B << std::endl;
}


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

const int N = 1e3 + 5;
float h[N];


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
  
    float n,t,a;
    cin>>n>>t>>a;
    float mn = 1e9, idx = -1;
    for (int i = 0; i < n; i++){
        cin>>h[i];
        h[i] = abs(a-( t - h[i]*0.006));
        if(h[i]<mn) mn = h[i], idx = i+1;
    }
    cout<<idx<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a,v,b,w,t; cin>>a>>v>>b>>w>>t;
	if(w>v){
		cout<<"NO"<<endl;
		return 0;
	}
	else if(w==v && a!=b){
		cout<<"NO"<<endl;
	}
	else{
		ll dist = abs(a-b);
		ll dspeed = abs(v-w);
		ll time = (dist+dspeed-1)/dspeed;
		if(time > t){
			cout<<"NO"<<endl;
		}
		else{
			cout<<"YES"<<endl;
		}
	}
	return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  LL q,h,s,d,n;
  cin >> q >> h >> s >> d >> n;
  s=min(s,min(4*q,2*h));
  cout << min(s*n,n/2*d+n%2*s) << endl;
  return 0;
}


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

int main() {
  int k;
  cin >> k;
  ll ans = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        ans += __gcd(__gcd(i, j), l);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
using namespace std ;
int main()
{
    int a,b;
    cin >> a >> b ;
    for(int i=1;i<1500;i++)
    {
        double p = (double)i*.08;
        //p=floor(p);
        double q = (double)i*.1;
        //q=floor(q);
        int x = (int)p;
        int y = (int)q;
        if(x==a && y==b){cout << i << endl;return 0;}
    }
    cout << "-1" << endl;
    return 0 ;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=200100,mod=1000000007;
inline void Add(int &a,int b){a=a+b>=mod?a+b-mod:a+b;}
inline int ksm(int a,int b)
{
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) res=1ll*res*a%mod;
	return res;
}
int fac[maxn],invfac[maxn];
inline int C(int n,int m){return 1ll*fac[n]*invfac[m]%mod*invfac[n-m]%mod;}
int main()
{
	for(int i=fac[0]=1;i<maxn;i++) fac[i]=1ll*fac[i-1]*i%mod;
	invfac[maxn-1]=ksm(fac[maxn-1],mod-2);
	for(int i=maxn-2;i>=0;i--) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
	int n,a,b,c,ans=0;
	cin>>n>>a>>b>>c;
	for(int cnt=n;cnt<n+n;cnt++)
	{
		Add(ans,1ll*C(cnt-1,n-1)*(1ll*ksm(a,n)*ksm(b,cnt-n)%mod+1ll*ksm(b,n)*ksm(a,cnt-n)%mod)%mod
		*cnt%mod*100%mod*ksm(1ll*ksm(a+b,cnt)*(100-c)%mod,mod-2)%mod);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5100
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt(), G = sc.nextInt(), B = sc.nextInt(), N = sc.nextInt();

        long[] RG = new long[N + 1];
        for (int r = 0; r * R <= N; r++) for (int g = 0; g * G <= N - r * R; g++) {
                RG[r * R + g * G]++;
        }

        long ans = 0;
        for (int rg = 0; rg <= N; rg++) for (int b = 0; b * B <= N - rg; b++) {
            if (N == rg + b * B)
                ans += RG[rg];
        }
//        debug(RG);
        System.out.println(ans);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 23124
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
#define biggest(A,B) A=max(A,B)
#define smallest(A,B) A=min(A,B)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n,k;
vector<LL> pos,neg,a1,a2;
const int MOD=1e9+7;
int main(){
	fastio;
	cin>>n>>k;
	if(n==k){
		LL tmp=1;
		rb(i,1,n){
			LL ai;
			cin>>ai;
			tmp*=ai;
			tmp%=MOD;
			tmp+=MOD;
			tmp%=MOD;
		}
		cout<<tmp<<endl;
		return 0;
	}
	rb(i,1,n){
		int ai;
		cin>>ai;
		if(ai<0)
			neg.PB(-ai);
		else{
			pos.PB(ai);
		}
	}	
	sort(ALL(pos));
	sort(ALL(neg));
	reverse(ALL(pos));
	reverse(ALL(neg));
	a1=pos;
	a2=neg;
	LL tmp=1;
	rep(i,pos.size()){
		pos[i]*=tmp;
		pos[i]%=MOD;
		tmp=pos[i];
	}
	tmp=1;
	rep(i,neg.size()){
		neg[i]*=tmp;
		neg[i]%=MOD;
		tmp=neg[i];
	}
	if((k&1)&&pos.empty()){
		
	reverse(ALL(a2));
	neg=a2;
	tmp=1;
	rep(i,neg.size()){
		neg[i]*=tmp;
		neg[i]%=MOD;
		tmp=neg[i];
	}
		cout<<MOD-neg[k-1]<<endl;
		return 0;//负数 
	}
	else{
		//正数
		LL res;
		bool ok=0;
		rb(i,0,neg.size()){
			if(i&1) continue;
			if(k-i<=pos.size()){
			if(i&&ok)
			if(a2[i-1]*a2[i-2]<a1[k-i]*a1[k-i+1]) break;
			if(i==0){
				res=pos[k-1];
			}
			else
			if(k-i-1>=0){
				res=pos[k-i-1]*neg[i-1]%MOD;
			}
			else{
				res=neg[i-1];
			}
				ok=1;
			} 
		} cout<<res<<endl;
	}
	return 0;
}


Measured memory_bytes: 6388
function main()
  
  N = parse(Int,readline())
  K = parse(Int,readline())
  
  check = 1
  
  for i in 1:N
    
    if 2*check >= check + K
      check += K
    else
      check *= 2
    end
    
  end
  
  println(check)
  
end

main()

Measured memory_bytes: 111456
s=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
h=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
c=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
d=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
n=gets.to_i
n.times do
  a,b=gets.split
  b=b.to_i
  s[b]=0 if a=='S'
  h[b]=0 if a=='H'
  c[b]=0 if a=='C'
  d[b]=0 if a=='D'
end
for i in 1..13
  puts 'S '+i.to_s if s[i]>0
end
for i in 1..13
  puts 'H '+i.to_s if h[i]>0
end
for i in 1..13
  puts 'C '+i.to_s if c[i]>0
end
for i in 1..13
  puts 'D '+i.to_s if d[i]>0
end



Measured memory_bytes: 6876
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int P[15];

int main()
{
	int N;
	cin >> N;
	int max = 0;
	int sum = 0;
	REP(i, N)
	{
		cin >> P[i];
		max = std::max(max, P[i]);
		sum += P[i];
	}
	sum -= max / 2;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

ans = 0
tmp_max = 1
dp = [0]*(N+1)
for i, a in enumerate(A):
    if a <= tmp_max:
        dp[i] = tmp_max
        tmp_max = 2*(tmp_max-a)
    else:
        ans = -1
        break
if ans == -1:
    print(ans)
else:
    tmp = 0
    for i in reversed(range(N+1)):
        if tmp + A[i] >= dp[i]:
            ans += dp[i]
            tmp = dp[i]
        else:
            ans += tmp + A[i]
            tmp += A[i]
    print(ans)

Measured memory_bytes: 674380
n,a,b=list(map(int,input().split()))
s=input()
ab=a+b
total=0
foreigner=0
for i in range(n):
    if s[i]=='a':
        if total < ab:
            total+=1
            print("Yes")
        else:
            print("No")
    elif s[i]=='b':
        if total < ab and foreigner < b:
            total+=1
            foreigner+=1
            print("Yes")
        else:
            print("No")
    else:
        print("No")


Measured memory_bytes: 9212
#include <iostream>

int main()
{
    while (true) {
        int n;
        std::cin >> n;
        if (std::cin.eof()) break;

        int cnt = 0;
        for (int i = 0; i <= 9; ++i)
            for (int j = 0; j <= 9; ++j)
                for (int k = 0; k <= 9; ++k)
                    for (int l = 0; l <= 9; ++l)
                        if (i + j + k + l == n) ++cnt;
        std::cout << cnt << std::endl;
    }
}

Measured memory_bytes: 1160
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

S=intput()
if S<3:
    print(0)
    exit()
ans=0
for k in range(1,S//3+1):
    ans+=comb(S-2*k-1,MOD).get(k-1)
    ans%=MOD
print(ans)

Measured memory_bytes: 69052
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#include<string>
#include<stdlib.h>

using namespace std;

#define ll long long int
#define ld long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl


int main(){
  ll num = 0;
  string s;
  char data[10][7] = {".,!? $","abc$$","def$$","ghi$$","jkl$$","mno$$","pqrs$","tuv$","wxyz$"};
  char ans;
  ll temp = 0;
  ll cou = 0;

  cin>>num;
  // m1;

  rep(i,num){
    cin>>s;
    //m2;
    
    rep(i,s.size()){
      ans = '#';
      cou = 0;
      while(s[i] != '0'){
	//m3;
	temp = s[i] - '0' -1;
	//m3;
	//cout<<temp<<endl;
	ans = data[temp][cou];
	//cout<<temp<<endl;
	//	m4;
	if(data[temp][cou] == '$'){
	  cou = 0;
	  ans = data[temp][cou];
	}
	cou++;
	i++;
      }
      if(ans != '#'){
	cout<<ans;
      }
      
    }
    cout<<endl;
  }
  return 0;
}
    
    

Measured memory_bytes: 3040
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

struct p {
    char c;
    int n;
};

int partition(vector<p> &A, int p, int r) {
    int x = A[r].n;
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (A[j].n <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

void QuickSort(vector<p> &A, int p, int r) {
    if (p < r) {
        int q = partition(A, p, r);
        QuickSort(A, p, q - 1);
        QuickSort(A, q + 1, r);
    }
}

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

    int N;
    cin >> N;
    vector<p> A(N);
    rep(i, N) {
        char a;
        int b;
        cin >> a >> b;
        A[i] = {a, b};
    }

    vector<p> AA = A;
    stable_sort(all(AA), [](p a, p b) { return a.n < b.n; });

    QuickSort(A, 0, N - 1);
    bool judge = 1;
    rep(i, N) {
        if (AA[i].c != A[i].c)
            judge = 0;
    }

    if (judge) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    rep(i, N) { cout << A[i].c << " " << A[i].n << endl; }
}



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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

int main() {
    ll a;
    string b;
    cin >> a >> b;
    string d = "";
    for (char c : b) {
        if (c == '.') continue;
        d.push_back(c);
    }

    ll k = atoi(d.c_str());

    ll f = a * k;

    cout << f / 100 << endl;

}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;

int ModPow(int N, int R, int M) {
  if (R == 0) return 1;
  if (R%2 == 0) {
    int t = ModPow(N, R/2, M);
    return (t*t) % M;
  }
  return N * ModPow(N, R-1, M);
}

int main() {
  string S;
  long long int L;
  cin >> S;
  L = S.length();
  int* M = new int[L];

  int ans = 0;
  map<int, int> mp;
  mp[0] = 1;

  for (long long int i = 0; i < L; i++) {
    int x = stoi(S.substr(L-i-1, 1));
    M[i] = i==0? x : ((x*ModPow(10, i, 2019))%2019 + M[i-1])%2019;
    if (mp.count(M[i]) > 0) {
      ans += mp[M[i]];
      mp[M[i]]++;
    }
    else mp[M[i]] = 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4508
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)

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

	if ((s.length() > (a + b + 1))
		|| (s[a] != '-')
		) {
		printf("No\n");
		return 0;
	}
	for (uint32_t i = 0; i < (a + b + 1); i++) {
		if (i == a) { continue; }
		if ('0' <= s[i] && s[i] <= '9') { continue; }
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;

	//	std::cout << "Hello World!\n"; 
}

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

int n,mod=1e9+7;

inline int ksm(int a,int b)
{
	int ans=1;
	a=a%mod;
	while(b)
	{
	  if(b&1) ans=(ans*a)%mod;
	  a=(a*a)%mod,b>>=1;
	}
	return ans;
}

signed main()
{
	cin>>n;
	cout<<(ksm(10,n)-(2*ksm(9,n))%mod+ksm(8,n)+mod)%mod;
	return 0;
}

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

int main(){
	
	int n;
	int ans=0;//素数计数 
	int k;
	
	cin>>n;
	int A[n];
	for(int i=0;i<n;i++)
		cin>>A[i]; 
		
	for(int i=0;i<n;i++){
		k=1;

		for(int j=2;j*j<=A[i];j++){
			if(A[i]%j==0){
				k=0;
				break;
			}
		}
		ans+=k;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <vector>
typedef long long unsigned int ll;
using namespace std;

int main() {
    int n;
    cin>>n;
    int a[100005]={0};
    int s;
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s>n) sum++;
        else a[s]++;
    }
    
    for(int i=1;i<=n;i++){
        if(a[i]>=i) sum+=a[i]-i;
        else sum+=a[i];
    }
    cout<<sum<<endl;
    return 0;
    
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long n, m;
    cin >> n >> m;
    long ans = abs(n-2)*abs(m-2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace B___Kleene_Inversion
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var N = NK[0];
            var K = NK[1];
            var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var MOD = 1000000007;

            var invert = new long[N];
            for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) if (A[i] > A[j]) invert[i]++;

            var lessCount = new long[N];
            for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (i != j && A[i] > A[j]) lessCount[i]++;

            long result = 0;
            for (int i = 0; i < N; i++)
            {
                result = (result + (invert[i] * K) % MOD) % MOD;
                result = (result + (lessCount[i] * ((K * K - K) / 2 % MOD)) % MOD) % MOD;
            }
            Console.WriteLine(result % MOD);
        }
    }
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

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

    vector<lint> A(N);
    for_(i,0,N) cin >> A[i];

    lint sum = A[0], ans = 0, MOD = (lint)1e9 + 7;
    for_(i,1,N) {
        lint add = (sum * A[i]) % MOD;
        ans = (ans + add) % MOD;
        sum = (sum + A[i]) % MOD;
    }
    cout << ans << endl;
}

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 10;

int x, ans = 0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> x;
    for (int i = 2000; i >= 600; i -= 200)
    {
        if (x < i)
        {
            ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3652
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

N = int(input())
S = input()
sl = list(S)
setS = set(S)
ans = 0
for i in range(10):
    if str(i) not in setS:
        continue
    else:
        i100_ind = sl.index(str(i))
        S10 =sl[i100_ind+1:-1]
        S10set = set(S10)
        for j in range(10):
            if str(j) not in S10set:
                continue
            else:
                i10_ind = S10.index(str(j))
                S1 = S10[i10_ind+1:]
                S1.append(sl[-1])
                ans += len(set(S1))
print(ans)


Measured memory_bytes: 27540
// Problem : D - Knight
// Contest : AtCoder - AtCoder Beginner Contest 145
// URL : https://atcoder.jp/contests/abc145/tasks/abc145_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 ll mod_pow(ll x,ll n) {
	if (n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n / 2);
	if (n & 1) res = res * x % MOD;
	return res;
}

ll comb(ll n, ll x) {
	ll ret = 1,k=1;
	F0R(i,x)ret = (ret * (n - i))%MOD;
	F0R(i,x)k = (k * (x-i))%MOD;
	k = mod_pow(k, MOD - 2);
	ret = (ret*k + MOD) % MOD;
	return ret;
}
int main() 
{
	// && has higher precedence than ||
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int X,Y;
	cin>>X>>Y;
	int i=0,j=0;
	int c1=-1,c2=-1;
	while(i<=X && j<=Y)
	{
		if((X-i)*2==(Y-j))
		{
			c1=j;
			c2=X-i;
			break;
		}
		i+=2;
		j++;
	}
	if(c1==-1)
	{
		cout<<0<<nl;
		return 0;
	}
	else
	{
		cout<<comb(c1+c2,min(c1,c2));
	}
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll; 
const ll  M = pow(10,9)+7;

int main(){
  ll N;
  cin >> N;
  vector<ll> fac(N+2);
  vector<ll> fac2(N+2);
  vector<ll> fac3(N+2);
  fac[0] = 1;
  fac2[0] = 1;
  fac3[0] = 1;
  for(ll i = 0; i<N+1; i++){
    fac[i+1] = fac[i]*8 % M;
    fac2[i+1] = fac2[i]*9 % M;
    fac3[i+1] = fac3[i]*10 % M;
  }
  ll k=fac2[N]-fac[N];
  ll k2=fac3[N]-fac[N];
  if(k<0) k=k+M;
  if(k2<0) k2=k2+M;
  if(k2-2*k<0) k2=k2+M;
  if((k2-2*k) %M < 0)cout << (k2-2*k) %M + M <<endl;
  else cout << (k2-2*k) %M <<endl;
}


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

int main()
{
    string S;
    cin >> S;

    int year = stoi(S.substr(0, 4));
    int month = stoi(S.substr(5, 2));

    if (year > 2019 || (year == 2019 && month >= 5)) {
        cout << "TBD" << endl;
    } else {
        cout << "Heisei" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	char input[1000];
	char v[3];
	char n[3];
	char* ptr;
	int i;
	int ok;
	while(1) {
		scanf("%s",input);
		if(input[0]=='#' && input[1]==0)break;
		for(ptr=input,ok=0;*ptr && !ok;) {
			ptr++;
			for(i=0;i<3;i++) {
				if(*ptr!='~') {
					v[i]=*ptr;
					n[i]=0;
				} else {
					v[i]=*(++ptr);
					n[i]=1;
				}
				ptr+=2;
			}
			if(*ptr)ptr++;
			ok=1;
			if(v[0]==v[1] && n[0]!=n[1])ok=0;
			if(v[1]==v[2] && n[1]!=n[2])ok=0;
			if(v[2]==v[0] && n[2]!=n[0])ok=0;
		}
		puts(ok?"yes":"no");
	}
	return 0;
}

Measured memory_bytes: 0
s = str(input())
char_list = list(s)
hoge = {}
flg = False
for i in char_list:
    if i in hoge:
        hoge[i] = hoge[i] + 1
    else:
        hoge[i] = 1
if len(hoge.keys()) == 2:
    if hoge[char_list[0]] == 2:
        print('Yes')
        flg = True
if not flg:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++);
#define end return 0;
 
ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans;
ll a,b,c,d,e;
ll x[100005],y[100005],z[100005];
ll dp[100005];
string s[105],t[105];

int main(){
    cin>>n;
	for(i=0;i<n;i++){
		cin>>s[i];
	}
	cin>>m;
	for(i=0;i<m;i++){
		cin>>t[i];
	}
	for(i=0;i<n;i++){
		num=0;
		for(j=0;j<n;j++){
			if(s[i]==s[j])num++;
		}
		for(j=0;j<m;j++){
			if(s[i]==t[j])num--;
		}
		ans = max(ans,num);
	}
	p(max(ans,0ll));
	end;
}

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

int main(void)
{
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    double sum = 0;
    for (int i = 0; i < N; i++) {
        sum += 1.0 / (double)A[i];
    }
    cout << setprecision(15) << 1.0 / sum << endl;
}


Measured memory_bytes: 256
from sys import stdin

A, B = [int(x) for x in stdin.readline().rstrip().split()]
k = 1
bit_sum = []


def bit(x, n):
    return 2 ** (n - 1) * ((x + 1) // (2 ** n)) + max(0, (x + 1) % (2 ** n) - 2 ** (n - 1))


while 2 ** (k - 1) <= B:
    bit_sum.append(bit(B, k) - bit(A - 1, k))
    k += 1

ans = [(bit_sum[k] % 2) * 2 ** k for k in range(len(bit_sum))]
print(sum(ans))


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int MAXN = 1 + 1e5;
const ll oo = 1  +1e18;
typedef pair < int, int > II;
typedef pair < int, II > III;



int main(){
    int n;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++){
        if (s[i] + n > 90)s[i] = char ((s[i] + n) % 90 + 'A' - 1);
        else s[i] = char (s[i] + n);
    }
    cout << s;
    
    
    return 0;
}


Measured memory_bytes: 256
//template code, C343, 2019
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Iterator;

class Graph2 {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph2() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		
		int edges = in.nextInt();
		
		for(int i = 0; i < totalVertex; i++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			adjList.add(tmp);
		}
		
		for(int i = 0; i < edges; i++) {
			int v1 = in.nextInt();
			int v2 = in.nextInt();
			
			adjList.get(v1).add(v2);
		}
		
		in.close();
	}
	
	
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		
		for (int i = 0; i < adjMatrix.length; i++) {
			for (int j = 0; j < adjMatrix[0].length; j++) {
				adjMatrix[i][j] = 0;
			}
		}
		
		for (int i = 0; i < totalVertex; i++) {
			LinkedList<Integer> list = adjList.get(i);
			
			Iterator<Integer> itr = list.iterator();
			while(itr.hasNext()) {
				adjMatrix[i][itr.next()] = 1;
			}
		}
		
		String ans = "";
		for (int i = 0; i < adjMatrix.length; i++) {
			for (int j = 0; j < adjMatrix[0].length; j++) {
				if (j == adjMatrix[0].length - 1) {
					ans += adjMatrix[i][j];
				} else {
					ans += adjMatrix[i][j] + " ";
				}
			}
			ans += "\n";
		}
		
		System.out.print(ans);
	}
	
	public static int time = 1;
	public void dfs(int idx, int[] discover, int[] finish, int[] visited) {
			
			
			discover[idx] = time;
			time++;
			visited[idx] = 1;
			
			LinkedList<Integer> list = adjList.get(idx);
			
			for (int i = 0; i < list.size(); i++) {
				int next = list.get(i);
				
				if (visited[next] == 0) {
					dfs(next, discover, finish, visited);
				}
				
				
			}
			
			finish[idx] = time;
			time++;
		}

	
	public int getTotalVertex() {
		return totalVertex;
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph2 g = new Graph2();
		g.loadAdjList();
		
		
		int[] discover = new int[g.getTotalVertex()];
		int[] finish = new int[g.getTotalVertex()];
		int[] visited = new int[g.getTotalVertex()];
		
		g.dfs(0, discover, finish, visited);
		
//		System.out.println(Arrays.toString(visited));
		for (int i = 0; i < g.getTotalVertex(); i++) {
			if (visited[i] == 0) {
				g.dfs(i, discover, finish, visited);
			}
		}
		
		

		
		boolean[] vis = new boolean[g.getTotalVertex()];
		
		for (int i = 0; i < g.getTotalVertex(); i++) {
			int max = -1;
			int maxIdx = -1;
			
			for (int j = 0; j < g.getTotalVertex(); j++) {
				if(finish[j] > max && vis[j] == false) {
					max = finish[j];
					
//					System.out.println(Arrays.toString(vis));
					maxIdx = j;
				}
			}
			
			vis[maxIdx] = true;
			System.out.println(maxIdx);
		}
		

	}
}




Measured memory_bytes: 72144
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n;
    cin>>n;
    vi vec(n);
    REP(i,n)cin>>vec[i];
    int ans=1;
    REP(i,n){
        ans*=3;
    }
    int cnt=1;
    REP(i,n){
        if(!(vec[i]%2)){
            cnt*=2;
        }
    }
    cout<<ans-cnt<<endl;
    return 0;
}

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

main(int n){
    static bool S[13],H[13],C[13],D[13];
    cin >> n;
    for(int i=0,num; i<n; ++i){
        char c;
        cin >> c >> num;
        switch(c){
            case 'S':
                S[num-1] = true;
                break;
            case 'H':
                H[num-1] = true;
                break;
            case 'C':
                C[num-1] = true;
                break;
            case 'D':
                D[num-1] = true;
                break;
        }
    }
    for(int i=0; i<13; ++i) if(!S[i]) cout << "S " << i+1 << endl;
    for(int i=0; i<13; ++i) if(!H[i]) cout << "H " << i+1 << endl;
    for(int i=0; i<13; ++i) if(!C[i]) cout << "C " << i+1 << endl;
    for(int i=0; i<13; ++i) if(!D[i]) cout << "D " << i+1 << endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    int n, x;
    cin >> n >> x;
    vector<int> v(n, 0);
    int res = n;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        x -= v[i];
    }
    sort(v.begin(), v.end());
    cout << res + x / v[0] << endl;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin>>s;
    cin>>t;
    int l=s.length();
    int v=0;
    for(int i=0; i<l; i++){
        if(s[i]!=t[i]){
            v++;
        }
    }
    cout<<v<<'\n';
    return 0;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
int gcd (int a,int b){
    if(a%b==0){
        return(b);
    }else{
        return(gcd(b,a%b));
    }
}
int main(){
    int64_t sum = 0;
    int K;
    cin >> K;


    for (int i = 0; i < K; i++)
    {
        int a = i + 1;
        for (int j = 0; j < K; j++)
        {
            int b = j + 1;
            for (int k = 0; k < K; k++)
            {
                int c = k + 1;
                int n = gcd(a,b);
                sum += gcd(n,c);
            }
            
        }
        
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 3632
program main
  implicit none

1 format(i0)
  
  integer*8 N,v(1:5),tmp2,tmp3,i
  integer(8) tmp1
  
  read(*,*) N
  read(*,*) v(1)
  read(*,*) v(2)
  read(*,*) v(3)
  read(*,*) v(4)
  read(*,*) v(5)
  
  tmp1 = min(v(1),v(2),v(3),v(4),v(5))
  
  tmp2 = N / tmp1
  tmp3 = mod(N,tmp1)
  
  if (tmp3 == 0) then
     write(*,1) (tmp2+4)
  else
     write(*,1) (tmp2+5)
  end if
end program main
  

Measured memory_bytes: 256
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    ll x;cin >> x;
    ll ans = 0;
    ans += 1000 * (x / 500);
    x %= 500;
    ans += 5 * (x / 5);
    cout << ans << '\n';
    return 0;
}
/*
 *!!CHECK!! 
 * intの掛け算をしてる場合：overflowは大丈夫？
 * 制約の下限・上限は大丈夫？
 * 木構造は一直線にした時TLEしない？
 * */


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

int main() {
  int H,W,N;
  cin>>H>>W>>N;
  if(H>W) {
    if(N%H==0) cout<<N/H<<endl;
    else cout<<N/H+1<<endl;
  }
  else{
    if(N%W==0) cout<<N/W<<endl;
    else cout<<N/W+1<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

main(){
  string in;
  while(cin >> in){
    for(int i=0;i<in.size();i++){
      int tmp=(int)in[i]-3;
      if(tmp<(int)'A') tmp='Z'+tmp-'A'+1;
      cout << (char)tmp;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
int N,check;
string S;
int ans=0;
vector<int> p(100,10);
cin >> N >> S;
for(int i=0;i<1000;i++)
{
check=0;
p.at(2)=i%10;p.at(1)=(i/10)%10;p.at(0)=i/100;
for(int j=0;j<S.size();j++)
{
if(p.at(check)==S.at(j)-'0')check++;
}
if(check==3)ans++;
}
cout << ans;
}


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

char a[15];

signed main()
{
	for (int i=1;i<=12;i++)  cin>>a[i];
	for (int i=1;i<=12;i++)
	{
		cout<<a[i];
		if (i==4)  cout<<' ';
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, p;
    cin >> n >> p;

    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
        s[i] -= '0';
    }

    ll r = 0;
    if (10 % p == 0) {
        for (int i = 0; i < n; i++) {
            if (s[i] % p == 0) r += i + 1;
        }

    } else {
        vector<int> c(p, 0);
        int t = 0, d = 1;

        for (int i = n - 1; i >= 0; i--) {
            c[t]++;
            t += s[i] * d;
            t %= p;
            d *= 10;
            d %= p;

            r += c[t];
        }
    }

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 720
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
typedef long long ll;
#include <cmath>
#include<cstdio>
#include<iomanip>

int main(int argc, char *argv[])
{
	string s;
	cin>>s;

	const int l=s.length();
	vector<ll> mo(2019,0);

	mo[0]=1;
	int m=0,keta=1;

	for (int i=l-1;i>=0;i--)
	{
		m=((s[i]-'0')*keta+m)%2019;
		cerr<<m<<endl;
		keta=(keta*10)%2019;
		mo[m]++;
	}
	ll ret=0;
	for (int i=0;i<2019;i++)
	{
		ret+=mo[i]*(mo[i]-1)/2;
	}
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 3728
import java.util.*;

public class Main {
    static ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
    static int[] discovers;
    static int[] finishes;
    static int time = 0;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		discovers = new int[n];
		finishes = new int[n];
		for (int i = 0; i < n; i++) {
		    graph.add(new ArrayList<>());
		}
		for (int i = 0; i < n; i++) {
		    int from = sc.nextInt() - 1;
		    int count = sc.nextInt();
		    for (int j = 0; j < count; j++) {
		        graph.get(from).add(sc.nextInt() - 1);
		    }
		}
		for (int i = 0; i < n; i++) {
		    if (discovers[i] == 0) {
		        search(i);
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    sb.append(i + 1).append(" ").append(discovers[i]).append(" ").append(finishes[i]).append("\n");
		}
		System.out.print(sb);
	}
	
	static void search(int x) {
	    time++;
	    discovers[x] = time;
	    for (int y : graph.get(x)) {
	        if (discovers[y] == 0) {
	            search(y);
	        }
	    }
	    time++;
	    finishes[x] = time;
	}
}



Measured memory_bytes: 28020
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <set>
const int inf = 0x3f3f3f3f;
typedef long long ll;
const ll INF_LL  = 1e18;
using namespace std;
stack<int>v;
int cnt;
int main(){
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	v.push(s[0]-'0');
	for(int i=1;i<s.length();i++){
		if((s[i]-'0')!=v.top()) {
		v.pop();
		v.push(s[i]-'0');}
		else {
			cnt++;
			v.pop();
		v.push(!(s[i]-'0'));
	}}
	cout<<cnt;
return 0;
}


Measured memory_bytes: 512
/*
[abc132] E - Hopscotch Addict
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int INF = 1e9;

int N, M;
int u[MAX_N], v[MAX_N];
int S, T;

vector<int> g[MAX_N];
queue<pii> q;
int dist[3][MAX_N];

ll solve() {
    for (int i = 0; i < M; i++) {
        g[u[i]].push_back(v[i]);
    }

    for (int i = 0; i < 3; i++) {
        fill(dist[i], dist[i] + N, INF);
    }
    q.push({0, S});  // d, v
    while (!q.empty()) {
        pii p = q.front();
        q.pop();
        int d = p.first;
        int v = p.second;
        if (dist[d % 3][v] > d) {
            dist[d % 3][v] = d;
            for (int to : g[v]) {
                q.push({d + 1, to});
            }
        }
    }

    return dist[0][T] < INF ? dist[0][T] / 3 : -1;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> u[i] >> v[i];
        u[i]--, v[i]--;
    }
    cin >> S >> T;
    S--, T--;

    cout << solve() << endl;

    return 0;
}


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

class Dice {
private:
	int label[6];
public:
	Dice(int* a) {
		for (int i = 0; i < 6; i++) {
			label[i] = a[i];
		}
	}
	Dice() {

	}

	void N() {
		int cpy[] = { label[0],label[1],label[4],label[5] };
		label[0] = cpy[1];
		label[1] = cpy[3];
		label[4] = cpy[0];
		label[5] = cpy[2];

	}
	void S() {
		int cpy[] = { label[0],label[1],label[4],label[5] };
		label[0] = cpy[2];
		label[1] = cpy[0];
		label[4] = cpy[3];
		label[5] = cpy[1];

	}
	void W() {
		int cpy[] = { label[0],label[2],label[3],label[5] };
		label[0] = cpy[1];
		label[2] = cpy[3];
		label[3] = cpy[0];
		label[5] = cpy[2];

	}
	void E() {
		int cpy[] = { label[0],label[2],label[3],label[5] };
		label[0] = cpy[2];
		label[2] = cpy[0];
		label[3] = cpy[3];
		label[5] = cpy[1];

	}
	void clock() {
		int cpy[] = { label[1],label[2],label[3],label[4] };
		label[1] = cpy[2];
		label[2] = cpy[0];
		label[3] = cpy[3];
		label[4] = cpy[1];
	}

	int getup() {
		return label[0];
	}
	int getfront() {
		return label[1];
	}
	int getright() {
		return label[2];
	}
	int getdown() {
		return label[5];
	}
	int getleft() {
		return label[3];
	}
	int getback() {
		return label[4];
	}
};

inline bool check(class Dice dice, class Dice dice2) {
	if (dice.getup() == dice2.getup() && dice.getfront() == dice2.getfront() && dice.getright() == dice2.getright() && dice.getdown() == dice2.getdown() && dice.getleft() == dice2.getleft() && dice.getback() == dice2.getback()) {
		return true;
	}
	else {
		return false;
	}
}

bool dicecheck(class Dice dice, class Dice dice2) {
	for (int j = 0; j < 6; j++) {
		//cout << dice2.getup() << endl;
		for (int i = 0; i < 4; i++) {
			//cout <<"\t"<< dice2.getfront() << "\n";
			if (check(dice, dice2)) {
				return true;
			}
			dice2.clock();
		}
		if (j < 3) {
			dice2.N();
		}
		else if (j == 3) {
			dice2.W();
		}
		else {
			dice2.W(), dice2.W();
		}
	}
	return false;
}

int main() {
	int a[100][6] = {}, n;
	cin >> n;
	for (int j = 0; j < n; j++) {
		for (int i = 0; i < 6; i++) {
			cin >> a[j][i];
		}
	}
	class Dice dice[100] ;
	for (int i = 0; i < n; i++) {
		dice[i]=Dice(a[i]);
	}
	for (int i = 0; i < n - 1;i++) {
		for (int j = i + 1; j < n; j++) {
			if (dicecheck(dice[i], dice[j])) {
				cout << "No" << endl;
				//cout << i << j << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back
const ll mod = 1000000007;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

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

	int count = 0;
	for (int n = 1; n <= N; n++) {
		if ((int)floor(log10(n) + 1) % 2 == 1) {
			count++;
		}
	}
	cout <<count <<endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <cstdio>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if(a <= 5){
      b = 0;
    }else if(a <= 12){
      b = b / 2;
    }
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h) cin >> s[i];
    int d[h][w];
    rep(i, h) rep(j, w) d[i][j] = inf;
    queue<pii> que;
    d[0][0] = 0;
    que.push(pii(0, 0));
    while(!que.empty()){
        pii p = que.front();
        que.pop();
        int x = p.first, y = p.second;
        rep2(i, -1, 1) rep2(j, -1, 1){
            if(i*j != 0 || i+j == 0) continue;
            int nx = x+i, ny = y+j;
            if(0 <= nx && nx < h && 0 <= ny && ny < w){
                if(s[nx][ny] == '.'){
                    if(d[nx][ny] > d[x][y]+1){
                        d[nx][ny] = d[x][y]+1;
                        que.push(pii(nx, ny));
                    }
                }
            }
        }
    }
    int sum = 0;
    rep(i, h) rep(j, w) if(s[i][j] == '.') sum++;
    if(d[h-1][w-1] == inf) cout << -1 << endl;
    else cout << sum-1 - d[h-1][w-1] << endl;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    int R,G,B,N,m,ans=0;
    cin>>R>>G>>B>>N;
    for(int i=0;i<=N/R;i++){
        for(int k=0;k<=N/G;k++){
            m=N-(i*R+k*G);
            if(m%B==0&&m>=0)ans++;
        }
        m=N;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int, input().split()))
A_even=[i for i in A if i%2==0]
ans=1
for i in A_even:
  if i%3!=0 and i%5!=0:
    ans=0
    break
if ans==1:
  print("APPROVED")
else:
  print("DENIED")
    

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

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

		while(true){
			int n = sc.nextInt();
			int x = sc.nextInt();

			if(n == 0 && x == 0){
				break;
			}
			int count = 0;
			for (int i = 1; i <= n-2; i++){

				for (int j = i + 1; j <= n - 1; j++){

					for(int k = j + 1;k <= n;k++){
						if(i + j + k == x){

							count++;
						}
					}
				}
			}
			System.out.println(count);
		}

	}

}

Measured memory_bytes: 26800
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main() {
    int N, M;
    cin >> N >> M;
    Graph G(N, vector<int>());
    vector<long long int> H(N);
    for(int i = 0; i < N; i++) {
        cin >> H[i];
    }
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        long long int count = 0;
        for(int j : G[i]) {
            if(H[j] < H[i]) {
                count++;
            }
        }
        if(count == G[i].size()) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9068