akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	int K,N;
	string S;
	cin >> N >> S >> K;
	for(int i(0);i<N;++i){
		if(S[K-1] != S[i]) cout << '*';
		else cout << S[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import { readFileSync } from "fs";
const input = readFileSync("/dev/stdin", "utf8");

const [HN, AS] = input.split("\n");

let [H, N] = HN.split(" ").map(s => ~~s);
const A = AS.split(" ").map(x => ~~x);

A.forEach(x => {
    H = H - x;
});

if (H <= 0) {
    console.log("Yes");
} else {
    console.log("No");
}


Measured memory_bytes: 16716
n,x,m= list(map(int, input().strip().split()))
t=0
b=[]
b.append(x)
for i in range(m+1):
        if b[-1]**2%m in b:
            b.append(b[-1]**2%m)
            break
        else:
            b.append(b[-1]**2%m)
        
l=len(b) 
for i in range(l-1):
    if b[i]==b[l-1]:
        q=i
w=l-2-q+1
s=0
for i in range(q):
    s+=b[i]
t=0
for i in range(q,l-1):
    t+=b[i]
u=(n-q)//w
v=(n-q)%w
ans=0
for i in range(q,q+v):
    ans+=b[i]
ans+=s+u*t

print(ans)
    

Measured memory_bytes: 71056
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
#define PI 3.141592653589793
using namespace std;
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M;
    int WA[105000];
    bool AC[105000];
    cin >> N >> M;
    int WAnum = 0;
    int ACnum = 0;
    for(int i = 1; i <= N; i++) {
        WA[i] = 0;
        AC[i] = false;
    }
    while(M--) {
        int p;
        string S;
        cin >> p >> S;
        if(AC[p]) continue;
        if(S == "AC") {
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        } else if(S == "WA") {
            WA[p]++;
        }
    }

    cout << ACnum << " " << WAnum << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    bool G = false;
    bool B = false;
    while(1){
        cin >> S;
        if(S == "end"){ 
            cout << endl;
            break;
        }
        if(B)cout << " ";
        for (int i = 0; i < S.size(); i++){
            if     (S.at(i) == 'a')cout << "A";
            else if(S.at(i) == 'b')cout <<"B";
            else if(S.at(i) == 'c')cout <<"C";
            else if(S.at(i) == 'd')cout <<"D";
            else if(S.at(i) == 'e')cout <<"E";
            else if(S.at(i) == 'f')cout <<"F";
            else if(S.at(i) == 'g')cout <<"G";
            else if(S.at(i) == 'h')cout <<"H";
            else if(S.at(i) == 'i')cout <<"I";
            else if(S.at(i) == 'j')cout <<"J";
            else if(S.at(i) == 'k')cout <<"K";
            else if(S.at(i) == 'l')cout <<"L";
            else if(S.at(i) == 'm')cout <<"M";
            else if(S.at(i) == 'n')cout <<"N";
            else if(S.at(i) == 'o')cout <<"O";
            else if(S.at(i) == 'p')cout <<"P";
            else if(S.at(i) == 'q')cout <<"Q";
            else if(S.at(i) == 'r')cout <<"R";
            else if(S.at(i) == 's')cout <<"S";
            else if(S.at(i) == 't')cout <<"T";
            else if(S.at(i) == 'u')cout <<"U";
            else if(S.at(i) == 'v')cout <<"V";
            else if(S.at(i) == 'w')cout <<"W";
            else if(S.at(i) == 'x')cout <<"X";
            else if(S.at(i) == 'y')cout <<"Y";
            else if(S.at(i) == 'z')cout <<"Z";
            else if(S.at(i) == 'A')cout <<"a";
            else if(S.at(i) == 'B')cout <<"b";
            else if(S.at(i) == 'C')cout <<"c";
            else if(S.at(i) == 'D')cout <<"d";
            else if(S.at(i) == 'E')cout <<"e";
            else if(S.at(i) == 'F')cout <<"f";
            else if(S.at(i) == 'G')cout <<"g";
            else if(S.at(i) == 'H')cout <<"h";
            else if(S.at(i) == 'I')cout <<"i";
            else if(S.at(i) == 'J')cout <<"j";
            else if(S.at(i) == 'K')cout <<"k";
            else if(S.at(i) == 'L')cout <<"l";
            else if(S.at(i) == 'M')cout <<"m";
            else if(S.at(i) == 'N')cout <<"n";
            else if(S.at(i) == 'O')cout <<"o";
            else if(S.at(i) == 'P')cout <<"p";
            else if(S.at(i) == 'Q')cout <<"q";
            else if(S.at(i) == 'R')cout <<"r";
            else if(S.at(i) == 'S')cout <<"s";
            else if(S.at(i) == 'T')cout <<"t";
            else if(S.at(i) == 'U')cout <<"u";
            else if(S.at(i) == 'V')cout <<"v";
            else if(S.at(i) == 'W')cout <<"w";
            else if(S.at(i) == 'X')cout <<"x";
            else if(S.at(i) == 'Y')cout <<"y";
            else if(S.at(i) == 'Z')cout <<"z";
            else if(S.at(i) == '.'){ cout << "."; G = true; }
            else                 cout << S.at(i);
        }
        B = true;
            S = "end";
    }
}


Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
//using System.Linq;
class Program
{
  //static List<string> list;
	static void Main(string[] args)
	{
		// 入力フェーズ
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int K = int.Parse(input[1]);
        List<int> h = new List<int>();

        for(int i=0; i<N; i++)
        {
          int hh = int.Parse(Console.ReadLine());
          h.Add(hh);
        }
        // 木の高さを昇順に並べる
        h.Sort();

        // 低い順からK本とったときの、差をとる
        int min = -1;
        for(int i=0; i<N-K+1; i++)
        {
          int start = h[i];
          int end = h[i+K-1];

          if(min == -1 || end - start < min)
            min = end - start;
        }

    // 出力
        Console.WriteLine(min);
    }
		class myClass{ //自作クラス
			public int ID {set; get;}
			public long Point {set; get;}
		}
    static private int getMaxPoint(int solve, int[,] table)
    {
      int ret = 0;

      return ret;
    }

}


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

int main(){
    int n,k; cin>>n>>k;
    vector<int> list(n);
    for(int i=0; i<n; i++){
        cin >> list[i];
    }
    int ans=0;
    sort(list.begin(), list.end());
    for(int j=0; j<k; j++){
        ans += list[j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9 + 7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    int h,w,K,ans = 0;
    cin >> h >> w >> K;
    vector<vector<char> > g(h,vector<char>(w));
    rep0(i, h)rep0(j, w)cin >> g[i][j];
    rep0(i, 1 << h)rep0(j, 1 << w){
        vector<vector<char> > m(h,vector<char>(w));
        m = g;
        rep0(k, h)if(i & (1 << k))rep0(l, w)m[k][l] = '.';
        rep0(k, w)if(j & (1 << k))rep0(l, h)m[l][k] = '.';
        ll q = 0;
        rep0(k, h)rep0(l, w)if(m[k][l] == '#')++q;
        if(q == K)++ans;
    }
    pf(ans);
    return 0;
}


Measured memory_bytes: 3640
n, a, b = map(int, input().split())
s = input()
c = 0
bc = 0

for i in s :
	if i == "c":
		print("No")
		continue


	if i == "a" and c < (a + b):
		print("Yes")
		c += 1
		continue

	elif i == "b" and c < (a + b) and bc < b:
		print("Yes")
		c += 1
		bc += 1
		continue

	print("No")
	

Measured memory_bytes: 4016
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*int a, b, c;
	cin >> a >> b >> c;
	if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a)) {
		puts("Yes");
		return 0;
	}
	puts("No");*/


	/*int n;
	cin >> n;
	int a;
	bool ok = true;
	rep(i, n) {
		cin >> a;
		if (a % 2 == 0) {
			if (a % 3 != 0 || a % 5 != 0) {
				ok = false;
			}
		}
	}
	if (ok)puts("APPROVED");
	else puts("DENIED");*/


	int n;
	cin >> n;
	map<string, int>mp;
	set<string>set;
	string s;
	rep(i, n) {
		cin >> s;
		set.insert(s);
		mp[s]++;
	}
	vector<vector<string>>v;
	for (auto s : set) {
		if (v.size() < mp[s])v.resize(mp[s]);
		v[mp[s] - 1].push_back(s);
	}
	sort(all(v[v.size() - 1]));
	rep(i, v[v.size() - 1].size()) {
		cout << v[v.size() - 1][i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 36212
from collections import defaultdict

N, M = map(int, input().split())

MOD = 1000000007

#階乗、逆元のテーブル算出。0番目は未使用
TABLE_NUM = 10001 + N
facts = [0 for _ in range(TABLE_NUM)]
invs = [0 for _ in range(TABLE_NUM)]
finvs = [0 for _ in range(TABLE_NUM)]
def create_table():
    facts[0] = facts[1] = 1
    invs[0] = invs[1] = 1
    finvs[0] = finvs[1] = 1
    for i in range(2, TABLE_NUM):
        facts[i] = facts[i - 1] * i % MOD
        invs[i] = MOD - invs[MOD % i] * (MOD // i) % MOD
        finvs[i] = finvs[i - 1] * invs[i] % MOD
create_table()

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return facts[n] * (finvs[k] * finvs[n - k] % MOD) % MOD


#素因数分解
prime_dict = defaultdict(int)
primes = []
n = 2
m = M
M_ROOT = int(M ** 0.5)
while m > 1 and n <= M_ROOT:
    if m % n == 0:
        prime_dict[n] += 1
        primes.append(n)
        m = m // n
        continue
    n += 1

if m > M_ROOT:
    primes.append(m)
    prime_dict[m] += 1

# n = 素数の乗数合計
# r = 素数自体の数
# Ai = Pi0 ** bi0 * Pi1 ** bi1 **  ...
# A0のパターン = nCr
# A1のパターン =

ans = 1
for k in prime_dict.keys():
    v = prime_dict[k]
    count = comb(v + N - 1, N - 1)
    ans = (ans * count) % MOD
print(ans)

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

using namespace std;

#define inputInt(a) scanf("%d", &a)
#define inputStr(a) getline(cin, a)
#define clr(a) memset(a, 0, sizeof(a))
#define print(a) cout<<a<<endl

int main()
{
    int r,g,b;
    cin>>r>>g;
    b = 2*g - r;
    cout<<b<<endl;

    return 0;
}


Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll K, A, B; cin >> K >> A >> B;

	if (A + 1>= B) {
		cout << 1 + K << endl;
		return 0;
	}

	ll sum = 1;
	ll m = 0;
	while (K > 0) {
		if (m == 1) {
			sum += B;
			m = 0;
			K--;
			continue;
		}
		if (sum < A || K <= 1) {
			sum++;
			K--;
		}
		else{
			m = 1;
			sum -= A;
			K--;
		}
	}

	cout << sum << endl;
}


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

typedef pair<int,int> P;

int main(){
	int n;
	int x[52],y[52];
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d%d",&x[i],&y[i]);
	}
	
	map<P,int> m;
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			if(i == j)continue;
			m[P(x[i]-x[j],y[i]-y[j])] ++;
		}
	}
	
	int ret = 0;
	for(pair<P,int> p: m){
		ret = max( ret , p.second );
	}
	cout << n-ret << endl;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

a,b,c = inputIL()

if a+b+c>21:
  print("bust")
else:
  print("win")

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;

vector <int> presort1[51],presort2[51];
int le[51][101],ri[51][101]; // [pernah di-ambil][langkah]

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

    int n,k;
    cin >> n >> k;
    int ar[n+1],minus=0,tot=0;
    for (int i=1;i<=n;i++){
        cin >> ar[i];
        if (ar[i]<0){
            minus++;
        } else tot+=ar[i];
    }

    if (n+minus<=k){
        cout << tot << el;
        return 0;
    }
    
    for (int i=1;i<=n;i++){
        for (int j=1;j<=i;j++) presort1[i].pb(ar[j]);

        sort(presort1[i].begin(),presort1[i].end(),greater<int>());
    }

    for (int i=n;i>=1;i--){
        for (int j=i;j<=n;j++) presort2[n-i+1].pb(ar[j]);

        sort(presort2[n-i+1].begin(),presort2[n-i+1].end(),greater<int>());
    }

    for (int i=0;i<=n;i++){
        int total=0;
        for (auto x : presort1[i]) total+=x;
        
        int id=i;
        le[i][id]=total;
        for (int j=i-1;j>=0;j--){
            id++;
            total-=presort1[i][j];
            le[i][id]=total;
        }
    }    

    for (int i=0;i<=n;i++){
        int total=0;
        for (auto x : presort2[i]) total+=x;

        int id=i;
        ri[i][id]=total;
        for (int j=i-1;j>=0;j--){
            id++;
            total-=presort2[i][j];
            ri[i][id]=total;
        }
    }

    for (int i=1;i<=n;i++){
        for (int j=1;j<=k;j++){
            le[i][j]=max(le[i][j],max(le[i-1][j],le[i][j-1]));
            ri[i][j]=max(ri[i][j],max(ri[i-1][j],ri[i][j-1]));
        }
    }

    int ans=0;
    for (int i=0;i<=n;i++){
        for (int j=0;j<=k;j++){
            ans=max(ans,le[i][j]+ri[n-i][k-j]);
        }
    }

    cout << ans << el;

    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 1000000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
	}
	ifac[1000000] = mpow(fac[1000000], M - 2);
	for (ll i = 1000000; i > 0; i--) {
		ifac[i - 1] = ifac[i] * i%M;
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	return fac[a] * ifac[a - b] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(c - a + b,0) << endl;
}


Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


    class Program
    {
        static void Main(string[] args)
        {
          string[] Input = Console.ReadLine().Split(' ');
          int S = int.Parse(Input[0]);
          int W = int.Parse(Input[1]);
          if(S > W)
          {
            Console.WriteLine("safe");
          }
          else
          {
            Console.WriteLine("unsafe");
          }
        }
    }



Measured memory_bytes: 17888
// abc059.a

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a, b, c;
	cin >> a >> b >> c;
	char A = 'A' + (a[0] - 'a');
	char B = 'A' + (b[0] - 'a');
	char C = 'A' + (c[0] - 'a');
	cout << A << B << C << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * https://abc058.contest.atcoder.jp/tasks/abc058_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		char[] o = sc.next().toCharArray();
		char[] e = sc.next().toCharArray();
		sc.close();
		
		StringBuilder ans = new StringBuilder();
		for(int i=0; i<o.length; i++){
			ans.append(o[i]);
			if(i<e.length) ans.append(e[i]);
		}
 
		System.out.println(ans.toString());
		

	}

}

Measured memory_bytes: 21716
n = int(input())
length = list(map(int, input().split()))

length.sort()
cnt = 0
y_start = 1
for i in range(0, len(length)-2, 1):
    a = length[i]
    for j in range(i+1, len(length)-1, 1):
        b = length[j]
        for k in range(j+1, len(length), 1):
            c = length[k]
            if a == b or b == c:
                continue
            if (a+b) > c:
                cnt += 1

print(cnt)


Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,s=0;
	cin>>a>>b;
	for(int i=a;i<=b;i++)
	if(((i%10)==(i/10000))&&((i%100/10)==i/1000%10))
	s++;
	cout<<s;
	return 0;
	
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
s=array(N)
N.times do|i|
    s[i]=get_nsp.sort.join("")
end
s.sort!
ans=0
cnt=1
(N-1).times do|i|
  if s[i]==s[i+1]
      cnt+=1
  else
      ans+=cnt*(cnt-1)/2
      cnt=1
  end
end
puts ans+(cnt-1)*cnt/2

Measured memory_bytes: 27256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
	int q;
	long long p,n;
	char c[3];
	while(~scanf("%d",&q)){
		long long view=0;
		while(q--){
			scanf("%lld%s%lld",&p,c,&n);
			if(c[0]=='(') view+=n;
			else view-=n;
			if(view==0) printf("Yes\n");
			else printf("No\n");	
		}
	}
	return 0;
}

Measured memory_bytes: 1176
//実験ゲー
//pos[i][j] = 値i(>=0)の左からj(>=0)番目の位置(0-indexed)とおき、posの復元順序を「左下,対角→対角,右上」とすればよい。
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> P;

int n;
int x[500];
P order[500];
int query[250000];
vector<int> pos[500];
int ans[250000];

int main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n * n; i++) query[i] = -1;
	for (i = 0; i < n; i++) { cin >> x[i]; x[i]--; order[i] = P(x[i], i); query[x[i]] = i; }
	sort(order, order + n);
	
	int t = 0;
	
	//1. まだ対角成分の左隣が埋まっていない行iのうち、x_iが最小の行を選択し、対角成分の左隣まで埋める
	//2. 1の過程で、対角成分を埋めるタイミングがあれば埋める。ここで埋められなければNO.
	for (i = 0; i < n; i++) {
		int row = order[i].second;
		for (j = 0; j < row; t++) {
			if (query[t] >= 0) {
				if (pos[query[t]].size() != query[t]) { cout << "No" << endl; return 0; }
				pos[query[t]].push_back(t);
			}
			else {
				pos[row].push_back(t);
				j++;
			}
		}
	}
	
	//3. 対角成分が埋まっているが一番右までは埋まっていない行iを適当に1つ選び、一番右まで埋める。埋めた要素数 < n * nなのにiを選べなければNO.
	//4. 3の過程で、対角成分を埋めるタイミングがあれば埋める。  (↑行iを選ぶ前に4を行うケースもあるので、注意）
	while (t < n * n) {
		if (query[t] >= 0) {
			if (pos[query[t]].size() != query[t]) { cout << "No" << endl; return 0; }	//ここのチェックいらないかも
			pos[query[t]].push_back(t);
			t++;
			continue;
		}
		
		for (i = 0; i < n; i++) if (i + 1 <= pos[i].size() && pos[i].size() < n) break;
		if (i == n) { cout << "No" << endl; return 0; }
		
		while (pos[i].size() < n) {
			if (query[t] >= 0) {
				if (pos[query[t]].size() != query[t]) { cout << "No" << endl; return 0; } //ここのチェックいらないかも
				pos[query[t]].push_back(t);
			}
			else {
				pos[i].push_back(t);
			}
			t++;
		}
	}
	
	//構成完了
	for (i = 0; i < n; i++) for (j = 0; j < pos[i].size(); j++) ans[pos[i][j]] = i;
	cout << "Yes" << endl;
	for (i = 0; i < n * n; i++) {
		cout << ans[i] + 1;
		if (i + 1 < n * n) cout << " ";
	}
	cout << endl;
	return 0;
}

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

int main(void)
{
    int n;
    cin >> n;
    int a[n];
    int ans = 1;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        if(a[i]%2==0)
        {
            if((a[i]%3==0) || (a[i]%5==0))
            {
            }
            else
            {
                ans = 0;
                break;
            }

        }
    }
    cout << (ans == 1 ? "APPROVED" : "DENIED") << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}

signed main(){
  int n; cin>>n;
	VL a(n); rep(i,n) cin>>a[i]; sort(RALL(a));
	VL b; ll ans=0;
	rep(i,n-1){
		if(a[i]==a[i+1]){
			b.PB(a[i]); i++;
		}
	}
	if(b.size()<2) ans=0;
	else ans=b[0]*b[1];
	cout << ans << endl;
  return 0;
}


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

#define int long long
using namespace std;
#define maxn 100010
int n,m;
vector<int> g[maxn];
int indegree[maxn] ,dist[maxn] ;
bool visited[maxn];

void dfs(int v,int p){
    visited[v] = true;
    for(auto x: g[v]){
        if(x == p)continue;
        dist[x] = max(dist[x] , 1 + dist[v]);
        indegree[x]--;
        if(indegree[x] == 0 and !visited[x])
            dfs(x ,v);
    }
}

int32_t main() {

    cin >> n >> m;

    int a ,b;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        g[a].push_back(b);
        indegree[b]++;
    }
    for(int i = 1; i <= n ;i++){
        if(!visited[i] and indegree[i] == 0)
            dfs(i , -1);
    }
    int ans = 0;
    for (int j = 1; j <= n; ++j) {
        ans = max(ans,dist[j]);
    }
    cout << ans;
}



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

#define ll long long int

using namespace std;

int main() {
    ll n;
    cin >> n;
    ll res = 0;
    for (ll i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        res += a - 1;
    }
    cout << res << endl;
}


Measured memory_bytes: 3600
#include <iostream>        
                           
using namespace std;       
int main(void){            
  int a,b,c,ans;           
  cin >> a >> b >> c;      
  if(b/a > c) ans = c;     
  else ans = b/a;          
  cout << ans << endl;     
  return 0;                
}                          
                           
                           
                           

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x, y, z, k, s;
    cin >> k >> s;
    int ans = 0;
    for (x = 0; x <= k; x++)
    {
        for (y = 0; y <= k && x + y <= s; y++)
        {
            for (z = s - (x + y); z <= k && x + y + z <= s; z++)
            {
                if (x + y + z == s)
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    vector <ll> v(n);
    generate(all(v),nxtl);
    ll test=1;
    for(int i=0;i<n;i++)
    {
        ll g=__gcd(test,v[i]);
        test*=(v[i]/g);
    }
    cout<<test<<endl;
    
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    // 整数の入力
    int A,B;

    cin >> A >> B;

    if(A > B){
        cout << (2 * A - 1);
    }else if(A == B){
        cout << (2 * A);
    }else{
        cout << (2 * B - 1);
    }

    return 0;
}

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

using namespace std;

class ModInt {
    using ll = long long;

public:
    int value;
    static int MOD;

    ModInt(ll value = 0) {
        this->value = value % MOD;
        if (this->value < 0) this->value += MOD;
    }

    operator int() const noexcept { return this->value; }

    ModInt& operator=(const ModInt& x) {
        if (this != &x) { this->value = x.value; }
        return *this;
    }

    bool operator==(const ModInt& x) const { return this->value == x.value; }
    bool operator!=(const ModInt& x) const { return !(*this == x); }

    ModInt operator+() const { return value; }
    ModInt operator-() const { return MOD - value; }
    ModInt operator~() const { return (*this) ^ (ModInt(MOD - 2)); }

    ModInt operator++() { return *this += 1; }
    ModInt operator--() { return *this -= 1; }

    ModInt operator++(int) {
        ModInt before = *this;
        ++(*this);
        return before;
    }
    ModInt operator--(int) {
        ModInt before = *this;
        --(*this);
        return before;
    }

    ModInt operator+=(const ModInt& x) { return *this = (this->value + x.value) % MOD; }
    ModInt operator-=(const ModInt& x) { return *this = (this->value + MOD - x.value) % MOD; }
    ModInt operator*=(const ModInt& x) { return *this = ll(this->value) * ll(x.value) % MOD; }
    ModInt operator/=(const ModInt& x) { return *this *= ~ModInt(MOD - 2); }

    ModInt operator^=(const ModInt& x) {
        int n = int(x);
        if (n == 0) return ModInt(1);
        if (n & 1) {
            return (*this) = ((*this) ^ ModInt(n - 1)) * (*this);
        } else {
            return (*this) = ((*this) * (*this)) ^ ModInt(n / 2);
        }
    }

    ModInt operator+(const ModInt& b) const { return ModInt(*this) += b; }
    ModInt operator-(const ModInt& b) const { return ModInt(*this) -= b; }
    ModInt operator*(const ModInt& b) const { return ModInt(*this) *= b; }
    ModInt operator/(const ModInt& b) const { return ModInt(*this) /= b; }
    ModInt operator^(const ModInt& b) const { return ModInt(*this) ^= b; }
};

int ModInt::MOD = 1000000007;

ostream& operator<<(ostream& os, const ModInt& x) { return os << x.value; }
istream& operator>>(istream& is, ModInt& x) { return is >> x.value; }


const int dx[2] = {0, 1}, dy[2] = {1, 0};

ModInt pat[1001][1001];
bool visited[1001][1001];

int main() {
    int H, W;
    cin >> H >> W;

    string S[H];
    for (int i = 0; i < H; ++i) {
        cin >> S[i];
    }

    pat[0][0] = 1;

    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));

    while (!que.empty()) {
        int x, y;
        tie(x, y) = que.front();
        que.pop();

        if (visited[x][y]) continue;
        visited[x][y] = true;

        for (int i = 0; i < 2; ++i) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || H <= nx || ny < 0 || W <= ny || S[nx][ny] == '#') continue;

            que.push(make_pair(nx, ny));
            pat[nx][ny] += pat[x][y];
        }
    }

    cout << pat[H - 1][W - 1] << endl;
    return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    int m;  // |S_i|
    int a = 0;  // n = m*(m+1)/2 となるmが存在するかチェックする変数
    int flag = 0;  // 条件を満たす部分集合の組が存在するとき1
    for(m = 1; m <= 500; m++) {
        a += m;
        if(a == n) {
            flag = 1;
            break;
        }
    }

    if(flag) {

        cout << "Yes" << "\n";
        cout << m+1 << "\n";
        
        vector<vector<int>> v(m+1, vector<int>(m));
        rep(j, m) {
            v[0][j] = j+1;
        }
        for(int i = 1; i <= m; i++) {

            for(int j = 0; j < i; j++) {
                v[i][j] = v[j][i-1];
            }

            int k = (2*m+1-i)*i/2 + 1;
            for(int j = i; j < m; j++) {
                v[i][j] = k;
                k++;
            }

        }

        rep(i, m+1) {
            cout << m << " ";
            rep(j, m) {
                cout << v[i][j] << " ";
            }
            cout << "\n";
        }

    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

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

#define _GLIBCXX_DEBUG

int main() {
  int n, z;
  set<int> d;
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> z;
    d.insert(z);
  }

  cout << d.size() << endl;
}

Measured memory_bytes: 256
h,w,n = gets.split.map(&:to_i)
sr,sc = gets.split.map(&:to_i)
s = gets.chomp.split('')
t = gets.chomp.split('')
hh = Hash.new(0)
th = Hash.new(0)
c = {'L' => 'R', 'R' => 'L', 'U' => 'D', 'D' => 'U'}
s.each_index do |i|
  hh[s[i]] += 1
  if hh['L'] >= sc || hh['R'] > w - sc || hh['U'] >= sr || hh['D'] > h - sr
    puts 'NO'
    exit
  end
  case t[i]
  when 'L'
    next if th['L'] >= sc - 1
  when 'R'
    next if th['R'] >= w - sc
  when 'U'
    next if th['U'] >= sr - 1
  when 'D'
    next if th['D'] >= h - sr
  end
  th[t[i]] += 1
  th[c[t[i]]] -= 1
  hh[c[t[i]]] -= 1
end
puts 'YES'


Measured memory_bytes: 22780
#include<bits/stdc++.h>
#define MAX 101
#define inf 1<<29
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define phi (1.0+sqrt(5))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int n,m;
int g[MAX][MAX];
bool used[MAX][MAX];

void dijkstra(int s){
  int d[MAX],p[MAX];
  priority_queue<pii,vector<pii>,greater<pii> > pq;
  fill(d,d+MAX,inf);
  fill(p,p+MAX,-1);
  d[s]=0;
  p[s]=s;
  pq.push(mp(0,s));

  while(pq.size()){
    pii u=pq.top();
    pq.pop();
    if(d[u.s]<u.f)continue;

    FOR(i,0,n){
      if(i==u.s || g[u.s][i]==inf)continue;
      int cost=g[u.s][i]+d[u.s];
      if(cost<d[i]){
        d[i]=cost;
        p[i]=u.s;
        pq.push(mp(cost,i));
      }
    }
  }
//  FOR(i,0,n)cout<<d[i]<<" ";
//  cout<<endl;
  FOR(i,0,n){
    if(s==i)continue;
    int ni=i;
    while(ni!=p[ni]){
      used[ni][p[ni]]=true;
      ni=p[ni];
    }
  }
}

int solve(){
  FOR(i,0,n){
    dijkstra(i);
  }
  int res=0;
  FOR(i,0,n)FOR(j,i+1,n)if(!used[i][j])res++;
  return res;
}

int main()
{
  FOR(i,0,MAX){
    FOR(j,0,MAX){
      g[i][j]=inf;
      used[i][j]=true;
    }
  }
  cin>>n>>m;
  FOR(i,0,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    g[a][b]=c;
    g[b][a]=c;
    used[a][b]=false;
    used[b][a]=false;
  }
  cout<<solve()<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXLEN = 100000;

char s[MAXLEN + 1]; int len;
char p[4][10] = { "dream","dreamer","erase","eraser" };

bool can[MAXLEN + 1];

void run() {
	scanf("%s", s); len = strlen(s);
	memset(can, false, sizeof(can)); can[0] = true;
	REP(i, len) if (can[i]) {
		REP(j, 4) {
			int cnt = strlen(p[j]);
			bool ok = true; REP(k, cnt) if (s[i + k] != p[j][k]) { ok = false; break; } if (!ok) continue;
			can[i + cnt] = true;
		}
	}
	printf("%s\n", can[len] ? "YES" : "NO");
}


int main() {
	run();
	return 0;
}


Measured memory_bytes: 512
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      total = 500*i + 100*j + 50*k
      if total == x:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>

using namespace std;

char s[300'009];

int main() {
  scanf("%*d %s", s);
  int e = 0;
  for (int i = 0; s[i]; ++i) {
    e += (s[i] == 'E');
  }
  int w = 0;
  int ans = 1'000'000'000;
  for (int i = 0; s[i]; ++i) {
    e -= (s[i] == 'E');
    ans = min(ans, e + w);
    w += (s[i] == 'W');
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

ll q;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>q;
	ll a=0,b=0;
	rep(i,q){
		ll p,n;char c;
		cin>>p>>c>>n;
		if(c=='(')a+=n;
		else b+=n;
		cout<<(a==b?"Yes":"No")<<endl;
	}
}

Measured memory_bytes: 1188
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{
    return a * b / gcd(a, b);
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/
int main()
{
    kira;
    lli n,m;
    cin>>n>>m;
    priority_queue<lli>pq;
    vector<pair<lli,lli>>v;
    lli a,b;
    forz(i,n)
    {
        cin>>a>>b;
        v.pb({a,b});
    }
    sort(all(v));
    lli in=0;
    lli ans=0;
    for(int i=1;i<=m;i++)
    {
        while(v[in].F==i&&in<n)
        {
            pq.push(v[in].S);
            in++;
        }
        if(!pq.empty())
        {
            ans+=pq.top();
            pq.pop();
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3568
# code-festival-2016-qualaB - 仲良しうさぎ / Friendly Rabbits
# exhaustive search
def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))
    ans = sum(i == A[j] for i, j in enumerate(A[1:], 1)) // 2
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14008
//
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    static constexpr long long mod = 1e9 + 7;
    long long N, K;
    cin >> N >> K;
    long long ans = 0;
    for (long long i = K; i <= N + 1; ++i)
    {
        //ans += (i * (2LL * N - 2LL * i + 1LL)) / 2LL + 1LL;
        long long minval = (i * (i - 1LL)) / 2LL;
        long long maxval = (i * (2LL * N - i + 1LL)) / 2LL;
        ans += maxval - minval + 1LL;
        ans = ans % mod;
        if (ans < 0) ans = (ans + mod) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
n = int(input())

dp = [i for i in range(101010)]

#dp[i] = i円払うのに必要な最小値
#6ˆn円,0<=i<=Nにおいて、dp[i+6ˆn] = min(dp[i+6ˆn] ,dp[i]+1)  

#6の倍数
t = 10
while True:
    for i in range(101010):
        if 6**t+(i+1) < 101010:
            dp[6**t+(i)] = min(dp[6**t+(i)], dp[i] + 1) 
    t -= 1
    if t == 0:
        break

#9の倍数
t = 10
while True:
    for i in range(101010):
        if 9**t+(i+1) < 101010:
            dp[9**t+(i)] = min(dp[9**t+(i)], dp[i] + 1)
    t -= 1
    if t == 0:
        break

i = 0
while i+1 < 101010:
    dp[i+1] = min(dp[i+1],dp[i]+1)
    i += 1

#print(dp)
print(dp[n])

Measured memory_bytes: 7064