akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <string>
#include <unordered_map>
#include <iomanip>
#include <deque>
#include <unordered_set>

using namespace std;
#define int long long

signed main () {
    int n;
    cin >> n;
    vector<pair<int, int>> red(n);
    vector <pair<int, int>> blue(n);
    unordered_set<int> use;
    for(int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        red[i] = make_pair(x, y);
    }
    for(int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        blue[i] = make_pair(x, y);
    }
    sort(red.begin(), red.end());
    sort(blue.begin(), blue.end());
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        int x = blue[i].first;
        int y = blue[i].second;
        int idx = -1;
        int maxx = -1;
        for(int j = 0; j < n; j++) {
            pair<int, int> it;
            it = red[j];
            if(use.find(j) != use.end()) continue;
            if(it.first > x) {
                break;
            }
            if(it.second > y) continue;
            if(it.second > maxx) {
                maxx = it.second;
                idx = j;
            }
        }
        if(idx >= 0) {
            use.insert(idx);
            cnt++;
        }
    }

    cout << cnt;
}

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int n; cin >> n;
  string s; cin >> s;
  int max_ = 0;
  loop(k,1,n-1) {
    set<char> S1, S2, S3;
    loop(i,0,k) S1.insert(s[i]);
    loop(i,k,n) S2.insert(s[i]);
    
    for (auto s1: S1) {
      if (S2.count(s1)) S3.insert(s1);
    }
    max_ = max(max_, (int)S3.size());
  }
  cout << max_ << endl;
  return 0;
}


Measured memory_bytes: 3620
#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>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

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


int n, s;
bool d[10];
int ans = 0;
vector< vector<int> > C;

void dfs(int i, int sum, int num){
	if (i == n&&sum == s){
		ans++;
		return;
	}

	for (int j = num; j < 10; j++){
		if (d[j] == 0){
			d[j] = 1;
			dfs(i + 1, sum + j, j);
			d[j] = 0;
		}
	}
	return;
}





int main(){
	while (cin >> n >> s){
		if (n + s == 0)break;
		dfs(0, 0, 0);
		cout << ans << endl;
		ans = 0;
	}
}

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int N, a[101];

int main(int argc, char const *argv[]) {
	cin >> N >> a[0];
	bool same = true;
	int avg = a[0];
	for (int i = 1; i < N; i++) {
		cin >> a[i];
		avg += a[i];
		if (a[i] != a[0]) same = false;
	}
	if (same) {
		cout << "0" << endl;
		return 0;
	}

	avg /= N;
	int res1 = 0, res2 = 0;
	for (int i = 0; i < N; i++) {
		res1 += pow(a[i]-avg, 2);
		res2 += pow(a[i]-avg-1, 2);
	}

	cout << min(res1, res2) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define PI 3.141592653589793238462643383279;

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

  ll k;
  string s;
	cin >> k >> s;
  if (s.length()>k) {
    cout << s.substr(0, k) << "..." << "\n";
  } else {
    cout << s << "\n";
  }
}


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

// macros
#define M 1000000007
#define addmod(a,b,m) (a%m + b%m)%m
#define submod(a,b,m) (a%m - b%m)%m
#define mulmod(a,b,m) ((a%m)*(b%m))%m
#define F first
#define S second
#define APSUM(a,b,n) n*((a*.5)+(b*.5))
#define GPSUM(a,b,k) (b*k-a)/(k-1)
#define INFGP(a,k) a/(1-r)
#define CEIL(a,b) ceil(double(a)/double(b))
#define FLOOR(a,b) floor(double(a)/double(b))
#define T(t) while(t--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'

using namespace std;

//typedefs
typedef long long int ll ;
typedef vector<ll> vi ;
typedef pair<ll,ll> pi ;
typedef map<ll,ll> mps;

ll power(ll base,ll val)
{
    ll res=1;
    while(val)
    {
        if(val&1)
    {
        res = (res*base)%M;
    }
     base = (base*base)%M;
     val/=2;
    }
    return res;
}
ll digit(ll n)
{
    double phi = (1 + sqrt(5))/2;
    ll value = round(pow(phi,n)/(sqrt(5)));
    ll count=0;
    while(value)
    {
        count++;
        value/=10;
    }
    return count;
}

int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
/*
when files are giving the inputs and outputs
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);

*/
 int n,m;
 cin>>n>>m;
 vector<int>arr(n+1,-1);
 bool game=true;
 for(int i=0;i<m;i++)
 {
     int a,b;
     cin>>a>>b;
     if(arr[a]==-1)
     {
         arr[a] = b;
     }
     else if(arr[a]!=b)
     {
         game=false;
         break;
     }
 }
 for(int i=1;i<=n;i++)
 {
     if(arr[i]==-1&&i!=1)
        arr[i]=0;
    if(arr[i]==-1&&i==1&&n==1)
    {
        arr[i]=0;
    }
     else if(arr[i]==-1&&i==1)
        arr[i]=1;
     else if(arr[i]==0&&i==1&&n!=1)
     {
         game=false;
         break;
     }

 }
 if(game)
 {
     for(int i=1;i<=n;i++)
        cout<<arr[i];
 }
    else
        cout<<-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i > 0; i--)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
template <typename Iter> std::string join(Iter begin, Iter end, std::string const& separator){ std::ostringstream result; if (begin != end){ result << *begin++; }; while (begin != end){ result << separator << *begin++; }; return result.str(); }
using namespace std;
typedef long long ll;
void solve() {
  ll N, K; cin >> N >> K;
  string S; cin >> S;
  ll init = 0;
  REP(i, N) {
    if(i > 0 && S[i] == 'L' && S[i-1] == 'L') {
      init += 1;
    }
    if(i < N - 1 && S[i] == 'R' && S[i+1] == 'R') {
      init += 1;
    }
  }
  cout << min(N - 1, init + K * 2) << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  int a;
  char str[11];

  scanf("%d", &a);
  scanf("%s", str);
  if(a >= 3200){
    printf("%s\n", str);
  }else{
    printf("red\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int flag = 1;
	int ocnt = 0, ecnt = 0;
	for(int i = 0; i < s.length(); ++i)
	{
		if(i%2 == 0 && s[i] == '0')
			++ecnt;
		if(i%2 != 0 && s[i] == '0')
			++ocnt;
	}

	if(ocnt < ecnt)
		flag = 0;
	int ans = 0;
	if(flag)
	{
		for(int i = 0; i < s.length(); ++i)
		{
			if(i%2 == 0 && s[i] != '1')
				++ans;
			if(i%2 != 0 && s[i] != '0')
				++ans;
		}
	}
	else
	{
		for(int i = 0; i < s.length(); ++i)
		{
			if(i%2 == 0 && s[i] != '0')
				++ans;
			if(i%2 != 0 && s[i] != '1')
				++ans;
		}
	}
	cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

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

  int n = s.length();
  string ans ="";

  rep(i,n){
    string tmp = "x";
    ans +=tmp;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long ll;
ll con[200][200];
int main()
{
    ll n;
    cin>>n;
    for(ll i =1;i<=n;++i)
    {
        ll flag = i;
        ll x = flag%10;
        ll y;
        while(flag)
        {
            y = flag%10;
            flag/=10;
        }
        con[x][y]++;
    }
    ll ans = 0;
    for(ll i=1;i<=9;++i)
        for(ll j =1;j<=9;++j)
            ans+=con[i][j]*con[j][i];
    cout<<ans<<endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string S; cin >> S;
  int y = stoi(S.substr(0, 4));
  int m = stoi(S.substr(5, 2));
  int d = stoi(S.substr(8, 2));
  if (y < 2019) {
    cout << "Heisei" << endl;
    return 0;
  }
  if (m <= 4) {
    cout << "Heisei" << endl;
    return 0;
  }
  cout << "TBD" << endl;
}


Measured memory_bytes: 3640
#include <stdio.h>

int main(void) {
	int n ,m ,i, j, tmp;
	int A[100][100] = {0};
	int b[100] = {0};

	scanf(" %d %d", &n, &m);
	for (i = 0; i < n; ++i) {
		for (j = 0; j < m; ++j) {
			scanf("%d",&A[i][j]);
		}
	}

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

	for(i = 0; i < n; ++i) {
		tmp = 0;
		for (j = 0; j < m; ++j) {
			tmp += A[i][j]* b[j];
		}
		printf("%d\n", tmp);
	}
	
	return 0;
}

Measured memory_bytes: 648
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, l = LI()
    a = LI()
    for i in range(n - 1):
        if a[i] + a[i + 1] >= l:
            x = i
    try:
        ans = []
        for j in range(x):
            ans.append(j + 1)
        for j in range(n - 2, x - 1, -1):
            ans.append(j + 1)
        print("Possible")
        print("\n".join(map(str, ans)))
    except:
        print("Impossible")
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 69480
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint INF = 1e18;
#define rep(i, n) for(int i = 0; i < int(n); i++)

signed main(){
	int n; cin >> n;
	vector<long double> a(n);
	rep(i, n) cin >> a[i];
	long double ans = 0.0;
	rep(i, n){
		ans += (1.0 / a[i]);
	}
	ans = 1.0 / ans;
	cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int N = 1e2 + 5;
const int V = 1e5 + 5;

i64 dp [V], dp1[V];

 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  F0R (i, V) {
    dp[i] = dp1[i] = 1e15;
  }
  int n, w;
  cin >> n >> w;
  dp[0] = dp1[0] = 0;
  F0R (i, n) {
    int peso, lucro;
    cin >> peso >> lucro;
    FOR (j, lucro, V) {
      dp1[j] = min (dp1[j], dp[j - lucro] + peso);
    }
    FOR (j, lucro, V) {
      dp[j] = dp1[j];
    }
  }
  int mx = 0;
  F0R (i, V) {
    if (dp[i] <= w) {
      mx = i;
    }
  }
  cout << mx << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL =LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    int n;cin>>n;string s,t;cin>>s>>t;
    string targ;
    
    for(auto i = 0;i<n;i++){
        
        if(s.substr(i,n-i) != t.substr(0,n-i))continue;
        
        cout<<i+n-i+i<<endl;
        return 0;
    }
    cout<<2*n<<endl;
    
    return 0;
}








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

int main(){
  int n;
  long long a[3000];
  cin >> n;
  for(int i = 0;i < n;i++) cin >> a[i];

  long long ans = 0;
  for(int i = 0;i < n;i++) ans += a[i];
  ans -= n;
  cout << ans << endl;




  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << "  " << y << endl
#define dbg3(x, y, z) cout << x << "  " << y << "  " << z << endl
#define mod 1000000007
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	ll n, k; cin >> n >> k;
	ll MOD = 1e9 + 7;
	ll mx = n * (n + 1) / 2 - (n - k)*(n - k + 1) / 2;
	ll mn = k * (k - 1) / 2;
	ll res = 0;
	for (int i = k; i <= n + 1; ++i)
	{
		res += mx - mn + 1;
		mx += n - i;
		mn += i;
		res %= MOD;
	}
	cout << res << endl;
}

Measured memory_bytes: 3672
#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 <list>
#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(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#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<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;



int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	rep(i,7){
		int a,b;
		cin>>a>>b;
		cout<<a-b<<endl;
	}
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll H, W, h, w;
    cin >> H >> W >> h >> w;
    ll sum = H * W;
    sum -= h * W;
    sum -= w * H;
    sum += h * w;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

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

    int N, K; cin >> N >> K;
    vi used(N);
    REP(i, K) {
        int d; cin >> d;
        REP(j, d) {
            int m; cin >> m;
            --m; used[m] = 1;
        }
    }

    cout << N - accumulate(ALL(used), 0) << endl;

    return 0;
}


Measured memory_bytes: 3652
N, M, Q = map(int, input().split())
#N: 正整数列の長さ, M:正整数列の最大値, Q: 4つの整数の組みの数

a_l = [0]*Q
b_l = [0]*Q
c_l = [0]*Q
d_l = [0]*Q
for i in range(Q):
    a_l[i], b_l[i], c_l[i], d_l[i] = map(int, input().split())

def calc_score(now):
    score = 0
    for a, b, c, d in zip(a_l, b_l, c_l, d_l):
        a -= 1
        b -= 1
        if c == (now[b]-now[a]):
            score += d

    return score

def dfs(now, n, num): #nowはこれから生成するもの
    if n == 0:
        score_list.append(calc_score(now))
    else:
        for i in range(num, M+1):
            dfs(now+[i], n-1, i)

score_list = []
dfs([], N, 1)
print(max(score_list))


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

fac = [0] * (N + 1)
fac[0] = 1
for i in range(N):
    fac[i + 1] = fac[i] * (i + 1) % 1000000007


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], 1000000005, 1000000007) * pow(fac[k], 1000000005, 1000000007) % 1000000007


A.sort(reverse = True)
result = 0
for i in range(N - K + 1):
    result += A[i] * mcomb(N - (i + 1), K - 1)
    result %= 1000000007

A.sort()
t = 0
for i in range(N - K + 1):
    t += A[i] * mcomb(N - (i + 1), K - 1)
    t %= 1000000007

result -= t
result += 1000000007
result %= 1000000007
print(result)


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

using namespace std;

void solve() {
  int n;
  cin >> n;
  bool ok = true;
  for (int i = 0; i < n; ++i) {
    int n;
    cin >> n;
    if (n % 2 == 0 && (n % 3 && n % 5)) {
      ok = false;
    }
  }

  cout << (ok ? "APPROVED" : "DENIED") << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
L = []
for _ in range(M):
    b, c = map(int, input().split())
    L.append([b, c])
L.sort(key=lambda x: x[1], reverse=True)
# 変更前のカードの枚数
# 変更後のカードの枚数
# をそれぞれ保存しておく

idx = 0
for i in range(N):
    if (idx > len(L) - 1):
        break
    if (A[i] < L[idx][1]):
        A[i] = L[idx][1]
        L[idx][0] -= 1
        if (L[idx][0] != 0):
            continue
        else:
            idx += 1
    else:
        break
print(sum(A))


Measured memory_bytes: 29420
#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((i)=0;(i)<(int)(n);(i)++)
using ll = long long;
using P = pair<int,int>;

int main() {
  int a,p;
  cin >> a >> p;

  cout << (3*a+p)/2 << endl;
  return 0;
}

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

const int MAX = 200;
vector<int> g[MAX];
vector<int> color(MAX,0);
typedef pair<int, int> P;
const int INF = 1e9;
int d[MAX];
int V;

bool dfs(int v, int c){
    color[v] = c;
    rep(i,g[v].size()){
        if(color[g[v][i]] == c) return false;
        if(color[g[v][i]] == 0 && !dfs(g[v][i],-c)) return false; 
    }
    return true;
}

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P>> que;
  rep(i, V) d[i] = INF;
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    rep(i, g[v].size()){
      int e = g[v][i];
      if(d[e] > d[v] + 1){
        d[e] = d[v] + 1;
        que.push(P(d[e], e));
      }
    }
  }
}

int main(){
  cin >> V;
  rep(i,V){
    string s;
    cin >> s;
    rep(j,V) {
      if(s[j] == '1') g[i].push_back(j);  
    }
  }
  if(dfs(0,1) == false) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  rep(i,V) {
    dijkstra(i);
    rep(j,V) if(d[j] + 1 > ans) ans = d[j] + 1;
  }
  cout << ans << endl;
  return 0;
}

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

signed main(){
  int N;
  cin>>N;
  int ans=N*(N-1)/2;
  cout<<ans<<endl;
}

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

word = set()
last = ""
blnOk=True
for i in range(n):
    s = input()
    word.add(s)
    if last != "" and last != s[0]:
        print('No')
        exit()
    last = s[-1]
print('Yes' if len(word) == n else 'No') 


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

void push(int A);
int pop(void);

int S[1000];
int Top = 0;

int main(void) {

	string str;
	int a, b;
	Top = 0;
	while (cin >> str) {

		if (str == "+") {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (str == "-") {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (str == "*") {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(str.c_str()));
		}
	}
	printf("%d\n", pop());

	return 0;
}

void push(int A) {
	S[++Top] = A;
}

int pop(void) {
	Top--;
	return S[Top + 1];
}


Measured memory_bytes: 3288
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  lint h, w; cin >> h >> w;
  lint g[500][500] = {};
  lint grid[500][500] = {};
  for(int i = 0; i < 500; i++)
    for(int j = 0; j < 500; j++)
      g[i][j] = 10010010;

  for(int i = 0; i < 500; i++)
    g[i][i] = 0;

  for(int i = 1; i <= h; i++) {
    for(int j = 1; j <= w; j++) {
      char c; cin >> c;
      if(c == '.') grid[i][j] = 1;
    }
  }
  
  set<int> dame;
  lint n = h * w;
  for(int i = 1; i <= h; i++) {
    for(int j = 1; j <= w; j++) {
      int cur = (i - 1) * w + j - 1;
      if(grid[i][j] == 0) {
        dame.insert(cur);
        continue;
      }
      for(int dir = 0; dir < 4; dir++) {
        int ni = i + di[dir];
        int nj = j + dj[dir];
        if(grid[ni][nj] == 0) continue;
        int nxt = (ni - 1) * w + nj - 1;
        g[cur][nxt] = 1;
        g[nxt][cur] = 1;
      }
    }
  }
  
  for(int k = 0; k < n; k++) {
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        g[i][j] = min(g[i][k] + g[k][j], g[i][j]);
      }
    }
  }


  lint ans = 0;
  for(int i = 0; i < n; i++) {
    for(int j = i + 1; j < n; j++) {
      if(dame.count(i) or dame.count(j)) continue;
      ans = max(ans, g[i][j]);
    }
  }

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


Measured memory_bytes: 4224
while n = gets.to_i
    break if n == 0

    s = Array.new(86401, 0)
    n.times {
        start, finish = gets.chomp.split(" ").map {|a|
            t = a.split(":").map(&:to_i)
            t[0] * 3600 + t[1] * 60 + t[2]
        }
        s[start]+=1
        s[finish]-=1
    }
    (1..86400).each do |i|
        s[i] += s[i-1]
    end
    puts s.max
end



Measured memory_bytes: 31176
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  string s;
  cin>>s;
  map<char, int> cnt;
  REP (i, SZ(s)) {
    cnt[s[i]]++;
  }
  int res = 1;
  for (auto p1 : cnt) {
    for (auto p2 : cnt) {
      if (p1.st < p2.st) {
        res += p1.nd * p2.nd;
      }
    }
  }
  cout<<res<<endl;
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>

using namespace std;

long long n, u, s, v;
long long a[200200], b[200200];
vector <long long> t[200200];

long long tohop ( long long n, int m ) {
    long long t = 1;
    for ( int i = n - m + 1; i <= n; i++) {
        t = t * i;
    }
    long long u = 1;
    for ( int i = 1; i <= m; i++) {
        u = u * i;
    }
    return t / u;
}

int main () {
    cin >> n;
    for ( int i = 1; i <= n; i++) {
        cin >> a[i];
        t[a[i]].push_back(i); b[i] = a[i];
    }
    sort(a + 1, a + 1 + n);
    for ( int i = 1; i <= n; i++) {
        if ( a[i] != a[i - 1] ) {
            if ( t[a[i]].size() >= 2 ) {
                s = s + tohop(t[a[i]].size(), 2);
            }
        }
    }
    //cout << s << endl;
    for ( int i = 1; i <= n; i++) {
        u = t[b[i]].size();
        //cout <<"i = " << i << " u = " << u << endl;
        if ( u < 2 ) {
            cout << s << endl;
        }
        else if ( u == 2 ) {
            cout << s - 1 << endl;
        }
        else {
            u--;
            v = tohop(t[b[i]].size(), 2);
            cout << s - v + tohop(u, 2) << endl;
        }
    }
}


Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define rep(i, s, e) for (auto i = s; i < e; i++)
#define peek(c)      \
	for (auto i : c) \
		cout << i << ' ';

void solve()
{
	ll n;
	cin >> n;
	vector<ll> in(n);
	rep(i, 0, n)
	{
		cin >> in[i];
	}
	vector<ll> s(n + 1, 0);
	rep(i, 0, n)
	{
		s[i + 1] = s[i] + in[i];
	}
	ll d = INT_MAX;
	rep(i, 1, n)
	{
		d = min(d, abs(s[i] - (s[n] - s[i])));
	}
	cout << d;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<stdio.h>

using namespace std;

int main(void)

{
    int A, B, res;
    cin>>A>>B;
    B *= 2;
    if(A-B <= 0)
        cout<<0<<"\n";
    else
        cout<<(A-B)<<"\n";
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(m);
  for (int i = 0; i < m; i++) {
    v.at(i) = 0;
  }
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      v.at(a - 1)++;
    }
  }
  int ans = 0;

  for (int i = 0; i < m; i++) {
    if (v.at(i) == n) {
      ans++;
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

template<typename T, typename S>
struct LazySegmentTree{
private:
    int n;
    vector<T> node;
    vector<S> lazy;
    T E0;
    S E1;

    inline void updatef(S& lazy,S& value){
        //lazy += value;
        lazy.first = lazy.first * value.first ;
        lazy.second = (lazy.second * value.first + value.second );
        //lazy = max(lazy, value);
        //lazy = min(lazy, value);
    }
    inline void calculatef(T& node,S& lazy,int len){
        //node += lazy * len; //区間sumはこっち
        // node += lazy ; //区間maxとか
        node = lazy.first * node + lazy.second ;
    }
    inline T queryf(T& x,T& y){
        //return x + y;
        //return x * y;
        //return max(x, y);
        return x+y;
    }
public:
    LazySegmentTree(int sz,T nodeE,S lazyE ):E0(nodeE), E1(lazyE){
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E0);
        lazy.resize(2*n-1,E1);
    }

    LazySegmentTree(vector<T>& v,T E0,S E1 ):E0(E0),E1(E1){
        n=1;
        int sz=v.size();
        while(n<sz)n<<=1;
        node.resize(2*n-1,E0);
        lazy.resize(2*n-1,E1);
        rep(i,sz)node[i+n-1] = v[i];
        for(int i=n-2; i>=0; --i){
            node[i] = queryf(node[2*i+1],node[2*i+2]);
        }
    }

    void eval(int k,int l,int r){
        if(lazy[k]==E1)return ;
        calculatef(node[k], lazy[k], r-l);
        if(r-l>1){
            updatef(lazy[2*k+1], lazy[k]);
            updatef(lazy[2*k+2], lazy[k]);
        }
        lazy[k]=E1;
    }

    void update(int a, int b, S x,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        eval(k,l,r);
        if(r<=a||b<=l)return;
        if(a<=l&&r<=b){
            updatef(lazy[k], x);
            eval(k,l,r);
        }
        else {
            update(a,b,x,2*k+1,l,(l+r)/2);
            update(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=queryf(node[2*k+1], node[2*k+2]);
        }
    }

    T query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        eval(k,l,r);
        if(r<=a||b<=l)return E0;
        if(a<=l&&r<=b)return node[k];
        T xl=query(a,b,2*k+1,l,(l+r)/2);
        T xr=query(a,b,2*k+2,(l+r)/2,r);
        return queryf(xl, xr);
    }
};

using ull = unsigned long long;
int main(){
    int n,k,t;
    cin>>n>>k>>t;
    LazySegmentTree<ull,pair<ull,ull>> sg(n,0,{1,0});
    const ull p = mod;
    while(t--){
        int l, r, x;
        cin>>l>>r>>x;
        sg.update(l-1,r,{mod,x});
    }
    ull ok = 0;
    rep(i,k){
        ok = ok * p + (i+1);
    }
    int ans=0;
    rep(i,n){
        if(sg.query(i,i+1)==ok)++ans;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 15240
S = input()
upper = S[:2]
lower = S[2:]
months = ["0"+str(i) if i < 10 else str(i) for i in range(1, 13)]
is_yymm = lower in months
is_mmyy = upper in months

if is_yymm and is_mmyy:
    print("AMBIGUOUS")
elif is_yymm:
    print("YYMM")
elif is_mmyy:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FASTIO std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef long long ll;
const int N = 2e5 + 5, mod = 998244353;

int main () {
  map<int, int>mp;
  int x, y, n , in = 0, p;
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    cin >> p;
    mp[p]++;

  }
  int l = x, r = x;
  while(1) {
    if (mp[l] == 0) {
      cout << l << endl;
      return 0;
    }
    if (mp[r] == 0) {
      cout << r << endl;
      return 0;
    }
    in++;
    l--;
    r++;
  }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
#define N 200005
using namespace std;
int l[N],r[N];
int main() {
	int n,m;
	cin>>n>>m;
	rep(i,1,m) cin>>l[i]>>r[i];
	sort(l+1,l+1+m);
	sort(r+1,r+1+m);
	if(r[1]-l[m]+1<0) cout<<0;
	else cout<<r[1]-l[m]+1;
	re 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n,p;
  cin>>n>>p;

  if(n==1) {
    cout << p << endl;
    return 0;
  }

  ll ans;
  repo(i,1000001){
    ll x=pow(i,n);
    if(x>p) break;
    if(p%x==0) ans=i;
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int N = 100010, M = 200010;

int n, m;
int d[N];
vector<pair<int, int>> g[N];
char s[N];
int ans[M];

void gg() {
  cout << "-1\n";
  exit(0);
}

void dfs(int u) {
  for (const auto& pr : g[u]) {
    int v, id;
    tie(v, id) = pr;
    if (s[v] || d[v] < d[u]) continue;
    s[v] = (s[u] == 'B') ? 'W' : 'B';
    ans[id] = d[v];
    dfs(v);
  }
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    cin >> d[i];
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].emplace_back(v, i);
    g[v].emplace_back(u, i);
  }
  fill(ans + 1, ans + m + 1, (int)1e9);
  for (int i = 1; i <= n; ++i)
    if (!s[i]) {
      bool f = true, f2 = false;
      for (const auto& pr : g[i]) {
        int v, id;
        tie(v, id) = pr;
        if (d[v] < d[i]) {
          f = true;
          continue;
        }
        if (d[v] == d[i])
          f2 = true;
      }
      if (f && f2) {
        s[i] = 'B';
        dfs(i);
      }
    }
  for (int i = 1; i <= n; ++i)
    if (!s[i])
      gg();
  cout << (s + 1) << '\n';
  for (int i = 1; i <= m; ++i)
    cout << ans[i] << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 12160
// ※※※ 解答不能 ※※※
// ha15氏.
// https://atcoder.jp/contests/code-festival-2016-qualb/submissions/7459000
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

struct Trie{
    array<Trie*, 26> next;
    array<int, 26> count;
    int end;
};

char c[404040];

int main(){
    int N;
    scanf("%d", &N);
    vector<string> S(N);
    for(auto &s : S){
        scanf("%s", c);
        s = c;
    }
    Trie *trie = new Trie();
    rep(i, N){
        const string &s = S[i];
        Trie *t = trie;
        rep(j, s.size()){
            t->count[s[j] - 'a']++;
            if (!t->next[s[j] - 'a']) t->next[s[j] - 'a'] = new Trie();
            t = t->next[s[j] - 'a'];
        }
        t->end++;
    }
    vector<array<array<int, 26>, 26>> counts(N);
    vector<int> ends(N);
    rep(i, N){
        const string &s = S[i];
        Trie *t = trie;
        rep(j, s.size()){
            ends[i] += t->end;
            rep(k, 26) counts[i][s[j] - 'a'][k] += t->count[k];
            t = t->next[s[j] - 'a'];
        }
    }
    int Q;
    scanf("%d", &Q);
    while(Q--){
        int i;
        scanf("%d", &i);
        i--;
        char p[27];
        scanf("%s", &p);
        int cnt = ends[i];
        rep(j, 26){
            rep(k, 26){
                if(p[k] == j + 'a') break;
                cnt += counts[i][j][p[k] - 'a'];
            }
        }
        printf("%d\n", cnt + 1);
    }
    return 0;
}

Measured memory_bytes: 309504
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

long long gcd(int a, int b){
  if (a%b == 0){
    return(b);
  }
  else{
    return(gcd(b, a%b));
  }
}

int main(){    
  long long N;
  cin >> N;
  long long sum = 0;
  int A[N],B[N+1]={};
  A[0] = 0;
  B[0] = 1;
  
  for(int i=1;i<N;i++){
    cin >> A[i];
    if(A[i]==A[i-1]){
      B[A[i]]++;
    }
    else{
      B[A[i]]++;
    }
  }
  
  for(int i=1;i<=N;i++){
    cout << B[i] << endl;
  }    
}
 


Measured memory_bytes: 5196
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <iomanip>
using namespace std;

int main(int argc, char const *argv[]) {
  int a,b,c,dd;cin>>a>>b>>c>>dd;
  int x=c-a,y=dd-b;
  char u,d,r,l;
  if(y>0&&x>0){
    u='U';
    d='D';
    r='R';
    l='L';
    for(int i=0;i<y;++i)cout<<u;
    for(int i=0;i<x;++i)cout<<r;
    for(int i=0;i<y;++i)cout<<d;
    for(int i=0;i<x;++i)cout<<l;
    cout<<l;
    for(int i=0;i<=y;++i)cout<<u;
    for(int i=0;i<=x;++i)cout<<r;
    cout<<d;
    cout<<r;
    for(int i=0;i<=y;++i)cout<<d;
    for(int i=0;i<=x;++i)cout<<l;
    cout<<u;
    cout<<endl;
  }
  if(y<0&&x>0){
    y*=-1;
    u='D';
    d='U';
    r='R';
    l='L';
    for(int i=0;i<y;++i)cout<<u;
    for(int i=0;i<x;++i)cout<<r;
    for(int i=0;i<y;++i)cout<<d;
    for(int i=0;i<x;++i)cout<<l;
    cout<<l;
    for(int i=0;i<=y;++i)cout<<u;
    for(int i=0;i<=x;++i)cout<<r;
    cout<<d;
    cout<<r;
    for(int i=0;i<=y;++i)cout<<d;
    for(int i=0;i<=x;++i)cout<<l;
    cout<<u;
  }
  if(y>0&&x<0){
    x*=-1;
    u='U';
    d='D';
    r='L';
    l='R';
    for(int i=0;i<y;++i)cout<<u;
    for(int i=0;i<x;++i)cout<<r;
    for(int i=0;i<y;++i)cout<<d;
    for(int i=0;i<x;++i)cout<<l;
    cout<<l;
    for(int i=0;i<=y;++i)cout<<u;
    for(int i=0;i<=x;++i)cout<<r;
    cout<<d;
    cout<<r;
    for(int i=0;i<=y;++i)cout<<d;
    for(int i=0;i<=x;++i)cout<<l;
    cout<<u;
  }
  if(y<0&&x<0){
    x*=-1;
    y*=-1;
    u='D';
    d='U';
    r='L';
    l='R';
    for(int i=0;i<y;++i)cout<<u;
    for(int i=0;i<x;++i)cout<<r;
    for(int i=0;i<y;++i)cout<<d;
    for(int i=0;i<x;++i)cout<<l;
    cout<<l;
    for(int i=0;i<=y;++i)cout<<u;
    for(int i=0;i<=x;++i)cout<<r;
    cout<<d;
    cout<<r;
    for(int i=0;i<=y;++i)cout<<d;
    for(int i=0;i<=x;++i)cout<<l;
    cout<<u;
  }
  if(x==0||y==0){
    u='U';
    d='D';
    l='L';
    r='R';
    for(int i=0;i<y;++i)cout<<u;
    cout<<r;
    for(int i=0;i<y;++i)cout<<d;
    cout<<l;
    cout<<l;
    for(int i=0;i<y;++i)cout<<u;
    cout<<r;
    cout<<u;
    cout<<l;
    cout<<l;
    for(int i=0;i<y+2;++i)cout<<d;
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int N;
  scanf("%d",&N);
  if(N%10==2)
    printf("hon");
  if(N%10==4)
    printf("hon");
  if(N%10==5)
    printf("hon");
  if(N%10==7)
    printf("hon");
  if(N%10==9)
    printf("hon");
  if(N%10==0)
    printf("pon");
  if(N%10==1)
    printf("pon");
  if(N%10==6)
    printf("pon");
  if(N%10==8)
    printf("pon");
  if(N%10==3)
    printf("bon");
  return 0;
}

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

bool win[100100];
int N,K,A[101];

int main()
{
	scanf ("%d %d",&N,&K);
	for (int i=0;i<N;i++) scanf ("%d",&A[i]);
	for (int i=1;i<=K;i++){
		for (int j=0;j<N;j++) if (i >= A[j]){
			if (!win[i-A[j]]){
				win[i] = true;
				break;
			}
		}
	}
	puts(win[K]?"First":"Second");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

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

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

    int sum = accumulate(a.begin(), a.end(), 0);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (4 * m * a[i] >= sum) {
            cnt++;
        }
    }

    if (cnt >= m) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define S 10000
#define T 500

main(){

  int n[S],q[T],count=0,a,b,i,j;

  scanf("%d",&a);
  for( i = 0 ; i < a ; i++ )
    scanf("%d",&n[i]);

  scanf("%d",&b);
  for( i = 0 ; i < b ;i++ )
    scanf("%d",&q[i]);

  for( i = 0 ; i < b ; i++){
    for( j = 0 ; j < a ; j++ ){
      if( n[j] == q[i] ){
	count++;
	  break;
      }
    }
  }

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

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

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

from collections import Counter

CA=Counter(A)
CB=Counter(B)

H=[]

for ca in CA:
    if CA[ca]>0 and CB[ca]>0:
        if CA[ca]+CB[ca]>N:
            print("No")
            sys.exit()
        H.append((-(CA[ca]+CB[ca]),ca))

import heapq
heapq.heapify(H)

ANSDICT=dict()

while len(H)>=2:
    c1,x1=heapq.heappop(H)
    c1=-c1

    c2,x2=heapq.heappop(H)
    c2=-c2

    if x1 in ANSDICT:
        ANSDICT[x1].append(x2)
    else:
        ANSDICT[x1]=[x2]

    if x2 in ANSDICT:
        ANSDICT[x2].append(x1)
    else:
        ANSDICT[x2]=[x1]

    CA[x1]-=1
    CA[x2]-=1
    CB[x1]-=1
    CB[x2]-=1

    if CA[x1]>0 and CB[x1]>0:
        heapq.heappush(H,(-(c1-2),x1))

    if CA[x2]>0 and CB[x2]>0:
        heapq.heappush(H,(-(c2-2),x2))

ANS=[-1]*N

for i in range(N):
    a=A[i]
    if a in ANSDICT and len(ANSDICT[a])!=0:
        
        x=ANSDICT[a].pop()
        ANS[i]=x

if H:
    cc,xx=H[0]
    cc=-cc

    for i in range(N):
        if ANS[i]==-1 and A[i]!=xx:
            ANS[i]=xx
            CB[xx]-=1

            if CB[xx]==0:
                break

ind=0
for cb in CB:
    while CB[cb]!=0:
        while ANS[ind]!=-1:
            ind+=1
        ANS[ind]=cb
        CB[cb]-=1

print("Yes")
print(*ANS)

Measured memory_bytes: 177716