akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}

vector<int> calc(vector<vector<ll>> &G){//2部グラフ判定 res[0]=-1なら2部グラフじゃない
  vector<int> res(G.size(),-1);
  vector<bool> did(G.size(),false);
  int n = G.size();
  for(int i=0;i<n;i++){
    if(did[i])continue;
    res[i] = 0;
    queue<int> q;
    q.push(i);
    did[i] = true;
    while(q.size()){
      int from = q.front();
      q.pop();
      for(auto to:G[from]){
        if(did[to] && res[from]==res[to]){
          res[0] = -1;
          return res;
        }else if(not did[to]){
          q.push(to);
          res[to] = 1 - res[from];
          did[to] = true;
        }
      }
    }
  }
  return res;
}

int main(){
  ll n,m;
  cin >> n >> m;
  vector<vector<ll>> G(n);
  FOR(i,0,m){
    ll a,b;
    cin >> a >> b;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  auto res = calc(G);
  if(res[0]>-1){
    ll b=0,w=0;
    b = count(res.begin(), res.end(),1);
    w = count(res.begin(), res.end(),0);
    ll ans = b*w-m;
    cout << ans << endl;
  }else{
    ll ans = n*(n-1)/2-m;
    cout << ans << endl;
  }
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int A,B;
    cin>>A>>B;

    int ans=0;
    int x=1;
    while(true){
        if(x>=B){cout<<ans<<endl;return 0;}
        ans++;
        x+=A-1;
    }
    

    



}




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

int n, m;
int h[200005];
set<int> s;

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> h[i];
	for (int i = 1; i <= m; i++)
	{
		int a, b;
		cin >> a >> b;
		if (h[a] <= h[b]) s.insert(a);
		if (h[a] >= h[b]) s.insert(b);
	}
	cout << n - s.size();
	return 0;
}


Measured memory_bytes: 6628
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

int trans(int x, int y) {
	if (x > y) swap(x, y);
	return x * 1000 + y;
}

vector<int> topological_sort(int n, vector<vector<int>> graph) {
	vector<int> indegree(n);
	for (int i = 0; i < n; i++) {
		for (int to : graph[i]) {
			indegree[to]++;
		}
	}
	vector<int> res;
	queue<int> que;
	for (int i = 0; i < n; i++) if (indegree[i] == 0) que.push(i);
	while (!que.empty()) {
		int ver = que.front(); que.pop();
		res.push_back(ver);
		for (int i : graph[ver]) {
			indegree[i]--;
			if (indegree[i] == 0) que.push(i);
		}
	}
	return res;
}

vector<vector<int>> graph(1000010, vector<int>());
vector<int> ans(1000010, 1);

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	rep(i, n) {
		vector<int> a(n - 1);
		rep(j, n - 1) {
			cin >> a[j];
			a[j]--;
		}
		rep(j, n - 2) graph[trans(i, a[j + 1])].pb(trans(i, a[j]));
	}
	vector<int> order = topological_sort(1000 * n, graph);
	if (order.size() != 1000 * n) {
		cout << -1 << '\n';
		return 0;
	}
	rep(i, 1000 * n) {
		for (int nxt : graph[order[i]]) {
			chmax(ans[nxt], ans[order[i]] + 1);
		}
	}
	int res = 0;
	rep(i, 1000 * n) chmax(res, ans[i]);
	cout << res << '\n';
}

Measured memory_bytes: 94324
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007
int acs(const void* a, const void* b) { return *(int*)a - *(int*)b; } //1,2,3,4
int des(const void* a, const void* b) { return *(int*)b - *(int*)a; } 
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } //a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } //aaa,aab
//temmie_のsnippet

typedef struct BC { int b; int c; }BC;
int cmp_BC(const void* a, const void* b) { return ((BC*)b)->c - ((BC*)a)->c; }//BCのcの大きい方から
#define N 100009//提出時確認
int main() {
	int n,m,x=0,a[N]; LL ans=0; BC q[N];
	scanf("%d%d",&n,&m);
	rep(i,n)scanf("%d",a+i);
	rep(i,m)scanf("%d%d",&q[i].b,&q[i].c);

	qsort(a,n,sizeof(int),acs);//aは小さい方から
	qsort(q,m,sizeof(BC),cmp_BC);//cは大きい方から

	rep(i,m)rep(j,q[i].b){if(q[i].c<=a[x])break;a[x++]=q[i].c;}//書換
	rep(i,n)ans+=(LL)a[i];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2164
#include <iostream>
#include <algorithm>
#include <string>
const int maxN = 2e5 + 10;
using namespace std;

string s;
int cnt[2019];

int main()
{
    int curr = 0;
    int base = 1;
    int res = 0;
    fill(cnt, cnt + 2019 + 1, 0);
    cnt[0] = 1;
    cin >> s;
    for(int i = s.length() - 1; i >= 0; --i)
    {
        curr = (curr + (s[i] - '0') * base) % 2019;
        //cout << curr << " " << cnt[curr] << endl;
        res += cnt[curr];
        ++cnt[curr];
        base = base * 10 % 2019;
    }

    cout << res;
}


Measured memory_bytes: 3464
package main

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

func solve() {
	n, k := getInt(), getInt()
	as := getIntSlice(k)

	isLiked := func(n int) bool {
		ret := true
	L:
		for ; n > 0; n /= 10 {
			x := n % 10
			for _, a := range as {
				if x == a {
					ret = false
					break L
				}
			}
		}
		return ret
	}

	ans := 0
	for ; ; n++ {
		if isLiked(n) {
			ans = n
			break
		}
	}

	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,x;
int a[100005],ap = 1;
int b[100005],bp = 1;
char in[100005];

int main()
{
    scanf("%s",&in);
    n = strlen(in);
    for(int i = 0;i < n;i++)
    {
        x = in[i]-'0'
        ;
        if(i % 2) a[x]++;
        else b[x]++;
    }
    int ma = 0,mb = 0,la = 0,lb = 0,pa,pb;
    for(int i = 0;i <= 1;i++)
    {
        //if(a[i] > 0) cout << i << " " << a[i] << "\n";
        if(ma < a[i])
        {
            la = ma;
            ma = a[i];
            pa = i;
        }
        else if(la < a[i])
        {
            la = a[i];
        }
        if(mb < b[i])
        {
            lb = mb;
            mb = b[i];
            pb = i;
        }
        else if(lb < b[i])
        {
            lb = b[i];
        }
    }
    if(pa == pb)
    {
        printf("%d",min(n-ma-lb,n-la-mb));
    }
    else
    {
        printf("%d",n-ma-mb);
    }
}


Measured memory_bytes: 384
N = int(input())
L = [int(x) for x in input().split()]
max_L = max(L)
idx_max_L = L.index(max_L)
rest_sum_L = 0
for i in range(N):
  if i != idx_max_L:
    rest_sum_L += L[i]
 
if rest_sum_L > max_L:
  print("Yes")
else:
  print("No")

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

int h, w, k, c;
int ans;
std::vector<std::vector<char>> vec;

int main() {
    std::cin >> h >> w >> k;
    vec.assign(h, std::vector<char>(w, 'A'));
    ans = 0;
    for (int i = 0; i < h; i++) {
        for (int r = 0; r < w; r++) {
            std::cin >> vec[i][r];
        }
    }
    for (int i = 0; i < (1 << h); i++) {
        for (int r = 0; r < (1 << w); r++) {
            c = 0;
            for (int t = 0; t < h; t++) {
                for (int s = 0; s < w; s++) {
                    if (((i >> t) & 1) && ((r >> s) & 1) && vec[t][s] == '#') {
                        c++;
                    }
                }
            }
            if (c == k) {
                ans++;
            }
        }
    }
    std::cout << ans << std::endl;
    
}

Measured memory_bytes: 3640
#include <stdio.h>
 
#define MAX 100001
#define max(a,b) ((a) < (b) ? (b) : (a))
 
int par[MAX],sib[MAX],deg[MAX];
int height[MAX],dep[MAX];
 
void init(int);
int depth(int,int);
 
int main(){
  int n,i,id,l,r;
 
  scanf("%d" ,&n); 
  init(n);  
 
  for(i = 0 ; i < n ; i++){
    scanf("%d%d%d" ,&id ,&l ,&r);
 
    if(l != -1){
      par[l] = id;
      deg[id]++;
    }
    if(r != -1){
      par[r] = id;
      deg[id]++;
    }
    if(l != -1 && r != -1){
      sib[l] = r;
      sib[r] = l;
    }
  }
 
  for(i = 0 ; i < n ; i++){
    dep[i] = depth(i,0);
  }
 
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, sibling = %d, "
       ,i, par[i], sib[i]);
 
    printf("degree = %d, depth = %d, height = %d, "
       , deg[i], dep[i], height[i]);
     
    if(par[i] == -1){
      printf("root\n");
    }else if(deg[i] != 0){
      printf("internal node\n");
    }else{
      printf("leaf\n");
    }
  }
 
  return 0;
}
 
void init(int n){
  int i;
 
  for(i = 0 ; i < n ; i++){
    par[i] = sib[i] = -1;
    deg[i] = height[i] = 0;
  }
}
 
int depth(int x,int dep){
  height[x] = max(height[x],dep);
  if(par[x] == -1){
    return dep;
  }else{
    return depth(par[x],dep+1);
  }
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    int X = A.at(0);
    int Y = A.at(1);
    int Z = X % Y;
    int count;

    for (int i = 1; i < N; i++) {
      count = 0;
      while (count == 0){
        if (Z == 0){
          if (i != N-1){
            X = A.at(i+1);
            Z = X % Y;
          }
          count++;
        }
        else {
          X = Y;
          Y = Z;
          Z = X % Y;
        }
      }
    }
    cout << Y << endl;
}
    



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

const int PrimeMax = 1000001;
int is_prime[PrimeMax];
void Eratosthenes(int N){
  for(int i = 0; i < N; i++){
    is_prime[i] = 1;
  }
  is_prime[1] = 0;
  for(int i = 2; i*i < N ; i++){
    if(is_prime[i]){
      for(int j = 0; i * (j + 2) < N; j++){
        is_prime[i *(j + 2)] = 0;
      }
    }
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  Eratosthenes(PrimeMax);
  vary(int,v,1,0);
  for(int i = 0,j = 0; i < 10001 && j < PrimeMax; ++ j){
    if(is_prime[j] != 0){
      v.pb(j + v[i]);
      ++i;
    }
  }
  int a;
  while(cin >> a){
    if(a == 0) break;
    cout << v[a+1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 7040
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
    int T;
    cin >> T;
    vector<bool> ans(T);

    rep(i, T) {
        ll A, B, C, D;
        cin >> A >> B >> C >> D;

        if (A < B || D < B) {
            ans[i] = false;
            continue;
        }

        // B <= A && B <= D

        if (A <= C) {
            ans[i] = true;
            continue;
        }

        if (B == C) {
            ans[i] = true;
            continue;
        }

        // B < C < A

        // x <= C
        ll E = ((A - C) + (B - 1)) / B;
        ll F = A - E * B;
        if (F < 0) {
            ans[i] = false;
            continue;
        }

        if (B == D) {
            ans[i] = true;
            continue;
        }
        else {
            // D > B

            ll g = gcd(B, D % B);
            ll M = B - g + (F % g);

            if (M > C) {
                ans[i] = false;
            }
            else {
                ans[i] = true;
            }

            continue;
        }
    }

    for (bool b : ans) {
        write(b ? "Yes" : "No");
    }
}

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

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

	int l = 0, r = s.size() - 1;
	bool can = true;
	int res = 0;
	int cnt = 0;
	while ((r > l) || (cnt++ > 1e8)) {
		if (s[l] == s[r]) {
			++l;
			--r;
		} else if (s[l] == 'x') {
			++l;
			++res;
		} else if (s[r] == 'x') {
			--r;
			++res;
		} else {
			can = false;
			break;
		}
	}

	if (can) { cout << res << endl; }
	else { cout << -1 << endl; }

	return 0;
}


Measured memory_bytes: 512
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
#####################################
def convert(x):
    if x==0:
        return "0"
    s=""
    while(x):
        r=x%2
        x//=2
        s=str(r)+s
    return s
def binary(m,size):
    s=convert(m)
    s=(size-len(s))*"0"+s
    return s
r,c,k=INPUT()
A=[]
for i in range(r):
    x=input()
    A.append(list(x))

rowblack=[]#all the sum of the rows r
for i in range(r):
    sum=0
    for j in range(c):
        if A[i][j]=="#":
            sum+=1
    rowblack.append(sum)
columnblack=[]
for i in range(c):
    sum=0
    for j in range(r):
        if A[j][i]=="#":
            sum+=1
    columnblack.append(sum)

Rows=[]
for i in range(2**r):
    Rows.append(binary(i,r))
Columns=[]
for j in range(2**c):
    Columns.append(binary(j,c))

ans=0
def count(l,m,A):
    c=0
    for i in range(len(l)):
        if int(l[i])==0:
            for j in range(len(m)):
                if int(m[j])==0:
                    if A[i][j]=="#":
                        c+=1
    #print(c)
    return c

for i in range(len(Rows)):
    for j in range(len(Columns)):
        if count(Rows[i],Columns[j],A)==k:
            ans+=1
print(ans)


Measured memory_bytes: 68768
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int h = vs[0];
			int w = vs[1];

			maze = new string[h];
			for (int i = 0; i < h; i++) {
				maze[i] = Console.ReadLine();
			}

			int ans = 0;
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					if (maze[y][x] == '.') {
						ans = Math.Max(ans, Search(maze, w, h, x, y));
					}
				}
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}

		static string[] maze;
		static Queue<int[]> queue = new Queue<int[]>();
		static int Search(string[] maze, int w, int h, int x, int y)
		{
			int result = 0;
			int[,] tmp = new int[w, h];
			tmp[x, y] = 1;
			queue.Enqueue(new int[] { x, y });
			while (queue.Count > 0) {
				var point = queue.Dequeue();
				foreach (var item in new int[][] { new int[] { 1, 0 }, new int[] { -1, 0 }, new int[] { 0, 1 }, new int[] { 0, -1 } }) {
					int x1 = point[0];
					int y1 = point[1];
					int x2 = x1 + item[0];
					int y2 = y1 + item[1];
					if (0 <= x2 && x2 < w && 0 <= y2 && y2 < h && maze[y2][x2] == '.' && tmp[x2, y2] == 0) {
						tmp[x2, y2] = tmp[x1, y1] + 1;
						result = tmp[x1, y1] + 1;
						queue.Enqueue(new int[] { x2, y2 });
					}
				}
			}
			//System.Diagnostics.Debug.WriteLine($"{x},{y}");
			//for (int i = 0; i < h; i++) {
			//	for (int j = 0; j < w; j++) {
			//		System.Diagnostics.Debug.Write($"{tmp[j, i]} ");
			//	}
			//	System.Diagnostics.Debug.WriteLine("");
			//}
			return result - 1;
		}

	}
}


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

int used[105];
int main(){
    int n,k;
    cin>>n>>k;
    rep(i,k){
        int d;
        cin>>d;
        rep(j,d){
            int tmp; cin>>tmp;
            used[tmp-1]+=1;
        }
    }
    int ans=0;
    rep(i,n){
        if(used[i]==0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

struct Combination
{
    int maxn;
    vector<ll> fmemo;
    vector<ll> imemo;
    vector<ll> ifmemo;
    
    Combination(int maxn) : maxn(maxn){
        fmemo.resize(maxn + 1);
        imemo.resize(maxn + 1);
        ifmemo.resize(maxn + 1);
        for(ll i = 1; i <= maxn; i++){
            imemo[i] = modpow(i, MOD - 2);
        }
    }

    ll fact(ll n){
        if(n == 0) return 1;
        if(fmemo[n]) return fmemo[n];
        return fmemo[n] = n * fact(n - 1) % MOD;
    }

    ll ifact(ll n){
        if(n == 0) return 1;
        if(ifmemo[n]) return ifmemo[n];
        return ifmemo[n] = imemo[n] * ifact(n - 1) % MOD;
    }

    ll com(ll n, ll k){
        if(k > n) return 0;
        if(k < 0) return 0;
        if(n < 0) return 0;
        if(k == n || k == 0) return 1;
        return (fact(n) * ifact(k) % MOD) * ifact(n - k) % MOD;
    }
};

ll dp[3002][3002];
int l[3002], r[3002];
int b[3002];

int main()
{
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    l[0] = r[0] = -1;
    for(int i = 1; i <= m; i++){
        cin >> l[i] >> r[i];
        l[i]--;
        if(i){
            if(r[i] <= r[i - 1]){
                m--;
                i--;
            }
            else if(l[i] == l[i - 1]){
                r[i - 1] = r[i];
                m--;
                i--;
            }
        }
    }
    l[m + 1] = r[m + 1] = MOD;
    for(int i = 1; i <= n; i++){
        b[i] = b[i - 1] + (s[i - 1] - '0');
    }
    Combination com(n);
    dp[0][0] = 1;
    for(int i = 1; i <= m; i++){
        int d = b[r[i]] - b[max(r[i - 1], l[i])];
        for(int j = 0; j <= max(0, r[i] - l[i + 1]); j++){
            for(int k = 0; k <= max(0, r[i - 1] - l[i]); k++){
                dp[i][j] = (dp[i][j] + dp[i - 1][k] * com.com(min(l[i + 1], r[i]) - l[i], d + k - j) % MOD) % MOD;
            }
        }
    }
    cout << dp[m][0] << endl;
}


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

using namespace std;

typedef long long ll;

int N, K;
int A[100010];
ll sums[3][100010];
int main(){

    cin >> N >> K;
    for(int i = 0; i < N; i++) cin >> A[i];
    // 累積和を計算
    for(int i = 0; i < N; i++) sums[0][i+1] = sums[0][i] + A[i];
    // 左から見た累積和を計算(pos intのみ)
    for(int i = 0; i < N; i++) sums[1][i+1] = sums[1][i] + max(0, A[i]);
    // 右からみた累積和を計算(pos intのみ)
    for(int i = N - 1; i >= 0; i--) sums[2][i] = sums[2][i+1] + max(0, A[i]);

    ll ans = 0;
    for(int k = 0; k + K <= N; k++){
        // [0, k), [k, k + K), [k + K, N) に分割して計算
        ll sum = sums[1][k] + sums[2][k + K] + max(sums[0][k+K] - sums[0][k], 0LL);
        ans = max(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
    char c;
    cin >> c;

  if ('A' <= c && c <= 'Z') {
    cout << "A" << endl;
  }
  else {
    cout << "a" << endl;
  }    
    return 0;
}

Measured memory_bytes: 3628
import sys
import copy
import math
import itertools
import numpy as np
l = [int(c) for c in input().split()]
N=l[0]
M=l[1]
LR=[list(map(int,input().split())) for c in range(M)]
small = 0
large = N
for i in range(M):
    if small<LR[i][0]:
        small=LR[i][0]
    
    if large>LR[i][1]:
        large=LR[i][1]

if  small <= large:
    print(large-small+1)
else:
    print(0)

Measured memory_bytes: 45124
#include <bits/stdc++.h>
#include<vector>
#define int long long
using namespace std;
bool ispalindrome(string& s)
{
    int i=0;
    int j=s.size()-1;
    while(i<=j)
        if(s[i++]!=s[j--])
        return false;
    return true;
}
int modPow(int a,int b,int mod)
{
    while(b>1)
    {
        if(b%2==0)
        {
            a=a*a%mod;
            b/=2;
        }
        else
            return a*modPow(a,b-1,mod)%mod;
    }
    return a;

}
bool prime[2001];
void sieve()
{
    prime[1]=false;
    for(int i=2;i*i<2001;i++)
    {
        if(prime[i])
        {
            for(int j=i*i;j<2001;j+=i)
                prime[j]=false;
        }
    }
}

signed main() {
	//code

	int n,k;
	cin>>n>>k;
	int mod=998244353;
	vector<pair<int,int> > a;
	for(int i=0;i<k;i++){
        int x,y;
        cin>>x>>y;
        a.push_back({x,y});
	}
	int dp[n+1]={0};
	dp[1]=1;
	for(int i=2;i<=n;i++)
      {
          for(int j=0;j<k;j++)
          {
              int l=max((int)1,i-a[j].second);
              int r=i-a[j].first;
              if(r>=l)
              {
                  dp[i]+=dp[r]-dp[l-1];
                  dp[i]=dp[i]%mod;
                  dp[i]+=mod;
                  dp[i]%=mod;
              }
          }
          if(i<n)
          {dp[i]+=dp[i-1];
          dp[i]=dp[i]%mod;}
      }

    cout<<dp[n]<<endl;
}


Measured memory_bytes: 5184
#!/usr/bin/env python3
import sys


def f(n):
    '''
    >>> f(1)
    True
    >>> f(2)
    True
    >>> f(22)
    True
    >>> f(34)
    False
    >>> f(565)
    True
    >>> f(789)
    False
    '''
    def g(n, m):
        return n // m % 10

    head = tail = 1
    while n // head > 10:
        head *= 10
    while head >= tail:
        if g(n, head) != g(n, tail):
            return False
        head //= 10
        tail *= 10
    return True

def solve(A: int, B: int):
    return sum(map(f, range(A, B+1)))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    print(solve(A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()


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


int main() {
    long long n, k, minn;
    cin >> n >> k;

    minn = n%k;
    while (abs(minn-k) < minn) {
        minn = abs(minn-k);
    }

    cout << minn << endl;

    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

vector<int> divisor(const int n){
  vector<int> ret;
  for(int i=1;i*i<=n;i++){
    if(n % i == 0){
      ret.push_back(i);
      if(i*i!= n) ret.push_back(n/i);
    }
  }
  sort(ret.begin(),ret.end());
  return ret;
}

bool check(int mid,vec &b,int d){
    int sum=0;
    rep(i,b.size()){
        if(i<mid) sum+=b[i];
        else sum-=d-b[i];
    }
    return sum>=0;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int sum=accumulate(all(a),0LL);

    vec d=divisor(sum);

    int ans=1;
    rep(i,d.size()){
        vec b(n);
        rep(j,n){
            b[j]=a[j]%d[i];
        }
        sort(all(b));

        int ng = 0, ok = n;
        while (abs(ng-ok)>1) {
          int mid = ng+(ok-ng)/2;
          (check(mid,b,d[i])?ok:ng) = mid;
        }

        int tot=0;
        rep(j,ok){
            tot+=b[j];
        }
        if(tot<=k) ans=d[i];
    }

    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
#define f first
#define s second
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;

int main()
{
	// 入力
	ll N;
	cin>>N;

	cout<<(N-2)*180<<endl;


	return 0;
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}


int main(){
    int n , K , a;
    cin >> n >> K;
    int Mx = 0 , g = 0;
    rep(i,0,n) {
        cin >> a;
        if(!g) g = a;
        else g = __gcd(g,a);
        Mx = max(Mx , a);
    }
    puts(K <= Mx && K % g == 0 ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
}


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

#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define sort_f(x)  sort(x.begin(),x.end());
#define sort_r(x)  sort(x.rbegin(),x.rend());

lli MOD  = 1000000007;
lli inf = 1e15;

void scan(scantype &x);
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli divi(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n,m;
    cin>>n>>m;
    int cnt =1;
    while(true)
    {
        n*=2;
       
        if(n<=m)
        {
            cnt++;
        }
        else
        {
            break;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n;
	scanf("%d", &n);
	int a[n];
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}

	int max1 = 0;
	int max2 = 0;

	for(int i = 0; i < n; i++){
		if(max2 < a[i]){
			if(max1 < a[i]){
				max2 = max1;
				max1 = a[i];
			}else{
				max2 = a[i];
			}
		}
	}

	for(int i = 0; i < n; i++){
		if(a[i] == max1){
			printf("%d\n", max2);
		}else{
			printf("%d\n", max1);
		}
	}
}

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

typedef long long ll;

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i,a,b) for(int i=b-1;i>=a;i--)

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;
int main() {
	string s;
  cin >> s;
  if(s[2]==s[3]&&s[4]==s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
ll gyaku(ll x){
  return pow(x,mod-2);
}
vector<ll> frac,gfrac;
void set_frac(ll n){
  frac.push_back(1);
  gfrac.push_back(1);
  for(ll i=1;i<=n;i++){
    frac.push_back(frac[i-1]*i%mod);
    gfrac.push_back(gyaku(frac[i]));
  }
}
ll nCr(ll n,ll r){
  ll res=frac[n]*gfrac[r]%mod;
  res*=gfrac[n-r];
  return res%mod;
}



int main(){
  ll n,m;
  cin>>n>>m;
  ll ans=0;
  set_frac(5*max(n,m)+30);

  vector<ll> vec,rsum;
  for(ll i=0;i<3*m+100;i++) vec.push_back(nCr(n+i-2,n-2));
  rsum.push_back(vec[0]);
  for(ll i=1;i<3*m+100;i++) rsum.push_back((rsum[i-1]+vec[i])%mod);
  for(ll t=0;t<=min(n,m);t++){
    ll kans1=0,kans2=0;
    if((m-t)%2==0){
      if(t<n){
        kans1=(nCr(((m-t)/2)+n-2,n-2)*n)%mod;
        kans1*=nCr(n-1,t);
        kans1%=mod;
      }

      kans2+=nCr(((3*m-t)/2)+n-1,n-1);
      kans2%=mod;

      kans2-=(n*rsum[((3*m-t)/2)-m])%mod;
      kans2+=mod;
      kans2%=mod;

      kans2*=nCr(n,t);
      kans2%=mod;
    }
    ans+=(kans1+kans2)%mod;
    ans%=mod;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 124732
# coding: utf-8
# Here your code !
N = int(input())
K = int(input())
ans = 0

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

for i in range(N):
    if x[i] > K/2:
        ans = ans + 2 *(K-x[i])
    else:
        ans = ans + 2 *x[i]

print(ans)

Measured memory_bytes: 3060
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
  String s = sc.next();
  char[] c = s.toCharArray();
  String[] t = new String[s.length()];
  for(int i = 0;i < s.length();i++){t[i] = String.valueOf(c[i]);}
  HashSet<String> hs = new HashSet<String>();
  for(int i = 0;i < s.length();i++){hs.add(t[i]);}
  if(hs.size()==t.length)System.out.println("yes");
  else System.out.println("no");
}}
    

Measured memory_bytes: 21972
x=int(input())
def divisor(a):
	cnt=0
	for i in range(1, int(a**0.5)+1):
		if a%i==0:
			cnt+=2
	return cnt
ans=1
mod = 10**9 +7
dic={i:0 for i in range(2,x+1)}
for a in range(2,x+1):
	for i in range(2, int(a**0.5)+1):
		while a%i==0:
			dic[i]+=1
			a//=i
	if a!=1:dic[a]+=1
A=[i for i in dic.values() if i!=0]
ans=1
for i in A:
	ans=ans*(i+1)%mod

print(ans)



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)
#define _overload4(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload4(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)
#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl


int main(){
    vi a(3);
    REP(i,3)cin>>a[i];
    sort(all(a));
    cout<<a[0]+a[1]+a[2]*10<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n,k,cnt=0;
  cin >> n >> k;
  while(n){
    n/=k;
    cnt++;
  }
  cout << cnt;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "unordered_set"
#include "stack"
#include "tuple"

#define rep(n) for (int i = 0; i < n; ++i)
#define REP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define intinf 0xe869120
#define llmax 9223372036854775807
#define llinf 1234567890987654321
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define P pair<int,int>

typedef long long ll;
using namespace std;

int n, k, a, b, cnt, mx;
vector<int>v[2000];
bool B[2000];

int dfs(int x, int y) {
	++cnt;
	B[x] = true;
	if (y) {
		rep(v[x].size()) {
			if (!B[v[x][i]])
				dfs(v[x][i], y - 1);
		}
	}
	return 0;
}

int main() {
	cin >> n >> k;
	rep(n - 1) {
		cin >> a >> b;
		--a;
		--b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	mx = 0;
	if (k % 2 == 0) {
		rep(n) {
			REP(n, j)
				B[j] = false;
			cnt = 0;
			dfs(i, k / 2);
			mx = max(mx, cnt);
		}
	}
	else {
		rep(n) {
			REP(v[i].size(), j) {
				REP(n, l)
					B[l] = false;
				B[i] = true;
				cnt = 0;
				dfs(v[i][j], k / 2);
				dfs(i, k / 2);
				mx = max(mx, cnt);
			}
		}
	}
	cout << n - mx << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = 1 << 20;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra() {
	priority_queue<pair<int, int> > PQ;
	int color[MAX];
	int d[MAX];
	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	PQ.push(make_pair(0, 0));
	color[0] = GRAY;

	while (!PQ.empty()) {
		pair<int, int>f = PQ.top(); PQ.pop();
		int u = f.second;
		color[u] = BLACK;

		if (d[u] < f.first * (-1))continue;

		for (int j = 0; j < adj[u].size(); j++) {
			int v = adj[u][j].first;
			if (color[v] == BLACK)continue;
			if (d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * (-1), v));
				color[v] = GRAY;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << "\n";
	}
}

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


Measured memory_bytes: 8076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}


int N,K;
int table[2005][2005];

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> N >> K;
  const int L = 2*K;
  rep(i,N){
    int x,y;cin >> x >> y;
    char c; cin >> c;
    x%=L;
    y%=L;
    int black = 1;
    if(c=='W')black^=1;
    if(x>=K)black^=1;
    if(y>=K)black^=1;
    x%=K;
    y%=K;
    table[0][0]+=black;
    if(!black)black=-1;
    table[0][y+1]-=black;
    table[x+1][0]-=black;
    table[x+1][y+1]+=2*black;
  }
  rep(x,K)repp(y,1,K)table[x][y] += table[x][y-1];
  rep(y,K)repp(x,1,K)table[x][y] += table[x-1][y];
  int ans = 0;
  rep(x,K)rep(y,K) ans= max(ans,max(table[x][y],N-table[x][y]));
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 8448
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

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

    //patternA
    lli a = 0;
    lli b = 0;
    if (N % 2 == 1) {
        for (int i = 0; i < N/2; i++) {
            a -= A[i] * 2;
        }
        a += A[N/2] + A[N/2 + 1];
        for (int i = N/2 + 2; i < N; i++) {
            a += A[i] * 2;
        }

        for (int i = 0; i < N/2 - 1; i++) {
            b -= A[i] * 2;
        }
        b -= (A[N/2 - 1] + A[N/2]);
        for (int i = N/2 + 1; i < N; i++) {
            b += A[i] * 2;
        }
    } else {
        for (int i = N/2 + 1; i < N; i++) {
            a += A[i] * 2;
        }
        a += A[N/2];
        a -= A[N/2 - 1];
        for (int i = 0; i < N/2 - 1; i++) {
            a -= A[i] * 2;
        }

        for (int i = 0; i < N/2 - 1; i++) {
            b -= A[i] * 2;
        }
        b -=  A[N/2 -1];
        b += A[N/2];
        for (int i = N/2 + 1; i < N; i++) {
            b += A[i] * 2;
        }
    }
    cout << (a > b ? a : b) << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

int main(){
  int a,b;
  cin>>a>>b;
  if(a+b>9)cout<<"error"<<endl;
  else cout<<a+b<<endl;
  return 0;
}

  



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

int main(){
	ll a,b; cin >> a >> b;
	ll p = -1;
	rep(i,1010){
		if((i+1)*2/25 == a && (i+1)/10 == b){
			p = i+1;
			break;
		}
	}
	cout << p << endl;
}

Measured memory_bytes: 256
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    string S;
    int N;
    cin>>N;
    cin>>S;
    //input
    const char* C=S.c_str();
    int len=S.length();
    vector<int> I(len);
    REP(i,len){
        I[i]=C[i]-'A';
        if(I[i]+N>=26){
            I[i]=I[i]+N-26;
        }else{
            I[i]=I[i]+N;
        }
        S[i]='A'+I[i];
    }
    REP(i,len){
        cout<<C[i];
    }
    cout<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    cout << n * (n + 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
bool f[100001];
int c[100002];
int N, L, R;
int main()
{
    for (int i = 2; i <= 100000; i++)
        if (!f[i])
            for (int j = i + i; j <= 100000; j += i)
                f[j] = true;
    for (int i = 3; i <= 100000; i += 2)
        if (!f[i] && !f[(i + 1) / 2])
            c[i]++;
    for (int i = 3; i <= 100000; i++)
        c[i] += c[i - 1];
    scanf("%d ", &N);
    while (N--)
    {
        scanf("%d %d ", &L, &R);
        printf("%d \n ", c[R] - c[L - 1]);
    }
}


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

sumA = sum(A)
divisors = []
for i in range(1, sumA + 1):
    if i * i > sumA:
        break
    if sumA % i != 0:
        continue
    divisors.append(i)
    if sumA // i != i:
        divisors.append(sumA // i)

divisors.sort(reverse=True)

for d in divisors:
    # 一旦全部マイナス方向に調整することにしたら総和はXの倍数になる
    # どれか一つ符号を逆転すると総和がx減るので、総和/d番目が境目になる
    # A = [8, 20]
    # d = 7
    # costs = [1, 6]
    # 20をプラス方向に調整することにすると、マイナス方向の調整は6減ってプラス方向に(7 - 1)増える
    # 1個をマイナス方向をプラス方向に変更すると、マイナス方向のコストの総和の差とプラス方向のコストの総和の差がdだけ詰まる
    # よって、最初全部マイナス方向に調整したときのコストの総和7を7で割ったところが境目
    # プラス方向にはcostが大きい方から変更したい(調整の量が少なくてすむ)ので、最初にソートしておく
    costs = [a % d for a in A]
    costs.sort(reverse=True)
    if sum(costs[sum(costs) // d:]) <= K:
        print(d)
        break


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

int main()
{
    int n,m,c=0;cin>>n>>m;
    int a[n][m],b[m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<m;i++)cin>>b[i];

    for(int i=0;i<n;i++){
        c=0;
        for(int j=0;j<m;j++){
            c=a[i][j]*b[j]+c;
        }
        cout<<c<<endl;
    }
}


Measured memory_bytes: 3092
n=int(input())
a=list(map(int,input().split()))
ans=0

res=0
right=0
sum=0
for left in range(n):
    while(right<n and sum^a[right]==sum+a[right]):
        sum+=a[right]
        right+=1
    res+=right-left
    if left==right:
        right+=1 #自身のxorは0になるので
    else:
        sum-=a[left]

print(res)

Measured memory_bytes: 24840
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
ans = 0
now = 0
cnt = 1
for i in range(1, n):
    if(a[i-1] != a[i]):
        if(cnt >= a[i-1]):
            ans += cnt - a[i-1]
        else:
            ans += cnt
        cnt = 1
    else:
        cnt += 1
if(cnt >= a[-1]):
    ans += cnt - a[-1]
else:
    ans += cnt

print(ans)


Measured memory_bytes: 14692
import sys
S = input()

left = 0
right = 0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        left = i+1
        right = left+1
        break

for i in range(len(S)-2):
    if S[i]==S[i+2]:
        left = i+1
        right = left+2
        break

if left==right:
    print(-1,-1)
else:
    print(left,right)
    

Measured memory_bytes: 3188
N = int(input())
AB = sorted([list(map(int,input().split())) for i in range(N)],key = lambda x:-x[0]-x[1])
Tsum = sum(AB[i][0] for i in range(N) if i%2 == 0)
Asum = sum(AB[i][1] for i in range(N) if i%2 == 1)
print(Tsum-Asum)

Measured memory_bytes: 33064