akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int,input().split()))
ans = 0
A.sort()

count = 0
m = 0

for i in range(N):
  if count == 0:
    m = A[i]
    count += 1
  elif A[i] == m:
    count += 1
  else:
    if m > count:
      ans += count
    else:
      ans += count-m
    count = 1
    m = A[i]

if m > count:
  ans += count
else:
  ans += count-m

print(ans)

Measured memory_bytes: 20640
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n; cin>>n;
    cout<<(n+110)/111*111<<endl;
}

Measured memory_bytes: 3600
/*
 * Author:  vawait
 * Created Time:  六  4/22 11:59:08 2017
 * File Name: a.cpp
 */
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define red(i, a, b) for (int i = (a); i >= (b); --i)
#define clr( x , y ) memset(x,y,sizeof(x))
#define sqr(x) ((x) * (x))
#define mp make_pair
#define pb push_back
#define db pop_back
typedef long long lint;
const int maxn = 101000;
int x , y , n , m , l , r , ans[maxn*2];
int vis[maxn];
vector < int > g[maxn];

void init()
{
    scanf("%d%d",&n,&m);
    rep(i,1,m) {
        scanf("%d%d",&x,&y);
        g[x].pb( y );
        g[y].pb( x );
    }
}

void dfs(int t,int ty) {
    int y;
    if ( ty > 0 ) ans[++r] = t; else ans[--l] = t;
    vis[t] = 1;
    red(i,g[t].size()-1,0) {
        y = g[t][i];
        if ( vis[y] ) continue;
        dfs( y , ty );
        return;
    }
}

void work()
{
    l = r = maxn;
    r --;
    vis[x] = vis[y] = 1;
    dfs( x , 1 );
    dfs( y , -1 );
    printf("%d\n",r-l+1);
    rep(i,l,r) printf("%d%c",ans[i],i==r?'\n':' ');
}

int main()
{
    init();
    work();
    return 0;
}


Measured memory_bytes: 7040
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <functional>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

template <typename T>
struct sliding_window {
    deque<pair<int, T> > data;
    function<bool (T const &, T const &)> cmp;
    template <typename F>
    sliding_window(F a_lt) : cmp(a_lt) {}
    T front() { return data.front().second; } // smallest
    void push_back(int i, T a) { while (not data.empty() and cmp(a, data.back().second)) data.pop_back(); data.emplace_back(i, a); }
    void pop_front(int i) { if (data.front().first == i) data.pop_front(); }
    void push_front(int i, T a) { if (data.empty() or not cmp(data.front().second, a)) data.emplace_front(i, a); }
};

const ll inf = ll(1e18)+9;
int main() {
    int n, m, k; cin >> n >> m >> k;
    vector<int> a(n); repeat (i,n) cin >> a[i];

    if (n == m) {
        vector<vector<ll> > dp = vectors(k, n, - inf);
        repeat (j,n) dp[0][j] = a[j];
        repeat (i,k-1) {
            repeat (j,n-1) setmax(dp[i][j+1], dp[i][j]);
            repeat (j,n) {
                if (j-1 >= 0) {
                    setmax(dp[i+1][j], dp[i][j-1] + (i+2) *(ll) a[j]);
                }
            }
        }
        ll ans = *whole(max_element, dp[k-1]);
        cout << ans << endl;
    } else {
        vector<vector<ll> > dp = vectors(k, n, - inf);
        repeat (j,n) dp[0][j] = a[j];
        repeat (i,k-1) {
            sliding_window<ll> rmq( (greater<ll>()) );
            rmq.push_back(-1, - inf);
            repeat (j,n) {
                if (j-m-1 >= -1) rmq.pop_front(j-m-1);
                setmax(dp[i+1][j], rmq.front() + (i+2) *(ll) a[j]);
                rmq.push_back(j, dp[i][j]);
            }
        }
        ll ans = *whole(max_element, dp[k-1]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 236672
#include<stdio.h>
#include<string.h>
#include<math.h>
void p(int,int);
int a,s,d[4]={0,-1,0,1},f[4]={-1,0,1,0},g,h,c,x;
char z[13][13];
int main(void)
{
	int i,j;
	while(scanf("%s",z[0])!=EOF){
		for(i=1;i<12;i++) scanf("%s",z[i]);
		g=0;
		for(i=0;i<12;i++){
			for(j=0;j<12;j++){
				if(z[i][j]=='1'){
					g++;
					p(i,j);
				}
			}
		}
		printf("%d\n",g);
	}
}
void p(int x,int c)
{
	int i,j;
	z[x][c]='0';
	for(i=0;i<4;i++){
		if(x+d[i]<12&&x+f[i]>=0&&z[x+d[i]][c]=='1') p(x+d[i],c);
		if(c+d[i]>=0&&c+f[i]<12&&z[x][c+f[i]]=='1') p(x,c+f[i]);
	}
}

Measured memory_bytes: 2700
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int> cnt;
    REP(i, n){
        cin >> a[i];
        cnt[a[i]]++;
    }
    if(n % 3 > 0 && cnt.size() >= 2) {
        cout << "No" << endl;
    }
    else if(cnt.size() == 1){
        cout << (cnt.count(0) > 0 ? "Yes" : "No") << endl;
    }
    else if(cnt.size() == 2){
        vector<pii> t;
        // count, number
        for(auto p: cnt){
            t.push_back(make_pair(p.second, p.first));
        }
        sort(t.begin(), t.end());
        if(t[0].first * 2 != t[1].first){
            cout << "No" << endl;
        }
        else{
            cout << (t[0].second == 0 ? "Yes" : "No") << endl;
        }
    }
    else if(cnt.size() == 3){
        vector<pii> t;
        // count, number
        for(auto p: cnt){
            t.push_back(make_pair(p.second, p.first));
        }
        sort(t.begin(), t.end());
        if(t[0].first == t[1].first && t[1].first == t[2].first && (t[0].second^t[1].second^t[2].second)==0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

const int mod = 1e9+7;
const int INF = 2000000;

int main() {
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(a >= k) cout << k << endl;
    else if(a+b >= k) cout << a << endl;
    else cout << a - (k-b-a) << endl;
}


Measured memory_bytes: 3636
from collections import deque
N = int(input())
tree = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    tree[a].append(b)
    tree[b].append(a)
C = list(map(int, input().split()))
C.sort(reverse=True)
q = deque([0])
visited = [False] * N
ans = {}
ans[0] = C[0]
visited[0] = True
pointa = 1
while len(q):
    v = q.pop()
    for e in tree[v]:
        if visited[e]:
            continue
        visited[e] = True
        ans[e] = C[pointa]
        pointa += 1
        q.append(e)
num = []
for i in range(N):
    num.append(str(ans[i]))
print(sum(C[1:]))
print(" ".join(num))


Measured memory_bytes: 6908
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int nmap[][] = new int[n][n];
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            for (int j = 0; j < n; j++) {
                if (s.charAt(j) == '#') {
                    nmap[i][j] = 1;
                } else {
                    nmap[i][j] = 0;
                }
            }
        }
        int mmap[][] = new int[m][m];
        for (int i = 0; i < m; i++) {
            String s = sc.next();
            for (int j = 0; j < m; j++) {
                if (s.charAt(j) == '#') {
                    mmap[i][j] = 1;
                } else {
                    mmap[i][j] = 0;
                }
            }
        }
        sc.close();
        for (int i = 0; i < n - m + 1; i++) {
            aa: for (int j = 0; j < n - m + 1; j++) {
                // i , j は左上の座標
                if (nmap[i][j] != mmap[0][0]) {
                    continue;
                } else {
                    for (int k = 0; k < m; k++) {
                        for (int l = 0; l < m; l++) {
                            if (nmap[i + k][j + l] != mmap[k][l]) {
                                continue aa;
                            }
                        }
                    }
                    System.out.println(("Yes"));
                    return;
                }
            }
        }
        System.out.println(("No"));

    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<vector<pair<int,char>>> A(200001),B(200001),C(400001)/*UL(-)*/,D(400001)/*UR(+)*/,E(400001)/*DL(+)*/,F(400001)/*DR(-)*/;
  for(int i=0;i<N;i++){
    int X,Y;
    char c;
    cin>>X>>Y>>c;
    if(c=='U'){
      A[X].push_back({Y,'U'});
      C[X-Y+200000].push_back({X,'U'});
      D[X+Y].push_back({X,'U'});
    }else if(c=='D'){
      A[X].push_back({Y,'D'});
      E[X+Y].push_back({X,'D'});
      F[X-Y+200000].push_back({X,'D'});
    }else if(c=='R'){
      B[Y].push_back({X,'R'});
      D[X+Y].push_back({X,'R'});
      F[X-Y+200000].push_back({X,'R'});
    }else{
      B[Y].push_back({X,'L'});
      C[X-Y+200000].push_back({X,'L'});
      E[X+Y].push_back({X,'L'});
    }
  }
  int ans=1000000000000000000;
  for(vector<pair<int,char>> &v:A){
    sort(v.begin(),v.end());
    for(int i=0;i+1<v.size();i++)
      if(v[i].second=='U' && v[i+1].second=='D')
        ans=min(ans,(v[i+1].first-v[i].first)*5);
  }
  for(vector<pair<int,char>> &v:B){
    sort(v.begin(),v.end());
    for(int i=0;i+1<v.size();i++)
      if(v[i].second=='R' && v[i+1].second=='L')
        ans=min(ans,(v[i+1].first-v[i].first)*5);
  }
  for(vector<pair<int,char>> &v:C){
    sort(v.begin(),v.end());
    for(int i=0;i+1<v.size();i++)
      if(v[i].second=='U' && v[i+1].second=='L')
        ans=min(ans,(v[i+1].first-v[i].first)*10);
  }
  for(vector<pair<int,char>> &v:D){
    sort(v.begin(),v.end());
    for(int i=0;i+1<v.size();i++)
      if(v[i].second=='R' && v[i+1].second=='U')
        ans=min(ans,(v[i+1].first-v[i].first)*10);
  }
  for(vector<pair<int,char>> &v:E){
    sort(v.begin(),v.end());
    for(int i=0;i+1<v.size();i++)
      if(v[i].second=='D' && v[i+1].second=='L')
        ans=min(ans,(v[i+1].first-v[i].first)*10);
  }
  for(vector<pair<int,char>> &v:F){
    sort(v.begin(),v.end());
    for(int i=0;i+1<v.size();i++)
      if(v[i].second=='R' && v[i+1].second=='D')
        ans=min(ans,(v[i+1].first-v[i].first)*10);
  }
  if(ans==1000000000000000000)puts("SAFE");
  else cout<<ans<<endl;
}

Measured memory_bytes: 68616
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 27 02:27:51 2020

@author: liang
"""

N = int(input())
A = [int(x) for x in input().split()]

tmp = sum(A)
tmp -= 2*A[0]
ans = abs(tmp)
for i in range(1,N-1):
    tmp -= 2*A[i]
    ans = min(abs(tmp),abs(ans))
print(ans)

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

using ll    = long long;
using vll   = vector<ll>;
using pll   = pair<ll,ll>;
using ld    = long double;

const ll mod = (ll)1e9 + 7;

void solve() {
	char ch;
	cin>>ch;
	if(isupper(ch)) cout<<"A";
	else cout<<"a";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
//	pre();
//	ll t;cin>>t;while (t--)
		solve();
}


Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<set>
using namespace std;
#define INF 1LL<<62
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll


signed main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    string S,T;
    cin>>N>>S>>T;
    for(int i=0;i<N;i++){
        cout<<S[i]<<T[i];
    }
    cout<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int L,R;
  cin >> L >> R;
  long long int mod = 2019;
  
  long long int aL = L / mod;
  long long int aR = R / mod;
  
  if(aL == aR){
    int min = INT_MAX;
    for(int i = L; i < R; i++){
		for(int j = L +1; j<=R;j++){
          int ans = ((i%mod)*(j%mod))%mod;
          if(ans < min) min  = ans;
        }
    }
    cout << min;
  }
  else{
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;

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

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

    std::sort(a.begin(), a.end(), std::greater<int>());

    std::vector<int> num_matches = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

    std::vector<long long> dp_num(n + 1, 0);

    for (int i = 0; i < n; i++) {
        for (auto num : a) {
            if (i + num_matches[num] <= n) {
                dp_num[i + num_matches[num]] = std::max(dp_num[i + num_matches[num]], dp_num[i] + 1);
            }
        }
    }

    std::vector<std::string> dp(n + 1, "");

    for (auto num : a) {
        if (n - num_matches[num] >= 0) {
            dp[n - num_matches[num]] = std::max(std::to_string(num), dp[n - num_matches[num]]);
        }
    }

    for (int i = n; i > 0; i--) {
        if (dp[i] == "") {
            continue;
        }

        for (auto num : a) {
            if (i - num_matches[num] < 0) {
                continue;
            }

            if (dp[i - num_matches[num]].size() <= dp[i].size()) {
                dp[i - num_matches[num]] = dp[i] + std::to_string(num);
            } else if (dp[i - num_matches[num]].size() - 1 == dp[i].size()) {
                dp[i - num_matches[num]] = std::max(dp[i - num_matches[num]], dp[i] + std::to_string(num));
            }
        }
    }

    std::cout << dp[0] << std::endl;
}


Measured memory_bytes: 33536
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, m;
	while (cin>>n>>m,n|m) {
		vector<pair<int, pii>> root(m);
		REP(i, m) {
			int t, s, d;
			cin >> t >> s >> d;
			root[i] = pair<int,pii>(t, pii(s, d));
		}
		SORT(root);
		set<int> virus;
		virus.insert(1);
		REP(i,m)
			if (virus.find(root[i].second.first) != virus.end()) {
				virus.insert(root[i].second.second);
			}
		cout << virus.size() << endl;
	}
}

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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	string X;
	cin >> X;
	int ans = 0;
	int sCount = 0;
	for (int i = 0; i < X.size(); ++i)
	{
		if (X[i] == 'S')
		{
			sCount += 1;
		}
		else
		{
			if (sCount >= 1)
			{
				--sCount;
			}
			else
			{
				++ans;
			}
		}
	}
	cout << ans + sCount << endl;
}

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

Measured memory_bytes: 640
from heapq import heappush, heappop

INF = 10**18

V, E, r = map(int, input().split())

cost = [[] for i in range(V)]
for i in range(E):
    x, y, z = map(int, input().split())
    cost[x].append([y, z])
 
dist_lst = [INF for _ in range(V)]

que = []
heappush(que, (0, r))
dist_lst[r] = 0

while que:
    dist, node = heappop(que)
    for to, cos in cost[node]:
        if dist_lst[to] > cos+dist:
            dist_lst[to] = cos + dist
            heappush(que, (cos+dist, to))
 
for dist in dist_lst:
    if(dist == INF):
        print("INF")
    else:
        print(dist)


Measured memory_bytes: 97984
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define mk make_pair
#define sc(x) scanf("%d", &x)
#define pr(x) printf("%d\n", x)
#define pb push_back
#define debug puts("???")
#define ABS(x) ((x)<0?(-x):(x));
#define ALL(x) x.begin(), x.end()
#define br puts("")
#define frein freopen("in.txt", "r", stdin)
#define freout freopen("out.txt", "w", stdout)
typedef long long LL;
const double PI = acos(-1.0);
using namespace std;


int main(){
    int n, k;
    cin >> n >> k;
    LL ans = 0;
    for(int i = 1; i <= n; i++){
        if((i*2)%k) continue;
        int cnt = (n-i)/k + (i-1)/k + 1;
        //printf("i:%d, cnt:%d\n", i, cnt);
        ans += 1LL*cnt*cnt;
    }
    cout << ans << endl;
    return 0;
}


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

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

    int i = 0;
    while(n[i] != '\0'){
        if(n[i] == '1'){
            n[i] = '9';
        }
        else{
            n[i] = '1';
        }
        i++;
    }
    cout << n << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
dict = {}
mx = 0
for i in range(n):
    s = input()
    if s not in dict:
        dict[s] = 0
    dict[s] += 1
    mx = max(mx, dict[s])
ans = []
for s in dict:
    if dict[s] == mx:
        ans.append(s)
ans.sort()
for s in ans:
    print(s)

Measured memory_bytes: 33320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define Would
#define you
#define please

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

	int A, B, X;
	cin >> A >> B >> X;
	
	int kotae  = 1;
	if (A > X) kotae = 0;
	if (A + B < X) kotae = 0;
	if (kotae == 1)	co("YES");
	else co("NO");
	Would you please return 0;
}

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

b = {}
for i in range(N):
    if A[i] not in b:
        b[A[i]] = 1
    else:
        b[A[i]] += 1

total = 0
for v in b.values():
    total += v*(v-1)/2

for k in range(N):
    n = b[A[k]]
    ans = int(total - n*(n-1)/2 + (n-1)*(n-2)/2)
    print(ans)

Measured memory_bytes: 26140
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int sum=1;
    for(int i=1;i<=N;i++){
        int ans=sum;
        sum=min(ans*2,ans+K);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int k=s.nextInt();
		
		String str=s.next();
		
		if(str.length()<=k)
		{
			System.out.println(str);
		}
		else
		{
			for(int i=0;i<k;i++)
			{
				System.out.print(str.charAt(i));
			}
			
			System.out.println("...");
		}
		
	}
	
}

Measured memory_bytes: 35900
using System;
using System.Collections;

namespace aoj1166
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                string wh = Console.ReadLine();
                string[] whs = wh.Split(' ');
                int w = int.Parse(whs[0]);
                int h = int.Parse(whs[1]);
                
                if (w == 0 || h == 0)
                    break;

                int[,] xwall = new int[w, h - 1];
                int[,] ywall = new int[w - 1, h];
                for (int i = 0; i < h; ++i)
                {
                    wh = Console.ReadLine();
                    whs = wh.Split(' ');
                    for (int j = 0; j < w - 1; ++j) 
                        ywall[j, i] = int.Parse(whs[j + 1]);

                    if (i == h - 1)
                        break;

                    wh = Console.ReadLine();
                    whs = wh.Split(' ');
                    for (int j = 0; j < w; ++j)
                        xwall[j, i] = int.Parse(whs[j]);
                }

                int[,] node = new int[w, h];
                
                Queue xq = new Queue();
                Queue yq = new Queue();
                
                for (int i = 0; i < w; ++i) 
                {
                    for (int j = 0; j < h; ++j) 
                    {
                        node[i, j] = 0;
                    }
                }
                node[0, 0] = 1;
                
                xq.Enqueue(0);
                yq.Enqueue(0);

                while (xq.Count > 0) 
                {
                    int nx = (int)xq.Dequeue();
                    int ny = (int)yq.Dequeue();

                    if (nx > 0 && ywall[nx - 1, ny] == 0 && (node[nx - 1, ny] == 0 || node[nx - 1, ny] > node[nx, ny] + 1)) 
                    {
                        node[nx - 1, ny] = node[nx, ny] + 1;
                        xq.Enqueue(nx - 1);
                        yq.Enqueue(ny);
                    }
                    if (ny > 0 && xwall[nx, ny - 1] == 0 && (node[nx, ny - 1] == 0 || node[nx, ny - 1] > node[nx, ny] + 1))
                    {
                        node[nx, ny - 1] = node[nx, ny] + 1;
                        xq.Enqueue(nx);
                        yq.Enqueue(ny - 1);
                    }
                    if (nx < w - 1 && ywall[nx, ny] == 0 && (node[nx + 1, ny] == 0 || node[nx + 1, ny] > node[nx, ny] + 1))
                    {
                        node[nx + 1, ny] = node[nx, ny] + 1;
                        xq.Enqueue(nx + 1);
                        yq.Enqueue(ny);
                    }
                    if (ny < h - 1 && xwall[nx, ny] == 0 && (node[nx, ny + 1] == 0 || node[nx, ny + 1] > node[nx, ny] + 1))
                    {
                        node[nx, ny + 1] = node[nx, ny] + 1;
                        xq.Enqueue(nx);
                        yq.Enqueue(ny + 1);
                    }
                }
                Console.WriteLine(node[w - 1, h - 1].ToString());
            }
        }
    }
}

Measured memory_bytes: 5928
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;
int main()
{
	long long k,i,num,h,j;
	while(scanf("%lld",&k)!=EOF)
	{
		if(k<=49)
		{
			for(i=2;i<=50;i++)
			{
				if(i>k)
				break;
			}
			printf("%lld\n",i);
			printf("%lld ",k*i+i-1);
			for(j=2;j<=i;j++)
			{
				printf("0");
				if(j!=i)
				printf(" ");
				else
				printf("\n");
			}
		}
		else
		{
			printf("50\n");
			if(k%50==0)
			{
				num=k/50+49;
				for(i=1;i<=50;i++)
				{
					printf("%lld",num);
					if(i!=50)
					printf(" ");
					else
					printf("\n");
				}
			}
			else
			{
				h=k%50;
				num=k/50+49;
				for(i=1;i<=h;i++)
				printf("%lld ",num+51-h);
				for(i=h+1;i<=50;i++)
				{
					printf("%lld",num-h);
					if(i!=50)
					printf(" ");
					else
					printf("\n");
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
S = list(input())

A = ['dream', 'dreamer', 'erase', 'eraser']

ans = 'YES'
l = len(S)
while l>=5:
    if S[l-5:l] == list(A[0]):
        l -= 5
    elif S[l-5:l] == list(A[2]):
        l -= 5
    elif l == 5:
        break
    elif S[l-6:l] == list(A[3]):
        l -= 6
    elif l == 6:
        break
    elif S[l-7:l] == list(A[1]):
        l -= 7
    else:
        ans = 'NO'
        break
if l != 0:
    ans = 'NO'
print(ans)

Measured memory_bytes: 3956
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;

fn main() {
    input! {
        a: isize,
        b: isize,
        c: isize,
        d: isize,
    };
    let kaisi = max(a, c);
    let owari = min(b, d);
    println!("{}", if kaisi < owari { owari - kaisi } else { 0 });
}


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

using i64 = int64_t;

int main(){
    vector<vector<int>> card(3, vector<int>(3));
    for(int i=0;i<3;++i){
        for(int j=0;j<3;++j){
            cin >> card[i][j];
        }
    }
    int n;
    cin >> n;
    deque<deque<bool>> marked(3, deque<bool>(3));
    for(int i=0;i<n;++i){
        int b;
        cin >> b;
        for(int j=0;j<3;++j){
            for(int k=0;k<3;++k){
                if(card[j][k] == b)marked[j][k] = true;
            }
        }
    }
    bool bingo = false;
    for(int i=0;i<3;++i){
        bool flag = true;
        for(int j=0;j<3;++j){
            if(!marked[i][j]){
                flag = false;
                break;
            }
        }
        if(flag)bingo = true;
    }
    for(int j=0;j<3;++j){
        bool flag = true;
        for(int i=0;i<3;++i){
            if(!marked[i][j]){
                flag = false;
                break;
            }
        }
        if(flag)bingo = true;
    }
    if(marked[0][0] && marked[1][1] && marked[2][2])bingo = true;
    if(marked[0][2] && marked[1][1] && marked[2][0])bingo = true;

    cout << (bingo ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
from collections import deque

def main():
    N, M = map(int, input().split(' '))
    lines = sys.stdin.read().split('\n')
    A = []
    B = []
    for line in lines:
        if not line:
            continue
        a, b = map(int, line.split(' '))
        A.append(a)
        B.append(b)
    adj = defaultdict(list)
    for val in zip(A,B):
        a, b = val
        adj[a].append(b)
        adj[b].append(a)

    source = defaultdict(int)
    start = 1
    source[1] = 1
    queue = deque([1])
    while len(queue) > 0:
        room = queue.pop()
        for adj_room in adj[room]:
            if adj_room in source:
                continue
            source[adj_room] = room
            queue.appendleft(adj_room)
    if len(source) != N:
        print('No')
        return
    print('Yes')
    for i in range(2, N+1):
        print(source[i])



if __name__ == '__main__':
    main()


Measured memory_bytes: 65784
# frozen_string_literal: true

# MaxFlowGraph
class MaxFlow
  def initialize(n = 0)
    @n   = n
    @pos = []
    @g   = Array.new(n) { [] }
  end

  def add_edge(from, to, cap)
    edge_number = @pos.size
    @pos     << [from, @g[from].size]
    @g[from] << [to,   @g[to].size,       cap]
    @g[to]   << [from, @g[from].size - 1, 0]
    edge_number
  end

  def [](i)
    @pos[i]
  end
  alias get_edge []

  def edges
    @pos
  end

  def flow(s, t, flow_limit = 1 << 64)
    level = Array.new(@n)
    iter  = Array.new(@n)
    que   = []

    flow = 0
    while flow < flow_limit
      bfs(level, que, s, t)
      break if level[t] == -1

      iter.fill(0)

      while flow < flow_limit
        f = dfs(t, flow_limit - flow, s, level, iter)
        break if f == 0

        flow += f
      end
    end

    flow
  end

  def calc(s, ans, m)
    @g[s].each do |e|
      next if e[2] > 0

      i, j = e[0].divmod(m)
      @g[e[0]].each do |f|
        next if f[2] > 0

        x, y = f[0].divmod(m)

        if i == x
          j, y = y, j if y < j
          ans[i][j], ans[i][y] = '>', '<'
        else
          i, x = x, i if x < i
          ans[i][j], ans[x][j] = 'v', '^'
        end
        break
      end
    end
  end

  private
  def bfs(level, que, s, t)
    level.fill(-1)
    level[s] = 0
    que.clear
    que << s

    while (v = que.shift)
      @g[v].each do |e|
        next if e[2] == 0 || level[e[0]] >= 0
        level[e[0]] = level[v] + 1
        return if e[0] == t
        que << e[0]
      end
    end
  end

  def dfs(v, up, s, level, iter)
    return up if v == s

    res = 0
    level_v = level[v]

    iter[v].upto(@g[v].size - 1) do |i|
      e = @g[v][i]
      next if level_v <= level[e[0]] || @g[e[0]][e[1]][2] == 0

      d = dfs(e[0], [up - res, @g[e[0]][e[1]][2]].min, s, level, iter)
      next if d <= 0

      @g[v][i][2] += d
      @g[e[0]][e[1]][2] -= d
      res += d
      break if res == up
    end

    return res
  end
end
MaxFlowGraph = MaxFlow
MFGraph      = MaxFlow

n, m = gets.split.map(&:to_i)

l = n * m
mf = MaxFlowGraph.new(l + 2)

s = n.times.map { gets.chars } << Array.new(m + 1, '#')
move = [[1, 0], [0, 1]]

n.times do |i|
  m.times do |j|
    next if s[i][j] != '.'

    f = !(i.odd? ^ j.odd?)
    f ? mf.add_edge(l, i * m + j, 1) : mf.add_edge(i * m + j, l + 1, 1)

    move.each do |x, y|
      x = i + x
      y = j + y
      next if s[x][y] != '.'

      f ? mf.add_edge(i * m + j, x * m + y, 1) : mf.add_edge(x * m + y, i * m + j, 1)
    end
  end
end

puts mf.flow(l, l + 1)
mf.calc(l, s, m)
puts s[0..-2].map{ |e| e.join.chomp }


Measured memory_bytes: 22304
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define LLFOR(i, a, b) for(long long i = (a); i < (b); ++i)
#define LLRFOR(i, a, b) for(long long i = (a); i >= (b); i--)
#define SORT(v, n) sort(v, v+n)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define LLREP(i, n) for(long long i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)
#define LLRREP(i, n) for(long long i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define ret return

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

int MAX(int a,int b){if(a>b){return a;}return b;}
int MIN(int a,int b){if(a<b){return a;}return b;}
int GCD(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){int c=GCD(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int POW(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
ll LLMAX(ll a,ll b){if(a>b){return a;}return b;}
ll LLMIN(ll a,ll b){if(a<b){return a;}return b;}
ll llGCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
ll llLCM(ll a,ll b){ll c=llGCD(a,b);a/=c;return a*b;}
ll llnCr(ll a,ll b){ll i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
ll llnHr(ll a,ll b){return llnCr(a+b-1,b);}
ll llpow(ll a,ll b){ll i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
   ios::sync_with_stdio(false);
   vector<ll> beki;
   LLFOR(i, 1, 32){
      LLFOR(j, 2, 32) beki.pb(llpow(i, j));
   }
   sort(ALL(beki), greater<ll>());

   ll x, ans;
   cin >> x;
   LLRFOR(i, x, 1){
      bool a = false;
      LLFOR(j, 0, 930){
         if(i == beki.at(j)){
            ans = i;
            a = true;
            break;
         }
      }
      if(a == true) break;
   }

   cout << ans << endl;
	ret 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort()

M = 10**6 + 1
cnt = [0]*M

for a in A:
    if cnt[a] != 0:
        cnt[a] += 1
        continue
    for i in range(M)[a::a]:
        cnt[i] += 1

ans = 0
for a in A:
    if cnt[a] == 1:
        ans += 1

print(ans)

Measured memory_bytes: 32344
s = input()
s1 = '01' * (10 ** 5 // 2)
s2 = '10' * (10 ** 5 // 2)
s1 = s1[:len(s)]
s2 = s2[:len(s)]
count = [0, 0]

for i in range(len(s)):
    if s[i] != s1[i]:
        count[0] += 1
    else:
        count[1] += 1

print(min(count))


Measured memory_bytes: 41712
import math
import sys

N, K = map(int, input().split())
H = [0] + list(map(int, input().split()))
if K == 0:
    ans = 0
    pre = 0
    for h in H:
        ans += max(0, h - pre)
        pre = h
    print(ans)
    sys.exit()
dp = [[math.inf]*(K+1) for _ in range(N+1)]  # (直前のインデックス, 使ったk) =>　最小
dp[0][0] = 0
for i in range(1, N + 1):
    for j in range(i):
        for k in range(K+1):
            dp[i][k] = min(dp[j][k] + max(0, H[i] - H[j]), dp[i][k])
    for j in range(i):
        for k in range(K-1, -1, -1):
            dp[j][k + 1] = dp[j][k]
        dp[j][0] = math.inf
ans = math.inf
for i in range(N + 1):
    ans = min(ans, min(dp[i]))
print(ans)


Measured memory_bytes: 80220
import Control.Applicative

main = do
  [w,h,x,y,r] <- map read . words <$> getLine
  putStrLn(if isInRect [w,h,x,y,r] then "Yes" else "No")

isInRect :: [Int] -> Bool
isInRect [w,h,x,y,r]
  | 0 <= x-r && x+r <= w && 0 <= y-r && y+r <= h = True
  | otherwise = False



Measured memory_bytes: 3664
n, m, x = map(int, input().split())
INF = 10 ** 18  # 定数は大文字　INF＝Infinity（無限大）
ans = INF
li = []
for i in range(n):
    li.append(list(map(int, input().split())))


for i in range(2 ** n):
    cost = 0
    know = [0]*m  # アルゴリズムM個
    for j in range(n):  # このループが一番のポイント
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            # フラグが立っていたら
            cost += li[j][0]
            for k in range(m):
                know[k] += li[j][k + 1]

    knowbool = True
    for i in range(m):  # 理解度がXを超えているか
        if (know[i] < x):
            knowbool = False

    if (knowbool):
        ans = min(ans, cost)


if (ans == INF):  # ansが更新されていない　つまりどのパターンをとっても理解度Xを超えなかったら
    print(-1)
else:
    print(ans)


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

int main() {
  int K, S;
  cin >> K >> S;
  int total;
  int count = 0;
  int z;
  
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
	  z = S - i - j;
      if (z <= K && z >= 0) {
		count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static Scanner sc = new Scanner(System.in);
	
	
	void run() {
		int n;
		n = sc.nextInt();
		
		BigInteger a, b, c;
		
		for (int i = 0; i < n; i++) {
			a = sc.nextBigInteger();
			b = sc.nextBigInteger();
			c = a.add(b);
			if (c.toString().length() > 80)
				System.out.println("overflow");
			else
				System.out.println(c);
		}
		
		
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}

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

int main(int argc, const char * argv[]) {
    
    int a,b,x;
    
    
    cin >> x;
    cin >> a;
    cin >> b;
    
    x-=a;
    
    for(;;){
        if(x-b<0) break;
        x-=b;
    }
    
    cout << x << endl;
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l_s = list(map(int, input().split()))
l_s.sort()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if l_s[i] == l_s[j]:
            continue
        for k in range(j + 1, n):
            if l_s[i] == l_s[k]:
                continue
            if l_s[j] == l_s[k]:
                continue
            if l_s[i] + l_s[j] > l_s[k]:
                ans += 1

print(ans)

Measured memory_bytes: 67684
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

int main() {
    vec in(3);
    cin>>N;
    rep(i,3) cin>>in[i];
    ll sum = accumulate(ALL(in), 0LL);
    vector<char> ans(N);
    map<string, int> mp;
    mp["AB"] = 0;
    mp["BC"] = 1;
    mp["AC"] = 2;
    if(sum == 1 || sum >= 3) {
        rep(i, N) {
            string s;
            cin >> s;
            int id = mp[s];
            int a = id, b = (id + 1) % 3;
            if (max(in[a], in[b]) == 0) {
                cout << "No" << endl;
                return 0;
            } else {
                if (in[a] > in[b]) {
                    --in[a];
                    ++in[b];
                    ans[i] = char('A' + b);
                }else{
                    ++in[a];
                    --in[b];
                    ans[i] = char('A' + a);
                }
            }
        }
        cout<<"Yes"<<endl;
        rep(i,N) cout<<ans[i]<<endl;
    }else if(sum == 2){
        vec id(N);
        rep(i,N){
            string s;
            cin >> s;
            id[i] = mp[s];
        }
        rep(i,N){
            int a = id[i], b = (id[i] + 1) % 3;
            if (max(in[a], in[b]) == 0) {
                cout << "No" << endl;
                return 0;
            }else if(in[a] == in[b] && i != N - 1){
                if(a == id[i+1] || a == (id[i+1]+1)%3){
                    ans[i] = char('A' + a);
                    ++in[a];
                    --in[b];
                }else{
                    ans[i] = char('A' + b);
                    --in[a];
                    ++in[b];
                }
            }else{
                if (in[a] > in[b]) {
                    --in[a];
                    ++in[b];
                    ans[i] = char('A' + b);
                }else{
                    ++in[a];
                    --in[b];
                    ans[i] = char('A' + a);
                }
            }
        }
        cout<<"Yes"<<endl;
        rep(i,N) cout<<ans[i]<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3996
import sys
import copy
from collections import deque
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

x, y = na()

if y%2==0 and y/2-x>=0 and 2*x-y/2>=0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 68188
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	int n;
	long x;
	{
		long[] tmp = readln.chomp.split.map!(to!long).array;
		n = cast(int) tmp[0];
		x = tmp[1];
		}
	long[] as = readln.chomp.split.map!(to!long).array;
	
	long[][] qs;
	qs.length = n;
	for(int i = 0; i < n; i ++){
		for(int k = 0; k < n; k ++){
			int j = i - k;
			if(j < 0) j += n;
			long u = as[j];
			if(qs[i].length && qs[i][$ - 1] < u) u = qs[i][$ - 1];
			qs[i] ~= u;
			}
		}
	
		long ans = long.max;
	for(int k = 0; k < n; k ++){
		long a = x * k;
		foreach(q; qs){
			a += q[k];
			}
		ans = min(ans, a);
		}
	
	ans.writeln;
	}

Measured memory_bytes: 33404
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			int a = A[i];
			if (a % 2 == 0){
				if ((a % 3 != 0 && a % 5 != 0)) {
					System.out.println("DENIED");
					return;
				}
			}
		}
		System.out.println("APPROVED");
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 24148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
#include <numeric>
#include <cmath>

#define INF 1000000000000000000

using namespace std;
using sl = signed long;
using sll = signed long long;
using ll = long long;

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

// For debug
template <class T> void print_vecotor(vector<T> vec){
	for(auto v: vec){
		cout << v << " ";
	}
}

int main(int argc, char *argv[])
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	string ans = "";
	if(N==1 || N % 2!=0 ||S.substr(0, N/2)!=S.substr(N/2,N)){
		ans= "No";
	}else{
		ans ="Yes";
	}

	cout << ans;

	return 0;
}

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

typedef pair <int, int> ii;

#define INF 1000000005

int dirh[] = {1, 0, -1, 0}, dirw[] = {0, 1, 0, -1};

int h, w;
int ch, cw;
int dh, dw;
char grid[1005][1005];
int dist[1005][1005];
deque <ii> dq;

int main() {
	scanf("%d%d", &h, &w);
	scanf("%d%d", &ch, &cw);
	scanf("%d%d", &dh, &dw);
	for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) scanf(" %c", &grid[i][j]);
	for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) dist[i][j] = INF;
	dist[ch][cw] = 0;
	dq.push_front(ii(ch, cw));
	while (!dq.empty()) {
		int uh, uw; tie(uh, uw) = dq.front(); dq.pop_front();
		for (int i = 0; i < 4; i++) {
			int vh = uh + dirh[i], vw = uw + dirw[i];
			if (vh <= 0 || vh > h || vw <= 0 || vw > w) continue;
			if (grid[vh][vw] == '#') continue;
			if (dist[vh][vw] > dist[uh][uw]) {
				dist[vh][vw] = dist[uh][uw];
				dq.emplace_front(vh, vw);
			}
		}
		for (int i = -2; i <= 2; i++) for (int j = -2; j <= 2; j++) {
			int vh = uh + i, vw = uw + j;
			if (vh <= 0 || vh > h || vw <= 0 || vw > w) continue;
			if (grid[vh][vw] == '#') continue;
			if (dist[vh][vw] > dist[uh][uw] + 1) {
				dist[vh][vw] = dist[uh][uw] + 1;
				dq.emplace_back(vh, vw);
			}
		}
	}
	if (dist[dh][dw] == INF) printf("-1\n");
	else printf("%d\n", dist[dh][dw]);
	return 0;
}


Measured memory_bytes: 8772
#include <stdio.h>
int main(void){
    
    
    int a,b;
    char op;
    while(1){
    scanf("%d %c %d",&a,&op,&b);
    
        
    if(op=='+'){
        printf("%d\n",a+b);
    }
    else if(op=='-'){
        printf("%d\n",a-b);
    }
    else if(op=='*'){
        printf("%d\n",a*b);
    }
    else if(op=='/'){
        printf("%d\n",a/b);
    }
    else if(op=='?'){
        break;
    }    
    }
    
}



Measured memory_bytes: 2084
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x = input()
n = len(x)
s = 0
d = 0
for i,j in enumerate(x):
    if j == 'S':
        s += 1
    else:
        if s > 0:
            d += 2
            s -= 1
print(n-d)

Measured memory_bytes: 41692
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    getLine
    as <- getIntList
    let zs = zipWith (\r l -> (r-l,r)) rs (tail ls)
            where ls = scanl min 1000000001 as
                  rs = scanr max 0 as
    let m = maximum $ map fst zs
    let ans = length . group $ filter ((== m).fst) zs
    print ans

Measured memory_bytes: 38472
#include<cstdio>
#include<algorithm>
using namespace std;
char str[200005];
int main(){
    int a, b;
    scanf("%d%d",&a,&b);

    if(a==1){
        if(b==1)
            puts("Draw");
        else
            puts("Alice");
    }else if(b==1){
        puts("Bob");
    }else
        puts((a!=b)?(a>b?"Alice":"Bob"):"Draw");

    return 0;
}


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

using namespace std;
typedef long long ll;
int main()
{
    ll n, ans = 0;
    cin >> n;
    map<ll, ll> mp;
    for(ll i=1;i<=n;i++)
    {
        ll x;
        cin >> x;
        mp[i+x]++;
 
        ans += mp[i-x];
 
    }
 
    cout << ans;
 
    return 0;
}


Measured memory_bytes: 26376
#全部の和 - 3の倍数の和 - 5の倍数の和 + 15の倍数の和

n = int(input())
ans = 0

for i in range(1,n+1):
    if i % 3 == 0 or i % 5 == 0:
        continue
    else:
        ans += i

print(ans)

Measured memory_bytes: 9164
N = int(input())
AB_number = 0
ab_cnt =0
a_cnt = 0
b_cnt = 0
for _ in range(N):
    s_i = input()
    AB_number += s_i.count("AB")
    if s_i[0] == "B" and s_i[-1] == "A":
        ab_cnt += 1
    elif s_i[-1] == "A":
        a_cnt += 1
    elif s_i[0] == "B":
        b_cnt += 1

if ab_cnt== 0:
    print(AB_number+min(a_cnt,b_cnt))
elif a_cnt != b_cnt:
    print(AB_number+(ab_cnt-1)+1+min(a_cnt,b_cnt))
elif a_cnt==0:
    print(AB_number+(ab_cnt-1)+min(a_cnt,b_cnt))
else:
    print(AB_number+(ab_cnt-1)+1+min(a_cnt,b_cnt))


Measured memory_bytes: 3188