akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
	int n, k;
	cin >> n >> k;
	mint ans = 0;
	vector<mint> t(k);
	rep(i, k){
		int now = i+1;
		mint add = k/now;
		add = add.pow(n);
		t.at(i) = add;
	}

	rrep(i, k){
		mint now = t.at(i);
		int in = i+1;
		for(int jn = in*2; jn <= k; jn += in){
			now -= t.at(jn-1);
		}
		t.at(i) = now;
		ans += now*in;
	}
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 4052
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        long[] a=cin.ArrayLong(N,0);
        Array.Sort(a);
        Array.Reverse(a);
        long tate=0;
        long yoko=0;
        for(int i=0;i<N-1;i++)
        {
            if(tate==0&&a[i]==a[i+1]){tate=a[i];i++;}
            else if(tate!=0&&yoko==0&&a[i]==a[i+1]){yoko=a[i];break;}
        }
        if(yoko==0&&a[0]==a[1])yoko=a[0];
        Console.WriteLine(tate*yoko);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 21088
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

ll tot(int lv){
  if(lv == 0) return 1;
  else return tot(lv-1)*2+3;
}

ll in(map<int, ll> &mp, int lv){
  if(lv == 0) return mp[lv] = 1;
  if(mp[lv] != 0) return mp[lv];
  mp[lv] = 1 + 2*in(mp, lv-1);
  return mp[lv];
}

ll fc(int lv, ll x, ll l, ll r){
  static map<int, ll> mp;
  if(mp[0] == 0) in(mp, lv);
  ll mid = (l+r)/2;
  if(r <= x) return mp[lv];
  if(mid < x && x < r){
    return mp[lv-1] + 1 + fc(lv-1, x, mid+1, r-1);
  }
  if(mid == x) return mp[lv-1] + 1;
  if(x == l) return 0;
  return fc(lv-1, x, l+1, mid-1);
}

int main(){
  int n;
  cin >> n;
  ll x;
  cin >> x;
  ll mx = tot(n);
  cout << fc(n, x, 1, mx) << endl;
  return 0;
}

Measured memory_bytes: 3584
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

type Alds14d struct {
}

func main() {
	a := &Alds14d{}
	a.main()
}

func (a *Alds14d) main() {
	scanner := bufio.NewScanner(os.Stdin)
	fmt.Println(a.solve(scanner))
}

func (a *Alds14d) solve(scanner *bufio.Scanner) int {

	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	S := make([]int, n+1)
	for i := 0; i < n; i++ {
		scanner.Scan()
		S[i], _ = strconv.Atoi(scanner.Text())
	}

	scanner.Scan()
	q, _ := strconv.Atoi(scanner.Text())
	T := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		T[i], _ = strconv.Atoi(scanner.Text())
	}

	res := 0

	i := 0
	for i < q {
		S[n] = T[i]

		j := 0
		for S[j] != T[i] {
			j++
		}
		if j != n {
			res++
		}

		i++
	}

	return res
}



Measured memory_bytes: 1768
N=gets.chop
K=gets.to_i
T,F=1,0
@dp=Array.new(N.size){Array.new(K){Array.new(2)}}
def dfs(n, k, eq)
  return 1 if k==K
  return 0 if n==N.size
  return @dp[n][k][eq] if @dp[n][k][eq]
  @dp[n][k][eq] = 0
  if eq==T
    if N[n]==?0
      @dp[n][k][eq] += dfs(n+1, k, T)
    else
      @dp[n][k][eq] += dfs(n+1, k+1, T)
      @dp[n][k][eq] += dfs(n+1, k, F)
      @dp[n][k][eq] += (N[n].to_i-1) * dfs(n+1, k+1, F)
    end
  else
    @dp[n][k][eq] += dfs(n+1, k, F)
    @dp[n][k][eq] += 9 * dfs(n+1, k+1, F)
  end
  @dp[n][k][eq]
end
p dfs(0,0,T)

Measured memory_bytes: 14348
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

signed main(){
    string s;
    cin >> s;
    int ans = 0;
    char c = s[0];
    rep(i,s.length()) {
        if(i==0) continue;
        if(s[i] != c) ans++;
        c = s[i];
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
	string s; cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.size()/2; i++) {
		if (s[i] != s[s.size() - 1 - i])cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  int m;
  int s;
  int a,b,c;
  while(scanf("%d %d",&n, &m), n!=0&&m!=0){
    s=m-n;
    a=s/1000;
    b=(s-1000*a)/500;
    c=(s-1000*a-500*b)/100;

    printf("%d %d %d\n", c, b, a);
  }

  return 0;
}

Measured memory_bytes: 600
def Parent(node_id):
    return int(node_id/2.0)

def LeftChild(node_id):
    return 2 * node_id

def RightChild(node_id):
    return 2 * node_id + 1

def Main():
    n = int(input())
    H = [None]*(n + 1)
    keys = [int(a) for a in input().split()]

    for i in range(1, n + 1):
        H[i] = keys[i - 1]

    for i in range(1, n + 1):
        information = "node {0}: key = {1}, ".format(i, H[i])
        
        if 1 <= Parent(i) <= n:
            information +=  "parent key = {0}, ".format(H[Parent(i)])

        if 1 <=  LeftChild(i) <= n:
            information += "left key = {0}, ".format(H[LeftChild(i)])

        if 1 <= RightChild(i) <= n:
            information += "right key = {0}, ".format(H[RightChild(i)])

        print(information)

Main()


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

int main(){
	int a,b;
	char op;

	while(1){
		cin >> a >> op >> b;
		if (op == '?') break;

		if( op == '+') cout << a + b << endl;
		else if( op == '-') cout << a - b << endl;
		else if( op == '*') cout << a * b << endl;
		else if( op == '/') cout << a / b << endl;
		}

		return 0; 
}

Measured memory_bytes: 3084
#include<iostream>
using namespace std;
int main()
{
	while (1) {
		int a, b;
		cin >> a >> b;
		if (a == 0 && b == 0)break;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= b; j++) {
				cout << "#";
			}
			cout << "\n";
		}
cout<<endl;

	}
	return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,m,cnt=0,aa[220000],k;
pair<int,int> p[110000];
string s;
char c;
signed main(){
    cin>>n>>k;
    rep(i,n){
        cin>>aa[i];
    }
    sort(aa,aa+n);
    rep(i,n-k){
        cnt+=aa[i];
    }
    cout<<cnt;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)
#define _popcnt __builtin_popcount

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int N; cin >> N;
  if(N & 1){
    cout << 0 << endl;
    return 0;
  }
  N /= 2;
  int cnt = 0;
  while(N > 0){
    cnt += N / 5;
    N /= 5;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
K, X = map(int, input().split())

min_x = X - (K - 1)
if min_x < -1000000:
    min_x = -1000000


max_x = X + (K - 1)

if max_x > 1000000:
    max_x = 1000000

ans = ""
for i in range(min_x, max_x + 1):
    ans += str(i) + " "

print(ans[:-1])


Measured memory_bytes: 3060
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

ll gcd_with_coef(ll x, ll y, ll* outCX, ll* outCY) {
    if (x < 0) {
        ll d = gcd_with_coef(-x, y, outCX, outCY);
        *outCX *= -1;
        return d;
    }
    if (y < 0) {
        ll d = gcd_with_coef(x, -y, outCX, outCY);
        *outCY *= -1;
        return d;
    }
    if (x > y) {
        return gcd_with_coef(y, x, outCY, outCX);
    }
    if (x == 0) {
        if (outCX != nullptr && outCY != nullptr) {
            *outCX = 0;
            *outCY = 1;
        }
        return y;
    }
    ll q = y / x;
    ll r = y % x;
    ll d = gcd_with_coef(r, x, outCY, outCX);
    if (outCX != nullptr && outCY != nullptr) {
        *outCX -= q * *outCY;
    }
    return d;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> Ais(N);
    rep(i,0,N) {
        cin >> Ais[i];
    }
    vector<ll> left_gcds(N+1);
    left_gcds[1] = Ais[0];
    rep(n,2,N+1) {
        left_gcds[n] = gcd_with_coef(left_gcds[n-1], Ais[n-1], nullptr, nullptr);
    }
    vector<ll> right_gcds(N+1);
    right_gcds[1] = Ais[N-1];
    rep(n,2,N+1) {
        right_gcds[n] = gcd_with_coef(right_gcds[n-1], Ais[N-n], nullptr, nullptr);
    }
    ll ans = numeric_limits<ll>::min();
    rep(i,0,N) {
        ll ans_loc = gcd_with_coef(left_gcds[i], right_gcds[N-i-1], nullptr, nullptr);
        ans = max(ans, ans_loc);
    }
    cout << ans << endl;
}



Measured memory_bytes: 2560
n, a, b, c, d = map(int, input().split())
s = input()

lbound = min(a, b) - 1

if "##" in s[a - 1 : c] or "##" in s[b - 1 : d]:
    print("No")
elif ((a > b) ^ (c > d)) and "..." not in s[max(a, b) - 2 : min(c, d) + 1]:
    print("No")
else:
    print("Yes")


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

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

    int N;
    scanf("%d", &N);
    vector<long long> A(N);
    long long sum = 0;
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
        sum += A[i];
    }
    long long sum2 = 0;
    long long mind = (long long) 2020202021 * 200000;
    for (int i = 0; i < N; i++) {
        sum2 += A[i];
        mind = min(mind, abs(sum2 * 2 - sum));
    }
    printf("%lld\n", mind);

    return 0;
}


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

int main()
{
    int64_t N;
    int64_t ans = 1;
    std::cin >> N;
    for (int i = 1; i <= N; ++i) {
        ans *= i;
        ans %= 1000000007;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 3576
#include <stdio.h>
int main(){
    int r,c;
    int i,j;
    int rc[110][110];
    int SUM;
    scanf("%d %d",&r,&c);
    for(i=0;i<r;i++){
        SUM=0;
        for(j=0;j<c;j++){
            scanf("%d",&rc[i][j]);
            SUM+=rc[i][j];
        }
        rc[i][c]=SUM;
    }
    for(i=0;i<c+1;i++){
        SUM=0;
        for(j=0;j<r;j++){
            SUM+=rc[j][i];
        }
        rc[r][i]=SUM;
    }
    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++){
            if(j!=0) printf(" ");
            printf("%d",rc[i][j]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 2088
N, M, Q = map(int, input().split())
A = [[0] * N for _ in range(N)]
for _ in range(M):
    l, m = map(int, input().split())
    A[l - 1][m - 1] += 1

questions = []
for _ in range(Q):
    p, q = map(int, input().split())
    questions.append((p - 1, q - 1))


D = []
for l in range(N):
    s = 0
    d = []
    for r in range(N):
        s += A[l][r]
        d.append(s)
    D.append(d)

T = []
for r in range(N):
    s = 0
    t = []
    for l in range(N):
        s += D[N - l - 1][r]
        t.append(s)
    T.append(t)

for question in questions:
    print(T[question[1]][N - question[0] - 1])


Measured memory_bytes: 25952
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int g;
string dir;
vector<string> ope;

string solve(string s, int i)
{
    int n = s.size();
    if(n == 1)
        return s;
    if(i == g)
        return solve(s.substr(1, n-2), 0);

    string ret;
    if(dir[i] == 'L'){
        int j = 0;
        int k = 0;
        int m = 0;
        while(k <= n){
            if(k < n && s[k] == '(')
                ++ m;
            if(k < n && s[k] == ')')
                -- m;
            if(m == 0 && (k == n || find(ope[i].begin(), ope[i].end(), s[k]) != ope[i].end())){
                if(j > 0)
                    ret = '(' + ret + s[j-1] + solve(s.substr(j, k-j), i+1) + ')';
                else
                    ret = solve(s.substr(j, k-j), i+1);
                j = k + 1;
            }
            ++ k;
        }
    }else{
        int j = n-1;
        int k = n-1;
        int m = 0;
        while(k >= -1){
            if(k >= 0 && s[k] == '(')
                ++ m;
            if(k >= 0 && s[k] == ')')
                -- m;
            if(m == 0 && (k == -1 || find(ope[i].begin(), ope[i].end(), s[k]) != ope[i].end())){
                if(j < n-1)
                    ret = '(' + solve(s.substr(k+1, j-k), i+1) + s[j+1] + ret + ')';
                else
                    ret = solve(s.substr(k+1, j-k), i+1);
                j = k - 1; 
            }
            -- k;
        }
    }

    return ret;
}

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

    while(--d >= 0){
        cin >> g;
        dir.resize(g);
        ope.resize(g);
        for(int i=0; i<g; ++i){
            int m;
            cin >> dir[i] >> m;
            ope[i].resize(m);
            for(int j=0; j<m; ++j)
                cin >> ope[i][j];
        }

        int n;
        cin >> n;
        for(int i=0; i<n; ++i){
            string s;
            cin >> s;
            cout << solve(s, 0) << endl;
        }

        if(d > 0)
            cout << endl;
    }

    return 0;
}

Measured memory_bytes: 972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
        String S = in.next();
        int N = S.length();

        int[] num = new int[N];

        for(int i = 0; i < N-1; i++){
            if(S.charAt(i) == 'R' && S.charAt(i+1) == 'L'){
                int index = i;
                while(index >= 0 && S.charAt(index) == 'R'){
                    if(Math.abs(i - index) % 2 == 0){
                        num[i]++;
                    }else{
                        num[i+1]++;
                    }
                    index--;
                }
                index = i+1;
                while(index < N && S.charAt(index) == 'L'){
                    if(Math.abs((i+1) - index) % 2 == 0){
                        num[i+1]++;
                    }else{
                        num[i]++;
                    }
                    index++;
                }
            }
        }
        for (int i = 0; i < N; i++) {
        	if (i!=N-1) {
        		System.out.print(num[i] + " ");
			} else {
				System.out.print(num[i]);
			}
		}
	}
}

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

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************
ll mod=1000000007;
void solve()
{
  ll n,k;
  cin >> n >> k;
  ll ans=0;
  for(ll i=k;i<=n+1;i++)
  {
      ll t1=i*(i-1)/2%mod;
      ll t2=n*(n+1)/2-(n-i)*(n-i+1)/2+mod;
      t2%=mod;
      ans+=t2-t1+1+mod;
      ans%=mod;
  }
  cout << ans << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N,X;
    cin >> N >> X;
    vector<int> M(N);
    int sum = 0;
    for(int i = 0;i < N;i++) {
        cin >> M[i]; sum += M[i];
    }
    sort(M.begin(),M.end());
    int ans = M.size();
    for(int i = 0;i < 123456789;i++){
        if(X - sum - M[0] >= 0){
            sum += M[0];
            ans++;
        }
        else break;
    }

   cout << ans << endl;
}   

Measured memory_bytes: 256
def get_num(num)
  case num
  when 'A'
    10
  when 'B'
    11
  when 'C'
    12
  when 'D'
    13  
  when 'E'
    14
  when 'F'
    15
  end
end
  
x,y=gets.split.map &:to_s
rx=get_num(x)
ry=get_num(y)

if rx < ry
  puts '<'
elsif rx > ry
  puts '>'
elsif rx === ry
  puts '='
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
	#include <ext/pb_ds/assoc_container.hpp>
	using namespace __gnu_pbds;
	using namespace std;
	#define mod 1000000007
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define ps push
	#define pll pair<long,long>
	typedef long long ll;
	#define PI 3.14159265
	#define vi vector<pll> 
		 
	typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
	const ll INF=(ll)5e17;	
		
	long long binpow(long long a, long long b, long long m) {
			a %= m;
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = res * a % m;
				a = a * a % m;
				b >>= 1;
			}
			return res;
	}

		
		
	int main()
	{
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		
		ll n,z,w;
		cin>>n>>z>>w;
		vector<ll> v(n);
		for(ll i=0;i<n;i++)
		{
			cin>>v[i];
		}
		if(n==1)
		{
			cout<<abs(w-v[0]);
		}
		else
		{
			cout<<max(abs(w-v[n-1]),abs(v[n-1]-v[n-2]));
		}
		
	}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    char ch;
    std::cin>>ch;

    std::string s = "aeiou";
    std::string ans;
    if(s.find(ch) == std::string::npos){
        ans = "consonant";
    }else{
        ans = "vowel";
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val S = readLine()!!.toCharArray()
    var ans = -1000000
    var l = -1
    for (r in S.indices) {
        if ("ACGT".contains(S[r])) continue
        ans = Math.max(ans, r - l - 1)
        l = r
    }
    ans = Math.max(ans, S.size - l - 1)
    println(ans)
}

Measured memory_bytes: 35728
#include <stdlib.h>
#include <stdio.h>

int cmpf(const void *x, const void *y){
	return (*(int*)x-*(int*)y);
}

int main(){
	int N;
	scanf("%d",&N);
	int *a;
        a=malloc(sizeof(int)*N);
	for(int i=0;i<N;i++) scanf("%d",&a[i]);
	qsort(a,N,sizeof(int),cmpf);
	double mid=(double)a[N-1]/2;
	int malim=N-2,milim=0;
	while(malim-milim>1)
	{
		int now=(malim+milim)/2;
		if(a[now]>mid){ malim=now; }
		else if(a[now+1]<mid){ milim=now+1; }
		else{
			malim=now+1;
			milim=now;
		}
	}
	printf("%d %d",a[N-1],((mid-(double)a[milim])<((double)a[malim]-mid)?a[milim]:a[malim]));
	return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 2e5;

int N, K;
vi node[2000];
int a[2000], b[2000];

int main() {
  cin >> N >> K;
  REP (i, N-1) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    node[a[i]].push_back(b[i]);
    node[b[i]].push_back(a[i]);
  }

  int ans = N;

  if (K%2 == 0) {
    REP (k, N) { /// 中心にするノード
      vector<bool> used(N);
      queue<int> q;
      q.push(k);
      used[k] = true;
      int d = 0; /// 中心からの距離 
      int last = k; /// 中心からの距離がdのときの最後の値
      int count = 0; /// 中心からの距離がK以下の数を数える
      while (!q.empty()) {
        int x = q.front(); q.pop();
        REP (i, node[x].size()) {
          int n = node[x][i];
          if (used[n]) continue;
          q.push(n);
          used[n] = true;
        }
        count++;
        if (x == last) {
          last = q.back();
          d++;
          if (d > K/2) {
            ans = min(ans, N-count);
            break;
          }
        }
      }
    }
  } else {
    REP (k, N-1) {
      vector<bool> used(N);
      queue<int> q;
      q.push(a[k]);
      q.push(b[k]);
      used[a[k]] = used[b[k]] = true;
      int d = 0;
      int last = b[k];
      int count = 0;
      while (!q.empty()) {
        int x = q.front(); q.pop();
        REP (i, node[x].size()) {
          int n = node[x][i];
          if (used[n]) continue;
          q.push(n);
          used[n] = true;
        }
        count++;
        if (x == last) {
          last = q.back();
          d++;
          if (d > K/2) {
            ans = min(ans, N-count);
            break;
          }
        }
      }
    }
  }

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

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

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

  vector<int> C( 4 );

  for( int i = 0; i < N; i++ ) {
    cin >> S;
    if( S == "AC" )
      C.at( 0 )++;
    else if( S == "WA" )
      C.at( 1 )++;
    else if( S == "TLE" )
      C.at( 2 )++;
    else
      C.at( 3 )++;
  }

  cout << "AC x " << C.at( 0 ) << endl << "WA x " << C.at( 1 ) << endl << "TLE x " << C.at( 2 ) << endl << "RE x " << C.at( 3 ) << endl;

}

Measured memory_bytes: 3612
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

#include <iostream>
#include <string>

using namespace std;

class BStringsWithTheSameLength {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        string S, T;
        in >> S >> T;

        string ret;
        for (int i = 0; i < N; ++i) {
            ret += S[i];
            ret += T[i];
        }

        out << ret;
    }
};


int main() {
	BStringsWithTheSameLength solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
    int n, x, y, ans[2000] {};
    scanf("%d %d %d", &n, &x, &y);
    for (int i = 1; i <= n - 1; i++) {
        for (int j = i + 1; j <= n; j++) {
            int k = min(abs(i - j), min(abs(x - i) + abs(y - j) + 1, abs(y - i) + abs(x - j) + 1));
            ans[k]++;
        }
    }
    for (int i = 1; i < n; i++) printf("%d\n", ans[i]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
int main(){
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  A.push_back(-INF);
  int tv = INF;
  int fv = -1;
  while (tv - fv > 1){
    int mid = (tv + fv) / 2;
    bool ok = false;
    for (int i = 0; i < N; i++){
      int cnt = 0;
      int cnt2 = 0;
      int cnt3 = 0;
      for (int j = 0; j <= N; j++){
        if (A[j] >= A[i] - mid){
          cnt2++;
          if (A[j] <= A[i]){
            cnt3++;
          }
        } else {
          cnt += max(min(cnt2 - K + 1, cnt3), 0);
          cnt2 = 0;
          cnt3 = 0;
        }
      }
      if (cnt >= Q){
        ok = true;
      }
    }
    if (ok){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}

Measured memory_bytes: 3620
while True:
    m,f,r=map(int, input().split())
    if m==-1 and f==-1 and r==-1:
        break
    if m+f>=80:
        print("A")
    elif m==-1 or f==-1:
        print("F")
    elif m+f<80 and m+f>=65:
        print("B")
    elif m+f<65 and m+f>=50:
        print("C")
    elif m+f<50 and m+f>=30:
        if r>=50:
            print("C")
        else:
            print("D")
    else:
        print("F")


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

int main(void){
		
  	int N;
	string S,T;
  	cin >> N;
  	cin >> S >> T;
  	char ans[2*N];
  	for (int i = 0; i < 2*N ; i++){
		ans[2*i] = S[i];
      	ans[2*i + 1] = T[i];
    }
  	cout << ans <<endl;
	
  	
	return 0;
  
}

Measured memory_bytes: 256
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut a: Vec<u64> = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect();
    a.push(0);
    for i in (0..n).rev() {
        a[i] += a[i + 1];
    }
    let a = a;
    let mut dp = vec![vec![0; n]; n];
    for len in 2..(n + 1) {
        for l in 0..(n + 1 - len) {
            let r = l + len - 1;
            let mut local = std::u64::MAX;
            for k in l..r {
                local = std::cmp::min(local, dp[l][k] + dp[k + 1][r]);
            }
            dp[l][r] = local + a[l] - a[r + 1];
        }
    }
    println!("{}", dp[0][n - 1]);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n;
    cin >> n;
    ll ans = 0;
    rrep(i, n) {
        if (i % 5 == 0 || i % 3 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
n = input()

if n == 2:
    print 1
    exit()

m = n - 1
sqm = int(m ** 0.5) + 1

ans = set([m])
for i in xrange(2, sqm):
    if m % i == 0:
        ans.add(i)
        if i * i != m: ans.add(m // i)

divs = [n]
sqn = int(n ** 0.5) + 1
for i in xrange(2, sqn):
    if n % i == 0:
        divs.append(i)
        if i * i != n: divs.append(n // i)

for d in divs:
    N = n
    while N % d == 0: N //= d

    if N % d == 1: ans.add(d)

print len(ans)

Measured memory_bytes: 30956
#include <stdio.h>

int main(void)
{
	int n;
	int re = 100000;
	int i;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		re *= 1.05;
	//	printf("%d\n", re);
		re = (re + 999) / 1000 * 1000;
	}
	
	printf("%d\n", re);
	return (0);
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll n;
  cin >> n;
  vector<string> s(n);
  for(ll i = 0; i < n; i++) cin >> s[i];
  sort(all(s));
  s.erase(unique(all(s)), s.end());
  cout << s.size() << endl;

  return 0;
}

Measured memory_bytes: 9508
#include <iostream>

#define MAXN 100000

using namespace std;

int A[MAXN+1];

void dp ( int x, int N )
{
  A[x] = 1;
  for ( int i = x+1; i <= N; ++i ) A[i] = min(A[i-x]+1, A[i]);
}

int func ( int N ) {
  for ( int i = 6; i <= N; i *= 6 ) dp(i,N);
  for ( int i = 9; i <= N; i *= 9 ) dp(i,N);
  return A[N];
}

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

  cout << func(N) << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pi 3.14159265358979
int main() {
	int n, d;
	long p, q;
	int ans = 0;
	cin >> n >> d;
	double h;
	rep(i, n) {
		cin >> p >> q;
		h = sqrt(pow(p, 2) + pow(q, 2));
		if (h <= d)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>
int main(void){
    int a, b;
    
    scanf("%d %d", &a, &b);
    
    if((a == 1 && b == 2) || (a == 2 && b == 1)){
        printf("3\n");
    }else if((a == 1 && b == 3) || (a == 3 && b == 1)){
        printf("2\n");
    }else if((a == 2 && b == 3) || (a == 3 && b == 2)){
        printf("1\n");
    }
    return 0;
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 5e3+5;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll a,b,c,k , ans=0;
    cin >> a >> b >> c >> k;

    ll tmp = min(a,k);
    a -= tmp , k -= tmp;
    ans += tmp;

    tmp = min(k,b);
    k -= tmp , b -= tmp;

    tmp = min(k,c);
    k -= tmp , ans -= tmp;
    cout << ans;

    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<string> vec(n);
  for (auto &v : vec) {
    string tmp;
    cin >> tmp;
    sort(tmp.begin(), tmp.end());
    v = tmp;
  }
  sort(vec.begin(), vec.end());
  vec.push_back("last");

  string last = "";
  ll cnt1 = 0;
  ll cnt2 = 0;
  for (auto &v : vec) {
    if (last == v) {
      ++cnt2;
    }
    else {
      cnt1 += (cnt2 + 1) * (cnt2) / 2;
      last = v;
      cnt2 = 0;
    }
  }

  cout << cnt1 << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = pair<ii, ll>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)x
const ll MOD = 1e9 + 7;
const ll INF = 2e9;
const ll N = 3e3 + 5;

ll n, k;
ll a[N];
ll dp[N][N];

ll f(ll l, ll r) {
    if(l > r) return 0;
    ll &sol = dp[l][r];
    if(sol != -1) return sol;
    return sol = max(a[l] - f(l + 1, r), a[r] - f(l, r - 1));
}

void solve() {
    cin >> n;
    for(ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << f(1, n) << "\n";
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    solve();
    
}

Measured memory_bytes: 74352
n,m,q = map(int,input().split())
ans = 0
x = [list(map(int,input().split())) for i in range(q)]
import itertools
arrs = list(itertools.combinations_with_replacement(range(m),n))
for arr in arrs:
    buf = 0
    for i in x:
        a,b,c,d = i
        if arr[b-1]-arr[a-1]==c:
            buf+=d
    ans = max(ans,buf)
print(ans)

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

// Nを入力したあとでN個の要素をもつ配列を入力する
vector<int> input(int N) {
  vector<int> vec(N);
  rep (i, N) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  // Nの入力
  int H,N;
  cin >> H >> N;

  // 受け取る
  vector<int> A;
  A = input(N);

  int Asum = 0;
  
  rep(i,N){
    Asum += A.at(i);
  }

  string result = "No";

  if(Asum >= H) result = "Yes";
  
  cout << result << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int K;cin>>K;
    cout<<(K/2)*(K-K/2)<<endl;
}

Measured memory_bytes: 3568
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;


void dfs_visit(int u) {
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for ( v = 0; v < n; v++ ) {
    if ( M[u][v] == 0 ) continue;
    if ( color[v] == WHITE ) {
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs() {
  int u;

  for ( u = 0; u < n; u++ ) color[u] = WHITE;
  tt = 0;
  
  for ( u = 0; u < n; u++ ) {

    if ( color[u] == WHITE ) dfs_visit(u);
  }
  for ( u = 0; u < n; u++ ) {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}


int main() {
  int u, v, k, i, j;

  scanf("%d", &n);
  for ( i = 0; i < n; i++) {
    for ( j = 0; j < n; j++ ) M[i][j] = 0;
    }

for ( i = 0; i < n; i++) {
  scanf("%d %d", &u, &k);
  u--;
  for ( j = 0; j < k; j++ ) {
    scanf("%d", &v);
    v--;
    M[u][v] = 1;
  }
 }

 dfs();

 return 0;
}



Measured memory_bytes: 2060
from itertools import accumulate
import sys
N,*L = map(int, open(0).read().split())
MOD = 10**9+7
T = L[:N]
A = L[N:]
h = [0]*N
p = -1
for i in range(N):
  if p != T[i]:
    p = T[i]
    h[i] = T[i]
p = -1
for i in range(N-1,-1,-1):
  if p!=A[i]:
    if h[i]!=0 and h[i]!=A[i]:
      print(0)
      sys.exit()
    p = A[i]
    h[i] = A[i]
xt = list(accumulate(h,max))
xa = list(accumulate(h[::-1],max))[::-1]
if xt!=T or xa!=A:
  print(0)
  sys.exit()
B = [min(t,a) for t,a in zip(T,A)]
ans = 1
for i in range(N):
  if h[i]==0:
    ans *= B[i]
    ans %= MOD
print(ans)

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

using namespace std;
const int MAXN=2e5;
vector<int> G[MAXN];
unordered_set<int>invG[MAXN];
vector<int> res;
int vis[MAXN];
int ans[MAXN];
void dfs(int x)
{
    if (vis[x]) return ;
    vis[x]=1;
    for (int i=0;i<G[x].size();i++)
    {
        dfs(G[x][i]);
    }
    res.push_back(x);
}
void dfs2(int u)
{
    //cout << u << endl;
    vector<int> tmp;
    for (int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        if (invG[v].size()>1) continue;
        tmp.push_back(v); 
    }
    for (int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        invG[v].erase(u);
    }
    for (int i=0;i<tmp.size();i++)
    {
        int v=tmp[i];
        ans[v]=u+1;
        dfs2(v);
    }
}
int main()
{
    int n,m;
    cin >> n >> m;
    for (int i=0;i<n+m-1;i++)
    {
        int x,y;
        cin >> x>> y;
        --x,--y;
        G[x].push_back(y);
        invG[y].insert(x);
    }
    for (int i=0;i<n;i++)
    {
        dfs(i);
    }
    dfs2(res.back());
    ans[res.back()]=0;
    //cout << endl;
    for (int i=0;i<n;i++)
    {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 38012
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    ll a,b;cin>>a>>b;
    ll c=a-b;
    vector<ll>h(n);
    rep(i,n)cin>>h[i];
    ll l=0,r=1000000000;
    while(r-l>1){
        ll k=(r+l)/2;
        ll cnt=0;
        rep(i,n){
            if(k*b>=h[i])continue;
            cnt+=(h[i]-k*b-1)/c+1;
        }
        if(cnt>k)l=k;
        else r=k;
    }
    cout<<r<<endl;
}

Measured memory_bytes: 1024
readline = input()
parmlist = readline.split()

monsterH = int(parmlist[0])
servalA = int(parmlist[1])
attack_times = monsterH/servalA
int_attack_times = int(attack_times)

if attack_times-int_attack_times > 0:
    real_attack_times = int_attack_times + 1
else:
    real_attack_times = int_attack_times

print(real_attack_times)


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

using namespace std;

typedef long long int ll;

void solve()
{
	int x, n;
	cin >> x >> n;
	if(x > n)cout << "safe\n";
	else cout << "unsafe\n";
}

int main()
{
	int t = 1;
	//cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}



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

#define sz(x) ((int)x.size())
#define int long long

using namespace std;


const int MAXN = 500 * 1000 + 23;








int a[MAXN], cnt;


int32_t main() {
    string s;
    cin >> s;
    for (int i = 0; i < sz(s); i++) {
        a[i] = max(a[i], cnt);
        if (s[i] == '<')
            cnt = a[i] + 1;
        else
            cnt = 0;
    }
    a[sz(s)] = max(a[sz(s)], cnt);
    cnt = 0;
    for (int i = sz(s) - 1; ~i; i--) {
        a[i + 1] = max(a[i + 1], cnt);
        if (s[i] == '>')
            cnt = a[i + 1] + 1;
        else
            cnt = 0;
    }
    a[0] = max(a[0], cnt);
    /*
    cout << a[0] << ' ';
    for (int i = 0; i < sz(s); i++)
        cout << s[i] << ' ' << a[i + 1] << ' ';
    cout << endl;
    */
    cout << accumulate(a, a + sz(s) + 1, 0ll);
    return 0;
}

Measured memory_bytes: 4740
#include<stdio.h>
#include<string.h>

void five(int h, int a){  // h=height , a=number
  
  if( (h==1&&a<=4) || (h==2&&a>=5) )
    printf("*");
  else
    printf(" ");
}

void ball(int h, int a){
  
  if(a==h-1||a==h+4)
    printf(" ");
  else
    printf("*");
}

int main(void){
  char num1[7];
  int num2[5];
  int i,j,f=0,len;
  
  while(scanf("%s",num1)!=EOF){  // scan
    len=strlen(num1);  // length

    for(i=0;i<5-len;i++)  // left zero
      num2[i]=0;
    j=0;
    for(i=5-len;i<5;i++)  // char->int copy
      num2[i]=num1[j++]-'0';

    if(f)
      puts("");  // data set \n

    for(j=1;j<=2;j++){  // j=1,2
      for(i=0;i<5;i++){
	five(j,num2[i]);
      }
      puts("");
    }
    
    puts("=====");
    
    for(j=1;j<=5;j++){  // j=1,2, ... ,5
      for(i=0;i<5;i++){
	ball(j,num2[i]);
      }
      puts("");
    }

    f=1;
  }
  return 0;
}

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


int main()
{
	int n;
	long long sum=0;
	cin>>n;
	int mon[n+10],he[n+9];
	for(int i=0;i<n+1;i++)
	{
		cin>>mon[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>he[i];
	}
	for(int i=0;i<n;i++)
	{
		if(mon[i]>=he[i])
		{
			sum+=he[i];
		}
		else
		{
			if(mon[i]<he[i])
			{
				sum+=mon[i];
				he[i]=he[i]-mon[i];
				if(mon[i+1]>=he[i])
				{
					sum+=he[i];
					mon[i+1]=mon[i+1]-he[i];
				}
				else
				{
					if(mon[i+1]<he[i])
					{
						sum+=mon[i+1];
						mon[i+1]=0;
					}
				}
			}
		}
	}
	cout<<sum;
}

Measured memory_bytes: 1024
N,K = map(int,input().split())
A = [int(a)-1 for a in input().split()]

if K <= N:
    p=0
    for i in range(K):
        p = A[p]
        
    print(p+1)
    exit()

p=0
t=[-1]*N
t[0]=0

for i in range(1,N):
    p =A[p]
    if t[p]!=-1:
        break
    t[p]=i
    
d=i-t[p]
K-=i
K%=d


for i in range(K):
    p =A[p]
print(p+1)

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


long long int power5(long long int x ){
    long long int temp = (x*x*x*x*x) ;
    return temp;
    
}

int main(){
   long long int X;
   cin >> X;
   for(long long int ii  = 0; ii < 200;ii++){
       for(long long int jj = -200 ; jj < 200 ;jj++){
           if((power5(ii) - power5(jj)) == X){
               cout << ii <<  " " << jj;
              return 0;
           }
       }
   }
    
}

Measured memory_bytes: 3124
#include <stdio.h>
#include <math.h>
int main(){
    int A,B;
    scanf("%d %d",&A,&B);
    if (A==B){
        printf("%d",A+A);
    }
    else if (A>B){
        printf("%d",A+A-1);
    }
    else{
        printf("%d",B+B-1);
    }
    
    
    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;

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

int h, w, cnt0, cnt1;
char s[N][N];
bool vis[N][N];
LL ans;

void dfs(int x, int y) {
    vis[x][y] = 1;
    if (s[x][y] == '.') cnt0++;
    else cnt1++;
    for (int i = 0; i < 4; i++) {
        int tx = x + dx[i], ty = y + dy[i];
        if (tx < 1 || tx > h || ty < 1 || ty > w) continue;
        if (!vis[tx][ty] && s[tx][ty] != s[x][y]) dfs(tx, ty);
    }

}

int main() {
    scanf("%d%d", &h, &w);
    for (int i = 1; i <= h; i++) scanf("%s", s[i] + 1);
    for (int i = 1; i <= h; i++)
        for (int j = 1; j <= w; j++) if (!vis[i][j] && s[i][j] == '#') {
            cnt0 = cnt1 = 0;
            dfs(i, j);
            ans += 1LL * cnt0 * cnt1;
        }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 8064
INF = (10 ** 9) + 7
N, M = map(int, input().split())

aLst = set(int(input()) for i in range(M))
ansLst = [0] * (N + 1)
ansLst[0] = 1

for i in range(1, N + 1):
    if i in aLst:
        continue
    tmp = ansLst[i - 1]
    if i > 1:
        tmp += ansLst[i - 2]
    ansLst[i] = tmp % INF


print(ansLst[N])


Measured memory_bytes: 11884