akhauriyash/Code-Regression huggingface dataset:
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
#endif
    crap;

    int k;
    cin >> k;

    int a, b;
    cin >> a >> b;

    double l = a / k;
    double r = b / k;

    if (r - l >= 1.00 or !(a % k) or !(b % k))
        cout << "OK";
    else {
        cout << "NG" << endl;
    }

    return 0;
}

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

int n, a[50];

bool solve(int i, int m) {
    if (m == 0) return true;
    if (i >= n) return false;
    bool res = solve(i + 1, m) || solve(i + 1, m - a[i]);
    return res;
}

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

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int m;
        cin >> m;
        if (solve(0, m))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}


Measured memory_bytes: 3084
if __name__ == '__main__':

	ans = []
	while True:
		try:
			n,b = input().split(",")
			ans.append(b)
		except EOFError:
			break

	print(ans.count("A"))
	print(ans.count("B"))
	print(ans.count("AB"))
	print(ans.count("O"))



Measured memory_bytes: 5556
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
int dp[100100];
bool vis[100100];
 
int dfs(vector<vector<int>>& adj, int node) {
	if (vis[node]) return dp[node];
	if (adj[node].size() == 0) {
		dp[node] = 0;
		vis[node] = true;
		return 0;
	}
 
	int maxChild = 0;
	for (int child : adj[node]) {
		maxChild = max(maxChild, dfs(adj, child));
	}
 
	dp[node] = max(dp[node], maxChild + 1);
	vis[node] = true;
 
	return dp[node];
}
 
int main() {
	int n, m;
	cin >> n >> m;
 
	memset(dp, 0, sizeof(dp));
	memset(vis, false, sizeof(vis));
 
	vector<vector<int>> adj(n);
 
	for (int i = 0; i < m; i++) {
		int from, to;
		cin >> from >> to;
 
		adj[--from].push_back(--to);
	}
 
	int maxLen = 0;
	for (int i = 0; i < n; i++) {
		maxLen = max(maxLen, dfs(adj, i));
	}
 
	cout << maxLen;
 
	return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int, int> P;

template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    A.erase(unique(A.begin(), A.end()), A.end());

    int count = 1;
    for (int i = 2; i < A.size(); i++) {
        if (A[i - 2] < A[i - 1] && A[i - 1] > A[i]) {
            count++;
            i++;
        }
        else if (A[i - 2] > A[i - 1] && A[i - 1] < A[i]) {
            count++;
            i++;
        }
    }
    cout << count << endl;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int ans = 0;
  for(int i=1; i<n-1; i++) {
    vector<int> s = {p[i-1], p[i], p[i+1]};
    sort(s.begin(), s.end());
    if (p[i] == s[1]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  int a, b;
  int sum = 0;
  rep(i, n) {
    cin >> a >> b;
    sum += b - a + 1;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
s = input()
count_a = s.count('a')
count_b = s.count('b')
count_c = s.count('c')
if abs(count_a - count_b) <= 1 and abs(count_b - count_c) <= 1 and abs(count_c - count_a) <= 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,a,b;
    cin>>n>>a>>b;
    deque<int> ans;
    for(int i=1;i<=a;i++) ans.push_back(i);
    if(b-1+a>n||1LL*a*b<n)
        print(-1);
    else{
        vi sz(b-1,1);
        int tot=b-1+a;
        for(int i=0;i<b-1;i++)
        {
            while(sz[i]<a&&tot<n)
            {
                tot++;
                sz[i]++;
            }
        }
        assert(tot==n);
        int p=a+1;
        for(int i=0;i<b-1;i++)
        {
            vi tmp;
            for(int j=0;j<sz[i];j++)
            {
                tmp.push_back(p);
                p++;
            }
            while(!tmp.empty())
            {
                ans.push_front(tmp.back());
                tmp.pop_back();
            }
        }
        vi op;
        while(!ans.empty())
        {
            op.push_back(ans.front());
            ans.pop_front();
        }
        print(op);
    }
}

Measured memory_bytes: 5140
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>

using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    map<char, char> m1;
    map<char, char> m2;
    for (int i = 0; i < S.size(); ++i) {
        auto next = m1.find(S[i]);
        if (next != m1.end() && next->second != T[i]) {
            cout << "No" << endl;
            return 0;
        } else {
            m1.insert(make_pair(S[i], T[i]));
        }
        next = m2.find(T[i]);
        if (next != m2.end() && next->second != S[i]) {
            cout << "No" << endl;
            return 0;
        } else {
            m2.insert(make_pair(T[i], S[i]));
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 904
// 写経
#include <bits/stdc++.h>

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

map<pair<string, string>, ll> a;
ll res = 0;
int n;
string s;
int main()
{
	cin >> n;
	cin >> s;

	rep(i, 1<<n) {
		string x, y;
		rep(j,n){
			(i>>j&1 ? x : y).push_back(s[j]);
		}
		a[{x,y}]++;
	}

	rep(i, 1<<n) {
		string x, y;
		rep(j,n) (i>>j&1 ? x : y).push_back(s[n+j]);
		string l = y, r = x;
		reverse(l.begin(),l.end());
		reverse(r.begin(),r.end());
		res += a[{l,r}];
	}
	cout << res << endl;
}


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

int main()
{
  
  #ifndef ONLINE_JUDGE
freopen("finput.txt", "r", stdin);
freopen("foutput.txt", "w", stdout);
#else
// online submission
#endif
int n;
cin>>n;
int val=(n-400)/200;
cout<<8-val;





}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

bool solve(vector<ll> a, ll n){
	if (a[n] == 1) { return false; }
	if (a[1] == 0) { return false; }
	repn(i, n - 1) { if (a[i] != a[n - i]) { return false; } }
	return true;
}



int main() {

	string s;
	cin >> s;
	ll n = s.size();

	vector<ll> a(n + 1);
	repn(i, n) a[i] = s[i - 1] - '0';

	if (!solve(a, n)) { cout << -1; }

	else {

		ll K = n;

		for (ll i = n - 1; i > 0; i--) {
			cout << K << " " << i<<endl;
			if (a[i] == 1) { K = i; }
		}

	}
	
	system("PAUSE");

}





Measured memory_bytes: 2664
#include <iostream>
using namespace std;
using ll = long long;

int main()
{
  int k;
  string s;
  cin >> k;
  cin >> s;
  if(s.length() <= (size_t)k) cout << s << endl;
  else cout << s.erase(k) + "..." << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main()
{
	int N,T,c[105],t[105];
	cin>>N>>T;
	for(int i=0;i<N;i++)
		cin>>c[i]>>t[i];
	int m=100000;
	for(int i=0;i<N;i++){
		if(t[i]<=T && c[i]<m)
			m=c[i];
	}
	if(m==100000) cout<<"TLE"<<endl;
	else cout<<m<<endl;
}

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

int M, T, P, R;
int wa[55][15]; // team, pena
int solved[55];
int pena[55];

bool cmp(int i, int j) {
    return make_pair(make_pair(-solved[i], pena[i]), -i) < make_pair(make_pair(-solved[j], pena[j]), -j);
}

bool equal(int i, int j) {
    return make_pair(-solved[i], pena[i]) == make_pair(-solved[j], pena[j]);
}

int main() {
    while (cin >> M >> T >> P >> R) {
        if (T == 0) break;
        memset(wa, 0, sizeof(wa));
        memset(solved, 0, sizeof(solved));
        memset(pena, 0, sizeof(pena));
        for (int i = 0; i < R; ++i) {
            int m, t, p, j; cin >> m >> t >> p >> j; --t;
            if (j == 0) {
                ++solved[t];
                pena[t] += m + wa[t][p];
            }
            else {
                wa[t][p] += 20;
            }
        }
        
        vector<int> vec(T);
        for (int i = 0; i < T; ++i) vec[i] = i;
        sort(vec.begin(), vec.end(), cmp);
        for (int i = 0; i < T; ++i) {
            if (i > 0) {
                if (equal(vec[i-1], vec[i])) cout << "=";
                else cout << ",";
            }
            cout << vec[i] + 1;
        }
        cout << endl;
    }
}


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

using namespace std;

const int m = 1000;
vector<int> counts(m + 1);
const int mod = pow(10, 9) + 7;

void countDivisors(int n) {
  if (n <= 1) {
    return;
  }
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      n /= i;
      counts[i]++;
    }
  }
  if (n > 1) {
    counts[n]++;
  }
}

int main() {
  int x;
  cin >> x;
  for (int i = 2; i <= x; i++) {
    countDivisors(i);
  }
  long long r = 1;
  for (int i = 2; i <= m; i++) {
    r *= (counts[i] + 1);
    r %= mod;
  }
  cout << r << endl;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll x, y; cin >> x >> y;
	ll cnt = 0;
	while (x <= y) {
		cnt++;
		x *= 2;
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

#define fr(i,b,e) for(int i=(b); i!=(e); ++i)
#define rp(i,e) for(int i=0; i!=(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long ll;
const int INF=1000000;
const int MOD=998244353;


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int out=0;

    out+=(n/500)*1000;
    n%=500;
    out+=(n/5)*5;
    cout << out << "\n";
}   

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N;
	cin >> N;
	vector<string> s(N);
	REP(i, N) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	sort(s.begin(), s.end());
	ll left = 0;
	ll right = 1;
	ll res = 0;
	while (left < N) {
		if (right == N || s[left] != s[right]) {
			res += (right - left)*(right - left - 1) / 2;
			left = right;
		}
		right++;
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
#define mp make_pair
typedef pair<int,int> pii;//Be careful in topcoder.

#define MAX_H 300
#define MAX_W 300

int v[MAX_H*MAX_W];
pair<int,int> crd[MAX_H*MAX_W];

int main(){
	int h,w,d;
	scanf("%d %d %d",&h,&w,&d);
	for(int x=0;x<h;++x) for(int y=0;y<w;++y){
		int a;
		scanf("%d",&a);
		crd[--a]=mp(x,y);
	}
	for(int a=0;a<h*w;++a){
		if(a>=d) v[a]=v[a-d]+abs(crd[a].fi-crd[a-d].fi)+abs(crd[a].sc-crd[a-d].sc);
		else v[a]=0;
	}
	int Q;
	scanf("%d",&Q);
	for(;Q>0;--Q){
		int l,r;
		scanf("%d %d",&l,&r);
		printf("%d\n",v[--r]-v[--l]);
	}
}

Measured memory_bytes: 2176
fn main() {
    let stdin = std::io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let n: usize = buf.trim().parse().unwrap_or(0);

    let mut dll = Vec::new();

    let mut head = 0;

    for _ in 0..n {
        //println!("{:?}",dll);
        let mut buf = String::new();
        stdin.read_line(&mut buf).ok();
        let vec: Vec<&str> = buf.split_whitespace().collect();

        if vec[0] == "insert" {
            dll.push(vec[1].parse().unwrap_or(0));
        } else if vec[0] == "delete" {
            for j in (head..dll.len()).rev() { 
                if vec[1].parse().unwrap_or(0) == dll[j] { 
                    dll.remove(j); 
                    break; 
                } 
            }
        } else if vec[0] == "deleteFirst" {
            dll.pop();
        } else if vec[0] == "deleteLast" {
            head += 1;
        }
    }
    for i in (head..dll.len()).rev() {
        print!("{}", dll[i]);
        if i == head {
            break;
        }
        print!(" ");
    }
    println!();
}



Measured memory_bytes: 9952
def func(n):
    ans = 0
    for s in str(n):
        ans += int(s)
    return ans


def main():
    n, a, b = map(int, input().split())

    ans = 0
    for i in range(1, n + 1):
        r = func(i)
        if a <= r <= b:
            ans += i

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n,m,v,p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = [0]*(n+1)
for i in range(n):
  b[i+1] = b[i] + a[i]

def judge(x):
  if x >= n-p: return True
  if a[x] + m < a[n-p]: return False
  safe = m*(n-1) + a[x]*(n-p-x) - b[n-p+1] + b[x+1]
  return safe >= m*(v-1)

ok = n-p
ng = -1
while ok-ng > 1:
  mid = (ok+ng)//2
  if judge(mid):
    ok = mid
  else:
    ng = mid
print(n-ok)


Measured memory_bytes: 14964
def array_integer(a)
	0.upto(a.count) {|x|
		a[x] = a[x].to_i
	}
	return a
end

n = STDIN.gets
n = n.to_i

nums = STDIN.gets.split(" ")
nums = array_integer(nums)

min = nums[0]
max = nums[0]
sum = 0

0.upto(n - 1) {|x|
	sum += nums[x]
	min = nums[x] if min > nums[x]
	max = nums[x] if max < nums[x]
}

print min, " ", max, " ", sum, "\n"



Measured memory_bytes: 8860
N = int(input())
p = list(list(map(int,input().split()))for i in range(N))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        x1,y1 = p[i]
        x2,y2 = p[j]
        ans += ((x1-x2)**2 + (y1 - y2)**2)**0.5
rate = 0
for i in range(N):
    rate += i
rate /= N-1
print(ans/rate)

Measured memory_bytes: 3188
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int A,B,C,D;
	cin>>A>>B>>C>>D;
	
	cout<<min(A,B)+min(C,D)<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
	char c;
	cin>>c;
	if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o') cout<<"vowel"<<endl;
	else cout<<"consonant"<<endl;
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}


import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import System.IO
import Control.Monad.State.Strict

patties :: Int -> Int
patties level = bit (level+1) - 1

layers :: Int -> Int
layers level = bit (level+2) - 3

bread :: State Int Int
bread = do
  layers <- get
  if layers > 0 then do
    put $ layers - 1
    return 0
  else
    return 0

eat :: Int -> State Int Int
eat 0 = do
  layers <- get
  if layers > 0 then do
    put $ layers - 1
    return 1
  else
    return 0
eat lv = do
  layersToEat <- get
  if layersToEat >= layers lv then do
    put $ layersToEat - layers lv
    return $ patties lv
  else if layersToEat > 0 then do
    bread
    first <- eat (lv - 1)
    second <- eat 0
    third <- eat (lv - 1)
    bread
    return $ first + second + third
  else
    return 0

main :: IO ()
main = do
  [n,x] <- map read . words <$> getLine
  print $ evalState (eat n) x 

Measured memory_bytes: 508
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
	string s;
	cin>>s;
	int  sum=0;
	int n=s.size();
	if(s[0]==s[n-1]) sum=n-1;
	else sum=n;
	if(sum%2==1) cout<<"First"<<endl;
	else cout<<"Second"<<endl; 
 } 

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define         MAX         262144
//   cout<<std::setprecision(12)<<

int main()
{
     int i,j,k,l,m,n,ans,fin=0,st;

     cin >> n >> k;

     int ar[n+10];

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

     int cnt[n+10];

     cnt[0] = ar[0];

     for(i=1;i<n;i++)
     {
         cnt[i] = cnt[i-1] + ar[i];
     }

     fin = cnt[k-1];
     st = 0;
     for(i=1;i<=n-k;i++)
     {
        ans = cnt[i+k-1] - cnt[i-1];

        if(ans > fin)
        {
            fin = ans;
            st = i;
        }
     }
     double keba,tad=0.0;
     for(i=st;i<st+k;i++)
     {
         l = ar[i];
         l = (l*(l+1))/2;
         keba = double(l)/double(ar[i]);
         tad += keba;
     }
     cout<<std::setprecision(12)<<tad<<endl;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

string s;

int main() {
  cin >> s;

  for (int i = 0; i < (1 << 3); i++) {
    int cal = s[0] - '0';
    for (int j = 1; j < s.size(); j++) {
      if ((i >> (j - 1)) % 2 == 1) {
        cal += s[j] - '0';
      } else {
        cal -= s[j] - '0';
      }
    }

    if (cal == 7) {
      cout << s[0];
      for (int j = 1; j < s.size(); j++) {
        if ((i >> (j - 1)) % 2 == 1) {
          cout << "+" << s[j];
        } else {
          cout << "-" << s[j];
        }
      }
      cout << "=7" << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G(a)((c=A[a]+A[P[a]]+C[a])%k?c:0)
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
    d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;}
//L K(L f){p=X[f];n=X[b];return p-n?E[p]<E[n]?swap(f,b),p=n:0,M(O[f])-M(O[p])+G(p)+K(P[p]):abs(M(O[f])-M(O[b]));}
L K(L f){p=X[f];n=X[b];return p-n?M(O[E[p]<E[n]?p=n,a=b,b=f,a:f])-M(O[p])+G(p)+K(P[p]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(b=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!b|a;S(a=H[a],O[a]=b++))X[a]=p;
       for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

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

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

int main(){
    int N,M;
    cin >> N >> M ;
    int c[M],cp[N];
    int ans=N;
    int a[N][M];
    rep(i,N){
        rep(j,M){
            cin >> a[i][j]; 
        }
    }
    rep(i,M) c[i]=1;

    rep(i,M-1){
        rep(i,N) cp[i]=1;    
            int p_num[M];
            rep(k,M) p_num[k]=0;
            rep(j,M){
                rep(k,N){
                    if(cp[k]&&c[a[k][j]-1]){
                    cp[k]=0;
                    p_num[a[k][j]-1]++;
                }
            }
        }
        int maxm=0,max=0;
        rep(j,M){// cout << p_num[j] << ":" <<endl; 
        if(p_num[j] > max){ maxm=j; max = p_num[j];}}
        //cout << "max: "<< max << endl;
        if(ans > max) ans = max;
        c[maxm]=0;
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    int ans = 0;
    for(int i=0; i<K; i++) ans += A[i];
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  ll n;
  cin >> n;
  vector<ll> v(n);
  rep(i,n)cin >> v[i];
  vector<ll> dp(n+1,0);
  dp[0] = 1000;
  for(int i = 1;i <= n;i++){
    dp[i] = dp[i-1];
    for(int j = 1;j < i;j++){
      dp[i] = max(dp[i],dp[j]+(v[i-1]-v[j-1])*(dp[j]/v[j-1]));
    }
  }
  cout << dp[n] << endl;
  
  

  return 0;
}

Measured memory_bytes: 3624
<?php
fscanf(STDIN, "%d %d %d", $A, $B, $K);
if($K<$A){
    $a = $A - $K;
}else{
    $a = 0;
}
if($a == 0){
    $b = $B - ($K - $A);
}else{
    $b = $B;
}
if($b < 0){
    $b = 0;
}

echo $a." ".$b;
?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int A,B,C,D,E,F;cin>>A>>B>>C>>D>>E>>F;
    int resx=0,resy=0;
    double buf=-1;
    for(double a=0;a*A*100<=F;a++){
        for(double b=0;(b*B+a*A)*100<=F;b++){
            for(double c=0;(a*A+b*B)*100+c*C<=F;c++){
                for(double d=0;(a*A+b*B)*100+c*C+d*D<=F;d++){
                    if((c*C+d*D)<=E*(a*A+b*B))if(chmax(buf,(c*C+d*D)/(a*A+b*B))){resx=(a*A+b*B)*100+c*C+d*D;resy=c*C+d*D;}
                }
            }
        }
    }
    cout<<resx<<" "<<resy<<endl;
}

Measured memory_bytes: 256
a,b = map(int,input().split())
l = []
k = []
s = 0
aa = 1000000000
for i in range(a):
    l.append(b+i)
m = sum(l)
for i in l:
    if abs(i)<aa:
        aa = abs(i)
        s = i

print(sum(l)-s)


Measured memory_bytes: 3060
import bisect
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [sum(A[:i]) for i in range(N + 1)]
sum_A = [S[r] - S[l] for l in range(N + 1) for r in range(l + 1, N + 1) if r != l]
sum_A.sort()

def f(m, A):
    if m < 0:
        return 0

    T = len(A)
    M = pow(2, m)
    r = bisect.bisect_left(A, M)
    num = T - r
    if num < K:
        return f(m - 1, sorted([a % M for a in A]))
    else:
        return M + f(m - 1, sorted([a % M for a in A[r:]]))

print(f(len(bin(sum_A[-1])) - 2, sum_A))


Measured memory_bytes: 59592
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

// const ll INF = 1LL << 60;

int N, W;
vector<ll> weight, value;

int main()
{
  cin >> N >> W;
  weight.resize(N);
  value.resize(N);
  for (int i = 0; i < N; i++)
  {
    cin >> weight[i] >> value[i];
  }

  // dp[i][w]: i番目(0-index)までの品物の中から、重さの総和がw以下である時の価値の総和の最大値
  vector<vector<ll>> dp(N, vector<ll>(W + 1, 0));

  for (int w = 0; w <= W; w++)
  {
    if (w >= weight[0])
    {
      dp[0][w] = value[0];
    }
  }

  for (int i = 1; i < N; i++)
  {
    for (int w = 0; w <= W; w++)
    {
      if (w >= weight[i])
      {
        chmax(dp[i][w], dp[i - 1][w - weight[i]] + value[i]);
      }
      chmax(dp[i][w], dp[i - 1][w]);
    }
  }

  cout << dp[N - 1][W] << endl;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------
#define bitrep(i, n)     for(ll i=0; i<(ll) (1<<n); i++)
#define bis(i, j)        i & (1<<j)

int main(void) {
  int n;
  cin >> n;
  arr(a,n);

  vec num(100002, 0);
  rep(i,n){
    num[(a[i]+1)-1]++;
    num[(a[i]+1)]++;
    num[(a[i]+1)+1]++;
  }
  int ans=0;
  rep(i,100002){
    chmax(ans, num[i]);
  }

  prt(ans);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
//#define ull unsigned  long  long
#define int long long int
#define lld long double
#define endl "\n"
#define S second
#define F first
#define pir      pair<int,int>
#define vtr      vector<int>
#define mpp      map<int,int>
#define pb       push_back
#define popb     pop_back()
#define mk       make_pair
#define stc      set<char>
#define st       set<int>
#define stk      stack<int>
#define ctn      continue
#define MOD      1000000007
#define fr(i,a,b)   for(int i=a;i<b;i++)
#define rfr(i,a,b)  for(int i=a-1;i>=b;i--)
#define must        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int lcm(int a, int b)
{
    return (a*b)/gcd(a, b);
}

int myfun(int x,int y)
{
    return x*y;
}
void primeFactors(int n)
{
    while (n%2 == 0)
    {
        cout<<2<<endl;
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            cout<<i<<endl;
            n = n/i;
        }
    }
    if (n > 2)
        cout<<n<<endl;
}

void fillPrefixSum(int a[], int N, int prefixSum[])
{
    prefixSum[0] = a[0];

    for (int i = 1; i < N; i++)
        prefixSum[i] = prefixSum[i-1] + a[i];
}
int is_sorted(int a[],int n)
{
    for(int i=0;i<n-1;i++)
    {
        if(a[i]>a[i+1])
            return false;
    }
    return true;
}

int factorial(int n)
{
    return (n==1 || n==0) ? 1: n * factorial(n - 1);
}

int findlcm(vtr a, int n) 
{ 
    // Initialize CNTult 
    int cnt = a[0]; 
  
    // cnt contains LCM of a[0], ..a[i] 
    // after i'th iteration, 
    for (int i = 1; i < n; i++) 
        cnt = (((a[i] * cnt)) / 
                (gcd(a[i], cnt))); 
  
    return cnt; 
} 



int power(int x,  int y, int p)
{
    int CNT = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            CNT = (CNT*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return CNT;
}

bool peli(string s)
{
    int right=s.length();
    int j;
    for(int i=0,j=right-1;i<=j;i++,j--)
    {
        if(s[i]!=s[j])
        {
            return false;
        }
    }
    return true;
}


void Solve1()
{
    int n;
    cin>>n;
    int cnt=0;
    int flag=0;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a==b)
        {
            cnt++;
            if(cnt>=3)
            {
                flag=1;
            }
        }
        else
        {
            cnt=0;
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else
    {
        cout<<"No"<<endl;
    }
}


signed main()
{

    must;
    int tt=1;
    //cin >> tt;
    while(tt--)Solve1();
    //double ttt;
    //ttt=double(e-s)/double(CLOCKS_PER_SEC);
    //cout<<fixed<<ttt<<setprecision(5)<<endl;
    return 0;
}


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

vector<int> adj[100010];
bool vis[100010];
vector<int> sorted;
int DP[100010];
int n,m;

void topovisit(int u)
{
	vis[u]=1;
	for (int i=0;i<adj[u].size();i++)
	{
		int v=adj[u][i];
		if (!vis[v])
		 topovisit(v);
	}
	sorted.push_back(u);
}

void SORT()
{
	for (int i=1;i<=n;i++)
	{
		if (!vis[i])
	  	 topovisit(i);
	  	DP[i] = 0;
	}
	reverse(sorted.begin(),sorted.end());
	return;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for (int i = 1 ; i <= m ; i ++)
	{
		int a,b;
		cin >> a >> b;
		adj[a].push_back(b);
	}
	SORT();
	int ans = 0;
	for (int i = 0 ; i < n ; i++)
	{
		for (int j = 0 ; j < adj[sorted[i]].size() ; j++)
		{
			DP[adj[sorted[i]][j]] = max(DP[adj[sorted[i]][j]],DP[sorted[i]] + 1);
		}
	}
	for (int i = 1 ; i <= n ; i++)
		ans = max(ans,DP[i]);
	cout << ans << endl;
}

Measured memory_bytes: 8056
#include<stdio.h>
int main(void)
{
	int n,x,a[100],y,b[100],z,c,cnt,i,j,k;
	cnt=0;
	scanf("%d %d",&n,&x);
	for(i=0;i<x;i++){
		scanf("%d",&a[i]);
	}
	scanf("%d",&y);
	for(i=0;i<y;i++){
		scanf("%d",&b[i]);
	}
	scanf("%d",&z);
	for(i=0;i<z;i++){
		scanf("%d",&c);
		cnt++;
		for(j=0;j<x;j++){
			if(c==a[j]){
				cnt--;
		       for(k=0;k<y;k++){
			      if(c==b[k]){
				cnt++;
			     }
		       } 
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 10000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
void allcout(auto V) {
    for(auto x : V) cout << x << ' ';
    cout << endl;
}

int factorial[200010];
void init(int mm) {
    factorial[0] = 1;
    rep(i, 200010) factorial[i + 1] = factorial[i] * (i + 1) % mm;
}
int extgcd(int a, int b, int &x, int &y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}
int mod_inverse(int a, int mm) {
    int x, y;
    extgcd(a, mod, x, y);
    return (mod + x % mm) % mm;
}
int combination(int m, int n, int mm) {
    return factorial[m] * mod_inverse(factorial[n], mm) % mm * mod_inverse(factorial[m - n], mm) % mm;
}

signed main() {
    init(mod);
    int n, k;
    cin >> n >> k;
    //0が0個以上min(n-1,k)個以下の物はすべて行ける
    int m = min(n - 1, k);
    int ans = 0;
    for(int i = 0; i <= m; i++) {
        int c = n - i;
        ans = (ans + combination(n, i, mod) * combination(n - 1, c - 1, mod) % mod) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        int now=0;
        int out_cnt=0;
        int base=0; 
        int point=0;
        while(now<n){
        	String line2 = br.readLine();
        	if(line2.equals("HIT")){
        		base++;
        		if(base>3){
        			point++;
        			base--;
        		}
        	}else if(line2.equals("OUT")){
        		out_cnt++;
        		
        	}else if(line2.equals("HOMERUN")){
        		point+=base+1;
        		base=0;
        	}
        	if(out_cnt>=3){
        		now++;
        		base=0;
        		out_cnt=0;
        		System.out.println(point);
        		point=0;
        	}
        }

    }
}

Measured memory_bytes: 24276
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            
          total = 500*a+100*b+50*c
          if total == X:
            count += 1
        
        
print(count)



Measured memory_bytes: 2940
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

LL nC2(LL n){
    return n*(n-1)/2;
}

int main() {
    LL n;
    vector<LL> a;
    LL tmp_a;
    vector<LL> multi_bin_n;
    vector<LL> multi_bin_v;
    LL tmp_ans;
    LL ans;

    cin >> n;
    vector<int> bin(n, 0);
    for(int i=0; i<n; i++){
        cin >> tmp_a;
        tmp_a--;
        a.push_back(tmp_a);
        bin[tmp_a]++;
    }

    tmp_ans=0;
    for(int i=0; i<n; i++){
        tmp_ans+=nC2(bin[i]);
    }
    //cout << tmp_ans << endl;

    for(int i=0; i<n; i++){
        ans=tmp_ans;
        ans-=nC2(bin[a[i]]);
        bin[a[i]]--;
        //cout << bin[a[i]] << " " << ans << endl;
        ans+=nC2(bin[a[i]]);
        bin[a[i]]++;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 5104
N, K = map(int, input().split())
D = list(map(str, input().split()))
num_set = set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
N_list = list(str(N))

diff_list = sorted(list(num_set.difference(set(D))))

if (list(set(D)&set(N_list)) == []):
    print(N)
else:
    if '0' in diff_list:
        n_list = [diff_list[1]] + ['0']*len(N_list)
    else:
        n_list = [diff_list[0]]*(len(N_list)+1)
    str_n = ''
    for i in n_list:
        str_n += str(i)
    new_n = int(str_n)+1
    for ii in range(N, new_n):
        if list(set(list(str(ii)))&set(D)) == []:
            print(ii)
            break

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<queue>
#include<memory.h>
#include<cstdio>
#include<utility>
#include<algorithm>
#define mp make_pear
#define pd push_bake
#include<bitset>
#include<cassert>
#include<climits>
#include<complex>
#include<stack>
#include<numeric>
#include<memory>
#include<functional>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<stack>
using namespace std;
int a,b,c,d,a1,b1,c1,d1; 
string s;
int main(){
	cin>>s;
    a1=a=s[0]-'0';
    b1=b=s[1]-'0';
    c1=c=s[2]-'0';
    d1=d=s[3]-'0';
    for(int i=0;i<=1;i++){
    	b=-b;
    	for(int j=0;j<=1;j++){
    		c=-c;
    		for(int f=0;f<=1;f++){
    			d=-d;
    	        if(a+b+c+d==7){
    	        	cout<<a;
    	        	if(i)cout<<"+"<<b1;
    	        	else cout<<"-"<<b1;
    	        	if(j)cout<<"+"<<c1;
    	        	else cout<<"-"<<c1;
    	        	if(f)cout<<"+"<<d1<<"=7\n";
    	        	else cout<<"-"<<d1<<"=7\n";
    	        //	cout<<s;
    	        	return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int count = 0;
  for(int i=0; i<S.size()/2;i++){
    if(S[i] != S[S.size()-1-i]) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $n);

$taro = 0;
$hanako = 0;
for ($i = 0; $i < $n; $i++) {
    $line = trim(fgets(STDIN));
    $animals = explode(' ', $line);

    if ($animals[0] > $animals[1]) {
        $taro += 3;
    } elseif ($animals[0] < $animals[1]) {
        $hanako += 3;
    } else {
        $taro++;
        $hanako++;
    }
}

printf("%d %d\n", $taro, $hanako);

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

int main() {
	int x, y, r, W, H;

	cin >> W >> H >> x >> y >> r;

	if (x - r < 0 || y - r < 0 || x + r > W || y + r > H) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;

}


Measured memory_bytes: 3088
package main

import "fmt"

func main() {
	nums := []int{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
	var K int
	fmt.Scan(&K)
	fmt.Print(nums[K-1])
}


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

typedef long long ll;
 
bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.second < b.second;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > list(M);
  for (int i = 0; i < M; i++) {
    cin >> list[i].first >> list[i].second;
  }

  sort(list.begin(), list.end(), cmp);

  int cnt = 0;
  int end = 0;
  for (int i = 0; i < list.size(); i++) {
    if (list[i].first >= end) {
      end = list[i].second;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a,b;
  cin>>a>>b;
  vector<ll>vec(a+1);
  for(ll i=0;i<a;i++){
    ll c;
    cin>>c;
    vec.at(c)+=1;
  }
  sort(vec.begin(),vec.end());
  ll d=0;
  ll e=0;
  for(ll i=a;i>=0;i--){
    if(vec.at(i)!=0){
      d+=1;
      e+=vec.at(i);
      if(b==d){
        break;
      }
    }
  }
  cout<<a-e<<endl;
  return 0;
}


Measured memory_bytes: 4820
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//if(strcmp(s[i],"AC")==0)
//if(s[l]=='#')
/*小文字判定
if((moji>= 'a') && (moji<='z')){
    printf("a\n");
    return 0;
  }
  */
//文字列中の一文字⇒数字の時は s[i]-'0'
int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

void swap(long long int *a, long long int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
//swap(&a, &b)

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

long long int cmp( const void *p, const void *q ) {
    return *(long long int*)p - *(long long int*)q;
}//ちいさい順
//qsort(a,n,sizeof(long long int),cmp);


int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);
//char s[n][11]

long long int GCD(long long int a, long long int b){
  long long int L=a,S=b;
  while(1){
    if(S>L){
      L=S+L;
      S=L-S;
      L=L-S;
    }
    if(L%S==0){
      return S;
    }
    L=L%S;
  }
  
}

long long int LCM(long long int a, long long int b){
  return a*b/(GCD(a,b));
}

long long int nCr[3000][3000]={0};
 
long long int combination(long long int n, long long int r)
{
    if (r == 0 || r == n){
      nCr[n][r]=1;
        return (1);
    }
    else if (r == 1){
      nCr[n][r]=n;
        return (n);
    }
  if(nCr[n-1][r-1]==0&&nCr[n-1][r]==0){
    nCr[n-1][r-1]=combination(n - 1, r - 1)%1;
    nCr[n-1][r]=combination(n - 1, r)%1;
    return (nCr[n-1][r-1]+nCr[n-1][r]);
  }
  else if(nCr[n-1][r-1]!=0&&nCr[n-1][r]==0){
    nCr[n-1][r]=combination(n-1,r)%1;
    return(nCr[n-1][r-1]+ nCr[n - 1][r]);
  }
  else if(nCr[n-1][r-1]==0&&nCr[n-1][r]!=0){
    nCr[n-1][r-1]=combination(n-1,r-1)%1;
    return(nCr[n-1][r]+ nCr[n - 1][r-1]);
  }
  else{
    return nCr[n-1][r]+nCr[n-1][r-1];
  }
    
}


int main (void)
{
	long long int n,i,min,k,a[210000]={0},max,j=1,count=0,x,m=1,temp,cou=1,flag=0,tem;
scanf("%lld%lld%lld",&n,&x,&m);
  count=x;
  for(i=2;i<=n;i++){
    //printf("i=%lld\n",i);
    count+=(x*x)%m;
    x=(x*x)%m;
    a[(x*x)%m]++;
    
    if(a[(x*x)%m]==3&&flag==0){
      flag=1;
      temp=(x*x)%m;
      for(j=1;j<100000;j++){
        if(a[j]==2){
          cou++;
          temp+=j;
        }
      }
      count+=temp*((n-i)/cou);
      tem=(n-i)/cou;
      i+=tem*cou;
      //printf("count=%lld i=%lld cou=%lld (n-i)/cou=%lld\n",count,i,cou,(n-i)/cou);
    }
  }
  printf("%lld",count);
return 0;
}


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

int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	int a[n];
	for(int i=0; i<n; i++) scanf("%d", &a[i]);
	
	for(int i=k; i<n; i++){
		if(a[i-k] < a[i]) puts("Yes");
		else puts("No");
	}
	return 0;
}



Measured memory_bytes: 4432
# A
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if max([a, b, c, d, e]) - min([a, b, c, d, e]) > k:
    print(":(")
else:
    print("Yay!")

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count = 0;
  char c = s[0];
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == c) count++;
    c = s[i];
  }
  cout << s.size() - count << endl;
  return 0;
}


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

main(){
    double x[8],y[8];
    int i,hekomi;
    while(1){
	hekomi=0;
        for(i=0;i<4;i++){
            if(scanf("%lf,%lf",&x[i],&y[i])==EOF)return 0;
            getchar();
        }
	memcpy(x+4,x,sizeof(double)*4);
        memcpy(y+4,y,sizeof(double)*4);
        for(i=0;i<4;i++){
            if((atan2(x[i+2]-x[i+1],y[i+2]-y[i+1]) - atan2(x[i+1]-x[i],y[i+1]-y[i]))<0)
                hekomi++;
            else
                hekomi--;
        }

	if(fabs(hekomi)==2)
            puts("YES");
        else
            puts("NO");
    }
}



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

int main () {
  string S ;
  cin >> S ;
  int ans = 10000 ;
  for(int i = 0 ; i < S.size() - 2 ; i++ ){
    ans = min(ans,abs(753-(100*(S[i]-'0')+10*(S[i+1]-'0')+(S[i+2]-'0')))) ;    
  }
  cout << ans << endl ;
}

Measured memory_bytes: 256