akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=1e9+7;

ll lasttwo(vector<ll> &v)
{
  ll n=v.size(); return v[n-1]*v[n-2];
}

ll product(auto v,ll i,ll j)
{
  ll ans=1;
  while(i<=j)
  {
    //cout<<v[i]<<" ";
    ans=(ans*v[i]+ mod)%mod;
    i++;
  }
  return (ans+mod)%mod;
}

bool comp(ll a,ll b)
{
  return abs(a)>abs(b);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,temp; cin>>n>>k;
    ll arr[n]; for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n,comp);
    //for(int i=0;i<n;i++) cout<<arr[i]<<" ";
    ll pos=0,neg=0,zero=0,poscnt=0,negcnt=0;
    for(int i=0;i<n;i++) 
    {
      if(arr[i]>0) poscnt++;
      else if(arr[i]<0) negcnt++;
    }

    if(poscnt==0)
    {
      if(k%2 ==0) cout<<product(arr,0,k-1);
      else cout<<product(arr,n-k,n-1);
      return 0;
    }
    else if(negcnt==0)
    {
      cout<<product(arr,0,k-1);
      return 0;
    }
    else if(k==n)
    {
      cout<<product(arr,0,n-1);
      return 0;
    }

    for(int i=0;i<k;i++)
    {
      if(arr[i]<0) neg++;
      else if(arr[i]>0) pos++;
      else zero++;
    }

    if(zero) cout<<0;
    else
    {
      if(neg%2 !=0)
      {
        ll npos=n,nneg=n;
        for(int i=k;i<n;i++)
        {
          if(arr[i]<0) {nneg=i; break;}
        }
        for(int i=k;i<n;i++)
        {
          if(arr[i]>0) {npos=i; break;}
        }

        int negidx=-1,posidx=-1;
        for(int i=k-1;i>-1;i--)
        {
          if(arr[i]<0) {negidx=i; break;}
        }
        for(int i=k-1;i>-1;i--)
        {
          if(arr[i]>0) {posidx=i; break;}
        }
        //cout<<negidx<<" "<<posidx<<" "<<nneg<<" "<<npos<<endl;
        if(negidx>-1 && npos<n && posidx>-1 && nneg<n)
        {
          if((arr[npos]*arr[posidx])>=arr[nneg]*arr[negidx])
            swap(arr[npos],arr[negidx]);
          else
            swap(arr[nneg],arr[posidx]);
        }
        else if(negidx>-1 && npos<n)
          swap(arr[npos],arr[negidx]);
        else if(posidx>-1 && nneg<n)
          swap(arr[nneg],arr[posidx]);
        else {cout<<0; return 0;}
      }
      //for(int i=0;i<k;i++) cout<<arr[i]<<" ";cout<<endl;
      cout<<product(arr,0,k-1);
    }
}


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

int main () {
    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.size() -1] == b[0] && b[b.size() -1] == c[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;                                                   
    }   
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,b) for(int i=0;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;

int main() {

	int x1, y1, x2, y2;

	cin >> x1 >> y1 >> x2 >> y2;

	int dx = abs(x1 - x2);
	int dy = abs(y1 - y2);


	int x3 = 0;
	int y3 = 0;
	int x4 = 0;
	int y4 = 0;

	if (x2 - x1 >= 0 && y2 - y1 >= 0) {
		x3 = x2 - dy;
		y3 = y2 + dx;

		x4 = x3 - dx;
		y4 = y3 - dy;

		cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

		return 0;
	}

	if (x2 - x1 <= 0 && y2 - y1 >= 0) {

		int buf = dx;
		dx = dy;
		dy = buf;

		x3 = x2 - dx;
		y3 = y2 - dy;

		x4 = x3 + dy;
		y4 = y3 - dx;

		cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

		return 0;
	}

	if (x2 - x1 <= 0 && y2 - y1 <= 0) {
		x3 = x2 + dy;
		y3 = y2 - dx;

		x4 = x3 + dx;
		y4 = y3 + dy;

		cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

		return 0;
	}

	if (x2 - x1 >= 0 && y2 - y1 <= 0) {


		int buf = dx;
		dx = dy;
		dy = buf;

		x3 = x2 + dx;
		y3 = y2 + dy;

		x4 = x3 - dy;
		y4 = y3 + dx;

		cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

		return 0;
	}

	
	
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	xm := make(map[int]int, n)
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
		xm[a[i]]++
	}

	sum := 0
	for _, v := range xm {
		sum += v * (v - 1) / 2
	}

	var wr = bufio.NewWriter(os.Stdout)
	for _, v := range a {
		wr.WriteString(strconv.Itoa(sum-(xm[v]-1)) + "\n")
	}
	wr.Flush()
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll A,B;
char S[111], T[111];
ll i, j, k, ans;
ll gcd(ll a,ll b){
    if(b==0)
        return a;
    return gcd(b, a % b);
}
int main(){
    scanf("%lld%lld", &A,&B);
    ans = gcd(A, B);
    printf("%lld", A*B/ans);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		int N = GetInt();
		int L = GetInt();
		int sum = 0;
		for(int i = 0; i < N; i++)
			sum += L + i;

		int ans = 0;
		int minDiff = int.MaxValue;
		for(int i = 0; i < N; i++)
		{
			int tmp = sum - L - i;
			if(Math.Abs(sum - tmp) < minDiff)
			{
				minDiff = Math.Abs(sum - tmp);
				ans = tmp;
			}
		}

		Console.WriteLine(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	std::string s;

	std::cin >> s;

	for (size_t i = 0; i < s.length(); i++)
	{
		if (i % 2 == 0) {
			std::cout << s[i];
		}
	}
	return 0;
}


Measured memory_bytes: 512
/*
	"We know what we are, but know not what we may be."
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

/*
	"You never know how strong you are until being strong is the only choice you have."
*/

int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
	
/*
	"With self-discipline most anything is possible."
*/
	
	long long n; cin >> n;
	
	set<long long> s;
	for(long long i = 0; i < n; i++){
		long long x; cin >> x;
		s.insert(x);
	}
	
	if(s.size() == n) cout << "YES";
	else cout << "NO";
	return 0;
}

/*
	"Reach for it. Push yourself as far as you can."
*/

Measured memory_bytes: 9600
N = int(input())

li = list(map(int,input().split()))	

d = [i for i in range(N)]
#print(d)

L = dict(zip(d,li))

#print(L)

import itertools
x = (list(itertools.combinations(d, 3)))
#print(x)
#print(x[0][0])
#print(x[0][1])
cnt = 0
num = len(x)
for i in range(num):
    a = L[x[i][0]]
    b = L[x[i][1]]
    c = L[x[i][2]]
   # print(a,b,c)
    if ((a + b >c) and (a+c >b) and (b+c>a)) and (a!=b and b!=c and a!=c):
        cnt = cnt+1
    else:
        pass
    a = 0
    b = 0
    c = 0
    
print(cnt)







Measured memory_bytes: 20480
#include <iostream>
using namespace std;
int main () {
    char a, b, c;
    cin >> a >> b >> c;
    if (a=='1') a='9';
    else a='1';
    if (b=='1') b='9';
    else b='1';
    if (c=='1') c='9';
    else c='1';
    cout << a << b << c;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long ans = 0;
        for (int i = 1; i <= N - 1; i++) {
            ans += i;
        }
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

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

using namespace std;

const int MOD = 998244353;
const int MX = 4007;

void add(int& x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
}

int mul(int x, int y) {
    return (1ll * x * y) % MOD;
}

int dp[MX][MX];
int ps[MX][MX];
int f[MX][MX];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    dp[0][0] = 1;
    for (int i = 0; i < MX; i++) {
        ps[0][i] = 1;
    }

    for (int i = 1; i < MX; i++) {
        for (int j = 0; j < MX; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j) {
                add(dp[i][j], mul(2, ps[i - 1][j - 1]));
            }
        }
        ps[i][0] = dp[i][0];
        for (int j = 1; j < MX; j++) {
            ps[i][j] = ps[i][j - 1];
            add(ps[i][j], dp[i][j]);
        }
    }

    f[0][0] = 1;
    for (int i = 1; i < MX; i++) {
        int sm = 0;
        for (int j = 0; j < MX; j++) {
            add(sm, f[i - 1][j]);
            f[i][j] = sm;
        }
    }

    int k, n;
    cin >> k >> n;
    for (int i = 2; i <= 2 * k; i++) {
        int gr = 0;
        for (int j = 1; j <= k; j++) {
            int ad = i - j;
            if (ad > j && ad <= k) {
                gr++;
            }
        }
        int og = k - 2 * gr;
        int ans = 0;
        if (i % 2 == 0) {
            og--;
            for (int take = 0; take <= n; take++) {
                add(ans, mul(f[og][take], dp[gr][n - take]));
                if (take > 0) {
                    add(ans, mul(f[og][take - 1], dp[gr][n - take]));
                }
            }
        } else {
            for (int take = 0; take <= n; take++) {
                add(ans, mul(f[og][take], dp[gr][n - take]));
            }
        }
        cout << ans << "\n";
    }
}




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

int gcd(int a, int b) {return (b) ? gcd(b, a % b) : abs(a);}
int lcm(int &a, int &b) {return abs(a / gcd(a, b) * b);}

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

  int a, b, c;
  cin >> a >> b >> c;
  int l = lcm(a, b);
  string ans = "NO";
  for (int i = a; i <= l; i += a) {
    if (i % b == c) {
      ans = "YES";
      break;
    } 
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
while 1:
	n, k = map(int,raw_input().split(" "))
	if (n,k) == (0,0):
		break
	card = sorted([int(raw_input()) for i in range(k)])
	group = []
	wild = False
	if card[0] == 0:
		card.pop(0)
		k = k-1
		wild = True 
	group.append([card[0],card[0],1])
	token = 0
	for i in range(1,k):
		if group[token][1] + 1 == card[i]:
			group[token][1] = card[i]
			group[token][2] += 1
		else:
			group.append([card[i],card[i],1])
			token += 1

	tmp_score = max(group, key = lambda x: x[2])[2]
	if wild:
		for i in range(len(group)-1):
			if group[i][1] + 2 == group[i+1][0]:
				tmp_score = max(tmp_score, group[i][2]+group[i+1][2])
		tmp_score += 1
	print tmp_score

Measured memory_bytes: 11132
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;

bool f(pair<ll, ll> a, pair<ll, ll> b, pair<ll, ll> c) {
    return a.first + b.first == c.first && a.second + b.second == c.second;
}


int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    pair<ll, ll> a[50];
    ll n;
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }

    sort(a, a + n);

    set<pair<ll, ll>> d;
    for (ll i = 0; i < n; i++) {
        for (ll j = i + 1; j < n; j++) {
            ll x = a[j].first - a[i].first;
            ll y = a[j].second - a[i].second;
            if (x || y) {
                d.insert(mp(x, y));
            }
        }
    }


    bool vis[n];
    ll ans = n;
    for (auto dif : d) {
        memset(vis, false, sizeof vis);
        ll just = 0;
        for (ll i = 0; i < n; i++) {
            if (!vis[i]) {
                just++;
                auto p = a[i];
                for (ll j = i + 1; j < n; j++) {
                    if (f(p, dif, a[j])) {
                        p = a[j];
                        vis[j] = true;
                    }
                }
            }
        }

        ans = min(ans, just);
    }


    cout << ans;



}




Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
int N;
int H[25];
int main(){
    cin >> N;
    rep(i,N) cin >> H[i];
    int mx = H[0];
    int ct = 0;
    rep(i,N){
        if(H[i] >= mx){
            mx = H[i];
            ct++;
        }
    }
    
    cout << ct << endl;
    
}

Measured memory_bytes: 256
/**
 * Created by hiramekun at 01:18 on 2020-05-12.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */


void solve() {
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) {
        cin >> s[i];
    }

    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            if (s[i][j] == '#') continue;

            vector<vector<ll>> d(h, vector<ll>(w, ll_inf));
            queue<P> q;
            q.push(make_pair(i, j));
            d[i][j] = 0;
            ll tmp = 0;
            while (!q.empty()) {
                ll x = q.front().F, y = q.front().S;
                q.pop();
                rep(k, 4) {
                    ll nx = x + dx[k], ny = y + dy[k];
                    if (nx < 0 || h - 1 < nx || ny < 0 || w - 1 < ny) continue;
                    if (d[nx][ny] < ll_inf || s[nx][ny] == '#') continue;

                    d[nx][ny] = d[x][y] + 1;
                    tmp = max(tmp, d[nx][ny]);
                    q.push(make_pair(nx, ny));
                }
            }
            ans = max(ans, tmp);
        }
    }

    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int n,x,y;
  cin>>n>>x>>y;
  x--;y--;
  std::vector<int> ans(n,0);
  for (int start = 0; start < n; ++start)
  {
    for (int goal = 0; goal < n; ++goal)
    {
      int direct=abs(goal-start);
      int via_xy=abs(x-start)+1+abs(goal-y);
      int via_yx=abs(y-start)+1+abs(goal-x);
      int dist=min({direct,via_xy,via_yx});
      ans[dist]++;
    }
  }
  for (int i = 1; i < n; ++i)
  {
    cout<<ans[i]/2<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if (!((a%2+b%2)%2)) cout << (a+b)/2 << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}



Measured memory_bytes: 256
D = int(input())
A = [[0]*26]*D
S = 0
C = list(map(int,input().split()))
P = 0
ld =[0]*26#最後に行った日の格納
l = [0]*26#損失の計算
sp = 0#一時格納
for i in range(D):
  A[i] = list(map(int,input().split()))
for j in range(D):
  maxvalue = max(A[j])
  index = A[j].index(maxvalue)
  for n in range(26):
    ld[n] = ld[n]+1
  sp = ld[index]
  ld[index] = 0 
  for k in range(26):
    l[k] = C[k]*ld[k]
  lmax =max(l)
  if 13*lmax > maxvalue:
    lindex = l.index(lmax)
    ld[index] = sp
    ld[lindex] = 0
    for m in range(26):
      l[m] = C[m]*ld[m]
  S = S+maxvalue-sum(l)
  print(index+1)

Measured memory_bytes: 9396
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
  cin >> a >> b >> c >> d;
	if(b<=c||d<=a){
		cout << 0 << endl;
		return 0;
	}
	if(b<d){
		if(a>c){
			cout << b-a << endl;
		}else if(a==c){
			cout << b-a << endl;
		}else{
			cout << b-c << endl;
		}
	}else if(b==d){
		if(a>c){
			cout << b-a << endl;
		}else if(a==c){
			cout << b-a << endl;
		}else{
			cout << b-c << endl;
		}
	}else{
		if(a>c){
			cout << d-a << endl;
		}else if(a==c){
			cout << d-a << endl;
		}else{
			cout << d-c << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define N_MAX 100
#define W_MAX 1000000000
#define V_MAX 100000
using namespace std;
//i個目までに価値がv以上になるための最小の重さdp[i][v]
long int dp[N_MAX+1][V_MAX+1]={0};
int w[N_MAX],v[N_MAX];

int main(){
  int N,W,i,k,ans;
  cin>>N>>W;
  dp[0][0]=0;
  for(i=0;i<=V_MAX;i++){
    dp[0][i]=W_MAX+1;
  } 
  for(i=0;i<N;i++){
    cin>>w[i+1]>>v[i+1];
    dp[i][0]=0;
    for(k=1;k<=V_MAX;k++){
      dp[i][k]=W_MAX+1;
    }
  }

  for(i=1;i<=N;i++){
    for(k=1;k<=V_MAX;k++){
      if(k-v[i]>=0){
        dp[i][k]=min(dp[i-1][k],dp[i-1][k-v[i]]+w[i]);
      }else{
        dp[i][k]=dp[i-1][k];
      }
    }
  }
  
  
  for(i=0;i<=V_MAX;i++){
    if(dp[N][i]<=W){
       ans=i;
    }
  }  
  cout << ans << endl; 
}

Measured memory_bytes: 79104
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-ffloat-store")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define endl "\n"
#define f(i,a,b) for(int i=a;i<b;i++)
#define debug(val) printf("check%d\n",val)
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define mod 1000000007
#define inf  1e18
#define ps(x,y)   fixed<<setprecision(y)<<x
#define clr(val) memset(val,0,sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define inp(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    FIO;
    ll n,d;
    cin>>n>>d;
    ll count=0;
    while(n--)
    {
        ll x,y;
        cin>>x>>y;
        if(sqrt((x*x)+(y*y)) <= d )
        count++;
    }
    cout<<count<<endl;
return 0;   
}

Measured memory_bytes: 3644
/*
	https://www.youtube.com/watch?v=766qmHTc2ro
*/
#include <bits/stdc++.h>
using namespace std;

#define ld long double
#define ull unsigned long long
#define ll long long
#define ss string
#define vt vector
#define pii pair <int,int>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define pll pair <ll,ll>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define sz(x) (int) x.size()
#define bcc __builtin_popcount
#define bll __builtin_popcountll
void ___(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
void data(){
	freopen("name.in","r",stdin);
	freopen("name.out","w",stdout);
}
const int N = 3e5 + 500;
const ll INF = 1e18;
const int mod = 1e9 + 7;





int main()
{
	//data();
	___();
	
	
	ss s;
	cin >> s;
	if(s[0] == s[1] and s[0] == 'R' and s[2] == s[0]){
		cout << 3;
		return 0;
	}
	if((s[0] == 'R' and s[0] == s[1]) or (s[1] == s[2] and s[1] == 'R')){
		cout << 2;
		return 0;
	}
	if(s[0] == 'R' or s[1] == 'R' or s[2] == 'R'){
		cout << 1;
	}else cout << 0;
	return 0;
}




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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

Graph graph;
ll dp[100005][2];
bool visited[100005];

ll dfs(int v) {
    dp[v][0] = 1;
    dp[v][1] = 1;
    visited[v] = true;
    for (int u : graph[v]) {
        if (!visited[u]) {
            dfs(u);
            dp[v][0] = dp[v][0] * ((dp[u][0] + dp[u][1]) % MOD);
            dp[v][0] %= MOD;
            dp[v][1] = dp[v][1] * (dp[u][0]);
            dp[v][1] %= MOD;
        }
    }
    return dp[v][0] + dp[v][1];
}

void Main() {
    int N;
    cin >> N;
    graph.resize(N);
    rep(i, N - 1) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    cout << dfs(0) % MOD << '\n';
}

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


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


int f(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(void) {
    int n;
    cin >> n;
    if(n % f(n) == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main()
{
  string s;
  while (getline(cin, s)) {
    if (s == "END OF INPUT")
      break;
    s += " ";
    
    int cnt = 0;
    bool flag = true;
    for (unsigned int i = 0; i < s.size(); ++i) {
      if (s[i] == ' ') {
	cout << cnt;
	if (flag) {
	  cnt = 0;
	  flag = false;
	}
      } else {
	++cnt;
	flag  = true;
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,g=0; cin>>n; 
    vi a(n+1),l(n+2),r(n+2);
    for (int i=0;i<n;i++) cin >> a[i] ; 
    for (int i=0;i<n-1;i++) 
        l[i+1] = __gcd(l[i],a[i]); 
    for (int i=n-1;i>=1;i--) 
        r[i-1] = __gcd(r[i],a[i]); 
    int ans = 0; 
    for (int i=0;i<n;i++) 
        ans = max(ans,__gcd(l[i],r[i])); 
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 5552
""" Created by Jieyi on 9/20/16. """


def main():
    while True:
        num = int(input())
        if num == 0:
            break

        num = str(oct(num)[2:])
        ans = num.translate(str.maketrans('4567', '5789'))
        print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7580
from collections import defaultdict

words = set()
blue = defaultdict(int)
red = defaultdict(int)
for _ in range(int(input())):
    w = input()
    words.add(w)
    blue[w] += 1
for _ in range(int(input())):
    w = input()
    words.add(w)
    red[w] += 1
ans = 0
for w in words:
    ans = max(ans, blue[w] - red[w])
print(ans)


Measured memory_bytes: 3316
#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 ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	int kotae = 0;
	rep1(i, N) {
		if (i == 100000) continue;
		else if (i >= 10000) kotae++;
		else if (i >= 1000) continue;
		else if (i >= 100) kotae++;
		else if (i >= 10) continue;
		else kotae++;
	}

	co(kotae);

	Would you please return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const ll maxn=110000;
ll dp[maxn];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  set<char> s;
  rep(i,n){
    char c; cin>>c;
    s.insert(c);
  }
  if(s.size()==4) cout<<"Four"<<endl;
  else cout<<"Three"<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int a[]=new int[N];
        int b[]=new int[N];
        int S=0; 
        int ans=0;
	    for(int i=0; i<N; i++){
            a[i]=sc.nextInt();
            S^=a[i];
        }
        for(int i=0; i<N; i++){
            b[i]=S^a[i];
            System.out.print(b[i]+" ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 63008
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ll n,m;
cin>>n>>m;
V<ll> a(n),b(n);
for(int i=0;i<n;i++){
    cin>>a[i];
    b[i]=a[i];
    b[i]/=2;
}
bool check=true;
sort(all(a));
while(1){
for(int i=0;i<n;i++){
    if(a[i]%2==0){
        a[i]/=2;
    if(!check){
        cout<<0<<endl;
        return 0;
    }
    }
    else check=false;
}
if(!check)break;
}
ll d=b[0];
for(int i=1;i<n;i++){
    d=lcm(d,b[i]);
}
cout<<(m/d+1)/2<<endl;

}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#define MAX_WH 20
#define MAX_VALUE 10000
using namespace std;


int w,h;//h:i,w:j
int si,sj,gi,gj;


int board[MAX_WH][MAX_WH];

int vx[4] = {1,-1,0,0};
int vy[4] = {0,0,1,-1};


int back(int i, int j,int sum){
	int mi=MAX_VALUE;
	if(sum<11){
		for(int k=0; k<4; k++){
			int pi,pj;
			pi=i+vx[k]; pj=j+vy[k];
			if(-1<pi && pi<h && -1<pj && pj<w && board[pi][pj] != 1){
				while(1){
					if(0>pi || pi>h-1 || 0>pj || pj>w-1)
						break;
					if(pi==gi && pj==gj){
						mi = sum + 1;
						break;
					}
					if(board[pi][pj] == 1){
						board[pi][pj] = 0;
						mi = min(mi, back(pi-vx[k],pj-vy[k],sum+1));
						board[pi][pj] = 1;
						break;
					}
					pi += vx[k]; pj += vy[k];
				}
			}
		}
	}
	return mi;
}

void solve(){
	int n = back(si,sj,0);
	if(n<11){
		printf("%d\n",n);
	} else {
		printf("-1\n");
	}
}	


int main(){
	while(1){
		scanf("%d %d",&w,&h);
		if(w==0 && h==0) break;
		
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				int n;
				scanf(" %d",&n);
				board[i][j] = n;
				if(n==2){
					si = i;
					sj = j;
				} 
				if(n==3){
					gi = i;
					gj = j;
				}
				
			}
		}
		solve();
	}
	return 0;
}

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

int n;
int a[40000],b[40000];

int main(){
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  while(cin>>n && n){
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=0;i<n;i++)cin >> b[i];

    sort(a,a+n,greater<int>());
    sort(b,b+n,greater<int>());

    n >>=1;
    int i;
    for(i=0;i<n;i++){
      if(a[i<<1]>b[i]){
	cout << (i<<1)+1 << endl;
	break;
      }
    }
    if(i==n)cout << "NA\n";
  }
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

int main() {
	int N;
	cin >> N;
	string S;
	vector<int> R(4, 0);
	for (int i = 0;i < N;i++) {
		cin >> S;
		if (S == "AC")R[0]++;
		if (S == "WA")R[1]++;
		if (S == "TLE")R[2]++;
		if (S == "RE")R[3]++;
	}
	cout << "AC x " << R[0];
	cout << "\nWA x " << R[1];
	cout << "\nTLE x " << R[2];
	cout << "\nRE x " << R[3] << "\n";
}

Measured memory_bytes: 3640
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

h,w,a,b = map(int,input().split())
ans = 0

mod = 10**9+7 #出力の制限
N = h+w+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

for i in range(b,w):
    ans += cmb(h-a+i-1,h-a-1,mod) * cmb(a-1+(w-i)-1,a-1,mod)

print(ans%mod)

Measured memory_bytes: 81008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;i++)
const ll INF=1e9;
typedef pair<ll, ll> P;
const ll MAX_N = 10000,MAX_M=10000;

char maze[MAX_N][MAX_M+1];
ll N, M;
ll sx, sy;
ll gx, gy;

ll d[MAX_N][MAX_M];

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

void bfs() {
    queue<P> que;
    //すべての点をINFで初期化
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            if(maze[i][j]=='#'){
                d[i][j]=0;
                que.push(P(i,j));
            }else d[i][j]=INF;
        }
    }

    //キューが空になるまでループ
    while (que.size()) {
        P p=que.front();que.pop();
        for(int i=0;i<4;i++){
            int nx=p.first + dx[i], ny=p.second + dy[i];
            //移動が可能かの判定とすでに訪れたことがあるかの判定
            if(0 <= nx && nx < N && 0 <= ny && ny < M && maze[nx][ny] != '#' && d[nx][ny] == INF){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
}
int main(){
    cin >> N >> M;
    rep(i,N){
        rep(j,M){
            cin >> maze[i][j];
        }
    }
    
    bfs();
    ll res=0;
    rep(i,N)rep(j,M)if(d[i][j]!=INF)res=max(res,d[i][j]);
    cout << res << endl;
}

Measured memory_bytes: 107060
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}

object Main {
  def solve(sc: => Scanner): Unit = {
    val N = sc.nextInt + 1
    var A = 1
    var count = 0
    while (A <= N) {
      A <<= 1
      count += 1
    }
    println(count - 1)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}


Measured memory_bytes: 45132
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail
{
  template <typename T, std::size_t NDIMS>
  struct vector_builder
  {
    using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
      if (!dims.empty())
        dims.pop_back();
      return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
    }
  };

  template <typename T>
  struct vector_builder<T, 1>
  {
    using type = std::vector<T>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      return type(dims.empty() ? 0 : dims.back(), v);
    }
  };
} // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T &v, SIZE_T... dims)
{
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

function<LL(LL, LL)> gcdlambda = [](LL n, LL m) { return __gcd(n, m); };
void solve(long long K)
{
  LL ans = 0;
  for (int i = 1; i <= K; i++)
    for (int j = 1; j <= K; j++)
    {
      LL tmp = gcdlambda(i, j);
      for (int k = 1; k <= K; k++)
      {
        ans += gcdlambda(tmp, k);
      }
    }
  cout << ans << endl;
}

int main()
{
  cout << setprecision(10);
  long long K;
  scanf("%lld", &K);
  solve(K);
  return 0;
}


Measured memory_bytes: 3736
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define FOR(i, c) \
  \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef vector<VB> VBB;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

int main() {
  ll x=0,y=0,k,n,m,h,w,ans=0,sum=0,Max=1,Min=1e9+1;
  string s,t;
  bool ok = false;
  cin >> s;
  char c = s[0];
  rep(i,3){
    if(c == s[i]){
      ans++;
    }
  }
  if(ans == 3)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

string s;

int main() {
    cin >> s;
    int slen = s.length();
    int acnt = 0; int bcnt = 0; int ccnt = 0;
    for(int i = 0; i < slen; ++i) {
        if(s.at(i) == 'a') acnt++;
        else if(s.at(i) == 'b') bcnt++;
        else ccnt++;
    }

    if(abs(acnt-bcnt) <= 1 && abs(acnt-ccnt) <= 1 && abs(bcnt-ccnt) <= 1) {
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 512
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


class Info:
    def __init__(self,arg_num,arg_loc):
        self.num = arg_num
        self.loc = arg_loc

    def __lt__(self,another):
        if self.num != another.num:
            return self.num > another.num
        else:
            return self.loc < another.loc


N,K = map(int,input().split())

Q = []

rest = N
need_out = N-K
out = 0

table = list(map(int,input().split()))

for loc in range(N):
    tmp = table[loc]
    heappush(Q,Info(tmp,loc))
    rest -= 1

    if out+rest >= need_out:
        continue

    info = heappop(Q)
    print("%d"%(info.num),end="")

    while len(Q) > 0 and Q[0].loc <= info.loc:
        heappop(Q)

print("")


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

int main() {
  int N, K, P = 0 ;
  cin >> N >> K ;
  vector<int> vec(N, 0);
  for (int i = 0; i < N; i++) {
      cin >> vec.at(i) ;
  }
  sort(vec.begin(), vec.end()); // {1, 2, 2, 5}

  for (int i = 0; i < K; i++) {
      P = P + vec.at(i) ;
  }

  cout << P << endl;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main(){
    int m, k;
    cin >> m >> k;
    int pm = pow(2, m);
    if(m == 0 && k == 0){
        cout << "0 0" << endl;
    }else if(m == 1 && k == 0){
        cout << "0 0 1 1" << endl;
    }else if(k == 0){
        rep(i, pm)
            cout << i << " ";
        repb(i, pm)
            cout << i << (i ? " " : "");
        cout << endl;
    }else if(m > 1 && k < pm){
        rep(i, pm)
            if(i != k) cout << i << " ";
        cout << k << " ";
        repb(i, pm)
            if(i != k) cout << i << " ";
        cout << k << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int x[n], y[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &x[i]);
    }
    memcpy(y, x, sizeof(int) * n);
    sort(y, &y[n]);
    for (int i = 0; i < n; i++) {
        if (x[i] < y[n / 2]) {
            printf("%d\n", y[n / 2]);
        } else {
            printf("%d\n", y[n / 2 - 1]);
        }
    }
    return 0;
}


Measured memory_bytes: 3712
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	string s;
 	cin>>s;
 	for(char c:s)
 	{
 		if(c=='7')
 		{
 			cout<<"Yes"<<endl;
 			return 0;
 		}
 	}	
 	cout<<"No"<<endl;
 	return 0;
    return 0;
}


Measured memory_bytes: 3652
//02, 12, 2018, 10:00:57 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

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

    cin >> num;

    if(num == 7 || num == 5 || num == 3){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int board[4][4];
	while(cin >> board[1][1] >> board[1][2] >> board[1][3] >> board[2][1] >> board[2][2] >> board[2][3] >> board[3][1] >> board[3][2] >> board[3][3])
	{
		int flag = 1;
		if((board[1][2] - board[1][1] != board[2][2] - board[2][1]) || (board[3][2] - board[3][1] != board[2][2] - board[2][1]) || (board[3][3] - board[3][2] != board[2][3] - board[2][2]) || (board[1][3] - board[1][2] != board[2][3] - board[2][2]) || (board[2][1] - board[1][1] != board[2][2] - board[1][2]) || (board[2][3] - board[1][3] != board[2][2] - board[1][2]) || (board[3][1] - board[2][1] != board[3][2] - board[2][2]) || (board[3][3] - board[2][3] != board[3][2] - board[2][2]))
			flag = 0;
		if(flag)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s=list(input())
c=0
if s[0]=="A" and "C" in s[2:-1]:
    s.remove("A")
    s.remove("C")
    for i in s:
        if i in "abcdefghijklmnopqrstuvwxyz":c+=1
        else:print("WA");break
    if c==len(s):print("AC")
    else:("WA")
else:print("WA")

Measured memory_bytes: 3060
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
S = 0
for i in range(len(N)):
	S += int(N[i])

print("Yes" if int(N)%S == 0 else "No")

Measured memory_bytes: 5148
def distance(x, y, p):
    return sum([abs(i - j) ** p for i, j in zip(x, y)]) ** (1 / p)

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

[print('{:f}'.format(distance(x, y, _))) for _ in range(1, 4)]
print('{:f}'.format(max([abs(i - j) for i, j in zip(x, y)])))


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

int main()
{
	int N, t, x, y;
	cin >> N;

	bool valid = true;

	for (int i = 0; i < N; i++)
	{
		cin >> t >> x >> y;

		if (valid)
			valid &= t >= x + y && (t - x - y) % 2 == 0;
	}

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

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,count=0;
  scanf("%d",&n);
  int p[n];
  for(i=0;i<n;i++)
    scanf("%d",&p[i]);
  for(i=1;i<n-1;i++){
    if((p[i]-p[i-1])*(p[i]-p[i+1])<0)
      count++;
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define fo(i,n) for(int i=1;i<=n;i++)
#define fo1(i,n) for(int i=0;i<n;i++)
#define lli long long int
#define llu unsigned long long int
#define vi vector <int>
#define vii vector <long long int>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define mk make_pair
#define mpp map<int,int>
#define ff first
#define ss second
#define mod 1000000007

using namespace std;

void loop()
{
	int x1,x2,x3,x4,x5;
	cin>>x1>>x2>>x3>>x4>>x5;
	if(x1==0)
		cout<<1<<"\n";
	if(x2==0)
		cout<<2<<"\n";
	if(x3==0)
		cout<<3<<"\n";
	if(x4==0)
		cout<<4<<"\n";
	if(x5==0)
		cout<<5<<"\n";
}

int main()
{
	fast;
	loop();
}


Measured memory_bytes: 3120