akhauriyash/Code-Regression huggingface dataset:
#4問目
N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def has_duplicates2(seq):
    seen = []
    unique_list = [x for x in seq if x not in seen and not seen.append(x)]
    return len(seq) != len(unique_list)

fact = prime_factorize(N)
# print(fact)
result  =  0

if has_duplicates2(fact):
    #重複した数字のリスト
    chofuku = [x for x in set(fact) if fact.count(x) > 1]
    for i in chofuku:
        flag = True
        n = 1
        Count = fact.count(i) + 1
        while flag:
            if(1/2 * n * (n - 1) < Count <= 1/2 * n * (n + 1)):
                result += n-1
                flag = False
            else:
                n += 1
    
    #重複していない数の個数
    NOTchofuku = len((list(set(fact)))) - len(chofuku)
    print(result + NOTchofuku)
else:
    print(len(fact))

Measured memory_bytes: 9276
import Data.List                                                                                                           
main :: IO ()                                                                                                              
main = getLine >> reverse . sort . map read . words <$> getLine >>= print . (\(x,y) -> x - y) . f (0,0)                    
                                                                                                                           
f :: (Int,Int) -> [Int] -> (Int,Int)                                                                                       
f (a,b) [] = (a,b)                                                                                                         
f (a,b) [x] = (a+x,b)                                                                                                      
f (a,b) (x:y:xs) = f (a+x,b+y) xs

Measured memory_bytes: 1020
#include<stdio.h>
int main(){
  int a,i;
  char s[10];
  scanf("%d",&a);
  scanf("%s",s);
  if(a<3200) printf("red");
  else{
    for(i=0;s[i]!='\0';i++){
      printf("%c",s[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, ans = 0; cin >> n;
	for (int h = 1; h < n; h++) {
		ans += h;
	}
	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
  val s = readLine()!!
  val k = readLine()!!.toInt()
  val list = mutableListOf<String>()
  for (i in 0 until s.length) {
    for (l in 1..k) {
      if (i + l > s.length) continue
      val t = s.substring(i, i + l)
      list.add(t)
    }
  }
  val uniqueSortedList = list.toSet().toList().sorted()
  println(uniqueSortedList[k - 1])
}


Measured memory_bytes: 41768
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
	var c = parseInt(tmp[2], 10);
	if(a+b+c >= 22){
       console.log('bust');
    }else{
       console.log('win');
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL A,B;
int main(){
	cin >> A >> B;
	if (A==B)
		return puts("1"),0;
	for (int i=59;i>=0;i--)
		if ((~A>>i&1LL)&&(B>>i&1LL)){
			A&=(1LL<<i)-1;
			B&=(1LL<<i)-1;
			LL ans=(1LL<<i)-A,k=0;
			while (B)
				B>>=1,k++;
			ans+=min((1LL<<k)+(1LL<<i)-A,1LL<<i);
			cout << ans << endl;
			return 0;
		}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 29
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}

struct Edge
{
  int src, dst;
  ll cost;
  Edge(int src, int dst, ll cost) :
    src(src), dst(dst), cost(cost) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
bool operator < (const Edge &e, const Edge &f)
{
  return e.cost != f.cost ? e.cost > f.cost : // !!INVERSE!! ???????????????????????????
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

ll chinesePostman(const Graph &g)
{
  ll total = 0;
  vector<int> odds;
  REP(u, g.size())
  {
    for(auto e : g[u]) total += e.cost;
    if (g[u].size() % 2) odds.push_back(u);
  }
  total /= 2;
  int n = odds.size(), N = 1 << n;
  ll w[n][n]; // make odd vertices graph
  REP(u,n) {
    int s = odds[u]; // dijkstra's shortest path
    vector<ll> dist(g.size(), INF); dist[s] = 0;
    vector<int>    prev(g.size(), -2);
    priority_queue<Edge> Q;
    Q.push( Edge(-1, s, 0) );
    while (!Q.empty())
    {
      Edge e = Q.top(); Q.pop();
      if (prev[e.dst] != -2) continue;
      prev[e.dst] = e.src;
      for(auto f : g[e.dst])
      {
        if (dist[f.dst] > e.cost+f.cost)
        {
          dist[f.dst] = e.cost+f.cost;
          Q.push(Edge(f.src, f.dst, e.cost+f.cost));
        }
      }
    }
    REP(v,n) w[u][v] = dist[odds[v]];
  }
  ll best[N]; // DP for general matching
  REP(S,N) best[S] = INF;
  best[0] = 0;

  for (int S = 0; S < N; ++S)
    for (int i = 0; i < n; ++i) if (!(S&(1<<i)))
      for (int j = i+1; j < n; ++j) if (!(S&(1<<j)))
        best[S|(1<<i)|(1<<j)] = min(best[S|(1<<i)|(1<<j)], best[S]+w[i][j]);
  return total + best[N-1];
}

int main()
{
  int n, m; cin >> n >> m;
  Graph g(n);
  REP(i,m)
  {
    int s, t; ll c; cin >> s >> t >> c;
    g[s].push_back(Edge(s,t,c));
    g[t].push_back(Edge(t,s,c));
  }
  cout << chinesePostman(g) << endl;
  return 0;
}

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

int main(){

    int n, a, b;
    cin >> n >> a >> b;

    int sum = 0;
    for (int i=0; i<10; i++){
        for (int j=0; j<10; j++){
            for (int k=0; k<10; k++){
                for (int l=0; l<10; l++){
                    int digit_sum = i + j + k + l;
                    int buf = 1000*i + 100*j + 10*k + l;

                    if (buf > n){
                        cout << sum << endl;
                        return 0;
                    }
                    if ((digit_sum >= a) && (digit_sum <= b)) sum += buf;
                }
            }
        }
    }

    if ((a == 1) && (n == 10000)){
        sum += 10000;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
// C++11
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iostream>
#include <numeric>
#include <random>
#include <vector>
#include <set>
#include <unordered_set>

using namespace std;

#define LOCAL 1

#if LOCAL
#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl
#else
#define pv(val)
#define pvn(name, val)
#define pl
#endif

template <class T>
ostream& operator<<(ostream& os, vector<T> const& vec) {
  if (vec.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
    os << vec.back() << '}';
  }
  return os;
}

template <class T, size_t S>
ostream& operator<<(ostream& os, array<T, S> const& arr) {
  if (arr.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
    os << arr.back() << '}';
  }
  return os;
}




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

  sort(a.rbegin(), a.rend());

  int alice = 0, bob = 0;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0) alice += a[i];
    else bob += a[i];
  }

  cout << (alice - bob) << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,Alice=0,Bob=0;
  cin >> N;
  vector<int>a(N);
  for (int i=0;i<N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  while (a.size()>0){
    Alice += a.at(a.size()-1);
    a.pop_back();
    if (a.size()==0){
      break;
    }
    Bob += a.at(a.size()-1);
    a.pop_back();
  }
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
n=int(input())
arc=[[[0]*10 for i in range(3)] for k in range(4)]
for i in range(n):
    b,f,r,v=map(int,input().split())
    arc[b-1][f-1][r-1] +=v

for i in range(4):
    for j in range(3):
        print("",*arc[i][j])
    if i!=3:print("#"*20)


Measured memory_bytes: 5620
#include<stdio.h>
int main(){
  int n1,n2,S[100000],T[1000000];
  int i,count=0;
  int left,right,mid;
  scanf("%d",&n1);
  for(i=0;i<n1;i++){
    scanf("%d",&S[i]);

  }
  scanf("%d",&n2);
  for(i=0;i<n2;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<n2;i++){
    left = 0;
    right = n1;
  while(left < right){

      mid = (left + right)/2;
      if(S[mid] == T[i]) {count++;break;}
      else if(T[i] < S[mid]){right=mid;}
      else {left = (mid+1);}

    }

  }
  printf("%d\n",count);
  return 0;

}

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

const int N = 100 * 1000 + 10;
long long h[N], n, a, b;

bool is_val(long long t)
{
	long long cnt = 0;
	for (int i = 0; i < n; i++)
	{
		long long x = h[i];
		x -= t * b;
		if(x <= 0)
			continue;
		cnt += (x / (a - b)) + min(1ll, x % (a - b));
	}
	return cnt <= t;
}

long long bin_search()
{
	long long low = 0, high = 1000 * 10000 * 1000 + 5;
	while(high - low > 1)
	{
		long long mid = (low + high) / 2;
		if(is_val(mid))
			high = mid;
		else
			low = mid;
	}
	return high;
}

int main()
{
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	cout << bin_search() << endl;
}

Measured memory_bytes: 1024
#挿入
#辞書順最少,左端に"("寄せる

from collections import deque

n = int(input())
s = input()

ans = deque()
cnt = 0
for i in range(n):
    if s[i]==")":
        if cnt<=0:
            ans.appendleft("(")
            ans.append(")")
        else:
            ans.append(")")
            cnt -= 1
    else:
        ans.append("(")
        cnt += 1
for i in range(cnt):
    ans.append(")")

print(''.join(ans))
        

Measured memory_bytes: 38768
#include <iostream>
#include <ios>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <functional>
#include <cassert>

using namespace std;

using i64 = long long;
using P = pair<i64, i64>;

const i64 mod = 1e9 + 7;

// dp1[i][j] := i 番目まで並べて最後の数がjになるような場合の数
// dp2[i][j] := i 番目まで並べてi + 1 番目に j 以下の数がおけるような場合の数

int main(){
    i64 n, k;
    cin >> n >> k;
    i64 m = 0;
    for(int i = 1; i * i <= n; ++i) m = i;
    vector<vector<i64>> dp1(k, vector<i64>(m + 1)), dp2(k, vector<i64>(m + 1));
    for(int i = 1; i <= m; ++i){
        dp1[0][i] = 1;
        if(n / i == i) dp2[0][i] = 0;
        else dp2[0][i] = n / i - n / (i + 1);
    }
    for(int i = 1; i < k; ++i){
        i64 s = 0;
        for(int j = 1; j <= m; ++j){
            s = (s + dp1[i - 1][j]) % mod;
            if(j * j != n) dp2[i][j] = s * dp2[0][j] % mod;
            else dp2[i][j] = 0;
        }
        for(int j = m; j >= 1; --j){
            s = (s + dp2[i - 1][j]) % mod;
            dp1[i][j] = s;
        }
    }
    i64 ans = 0;
    for(int i = 1; i <= m; ++i) ans = (ans + dp1[k - 1][i]) % mod;
    for(int i = 1; i <= m; ++i) ans = (ans + dp2[k - 1][i]) % mod;
    //for(int i = 1; i <= m; ++i) cout << "dp1[k - 1][" << i << "]: " << dp1[k - 1][i] << endl;
    //for(int i = 1; i <= m; ++i) cout << "dp2[k - 1][" << i << "]: " << dp2[k - 1][i] << endl;
    cout << ans << endl;
}

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

int main() {
    int K, X;
    cin >> K >> X;

    string ans = "No";
    if (500 * K >= X) ans = "Yes";

    cout << ans << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
p=0
for i in range(1,n+1):
    r=k/i
    if r==1:
        p+=1
        continue
    m=1
    count=0
    while True: 
        if r>m:
            m=m*2
            count+=1
        else:
          break
    p+=1/m
p=p/n
print(p)

Measured memory_bytes: 3060
def push(S,t,x):
    S[t].append(x)
    return S

def top(S,t):
    count=len(S[t])
    if count!=0:
        print(S[t][-1])

def pop(S,t):
    count=len(S[t])
    if count!=0:
        del S[t][-1]
    return S

n,q=(int(x) for x in input().split())
S=[[] for i in range(n)]

for i in range(q):
    query=list(map(int,input().split()))
    if query[0]==0:
        S=push(S,query[1],query[2])
    elif query[0]==1:
        top(S,query[1])
    else:
        S=pop(S,query[1])
    



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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n, m, k;
    cin >> n >> m >> k;
    
    FOR(i,0,n) FOR(j,0,m) {
        int black = i * (m - j) + j * (n - i);
        if (black == k) {
            cout << "Yes";
            return 0;
        }
    }
    
    cout << "No";

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 256
N, K = gets.chomp.split.map(&:to_i)

memo = N.times.map do
  K.times.map do
    0
  end
end

K.times.each do
  sugar = gets.chomp.to_i
  okasi = gets.chomp.split.map(&:to_i)
  okasi.each do |human|
    memo[human - 1][sugar - 1] = 1
  end
end

count = 0

memo.each do |human|
  count += 1 if human.all?(0)
end

puts count


Measured memory_bytes: 14508
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}

int main(){
    int n;cin>>n;
    string s;cin>>s;
    if(n%2){
        cout<<"No"<<endl;
        return 0;
    }
    rep(i,n/2){
        if(s[i]!=s[i+n/2]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
	long k;
  cin >> s >> k;
	if(k==1){cout<<s[0];return 0;}
	if(s.length()>=k){
		for(int t=0;t<k-1;t++){
			if(s[t]!='1'){cout << s[t]; return 0;}
		}
		cout << s[k-1]; return 0;
	}
	else {
		for(int t=0;t<s.length();t++){
			if(s[t]!='1'){cout << s[t]; return 0;}
		}
		cout << 1; return 0;
	}
	
  return 0;
}

Measured memory_bytes: 256
import sys
# (x,y) 探索開始座標を与えると、それで画像が一致していればTrue,そうでなければ　Falseを返す関数hantei
def hantei(x,y,m):
    for h in range(m):
        if A[h+y][x:x+m]!=B[h]:
            return False
    else:
        return True
            
n,m =map(int,input().split())
A=[]
B=[]
for i in range(n):
    A.append(input())
for j in range(m):
    B.append(input())  

for y in range(n-m+1):
    for x in range(n-m+1):
        if hantei(x,y,m):
            print("Yes")
            sys.exit()
        else: continue
print("No")
        

Measured memory_bytes: 3064
s=input()
a=int(s[:2])
b=int(s[2:])
if 0<a<=12 and 0<b<=12:
    print("AMBIGUOUS")
elif 0<a<=12:
    print("MMYY")
elif 0<b<=12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n,m = LI()
    root = [[] for _ in range(n+1)]
    for _ in range(m):
        a,b = LI()
        root[a].append(b)
        root[b].append(a)

    pers = itertools.permutations(list(range(2,n+1)))
    ans = 0

    for per in pers:
        for i in range(n-1):
            if i == 0:
                now = 1
                next = per[0]
                if next not in root[now]:
                    break
            else:
                now = per[i-1]
                next = per[i]
                if next not in root[now]:
                    break
        else:
            ans += 1
    
    print(ans)
main()

Measured memory_bytes: 75116
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "a.cpp"

int main() {
  ll n;
  cin >> n;
  if (n%1000 == 0) cout << 0 << el;
  else cout << 1000-n%1000 << el;
}


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

vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
bool b[200000], ok[100000];

void bfs(int u) {
	queue<int>que;
	que.push(u);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		for (int v : E[p]) {
			if (d[v] == d[p] + 1 && !ok[v]) {
				ok[v] = true; cnt++; que.push(v);
			}
		}
	}
}
int main() {
	int n, m, q; scanf("%d%d%d", &n, &m, &q);
	rep(i, m) {
		scanf("%d%d", &u[i], &v[i]);
		u[i]--; v[i]--;
		E[u[i]].push_back(v[i]); E[v[i]].push_back(u[i]);
	}
	queue<int>que;
	memset(d, -1, sizeof(d));
	d[0] = 0; que.push(0);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		for (int i : E[p]) {
			if (d[i] == -1) {
				d[i] = d[p] + 1; que.push(i);
			}
		}
	}
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		scanf("%d", &r[i]); r[i]--;
		b[r[i]] = true;
	}
	ok[0] = true;
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] - d[u[i]] == 1) {
				E[u[i]].push_back(v[i]);
			}
		}
	}
	bfs(0);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] - d[u[r[i]]] == 1 && !ok[v[r[i]]]) {
			E[u[r[i]]].push_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = true;
				bfs(v[r[i]]);
			}
		}
	}
	rep(i, q)printf("%d\n", ans[i]);
}

Measured memory_bytes: 13620
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  printf("%d\n", MIN(a * b, c));
  return 0;
}


Measured memory_bytes: 128
while True:	
	H,W = map(int, input().split())
	if H==0 and W==0: break
	for y in range(0,H):
		for x in range(0,W):
			if y%2==1:
				if x%2==1: print("#",end="")
				else: print(".",end="")
			else:
				if x%2==1: print(".",end="")
				else: print("#",end="")
		print()
	print()


Measured memory_bytes: 7004
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))

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

ans = 0
tmp = abs(A - (T - H[0]*0.006))

for i in range(1,N):
    tmp2 = abs(A - (T - H[i]*0.006))
    if tmp2 < tmp:
        ans = i
        tmp = tmp2


print(ans+1)

Measured memory_bytes: 77500
N = int(input())
A = [0] * N
B = []
for n in range(N):
    A[n] = int(input())
    bn = []
    for i in range(A[n]):
        x, y = map(int, input().split())
        bn.append((x-1, y))
    B.append(bn)

ans = 0
# bit & (1 << n) で n 番目の 0,1
for bit in range(1 << N):
    ok = [False] * N
    for n in range(N):
        if ((bit >> n) & 1) == 1:
            if all([((bit >> B[n][i][0]) & 1) == B[n][i][1] for i in range(A[n])]):
                ok[n] = True
        else:
            ok[n] = True
    if all(ok):
        ans = max(ans, sum(list(map(int, format(bit, "b")))))

print(ans)




Measured memory_bytes: 46172
from string import ascii_lowercase


def cut_and_count(s, n, i):
    x = set(s[:i])
    y = set(s[i:])
    cnt = 0

    for ch in ascii_lowercase:
        if ch in x and ch in y:
            cnt += 1
    return cnt


def main():
    n = int(input())
    s = list(input())
    ans = 0

    for i in range(1, n):
        res = cut_and_count(s, n, i)
        ans = max(ans, res)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 68836
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
count = 0
for i in range(N):
	A.append(list(map(int, input().split())))
for s in range(N):
	ans = 0
	for t in range(M):
		ans += A[s][t]*B[t]
	if(t == M - 1):
		ans += C
	if(ans > 0):
		count += 1
print(count)

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	V := make([]int, N)
	C := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &V[i])
	}
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &C[i])
	}
	sum := 0
	for i := 0; i < N; i++ {
		if V[i]-C[i] > 0 {
			sum += V[i] - C[i]
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf INT_MAX
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 1e-9

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;cin>>s;
    rep(i,0,2)
    {
        if(s[i]==s[i+1])
        {
            cout<<"Bad"<<"\n";
            return 0;
        }
    }
    cout<<"Good"<<"\n";

    return 0;

    //check for long long or int
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
f=0
g=0
ans="DENIED"
for i in range(n):
  if a[i]%2==0:
    f=1
    if (a[i]%3==0 or a[i]%5==0):
      continue
    else:
      g=1
if f==1 and g==0:
  ans="APPROVED"
if f==0 and ans=="DENIED":
  ans="APPROVED"
print(ans)
  


Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll x_0 = A[0];
  for (int i = 1; i < N; i++) {
    if (i % 2 == 1)
      x_0 -= A[i];
    else
      x_0 += A[i];
  }
  vector<ll> X(N, 0);
  X[0] = x_0;
  cout << X[0] << " ";
  for (int i = 0; i < N - 1; i++) {
    X[i + 1] = 2 * (A[i] - (X[i] / 2));
    cout << X[i + 1] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main(){
int N;
cin >> N;
vector<int> A(N);
for(int i = 0; i < N; i++){
    cin >> A[i];
}
int Z = 0;
for(int i = 0; i < N; i++){
    for(int j = i + 1; j < N; j++){
       Z = max(Z ,abs(A[i] - A[j]));
    }
}

cout << Z << endl;
}

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


ll N, A, B, K;
ll mod = 1e9 + 7;

struct ModComb {
    vector<long long> fact, rfact;
    long long max, mod;
    ModComb(long long ma = 1, long long mod=1e9+7) :fact(ma, 0), rfact(ma, 0), max(ma), mod(mod) {
        fact[0] = 1;
        for (long long i=1; i<max; ++i) {
            fact[i] = fact[i-1]*i;
            fact[i] %= mod;
        }
        rfact[max-1] = mod_inverse(fact[max-1], mod);
        for (long long i=max-2; i>=0; --i) {
            rfact[i] = rfact[i+1]*(i+1);
            rfact[i] %= mod;
        }
    }
    long long mod_pow(long long x, long long n, long long mod) {
        long long a = 1LL;
        while (n) {
            if (n%2) a = ((a%mod)*(x%mod))%mod;
            x = ((x%mod)*(x%mod))%mod;
            n /= 2LL;
        }
        return a;
    }

    long long mod_inverse(long long a, long long m) {
        return mod_pow(a, m-2, m);
    }

    // O(r)で求める方法
    long long calc(ll n, ll r, ll mod) {
        ll ret = 1, k = 0;
        for (ll a=r; a>=1; --a) {
            ll tmp = (n - k) * mod_inverse(a, mod) % mod;
            tmp %= mod;
            ret *= tmp;
            ret %= mod;
            k++;
        }
        return ret;
    }

    long long operator()(long long n, long long r) {
        if (n < r) return 0;
        return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
    }
};

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    ModComb mb;
    ll ans = 0;
    ans = mb.mod_pow(2, n, mod) - 1;
    ans %= mod;

    ans -= mb.calc(n, a, mod);
    ans = (ans + mod) % mod;
    ans -= mb.calc(n, b, mod);
    ans = (ans + mod) % mod;
    cout << ans << endl;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll n,a,b;cin>>n>>a>>b;
    cout << ((b-a)%2 == 0?"Alice":"Borys") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
vector<int> bd, ans;
char c;

int main() {
  cin >> n >> m;
  for (int i=0; i<=n; i++) {
      cin >> c;
      if (c=='0') {
          bd.push_back(i);
      }
  }
  int a = n;
  while (a) {
      int b = bd[lower_bound(bd.begin(), bd.end(), a-m)-bd.begin()];
      if (b==a) {
          cout << -1;
          break;
      }
      else {
          ans.push_back(a-b);
          a = b;
      }
  }
  if (a==0) {
      for (int i=ans.size()-1; i>=0; i--) {
          cout << ans[i] << ' ';
      }
  }
}

Measured memory_bytes: 1400
public class Main{
    public static void main(String[]args){
        StringBuilder sb = new StringBuilder();
        for(int i=1; i<=9; i++){
            for(int k=1; k<=9; k++){
                sb.append(i).append("x").append(k).append("=").append(i*k).append("\n");
            }
        }
        System.out.print(sb);

    }
}

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

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

    double sum = 0;

    vector<int> vec(N);

    rep(i, N) {
        cin >> vec.at(i);
        sum += vec.at(i);
    }

    sort(all(vec), greater<int>());

    string ans = "Yes";

    rep(i, M) {
        if (vec.at(i) < sum / (4 * M)) {
            ans = "No";
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

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

	int ans = R;
	if (N < 10)
		ans += 100 * (10 - N);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin>>x;
    x %= 10;
    if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9){
        puts("hon");
    }
    else if(x == 3)puts("bon");
    else puts("pon");
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define md 1000000007

long long a[4] = {1};
char s[100005];
int main(){
	scanf("%s", s);
	for(int i = 0; s[i] != '\0'; i++) for(int j = 3; j >= 0; j--)
		a[j] = (a[j]*(s[i]=='?'?3:1) + (j&&(s[i]=='?'||s[i]-'A'==j-1)?a[j-1]:0))%md;
	printf("%lld\n", a[3]);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(ll i = 0;i < (n); ++i)
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    for(int i=n-1;i>0;i--){
        int H = h[i] - h[i-1];
        if(H < -1){
            cout << "No" << endl;
            return 0;
        }
        if(H == -1) h[i-1]--;
    }
    cout << "Yes" << endl;
    return 0;
} 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

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

	int ans  = 0;
	rep (i, s.size()) {
		if (s[i] != t[i]) ans++;
	}

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


Measured memory_bytes: 3916
n = gets.to_i
ac = 0
wa = 0
tle = 0
re = 0

n.times do
  tmp = gets.chomp
  case tmp
  when "AC"
    ac += 1
  when "WA"
    wa += 1
  when "TLE"
    tle += 1
  else
    re += 1
  end
end

puts <<~EOS
       AC x #{ac}
       WA x #{wa}
       TLE x #{tle}
       RE x #{re}
     EOS


Measured memory_bytes: 14372
local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = {}
  t[i].a, t[i].b = io.read("*n", "*n")
  t[i].c = t[i].b - t[i].a
end
table.sort(t, function(x, y)
  return x.b > y.b
end)

local mmi = math.min
-- local isok = true
local cur = t[1].c
for i = 2, n do
  cur = mmi(t[i].c, cur - t[i].a)
end
print(0 <= cur and "Yes" or "No")


Measured memory_bytes: 35444
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(class vector<T>::size_type h,class vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll x=in(),n=in();
    vector<ll>p(n);for(ll i=0;i<n;++i)p[i]=in();
    for(ll i=0;;++i){
        if(!count(p.begin(),p.end(),x-i)){
            cout<<x-i<<endl;
            return 0;
        }
        if(!count(p.begin(),p.end(),x+i)){
            cout<<x+i<<endl;
            return 0;
        }
    }
}



Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String O = scan.nextLine();
		String E = scan.nextLine();
		for(int i = 0; i < O.length(); i++) {
			System.out.print(O.substring(i, i + 1));
			if(i < E.length()) {
				System.out.print(E.substring(i, i + 1));
			}
		}
		scan.close();

	}

}


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

#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define All(obj) (obj).begin(),(obj).end()
#define REP(n) for(int i=0;i<(n);++i)
#define REPR(n) for(int i=(n-1); i>=0;--i)
#define FOR(i,b,n) for(int i=(b);i<(n);++i)

typedef long long ll;

const int M=2e5+5;
const int INF=2e9;
const int MOD=1e9+7; //prime number
/*
vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
vector<int> split_into_num(const string &str, char sep)
{
    vector<int> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(stoi(buffer));
    }
    return v;
}
*/
int gcd(int a, int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
bool isPrime(int a)
{
    if(a==2)
        return true;
    else if(a<=1 or a%2 == 0)
        return false;

    for(int i = 3; i <= sqrt(a); i+=2)
    {
        if(a%i==0)
            return false;
    }
    return true;
}
void BubbleSort(vector<string> &v, int n)
{
    int a,b;
    for(int i = 0; i < n-1; ++i)
    {
        bool swapped = false;
        for(int j = 0; j < n-i-1; ++j)
        {
            a = v[j][1] - '0';
            b = v[j+1][1] - '0';
            if(a > b)
            {
                swap(v[j],v[j+1]);
                swapped = true;
            }
        }
        if(swapped == false)
            break;
    }
}
void SelectionSort(vector<string> &v, int n)
{
    bool swapped;
    int index,a,b;
    for(int i = 0; i < n-1; ++i)
    {
        swapped = false;
        index = i;
        for(int j = i+1; j < n; ++j)
        {
            a = v[index][1] - '0';
            b = v[j][1] - '0';
            if(a>b)
            {
                index = j;
                swapped = true;
            }
        }
        if(swapped)
        {
            swap(v[i],v[index]);
        }
    }
}
void Solve()
{
    double long a[2],b[2];
    for(double long &num: a) cin >> num;
    for(double long &num: b) cin >> num;

    double long ans = a[0]*b[0];
    for(int i = 0; i < 2; ++i)
    {
        for(int j = 0; j < 2; ++j)
        {
            ans = max(a[i]*b[j],ans);
        }
    }
    cout << setprecision(20)<< ans;
}
int main()
{
    fastio;
    Solve();

    return 0;
}



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

int main() {
  int N;
  cin >> N;
  int a, b, t;
  cin >> t >> a >> b;
  LL base = b;
  priority_queue<LL> small;
  priority_queue<LL, vector<LL>, greater<LL>> large;
  small.push(a);
  large.push(a);
  for (int i = 1; i < N; i++) {
    int k;
    cin >> k;
    auto p1 = small.top();
    auto p2 = large.top();

    if (k == 1) {
      cin >> a >> b;
      base += b;
      if (a < p1) {
        base += p1 - a;
        small.push(a);
        small.push(a);
        small.pop();
        large.push(p1);
      } else if (p2 < a) {
        base += a - p2;
        large.push(a);
        large.push(a);
        large.pop();
        small.push(p2);
      } else {
        small.push(a);
        large.push(a);
      }

    } else {
      cout << p1 << " " << base << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4588
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
  for(int N;cin>>N,N;){
    string b[1000];
    for(int i=0;i<N;i++){
      cin>>b[i];
    }
    int dp[1001]={1};
    for(int i=0;i<N;i++){
      vector<string> bp[4]={
	{"0xxxxxxx"},
	{"110yyyyx","10xxxxxx"},
	{"1110yyyy","10yxxxxx","10xxxxxx"},
	{"11110yyy","10yyxxxx","10xxxxxx","10xxxxxx"}
      };
      for(int j=0;j<4;j++){
	if(N-i<bp[j].size())continue;
	bool f=false;
	int x=0,y=0;
	bool yz=false;
	for(int k=0;k<bp[j].size();k++){
	  for(int l=0;l<8;l++){
	    if(bp[j][k][l]=='0'||bp[j][k][l]=='1'){
	      f|=b[i+k][l]==(bp[j][k][l]^'0'^'1');
	    }else if(bp[j][k][l]=='y'){
	      y+=b[i+k][l]=='x';
	      yz|=b[i+k][l]=='1';
	    }else{
	      x+=b[i+k][l]=='x';
	    }
	  }
	}
	if(!f){
	  long long yf=(j==0)?1:(1LL<<y)-!yz;
	  const int M=1000000;
	  dp[i+bp[j].size()]=(dp[i+bp[j].size()]+(yf<<x)%M*dp[i])%M;
	}
      }
    }
    cout<<dp[N]<<endl;
  }
}

Measured memory_bytes: 1272
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int tokuten[] =  new int[N+1];//得点の配列

		for(int i = 0;i<N*(N-1)/2;i++){//Nチームあるときの試合数まで繰り返す
			int a = sc.nextInt();
			int b = sc.nextInt();
			int a1 = sc.nextInt();
		    int b1 = sc.nextInt();
		    
		    if (a1 > b1){//aが勝った場合
		    	tokuten[a] += 3;
		    }else if (a1 < b1){//bが勝った場合
		    tokuten[b] += 3;
		    }else{//同点の場合
		    tokuten[a] += 1;
		    tokuten[b] += 1;
		    }
		}

		for(int i = 1; i < N+1; i++){
			int length = 1;
			for(int j = 0; j < N+1; j++){
				if(tokuten[i] < tokuten[j])
					length += 1;
			}
		    System.out.println(length);
		}
	}
}

Measured memory_bytes: 42048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vi B(M + 1), A(N + 1);
  for (ll i = 0; i < N; i++) {
    ll a;
    cin >> a;
    A[i + 1] = A[i] + a;
  }
  for (ll i = 0; i < M; i++) {
    ll b;
    cin >> b;
    B[i + 1] = B[i] + b;
  }

  ll ans = 0;
  ll j = M;
  for (int i = 0; i <= N && A[i] <= K; i++) {
    while (j >= 0 && A[i] + B[j] > K) j--;
    ans = max(ans, i + j);
  }

  cout << ans << endl;
}


Measured memory_bytes: 6416
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  char s[n];
  // Aがゴールのパターン、Bがゴールのパターン
  bool flag = true;

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

    //岩が二連続のパターン
    if (i >= a && i <= max(c, d)) {
      if (s[i] == '#' && s[i] == s[i - 1]) flag = false;
    }
  }

  // c>dならb動かしてa動かして終わり
  if (d < c) {
    // d前後に岩があるとき
    if (s[d + 1] == '#' || s[d - 1] == '#') flag = false;

    for (int i = b; i <= d; i++) {
      // 途中の道で.が3連続であるとき
      if (s[i] == s[i + 1] && s[i] == s[i - 1] && s[i] == '.') {
        flag = true;
        break;
      }
    }

 
  }

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

public class Main {

	static FastReaderR in = new FastReaderR(System.in) ;
	
	static int N,index ;
	
	static int V[] = new int[21] , C[] = new int[21] ; 
	
	static int mmax = Integer.MIN_VALUE ;
	
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		N = in.nextInt() ;
		for(int i=0;i<N;i++){
			V[i] = in.nextInt() ;
		}
		for(int i=0;i<N;i++){
			C[i] = in.nextInt() ;
		}
		f(N-1,0) ;
		System.out.println(mmax);
	}
	
	public static void f(int dp,int now){
		if(dp==-1){
			if(now>mmax){
				mmax = now ;
			}
		}else{
			f(dp-1,now+(V[dp]-C[dp])) ;
			f(dp-1,now) ; 
		}
	}

}
class FastReaderR {
    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;
 
    FastReaderR(InputStream is) {
        in = is;
    }
    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }
    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan());
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan());
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
}

Measured memory_bytes: 23508
import java.util.Scanner;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int result = 0;
        while(true)
        {
            result += N;
            N--;
            if(N==0)
            break;
        }
        System.out.println(result);
    }
}

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

int main() {
  long a[10000], n;
  long tmp, _max = -1000000, _min = 1000000;
  double _sum = 0;
  cin >> n;
  while (n--) {
    cin >> tmp;
    if (_max < tmp) _max = tmp;
    if (_min > tmp) _min = tmp;
    _sum += tmp;
  }
  cout << _min << ' '
       << _max << ' '
       << fixed << setprecision(0) << _sum << endl;
}

Measured memory_bytes: 1240
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
  int n;
  int f[10005] = {0};
  // (x+y)^2 + (y+z)^2 + (x+z)^2 = 2n
  cin >> n;
  for(int x=1;x<142;x++){
    if(x*x > 2*n) break;
    for(int y=1;y<142;y++){
      if((x+y) * (x+y) > 2*n) break;
      for(int z=1;z<142;z++){
        int two_n = (x+y) * (x+y) + (y+z)*(y+z) + (x+z)*(x+z);
        //cout << two_n  << ' ' << x << ' ' << y << ' ' << z << endl;
        if(two_n > 2*n) break;
        if(two_n % 2 != 0) continue;
        else f[two_n/2]++;
      }
    }
  }

  for(int i=1;i<n;i++){
    cout << f[i] << endl;
  }
  cout << f[n];
  return 0;
}


Measured memory_bytes: 3668
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

cost = 0
temp1 = 0
temp2 = 0
for i in range(M):
    if X < A[i] and N > A[i]:
        temp1 += 1
for i in reversed(range(M)):
    if X > A[i] and 0 < A[i]:
        temp2 += 1
cost = min(temp1, temp2)
print(cost)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int main() {
  int n; cin >> n;
  vector<long long int> a(n);
  vector<long long int> b(n);
  for(int i=0; i<n; i++) cin >> a[i];
  priority_queue<long long int> pq;
  long long int cnt = 0;
  long long int sum = 0;
  for(int i=0; i<n; i++) {
    cin >> b[i];
    if(b[i] > a[i]) sum += b[i]-a[i], cnt++;
    else if(b[i] == a[i]) continue;
    else pq.push(a[i]-b[i]);
  }

  while(!pq.empty()) {
    long long int x = pq.top();
    pq.pop();
    if(sum > 0) cnt++;
    sum -= x;
  }
  if(sum > 0){
    cout << -1 << endl;
    return 0;
  }

  cout << cnt << endl;



  return 0;
}



//EOF


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

int main() {
    int a,b,c,x,y; cin>>a>>b>>c>>x>>y;
    
    long long ans,ans2;
    
    ans = min(a*x+b*y, 2*c*max(x,y));
    
    if(x>=y)ans2 = 2*c*min(x,y)+ a*(x-y);
    if(x< y)ans2 = 2*c*min(x,y)+ b*(y-x);
    
    ans = min(ans,ans2);

    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int bit[100000+1],n;
int sum(int i){
  int s=0;
  while(i>0){
    s+=bit[i];
    i-=i&-i;
  }
  return s;
}
void add(int i,int x){
  while(i<=n){
    bit[i]+=x;
    i+=i&-i;
  }
}
int main(){
  int q;
  cin >> n>>q;
  fill(bit,bit+100000+1,0);
  int a,b,c;
  while(q--){
    cin >> a >> b >> c;
    if(a==0) add(b,c);
    else{
      if(b==0) cout << sum(c) << endl;
      else cout << sum(c)-sum(b-1)<<endl;
    }
  }
}

Measured memory_bytes: 1552