akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

int main(int argc, char** argv)
{
	int turn = 0;
	std::cin >> turn;

	int point[2] = { 0 };
	for (int i = 0; i < turn; ++i)
	{
		std::string card[2];
		std::cin >> card[0] >> card[1];
		if (card[0] > card[1])
		{
			point[0] += 3;
		}
		else if (card[0] < card[1])
		{
			point[1] += 3;
		}
		else
		{
			point[0] += 1;
			point[1] += 1;
		}
	}

	std::cout << point[0] << " " << point[1] << std::endl;

	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    int n, m ;
    cin >> n >> m ;
    vector<vector<ll>> gra(n,vector<ll>(n,0)) ;
    REP(i,m){
        ll a, b ;
        cin >> a >> b ;
        a-- ;
        b-- ;
        gra[a][b] = 1 ;
        gra[b][a] = 1 ;
    }
    vector<ll> num(n) ;
    REP(i,n){
        num[i] = i ;
    }
    ll ans = 0 ;

    do{
        if(num[0]!=0){
            break ;
        }
        REP(i,n-1){
            if(gra[num[i]][num[i+1]]==0){
                break ;
            }
            if(i==n-2){
                ans++ ;
            }
        }

    }while(NP(ALL(num)));

    cout << ans <<endl;
    


    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main()
{
 ios::sync_with_stdio(false);
 char s[100001];
 bool b=0;
 cin>>s;
 for (int i=0;i<=strlen(s);i++)
 {
 	if (s[i]=='C')
 		b=1;
	if (s[i]=='F')
		if (b)
		{
			cout<<"Yes"<<endl;	
 			return 0;
		}
 }
 cout<<"No"<<endl;
 return 0;
}



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

using namespace std;






int main() {
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    long double pi=M_PI;
    long double dist=sqrt(a*a+b*b-2*a*b*cos((h+(m/60.0))*11*pi/6));
    cout<<setprecision(15)<<dist;




















    return 0;
}


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

int main(void) {
    double a,b,corner;
    cin>>a>>b>>corner;
    double s=0.0,l=0.0,h=0.0;
    s=(a*b*sin(corner*M_PI/180.00000000))/2;
    l=a+b+(sqrt(a*a+b*b-2*a*b*cos(corner*M_PI/180.00000000)));
    h=2*s/a;
    printf("%.8f\n",s);
    printf("%.8f\n",l);
    printf("%.8f\n",h);
    return 0;
}

Measured memory_bytes: 3484
// 解説動画そのまんま、、
// いつか復習したい
#include <bits/stdc++.h>
using namespace std;

struct L {
    int a, b, c;
    L(int _a = 0, int _b = 0, int _c = 0) : a(_a), b(_b), c(_c) {}
};

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

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> mpX, mpY;
    mpX[0] = 0;
    mpY[0] = 0;

    vector<L> lh, lv;
    for (int i = 0; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        mpX[a] = 0;
        mpX[b] = 0;
        mpY[c] = 0;
        lh.emplace_back(a, b, c);
    }
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> c >> a >> b;
        mpY[a] = 0;
        mpY[b] = 0;
        mpX[c] = 0;
        lv.emplace_back(a, b, c);
    }

    vector<int> xs, ys;
    for (auto &p : mpX) {
        p.second = xs.size();
        xs.push_back(p.first);
    }
    for (auto &p : mpY) {
        p.second = ys.size();
        ys.push_back(p.first);
    }

    int h = xs.size() * 2;
    int w = ys.size() * 2;

    vector<vector<int>> d(h, vector<int>(w));

    for (int i = 0; i < n; ++i) {
        int a = mpX[lh[i].a] * 2;
        int b = mpX[lh[i].b] * 2;
        int c = mpY[lh[i].c] * 2;
        for (int x = a; x <= b; ++x) d[x][c] = -1;
    }

    for (int i = 0; i < m; ++i) {
        int a = mpY[lv[i].a] * 2;
        int b = mpY[lv[i].b] * 2;
        int c = mpX[lv[i].c] * 2;
        for (int y = a; y <= b; ++y) d[c][y] = -1;
    }

    queue<pair<int, int>> q;
    int sx = mpX[0] * 2, sy = mpY[0] * 2;
    d[sx][sy] = 1;
    q.emplace(sx, sy);
    while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int v = 0; v < 4; ++v) {
            int nx = x + dx[v], ny = y + dy[v];
            if (nx < 0 || nx >= h) continue;
            if (ny < 0 || ny >= w) continue;
            if (d[nx][ny] != 0) continue;
            d[nx][ny] = 1;
            q.emplace(nx, ny);
        }
    }

    long long ans = 0;
    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            if (d[x][y] != 1) continue;
            if (x == 0 || x == h - 1 || y == 0 || y == w - 1) {
                cout << "INF" << endl;
                return 0;
            }
            if (x % 2 == 0 || y % 2 == 0) continue;
            // x/2 + 1が配列の参照外に当たりそうだけど、x == h-1の条件は上で処理してあるから大丈夫
            long long ex = xs[x / 2 + 1] - xs[x / 2];
            long long ey = ys[y / 2 + 1] - ys[y / 2];
            ans += ex * ey;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 144504
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  char c;cin>>c;
  cout << char(c+1) << endl;
  return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  string s;
  cin >> s;
  cout << s.substr(0, s.size() - u8"FESTIVAL"s.size()) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long u64;

u64 binpow(u64 n, u64 x, u64 mod)
{
  u64 tgt = 1;
  u64 dig = n;
  while (x > 0) {
    if (x%2) {
      tgt = (tgt * dig) % mod;
    }
    dig = (dig * dig) % mod;
    x /= 2;
  }
  return tgt;
}

class Comb
{
public:
  u64 mod;
  vector< u64 > fact;
  vector< u64 > factf;
  void init(u64 size, u64 imod) {
    mod = imod;
    fact.resize(size+1);
    factf.resize(size+1);
    fact[0] = 1;
    factf[0] = 1;
    for (u64 i = 1; i <= size; ++i) {
      fact[i] = fact[i-1]*i%mod;
      factf[i] = binpow(fact[i], mod-2, mod);
    }
  }
  u64 comb(u64 n, u64 k) {
    if (n<k) return 0;
    if (k==0 || n==k) return 1;
    return ((fact[n] * factf[k]) % mod * factf[n-k]) % mod;
  }
};

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  Comb comb;
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  comb.init(h+w, 1e9+7);
  u64 sum = comb.comb(h+w-2, h-1);
  u64 sum_d = 0;
  for (int i = 0; i < b; ++i) {
    sum_d += comb.comb(i+h-a-1, i) * comb.comb(a-1+w-i-1, a-1);
    sum_d = sum_d % 1000000007;
  }
  cout << (sum+1000000007-sum_d)%1000000007 << endl;
  return 0;
}


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

namespace ABC123_B_Five_Dishes
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] time = new int[5];
			for(int i = 0; i < 5; i++)
			{
				time[i] = int.Parse(Console.ReadLine());
			}

			int min = 643;

			for(int i = 0; i < 5; i++)
			{
				int temp = 0;
				for (int j = 0; j < 5; j++)
				{
					if(i == j)
					{
						continue;
					}

					int remainder = time[j] % 10;
					if(remainder == 0)
					{
						temp += time[j];
					}
					else
					{
						temp += time[j] + (10 - remainder);
					}
				}

				temp += time[i];
				if(temp < min)
				{
					min = temp;
				}
			}

			Console.WriteLine(min);
		}
	}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
long long n,ans;
int main()
{
	scanf("%lld",&n);
	if(n%2==0){
		for(long long i=10;i<=n;i*=5)
			ans+=(n/i);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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 const INF = 1001001001;


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

int N;
string S;
cin >> N >> S;

// atcoder
// u = "a" v = "tcoder"
// u = "atcode" v = "r"
int ans = 0;
for(int i = 1; i <= N-1; ++i) {
    string u = S.substr(0,i);
    string v = S.substr(i);
    map<char, int> mpu,mpv;
    rep(j,u.size()) mpu[u[j]]++;
    rep(j,v.size()) mpv[v[j]]++;
    int cnt = 0;
    for(auto x : mpu) {
        if(x.second > 0 && mpv[x.first] > 0) cnt++;
    }
    ans = max(ans,cnt);
}
cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int INF = 1000;
int main(){
  while (1){
    int T;
    cin >> T;
    if (T == 0){
      break;
    }
    vector<int> t(T);
    for (int i = 0; i < T; i++){
      cin >> t[i];
    }
    int N;
    cin >> N;
    vector<int> t2(101, 24);
    for (int i = 0; i < N; i++){
      int D, M;
      cin >> D >> M;
      t2[D - 1] = min(t2[D - 1], M);
    }
    vector<int> dp(101, INF);
    dp[0] = 0;
    for (int i = 1; i < 101; i++){
      if (t2[i] >= t[i % T]){
        dp[i] = 0;
      } else {
        dp[i] = 0;
        break;
      }
    }
    for (int i = 1; i < 101; i++){
      for (int j = 0; j < i; j++){
        bool ok = true;
        for (int k = j; k < i; k++){
          if (t2[k] < t[(k - j) % T]){
            ok = false;
          }
        }
        if (ok){
          dp[i] = min(dp[i], dp[j] + 1);
        }
      }
    }
    cout << dp[100] << endl;
  }
}


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

int32_t main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n; cin>>n;
    cout<<n+n*n+n*n*n;
	
}



Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
    double x[3], y[3];
    for (int i = 0; i < 3; i++) {
        scanf("%lf %lf", &x[i], &y[i]);
    }
    double S[3], ang[3];
    for (int i = 0; i < 3; i++) {
        S[i] = hypot(x[(i + 1) % 3] - x[(i + 2) % 3], y[(i + 1) % 3] - y[(i + 2) % 3]);
        double vx = (x[(i + 1) % 3] - x[i]), vy = (y[(i + 1) % 3] - y[i]);
        double ux = (x[(i + 2) % 3] - x[i]), uy = (y[(i + 2) % 3] - y[i]);
        ang[i] = fabs(atan2(vx * uy - ux * vy, vx * ux + vy * uy));
    }
    double ans = 0;
    for (int i = 0; i < 3; i++) {
        ans = max(ans, S[i] / (2 + 1.0 / tan(ang[(i + 1) % 3] / 2) + 1.0 / tan(ang[(i + 2) % 3] / 2)));
    }
    printf("%.10lf\n", ans);
}


Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int x, p[5][5];
int main() {
	scanf("%d", &x);
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < 5; j++) {
			for (int k = 0; k < 5; k++) {
				scanf("%d", &p[j][k]);
			}
		}
		int ret = 0;
		for (int j = 0; j < 5; j++) {
			for (int k = 0; k < 5; k++) {
				for (int l = j + 1; l <= 5; l++) {
					for (int m = k + 1; m <= 5; m++) {
						bool flag = true;
						for (int n = j; n < l; n++) {
							for (int o = k; o < m; o++) {
								flag = flag && p[n][o];
							}
						}
						if (flag) {
							ret = max(ret, (l - j) * (m - k));
						}
					}
				}
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 2588
// @author :: Amirul Islam 

#include <bits/stdc++.h>
using namespace std;
#define LLI long long int

const int mx = 1e5;
const double pi = acos(-1.0);

int main() {
    // freopen("in", "r", stdin);
    
    string a, b;
    cin >> a >> b;
    bool ok;
    for (int i = 0; i < a.size(); i++) {
        ok = 1;
        for (int j = 0; j < b.size(); j++) {
            if (a[(i+j) % a.size()] != b[j]) {
                ok = 0;
                break;
            }
        }
        if (ok) break;
    }
    cout << (ok ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define repz(i, z, n) for(decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for(decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(all(v)))
#define MIN(v) (*min_element(all(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

using namespace std;
void debug_out(){ cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

typedef long long ll;
typedef unsigned long long ul;
// 1s間で可能なループ回数2E+8回
// intの最大値2147483647~2E+9
// long longの最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<> push_back
// 連想配列map<key,value> insert,
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// 大文字65-90(-32)
// 小文字97-122(+32)
// 1E+9 +7
const ll mod = 1000000000+7;
int main(){
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s;
  cin >> s;
  if(s[2]==s[3] and s[4]==s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC138
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');

            double sum = 0.0000f;

            for (int i = 0; i < N; i++)
            {
                sum += (1f / int.Parse(input[i]));
            }

            double res = (1 / sum);
            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(int(a.find('C'))!=-1&&int(a.rfind('F'))!=-1&&a.find('C')<a.rfind('F'))
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,X = readInts() # その時点の距離からの絶対値
a = list(map(lambda x:abs(X - int(x)), input().split()))
res = 0
from fractions import gcd
for i in range(n):
    res = gcd(res,a[i])
print(res)


Measured memory_bytes: 14620
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <random>
#include <functional>
#include <bit>
#include <cstdint>

#include <fstream>
#include <vector>
#include <algorithm>

#define ll long long int
#define MOD 1000000007

using namespace std;

bool isPrime(ll n)
{
    if(n == 1)
    {
        return false;
    }
    for(ll i = 2; i*i <= n; i++)
    {
        if(n % i == 0)
        {
            return false;
        }
    }
    
    return true;
}

int main(void)
{
    
    ll x;
    
    cin >> x;
    
    if(400 <= x && x <= 599)
    {
        cout << 8;
    }
    else if(600 <= x && x <= 799)
    {
        cout << 7;
    }
    else if(800 <= x && x <= 999)
    {
        cout << 6;
    }
    else if(1000 <= x && x <= 1199)
    {
        cout << 5;
    }
    else if(1200 <= x && x <= 1399)
    {
        cout << 4;
    }
    else if(1400 <= x && x <= 1599)
    {
        cout << 3;
    }
    else if(1600 <= x && x <= 1799)
    {
        cout << 2;
    }
    else if(1800 <= x && x <= 1999)
    {
        cout << 1;
    }
    
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
inline int newline() { putchar('\n'); return 0; }

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

    vector<bool> ac(n, false);
    vector<ll> wa(n, 0);
    rep2(i, m) {
        ll p;
        string s;
        cin(p);
        cin(s);

        if (ac[p - 1]) continue;

        if (s == "AC") {
            ac[p - 1] = true;
        } else {
            wa[p - 1]++;
        }
    }

    ll answer = 0;
    ll penalty = 0;
    rep2(i, n) {
        if (ac[i]) {
            answer++;
            penalty += wa[i];
        }
    }

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

Measured memory_bytes: 1024
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<cmath>
#include<utility>
using namespace std;

int main(void)
{
	int N;
	cin >> N;

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

	auto maxa = max_element(a.begin(), a.end());
	auto mina = min_element(a.begin(), a.end());

	auto add = (abs(*maxa) > abs(*mina)) ? maxa : mina;
	
	typedef pair<int, int> State;
	vector<State> ret;
	for(int i=0; i<N; i++){
		if(a[i] == *add)
			continue;

		a[i] += *add;
		ret.push_back(make_pair(add-a.begin()+1, i+1));
	}
	
	if(*add > 0)
		for(int i=1; i<N; i++){
			a[i] += a[i-1];
			ret.push_back(make_pair(i, i+1));
		}
	else
		for(int i=N; i>1; i--){
			a[i-2] += a[i-1];
			ret.push_back(make_pair(i, i-1));
		}

	//copy(a.begin(), a.end(), ostream_iterator<int>(cout, " "));
	cout << endl;
	cout << ret.size() << endl;
	for(int i=0; i<ret.size(); i++)
		cout << ret[i].first << " " << ret[i].second << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int list (int n,int k,int a);
int main()
{
	int N;
	int K;
	int a=1;
	int b;
	scanf("%d",&N);
	scanf("%d",&K);
	a=a*K;
	K--;
	N--;
	if(N==0)
	{
		printf("%d",a);
		return 0;
	}
	printf("%d",list(N,K,a));
}
int list(int n,int k,int a)
{
	if(n!=0)
	{
		n--;
		a=a*k;
		return list(n,k,a);
	}else
	{
		return a;
	}
}

Measured memory_bytes: 128
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        Console.WriteLine(getAns(n,k));
    }
    static int getAns (int n, int k)
    {
        var bsum = 1;
        var count = 1;
        while (true)
        {
            var need = (bsum + k - 1) / k;
            count++;
            bsum += need;
            if (bsum == n) return count;
            else if (bsum > n) return count - 1;
        }
    }
}


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

int n,t,w,cnt;
int fa[200010],d[200010];
pair<int,int> q[4000010];
map<int,int> h[200010];

int find(int x)
{return fa[x]==x?x:fa[x]=find(fa[x]);
}

int main()
{int i,j,x,y,k;
 map<int,int>::iterator p;
 
 scanf("%d",&n);
 for(i=1;i<n;i++)
 {	scanf("%d%d",&x,&y);
 	h[x][y]=1;
 	h[y][x]=1;
 	d[x]++;
 	d[y]++;
 }
 t=1;
 w=0;
 for(i=1;i<n;i++)
 {	scanf("%d%d",&x,&y);
 	h[x][y]++;
 	h[y][x]++;
 	d[x]++;
 	d[y]++;
 	if(h[x][y]==2) q[++w]=make_pair(x,y);
 }
 for(i=1;i<=n;i++) fa[i]=i;
 while(t<=w)
 {	x=find(q[t].first);
 	y=find(q[t].second);
 	if(x!=y)
 	{	if(d[x]<d[y]) swap(x,y);
 		h[x][y]-=2;
 		h[y][x]-=2;
 		for(p=h[y].begin();p!=h[y].end();p++)
 		{	if((*p).second==0) continue;
	 		k=(h[x][(*p).first]+=(*p).second);
 			h[(*p).first][x]+=(*p).second;
 			h[(*p).first][y]-=(*p).second;
 			if(k==2)
 				q[++w]=make_pair(x,(*p).first);
 		}
 		h[y].clear();
		d[x]+=d[y]-2;
		fa[y]=x;
		cnt++;
	}
 	t++;
 }
 printf("%s\n",cnt==n-1?"YES":"NO");
 return 0;
}

Measured memory_bytes: 31872
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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(){
    int n; cin >> n;
    vector<ll> A(n), C(100010); 
    ll sum = 0;
    rep(i, n){
        cin >> A[i];
        C[A[i]]++;
        sum += A[i];
    }
    int q; cin >> q;
    vector<ll> res;
    rep(i, q){
        ll b, c; cin >> b >> c;
        sum += (c - b) * C[b];
        res.push_back(sum);
        C[c] += C[b];
        C[b] = 0;
    }
    for(auto num: res) cout << num << ln;
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for(int i = (int)(n); i > 0; --i)
#define all(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rall(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)
#define sz(a) (int)(a).size()
#define mins(a,...) a = min({a, ## __VA_ARGS__})
#define maxs(a,...) a = max({a, ## __VA_ARGS__})
#define plusMod(a,b) a = (a % mod + b % mod) % mod
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) {
    return os.put(os.widen('\n'));
}
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}

int w, h;
ll p[100005], q[100005];
void solve() {
    cin >> w >> h;

    ll ans = 0;
    rep(i, w) {
        cin >> p[i];
        ans += p[i];
    }
    rep(i, h) {
        cin >> q[i];
        ans += q[i];
    }

    sort(p, p + w);
    sort(q, q + h);

    rep(i, w) {
        auto dis = distance(lower_bound(q, q + h, p[i]), q + h);

        ans += p[i] * dis;
    }

    rep(i, h) {
        auto ptr = distance(upper_bound(p, p + w, q[i]), p + w);

        ans += q[i] * ptr;
    }

    cout << ans << endn;

}


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

    solve();

    cout << flush;

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> E(100002);
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    E.at(a)++;
    E.at(a+1)++;
    E.at(a+2)++;
  }
  int ans=0;
  for(int i=0; i<100002; i++){
    ans=max(ans, E.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
/*input
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
*/
#include <bits/stdc++.h>
using namespace std;

typedef double db;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;

#define FOR(i, l, r) for(int i = l; i <= r; ++i)
#define FORD(i, l, r) for(int i = l; i >= r; --i)
#define REP(i, r) for(int i = 0; i < int(r); ++i)
#define REPD(i, r) for(int i = int(r)-1; i >= 0; --i)
#define fi first
#define se second
#define sz size
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;

const int Nmax = 1e6 + 10;
const ll inf = 1e9;
const db _eps = 1e-5;

priority_queue <ii, vector<ii>, greater<ii> > pq;

int a[300][300];
int d[100];
int c[300][300];
int res;
int m, n;

void dijkstra() {
	FOR(i, 0, 9) d[i] = 1e9;
	pq.push(ii(d[1]=0, 1));
	while (!pq.empty()) {
		int u = pq.top().se, du = pq.top().fi; pq.pop();
		if (d[u] != du) continue;
		FOR(i, 0, 9) {
			if (d[i]  > d[u] + c[u][i])
				pq.push(ii(d[i]=d[u]+c[u][i], i));
		}
	}
}

int main() {
	cin >> m >> n;
	FOR(i, 0, 9) FOR(j, 0, 9) cin >> c[j][i];
	dijkstra();
	FOR(i, 1, m) FOR(j, 1, n) {
		cin >> a[i][j];
		if (a[i][j] == -1) continue;
		res += d[a[i][j]];
	}
	cout << res << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
using lint=int64_t;

lint a[3010]={};
lint dp[3010][3010];
bool visited[3010][3010];

lint rec(int l,int r,int turn)
{
	if(l==r)
		return 0;
	
	if(visited[l][r])
		return dp[l][r];

	// turn of first
	lint ret=0;
	if(turn==1)
		ret=max(rec(l+1,r,-turn)+a[l],rec(l,r-1,-turn)+a[r-1]);
	else // turn of second
		ret=min(rec(l+1,r,-turn)-a[l],rec(l,r-1,-turn)-a[r-1]);

	dp[l][r]=ret;
	visited[l][r]=true;
	return ret;
}

int main()
{
	int N;

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

	cout << rec(0,N,1) << endl;
	return 0;
}


Measured memory_bytes: 78464
#include <bits/stdc++.h>
#include <atcoder/scc>

using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

using ll = long long int;

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }

int N,M;
inline void input(){
    fast_io();
    cin >> N >> M;
}

inline int solve(){
    atcoder::scc_graph scc_g(N);
    for (int i = 0; i < M; i++)
    {
        int a,b; cin >> a >> b;
        scc_g.add_edge(a,b);
    }
    auto scc = scc_g.scc();
    cout << scc.size() << "\n";
    for(auto vec:scc){
        cout << vec.size() << " ";
        // reverse(vec.begin(),vec.end());
        cout << vec << "\n";
    }
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 40600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	bool ch=true;
	int n,i;
	cin>>n;
	int t1=0,t2,x1=0,x2,y1=0,y2;
	for(i=0;i<n;i++){
		cin>>t2>>x2>>y2;
		ll dis=(ll)abs(x2-x1)+(ll)abs(y2-y1),dt=t2-t1;
		if(dis<=dt&&dis%2==dt%2){}
		else{
			ch=false;
			break;
		}
		t1=t2;
		x1=x2;
		y1=y2;
	}
	if(ch)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	
	
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
X=[]
for i in range(N):
    K=list(map(int,input().split()))
    for i in range(K[0]):
        X.append(K[i+1])
count=0
for i in range(M):
    if X.count(i+1)==N:
        count+=1
print(count)


Measured memory_bytes: 3060
using System;

class Program
{
	static char[] alpha = new char[26];

	static void Main(string[] args)
	{
		int i;
		
		Int64 n = Int64.Parse(Console.ReadLine());
		

		for(i = 0; i < 26; i++)
        {
			alpha[i] = (char)('a' + (char)i);
        }

		string result = To26sin(n);

		Console.WriteLine(result);
		return;
	}

	//N進数に変換
	static string To26sin(Int64 val)
    {
		Int64 tmpVal;
		string ans = "";

        while (true)
        {
			val--;
			tmpVal = val % 26;
			ans = alpha[tmpVal] + ans;
			val = val/26;
			
			if(val <= 0)
            {
				break;
            }
        }

		return ans;
    }

}

Measured memory_bytes: 27504
arr_1 = [1,3,5,7,8,10,12]
arr_2 = [4,6,9,11]
arr_3 = [2]
x,y = gets.split.map(&:to_i)

if arr_1.include?(x)&& arr_1.include?(y) ||
   arr_2.include?(x)&& arr_2.include?(y)||
   arr_3.include?(x)&& arr_3.include?(y)
   puts "Yes"
else
   puts "No"
end


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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T &_t) { for (auto &_e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

char ToUpper(char cX) { return toupper(cX); }

int main(void) {
	string a, b, c;
	cin >> a >> b >> c;
	string ans = { a[0] , b[0] , c[0] };
	std::transform(ans.begin(), ans.end(), ans.begin(), ToUpper);
	cout << ans << endl;
	return 0;
}

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

//ユーグリッドの互除法による最大公約数を求めるメソッド
ll gcd(ll a, ll b) {
  ll smaller = min(a, b);
  ll bigger = max(a, b);
  ll surplus = bigger % smaller;
  if (surplus == 0) return smaller;
  surplus = gcd(smaller, surplus);
  return surplus;
}

//最小公倍数を求めるメソッド
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  rep(i,n){
    ll t;
    cin >> t;
    ans = lcm(ans, t);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
const ll MOD = 1e9 + 7;


ll a[N], x, b[N];

int main() {

    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    int n;
    cin>>n;

    for(int i=0;i<n;i++) {
        cin>>x;
        b[i] = x;
        a[x] ++;
    }
    ll ret = 0;
    for(int i=0;i<N-5;i++) {
        ret += a[i] * (a[i] - 1) / 2;
    }
    //cout<<ret<<endl;

    int last = 1e6;
    for(int i=0;i<n;i++) {
        ret = ret - (a[b[i]] - 1);
        a[b[i]] --;
        ret = ret + a[last];
        a[last] ++;
        last = b[i];
        printf("%lld\n", ret);
    }
	return 0;
}


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

#define ll long long int
#define str string
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

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

vector <ll> v;
double Y[10000000] = {}, X[10000000] = {},m = 0,a = 0,b = 0,n = 0, x = 0,y = 0,sum = 0, max = 999999999;
ll digit[100000000] = {};
str S,Sa;
bool ans = false;

int findDigits(int n) {
        int i = 0;
        while (n > 0) {

                digit[i] = n%10;
                n /= 10;
                i++;
        }
        return i;
}

int main(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        //Code Line
        string SA;
        cin >> S >> Sa >> SA;
  Sa =toupper(Sa[0],locale());
      cout << toupper(S[0],locale()) << Sa[0] << toupper(SA[0],locale()) << endl;
                //Code Line
        return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    long long int n,k,q;
    long long int p;
    long long int a[100005];
    scanf("%lld%lld%lld",&n,&k,&q);
    for(int i = 1 ; i <= n ; i ++ )
        a[i] = k;
    for(int i = 1 ; i <= q ; i ++ )
    {
        scanf("%lld",&p);
        a[p] ++ ;
    }
    for(int i = 1 ; i <= n ; i ++ )
    {
        a[i] -= q;
    }
    for(int i = 1 ; i <= n ; i ++ )
    {
        if(a[i] <= 0)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	ll N, W, w, v, miw;
	vector<ll> V[4];
	cin >> N >> W;
	ll i, j, k, l;
	for (i = 0; i < N; i++) {
		cin >> w >> v;
		if (!i)miw = w;
		V[w - miw].push_back(v);
	}
	for (i = 0; i < 4; i++) {
		V[i].push_back(0ll);
		sort(V[i].begin(), V[i].end(), greater<ll>());
		for (j = 1; j < V[i].size(); j++) {
			V[i][j] += V[i][j - 1];
		}
	}
	ll ans = 0;
	for (i = 0; i < V[0].size(); i++) {
		for (j = 0; j < V[1].size(); j++) {
			for (k = 0; k < V[2].size(); k++) {
				for (l = 0; l < V[3].size(); l++) {
					if (miw*(i + j + k + l ) + j + 2 * k + 3 * l > W)continue;
					ll I, J, K, L;
					I = (i == 0 ? 0 : V[0][i - 1]);
					J = (j == 0 ? 0 : V[1][j - 1]);
					K = (k == 0 ? 0 : V[2][k - 1]);
					L = (l == 0 ? 0 : V[3][l - 1]);
					ans = max(ans, I + J + K + L);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

const int MAXN = 300;
const int MOD = int(1E9) + 7;
const int INV2 = (MOD + 1) / 2;

inline int add(int x, int y) {return (x + y >= MOD ? x + y - MOD : x + y);}
inline int sub(int x, int y) {return (x - y < 0 ? x - y + MOD : x - y);}
inline int mul(int x, int y) {return 1LL * x * y % MOD;}

int pow_mod(int b, int p) {
	int ret = 1;
	for(int i=p;i;i>>=1,b=mul(b,b))
		if( i & 1 ) ret = mul(ret, b);
	return ret;
}

int fct[2*MAXN + 5], ifct[2*MAXN + 5];
void init() {
	fct[0] = 1; for(int i=1;i<=2*MAXN;i++) fct[i] = mul(fct[i - 1], i);
	for(int i=0;i<=2*MAXN;i++) ifct[i] = pow_mod(fct[i], MOD - 2);
}

int dp[2][MAXN + 5][MAXN + 5];

int d[MAXN + 5], N;
int main() {
	init(), scanf("%d", &N);
	for(int i=1;i<=N;i++)
		scanf("%d", &d[i]), d[i]--;
	int tot = 0; dp[0][0][0] = 1;
	for(int i=1;i<=N;i++) {
		if( d[i] ) {
			for(int j=0;j<i;j++)
				for(int k=0;k<=tot;k++)
					dp[1][j][k] = dp[0][j][k];
			for(int j=0;j<i;j++)
				for(int k=0;k<=tot;k++)
					dp[0][j+1][k+d[i]-1] = add(dp[0][j+1][k+d[i]-1], mul(d[i], dp[1][j][k]));
			tot += d[i] - 1;
		}
	}
	int ans = mul(mul(fct[N-1], INV2), dp[0][N][0]), tmp = 1;
	for(int i=1;i<=N;i++) tmp = mul(tmp, ifct[d[i]]);
	for(int i=3;i<N;i++)
		for(int j=1;j<=tot;j++) {
			int coef = mul(mul(fct[i-1], INV2), mul(fct[N-i-1], tmp));
			ans = add(ans, mul(mul(coef, j), dp[0][i][j]));
		}
	printf("%d\n", ans);
}

Measured memory_bytes: 896
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String, Integer> hash = new HashMap<String, Integer>();

        int N = sc.nextInt();
        for (int i=0; i<N; i++) {
            String s = sc.next();
            int count = hash.getOrDefault(s, 0);
            count++;
            hash.put(s, count);
        }

        int M = sc.nextInt();
        for (int i=0; i<M; i++) {
            String t = sc.next();
            int count = hash.getOrDefault(t, 0);
            count--;
            hash.put(t, count);
        }

        int max = -1000000000;
        for (int val : hash.values()) {
            max = Math.max(max, val);
        }
        if (max >= 0)
            System.out.println(max);
        else
            System.out.println(0);
    }
}

Measured memory_bytes: 22996
N, C = gets.split(' ').map(&:to_i)
pl = []
N.times do
  pr = gets.split(' ').map(&:to_i)
  pl.push(pr)
end
sum = [0] * (10 ** 5 + 1)
pl.sort_by!{|p| [p[2], p[0]]}
1.upto(C) do |i|
  preen = -1
  while !pl.empty? && pl[0][2] == i
    st, en = pl.shift
    if st == preen
      sum[st] += 1
    else
      sum[st - 1] += 1
    end
    sum[en] -= 1
    preen = en
  end
end
1.upto(10 ** 5) do |i|
  sum[i] += sum[i - 1]
end
puts sum.max

Measured memory_bytes: 15224
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  vector<ll> low, high;
  low.push_back(0);
  high.push_back(1);
  low.push_back(-2);
  high.push_back(-1);
  ll len = 4;
  for(int i = 2; i < 42; i++, len *= 2LL) {
    if(i % 2 ==	0) {
      ll b = high[high.size()-2];
      low.push_back(b + 1LL);
      high.push_back(b + len);
    } else {
      ll b = low[low.size()-2];
      high.push_back(b - 1LL);
      low.push_back(b - len);
    }
  }
  vector<ll> base(low.size(), 1LL);
  for(int i = 1; i < low.size(); i++) base[i] =	base[i-1] * -2LL;
  //  REP(i, low.size()) {                                                      
  //    cout << i << "," << low[i] << "," << high[i] << "," << base[i] << endl;
  //  }                                                                         
  int fst = 0;
  vector<int> bits(50, 0);
  ll N;  cin>>N;
  for(int i = low.size() - 1; i >= 1; i--) {
    if(N >= low[i] && N <= high[i]) {
      if(fst == 0) fst = i;
      bits[i] = 1;
      N	-= base[i];
    }
  }
  if(N == 1) bits[0] = 1;
  for(int i = fst; i >= 0; i--) cout <<	bits[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  vector<pair<char, int>> v(n);
  rep(i, n) cin >> v[i].fi >> v[i].se;
  int s = 0;
  for (auto &p : v) {
    char c;
    int x;
    tie(c, x) = p;
    s += x * ((c == '(') - (c == ')'));
    if (s < 0) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << (s ? "NO" : "YES") << endl;
}

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

int main() {
  string O,E,P,S;
  cin>>O>>E;
  S=O+E;
  int N=S.size();
  
  for(int i=0;i<N;i++){
      if (i % 2 == 0){
        P = P + O.at(i/2);
      } else{
        P = P + E.at(i/2);
      }
  }
  cout<<P<<endl;
  
}


Measured memory_bytes: 256
N,n,v,w,t,*m,*p;main(W){for(;scanf("%d",&W),W;){int c[1001]={0};for(scanf("%d",&n);n--;)for(scanf("%d,%d",&v,&w),p=c+W+1;--p-c;*p==c[W]?m=p:0)p-c>=w&&*p<(t=p[-w]+v)?*p=t:0;printf("Case %d:\n%d\n%d\n",++N,c[W],m-c);}return 0;}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int A=1, B=2, C=4, D=8, E=16, F=32, G=64;

int sig[10];


int main()
{
    sig[0] =1 + B*1 + C*1 + D*1 + E*1 + F*1 + G*0;
    sig[1] =0 + B*1 + C*1 + D*0 + E*0 + F*0 + G*0;
    sig[2] =1 + B*1 + C*0 + D*1 + E*1 + F*0 + G*1;
    sig[3] =1 + B*1 + C*1 + D*1 + E*0 + F*0 + G*1;
    sig[4] =0 + B*1 + C*1 + D*0 + E*0 + F*1 + G*1;
    sig[5] =1 + B*0 + C*1 + D*1 + E*0 + F*1 + G*1;
    sig[6] =1 + B*0 + C*1 + D*1 + E*1 + F*1 + G*1;
    sig[7] =1 + B*1 + C*1 + D*0 + E*0 + F*1 + G*0;
    sig[8] =1 + B*1 + C*1 + D*1 + E*1 + F*1 + G*1;
    sig[9] =1 + B*1 + C*1 + D*1 + E*0 + F*1 + G*1;

    //REP(10) cout << i << ":" << sig[i] << endl;
    int n;
    while(cin >> n )
    {
        if(n== -1) break;
        int disp = 0, next = 0, ans = 0;
        REP(n)
        {
            cin >> next;
            ans = sig[next]^disp;
            //cout << "ans" << ans << endl;
            rep(j,7)cout << (ans>>(6-j) & 1);
            cout << endl;
            disp = sig[next];
        }
        
    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

#define mp make_pair
#define f first
#define s second

using namespace std;

typedef pair<int,int> P;

const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int h,w;
string grid[1000];
int d[1000][1000];

void bfs(P S){

  queue<P>que;
  que.push(S);
  d[S.f][S.s]=0;

  while(!que.empty()){
    P now=que.front();
    
    que.pop();
    for(int i=0;i<4;i++){
      if(0<=now.f+dx[i] && 0<=now.s+dy[i] &&
	 now.f+dx[i]<h && now.s+dy[i]<w
	 && grid[now.f+dx[i]][now.s+dy[i]]!='X'){

	if(d[now.f][now.s]+1<d[now.f+dx[i]][now.s+dy[i]]){
	  d[now.f+dx[i]][now.s+dy[i]]=d[now.f][now.s]+1;
	  que.push(P(now.f+dx[i],now.s+dy[i]));
	}
      }
    }
  }
}

int main(void){
  int n;
  P v[1001];

  cin >> h >> w >> n;

  for(int i=0;i<h;i++)cin >> grid[i];

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(grid[i][j]=='S')v[0]=mp(i,j);
      if(grid[i][j]!='X'&&grid[i][j]!='.')
	v[grid[i][j]-'0']=mp(i,j);
    }
  }

  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<h;j++)
      for(int k=0;k<w;k++)d[j][k]=100000000;
    bfs(v[i]);
    ans+=d[v[i+1].f][v[i+1].s];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6180
N = int(input())
B = [int(n) for n in input().split()]

A = [0]*N
A[0] = B[0]
for x in range(len(B)):
	if A[x] > B[x]:
		A[x] = B[x]
	A[x+1] = B[x]

print(sum(A))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long n, v;
list<int>a, b;
void solve()
{
	if (!n)return;
	if (n % 2 == 1)
		n >>= 1, solve(), v++, a.insert(a.begin(), v), b.insert(b.begin(), v);
	else n--, solve(), v++, a.insert(a.begin(), v), b.insert(b.end(), v);
}
int main()
{
	cin >> n;
	solve();
	cout << a.size() + b.size() << endl;
	for (list<int>::iterator i = a.begin(); i != a.end(); i++)
		cout << *i << ' ';
	for (list<int>::iterator i = b.begin(); i != b.end(); i++)
		cout << *i << ' ';
	cout << endl;
	return 0;
}

Measured memory_bytes: 256