akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;
 
inline int read(){
	int x = 0, ch = getchar(), f = 1;
	while (!isdigit(ch)){if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}

const int N = 100005;
int n, xi[N], L, q, nxt[N][25];

int main(){
	n = read();
	REP(i, 1, n) xi[i] = read();
	L = read(), q = read();
	int r = 1;
	REP(i, 1, n){
		while (r < n && xi[r + 1] - xi[i] <= L) ++r;
		nxt[i][0] = r;
	}
	for (int j = 1; (1 << j) <= n; ++j)
		for (int i = 1; i <= n; ++i)
			nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
	REP(i, 1, q){
		int x = read(), y = read();
		if (x > y) swap(x, y);
		LL ans = 0;
		PER(j, 19, 0) if (nxt[x][j] && nxt[x][j] < y){
			x = nxt[x][j];
			ans += (1ll << j);
		}
		if (x == y) cout << ans << endl;
		else cout << ans + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 11008
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    long long A;
    long long M = 1000000007;
    long long sum = 0;
    long long diag = 0;
    for (int i = 0; i < N; ++i)
    {
        cin >> A;
        sum = (sum + A) % M;
        diag = (diag + A * A)%M;
    }
    long long tmp = sum * sum - diag;
    tmp = ((tmp & 1)==0) ? tmp : (tmp + M); 
    long long ret = (tmp / 2) % M;
    cout << ret;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int k; scanf("%d",&k);
	vector<lint> a(k);
	rep(i,k) scanf("%lld",&a[i]);

	lint mn=2,mx=2;
	for(int i=k-1;i>=0;i--){
		mn=(mn+a[i]-1)/a[i]*a[i];
		mx=mx/a[i]*a[i]+(a[i]-1);
		if(mn>mx) return puts("-1"),0;
	}
	printf("%lld %lld\n",mn,mx);

	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	String w = sc.next();
      	int[] eng = new int[26];
      	boolean res = true;
      	for(int i = 0; i < w.length(); i++){
        	eng[w.charAt(i)-'a']++;
        }
      	for(int i = 0; i < 26; i++){
        	if(eng[i] % 2 != 0) res = false;
        }
      	if(res){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 35760
import kotlin.math.sqrt
fun main() {

// 数値
    val n = readLine()!!.toInt()

    val m = sqrt(n.toDouble()).toInt()
    var an = 0
    val ary = Array(n){0}
    for (i in 1..100) {
        for (j in 1..100) {
            for (k in 1..100) {
                val sum = i * i + j * j + k * k + i * j + j * k + k * i
                if (sum<=n){
                    ary[sum-1]+=1
                }
            }
        }
    }
    for (i in ary) {
        println(i)
    }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

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

  string s;
  cin >> s;
  rep(i, 0, s.size())  {
    cout << "x";
  }
  cout << endl;

  return 0;
};


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int i,o=0,ans=0;
  for(i=10;i<100000000;i*=100) {
    if(N < i/10) {
      i=100000000;
    } else if(N < i-1) {
      ans += N-o;
      i=100000000;
    } else {
      ans += i-o-1;
    }
    o=o*100+99;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()] + [0]

c = 0
leave = 0

for i, j in zip(a, b):
    atk = j + leave
    c += min(i, atk)
    if leave > i:
        leave = j
    elif leave + j > i:
        leave = j - (i - leave)
    else:
        leave = 0
print(c)


Measured memory_bytes: 19648
def solve():
    weightNum = int(input())
    weights = [int(x) for x in input().split()]

    abses = []
    for i in range(1, weightNum):
        s1 = sum(weights[:i])
        s2 = sum(weights[i:])
        abses.append(abs(s1 - s2))
    print(min(abses))
solve()

Measured memory_bytes: 2940
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def abc132d_blue_and_red_balls():
    n, k = map(int, input().split())
    for i in range(1, k+1):
        if n+1-k< i:
            print(0)
            continue
        print((cmb(n+1-k, i)*cmb(k-1, i - 1))%(pow(10, 9)+7))
abc132d_blue_and_red_balls()

Measured memory_bytes: 75096
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    map<int, int> ansmap;
    for (int i = 0; i < n - 1; i++) {
        for (int j = 1; j < n; j++) {
            int dist = j - i;
            if ((i < x && j <= x) || (i >= y && j > y)) {
                // X-Yの区間に入らない場合はそのまま。
            } else {
                dist = min(abs(i - x) + abs(y - j) + 1, dist);
            }
            if (ansmap.count(dist) > 0) {
                ansmap[dist]++;
            } else {
                ansmap[dist] = 1;
            }
        }
    }
    for (int i = 1; i < n; i++) {
        if (ansmap.count(i) > 0) {
            cout << ansmap[i] << endl;
        } else {
            cout << 0 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 200100;
const long long MOD = 1e9 + 7;
long long n, a[N], f[N * 10], ans, lcm = 1;

long long powMod(long long base, long long exp) {
	if(exp == 0)return 1;
	long long tmp = powMod(base, exp / 2);
	tmp = (1LL * tmp * tmp) % MOD;
	if(exp % 2) tmp = (tmp * base) % MOD;
	return tmp;
}


long long invMod(long long a) {
	return powMod(a, MOD - 2);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
		long long g = a[i];
		for(long long j = 2; j * j <= g; j++) {
			long long cnt = 0;
			while(g % j == 0)
				g /= j, cnt++;
			f[j] = max(f[j], cnt);
		}
		if(g != 1) f[g] = max(f[g], 1LL);
	}

	dbg_v(f, 10);

	for(int i = 1; i <= 1000000; i++) {
		lcm *= powMod(i, f[i]);
		lcm %= MOD;
	}

	for(long long i = 1; i <= n; i++) {
		long long g = a[i];
		long long tmp_ans = lcm * invMod(a[i]);
		tmp_ans %= MOD;
		ans += tmp_ans;
		ans %= MOD;
	}

	cout << ans << '\n';
}	




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

signed main() {
  int n; cin >> n;
  int maxN = 1;
  for(int i = 1; i*i <= n; i++) {
    maxN = max(maxN, i*i);
  }
  cout << maxN << endl;
  return 0;
}


Measured memory_bytes: 256
////=====BIsmillahir Rahmanir Rahim =====////

/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
         Comilla University

*/
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
#define fi 2*acos(0.0)
#define ee 2.71828
#define ll  long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define edl printf("\n")
#define infinity 1e16
#define mod 1000000007
#define cn continue
#define csprint1 printf("Case %lld: ", cs++)
#define csprint2 printf("Case %lld:\n", cs++)
#define sf(a) scanf("%lld", &a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define all(v) v.begin(),v.end()
#define pfn(a) printf("%lld\n",a)
#define pfs(a) printf("%lld ",a)

// using namespace __gnu_pbds;
using namespace std;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<pl> vpi;
typedef vector<pl> vpl;
// typedef tree<pair<ll, int> , null_type, less<pair<ll, int> >, rb_tree_tag, tree_order_statistics_node_update> ost;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a <<","<< spc;
    err(++it, args...);
    cout<<edl;
}
///Bit manipulation

bool checkbit(int mask,int bit){return mask & (1<<bit);}
int setbit(int mask,int bit){ return mask | (1<<bit) ; }
int clearbit(int mask,int bit){return mask & ~(1<<bit);}
int togglebit(int mask,int bit){return mask ^ (1<<bit);}
int bitno(int mask) {return (int)__builtin_popcount(mask);}

/*----------------------Graph Moves----------------*/
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

///=====================================///
const long long maX=1e5+5;
string str="codeforces";
int main(){
        ll n;
        sf(n);
        ll cc=0;
        bool ok=false;
        for(ll i=0;i<n;i++){
            ll x,y;
            sff(x,y);
            if(x==y){
                cc++;
            }
            else cc=0;
            if(cc>=3)ok=true;
        }
        if(ok)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3688
def calc(num_list) -> int:
    result = 1
    max = 10**18

    if 0 in num_list:
        return 0

    for num in num_list:
        result *= num
        if result > max:
            return -1
    return result

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

print(str(calc(num_list)))

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

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

  if (S[0] == S[1] && S[0] == S[2]  && S[0] == S[3]) cout << "No" << endl;
  else if(S[0] == S[1] && S[2] == S[3]) cout << "Yes" << endl;
  else if (S[0] == S[2] && S[1] == S[3]) cout << "Yes" << endl;
  else if (S[0] == S[3] && S[1] == S[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	int rmvsm=(n+1)-n%2;
	cout<<n*(n-1)/2-n/2<<endl;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if((i+j)!=rmvsm)
			{
				cout<<i<<' '<<j<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
def abc175_c_1():
    x, k, d = map(int, input().split())

    def solve(x, k, d):
        # Xを絶対値でプラスの値にし、0に近づける問題に置き換える
        x = abs(x)

        # (x // d)は0の手前まで移動するのに必要な回数。kの方が小さい場合はk回移動してしまえばよい
        if k < (x // d):
            return x - (k * d)
        # kのほうが大きい場合はそこから数回移動が必要
        else:
            # xからとりあえずx//d回は移動してOK
            current_x = x - d * (x // d)
            k = k - (x // d)

            # 結局ここが時間がかかるので終わらない。(10**15回とか探索しちゃう。)

            if (k % 2) == 0:
                # 残りの移動回数が偶数回なら移動を繰り返してその場所に戻ってくる
                return current_x
            else:
                # 奇数回の場合、偶数回移動を繰り返した後、もう一回だけ移動する。
                # return min(abs(current_x + d), abs(current_x - d))
                return abs(current_x - d)

    ans = solve(x, k, d)
    print(ans)

if __name__ == '__main__':
    abc175_c_1()

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
using namespace std;
typedef long long LL;
const int SIZE=50;

vector<string> vs;
string s;
int nums;
void solve(int now,bool isWant,int& times,bool abley[],bool used[],string nows){
	if(s.size()==now){
			nums++;
		if(times) {
			times--;
			vs.PB(nows);
		}
		return;
	}
	if((used[s[now]-'a']) && isWant){
		solve(now+1,isWant,times,abley,used,nows+(s[now]));			
	}
	if(!used[s[now]-'a'+1] && s[now]!='z'){
		used[s[now]-'a'+1]=true;
		solve(now+1,isWant,times,abley,used,nows+(char(s[now]+1)));
		used[s[now]-'a'+1]=false;	
	}
	if((used[s[now]-'a']) && !isWant){
		solve(now+1,isWant,times,abley,used,nows+(s[now]));			
	}
}
int main(){
	while(true){
		nums=0;		
		cin >> s;
		if(s=="#") break;
		vs.clear();
		bool abley[SIZE]={1,0},used[SIZE]={};
		used[0]=true;
		int x=5;
		solve(0,true,x,abley,used,string());
		x=5;
		solve(0,false,x,abley,used,string());
		sort(ALL(vs));
		vs.erase(unique(ALL(vs)),vs.end());
		cout << nums/2 << endl;
		REP(i,vs.size())
			if(i==0 || vs[i]!=vs[i-1])
				cout << vs[i] << endl;

	}
}

Measured memory_bytes: 3192
using System; 
using System.Text;
using System.Collections.Generic; 
using System.Linq; 
using E = System.Linq.Enumerable; 
class Program {
    static List<long>[] SNS;
    static long N; static void
    Main(string[] args) {
        //入力を受け取る
        var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            N = NM[0];
        var M = NM[1];
        //橋の関係を記録するリスト
        SNS = new List<long>[N + 1];
        for (long i = 0; i <= N; i++) {
            SNS[i] = new List<long>();
        }
        var AB = new long[M][];
        for(long i = 0; i < M; i++) {
            AB[i] =
            Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var A = AB[i][0];
            var B = AB[i][1];
            SNS[A].Add(B);
            SNS[B].Add(A);
            }
            //幅優先探索でSNS上の友達の友達（深さが2まで求める)
            var ans=0;
            for (long i = 1; i <= M; i++) {
              SNS[AB[i-1][0]].Remove(AB[i-1][1]);
SNS[AB[i-1][1]].Remove(AB[i-1][0]);
              //iの友人関係を調べ
              if(WFS(1)<N){
                ans++;
              }
              
SNS[AB[i-1][0]].Add(AB[i-1][1]);
SNS[AB[i-1][1]].Add(AB[i-1][0]);              
               }
               Console.WriteLine(ans);
     }
               
     //numは起点にする値         
     static long WFS(long num) {
         var depth = new long[N+1];
         var queue = new MyQueue();
         var count = 1L;
         queue.Enque(num);
         depth[num] = 1;
         while(!(queue.isEmpty())){ 
             var top = queue.Deque(); 
             foreach (long item in SNS[top]){
                 //探索済みか
                 if (depth[item] == 0){
                     depth[item] = depth[top] + 1;
                     queue.Enque(item);
                     count++;
                 }
             }
             
         }
         return count;
      } 
                   }
                   class MyQueue { public long[] datas = new long[100000]; public int enpoint = -1; public int depoint = -1; public void Enque(long data) { this.enpoint++; datas[this.enpoint] = data; } public long Deque() { this.depoint++; return datas[this.depoint]; } public bool isEmpty() { return (this.depoint == this.enpoint); } }


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

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

int N;
ll A[100010];
ll U[100010];
int par[100010];
vector<pii> mem;
vector<int> G[100010];
bool visit[100010] = {0},F = false;
int root;

void DFS(int v,int p,int d)
{
    if(visit[v])return;
    visit[v] = true;
    par[v] = p;
    mem.push_back(make_pair(d,v));
    for(int i = 0; i < G[v].size(); i++)if(G[v][i] != p)DFS(G[v][i],v,d + 1);
    return;
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%lld",A + i + 1);

    for(int i = 0; i < N - 1; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if(N == 2)
    {
        if(A[1] == A[2])printf("YES\n");
        else printf("NO\n");
        return 0;
    }
    for(int i = 1; i <= N; i++)
    {
        if(G[i].size() > 1)
        {
            root = i;
            DFS(i,-1,0);
            break;
        }
    }
    sort(mem.begin(),mem.end());
    reverse(mem.begin(),mem.end());
    for(int i = 0; i < N; i++)
    {
        int v = mem[i].second;
        if(G[v].size() == 1)
        {
            U[v] = A[v];
            continue;
        }
        ll sum = 0,MAX = 0,MIN = 100000000000;
        for(int i = 0; i < G[v].size(); i++)
        {
            if(par[v] == G[v][i])continue;
            sum += U[G[v][i]];
            MAX = max(MAX,U[G[v][i]]);
            if(U[G[v][i]] == -1 || A[v] < U[G[v][i]])F = true;
        }
        if(A[v] * 2 < sum || A[v] < A[v] * 2 - sum)U[v] = -1;
        else U[v] = A[v] * 2 - sum;
    }
    if(U[root] == 0 && !F)printf("YES\n");
    else printf("NO\n");
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  if ((N/10)%111 == 0) {
    cout << "Yes" << endl;
  }
  else if (N%1111 == 0) {
    cout << "Yes" << endl;
  }
  else if ((N%1000)%111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7; 

fn main(){
    let n: usize = read();
    let m: usize = read();
    let mut ab: Vec<Vec<usize>> = vec![vec![]; m];
    for _ in 0..n {
        let a: usize = read();
        let b: usize = read();
        if m >= a{
            ab[m - a].push(b);
        }
    }
    let mut q = BinaryHeap::new();
    let mut ans: usize = 0;
    for i in (0..m).rev(){
        for j in &ab[i]{
            q.push(*j);
        }
        if !q.is_empty(){
            ans += q.pop().unwrap();
        }
    } 
    println!("{}", ans);
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

using namespace std;

#define PI acos(-1.0)

int main() {
    int a, b, ang_c;
    cin >> a >> b >> ang_c;
    
    double deg_c = PI * ang_c / 180.0;
    double s = a * b * sin(deg_c) / 2.0;
    double l = a + b + sqrt(a * a + b * b - 2 * a * b * cos(deg_c));
    double h = b * sin(deg_c);

    printf("%lf\n%lf\n%lf\n", s, l, h);
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main(void) {

  int n;
  int m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    n -= a;
  }

  if (n < 0) {
    cout << -1 << endl;
  } else {
    cout << n << endl;
  }
  return 0;
}


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

int main (){
  int K,A,B;
  cin >> K >> A >> B;
  bool ans = false;
  for(int i = A; i <= B;i++){
    if( i % K == 0) ans = true;
  }
  if(ans) cout << "OK" << endl;
  else cout << "NG" << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

int dp[1000010][3];

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string n;
  cin>>n;
  int ans=0;
  int cnt=0;
  dp[0][0]=n[0]-'0';//sonomama
  dp[0][1]=11-(n[0]-'0');//kurisagarilast
  dp[0][2]=10-(n[0]-'0');//kurisagatitotyuu
  repi(i,1,n.size()){
    int num=n[i]-'0';
    dp[i][0]=min(dp[i-1][0]+num,dp[i-1][1]+num);
    dp[i][1]=min(dp[i-1][0]+11-num,dp[i-1][2]+10-num);
    dp[i][2]=min(dp[i-1][0]+10-num,dp[i-1][2]+9-num);
  }
  /* rep(i,n.size() ){
    rep(j,3){
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
    }*/
  cout<<min(dp[n.size()-1][0],dp[n.size()-1][1])<<endl;


  return 0;
}


Measured memory_bytes: 24860
N, K = map(int, input().split())
A = list(map(int, input().split()))

def is_ok(X):
    # 全部をX以下にするために切る回数 <= K
    cnt = 0
    for i in range(N):
        cnt += (A[i]-1)//X
    return cnt <= K
 
def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok
  
print(meguru_bisect(0, 10**9))

Measured memory_bytes: 30984
#break文を使わないで攻略したい
N, M = map(int, input().split())
lst = []
for i in range(N):
    lst.append([j for j in map(int, input().split())])
#値段が安い順番に並べ直す
lst = sorted(lst)
#最小必要経費
cost = 0
#持っているドリンクの本数
drink = 0
#店の個数だけまわる予定
for i in range(N):
    if (drink + lst[i][1]) <= M:
        drink += lst[i][1]
        cost += lst[i][0] * lst[i][1]
    else:
        cost += lst[i][0] * (M - drink)
        break
print(cost)

Measured memory_bytes: 22384
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {

    int n, k;
    cin >> n >> k;

    vector<int> len(n);
    for (int i = 0; i < n; i++)
        cin >> len[i];

    sort(len.begin(), len.end(), greater<int>());

    int sum = 0;

    for (int i = 0; i < k; i++) {
        sum += len[i];
    }

    cout << sum << endl;

    return 0;   

}


Measured memory_bytes: 256
/*

* author:mel0n
* le epic style 
*
*

*/

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0)
#define lli long long int
#define pi pair<int,int>
#define all(x) (x).begin(),(x).end()

using namespace std;

void update(vector <lli> &bit,lli val,lli n,lli p)
{

for(int i=p;i<=n;i+=i&(-i))
{
bit[i]+=val;
}

}




int main()
{
	lli n;
	cin>>n;
	vector <lli> a(n);
	vector <lli> st(100005,0);
	lli sum=0;
	for(int i=0;i<n;i++)
	{
	cin>>a[i];
	sum+=a[i];
	st[a[i]]++;
	}
        lli q;	
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		lli b,c;
		cin>>b>>c;
		sum+=(c-b)*st[b];
		st[c]+=st[b];
		st[b]=0;
		cout<<sum<<endl;
	}
	

return 0;
}



Measured memory_bytes: 4796
#include <bits/stdc++.h>
using namespace std;
#define db double
int main(){
  int i,n,j;
  cin>>n;
  db dp[n+1];
  memset(dp,0,sizeof(dp));
  dp[0]=1;
  for(i=1;i<=n;i++){
   db p;
   cin>>p;
   for(j=i;j>=0;j--)
     if(j==0) dp[j]=dp[j]*(1 - p);
     else dp[j]=dp[j-1]*p+dp[j]*(1 - p);
  }
  db ans=.0;
  for(i=n/2+1;i<=n;i++)
   ans+=dp[i];
  cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

const int MOD=1e9+7;
signed main() {
    int n;
    cin>>n;
    vector<int> T(n),A(n),M(n);
    vector<bool> ch1(n,false),ch2(n,false);
    cin>>T>>A;

    REP(i,n) {
        M[i]=min(T[i],A[i]);
    }
    ch1[0]=true;
    REPF(i,1,n) {
        if(T[i-1]<T[i]) ch1[i]=true;
    }
    ch2[n-1]=true;
    for(int i=n-2;i>=0;i--) {
        if(A[i]>A[i+1]) ch2[i]=true;
    }

    REP(i,n) {
        if((ch1[i] && T[i]>A[i]) || (ch2[i] && T[i]<A[i])) {
            cout<<0<<endl;
            return 0;
        }
    }

    int ans=1;
    REP(i,n) {
        if(!ch1[i] && !ch2[i]) {
            ans*=M[i];
            ans%=MOD;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2688
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

template <typename It>
vector<int> zAlgorithm(It s, It t) {
  int n = t - s;
  vector<int> z(n);
  if (n == 0) {
    return z;
  }

  int l = 0;
  z[0] = 0;
  for (int i = 1; i < n; i++) {
    int r = l + z[l];

    if (r > i + z[i - l]) {
      z[i] = z[i - l];
    } else {
      z[i] = max(0, r - i);
      l = i;
      for (int j = z[i]; i + j < n && s[i + j] == s[j]; j++) {
        z[i]++;
      }
    }
  }
  z[0] = n;

  return move(z);
}

const int INF = 500'000;
void dfs(int node, int root, const vector<int>& z, int n, int m,
         vector<bool>& isVisited, vector<int>& depth) {
  isVisited[node] = true;
  if (z[node + m] < m) {
    depth[node] = 0;
  } else {
    const int nxt = (node + m) % n;
    if (!isVisited[nxt]) {
      dfs(nxt, root, z, n, m, isVisited, depth);
    }
    if (nxt == root) {
      depth[node] = INF;
    } else {
      depth[node] = depth[nxt] + 1;
    }
  }
}

int main() {
  string s, t;
  cin >> s >> t;

  int n = (s.size() + t.size() + s.size() - 1) / s.size();

  string u(t);
  rep(i, n) { copy(s.begin(), s.end(), back_inserter(u)); }

  vector<int> z = zAlgorithm(u.begin(), u.end());

  vector<bool> isVisited(s.size(), false);
  vector<int> depth(s.size());
  int result = 0;
  rep(i, s.size()) {
    if (!isVisited[i]) {
      dfs(i, i, z, s.size(), t.size(), isVisited, depth);
    }
    result = max(result, depth[i]);
  }

  cout << (result >= INF ? -1 : result) << endl;
  return 0;
}

Measured memory_bytes: 52168
#include<iostream>
using namespace std;
int num[10];

int op[10][10];

int main() {
//	freopen("in","r",stdin);
	for(int i=1;i<=6;i++)
		cin>>num[i];

	op[1][2] = 3;
	op[1][3] = 5;
	op[1][4] = 2;
	op[1][5] = 4;

	op[2][1] = 4;
	op[2][4] = 6;
	op[2][3] = 1;
	op[2][6] = 3;

	op[3][2] = 6;
	op[3][1] = 2;
	op[3][6] = 5;
	op[3][5] = 1;

	op[4][1] = 5;
	op[4][5] = 6;
	op[4][6] = 2;
	op[4][2] = 1;

	op[5][1] = 3;
	op[5][3] = 6;
	op[5][4] = 1;
	op[5][6] = 4;

	op[6][2] = 4;
	op[6][3] = 2;
	op[6][4] = 5;
	op[6][5] = 3;

	int n; cin>>n;
	while(n--) {
		int a, b; cin>>a>>b;
		for(int i=1;i<=6;i++) 
			if(a==num[i]) {
				a = i; break;
			}

		for(int i=1;i<=6;i++) 
			if(b==num[i]) {
				b = i; break;
			}

		cout<<num[op[a][b]]<<endl;
	}

	return 0;
}


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

int main(){
string s;
bool flag=0;
cin >>s;
    for(int i=0; i<4; i++){
        if(s[i]==s[i+1]){
          cout <<"Bad" <<endl;
        flag=1;//Badが出力されたことを示す
           break;
        }
    }
        if(flag==0) cout <<"Good" <<endl;
return 0;
}

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

typedef long long ll;
typedef long double ld;

pair <int, int> hsh[10005];
map <pair <int, int>, bool> bio;

const int MOD1 = 1000000007;
const int MOD2 = 1000000009;

const int p = 41;

int add(int a, int b, int mod){
    return (a+b)%mod;
}

int mul(int a, int b, int mod){
    return ((ll)a*b)%mod;
}

int n;
string s;

bool check(int k){
    bio.clear();
    int trenp1 = 1, trenp2 = 1;
    int hsh1 = 0, hsh2 = 0;
    queue <pair <int, int>> q;
    for(int i=1; i<=k; i++){
        if(i < k) trenp1 = mul(trenp1, p, MOD1);
        if(i < k) trenp2 = mul(trenp2, p, MOD2);
        hsh1 = add(mul(hsh1, p, MOD1), s[i-1]-'a'+1, MOD1);
        hsh2 = add(mul(hsh2, p, MOD2), s[i-1]-'a'+1, MOD2);
        q.push({-1, -1});
    }
    q.pop();
    q.push({hsh1, hsh2});
    for(int r=k+1; r<=n; r++){
        pair <int, int> d = q.front();
        q.pop();
        //if(k == 2) cout << d.first << " " << d.second << endl;
        bio[d] = 1;
        int l = r-k;
        hsh1 = add(hsh1, MOD1-mul(trenp1, s[l-1]-'a'+1, MOD1), MOD1);
        hsh2 = add(hsh2, MOD2-mul(trenp2, s[l-1]-'a'+1, MOD2), MOD2);
        hsh1 = add(mul(hsh1, p, MOD1), s[r-1]-'a'+1, MOD1);
        hsh2 = add(mul(hsh2, p, MOD2), s[r-1]-'a'+1, MOD2);
        if(bio[{hsh1, hsh2}]) return 1;
        q.push({hsh1, hsh2});
    }
    return 0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    cin >> n;
    cin >> s;
    int res = 0, l = 1, r = n;
    while(l <= r){
        int mid = (l+r)/2;
        if(check(mid)){
            res = mid;
            l = mid+1;
        }
        else r = mid-1;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 640
//AtCoder ABC117 C - Streamline
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
#if LOCAL&0
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N,M; cin>>N>>M;
    vector<ll> xm(M);
    for(auto&& x:xm){
        cin>>x;
    }
    sort(xm.begin(),xm.end());
    vector<ll> dist(M-1);
    for(ll i=0;i<xm.size()-1;++i){
        dist[i]=xm[i+1]-xm[i];
    }
    sort(dist.begin(),dist.end(),greater<ll>());
    ll ans=0;
    for(ll i=N-1;i<dist.size();++i){
        ans+=dist[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,m,n) for (int i = m; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b;}
template<class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b;}
template<class T> void drop(const T &x) { std::cout<<x<<endl; exit(0);}
void debug_out() { std::cout << "\n";}
template<class T, class... Args> void debug_out(const T &x, const Args &... args) { std::cout<<x<< " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

struct InitIO{
  InitIO() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
  }
}init_io;

using P = pair<ll,ll>;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x; }
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  ll n;
  cin >> n;
  Sieve sieve(n+1);
  ll ans = 0;
  rep2(i, 1, n+1) {
    auto res = sieve.factor(i);
    ll temp = 1;
    for (auto&& p : res) {
      temp *= (p.second+1);
    }
    ans += temp*i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 46480
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

tmp = 0
for i in range(n - 1):
    if a[i + 1] - a[i] == 1:
        tmp += c[a[i] - 1]

print(sum(b) + tmp)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define  fastIO    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  endl        "\n";
#define  pi          2*acos(0.0)
#define  inf         LONG_MAX
#define  size        1e5

int main(){
    fastIO;
    //testCase
    string str;         cin>>str;
    char c[str.length()];
    strcpy(c, str.c_str());
    sort(c,(sizeof(c)/sizeof(c[0]))+c );
    //cout<<c<<endl;
    if(c[1]!=c[2] && c[0]==c[1] && c[2]==c[3]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3624
n = int(input())
t = [list(map(int, input().split())) for _ in range(n)]

t.sort(key=lambda x: x[1])

cnt = 0
flag = True

for i in t:
  cnt += i[0]

  if cnt > i[1]:
    flag = False
    break

print('Yes' if flag else 'No')


Measured memory_bytes: 53600
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;


int main() {
	int N;
	cin >> N;
	vector<float> A(N);
	float ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		ans += 1 / A[i];
	}
	cout << 1.0 / ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, s, n) for(int i = s; i < n; i++) 
typedef pair<int, int> P;

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    vector<int> state;
    if(s[0] == '0') state.push_back(0);
    rep(i, 0, n) {
        int j = i;
        while(j < n && s[i] == s[j]) j++;
        state.push_back(j-i);
        i = j-1;
    }
    if(s.back() == '0') state.push_back(0);

    vector<int> sum(state.size()+1, 0);
    rep(i, 0, state.size()) {
        sum[i+1] = sum[i]+state[i];
    }
    int ans = 0;
    for(int left = 0; left < sum.size(); left += 2) {
        int right = left+2*k+1;
        if(right >= sum.size()) right = sum.size()-1;
        ans = max(ans, sum[right]-sum[left]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1272
#include<stdio.h>

#define WHITE 1
#define GRAY 2
#define BLACK 3

int V,color[101],d[101],f[101],time,a[101][101];

void visit(int u){
  int i;
  color[u] = GRAY;
  d[u] = ++ time;
  for(i=1;i<=V;i++){
    if(a[u][i]==1 &&color[i] == WHITE){
      visit(i);
    }
  }
  color[u] = BLACK;
  f[u] = ++time;
}

void dfs(void){
  int u;
  for(u=1;u<=V;u++){
    color[u] = WHITE;
  }
  time = 0;
  for(u=1;u<=V;u++){
    if(color[u] == WHITE){
      visit(u);
    }
  }
}
int main(){
  int i,j,n,id,k;
  scanf("%d",&V);
  for(i=1;i<=V;i++){
    for(j=1;j<=V;j++){
      a[i][j] =0;
    }
  }
  for(i=1;i<=V;i++){
    scanf("%d%d",&id,&n);
    if(n!=0){
      for(j=0;j<n;j++){
        scanf("%d",&k);
        a[i][k] = 1;
      }
    }
  }
  for(i=1;i<=V;i++){
    dfs();
  }
  for(i=1;i<=V;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define rep(i, v)        for(int i=0;i<(v).sz;++i)
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prii(a, b)	printf("%d %d\n",a, b)
#define DB1(a)          std::cout<<#a<<"="<<(a)<<endl
#define DB2(a,b)        std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl
#define DB3(a,b,c)      std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<endl
#define DB4(a,b,c,d)    std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<endl
#define DB5(a,b,c,d,e)  std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<endl
typedef pair<int, int> pii;
typedef long long ll;
const ll  inf = 1000000000000000000LL;
const double EPS = 1e-9;
const ll mod = 1000000007ll;
#define PI acos(-1)

const int maxn = 300500;

int s[maxn];

int main(){
	int n, a, b; scii(n, a); sci(b);
	pri(min(b, a*n));
}



Measured memory_bytes: 256
NM=list(map(int,input().split()))

Hlist=list(map(int,input().split()))

A=[0]*NM[0]
for i in range (NM[1]):
    AB=list(map(int,input().split()))
    if Hlist[AB[0]-1]<=Hlist[AB[1]-1]:
        A[AB[0]-1]=1
    if Hlist[AB[1]-1]<=Hlist[AB[0]-1]:
        A[AB[1]-1]=1
ans=NM[0]-sum(A)
print(ans)

Measured memory_bytes: 20120
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;


int max_dimention(const vvi &tree)
{
    int r = 0;
    for (const vi &n : tree)
    {
        r = max<int>(r, n.size());      
    }
    return r;
}

pair<int,int> edge(int a, int b)
{
    if (a < b)
        return {a, b};
    else
        return {b, a};
}

void dfs(const vvi &tree, map<pair<int,int>,int> &edge_color, int K, int current, int parent)
{
    const vi &node = tree[current];
    for (int i = 0, c = 0; i < (int)node.size(); ++i)
    {
        int next = node[i];
        if (next == parent) continue;
        if (parent >= 0 && c == edge_color[edge(current, parent)]) ++c;

        edge_color[edge(current, next)] = c++;
        dfs(tree, edge_color, K, next, current);
    }
}

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

    vvi tree(N);
    vector<pair<int,int>> edges(N-1);
    map<pair<int,int>,int> edge_color;

    for (int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        --a; --b;

        tree[a].push_back(b);
        tree[b].push_back(a);

        auto e = edge(a,b);
        edges[i] = e;
        edge_color[e] = -1;
    }

    int K = max_dimention(tree);
    dfs(tree, edge_color, K, 0, -1);

    cout << K << endl;
    for (auto e : edges)
        cout << (edge_color[e] + 1) << endl;
}

Measured memory_bytes: 16768
while n = gets.to_i
  break if n == 0
  arr = gets.split(' ').map(&:to_i)

  count = 0
  0.upto(n-1) do |i|
    min_j = i
    i.upto(n-1) do |j|
      min_j = j if arr[min_j] > arr[j]
    end
    if min_j != i
      arr[i], arr[min_j] = arr[min_j], arr[i]
      count += 1
    end
  end
  puts arr.join(' ')
  puts count
end

Measured memory_bytes: 8596
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int MOD=1000000007;
const double PI = 3.1415926535897932384626433;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

vector<long long> enum_divisors(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N/i != i) res.push_back(N/i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

ll zyou(ll x,ll n){
	ll y=1;
	rep(i,0,n){
		y*=x;
	}
	return y;
}

ll gozyou(ll a){
	ll tmp=a;
	rep(i,0,4)tmp*=a;
	return tmp;
}

int main() {
	ll x;
	cin>>x;
	rep(i,0,1000){
		rep(j,-1000,1000){
			if(gozyou(i)-gozyou(j)==x){
				print(i<<" "<<j);
				return 0;
			}
		}
	}
}

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

using namespace std;

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

    vector<int> L(M);
    vector<int> R(M);

    int maxL = 0,minR = 1000001;

    for (int  i = 0; i < M; i++){
        cin >> L[i] >> R[i];
        maxL = max(maxL,L[i]);
        minR = min(minR,R[i]);
    }

    //cout << maxL << " R = " << minR << endl;
    
    if(minR < maxL){
        cout << 0 << endl;
    }
    else{
        cout << minR - maxL + 1;
    }
    return 0;

}
    

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int d;
int c[26];
int s[365][26];
int last[26] = {};  // 各コンテストを最後に開催した日
int t[365] = { 0 };  // 各日に開催するコンテスト

int main()
{
    cin >> d;
    rep(i, 26) cin >> c[i];
    rep(i, d) rep(j, 26) cin >> s[i][j];

    rep(i, d) {
        int max_v = -INF;
        rep(j, 26) {  // どのコンテストを開催するか決める
            int v = 0;
            v += s[i][j];  // 満足度上昇
            int m = min(d - i - 1, 13);
            rep(l, m) {
                rep(k, 26) {
                    if (k == j) v -= c[k] * (l);
                    v -= c[k] * (i + 1 + l - last[k]);  // 満足度低下
                }
            }
            if (v > max_v) {
                max_v = v;
                t[i] = j + 1;  // 開催するコンテストを格納
            }
        }
        last[t[i] - 1] = i + 1;  // 最後に開催した日を格納
    }

    rep(i, d) {
        cout << t[i] << endl;
    }

    // スコア計算
    //int score = 0;
    //int last_[26] = {};
    //rep(i, d){
    //    score += s[i][t[i]];
    //    rep(j, 26) {
    //        score -= c[j] * (i + 1 - last_[j]);
    //    }
    //    last_[t[i] - 1] = i + 1;
    //}
    //cout << "score=" << score << endl;
    return 0;
}


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

int main() {
	int K, ans = 0;
	cin >> K;
	if (K % 2 == 0) {
		ans = (K / 2)*(K / 2);
	}
	else {
		ans = (K / 2)*(K / 2 + 1);
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
import collections

N = int(input())
W = [input() for i in range(N)]
w = collections.Counter(W)
if len(w.values()) != len(W):
  print('No')
else:
  for i in range(len(W)-1):
    s = W[i]
    tmp = s[len(s)-1]
    s_next = W[i+1]
    if tmp != s_next[0]:
      print('No')
      break
  else:
    print('Yes')


Measured memory_bytes: 3316