akhauriyash/Code-Regression huggingface dataset:
import sys
import math
input = sys.stdin.readline
MOD = 10**9 + 7

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

# dp[i][j], i:processed i-th item, j:status
dp = [[n] * (n + 1) for _ in range(5)]
for i in range(5):
    dp[i][0] = 0
for i, item in enumerate(a):
    if item != 0:
        odd_cost = (item % 2 == 1)
        even_cost = (item % 2 == 0)
        # from 0 
        dp[0][i+1] = min(dp[0][i+1], dp[0][i] + item)
        dp[1][i+1] = min(dp[1][i+1], dp[0][i] + odd_cost)
        dp[2][i+1] = min(dp[2][i+1], dp[0][i] + even_cost)
        dp[3][i+1] = min(dp[3][i+1], dp[0][i] + odd_cost)
        dp[4][i+1] = min(dp[4][i+1], dp[0][i] + item)
        # from 1
        dp[1][i+1] = min(dp[1][i+1], dp[1][i] + odd_cost)
        dp[2][i+1] = min(dp[2][i+1], dp[1][i] + even_cost)
        dp[3][i+1] = min(dp[3][i+1], dp[1][i] + odd_cost)
        dp[4][i+1] = min(dp[4][i+1], dp[1][i] + item)
        # from 2
        dp[2][i+1] = min(dp[2][i+1], dp[2][i] + even_cost)
        dp[3][i+1] = min(dp[3][i+1], dp[2][i] + odd_cost)
        dp[4][i+1] = min(dp[4][i+1], dp[2][i] + item)
        # from 3
        dp[3][i+1] = min(dp[3][i+1], dp[3][i] + odd_cost)
        dp[4][i+1] = min(dp[4][i+1], dp[3][i] + item)
        # from 4
        dp[4][i+1] = min(dp[4][i+1], dp[4][i] + item)
    else:
        # from 0 
        dp[0][i+1] = min(dp[0][i+1], dp[0][i])
        dp[1][i+1] = min(dp[1][i+1], dp[0][i] + 2)
        dp[2][i+1] = min(dp[2][i+1], dp[0][i] + 1)
        dp[3][i+1] = min(dp[3][i+1], dp[0][i] + 2)
        dp[4][i+1] = min(dp[4][i+1], dp[0][i])
        # from 1
        dp[1][i+1] = min(dp[1][i+1], dp[1][i] + 2)
        dp[2][i+1] = min(dp[2][i+1], dp[1][i] + 1)
        dp[3][i+1] = min(dp[3][i+1], dp[1][i] + 2)
        dp[4][i+1] = min(dp[4][i+1], dp[1][i])
        # from 2
        dp[2][i+1] = min(dp[2][i+1], dp[2][i] + 1)
        dp[3][i+1] = min(dp[3][i+1], dp[2][i] + 2)
        dp[4][i+1] = min(dp[4][i+1], dp[2][i])
        # from 3
        dp[3][i+1] = min(dp[3][i+1], dp[3][i] + 2)
        dp[4][i+1] = min(dp[4][i+1], dp[3][i])
        # from 4
        dp[4][i+1] = min(dp[4][i+1], dp[4][i])

ans = n
for line in dp:
    ans = min(ans, line[n])
print(ans)

Measured memory_bytes: 39548
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,M;
  cin>>N;
  vector<int> money(N);
  vector<string> NString(N);
  for(int i=0;i<N;i++){
    cin>>NString.at(i);
  }
  cin>>M;
  vector<string> MString(M);
  for(int i=0;i<M;i++){
    cin>>MString.at(i);
  }
  
  int n1=0,n2=0;
  string re1,re2;
  for(int i=0;i<N;i++){
    re1=NString.at(i);
    for(int j=0;j<N;j++){
      re2=NString.at(j);
      if(re1==re2)
        money.at(i)++;
    }
    for(int j=0;j<M;j++){
      re2=MString.at(j);
      if(re1==re2)
        money.at(i)--;
    }
  }
  int most=0;
  for(int i=0;i<N;i++){
    if(most<money.at(i))
      most=money.at(i);
  }
  if(most<0)
    most=0;
  cout<<most<<endl;
  
}

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

void SplitDigit(int n,int number[5]){
  int i=0;
while(n>0){
number[i]=n%10;
  n/=10;
  i++;
}
}
int main(){
int A,B;
int i;
cin>>A>>B;
  int res=0;
  int number[5];
  for(i=A;i<=B;i++){
    SplitDigit(i,number);
    if(number[0]==number[4]&&number[1]==number[3]){
    res++;
    }
  }
  cout<<res;
      }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int n,m,s=0,c;
  cin>>n>>m;
  r(i,n){int k=0; 
    r(j,m)if(cin>>c&&c)k++;
    s=max(s,k);
  }cout<<s<<endl;
}

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

using ll = long long int;
const int MAX_N = (int)(200000 + 5);

ll n;
ll a[MAX_N], b[MAX_N];

ll k;
ll ma[MAX_N], mb[MAX_N];
ll *low;
ll *upp;
ll numodd;
ll ansxor;

int main(void) {
  // Here your code !
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {scanf("%lld", &(a[i]));}
  for (int i = 0; i < n; ++i) {scanf("%lld", &(b[i]));}

	for (int k = 0; k < 30; ++k) {
    ll t = pow(2, k);
    for (int i = 0; i < n; ++i) {ma[i] = a[i] % (2 * t);}
    for (int i = 0; i < n; ++i) {mb[i] = b[i] % (2 * t);}

    sort(mb, mb + n);

    ll whole = 0;
    for (int i = 0; i < n; ++i) {
      low = lower_bound(mb, mb + n, 1 * t - ma[i]);
      upp = upper_bound(mb, mb + n, 2 * t - ma[i] - 1);
      numodd = upp - low;

      whole += numodd;

      low = lower_bound(mb, mb + n, 3 * t - ma[i]);
      upp = upper_bound(mb, mb + n, 4 * t - ma[i] - 1);
      numodd = upp - low;

      whole += numodd;
    }

    if (whole % 2 == 1) ansxor += t;
  }

  printf("%lld\n", ansxor);

	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
const int maxk=1e5+5;
int a[maxn];
bool valid[maxk];
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//    fl();
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=k;i++)
		for(int j=1;j<=n;j++)
			if(i>=a[j])
				valid[i]|=(!valid[i-a[j]]);
	if(valid[k]) 
		puts("First");
	else puts("Second"); 
	return 0;
}


Measured memory_bytes: 3820
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int N = sc.nextInt();
    int lo = 0;
    int hi = N;
    int base = query(0);
    if (base == 0) return;
    for (int i = 1; i < 20; i++) {
      if (hi - lo - 1 <= 20 - i) {
        for (int j = lo + 1; j < hi; j++) {
          int res = query(j);
          if (res == 0) return;
        }
      }
      int mid = lo + (hi - lo) / 2;
      int cur = query(mid);
      if (cur == 0) return;
      int expect = base * ((mid - lo) % 2 == 0 ? 1 : -1);
      if (cur == expect) {
        lo = mid;
        base = cur;
      } else {
        hi = mid;
      }
    }
  }

  static int query(int pos) {
    System.out.println(pos);
    System.out.flush();
    String s = sc.next();
    if (s.equals("Male")) {
      return 1;
    } else if (s.equals("Female")) {
      return -1;
    } else {
      return 0;
    }
  }

}


Measured memory_bytes: 24360
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a==b && b==c){
    printf("1\n");
  }else if(a==b || b==c || c==a){
    printf("2\n");
  }else{
    printf("3\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll N;
    ll A[MAX_N], B[MAX_N], C[MAX_N];
    ll l[MAX_N + 1], u[MAX_N + 1];
    ll answer = 0;

    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];

    sort(A, A + N);
    sort(B, B + N);
    sort(C, C + N);

    l[0] = 0;
    u[N] = 0;
    rep(i, N){
        l[i + 1] = l[i];
        u[N - i - 1] = u[N - i];
        For(j, l[i], N) if (A[j] < B[i]) l[i + 1] ++; else break;
        For(j, u[N - i], N) if (B[N - i - 1] < C[N - j - 1]) u[N - i - 1] ++; else break;
    }

    rep(i, N) answer += l[i + 1] * u[i];

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 4096
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

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

vector<ll> enum_div(ll n)  // nの約数を列挙
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

map<ll, ll> prime_factor(ll n) {
    map<ll, ll> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A, B;
    cin >> A >> B;

    ll cd = gcd(A, B);
    map<ll, ll> pr = prime_factor(cd);
    cout << pr.size() + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  	int flag=0;
    string s;
    cin >> s;
    map<char,int> mp;
    rep(i,s.length()){
        mp[s[i]]=0;
    }
    for(char j='a';j<='z';j++){
        if(!(mp.count(j))){
            cout << j << endl;
            flag=1;
          	break;
        }
    }
    if(!flag)cout << "None" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

typedef pair<int, int> P;

P nukumori(char a) {
    if (a == 'A') {
        return P(0, 0);
    } else if (a == 'B') {
        return P(1, 0);
    } else if (a == 'C') {
        return P(2, 0);
    } else if (a == 'D') {
        return P(0, 1);
    } else if (a == 'E') {
        return P(1, 1);
    } else if (a == 'F') {
        return P(2, 1);
    } else if (a == 'G') {
        return P(0, 2);
    } else if (a == 'H') {
        return P(1, 2);
    } else {
        return P(2, 2);
    }
}

int sx, sy, gx, gy, ox, oy;
double memo[3][3][20];

double rec(int x, int y, int times) {
    if (memo[x][y][times] >= 0.0) return memo[x][y][times];

    if (times == 0) {
        if (x == gx && y == gy) {
            return 1.0;
        } else {
            return 0.0;
        }
    }

    double res = 0.0;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx >= 0 && nx < 3 && ny >= 0 && ny < 3 &&
                !(nx == ox && ny == oy)) {
            res += rec(nx, ny, times - 1) / 4.0;
        } else {
            res += rec(x, y, times - 1) / 4.0;
        }
    }
    return memo[x][y][times] = res;
}

int main(){
    int n;
    char s, t, b;
    while (scanf("%d", &n), n) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 20; k++) {
                    memo[i][j][k] = -1.0;
                }
            }
        }
        cin >> s >> t >> b;

        P temps = nukumori(s),
          tempt = nukumori(t),
          tempb = nukumori(b);

        sx = temps.first; sy = temps.second;
        gx = tempt.first; gy = tempt.second;
        ox = tempb.first; oy = tempb.second;

        printf("%.10f\n", rec(sx, sy, n));
    }

    return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#include <queue>
#include <cassert>
#include <cstdio>
#define int long long
using namespace std;
signed main()
{
    string s;
    cin >> s;
    if (s.size() < 4){
        cout << "No" << endl;
    }
    else{
        if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 999999

//?´???°??????
bool isPrime(int x) {
	if (x < 2)return 0;
	else if (x == 2)return 1;
	if (x % 2 == 0)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}

//??¨????????????????????????
//n??\????????£??´??°????´???°???????????°???????????????is_prime[]???????´?
void eratos(int n, bool is_prime[]) {
	fill(is_prime, is_prime + n, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i*i <= n; i++) {
		if (is_prime[i]) {
			int j = i + i;
			while (j <= n) {
				is_prime[j] = false;
				j = j + i;
			}
		}
	}
}

int main() {
	bool is_prime[MAX];
	eratos(MAX, is_prime);

	for (int n; cin >> n;) {
		int cnt = 0;
		for (int i = 0; i <= n; i++) {
			if (is_prime[i])cnt++;
		}
		cout << cnt << endl;;
	}
	return 0;
}

Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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

#define S second
#define F first
#define int long long  

//////////

signed main()
{
    fastio;
    int n;
    cin>>n;
    long double a[n+1][n+1];
    for(int i=0;i<=n;++i)
        for(int j=0;j<=n;++j)
            a[i][j]=0;
    long double p;
    cin>>p;
    a[1][0]=1-p;
    a[1][1]=p;
    for(int i=2;i<=n;++i)
    {
        cin>>p;
        for(int j=0;j<=i;++j)
        {
            if(j==0)
                a[i][j]=a[i-1][j]*(1-p);
            else
            {
                a[i][j]=a[i-1][j]*(1-p)+a[i-1][j-1]*(p);
            }
        }
    }
    long double ans=0;
    for(int i=0;i<=n;++i)
    {
        if(i>n-i)
        {
            ans+=a[n][i];
        }
    }
    cout<<fixed<<setprecision(15)<<ans;
}

Measured memory_bytes: 140928
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,n,s) for(int i=(int)(s);i<(int)(n);++i)
#define RREP(i,n,s) for(int i=(int)(s);i>=(int)(n);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n;cin>>n;
    vector<ii> r(n), b(n);
    REP(i,n) {
        int x,y;cin>>x>>y;
        r[i] = make_pair(x,y);
    }
    REP(i,n) {
        int x,y;cin>>x>>y;
        b[i] = make_pair(x,y);
    }

    auto cmpX = [](const ii& a, const ii& b){
        return a.first < b.first;
    };
    auto cmpY = [](const ii& a, const ii& b){
        return a.second < b.second;
    };

    sort(ALL(r), cmpX);
    sort(ALL(b), cmpX);

    int ans = 0;
    REP(i,n) {
        auto itr = lower_bound(ALL(r), b[i], cmpX);
        if (itr == r.begin()) continue;

        auto maxitr = r.end();
        int maxy = -1;
        for(auto j = r.begin();j!=itr;++j) {
            if(j->second > maxy && j->second < b[i].second) {
                maxitr = j;
                maxy = j->second;
            }
        }
        if(maxitr != r.end()) {
            r.erase(maxitr);
            ans++;
        }
    }

    cout << ans << endl;
}


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

using namespace std;

using ll=long long;

constexpr ll INF = 1e15;

ll train[20][100][100];
ll tr[100][100];
int p[20];

ll dc(ll d, vector<ll>&q, vector<ll>&r){
    int qs=q.size();
    if(qs==0)return d*r[0];
    ll ret=0, pre=0;
    for(int i=0;i<qs;++i){
        if(q[i]<d){
            ret+=(q[i]-pre)*r[i];
            pre=q[i];
        }
        else{
            ret+=(d-pre)*r[i];
            return ret;
        }
    }
    return ret+(d-q[qs-1])*r[qs];
}

int main(){
    int n,m,c,s,g;
    while(cin>>n>>m>>c>>s>>g,n){
        for(int i=0;i<20;++i){
            for(int j=0;j<100;++j){
                for(int k=0;k<100;++k)train[i][j][k]=INF;
            }
        }
        for(int i=0;i<100;++i){
            for(int j=0;j<100;++j){
                tr[i][j]=INF;
            }
        }
        for(int i=0;i<m;++i){
            ll x,y,d,co;
            cin>>x>>y>>d>>co;
            train[co-1][x-1][y-1]=train[co-1][y-1][x-1]=min(train[co-1][x-1][y-1], d);
        }
        for(int i=0;i<c;++i){
            for(int k=0;k<n;++k){
                for(int u=0;u<n;++u){
                    for(int v=0;v<n;++v){
                        if(train[i][u][v]>train[i][u][k]+train[i][k][v]){
                            train[i][u][v]=train[i][u][k]+train[i][k][v];
                        }
                    }
                }
            }
        }
        for(int i=0;i<c;++i){
            cin>>p[i];
        }
        for(int i=0;i<c;++i){
            vector<ll>q(p[i]-1),r(p[i]);
            for(int j=0;j<p[i]-1;++j)cin>>q[j];
            for(int j=0;j<p[i];++j)cin>>r[j];
            for(int u=0;u<n;++u){
                for(int v=0;v<n;++v){
                    if(train[i][u][v]==INF)continue;
                    tr[u][v]=min(tr[u][v],dc(train[i][u][v],q,r));
                }
            }
        }
        for(int k=0;k<n;++k){
            for(int i=0;i<n;++i){
                for(int j=0;j<n;++j){
                    if(tr[i][j]>tr[i][k]+tr[k][j]){
                        tr[i][j]=tr[i][k]+tr[k][j];
                    }
                }
            }
        }
        if(tr[s-1][g-1]==INF)cout<<-1<<endl;
        else cout<<tr[s-1][g-1]<<endl;
    }
}


Measured memory_bytes: 4736
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    ArrayList<Integer> menu = new ArrayList<Integer>();
    while (sc.hasNext()) {
      menu.add(sc.nextInt());
    }
    int min =10, total =0, last =0;
    for (int j=1; j<10; j++) {
      for (int i=0; i<menu.size(); i++) {
        if (menu.get(i) % 10 == 0) continue;
        if (menu.get(i) % 10 < min) {
          min = menu.get(i) % 10;
          last = i;
        }
      }
    }
    for (int i=0; i<menu.size(); i++) {
      if (i == last) continue;
      double ex = Math.ceil((double)menu.get(i)/10);
      total += ex * 10;
    }
    total += menu.get(last);
    System.out.println(total);
  }
}

Measured memory_bytes: 22612
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int A[510][510];
int B[251000][4];

int main(){
  int h,w;
  cin>>h>>w;
  
  int x;
  rep(i,h){
    rep(j,w){
      cin>>x;
      A[i+1][j+1]=x%2;
    }
  }
  
  int k=0;
  bool b=false;
  int tmph,tmpw;
  for(int i=1;i<=h;i++){
    if(i%2==1){
      for(int j=1;j<=w;j++){
        if(b==false && A[i][j]%2==1){
          tmph=i,tmpw=j;
          b=true;
        }
        else if(b==true){
          B[k][0]=tmph,B[k][1]=tmpw,B[k][2]=i,B[k][3]=j;
          k++;
          if(A[i][j]%2==1) b=false;
          else tmph=i,tmpw=j;
        }
      }
    }
    else{
      for(int j=w;j>=1;j--){
        if(b==false && A[i][j]%2==1){
          tmph=i,tmpw=j;
          b=true;
        }
        else if(b==true){
          B[k][0]=tmph,B[k][1]=tmpw,B[k][2]=i,B[k][3]=j;
          k++;
          if(A[i][j]%2==1) b=false;
          else tmph=i,tmpw=j;
        }
      }
    }
  }
  
  cout<<k<<endl;
  rep(i,k) cout<<B[i][0]<<" "<<B[i][1]<<" "<<B[i][2]<<" "<<B[i][3]<<endl;

  return 0;
}

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

const int N = 1e5 + 5;

int a, b, c, n;
string s[N];
char ans[N];

int main() {
	cin>>n>>a>>b>>c;
	for(int i = 1; i <= n; i++)
		cin>>s[i];
	for(int i = 1; i <= n; i++) {
		if(s[i] == "AB") {
			if(a == b) {
				if(s[i + 1] == "AC") a++, b--, ans[i] = 'A';
				else a--, b++, ans[i] = 'B'; 
			}
			else {
			    if(a > b) a--, b++, ans[i] = 'B';
			    else a++, b--, ans[i] = 'A';
			}
		}
		if(s[i] == "AC") {
			if(a == c) {
				if(s[i + 1] == "AB") a++, c--, ans[i] = 'A';
				else a--, c++, ans[i] = 'C'; 
			}
			else {
			    if(a > c) a--, c++, ans[i] = 'C';
			    else a++, c--, ans[i] = 'A';
			}
		}
		if(s[i] == "BC") {
			if(c == b) {
				if(s[i + 1] == "AC") c++, b--, ans[i] = 'C';
				else c--, b++, ans[i] = 'B'; 
			}
			else {
			    if(c > b) c--, b++, ans[i] = 'B';
			    else c++, b--, ans[i] = 'C';
			}
		}				
		if(min(a, min(b, c)) < 0) {
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	for(int i = 1; i <= n; i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 6860
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.input()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.input();
    let k: usize = sc.input();
    const MOD: usize = 1_000_000_007;

    let mut ans: usize = 0;
    for x in k..=n + 1 {
        let a  = x * (x - 1) / 2;
        let b = (n * 2 - x + 1) * x / 2;
        let add = b - a+ 1;
        ans = (ans + add) % MOD;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2148
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		long ans=0;
		while(y>=x){
			x*=2;
			ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 20560
#include <stdio.h>
#include <stdlib.h>
int main(void) {
  long long int x, k, d;
  long long int q, r;
  scanf("%lld%lld%lld", &x, &k, &d);
  x = llabs(x);
  d = llabs(d);
  q = x/d;
  r = x%d;
  if (k <= q) {
    printf("%lld", x - d*k);
    return 0;
  }
  if ((k-q)%2==0) {
    printf("%lld", r);
    return 0;
  }
  if ((k-q)%2!=0) {
    printf("%lld", d-r);
    return 0;
  }
}

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

using ll = long long;

const ll MOD = 1e9 + 7;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int N; cin >> N;
	vector<pair<int, bool>> coords;
	coords.reserve(2*N);
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		coords.emplace_back(a, false);
	}
	for (int i = 0; i < N; i++) {
		int b; cin >> b;
		coords.emplace_back(b, true);
	}
	sort(coords.begin(), coords.end());
	int cnts[2] = {};
	ll ans = 1;
	for (auto it : coords) {
		bool t = it.second;
		if (cnts[!t]) {
			ans *= cnts[!t];
			ans %= MOD;
			cnts[!t]--;
		} else {
			cnts[t]++;
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
long long a,b,c,x,y,s,minn,maxx,z,ans;
int main()
{
	cin>>a>>b>>c>>x>>y;
	s=a+b;
	minn=min(x,y);
	maxx=max(x,y);
	z=maxx-minn;
	if(s>=2*c)
	{
	
	ans+=minn*2*c;
	if(a<=2*c&&x==maxx)
	{
		ans+=z*a;
	}
	else if(a>2*c&&x==maxx)
	{
		ans+=z*2*c;
	}
	else if(b>2*c&&y==maxx)
	{
		ans+=z*2*c;
	}
	else if(a<=2*c&&y==maxx)
	{
		ans+=z*b;
	}	
	}
	else if(s<2*c)
	{
		
	ans+=minn*s;
	if(a<=2*c&&x==maxx)
	{
		ans+=z*a;
	}
	else if(a>2*c&&x==maxx)
	{
		ans+=z*2*c;
	}
	else if(b>2*c&&y==maxx)
	{
		ans+=z*2*c;
	}
	else if(a<=2*c&&y==maxx)
	{
		ans+=z*b;
	}	
	}
	cout<<ans;
	return 0;
	
} 

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

int k, s;

int main() {
	cin >> k >> s;
	
	int ans = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (0 <= z && z <= k) {
				ans++;
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function main(input) {
  var lines = input.split('\n');

  var _lines = _slicedToArray(lines, 2),
      S = _lines[0],
      T = _lines[1];

  var sr = representation(S);
  var tr = representation(T);
  var result = String(sr) === String(tr) ? "Yes" : "No";
  console.log(result);
}

function representation(str) {
  var result = [];
  var map = new Map();
  var nextid = 0;
  var _iteratorNormalCompletion = true;
  var _didIteratorError = false;
  var _iteratorError = undefined;

  try {
    for (var _iterator = str[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
      var char = _step.value;

      if (map.has(char)) {
        result.push(map.get(char));
      } else {
        map.set(char, nextid);
        result.push(nextid);
        nextid++;
      }
    }
  } catch (err) {
    _didIteratorError = true;
    _iteratorError = err;
  } finally {
    try {
      if (!_iteratorNormalCompletion && _iterator.return != null) {
        _iterator.return();
      }
    } finally {
      if (_didIteratorError) {
        throw _iteratorError;
      }
    }
  }

  return result;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


Measured memory_bytes: 24048
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  deque<int> b;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (i % 2 == n % 2) {
      b.push_back(a[i]);
    } else {
      b.push_front(a[i]);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << b[i] << flush;
    if (i < n - 1)
      cout << " " << flush;
    else
      cout << endl;
  }
  return 0;
}

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

int main(){
    int n;
    while(cin >> n, n){
        bool sink = true, l = true, r = true;
        int ans = 0;
        string op;
        for(int i = 0; i < n; i++){
            cin >> op;
            if(op == "lu")  l = false;
            if(op == "ru")  r = false;
            if(op == "ld")  l = true;
            if(op == "rd")  r = true;
            if(l == r && l != sink){
                ans++;
                sink = !sink;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

signed main()
{
    int a,b,a1=0,b1=0;
    cin>>a>>b;
    for (int i=1; i<=a; i++) b1=b1*10+b;
    for (int i=1; i<=b; i++) a1=a1*10+a;
    if (a1>b1) cout<<a1;
    else cout<<b1;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a = N % 10;
		if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9) {
			System.out.println("hon");
		} else if (a == 0 || a == 1 || a == 6 || a == 8) {
			System.out.println("pon");
		} else {
			System.out.println("bon");
		}
	}
}


Measured memory_bytes: 35740
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;
 
int main(){
  int a,b;
  cin >> a >> b;
  int orib=0;
  for(int i=1; i<=b-a; i++){ orib += i;}
  int ans = orib-b;
  cout << ans << endl;
  return 0;
}


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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

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

const int INF = 1e9;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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; }


int main(void){
  ios::sync_with_stdio(false);

  int M1, D1, M2, D2;
  int ans;
  cin >> M1 >> D1 >> M2 >> D2;
  if (M1 != M2){ans = 1;}
  else ans = 0;
  cout << ans << endl;



  return 0;
}



Measured memory_bytes: 256
#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 memo[1001001];
int used[1001001];
int topo[1001001];
int t, yabai;
vector<int> E[1001001];
int dfs(int p){
	if (used[p]) return memo[p];
	used[p] = 1;
	if (memo[p]) return memo[p];
	int ret = 1;
	for (int to : E[p]) {
		ret = max(ret, dfs(to) + 1);
	}
	topo[p] = t++;
	return memo[p] = ret;
}

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


	int N;
	cin >> N;
	int A[1001][1001];
	rep1(i, N) rep(j, N - 1) {
		cin >> A[i][j];
	}

	rep1(i, N) rep(j, N - 2) {
		int a = i;
		int b = A[i][j];
		if (a > b) swap(a, b);
		int k1 = 1000 * a + b;
		a = i;
		b = A[i][j + 1];
		if (a > b) swap(a, b);
		int k2 = 1000 * a + b;
		E[k1].pb(k2);
	}

	int kotae = 0;
	rep1(i, N - 1) for (int j = i + 1; j <= N; j++) {
		int k = 1000 * i + j;
		kotae = max(kotae, dfs(k));
		for (int to : E[k]) {
			if (topo[k] < topo[to]) yabai = 1;
		}
	}
	if (yabai) co(-1);
	else co(kotae);

	Would you please return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

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

    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    vector<vector<int>> dis(h, vector<int>(w, INF));
    queue<P> que;
    for (int i = 0; i < h; i++)
    {
        cin >> a[i];
        for (int j = 0; j < w; j++)
        {
            if (a[i][j] == '#')
            {
                dis[i][j] = 0;
                que.push(P(i, j));
            }
        }
    }
    while (!que.empty())
    {
        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 (nx < 0 || h <= nx || ny < 0 || w <= ny)
                continue;
            if (dis[nx][ny] != INF)
                continue;
            dis[nx][ny] = dis[p.first][p.second] + 1;
            que.push(P(nx, ny));
        }
    }
    int ret = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            ret = max(ret, dis[i][j]);
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 13456
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

A, B, C = [x for x in input().split()]
print("{} {} {}".format(C,A,B))

Measured memory_bytes: 3060
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
check={}
for c in s:
    if c not in check:
        check[c]=1
    else:
        check[c]+=1
for c in t:
    if c in check:
        check[c]-=1
M=0
for c in check:
    M=max(M,check[c])
print(M)


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


int main(){
  cin >> h >>n;
  vector<int> dp(h+1, inf);
  dp.at(0) = 0;
  
  rep(i,n){
    int a, b;
    cin >> a >> b;
    rep(j,h){
      int nj = min(j+a,h);
      dp.at(nj) = min(dp.at(nj), dp.at(j)+b);
    }
  }
  cout << dp.at(h) << endl;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(i%2!=0){
      if(s.at(i)!='L'&&s.at(i)!='U'&&s.at(i)!='D'){
        cout<<"No"<<endl;
        return 0;
        }
    }else{
      if(s.at(i)!='R'&&s.at(i)!='U'&&s.at(i)!='D')
      {
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
stack<int> st[111111],s;
int a[111111],n;

int main() {
  cin >> n;
  for(int i=0,x; i<n; i++) {
    cin >> x;
    st[x-1].push(i+1);
  }
  for(int k=0; k<2; k++) {
    for(int i=0; i<n; i++) {
      while(!st[i].empty()) s.push(st[i].top()),st[i].pop();
      if(!a[i]&&!s.empty()) a[i]=s.top(),s.pop();
    }
  }
  for(int i=0; i<n; i++) cout << a[i] << endl;
  return 0;
}


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

int a[100010];

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

    int n;
    cin>>n;

    int cnt2=0,cnt4=0;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;

        if(a%2==0)
        {
            if(a%4==0)cnt4++;
            else cnt2++;
        } 
    }

    puts(cnt4*2+1>=n||cnt4*2+cnt2>=n?"Yes":"No");

    return 0;
}


Measured memory_bytes: 3656
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = solve <$> f <*> f >>= print
  where
    f = readil B.readInt <$> B.getLine

solve :: [Int] -> [Int] -> Int
solve [n, k] = sum . drop k . sortBy (flip compare)

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')


Measured memory_bytes: 31100
from collections import Counter
n=int(input())
s = [input() for i in range(n)]
# 各要素の計算
calc=Counter(s)

# print(calc.most_common()[0])
m=0

for v in calc.values():
  m=max(m,v)
ans = []
for k, v in calc.items():
  if v==m:
    ans.append(k)
ans.sort()
# print(*ans, sep="\n")
print('\n'.join(ans))
# print(s)
# for i in range(len(s)):
#   print(s[i])
# print([i for i in if calc.most_common()[i][1])

Measured memory_bytes: 35952
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rRep(i,a,b) for(int i = a; i >= b; i--)
#define rrep(i,a) rRep(i,a,0)
#define allof(a) (a).begin(), (a).end()

const int inf = 1e9+7;
const ll infll = 1 << 60;
const ll mod = 1e9 + 7;

// 型による変数のオーバーフローに気をつけろ！！

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);

	rep(i, n) {
		cin >> a[i];
		a[i] -= (i + 1);
	}

	ll ans = 0;
	// aの中間の点を求める
	sort(allof(a));
	ll num = a[n / 2];
	//if (num < 0) num = 0;
	ll sum = 0;
	rep(i, n) {
		sum += abs(a[i] - num);
	}
	// O(n^2)で解きたいがどうしたものか

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
	"go/token"
	"go/types"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	ans := ""
	for i := 0; i < 8; i++ {
		formula := string(s[0])
		for j := 0; j < 3; j++ {
			if i&(1<<uint(j)) > 0 {
				formula += "+"
			} else {
				formula += "-"
			}
			formula += string(s[j+1])
		}
		result, err := types.Eval(token.NewFileSet(), nil, token.NoPos, formula)
		if err != nil {
			panic(err)
		}
		calcedValue, err := strconv.Atoi(result.Value.String())
		if err != nil {
			panic(err)
		}

		if calcedValue == 7 {
			ans = formula + "=7"
			break
		}
	}

	fmt.Println(ans)
}


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

int f(double x) {
  return (x >= 165.0) + (x >= 170.0) + (x >= 175.0) +
         (x >= 180.0) + (x >= 185.0);
}

void solve() {
  int n;
  cin >> n;
  vi v(6);
  rep(i, n) {
    double h;
    cin >> h;
    v[f(h)]++;
  }
  rep(i, 6) cout << i + 1 << ':' << string(v[i], '*') << endl;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define print(x) cout<<x<<endl;

int main() {
	string a, b;
	cin >> a >> b;
	if (a == "H" && b == "H") {
		print("H")
	}
	else if(a == "H" && b == "D") {
		print("D");
	}
	else if(a == "D" && b == "D") {
		print("H");
	}
	else if(a == "D" && b == "H") {
		print("D");
	}
}

Measured memory_bytes: 256
#include<algorithm>
#include<cassert>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const int DEBUG=0;

typedef long long ll;
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2236726
struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;
 
public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
 
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }
 
    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] = -node[k];
            if(r - l > 1) {
                lazy[2*k+1] ^=1;
                lazy[2*k+2] ^=1;
            }
            lazy[k] = 0;
        }
    }
 
    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }
 
    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

const int N=110000;
vi ch[N];
int st[N],en[N];
int cnt=0;
void dfs(int v){
  cnt++;
  st[v]=cnt;
  rep(i,ch[v].size()){
    int w=ch[v][i];
    dfs(w);
  }
  en[v]=cnt;
}


int main(){
  int n,q;
  cin>>n>>q;
  vi p(n,-1);
  rep(i,n-1){
    cin>>p[i+1];
    p[i+1]--;
    ch[p[i+1]].push_back(i+1);
  }
  vi c(n);
  rep(i,n){
    char k;
    cin>>k;
    c[i]=k=='G';
  }
  dfs(0);
  assert(cnt==n);
  if(DEBUG){
    rep(i,n){
      cerr<<"vert " << i << "["<<st[i]<<","<<en[i]<<"]"<<endl;
    }
  }
  vector<lint> dat(n+1);
  rep(i,n){
    dat[st[i]]=2*c[i]-1;
  }
  LazySegmentTree lst(dat);
  rep(i,q){
    int v;
    cin>>v;
    v--;
    lst.add(st[v],en[v]+1,1);
    if(lst.getsum(1,n+1)>0){
      cout<<"broccoli"<<endl;
    }else{
      cout<<"cauliflower"<<endl;
    }
    if(DEBUG){
      cerr<<"lst:";
      rep(i,n+1){
	cerr<<" "<<lst.getsum(i,i+1);
      }
      cerr<<endl;
    }
  }
}



Measured memory_bytes: 20580
n = int(input())
f = [[int(i) for i in input().split()] for _ in range(n)]
p = [[int(i) for i in input().split()] for _ in range(n)]
ans = -float("inf")
for x in range(1,1<<10):
    res = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if x>>j&1 and f[i][j]: cnt += 1
        res += p[i][cnt]
    ans = max(ans,res)
print(ans)

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

int N, freq[100100], bil, total, maks=0;

int main() {
    cin >> N;
    for (int i = 1; i<= N; i++ ){
        cin >> bil;
        freq[bil]++;
    }
    for (int i= 1;i<=100000; i++){
        total = freq[i] + freq[i+1]+ freq[i-1];
        if (maks < total){
            maks=total;
        }
    }
    cout << maks << endl;
}


Measured memory_bytes: 3916
#ifndef ONPC
  #define _FORTIFY_SOURCE 0
  #pragma GCC optimize("Ofast")
  #pragma GCC optimize("no-stack-protector")
  #pragma GCC optimize("unroll-loops")
  #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
  #pragma GCC optimize("fast-math")
#endif

#include <bits/stdc++.h>

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 200000;
//#define int long long
const int INF = 1e9;

vector<int> g[MAXN];

int col[MAXN];
int cc[2];

void dfs(int v, int p, int c){
  cc[c]++;
  col[v] = c;

  for (int i : g[v]){
    if (i == p) continue;

    dfs(i, v, c^1);
  }
}

int p[MAXN];

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    int a, b;
    for (int i =0; i < n-1; i++){
      cin >> a >> b;
      a--; b--;
      g[a].eb(b);
      g[b].eb(a);
    }

    memset(col, 0, sizeof col);
    cc[0] = 0; cc[1] = 0;

    dfs(0, -1, 0);

    int x = n / 3;

    int good = 0;
    int mn = cc[0];

    if (cc[1] < cc[0]){
      mn = cc[1];
      good = 1;
    }

    memset(p, 0, sizeof p);

    if (mn <= x){
      //cerr << "JOPA\n";
      int cur = 3;
      int ccc = 1;
      for (int i = 0; i < n; i++){
        if (col[i] == good){
          p[i] = cur;
          cur += 3;
        } else {
          p[i] = ccc;
          ccc++;
          if (ccc % 3 == 0 && ccc <= mn * 3) ccc++;
        }
      }
    } else {
      int cur1 = 1;
      int cur2 = 2;
      int cur3 = 3;

      for (int i = 0; i < n; i++){
        if (col[i]){
          if (cur1 <= n){
            p[i] = cur1;
            cur1 += 3;
          } else {
            p[i] = cur3;
            cur3 += 3;
          }
        } else {
          if (cur2 <= n){
            p[i] = cur2;
            cur2 += 3;
          } else {
            p[i] = cur3;
            cur3 += 3;
          }
        }
      }
    }

    //for (int i = 0; i < n; i++) cout << col[i] << ' ';
    //cout << '\n';

    for (int i = 0; i < n; i++) cout << p[i] << ' ';
    cout << '\n';

    return 0;
}


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

#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define forup(i,l,r) for (register int i = l ; i <= r ; i += lowbit(i))
#define fordown(i,id) for (register int i = id ; i ; i -= lowbit(i))
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define lowbit(x) (x&(-x))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pr;

const ld inf = 2e18;
const int N = 3e6 + 10;
const int maxn = 100020;
const ll mod = 1e9 + 7;

int deg[10];
inline ll power(ll x,ll y){
	y = ((y % (mod - 1)) + (mod - 1)) % (mod - 1);
//	if ( y < 0 ) return power(power(x,-y),mod - 2);
	ll res = 1;
	while ( y ){
		if ( y & 1 ) res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
bool check(){
	
	rep(i,1,4) if ( deg[i] == 3 ) return 0;
	return 1;
}
int main(){
	rep(i,1,3){
		int x,y;
		scanf("%d %d",&x,&y);
		deg[x]++ , deg[y]++;
	}
	if ( check() ) puts("YES");
	else puts("NO");
}


Measured memory_bytes: 256