akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a[25],b[25],ans;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(n);
	for(int i=1;i<=n;i++)in(a[i]);for(int i=1;i<=n;i++)in(b[i]);
	for(int i=1;i<=n;i++){
		if(a[i]>b[i])ans+=a[i]-b[i];
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,M; cin>>N>>M;
  vi A(N);
  int AC=0,WA=0;
  rep(i,0,M){
    int X; string Y; cin>>X>>Y;
    X--;
    if(Y=="AC"){
      if(A[X]>=0){
        WA+=A[X];
        A[X]=-1;
        AC++;
      }
    }
    else{
      if(A[X]>=0){
        A[X]++;
      }
    }
  }
  cout<<AC<<" "<<WA<<endl;
  }



Measured memory_bytes: 1024
n = int(raw_input())

s = raw_input()

count = 0

num_list= s.split(" ")
for i in range(n):
    num_list[i] = int(num_list[i])

for i in range(n):
    minj = i
    for j in range(i, n):
        if num_list[j] < num_list[minj]:
            minj = j
    num_list[i], num_list[minj] = num_list[minj], num_list[i]
    if i != minj:
        count += 1

print " ".join([str(a) for a in num_list])
print count

Measured memory_bytes: 6352
a = [input().split() for l in range(2)]
N=int(a[0][0])
p=a[1]
count=0
for i in range(N):
    if int(p[i])!=i+1:
        count=count+1

if count==0 or count==2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vector<int> V(N);
    int L[100100],R[100010];
    int Lans = 0;
    int Rans = INF;
    REP(i,M){
        cin >> L[i] >> R[i];
        Lans = max(Lans,L[i]); Rans = min(Rans,R[i]);
        if(Lans > R[i] || Rans < L[i]){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << Rans - Lans +1 << endl;
}

Measured memory_bytes: 1408
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans=0
cnt=0
fin=False
while not fin:
    fin=True
    z_cnt=0
    o_cnt=0
    for i in range(len(a)):
        q,mod = divmod(a[i],2)
        a[i]=q
        if q!=0:
            fin=False
        if mod==0:
            z_cnt+=1
        else:
            o_cnt+=1

    ans+=(z_cnt*o_cnt) * pow(2,cnt)
    ans%=10**9+7
    cnt+=1
print(ans)

Measured memory_bytes: 122936
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
int a[9], used[9], ans = 0;

void calc() {
  int _p = a[0]+a[2]+a[5], p =_p%10; // 1
  int _q = _p/10+a[1]+a[4], q = _q%10; // 10
  int _r = _q/10+a[3], r = _r%10; // 100
  if (p==a[8] && q==a[7] && r==a[6]) ans++;
}

void dfs(int x) {
  if (x == 9) {
    calc();
  } else if (a[x] != -1) {
    dfs(x+1);
  } else {
    for(int i=0;i<9;i++){
      if(used[i]==1) continue;
      used[i]=1, a[x]=i+1;
      dfs(x+1);
      used[i]=0, a[x]=-1;
    } 
  }
}

signed main() {
  for (int i = 0; i < 9; i++) {
    cin >> a[i];
    if (a[i] != -1) used[a[i]-1]=1;
  }
  dfs(0);
  cout << ans << endl;
}




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

const int N = 1e5 + 10;
string ans[N], s[N];
int n;
void dfs(int u, int a, int b, int c) {
	if(u == n + 1) {
		cout << "Yes\n";
		for(int i = 1;i <= n; i++) cout << ans[i] << "\n";
		exit(0); 
	}
	
	if(s[u] == "AB") {
		if(a > 0) ans[u] = "B", dfs(u + 1, a - 1, b + 1, c);
		if(b > 0) ans[u] = "A", dfs(u + 1, a + 1, b - 1, c);
	}
	else if(s[u] == "BC") {
		if(b > 0) ans[u] = "C", dfs(u + 1, a, b - 1, c + 1);
		if(c > 0) ans[u] = "B", dfs(u + 1, a, b + 1, c - 1);
	}
	else {
		if(a > 0) ans[u] = "C", dfs(u + 1, a - 1, b, c + 1);
		if(c > 0) ans[u] = "A", dfs(u + 1, a + 1, b, c - 1);
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c;
	cin >> n >> a >> b >> c;
	for(int i = 1; i <= n; i++) cin >> s[i];
	dfs(1, a, b, c);
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 17608
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
#define MAXN 100000
#define M 1000000007
#define LL long long
LL n,m,p,q,ans,S;
LL fac[MAXN*2+5],inv[MAXN*2+5];
LL fst_pow(LL A,int B)
{
	LL ret=1;
	while(B)
	{
		if(B&1)ret=ret*A%M;
		A=A*A%M;
		B>>=1;
	}
	return  ret;
}
void init()
{
	fac[0]=1;
	for(int i=1;i<=S;i++)
	{
		fac[i]=(fac[i-1]*(i%M))%M;
	}
	inv[S]=fst_pow(fac[S],M-2);
	inv[0]=1;
	for(int i=S-1;i>=1;i--)
	{
		inv[i]=(inv[i+1]*((i+1)%M))%M;
	}
}
LL Comb(int N,int R)
{
	if(N<0||R<0)return 1;
	return fac[N]*inv[R]%M*inv[N-R]%M;
}
int main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&p,&q);
	S=n+m-2;
	init();
	ans=Comb(n+m-2,n-1);
	for(int i=1;i<=q;i++)
	{
		ans-=Comb(n-p+i-2,n-p-1)*Comb(p-1+m-i,p-1)%M;
		//printf("%lld %lld\n",Comb(n-p+i-2,n-p-1),Comb(p-1+m-i,p-1));
		ans=(ans%M+M)%M;
	}
	printf("%lld",ans);
}
//2 3 1 1
//10 7 3 4


Measured memory_bytes: 3328
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

typedef double D;
typedef complex<D> P;

const D INF = 1e100;

void mainmain(){
	D xs, ys, xt, yt;
	int n;
	cin >> xs >> ys >> xt >> yt >> n;
	vector<P> cs(n + 2);
	vector<D> rs(n + 2);
	cs[n] = P(xs, ys);
	cs[n + 1] = P(xt, yt);
	for(int i = 0; i < n; ++i){
		D x, y;
		cin >> x >> y >> rs[i];
		cs[i] = P(x, y);
	}

	vector<D> ds(n + 2, INF);
	vector<char> vis(n + 2);
	ds[n] = 0;
	int u = n;
	while(u >= 0){
		vis[u] = 1;
		D next = INF;
		int v = -1;
		for(int i = 0; i < n + 2; ++i){
			if(vis[i]){ continue; }
			D t = ds[u] + max(abs(cs[u] - cs[i]) - rs[u] - rs[i], 0.0);
			ds[i] = min(ds[i], t);
			if(next > ds[i]){
				next = ds[i];
				v = i;
			}
		}
		u = v;
	}
	
	cout << ds.back() << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

int main() {
    char a;
    cin >> a;
    string S = "aeiou";
    for (int i = 0; i < S.size(); i++) {
        if (a == S[i]) {
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;
}

Measured memory_bytes: 256
/*

Sviatoslav Bidzilia 2019
CF: anakib1

*/

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long

template<typename A, typename B, typename C>
struct triple
{
	A X;
	B Y;
	C Z;
	triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
{
	return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
{
	if (a.X != b.X)
		return a.X < b.X;
	if (a.Y != b.Y)
		return a.Y < b.Y;
	return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
{
	ofs << "( " << p.F << " , " << p.S << " )";
	return ofs;
}
template<typename T>
void print(T a)
{
	for (auto i : a)
		cout << i << ' ';
	cout << '\n';
}
template<typename T>
T max(T a, T b, T c)
{
	return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c)
{
	return min(a, min(b, c));
}
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const
	{
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
int n;
int f(deque<int>& a, deque<int>& b, int x)
{
	int need = 0;
	for (int i = 0; i < n; i++)
		need += max(0LL, a[i] - x/b[i]);
	return need;
}
signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	int k;
	cin >> n >> k;
	deque<int> a, b;
	a = b = deque<int>(n);
	for (auto& i : a)
		cin >> i;
	for (auto& i : b)
		cin >> i;
	SORT(a);
	sort(b.rbegin(), b.rend());
	int l = 0, r = 1e18;
	while (r - l > 1)
	{
		int m = l + r >> 1;
		if (f(a, b, m) <= k)
			r = m;
		else
			l = m;
	}
	if (f(a, b, l) <= k)
		cout << l << '\n';
	else
		cout << r << '\n';
}

Measured memory_bytes: 3584
def Main():
    N, K = map(int, input().split())
    S = input()
    arr = []
    arr.append(0)
    if S[0] == '0':
        arr.append(0)
    cnt = 1
    for i in range(1, N):
        if S[i-1] == S[i]:
            cnt += 1
        else:
            arr.append(cnt)
            cnt = 1
    arr.append(cnt)
    n = len(arr)
    for i in range(1, n):
        arr[i] += arr[i-1]
    #print(arr)
    ans = 0
    sum = 0
    l = 0
    for r in range(1, n):
        while((r-l)//2 > K):
            l += 2
        #print(l, r)
        ans = max(ans, arr[r]-arr[l]) 
       
    print(ans)

if __name__ == "__main__":
    Main()


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

int main() {
  int N;
  string a;
  cin >> N ;
  string m = "Three";
  for(int i=0; i< N;i++){
  cin >>a;
    if (a =="Y"){
    m = "Four";
    }
  }
  cout << m << endl;
}

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

int main() {
  int N; cin >> N;
  int D[N]; for (int i = 0; i < N; i++) cin >> D[i];
  int sum = 0;
  for (int i = 0; i < N-1; i++) {
    for (int j = i+1; j < N; j++) {
      sum += D[i] * D[j];
    }
  }
  cout << sum << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

const int MAX = 2e5+10;

ll N, K;
ll A[MAX];

void solve() {
    REP (k, K) {
        vi imos(N+1);
        ll mn = MAX;
        REP (i, N) {
            CHMIN(mn, A[i]);
            imos[max(0ll, i-A[i])]++;
            imos[min(N, i+A[i]+1)]--;
        }
        REP (i, N-1) imos[i+1] += imos[i];
        REP (i, N) A[i] = imos[i];
        if (mn == N) return;
    }
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N >> K;
    REP (i, N) cin >> A[i];
    solve();
    REP (i, N) cout << A[i] << " ";
    cout << endl;
}

Measured memory_bytes: 6712
# -*- coding: utf-8 -*-
"""
A - Wanna go back home
https://atcoder.jp/contests/agc003/tasks/agc003_a

"""
import sys


def solve(S):
    if ('N' in S and 'S' not in S) or ('S' in S and 'N' not in S):
        return 'No'
    if ('E' in S and 'W' not in S) or ('W' in S and 'E' not in S):
        return 'No'
    return 'Yes'


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
/*************************************************************************
    > File Name: B.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com 
    > Created Time: 2018-12-15 20:03:59
 ************************************************************************/

#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll tot,n,ans,a[MAXN];
bool vis[MAXN];
map<ll,ll> mp;
multiset<ll> s;
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++) 
    {
        ll x;
        scanf("%lld",&x);
        s.insert(x);
    }
    while(s.size())
    {
        auto it=s.end();it--;
        ll v=*it;
        s.erase(it);
        ll x=1;while(x<=v) x*=2;
        if(s.count(x-v))
        {
            s.erase(s.find(x-v));
            ans++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 9600
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ab.sort(key=lambda x:(x[1]))
c = 0
brid = -1
for a,b in ab:
    if a > brid:
        c += 1
        brid = b-1
print(c)

Measured memory_bytes: 29084
x = STDIN.gets.chomp.to_i

d = x / 11
m = x % 11

if m == 0 then
  STDOUT.puts (d * 2)
elsif m <= 6 then
  STDOUT.puts (d * 2 + 1)
else
  STDOUT.puts (d * 2 + 2)
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long x;
	cin>>x;
	for(long long i=1;i<300;i++){
		for(long long j=i-1;j>-300;j--){
			if(((i*i*i*i*i)-(j*j*j*j*j))==x){
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#define MOD	10000

int N, K, A[112], B[112];
int selected[112], memo[112][3][3][3], ans = -1;

// dp(i,A,B,C) := i??\??????????????????A??§,i+1??\??????????????????B??§???
//					i+2??\??????????????????C?????????i+3??\?????\????????????????????°
int dp(int i, int A, int B, int C) {
	int res = 0;
	if (A >= 0&&B >= 0&&C >= 0 && memo[i][A][B][C] != -1) { return memo[i][A][B][C]; }
	if (A == B&&B == C) { return memo[i][A][B][C] = 0; }
	if (i == N) { return memo[i][A][B][C] = 1; }
	if (selected[i] != 0) { return memo[i][A][B][C] = dp(i + 1, B, C, selected[i]); }
	else {
		for (int j = 1; j <= 3; ++j) {
			res += dp(i + 1, B, C, j) % MOD;
		}
	}
	if (A >= B >= C >= 0) { memo[i][A][B][C] = res % MOD; }
	return memo[i][A][B][C];
}

int main(void) {
	scanf("%d%d", &N, &K);
	for (int i = 0; i < K; ++i) { scanf("%d%d", &A[i], &B[i]); }

	memset(memo, -1, sizeof(memo));
	for (int i = 0; i < K; ++i) { selected[A[i] - 1] = B[i]; }

	printf("%d\n", dp(0, -1, -2, -3));
	return 0;
}

Measured memory_bytes: 2728
N = int(input())
a = list(map(int, input().split()))

a_sum = [0]*N
cur = 0
for i in range(0,N):
    cur += a[i]
    a_sum[i] = cur

ans = abs(cur-2*a_sum[0])
for i in range(1,N-1):
    if ans > abs(cur-2*a_sum[i]):
        ans = abs(cur-2*a_sum[i])

print(ans)

Measured memory_bytes: 24832
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

long a[3][100005];
long b[100005];
ll sb[100005];
ll c[100005];

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    long i,j;
    for(i=0; i<3; i++) {
        for(j=0; j<n; j++) {
            scanf("%ld", &a[i][j]);
        }
    }

    for(i=0; i<3; i++) {
        sort(&(a[i][0]), &(a[i][0])+n);
    }

    for(i=0; i<n; i++) {
        long tmp = lower_bound( &(a[0][0]), &(a[0][0])+n, a[1][i]) - &(a[0][0]);
        b[i] = tmp-1+1;
    }

    sb[0]=0;
    for(i=0; i<n; i++) {
        sb[i+1] = sb[i]+b[i];
    }

    for(i=0; i<n; i++) {
        long tmp = lower_bound( &(a[1][0]), &(a[1][0])+n, a[2][i]) - &(a[1][0]);
        c[i] = sb[tmp];
    }

    ll sum=0;
    for(i=0; i<n; i++) {
        sum += c[i];
    }

    printf("%lld\n", sum);
 
    return 0;
}


Measured memory_bytes: 4864
// Problem : B - Tag
// Contest : AtCoder - Tokio Marine & Nichido Fire Insurance Programming Contest 2020
// URL : https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	ll a,v,b,w,t;
	cin >> a >> v >> b >> w >> t;
	int f=0;
	if(a<b)
	{
		a=a+v*t;
		b=b+w*t;
		if(a>=b)
		f=1;
	}
	else
	{
		a=a-v*t;
		b=b-w*t;
		if(a<=b)
		f=1;
	}
	if(f)
	cout << "YES" << endl;
	else
	cout << "NO" << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


Measured memory_bytes: 3640
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

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

const ll MOD = 1e9 + 7;


int main(int argc, char* argv[]) {
	
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}

	int sum = 0;
	for (int ai : a) {
		sum += ai;
	}

	int ans = n - sum;
	if (ans < 0) {
		ans = -1;
	}

	cout << ans << endl;
	


}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

VI adj[10010];

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    REP(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        adj[a].eb(b);
        adj[b].eb(a);
    }
    VI cs(N);
    REP(i,N) cin >> cs[i];
    sort(cs.begin(),cs.end(),greater<int>());

    LL ans = 0;
    FOR(i,1,N) ans += cs[i];

    queue<int> que;
    VI order;
    int used[10010] = {};
    order.pb(0);
    que.push(0);
    used[0] = 1;
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(auto p : adj[v]){
            if(used[p] == 0){
                que.push(p);
                order.pb(p);
                used[p] = 1;
            }
        }
    }
    //cout << ans << endl;
    int slot[10010];
    REP(i,N){
        dump(order[i])
        slot[order[i]] = cs[i];
    }
    cout << ans << endl;
    REP(i,N){
        cout << slot[i] << " ";
    }
    cout << endl;


}

Measured memory_bytes: 1152
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	long long int t = K;
	while (--N) {
		t *= K - 1;
	}
	cout << t << endl;

	return 0;
}

Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

n = int(input())
s = input()
stack = []
ans = deque(list(s))
countl = 0
countr = 0
for c in s:
    if c == '(':
        stack.append('(')
    if c == ')':
        if stack:
            stack.pop()
        else:
            countl+=1
countr = len(stack)
for i in range(countl):
    ans.appendleft('(')
for i in range(countr):
    ans.append(')')
print(''.join(ans))

Measured memory_bytes: 38256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=100005;

using Pl = pair<int,ll>;
ll d[MAX_N];
vector<Pl> graph[MAX_N];
int N,Q,K;

void dfs(int x){
  for(auto&& y:graph[x]){
    int a; ll b;
    tie(a,b) = y;
    if(d[a]==-1){
      d[a]=d[x]+b;
      dfs(a);
    }
  } 
}

int main(){
  cin >> N ;
  rep(i,N-1){
    int a,b; ll c;
    scanf("%d%d%lld",&a,&b,&c);
    a--; b--;
    graph[a].pb(Pl(b,c)); graph[b].pb(Pl(a,c));
  }
  cin >> Q >> K ;
  fill(d,d+N,-1);
  d[--K]=0;
  dfs(K);
  rep(i,Q){
    int a,b;
    scanf("%d%d",&a,&b);
    a--; b--;
    printf("%lld\n",d[a]+d[b]);
  }
  return 0;
}

Measured memory_bytes: 12672
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>
#include <set>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> v(n + 1, 0);
    int l = 1, r = n;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        l = max(l, a);
        r = min(r, b);
    }

    int count = max(r - l + 1, 0);

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define LL long long
#define FOR(i,l,r) for(int i = l; i <= r; ++i)
#define REP(i,l,r) for(int i = l; i < r; ++i)
#define pi pair<int,LL>
#define mp make_pair

const int maxN = 301;
const LL oo = 1e16;

int N,M,L,Q;
LL F[maxN][maxN],C[maxN][maxN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    //
    //freopen("E.INP","r",stdin);
    //freopen("E.OUT","w",stdout);

    cin >> N >> M >> L;
    FOR(i,1,N) FOR(j,1,N) F[i][j] = C[i][j] = oo;
    //
    FOR(i,1,M){
        int u,v,c;
        cin >> u >> v >> c;
        F[u][v] = F[v][u] = min(F[u][v],1LL * c);
    }
    FOR(k,1,N)
    FOR(i,1,N)
    FOR(j,1,N) F[i][j] = min(F[i][j],F[i][k] + F[k][j]);
    //
    FOR(i,1,N) FOR(j,1,N) if(F[i][j] <= L) C[i][j] = 1;
    //
    FOR(k,1,N)
    FOR(i,1,N)
    FOR(j,1,N) C[i][j] = min(C[i][j],C[i][k] + C[k][j]);
    //
    cin >> Q;
    FOR(i,1,Q){
        int s,t;
        cin >> s >> t;
        if(C[s][t] >= oo) cout << -1 << endl;
        else cout << C[s][t] - 1 << endl;
    }

    return 0;

}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int q;

int main() {
	cin >> q;
	ll num = 0;
	rep(i, q) {
		int p, n;
		char c;
		cin >> p >> c >> n;
		if (c == '(')num += n;
		else num -= n;
		if (num == 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


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

using namespace std;
typedef long long ll;
int main(){
	ll X, K, D;
	cin >> X >> K >> D;
	
	// X >= 0として一般性を失わない!
	X = abs(X);

	ll ans;
	if (X / D - K > 0)
	{
		// 原点まで至らない場合 K * D < X <= 10^15 が保証されるので掛け算OK
		ans = X - K * D;
	}else {
		ll di = X / D; // 引ける回数
		ll x0 = X - di * D; // x >= 0 側で最接近したときの座標
		ll k0 = K - di; // x >= 0 側で最接近したときの残り回数

		if (k0 % 2 == 0)
		{
			// 残り偶数回数移動
			ans = x0;
		} else {
			// 残り奇数回数移動
			ans = D - x0;
		}
		
	}
	cout << ans << endl;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  bool failf = false;
  rep(i,n-1){
    if(a.at(i) == a.at(i+1)){
      failf = true;
    }
  }
  if(failf){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
}
        
    
      
    
      
  
  

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstring>
using namespace std;
typedef long long int ll;
const int MAX=100;
const int MAX_cap=10000;

class edge
{
public:
	int to,cap,rev;
	edge(){}
	edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
};

vector<edge> G[MAX];
int level[MAX];//s->v distance

void add_edge(int from,int to,int cap)
{
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,0,G[from].size()-1));
	return;
}

void bfs(int s)
{
	memset(level,-1,sizeof(level));
	queue<int> Q;
	level[s]=0;
	Q.push(s);
	
	while(!Q.empty())
	{
		int v=Q.front();Q.pop();
		for(int i=0;i<G[v].size();i++)
		{
			edge e=G[v][i];
			if(e.cap>0&&level[e.to]<0)
			{
				level[e.to]=level[v]+1;
				Q.push(e.to);
			}
		}
	}
	return;
}

int dfs(int v,int t,int f)
{
	if(v==t)return f;
	for(int i=0;i<G[v].size();i++)
	{
		edge &e=G[v][i];
		if(e.cap>0&&level[v]<level[e.to])
		{
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0)
			{
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int maxflow(int s,int t)
{
	int flow=0;
	while(1)
	{
		bfs(s);
		if(level[t]<0)return flow;
		int f;
		while((f=dfs(s,t,MAX_cap))>0)flow+=f;
	}
}
int main()
{
	int V,E;cin>>V>>E;
	int u,v,c;
	for(int i=0;i<E;i++)
	{
		cin>>u>>v>>c;
		add_edge(u,v,c);
	}
	cout<<maxflow(0,V-1)<<endl;
	return 0;
}

Measured memory_bytes: 3128
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
ll a[100000];
ll dom[100001];
int main(){
  int n;
  ll su=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    su+=a[i];
  }
  ll cnt=0;
  ll tmp=0;
  for(ll i=1;i<=n;i++){
    dom[i]=su;
    cnt=0;
    tmp=i+1;
    if(i==1){
    while(cnt!=(n-1)/2){
      if(tmp>n) tmp%=n;
      dom[i]-=(2*a[tmp]);
      //cout<<dom[i]<<endl;
      tmp=(tmp+2);
      cnt++;
    }
    }else{
      dom[i]=2*a[i-1]-dom[i-1];
    }
    cout<<dom[i]<<" ";
  }
  return 0;
}

Measured memory_bytes: 2816
let scan_string () = Scanf.scanf " %s" (fun x -> x)
let print_int n = Printf.printf "%d\n" n

let () =
  let s = scan_string() and t = scan_string() in
  let judge i = if (s.[i] == t.[i]) then 1 else 0 in
  print_int (judge 0 + judge 1 + judge 2)


Measured memory_bytes: 384
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n,k,m;
int main(){
	while(cin>>n>>k>>m,n||k||m){
		vector<int> clock;
		clock.clear();
		for(int i = 1;i <=n;i++){
			clock.push_back(i);
		}
		int pos = m-1;
		clock.erase(clock.begin()+pos);
		int cnt;
		while(!clock.size()!=1){
			pos =(pos+k-1)%clock.size();
			clock.erase(clock.begin()+pos);
		}
		cout <<clock.front()<<endl;
	}

	return 0;
}

Measured memory_bytes: 1324
#include<bits/stdc++.h>
#define int long long
using namespace std;

set<int>s;

bool recur(int n){

    bool f = 0;
    set<int>ko;
    while (n%2==0){

        if (s.find(2)!=s.end()){
         f=1;
         return f;
        }

        ko.insert(2);
        n/=2;
    }

    for (int i=3;i<=sqrt((double)n);i+=2){

        while (n%i==0){
            if (s.find(i)!=s.end()){
                f=1;
                return f;
            }

            ko.insert(i);
            n/=i;
        }

    }

    if (n>1){
        if (s.find(n)!=s.end()){
                f=1;
                return f;
            }

            ko.insert(n);
    }

    for (auto k : ko )s.insert(k);

    return f;

}

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

    int n;
    cin >> n;

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

    bool f = 0;
    for (int i=0;i<n;i++){
        if (recur(arr[i]))
            f=1;
    }

    if (!f)
        cout<<"pairwise coprime\n";
    else{
        int val = arr[0];
        for (int i=1;i<n;i++) val = __gcd(val,arr[i]);

        if (val == 1)
            cout<<"setwise coprime\n";
        else
            cout<<"not coprime\n";
    }

}


Measured memory_bytes: 15124
N, M = (int(x) for x in input().split())
L, R = [None]*M, [None]*M
for i in range(M):
    L[i], R[i] = (int(x) for x in input().split())

tmp = [L[0], R[0]]
for j in range(1, M):
    if tmp[0] < L[j]:
        tmp[0] = L[j]
    if R[j] < tmp[1]:
        tmp[1] = R[j]
    if tmp[0] > tmp[1]:
        print(0)
        exit()

print(tmp[1]-tmp[0]+1)


Measured memory_bytes: 10948
#include <bits/stdc++.h>
 
#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define lf long float
#define pb push_back
 
using namespace std; 
 
int main()
{
    ll n;
    cin>>n;
    map<multiset<char>,ll> m;
    set<multiset<char> > p;
    for(ll i = 0 ; i < n ; i++)
    {
        multiset<char> temp;
        string s;
        cin>>s;
        for(int i = 0 ; i < 10 ; i++)
        {
            temp.insert(s[i]);
        }
        p.insert(temp);
        if(m.find(temp) == m.end())
        m[temp] = 1;
        else
        m[temp]++;
    }
    ll ans = 0;
    std::set<multiset<char> >::iterator it;
    for(it = p.begin() ; it != p.end() ; it++)
    {
        ll temp = m[*it];
        ans += (temp*(temp-1))/2;
    }
    cout<<ans<<endl;
    return 0;
}

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

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<lint> cnt(n, 0);
    std::vector<int> xs(n);
    for (auto& x : xs) {
        std::cin >> x;
        --x;
        ++cnt[x];
    }

    lint ans = 0;
    for (auto c : cnt) ans += c * (c - 1) / 2;

    for (auto x : xs) {
        std::cout << ans - (cnt[x] - 1) << std::endl;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 4992
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class user
{
    int value;
    char dir;
    user()
    {
        value=0;
        dir='u';
    }
}

class Main
{
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        String t=sc.nextLine();
        user value[][]=new user[s.length()+1][t.length()+1];
        for(int i=0;i<=s.length();i++)
          value[i][0]=new user();
        for(int i=0;i<=t.length();i++)
          value[0][i]=new user();
        for(int i=1;i<=s.length();i++)
        {
            for(int j=1;j<=t.length();j++)
            {
                value[i][j]=new user();
                if(s.charAt(i-1)==t.charAt(j-1))
                  {
                      value[i][j].value=value[i-1][j-1].value+1;
                      value[i][j].dir='d';
                  }
                else 
                {
                    if(value[i][j-1].value>value[i-1][j].value)
                       {
                        value[i][j].value=value[i][j-1].value;
                        value[i][j].dir='l';
                       }
                    else
                    {
                        value[i][j].value=value[i-1][j].value;
                        value[i][j].dir='u';
                    }
                }
              //  System.out.print(value[i][j].value+" "+value[i][j].dir+", ");
            }
            //System.out.println("");
        }
        int i=s.length(),j=t.length();
        StringBuilder common=new StringBuilder("");
        while(i>=0&&j>=0&&value[i][j].value!=0)
        {
            if(value[i][j].dir=='l')
            {
                 j--;
            }
            else if(value[i][j].dir=='u')
            {
                i--;
            }
            else
             {
                 common=common.append(s.charAt(i-1));
                 i--;
                 j--;
             }
        }
        System.out.println(common.reverse().toString());
        sc.close();
    }
}

Measured memory_bytes: 360580
# coding: utf-8
# Your code here!
S=list(input())

l=[0,0,0]
for i in range(len(S)):
    if S[i]=="a":
        l[0]+=1
    elif S[i]=="b":
        l[1]+=1
    else:
        l[2]+=1

temp=min(l)
for i in range(3):
    l[i]-=temp
    
#print(l)
if (l[0]*l[1]*l[2]==0) and (l[0]>1 or l[1]>1 or l[2]>1):
    print("NO")
else:
    print("YES")


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int A,B,K;
    scanf("%d",&K);
    scanf("%d %d",&A,&B);

    for(int i = A; i <= B; ++i){
        if(i % K == 0){
            printf("OK");
            return 0;
        }

    }
    printf("NG");



    return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
bool bj(int a,int b)
{
return a>b;
}
int main()
{
	int a[100],n,k,i,s=0;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	  cin>>a[i];
	sort(a+1,a+n+1,bj);
	for(i=1;i<=k;i++)
	  s+=a[i];
	cout<<s<<endl;
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll N;
  cin>>N;
  vector<vector<pair<ll,ll>>> vec(N,vector<pair<ll,ll>>(0));
  for(ll i=0;i<N;i++) {
ll A;
    cin>>A;
    for(ll j=0;j<A;j++) {
ll x,y;
      cin>>x>>y;
      vec[x-1].push_back(make_pair(i+1,y));
    }
  }
  
  
  ll ans=0;
  for(ll tmp=0;tmp<(1<<N);tmp++) {
bitset<15> S(tmp);
    bool a=true;
    
    for(ll i=0;i<N;i++) {
      ll k;
      if(S.test(i)) {
k=1;
      }
      else {
        k=0;
      }
for(auto x:vec[i]) {
  if(S.test(x.first-1)) {
  if(x.second!=k) {
a=false;
  }
}
      
}
    }

    if(a) {
      ll sum=S.count();
ans=max(ans,sum);
    }
  }
  
  
  
  
  cout<<ans<<endl;
}
    
    
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mood;
		}
		x = x * x % mood;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int a, b;

signed main() {
	cin >> a >> b;
	cout << max((int)0, a - b * 2) << endl;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <limits.h>
#include <math.h>

int main(void)
{
	int way[21][21];
	int i, j, k;
	int n, m;
	int sp, ep, p, c;

	scanf("%d %d", &n, &m);
	for (i = 1; i <= n; i++){
		for (j = 1; j <= n; j++){
			way[i][j] = INT_MAX / 4;
		}
		way[i][i] = 0;
	}
	for (i = 0; i < m; i++){
		int f, t, fc, tc;
		scanf("%d,%d,%d,%d", &f, &t, &fc, &tc);
		way[f][t] = fc;
		way[t][f] = tc;
	}

	for (i = 1; i <= n; i++){
		for (j = 1; j <= n; j++){
			for (k = 1; k <= n; k++){
				way[j][k] = fmin(way[j][k], way[j][i] + way[i][k]);
			}
		}
	}
	scanf("%d,%d,%d,%d", &sp, &ep, &p, &c);

	p -= way[sp][ep] + way[ep][sp] + c;
	printf("%d\n", p);

	return (0);
}

Measured memory_bytes: 604
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        m: usize,
        k: usize,
        a: [u64; n],
    }
    let mut dp = a.clone();
    for k in 1..k {
        let mut d = std::collections::VecDeque::new();
        d.push_back((k - 1, dp[k - 1]));
        for (i, (a, dp)) in a[k..].iter().zip(dp[k..].iter_mut()).enumerate() {
            let i = i + k;
            if d.front().unwrap().0 + m + 1 == i {
                d.pop_front();
            }
            let next = d.front().unwrap().1 + ((k + 1) as u64) * *a;
            while let Some((j, v)) = d.pop_back() {
                if v > *dp {
                    d.push_back((j, v));
                    break;
                }
            }
            d.push_back((i, *dp));
            *dp = next;
        }
    }
    let ans = dp[(k - 1)..].iter().max().unwrap();
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 6396
from collections import Counter
N, K = map(int,input().split())
A = list(map(int,input().split()))
dp = [0]*(K+1)

for i in range(K+1):
    d = set(range(N + 1))
    for a in A:
        if i - a < 0:
            continue
        if dp[i - a] in d:
            d.remove(dp[i - a])
    dp[i] = min(list(d))

print('First' if dp[-1] > 0 else 'Second')

Measured memory_bytes: 44444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1e16;
const int maxn=305;

int n,m,L,Q;
ll g[maxn][maxn],dp[maxn][maxn];

int main(){
    scanf("%d%d%d",&n,&m,&L);
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            if(i==j) g[i][j]=0;
            else g[i][j]=inf;
        }
    }
    for(int i=1;i<=m;++i){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        g[u][v]=g[v][u]=w;
    }
    for(int k=1;k<=n;++k){
        for(int i=1;i<=n;++i){
            for(int j=1;j<=n;++j){
                if(g[i][k]<inf && g[k][j]<inf && g[i][j]>g[i][k]+g[k][j]){
                    g[i][j]=g[i][k]+g[k][j];
                }
            }
        }
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            if(j==i) dp[i][j]=0;
            else if(g[i][j]<=L) dp[i][j]=1;
            else dp[i][j]=inf;
        }
    }
    for(int k=1;k<=n;++k){
        for(int i=1;i<=n;++i){
            for(int j=1;j<=n;++j){
                if(dp[i][k]<inf && dp[k][j]<inf && dp[i][j]>dp[i][k]+dp[k][j]){
                    dp[i][j]=dp[i][k]+dp[k][j];
                }
            }
        }
    }
    scanf("%d",&Q);
    while(Q--){
        int s,t;
        scanf("%d%d",&s,&t);
        if(dp[s][t]<inf) printf("%lld\n",dp[s][t]-1);
        else puts("-1");
    }
    return 0;
}

Measured memory_bytes: 1920