akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder {
    class _042a {
        static void Main() {
            string[] input = Console.ReadLine().Split(' ');
            int five = 0;
            int seven = 0;
            foreach(string s in input) {
                int x = int.Parse(s);
                if(x == 5) {
                    five++;
                }
                else if(x == 7) {
                    seven++;
                }
                else {
                    five = 0;
                    seven = 0;
                    break;
                }
            }
            if(five == 2 && seven == 1) {
                Console.WriteLine("YES");
            }
            else {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 11092
function Main(input) {
	input = input.trim().split("\n").map((input)=>Number(input));
  var k = input[5];
  for(var i = 0; i < 5; i++){
    for(var j = i + 1; j < 5; j++){
      if(input[j] - input[i] > k){
         console.log(":(");
        return;
      }
    }
  }
  console.log("Yay!");
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> B(N-1);
    for (auto &b : B) cin >> b;
    int ans = B[0];
    for (int i = 1; i < N-1; ++i) {
        ans += min(B[i-1], B[i]);
    }
    ans += B[N-2];
    printf("%d\n", ans);
    return 0;
}


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

int main(){
  int N , T ; 
  cin >> N >> T ; 
  int ans = 1005 ;
  int cnt = 0 ; 
  
  for(int i = 0 ; i < N ;i++){
    int c, t ; 
    cin >> c >> t ; 
    if(t <= T){
      ans = min(ans,c) ; 
      cnt++ ; 
    }
    
  }
  if( cnt == 0 ){
    cout << "TLE" << endl ; 
    return 0 ; 
  }
  cout << ans << endl ; 
  
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin >> a;
  int x = a.size();
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == 'C') {
      x = i;
    }
  }
  for (int i = x; i < a.size(); i++) {
    if (a[i] == 'F') {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
struct Rest
{
    int i,p;
    string s;
};
Rest rest[100+10];
bool comp(Rest a,Rest b)
{
    if(a.i!=b.i)
    {
        if(a.s!=b.s) return a.s<b.s;
        else
        {
            if(a.i!=b.i)
            {
                return a.p>b.p;
            }
        }
    }
    return a.p>b.p;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        rest[i].i=i;
        cin>>rest[i].s>>rest[i].p;
    }
    sort(rest+1,rest+n+1,comp);
    for(int i=1;i<=n;i++)
    {
        cout<<rest[i].i<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        s: chars,
        t: chars,
    }
    let mut ss = s.clone();
    ss.extend_from_slice(&s);
    let n = s.len();
    let mut tbl = vec![[2 * n + 1; 26]; 2 * n + 1];
    for i in (0..2 * n).rev() {
        let val = tbl[i + 1];
        tbl[i] = val;
        let idx = ss[i] as usize - 97;
        tbl[i][idx] = i + 1;
    }
    // Assumes usize is 64-bit.
    assert_eq!(std::mem::size_of::<usize>(), 8);
    let mut cnt = 0;
    for t in t {
        let idx = t as usize - 97;
        let rem = cnt % n;
        let to = tbl[rem][idx];
        if to >= 2 * n {
            puts!("-1\n");
            return;
        }
        cnt += to - rem;
    }
    puts!("{}\n", cnt);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 51452
open Batteries
open Printf
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in

  let l = [1;2;4;8;16;32;64] in
  let ans = 
    List.filter (fun x -> x <= n) l |>
    List.max
  in

  Printf.printf "%d\n" ans


Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int a,b,c;
	char d;
	int ans=0;

	cin>>a;
	cin>>d;
	cin>>b;
	cin>>d;
	cin>>c;
	if(a<2019)ans=1;
	if(a==2019&&b<4)ans=1;
	if(a==2019&&b<=4&&c<=30)ans=1;
	if(ans==1)cout<<"Heisei"<<endl;
	if(ans==0)cout<<"TBD"<<endl;
	return 0;
}


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

int main(){
  int A,B;
  string S;

  cin >> A >> B;
  cin >> S;
  for (int i = 0; i < A; i++){
    if(!isdigit(S[i])){
      cout << "No" << endl;
      return 0;
    }
  }
  if(S[A] != '-'){
    cout << "No" << endl;
    return 0;
  }
  for (int i = A+1; i < A+B+1; i++){
    if(!isdigit(S[i])){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
dxy1 = 0
for i in range(n):
    dxy1 += abs(x[i]-y[i])
dxy2 = 0
for i in range(n):
    dxy2 += abs(x[i]-y[i])**2
dxy2 = math.sqrt(dxy2)
dxy3 = 0
for i in range(n):
    dxy3 += abs(x[i]-y[i])**3
dxy3 = dxy3**(1/3)
dxy4 = 0
for i in range(n):
    tmp = abs(x[i]-y[i])
    if dxy4 < tmp:
        dxy4 = tmp
print(dxy1)
print(dxy2)
print(dxy3)
print(dxy4)



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

using namespace std;

typedef long long LL;
typedef double DB;
typedef unsigned int UI;
typedef pair<int, int> PII;

const int inf = 0x7f7f7f7f;

#define rdi() read<int>()
#define rdl() read<LL>()
#define rds(a) scanf("%s", a)
#define mk(i, j) make_pair(i, j)
#define pb push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = j; i <= k; i ++)
#define Rep(i, j, k) for (int i = j; i >= k; i --)
#define Edge(i, u) for (int i = head[u]; i; i = e[i].nxt)

template<typename t> t read()
{
    t x = 0; int f = 1; char c = getchar();
    while (c > '9' || c < '0') f = c == '-' ? -1 : 1 , c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - 48 , c = getchar();
    return x * f;
}

template<typename t> void write(t x)
{
    if (x < 0){
        putchar('-'), write(-x);
        return;
    }
    if (x >= 10) write(x / 10);
    putchar(x % 10 + 48);
}

const int P = 1e9 + 7;
const int N = 1e5 + 10;
int fac[N], facinv[N], a[N], n, pos, vis[N], id;

int power(int a, int b)
{
    int c = 1;
    for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) c = 1ll * c * a % P;
    return c;
}

int C(int x, int y)
{
    return 1ll * fac[x] * facinv[y] % P * facinv[x - y] % P;
}

int main()
{
    n = rdi() + 1;
    for (int i = 1; i <= n; i ++) a[i] = rdi();
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; i ++) fac[i] = 1ll * fac[i - 1] * i % P;
    facinv[n] = power(fac[n], P - 2);
    for (int i = n - 1; i >= 0; i --) facinv[i] = 1ll * facinv[i + 1] * (i + 1) % P;
    for (int i = 1; i <= n; i ++)
	{
        if (vis[a[i]]) {
            pos = i;
            id = a[i];
            break;
        }
        vis[a[i]] = i;
    }
    int len = n - pos + 1;
    for (int i = 1; i <= n; i ++)
	{
        int ans = C(n, i); 
        if (i - 1 <= len - 1 + vis[id] - 1) ans -= C(len - 1 + vis[id] - 1, i - 1);
        ans = (ans + P) % P;
        write(ans), putchar(10);
    } 
    return 0;
}

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

int main() {
    int N , M;
    cin>>N>>M;
    vector<int> a(M);
    int study=0;
    rep(i,M){
        cin>>a[i];
        study+=a[i];
    }
    int ans = N-study;
    if (ans>=0){
        cout << ans << endl; 
    }else{
        cout << "-1" << endl; 
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=2e5+10;
int P[N],sMx[N],hsum[N],Is[N];
int f[N][2];
int tr[2][N],n;
#define lowbit(a) ((a)&(-a))
inline void Update(int*tr,int p,int x){p=n-p+1;for(;p<=n;p+=lowbit(p)) tr[p]=max(tr[p],x);return;}
inline int  Query(int*tr,int p){p=n-p+1;int ret=0;for(;p;p-=lowbit(p)) ret=max(ret,tr[p]);return ret;}
int Mx[2][N<<2];
#define ls (u<<1)
#define rs (u<<1|1)
const int INF=1e9;
inline void Insert(int u,int l,int r,int i,int p){
	Mx[0][u]=max(Mx[0][u],f[i][0]);
	if(!Mx[1][u]) Mx[1][u]=f[i][1];
	else Mx[1][u]=max(Mx[1][u],f[i][1]);
	if(l==r) return;
	int mid=(l+r)>>1;
	if(mid>=p) Insert(ls,l,mid,i,p);
	else       Insert(rs,mid+1,r,i,p);
}
inline void update(int u){Mx[0][u]=max(Mx[0][ls],Mx[0][rs]),Mx[1][u]=max(Mx[1][ls],Mx[1][rs]);}
inline void Del(int u,int l,int r,int p){
	if(l==r) {Mx[0][u]=0,Mx[1][u]=-INF;return;}
	int mid=(l+r)>>1;
	if(mid>=p) Del(ls,l,mid,p);
	else       Del(rs,mid+1,r,p);
	update(u);
}
int Query(int u,int l,int r,int p,int fl){
	if(Mx[fl][u]==-INF) return -INF;
	if(p>r) return -INF;
	if(l>=p) return Mx[fl][u];
	int mid=(l+r)>>1;int re=-INF;
	if(mid>=p) re=max(re,Query(ls,l,mid,p,fl));
	re=max(re,Query(rs,mid+1,r,p,fl));
	return re;
}
char ans[N];
inline bool check(int i,int cntx,int cnty,int maxx,int maxy){
	if(i==n) return cntx==cnty;
	//cerr<<"check : ";cerr<<cntx<<' '<<cnty<<' '<<maxx<<' '<<maxy<<endl;
	int p=hsum[n]-hsum[i];
	int val=cntx-cnty+p,re;
	if(val>=0){
		if(val%2==0) re=Query(1,1,n,maxy+1,0);
		else         re=Query(1,1,n,maxy+1,1);
		//cerr<<"p="<<p<<"  goal_val1="<<val<<"  result1="<<re<<endl;
		if(re>=val) return 1;
	}
	val=cnty-cntx+p;
	if(val>=0){
		if(val%2==0) re=Query(1,1,n,maxx+1,0);
		else         re=Query(1,1,n,maxx+1,1);
		//cerr<<"p="<<p<<"  goal_val2="<<val<<"  result2="<<re<<endl;
		if(re>=val) return 1;
	}
	return 0;
}
int main()
{
	init(n);
	for(int i=1;i<=n;++i) {
		init(P[i]),sMx[i]=max(sMx[i-1],P[i]);
		hsum[i]=hsum[i-1]+(Is[i]=(int)(sMx[i]==P[i]));
	}
	for(int i=n;i;--i) {
		if(Is[i]) {
			f[i][0]=Query(tr[0],P[i])+2;
			f[i][1]=Query(tr[1],P[i])+2;
		}else{
			f[i][0]=Query(tr[1],P[i])+1;
			f[i][1]=Query(tr[0],P[i])+1;
		}
		if(!(f[i][1]&1)) f[i][1]=-INF;
		if(f[i][0]&1) f[i][0]=-INF;
		Update(tr[0],P[i],f[i][0]);
		Update(tr[1],P[i],f[i][1]);
	}
	for(int i=1;i<=n;++i) Insert(1,1,n,i,P[i]);
	int cntx=0,cnty=0;int maxx=0,maxy=0;
	for(int i=1;i<=n;++i) {
		Del(1,1,n,P[i]);
		if(check(i,cntx+(P[i]>maxx),cnty,max(maxx,P[i]),maxy)) ans[i]='0',cntx+=P[i]>maxx,maxx=max(maxx,P[i]);
		else if(check(i,cntx,cnty+(P[i]>maxy),maxx,max(P[i],maxy))) ans[i]='1',cnty+=P[i]>maxy,maxy=max(maxy,P[i]);
		else return puts("-1"),0;
		//puts(ans+1);
	}
	puts(ans+1);
	return 0;
}


Measured memory_bytes: 13184
S = list(input())
dp = [[0 for _ in range(13)] for _ in range(len(S)+1)]
dp[0][0]=1
#print(dp[15][5])
for i in range(len(S)):
  a = 0
  if S[i]=="?":
    for j in range(10):
      for k in range(13):
        dp[i+1][(k*10+j)%13] += dp[i][k]
  else:
    a = int(S[i])
    for k in range(13):
      dp[i+1][(k*10+a)%13] += dp[i][k]
  for k in range(13):
    dp[i + 1][k] %= (10**9+7)
print(dp[len(S)][5])


Measured memory_bytes: 69512
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
int main()
{
  int N, A;

  cin >> N >> A;

  if((N%500) <= A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(a,b) for(long long a = 0;a < b;++a)
int main(){
	vector<int> a;
	REP(i,12){
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	sort(a.begin(),a.end());
	for(int i = 0;i < 12;++i){
		if(i % 4 != 3&&a[i] != a[i+1]){
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n,k;
	cin>>n>>k;

	vector<lli> x(n);
	REP(i,0,n)cin>>x[i];

	//折り返さないでマイナス方向にひたすら行く場合
	lli ans = INF;

	//折り返さないでプラス方向にひたすら行く場合

	REP(i,0,n-k+1){
		lli s = x[i];
		lli e = x[i+k-1];
		if(DEBUG)cout<<"s="<<s<<"e="<<e<<endl;
		if(s * e > 0)ans = min(ans,max(abs(s),abs(e)));
		else{
			ans = min({ans,abs(2*s-e),abs(2*e-s)});
		}
	}
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

bool cmpc(pair<int, int> a, pair<int, int> b) {
    if(a.first!=b.first) {
        return a.first<b.first;
    } else {
        return a.second<b.second;
    }
}
bool cmpa(pair<int, int> a, pair<int, int> b) {
    if(a.second!=b.second) {
        return a.second>b.second;
    } else {
        return a.first>b.first;
    }
}

int main() {
    int N;
    cin >> N;
    vector<pair<int, int> > ab, cd;
    for(int n=0; n<N; n++) {
        int a, b;
        cin >> a >> b;
        ab.push_back(make_pair(a, b));
    }
    sort(ab.begin(), ab.end(), cmpa);
    
    for(int n=0; n<N; n++) {
        int c, d;
        cin >> c >> d;
        cd.push_back(make_pair(c, d));
    }
    sort(cd.begin(), cd.end(), cmpc);
    
    vector<bool> seen(N, false);
    int ans=0;
    for(int cdn=0; cdn<N; cdn++) {
        for(int abn=0; abn<N; abn++) {
            if(cd[cdn].first>ab[abn].first && cd[cdn].second>ab[abn].second && !seen[abn]) {
                ans++;
                seen[abn]=true;
                break;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
    
}

Measured memory_bytes: 504
n = int(input())
a = [-1]
for i in range(n):
    a.append(int(input()))

ans = 0
cur = 0
for i, item in enumerate(a[::-1]):
    if i == 0:
        cur = item
        ans += item
        continue
    cur -= 1
    if cur < item:
        ans += item
        cur = item
    elif cur == item:
        continue
    elif cur > item:
        print(-1)
        exit()
print(ans)

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

long long mergeVal(vector<int>& A, int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;

	vector<int> L(n1), R(n2);
	for (int i = 0; i < n1; i++) L.at(i) = A.at(left + i);
	for (int i = 0; i < n2; i++) R.at(i) = A.at(mid + i);
	L.push_back(1000000005);
	R.push_back(1000000005);

	int j = 0;
	int k = 0;
	long long inv = 0;
	for (int i = left; i < right; i++)
	{
		if (L.at(j) <= R.at(k)) {
			A.at(i) = L.at(j++);
		}
		else {
			A.at(i) = R.at(k++);
			inv += n1 - j;
		}
	}

	return inv;
}

long long mergeSort(vector<int>& A, int left, int right)
{
	if (left + 1 >= right) return 0;

	int mid = (left + right) / 2;

	long long inv = 0;
	inv += mergeSort(A, left, mid);
	inv += mergeSort(A, mid, right);
	inv += mergeVal(A, left, mid, right);

	return inv;
}

int main(void)
{

	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A.at(i);

	cout << mergeSort(A, 0, N) << endl;;

	return 0;
}



Measured memory_bytes: 5244
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
  ll n;
  cin>>n;
  
  cout<<(n>=30?"Yes":"No");
  return 0;
}

Measured memory_bytes: 3620
n,a,b = [int(x) for x in input().split()]

ans = 0
mod = 10**9+7
ans = (pow(2,n,mod)-1)%mod

com1 = 1
for i in range(n-a+1,n+1):
    com1 = com1*i%mod
for i in range(1,a+1):
    com1 = com1 * pow(i,mod-2,mod)%mod
com2 = 1
for i in range(n-b+1,n+1):
    com2 = com2*i%mod
x = 1
for i in range(1,b+1):
    x = x*i%mod
com2 = com2*pow(x,mod-2,mod)%mod

ans = (ans - com1 - com2)%mod
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

const int N =1e+5+5;

int main() {
    using namespace std;
    int a[N], b[N];
    int n;

    cin >> n;

    int maxval = 0;
    int res;
    for (int i=0; i<n; ++i) {
        cin >> a[i] >> b[i];
        if (maxval < a[i]) {
            maxval = a[i];
            res = a[i] + b[i];
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main(){
  ll N;
  cin >> N;
  vector<string> s(N);
  rep(i, N) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  ll ans= 0;
  ll flag=88888888;
  sort(all(s));
  for (ll i = 1; i < N; i++) {
    if (s[i] == s[i-1]) {
      flag = min(i-1,flag);
      ans+=i-flag;
      //dout << flag << "/" << i << endl;
    } else {
      flag = 999999;
    }
  }
  cout << ans;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の string型配列と同じような感じ）
map<int, string> mp;
for (auto itr =mp.begin(); itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;


*/


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  int i,count=0;
  for(i=0;i<n;i++){
    cin >> vec.at(i);
  }
  for(i=0;i<n;i++){
    if(vec.at(i)!=i+1){
      count++;
    }
  }
  if(count<=2){
    cout << "YES";
  }else{
    cout << "NO";
  }
}


Measured memory_bytes: 256
import sys
import numpy as np

X, N = (int(item) for item in sys.stdin.readline().split())
p = np.array([int(item) for item in sys.stdin.readline().split()], dtype=np.int8)

# 空配列の時
if N == 0:
    print(X)
    exit()

diff = [0 for _ in range(100)]
for item in p-X:
    diff[abs(item)] += 1
diff_ans = 0
while(True):
    if diff[diff_ans] < 2:
        ans_small = X - diff_ans
        if diff_ans > 0:
            if ans_small in p:
                print(X + diff_ans)
            elif diff_ans:
                print(ans_small)
            break
        elif X not in p:
            print(X)
            break
    diff_ans += 1


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

int main(){
  int N;
  cin >> N;
  vector<int> v(N+1,0);
  for(int i=2;i<=N;i++){
    int A;
    cin >> A;
    v.at(A)++;
  }
  for(int i=1;i<=N;i++){
    cout << v.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 4052
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	vector<pair<int,int>> A(100);
	REP(i,100){
		A[i].first = i+1;
		A[i].second = 0;
	}
	int v;
	while(cin>>v){
		A[v-1].second++;
	}
	sort(ALL(A),[](pair<int,int>& l,pair<int,int>& r){return l.second==r.second ? l.first<r.first : l.second>r.second;});
	int M=A[0].second;
	for(int i=0;i<100;i++){
		if(A[i].second!=M) break;
		out(A[i].first);
	}
	return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

struct Combination{
    vector<ll> fac,finv,inv;
    Combination(int mx){init(mx);}
    void init(int mx){
        fac.resize(mx+1);
        finv.resize(mx+1);
        inv.resize(mx+1);
        fac[0]=fac[1]=1;
        finv[0]=finv[1]=1;
        inv[1]=1;
        for(int i=2;i<=mx;i++){
            fac[i]=fac[i-1]*i%MOD;
            inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
            finv[i]=finv[i-1]*inv[i]%MOD;
        }
    }
    ll calc(int n,int k){
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
    }
};

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1)res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int main(){
    int n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    ll dp[n+1]={};
    dp[0]=1;
    Combination comb(n);
    for(int j=a;j<=b;j++){
        for(int i=n;i>=1;i--){
            for(int k=c;k<=i/j&&k<=d;k++){
                ll ce=comb.calc(n-(i-k*j),k*j)*comb.fac[k*j];
                ce%=MOD;
                ce*=comb.finv[k];
                ce%=MOD;
                ce*=modpow(comb.finv[j],k);
                ce%=MOD;
                dp[i]+=dp[i-k*j]*ce;
                dp[i]%=MOD;
            }
        }
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define eb emplace_back
#define ii pair<int, int> 
#define vii vector<pair<int, int> >
#define fi first
#define se second
const int MOD = (int) 1e9+7;
map<int, vi> dist, cnt;
int n, m;
vector<pair<ii, int> > q;
vii G[200005];
void djk(int s, vi& dist, vi& cnt)
{
	dist.assign(n+5, LLONG_MAX/100000LL);
	cnt.assign(n+5, 0);
	priority_queue<ii, vii, greater<ii> > q;
	q.push({0, s}); dist[s]=0, cnt[s]=1;
	while(!q.empty())
	{
		int d=q.top().fi, u=q.top().se; q.pop();
		if(dist[u]!=d) continue;
		for(auto v: G[u])
		{
			if(dist[u]<LLONG_MAX and dist[v.fi]>dist[u]+v.se)
			{
				cnt[v.fi]=cnt[u];
				dist[v.fi]=dist[u]+v.se;
				q.push({dist[v.fi], v.fi});
			}
			else if(dist[v.fi]==dist[u]+v.se)
			{
				cnt[v.fi]=(cnt[v.fi]+cnt[u])%MOD;
			}
		}
	}
}
signed main()
{
	int s, t;
	cin>>n>>m>>s>>t;
	while(m--)
	{
		int u, v, w;
		cin>>u>>v>>w;
//		cout<<u<<" "<<v<<endl;
		G[u].eb(v, w);
		G[v].eb(u, w);
		q.push_back({{u, v}, w});
	}
	djk(s, dist[s], cnt[s]);
	djk(t, dist[t], cnt[t]);
	int ans=cnt[s][t]*cnt[s][t]%MOD;
	for(auto e: q)
	{
		int u=e.fi.fi, v=e.fi.se, d=e.se;
		if(dist[s][u]+dist[t][v]+d==dist[s][t] and 2*dist[s][u]<dist[s][t] and 2*dist[t][v]<dist[s][t])
		{
			int k=cnt[s][u]*cnt[t][v]%MOD;
			ans = (ans-k*k)%MOD;
		}
		if(dist[s][v]+dist[t][u]+d==dist[s][t] and 2*dist[s][v]<dist[s][t] and 2*dist[t][u]<dist[s][t])
		{
			int k=cnt[s][v]*cnt[t][u]%MOD;
			ans=(ans-k*k)%MOD;
		}
	}
	for(int u=1; u<=n; u++)
	{
		if(2*dist[s][u]==dist[s][t] and 2*dist[t][u]==dist[s][t]) 
		{
			int k=cnt[s][u]*cnt[t][u]%MOD;
			ans = (ans-k*k)%MOD;
		}
	}
	while(ans<0) ans+=MOD;
	cout<<ans;
}


Measured memory_bytes: 28976
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
 
using namespace std;
 
int main()
{   
    int flag = 0;
    string s, p;
    cin >> s >> p;
    string t = s + s;
    for (int i = 0;i < t.length();++i) {
        if (t.substr(i, p.length()) == p) flag = 1;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
 
    return 0;
}

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

const int N = 300010;

int num[N], n;

inline bool check(int l, int r) {
	if (num[l] == l) l++;
	if (num[r] == r) r--;
	if (l > r) return true;
	for (int i = l + 1; i <= r; i += 2) 
		if (num[i] != i) return false;
	for (int i = l; i <= r; i += 2)
		if (num[i] == i) return false;
	int mn = 1e9, mx = 0;
	for (int i = l; i <= r; i++) 
		mn = min(mn, num[i]), mx = max(mx, num[i]);
	if (mn != l || mx != r) return false;
	for (int i = l, a = 0, b = 0; i <= r; i += 2) {
		if (num[i] < i) {
			if (a > num[i]) return false;
			a = num[i];
		} else {
			if (b > num[i]) return false;
			b = num[i];
		}
	} 
	return true;
}

int fuck[N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) 
		scanf("%d", &num[i]), fuck[i] = num[i] == i;
	int ls = 1;
	for (int i = 1; i <= n; i++) {
		if (fuck[i] && fuck[i - 1]) {
			if (!check(ls, i - 2)) return puts("No"), 0;
			ls = i + 1;
		} else if (!fuck[i] && !fuck[i - 1]) {
			if (!check(ls, i - 1)) return puts("No"), 0;
			ls = i;
		} 
	}
	if (!check(ls, n)) return puts("No"), 0;
	puts("Yes");
}//

Measured memory_bytes: 2688
import numpy as np
N, M = map(int, input().split())
x = [0]*N
y = [0]*N
z = [0]*N
for i in range(N):
    x[i], y[i], z[i] = map(int, input().split())
x = np.array(x)
y = np.array(y)
z = np.array(z)


r = np.zeros((N,8))
r[:,0] =  x[:] +y[:] +z[:]
r[:,1] =  x[:] -y[:] +z[:]
r[:,2] =  x[:] +y[:] -z[:]
r[:,3] =  x[:] -y[:] -z[:]
r[:,4] = -x[:] +y[:] +z[:]
r[:,5] = -x[:] -y[:] +z[:]
r[:,6] = -x[:] +y[:] -z[:]
r[:,7] = -x[:] -y[:] -z[:]

print(int(max(np.sum(np.sort(r, axis=0)[::-1][:M,:],axis=0))))


Measured memory_bytes: 12596
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iostream>
#include <algorithm>
#define MAX 1000007
#define MAXN 1007
#define MAXM 1007
#define INF  0x3f3f3f3f
#define NINF 0xc0c0c0c0
#define MOD 1000000007
const double EXP=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> Vec;
typedef vector<Vec> Mat;
//================================================================================================

char s[205][30]; 
int main(){
	int a,b,c,x,y,ans=0;
	cin>>a>>b>>c>>x>>y;
	if(a+b<=2*c) {
		ans+=min(x,y)*(a+b);
	} else {
		ans+=min(x,y)*(c*2);
	}
	int t=min(x,y);
	x-=t;
	y-=t;
	if(x==0) {
		x=y;
		a=b;
	}
	if(a<=2*c) {
		ans+=a*x;
	} else {
		ans+=x*2*c;
	}
	cout<<ans;
    return 0;
}

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

int main(){
    int n,m,arr[10000],sum=0,cnt=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    int lw=ceil(sum*1.0/(4*m));
    for(int i=0;i<n;i++){
        if(arr[i]>=lw){
            cnt++;
        }
    }
    if(m<=cnt){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        String a=sc.next();
        char m[]=a.toCharArray();
        if(m[0]>='a'&&m[0]<='z')
            System.out.println("a");
        else System.out.println("A");
    }
}


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

using namespace std;

int main()
{
  string S;
  cin >> S;
  long long ans = 0;
  queue<pair<long long, string>> q;
  q.push({0, S});
  while (q.size())
  {
    pair<long long, string> p = q.front();
    q.pop();
    int size = p.second.size();
    if (size == 0)
    {
      ans += p.first;
      continue;
    }
    for (int i = 1; i <= size; i++)
      q.push({p.first + stoll(p.second.substr(0, i)), p.second.substr(i, size - i)});
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int A, B, C, D;
  cin>>A>>B>>C>>D;

  int taka = (C+(B-1))/B;
  int aoki = (A+(D-1))/D;
  if(taka>aoki){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int H = scanner.nextInt();
        int M = scanner.nextInt();

        double angle = Math.abs(M*6.0 - 0.5*(60*H + M));
        double length = Math.sqrt(Math.pow(A, 2) + Math.pow(B, 2) - 2*A*B*Math.cos(Math.toRadians(angle)));
        System.out.println(length);
    }
}


Measured memory_bytes: 36100
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
    int n;
    int m;
 
   cin >> n >> m;
  
   cout << (n*3+m)/2 << endl;
 
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    vector<int>  v(n);
    for(int i=1;i<=n;i++)
        v[i-1]=i;
    int curr=1;
    int ans=0;
    do
    {
        int flag=0;
        for(int i=0;i<n;i++)
        {
            if(v[i]!=a[i])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
            ans+=curr;
        flag=0;
        for(int i=0;i<n;i++)
        {
            if(v[i]!=b[i])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
            ans-=curr;
        curr++;
    }while(next_permutation(v.begin(),v.end()));
    cout<<abs(ans);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

void solve() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			return;
		}
		int grid[100][100] = {};
		int w, h;
		cin >> w >> h;
		REP(i, n) {
			int a, b;
			cin >> a >> b;
			a--; b--;
			grid[a][b]++;
		}
		int s, t;
		cin >> s >> t;
		int ans = 0;
		for (int i = 0; i < w - s + 1; ++i) {
			for (int q = 0; q < h - t + 1; ++q) {
				int cnt = 0;
				REP(te, s) {
					REP(j, t) {
						cnt += grid[i + te][q + j];
					}
				}
				ans = max(ans, cnt);
			}
		}
		cout << ans << endl;
	}
}

int main() {
	init();
	solve();
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
struct UnionFind {
    vector<int> par, siz;
    UnionFind(int n) {
        par.resize(n);
        siz.resize(n, 1);
        for(int i = 0; i < n; i++)
            par[i] = i;
    }
    int find(int x) {
        if(par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    bool unite(int u, int v) {
        u = find(u), v = find(v);
        if(u == v)
            return false;
        if(siz[u] < siz[v])
            swap(u, v);
        par[v] = u;
        siz[u] += siz[v];
        return true;
    }
    bool same(int u, int v) { return find(u) == find(v); }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<vector<int>> y(100010), x(100010);
    for(int i = 0; i < n; i++) {
        int xx, yy;
        cin >> xx >> yy;
        y[xx].push_back(yy);
        x[yy].push_back(xx);
    }
    UnionFind uf(100010);
    for(int i = 0; i <= 100000; i++) {
        for(int j = 1; j < x[i].size(); j++) {
            uf.unite(x[i][j], x[i][j - 1]);
        }
    }
    vector<vector<int>> v(100010);
    for(int i = 0; i <= 100000; i++) {
        v[uf.find(i)].push_back(i);
    }
    ll ans = 0;
    for(int i = 0; i <= 100000; i++) {
        if(uf.find(i) != i) {
            continue;
        }
        set<int> st;
        for(auto& e : v[i]) {
            for(auto& s : y[e]) {
                st.insert(s);
            }
        }
        if(st.empty()) {
            if(y[i].size() > 0) {
                ans += (ll)uf.siz[i];
            }
        } else {
            ll to = uf.siz[i];
            to *= (ll)st.size();
            ans += to;
        }
    }
    cout << ans - n << endl;
}


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

long long n, m, q;
vector<vector<long long> > as;
long long ans;

void dfs() {
  queue<vector<long long> > que;
  vector<long long> initV;
  initV.push_back(1);
  que.push(initV);

  while(!que.empty()) {
    vector<long long> curr = que.front();
    que.pop();
    if (curr.size() == n) {
      long long now = 0;
      for (int i = 0; i < as.size(); i++) {
        if (curr[as[i][1]-1] - curr[as[i][0]-1] == as[i][2]) now += as[i][3];
      }
      ans = max(ans, now);
      continue;
    }

    for (int i = 0; i + curr.back() <= m; i++) {
      vector<long long> next(curr.size());
      copy(curr.begin(), curr.end(), next.begin());
      next.push_back(curr.back() + i);
      que.push(next);
    }
  }
}

void solver() {
  cin >> n >> m >> q;

  for (int i = 0; i < q; i++) {
    vector<long long> a(4);
    cin >> a[0];
    cin >> a[1];
    cin >> a[2];
    cin >> a[3];
    as.push_back(a);
  }

  dfs();
  cout << ans << "\n";
}

int main() {
  solver();
}


Measured memory_bytes: 9380
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <type_traits>
#include <vector>

using namespace std;

static int comp_count = 0;

#define NDEBUG 1

#ifndef NDEBUG
#define _DBG 1
#include <stdio.h>
#else
#define _DBG 0
#endif

#define DbgP(fmt, ...) \
    do { if (_DBG){ fprintf(stderr, fmt, __VA_ARGS__); }} while (0)

#define DbgFunc(fmt, ...) \
    do { if (_DBG){ fprintf(stderr, "%s(", __FUNCTION__); fprintf(stderr, fmt, __VA_ARGS__); fputs(")\n", stderr); }} while (0)

template<typename R, typename A>
void merge(int left, int left_last, int right_last, R ar, A tmp){
    int right = left_last + 1;
    int n = right_last - left + 1;
    int t = left;
    int c = left;
    DbgFunc("%d,%d,%d,%d", left, left_last, right, right_last);

    while (left <= left_last && right <= right_last) {
        if(ar[left] <= ar[right]){
            tmp[t] = ar[left];
            left++;
        }else{
            tmp[t] = ar[right];
            right++;
        }
        t++;
    }

    while (left <= left_last) {
        tmp[t++] = ar[left++];
    }
    while (right <= right_last) {
        tmp[t++] = ar[right++];
    }

    for (int i = 0; i < n; i++) {
        ar[right_last] = tmp[right_last];
        right_last--;
    }

    comp_count += t - c;
}

template<typename R, typename A>
void m_sort(int left, int right, R ar, A tmp){
    if(left < right){
        int mid = (left + right) / 2;
        
        m_sort(left, mid, ar, tmp);
        m_sort(mid + 1, right, ar, tmp);

        merge(left, mid, right, ar, tmp);
    }
}

template<typename T>
void merge_sort(T begin, T end){
    if(begin < end){
        int n = end - begin;
        auto tmp = new typename decay<decltype(*begin)>::type[n];
        m_sort(0, end - begin - 1, begin, tmp);
    }
}

int ar[500000];

int main(int argc, char const* argv[])
{
    int n;

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

    merge_sort(ar, ar + n);

    for (int i = 0; i < n - 1; i++) {
        printf("%d ", ar[i]);
    }
    printf("%d\n", ar[n - 1]);
    printf("%d\n", comp_count);

    return 0;
}

Measured memory_bytes: 6520
#include <stdio.h>

int max(int a[],int n)
{
	int ans = a[0];
	
	for(int i = 1; i < n; i++){
		if(a[i] > ans){
			ans = a[i];
		}
	}
	return ans;
}

int sum(int a[],int n){
	int ans = 0;
	
	for(int i = 0; i < n; i++){
		ans += a[i];
	}
	
	return ans;
}

int main(void)
{
	int n;
	scanf("%d",&n);
	int l[n];
	
	for(int i = 0; i < n; i++){
		scanf("%d",&l[i]);
	}
	
	int saidai = max(l,n);
	
	int total = sum(l,n);
	
	if(saidai < total - saidai){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}
	
	
	
	

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli; 
string s;
lli a,b,c,t,temp1,temp2,x,y,temp,q,d,k,mod=1e9+7;

bool is(int i,int j)
{
	string one="",two="";
	
	for(int a=i;a<=j;a++)
	{
		one+=s[a];
		two+=s[a];
	}
	
	reverse(two.begin(),two.end());

	if(one==two)return true;
	return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	cin>>s;
	lli len=s.length();
	s="0"+s;
	
	if(is(1,len)&&is(1,(len-1)/2)&&is((len+3)/2,len))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 3644
while True:
    a,b = map(int,input().split())
    if a == 0 and b == 0: break
    for i in range(a):
        for j in range(b):
            if j == 0 or j == b-1 or i == 0 or i == a -1:
                print(r"#",end="")
            else:
                print(r".",end="")
        print()
    print("")



Measured memory_bytes: 7000
#import sys

#input = sys.stdin.readline

#import heapq

def main():
#    h,w,a,b = map(int, input().split())
    n = int(input())
    if n%2==0:
        print("0.5")
    else:
        print((1/n)*(n//2+1))

#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <random>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define pi 3.141592653589793
#define prique priority_queue
constexpr auto mod=1000000007;
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int n){
    int cnt=0;
    for(int i=1;i<=sqrt(n);i++){
        if(n%1==0)cnt++;
    }
    if(cnt!=1) return false;
    else return n!=1;
}
struct UnionFind{
    vector<int> r;
    UnionFind(int N){
        r=vector<int>(N,-1);
    }
    int root(int x){
        if(r[x]<0) return x;
        return r[x]=root(r[x]);
    }
    bool unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(r[x]>r[y]) swap(x,y);
        r[x]+=r[y];
        r[y]=x;
        return true;
    }
    int size(int x){
        return -r[root(x)];
    }
};
vector<int> v;
int n,m,cnt=0,ans=0,aa[220000],ab[220000];
pair<int,int> pp[220000];
string s,ss[220000];
queue<int> que;
signed main(){
    cin>>n>>m;
    cout<<abs(n-2)*abs(m-2);
}

Measured memory_bytes: 10576
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, BufWriter, Write};

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>,
}

impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scan = Scanner::default();
    let out = &mut BufWriter::new(stdout());

    let a :i32 = scan.next();
    let b :i32 = scan.next();
    if a < b {
        writeln!(out, "a < b").ok();
    } else if a > b {
        writeln!(out, "a > b").ok();
    } else {
        writeln!(out, "a == b").ok();
    }
}



Measured memory_bytes: 5032
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

int main(){
    int N,D,ans=0;
    cin>>N>>D;
    while(N>0){
        ans++;
        N=N-(2*D+1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
    char s[4];

    scanf("%s",s);

    for (int i = 0; i < 3; i++)
    {
        s[i]=(s[i]=='1')? '9':'1';
    }

    printf("%s",s);

    return 0;
}

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

int check(long long int n,long long int x,long long int y){
	long long int a,b;//分子、分母
	a=4*x-n,b=n*x;
	if(a<=0)return -1;
	a=a*y-b,b*=y;
	if(a<=0)return -1;
	if(b%a==0)return b/a;
	else return -1;
}

int main(){
	long long int n;
	long long int a,b,c;
	long long int i,j,k;
	cin>>n;
	a=n/4;
	if(a<1)a=1;
	for(i=a;i<=3500;i++){
		for(j=a;j<3500;j++){
			k=check(n,i,j);
			if(k!=-1){
				cout<<i<<" "<<j<<" "<<k<<" "<<endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

void
solve() {
  int n;
  string s;
  cin>>n;
  cin>>s;

  int ans = 0;
  int start = 0;
  while (1) {
    auto p = s.find("ABC", start);
    if (p == string::npos) break;
    
    start = p + 1;
    ans++;
  }

  cout<<ans<<endl;
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int K, N, ans = 0;
    cin >> K >> N;
    vector<int> A(N);
    priority_queue<int> B;
    for(int i = 0; i < N; ++i){
        cin >> A.at(i);
        if(i == 0) continue;
        else{
            B.push(A.at(i) - A.at(i - 1));
            if(i == N - 1) B.push((K - A.at(N - 1)) + A.at(0));
        }
    }
    for(int i = 0; i < N; ++i){
        if(i == 0)B.pop();
        else{
            ans += B.top();
            B.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>
int main (){
	int a,b,c;
	scanf ("%d",&a);
	scanf ("%d",&b);
	scanf ("%d",&c);
	if (a==c && a!=b && b!=c || a==b && a!=c && b!=c || b==c && a!=b && a!=c){
		printf ("Yes");	
	}
	else if (a==b && b==c && a==c) {
		printf ("No");
	}
	else if (a!=b && b!=c && a!=c){
		printf ("No");
	}
	return 0;
}

Measured memory_bytes: 2104