akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

std::string S, T;
int SS[100001], TS[100001];
int q;

int main()
{
  std::cin >> S >> T >> q;

  rep( i, S.size() )
    SS[i+1] = SS[i]+(S[i]=='A'?1:2);
  rep( i, T.size() )
    TS[i+1] = TS[i]+(T[i]=='A'?1:2);

  rep( i, q )
  {
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;

    puts( (SS[b]-SS[a-1])%3 == (TS[d]-TS[c-1])%3 ? "YES" : "NO" );
  }
  
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std; 
const int dx[]={1,0,-1,0,1,-1,-1,1}; 
const int dy[]={0,1,0,-1,1,1,-1,-1}; 
const int INF = 1e9; 
const long long LINF = 1e18; 
const double EPS = 1e-8; 
#define pb push_back 
#define mk make_pair 
#define fr first 
#define sc second 
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); ++i) 
#define rep(i,j) reps(i,0,j) 
#define all(a) (a).begin(),(a).end() 
#define MOD 1000000007 
typedef pair<int,int> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
int stage[1024][1024];
int H,W;
int memo[1024][1024];
int main(){
    //input
    cin >> H >> W;
    
    rep(i,H){
        rep(j,W){
            cin >> stage[i][j];
        }
    }
    vector<Pii> pond;
    
    rep(i,H){
        rep(j,W){
            bool flg = false;
            rep(k,4){
                int ny = i + dy[k];
                int nx = j + dx[k];
                if(ny < 0 || ny > H-1 || nx < 0 || nx > W-1)continue;
                if(stage[i][j] > stage[ny][nx]){
                    flg = true;
                }
            }
            if(!flg){
                pond.pb(mk(i,j));
            }
        }
    }
    
    rep(q,pond.size()){
        bool used[1024][1024]={{}};
        queue < Pii > Q;
        Q.push(pond[q]);
        while(!Q.empty()){
            Pii p = Q.front();Q.pop();
            if(used[p.fr][p.sc])continue;
            used[p.fr][p.sc] = 1;
            rep(k,4){
                int ny = p.fr + dy[k];
                int nx = p.sc + dx[k];
            
                if(ny < 0 || ny > H-1 || nx < 0 || nx > W-1)continue;
                if(stage[p.fr][p.sc] > stage[ny][nx] || used[ny][nx])continue;
                Q.push(Pii(ny,nx));
            }
        }
        
        rep(i,H){
            rep(j,W){
                if(used[i][j] && !(pond[q].fr == i && pond[q].sc == j)){
                    memo[i][j]++;
                }
            }
        }
    }
    int ans = 0;
    rep(i,H){
        rep(j,W){
            if(memo[i][j] > 1){
                ++ans;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

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

typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define mp make_pair

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a + b + c > 21){
        puts("bust");
    } else {
        puts("win");
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        Scanner sc = new Scanner(System.in);
        char[] S = sc.next().toCharArray();
        char[] T = sc.next().toCharArray();

        int ans = 0;
        for (int i = 0; i < S.length; i++) {
            if(S[i]==T[i]) ans ++;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;


#include <random>

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

    int D;
    cin>>D;
    int c[26];
    int q[D];
    rep(i,26){
        cin>>c[i];
    }
    int s[D][26];
    rep(i,D){
        rep(j,26){
            cin>>s[i][j];
        }
    }
    int ans=0;
    map<int,int> m;
    int y=0;
    rep(i,D){

        int an=-INF;
        int x=0;
        rep(k,26){
            int a=ans;
            map<int,int> ma=m;
            a+=s[i][k];
            rep(j,26){
                if(j==k){
                    ma[k]=0;
                }else{
                    ma[j]++;
                    a-=ma[j]*c[j];
                }
            }
            if(an<a){
                x=k;
                an=a;
            }
        }
        y=x;
        ans+=s[i][y];
        rep(j,26){
            if(j==y){
                m[y]=0;
            }else{
                m[j]++;
                ans-=m[j]*c[j];
            }
        }
        y++;
        q[i]=y;
    }

    int tr=0;
    std::random_device rnd; 
    while(tr<=16500){
        int g=rnd()%26;
        int h=rnd()%26;
        tr++;
        int ansm=0;
        int r[D];
        rep(i,D){
            if(i==g){
                r[i]=h;
            }else{
                r[i]=q[i];
            }
        }
        map<int,int> mx;
        rep(i,D){
            ansm+=s[i][r[i]];
            rep(j,26){
                if(j==r[i]){
                    mx[r[i]]=0;
                }else{
                    mx[j]++;
                    ansm-=mx[j]*c[j];
                }
            }
        }
        if(ansm>ans){
            rep(i,D){
                q[i]=r[i];
            }
        }
    }
    rep(i,D){
        cout << q[i] << endl;
    }

    



}


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

using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 2000;

int n, m, a, b;
int mark[N + 5][N + 5];

char idx(int x) {
    if(x == 0) return '.';
    if(x == 1) return '<';
    if(x == 2) return '>';
    if(x == 3) return '^';
    if(x == 4) return 'v';
    return 'X';
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n), read(m), read(a), read(b);

    if(n & 1) {
        for (int i = 1; i < m; i += 2) {
            if(!mark[n][i] && !mark[n][i+1] && a) 
                mark[n][i] = 1, mark[n][i+1] = 2, -- a;
        }
    }

    if(m & 1) {
        for (int i = 1; i < n; i += 2) {
            if(!mark[i][m] && !mark[i+1][m] && b) 
                mark[i][m] = 3, mark[i+1][m] = 4, -- b;
        }
    }

    for (int i = 1; i < n; i += 2) 
        for (int j = 1; j < m; j += 2) {

            if(i == n - 2 && j == m - 2 && a == 1 && b == 1) {
                mark[i][j] = 1, mark[i][j+1] = 2, mark[i][j+2] = 3;
                mark[i+1][j] = 3, mark[i+1][j+1] = 0, mark[i+1][j+2] = 4;
                mark[i+2][j] = 4, mark[i+2][j+1] = 1, mark[i+2][j+2] = 2;

                a = 0, b = 0;
            } else if(a >= 2 || (a == 1 && (!b || (b == 1 && (i != n-2 || j != m-2))))) {
                if(a) mark[i][j] = 1, mark[i][j+1] = 2, -- a;
                if(a) mark[i+1][j] = 1, mark[i+1][j+1] = 2, -- a;
            } else if(b >= 2 || (b == 1 && (!a || (a == 1 && (i != n-2 || j != m-2))))) {
                if(b) mark[i][j] = 3, mark[i+1][j] = 4, -- b;
                if(b) mark[i][j+1] = 3, mark[i+1][j+1] = 4, -- b;
            }
        }

    if(a || b) return !puts("NO");

    puts("YES");
    for (int i = 1; i <= n; ++ i) {
        for (int j = 1; j <= m; ++ j) {
            printf("%c", idx(mark[i][j])); 
        }
        puts("");
    }

    return 0;
}


Measured memory_bytes: 9344
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        for (int i = a; i <= b * a; ++i) {
            if (i % a == 0 && i % b == c) {
                _out.println("YES");
                return;
            }
        }
        _out.println("NO");
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 23764
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string S;
    cin >> S;

    REP(i, 3) {
        cout << S[i];
    }

    cout << endl;
    
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999999
#define MOD 998244353 

ll logn(ll n, ll r) 
{ 
    return (n > r - 1) ? 1 + logn(n / r, r) : 0; 
} 

void func()
{
    ll n;
    cin>>n;
    string v;
    char c[26];
    c[0]='z';c[1]='a';
    loop(i,2,26){
        c[i]=c[i-1]+1;
    }
    while(n>0){
        v.pb(c[n%26]);
        if(n%26==0){
            n=n-26;
        }
        else{
            n=n-(n%26);
        }
        n=n/26;
    }
    reverse(v.begin(), v.end());
    cout<<v<<"\n";
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

Measured memory_bytes: 3652
#include <vector>
#include <iostream>
#include <set>

#define FOR(i,n) for(int i=0; i<n; i++)
#define FORI(i,z,n) for(int i=z; i<n; i++)

using namespace std;

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

    set<int> coins;
    vector<int> dyn(n);
    dyn[0] = 1;

    FOR(i, m) {
        int c;
        cin >> c;
        coins.insert(c);
    }

    FORI(i, 1, n) {
        int coinVal = i+1;
        if (coins.find(coinVal) != coins.end()) {
            // There is an exact coin for the value i
            dyn[i] = 1;
        } else {
            // We need to combine previous value e.g: (n-1, 1), (n-2, 2), ...
            int minVal = 0;
            FOR(j, i)
                if (minVal == 0 || dyn[j] + dyn[i-j-1] < minVal)
                    minVal = dyn[j] + dyn[i-j-1];
            dyn[i] = minVal;
        }
    }

    cout << dyn[n-1] << endl;
}



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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

int _runtimeTerror_()
{
    ll n,ans=0;
    cin>>n;
    vector<ll> v(n);
    for(int i=0;i<n;++i)
        cin>>v[i];
    ll mx=v[0];
    for(int i=1;i<n;++i)
    {
        amax(mx,v[i]);
        ans+=mx-v[i];
    }
    cout<<ans<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

Measured memory_bytes: 4764
module DoublyLinkedList = struct
  type t = {
    mutable data : int;
    mutable next : t;
    mutable prev : t;
  }

  let make () =
    let rec head = { data = 0; next = head; prev = head } in
    head

  let insert data head =
    let x = { data = data; next = head.next; prev = head } in
    head.next.prev <- x;
    head.next <- x

  let delete x =
    x.next.prev <- x.prev;
    x.prev.next <- x.next

  let delete_first head = delete head.next

  let delete_last head = delete head.prev

  let delete_node data head =
    let rec doit ite =
      if ite == head then None
      else if ite.data = data then Some ite
      else doit ite.next
    in
    match doit head.next with
    | None -> ()
    | Some ite -> delete ite

  let iteri head ~f =
    let rec doit i ite =
      if ite != head then (f i ite.data; doit (i + 1) ite.next)
    in doit 0 head.next
end

module L = DoublyLinkedList

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc)
  in doit str []

let () =
  let n = read_int () in
  let head = L.make () in
  let rec read i =
    if i < n then begin
      match split (read_line ()) ' ' with
      | ["insert"; n] -> (L.insert (int_of_string n) head; read (i + 1))
      | ["delete"; n] -> (L.delete_node (int_of_string n) head; read (i + 1))
      | ["deleteFirst"] -> (L.delete_first head; read (i + 1))
      | ["deleteLast"] -> (L.delete_last head; read (i + 1))
      | _ -> exit 1
    end in
  read 0;
  L.iteri head ~f:(fun i n -> if i <> 0 then print_string " "; print_int n);
  print_newline ()

Measured memory_bytes: 38992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        class Table
        {
            public readonly int s;
            public readonly int t;
            public readonly int c;
            public Table(int[] v)
            {
                s = v[0];
                t = v[1];
                c = v[2];
            }
        }
        static int Solve(int N, IEnumerable<Tuple<int, int>> tuples)
        {
            int max = 0;
            int cnt = 0;
            foreach (var tuple in tuples)
            {
                cnt += tuple.Item2;
                max = Math.Max(cnt, max);
            }
            return max;
        }
        static void Main(string[] args)
        {
            int[] v1 = ReadInts();
            int N = v1[0];
            int C = v1[1];
            var t1 = new Table[N];
            for (int i = 0; i < N; ++i)
            {
                t1[i] = new Table(ReadInts());
            }
            var t2 = t1.OrderBy(t => t.c).ThenBy(t => t.s).ToArray();
            var tuples = new List<Tuple<int, int>>();
            for (int i = 0; i < N; ++i)
            {
                if (i - 1 < 0 || t2[i - 1].t != t2[i].s || t2[i - 1].c != t2[i].c)
                {
                    tuples.Add(new Tuple<int, int>(t2[i].s, 1));
                }
                if (i + 1 >= N || t2[i + 1].s != t2[i].t || t2[i + 1].c != t2[i].c)
                {
                    tuples.Add(new Tuple<int, int>(t2[i].t, -1));
                }
            }
            Console.WriteLine(Solve(N, tuples.OrderBy(t => t.Item1).ThenByDescending(t => t.Item2)));
        }
    }
}


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

int main(){

    int N, M;
    cin >> N >> M;

    int i;
    int ans = 0;

    vector<int> height(N);
    for (i=0; i<N; i++){
        cin >> height.at(i);
    }
    vector<int> flg(N);
    for (i=0; i<N; i++){
        flg.at(i) = 1;
    }

    int A, B;
    for (i=0; i<M; i++){
        cin >> A >> B;

        if (height.at(A-1) >= height.at(B-1)){
            flg.at(B-1) = 0;
        }
        if (height.at(A-1) <= height.at(B-1)){
            flg.at(A-1) = 0;
        }
    }

    for (i=0; i<N; i++){
        if (flg.at(i) == 1){
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,m,k,i,j;cin >> n >> m >> k;bool ok = false;
  for(i=0;i<=m;i++){
    for(j=0;j<=n;j++){
      if((n-j)*i+(m-i)*j==k) ok = true;
    }
  }
  cout << ((ok) ? "Yes":"No") << endl;
}
      


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            long a = in.nextLong();
            long b = in.nextLong();
            long sum = 0;
            Long[] arr = new Long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextLong();
                sum += arr[i];
            }
            Arrays.sort(arr);
            long diff = 0;
            for (int i = 1; i < n; i++) {
                diff = Math.max(arr[i] - arr[i - 1], diff);
            }
            long ans = 0;
            long delta = a - b;
            long lo = 0, hi = (long) 1e9;
            while (lo <= hi) {
                long mid = (lo + hi) >> 1;
                long s = 0;
                for (int i = 0; i < n; i++) {
                    if (arr[i] - b * mid <= 0) continue;
                    s = s + (arr[i] - (b * mid) + (a - b - 1)) / (a - b);
                }
                if (s <= mid) {
                    ans = mid;
                    hi = mid - 1;
                } else {
                    lo = mid + 1;
                }
            }
            out.println(ans);
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 41332
import java.util.*;
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt(), W = sc.nextInt(), no = H, i = 0, j = 0, k = 0;
		char[][] g = new char[H][W];
		boolean[][] c = new boolean[H][W];
		int[] row = {-1,1,0,0};
		int[] col = {0,0,-1,1};
		boolean ok = true;
		while (no-->0) {
			for (char ch : sc.next().toCharArray()) g[i][j++] = ch;
			i++; j=0;
		}
		for (i=0; i<H; i++) {
			for (j=0; j<W; j++) {
				if (g[i][j]=='#') {
					boolean canPaint=false;
					no=4; k=0; 
					while (no-->0) {
						if (i+row[k]>=0 && i+row[k]<H && j+col[k]>=0 && j+col[k]<W) {
							if (g[i+row[k]][j+col[k]]=='#'){
								c[i+row[k]][j+col[k]]=true; canPaint = true;
							}
						}
						k++;
					}
					if (canPaint) c[i][j]=true;
				}
			}
		}
		for (i=0; i<H; i++) for (j=0; j<W; j++) if (g[i][j]=='#' && !c[i][j]) ok=false;
		System.out.println(ok ? "Yes" : "No");
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 36060
#include <bits/stdc++.h>
using namespace std;
# define ll  long long  int
# define ld  long double
#define fin0(i,a,b,c) for(int i=a;i<b;i+=c)
#define fin1(i,a,b,c) for(int i=a;i<=b;i+=c)
#define fde0(i,a,b,c) for(int i=a;i>b;i-=c)
#define fde1(i,a,b,c) for(int i=a;i>=b;i-=c)
#define vi vector<int>
#define vll vector<ll>
#define vboo vector<bool>
#define all(a) a.begin(),a.end()
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
# define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define t     \
    int t;    \
    cin >> t; \
    while (t--)
# define trace1(x)                cerr << #x << ": " << x << "\n";
# define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
# define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
# define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
const ll INF= 1e18;


int main(){
  IOS;
  int N;
  cin>>N;
  ll arr[N];
  ll count_a =0;
  fin0(i,0,N,1){
    cin>>arr[i];
  }
  fin0(i,1,N,1){
     if(arr[i-1]>arr[i]){
        count_a += arr[i-1]-arr[i];
        arr[i]=arr[i-1];
     }
  }
  cout<<count_a;
  return 0;
}


Measured memory_bytes: 5124
#include <cstdio>
#include <cstdlib>
#include <vector>

int as[3][100000];

int bs[100000];

int flips[2];

void fail(){
  printf("No\n");
  exit(0);
}

void mergesort(std::vector<int>& vs,int L,int R,int& inv){
  if(R-L>1){
    int M=(L+R)/2;
    mergesort(vs,L,M,inv);
    mergesort(vs,M,R,inv);
    int i=L,j=M;
    std::vector<int> tmp;
    while(i<M||j<R){
      if(j==R||i<M&&vs[i]<vs[j]){
	tmp.push_back(vs[i++]);
	inv+=j-M;
      }else{
	tmp.push_back(vs[j++]);
      }
    }
    for(int k=0;k<tmp.size();k++){
      vs[L+k]=tmp[k];
    }
  }
}

int main(){
  int N;
  scanf("%d",&N);
  for(int r=0;r<3;r++){
    for(int i=0;i<N;i++){
      scanf("%d",&as[r][i]);
    }
  }
  for(int i=0;i<N;i++){
    if(as[1][i]%3!=2) fail();
    if(as[0][i]==as[1][i]-1&&as[1][i]==as[2][i]-1){
      bs[i]=as[1][i]/3;
    }else if(as[0][i]==as[1][i]+1&&as[1][i]==as[2][i]+1){
      bs[i]=as[1][i]/3;
      flips[i%2]++;
    }else{
      fail();
    }
  }
  /*
  for(int i=0;i<N;i++){
    printf("B%d\n",bs[i]);
  }
  */
  std::vector<int> evens,odds;
  for(int i=0;i<N;i+=2){
    evens.push_back(bs[i]);
  }
  for(int i=1;i<N;i+=2){
    odds.push_back(bs[i]);
  }
  int evens_inv=0,odds_inv=0;
  mergesort(evens,0,evens.size(),evens_inv);
  mergesort(odds,0,odds.size(),odds_inv);
  /*
  for(int i=0;i<evens.size();i++){
    printf("E%d\n",evens[i]);
  }
  for(int i=0;i<odds.size();i++){
    printf("O%d\n",odds[i]);
  }
  */
  for(int i=0;i<evens.size();i++){
    if(evens[i]!=i*2) fail();
  }
  for(int i=0;i<odds.size();i++){
    if(odds[i]!=i*2+1) fail();
  }
  /*
    printf("EI=%d\n",evens_inv);
    printf("OI=%d\n",odds_inv);
    printf("EN=%d\n",flips[0]);
    printf("ON=%d\n",flips[1]);
  */
  if((evens_inv+flips[1])%2) fail();
  if((odds_inv+flips[0])%2) fail();
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 2672
n,k = map(int,input().split())
MOD = 10**9+7

history = {}
def comb(n,k):
  if (n,k) in history:
    return history[(n,k)]
  if k == 0:
    return 1
  res = (n-k+1)*pow(k,MOD-2,MOD)*comb(n,k-1)
  res = res%MOD
  history[(n,k)] = res
  history[(n,n-k)] = res
  return res

for i in range(k):
  #print(comb(k-1,i),comb(n-k+1,i+1))
  ans = comb(k-1,i) * comb(n-k+1,i+1)
  print(ans % MOD)




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

int main() {
    int n, a, b; cin >> n >> a >> b;

    int ans = 0;
    for (int i = 0; i <= n; i++) {
     
        int tmp = i;
        int sum = 0;
        do {
            sum += tmp % 10;
            tmp /= 10;
        } while (tmp != 0);

        if (a <= sum && sum <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  for (int i = 0; i < W+2; i++){
    cout << "#";
  }
  cout << endl;
  
  for ( int i = 0; i < H; i ++){
  string s;
  cin >> s;
  cout << "#" << s << "#" << endl;
  }
  
  for (int i = 0; i < W+2; i++){
    cout << "#";
  }
  cout << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 2e5 + 10;
int arr[maxn];
signed main() {
    int N;
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> arr[i];
    }
    int mx = arr[1], ans = 0;
    for (int i = 2; i <= N; ++i) {
        if (arr[i] > mx) {
            mx = arr[i];
        } else {
            ans += mx - arr[i];
        }
    }
    cout << ans << endl;
    system("pause");
    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

struct Data { int x,y,w; };
struct Segment { 
  int range[2]; 
  bool operator < ( const Segment& seg ) const {
    if( range[0] != seg.range[0] ) return range[0] < seg.range[0];
    return range[1] > seg.range[1];
  }
};

int N,W,H;

bool check(bool type,vector<Data> &vec,int limit){ // type 0 -> x, 1 -> y
  vector<Segment> segs(vec.size());
  rep(i,vec.size()) {
    int coor = (type?vec[i].y:vec[i].x);
    segs[i].range[0] = coor - vec[i].w;
    segs[i].range[1] = coor + vec[i].w;
  }
  sort(segs.begin(),segs.end());
  int maxi = 0;
  rep(i,segs.size()) if( maxi >= segs[i].range[0] ) maxi = max(maxi,segs[i].range[1]);
  return maxi >= limit;
}

int main(){
  cin >> N >> W >> H;
  vector<Data> vec(N);
  rep(i,N) cin >> vec[i].x >> vec[i].y >> vec[i].w;
  puts((check(0,vec,W)||check(1,vec,H))?"Yes":"No");
  return 0;
}

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

using namespace std;

#define ll long long
#define M 1005000
#define ii pair<ll, ll>
#define iii pair<ll, ii>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()

ll n, m, ans;
vector<ii> v;
char a[50][50];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

ll solve(ii x, ii y){
    if (x == y) return 0;
    queue<ii> q;
    q.push(x);
    ll dis[50][50] = {0};
    dis[x.fi][x.se] = 1;
    while (!q.empty()){
        ii u = q.front(); q.pop();
        for (int i = 0; i < 4; i++){
            int xx = u.fi + dx[i];
            int yy = u.se + dy[i];
            if (0 < xx && xx <= n && 0 < yy && yy <= m && a[xx][yy] == '.' && dis[xx][yy] == 0){
                dis[xx][yy] = dis[u.fi][u.se] + 1;
                if (xx == y.fi && yy == y.se) return dis[u.fi][u.se];
                q.push({xx, yy});
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++){
            cin >> a[i][j];
            if (a[i][j] == '.') v.pb({i, j});
        }
    for (int i = 0; i < v.size(); i++)
        for (int j = i + 1; j < v.size(); j++)
            ans = max(ans, solve(v[i], v[j]));
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")
from collections import defaultdict


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(s: str, x: int, y: int):
    N = len(s)
    s = [len(FF) for FF in s.split("T")]
    sX = s[0::2]                # 空となるケースに注意
    sY = s[1::2]                # 空となるケースに注意
    # print(sX, sY)

    # sXを足すか引くかして、xにたどり着くことができるか
    DPx = defaultdict(bool)
    DPx[sX[0]] = True
    for c in sX[1:]:
        DPnext = defaultdict(bool)
        for key in DPx:
            DPnext[key-c] = True
            DPnext[key+c] = True
        DPx = DPnext

    DPy = defaultdict(bool)
    DPy[0] = True
    for c in sY:
        DPnext = defaultdict(bool)
        for key in DPy:
            DPnext[key-c] = True
            DPnext[key+c] = True
        DPy = DPnext

    if DPx[x] and DPy[y]:
        yes()
    else:
        no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    x = int(next(tokens))  # type: int
    y = int(next(tokens))  # type: int
    solve(s, x, y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4456
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,m; cin>>n>>m;
    for(int i=0;i<max(m,n);i++) cout<<min(m,n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
#define eprintf(...) fprintf(stderr,__VA_ARGS__)

const int N=int(1e5)+5;

int n,a[N];
vector<int> b[N];

int dfs(int u){
	vector<int> d;
	for(auto v:b[u])
		d.push_back(dfs(v));
	sort(d.begin(),d.end(),greater<int>());
	int ans=0;
	for(int i=1;i<=int(d.size());i++){
		ans=max(ans,i+d[i-1]);
	}
	return ans;
}

int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		scanf("%d",&a[i]);
		b[a[i]].push_back(i);
	}
	printf("%d\n",dfs(1));
}

Measured memory_bytes: 13952
loop do
  w, d = gets.chomp.split.map(&:to_i)
  break if w.zero? && d.zero?

  widths  = Array.new(21, 0)
  heights = Array.new(21, 0)

  gets.split.map(&:to_i).each do |i|
    widths[i] += 1
  end
  gets.split.map(&:to_i).each do |i|
    heights[i] += 1
  end

  answer = 0
  0.upto(20).each do |i|
    answer += [widths[i], heights[i]].max * i
  end

  puts answer
end

Measured memory_bytes: 6120
#include <stdio.h>

int main(void) {
    unsigned int n, k;
    scanf("%u %u%*c", &n, &k);

    unsigned long ret = 1l;
    ret *= k;

    int i;
    for(i=1;i<n;i++) {
        ret *= (k-1);
    }

    printf("%lu\n", ret);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int a[100];
int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int c, d;
        cin >> c >> d;
        a[c]++;a[d]++;
    }
    for (int i = 1; i <= n; i++)
        cout << a[i] << endl;

}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let mut vec: Vec<u32> = Vec::new();
    let mut first_flag: bool = true;
    for _ in 0..n {
        vec.push(read());
    }
    vec.reverse();
    for number in vec {
        if first_flag {
            print!("{}", number);
            first_flag = false;
        } else {
            print!(" {}", number);
        }
    }
    println!()
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

ll n, K;
vl a, f;

bool check(ll x) {
  ll k = K;
  rep(i,n) {
    ll d = a[i]*f[i] - x;
    if (d > 0) {
      if(d > k*f[i]) {
        return false;
      } else {
        k -= (d+f[i]-1)/f[i];
      }
    }
  }
  return true;
}

int main() {
  cin >> n >> K;
  a.resize(n); ina(a,n);
  f.resize(n); ina(f,n);
  sort(all(a));
  sort(all(f),greater<ll>());
  ll ok = 1e12+1, ng = -1;
  while (ng < ok - 1) {
    ll mid = (ok + ng) / 2;
    if (check(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;


int main() {
  int x;
  cin >> x;
  if (400 <= x && x <= 599) cout << 8 << endl;
  if (600 <= x && x <= 799) cout << 7 << endl;
  if (800 <= x && x <= 999) cout << 6 << endl;
  if (1000 <= x && x <= 1199) cout << 5 << endl;
  if (1200 <= x && x <= 1399) cout << 4 << endl;
  if (1400 <= x && x <= 1599) cout << 3 << endl;
  if (1600 <= x && x <= 1799) cout << 2 << endl;
  if (1800 <= x && x <= 1999) cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i, 1, 5) --> {1,2,3,4}
// rep(i, 5, 1) --> {4,3,2,1}
// rep(it, end(v), begin(v)) --> *it

using namespace std;

int n;

void dfs(string s, char mx)
{
    if (s.size() == n)
        cout << s << "\n";
    else 
        for (char c = 'a'; c <= mx; c++)
            dfs(s + c, (c == mx ? mx + 1 : mx));
}

int main()
{
    cin >> n;
    dfs("", 'a');
    return 0;
}

Measured memory_bytes: 1536
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
  a = A[i] - 1
  ans += B[a]
  if i != 0 and a == A[i - 1]:
    ans += C[A[i - 1] - 1]
print(ans)

Measured memory_bytes: 3064
N=int(input())
a=list(map(int,input().split()))
b=[0 for i in range(N)]
for i in range(0,N):
    x=N-i
    cnt=0
    for j in range(0, N//x):
        if b[x*(j+1)-1]==1:
            cnt+=1
    b[x-1]=(cnt-a[x-1])%2
print(sum(b))
for i in range(N):
    if b[i]:
        print(i+1)


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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String s = reader.readLine();
        int[] leftBkSize = new int[n + 1];
        for (int i = 0; i < n; i++) {
            leftBkSize[i + 1] = leftBkSize[i] + ((s.charAt(i) == '#') ? 1 : 0);
        }
        int min = Integer.MAX_VALUE;
        for (int i = 0; i <= n; i++) {
            // switchCount = leftBk + rightWh
            //             = leftBk + (allWh - leftWh)
            //             = leftBk + ((n - allBk) - (i - leftBk))
            //             = 2 * leftBk + n - allBk - i
            int switchCount = 2 * leftBkSize[i] + n - leftBkSize[n] - i;
            if (switchCount < min) {
                min = switchCount;
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 26964
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{
      senky_bansal
      IIIT_ALLAHABAD

      ll n;
      cin>>n;
      n--;
      cout<<(n*(n+1))/2;





}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int A,B;
	cin >> A >> B;
	int ret = 0;
	int cnt = 1;
	for(int i = 0;i < 100;i++) {
		if(cnt >= B) {
			break;
		}
		ret++;
		cnt += A - 1;
	}
	cout << ret << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

ll solve(vector<ll> &a, int i, ll s, ll t){
	if(i==a.size()) return 0;
	s += a[i];
	ll res = 0;
	if(s*t<=0){
		res += abs(s)+1;
		s = t;
	}
	return res + solve(a, i+1, s, -t);
}

int main(){
	ll n;
	cin>>n;
	vector<ll> a(n);
	rep(i, n) cin>>a[i];
	ll res = min(solve(a, 0, 0, 1), solve(a, 0, 0, -1));
	cout<<res<<endl;
	return 0;
}


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

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

    if (A >=13){
        cout << B;
    } else if(A>=6){
        cout << B/2;
    } else{
        cout <<0;
    }
    cin >> A;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = (ll)1e15;

int main(void)
{
	ll n;
	cin >> n;
	vector<vector<ll>> ms(n);
	rep(i, n-1) {
		ll a;
		cin >> a;
		a--;
		ms[a].push_back(i+1);
	}
	rep(i, n) {
		cout << ms[i].size() << endl;
	}
	return 0;
}


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

typedef long long int ll;

int N, K;
vector<ll> A;

vector<ll> compress(vector<ll> vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

class BIT{
private:
    vector<ll> bit;
    
public:
    BIT(int n){
        bit.resize(n+1);
    }
    
    ll sum(int i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i&-i;
        }
        return s;
    }
    
    void add(int i, ll v){
        while(i <= bit.size()){
            bit[i] += v;
            i += i&-i;
        }
    }
};

int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++){
        int x; cin >> x;
        A.push_back(x-K);
    }
    vector<ll> imos(N+1);
    
    for(int i=0; i<N; i++){
        imos[i+1] = imos[i] + A[i];
    }
    auto iimos = compress(imos);
    
    BIT bit(N+1);
    
    ll ans = 0;
    for(int i=0; i<=N; i++){
        int imosi = lower_bound(iimos.begin(), iimos.end(), imos[i]) - iimos.begin();
        ans += bit.sum(imosi+1);
        bit.add(imosi+1, 1);
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
  string s;
  cin >> s;
  int g=0;
  int p=0;
  rep(i,s.size()){
    if(s.at(i)=='g'){
      g++;
    }
    else{
      p++;
    }
  }
  
  int ans=s.size()/2-p;
    cout<<ans<<endl;
  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

bool road[16][16];
int memo[16][16];
int h,w;
int solve(int x, int y){
    if(y<0 || y >=h || x<0 || x>=w || road[y][x]) return 0;
    if(memo[y][x]) return memo[y][x];
    if(x==w-1 && y==h-1) return 1;
    return memo[y][x] = solve(x+1,y) + solve(x,y+1);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    while(cin >> w >> h , w){
        fill_n(road[0],16*16,0) , fill_n(memo[0],16*16,0);
        cin >> c;
        while(c--){
        cin >> a >> b;
        road[--b][--a] = true;
        }
        cout << solve(0,0) << endl;
    }
}


Measured memory_bytes: 3068
N, C = gets.split.map(&:to_i)
ds = []
C.times do |i|
    ds[i] = gets.split.map(&:to_i)
end
num = Array.new(3){Array.new(C, 0)}
N.times do |i|
    arr = gets.split.map(&:to_i)
    N.times do |j|
        num[(i+j)%3][arr[j]-1] += 1
    end
end

sum = Array.new(3){Array.new(C, 0)}
C.times do |i|
    C.times do |j|
        3.times do |k|
            sum[k][j] += ds[i][j] * num[k][i]
        end
    end
end

ans = 10**18
C.times do |c0|
    C.times do |c1|
        C.times do |c2|
            next if c0==c1 || c1==c2 || c2==c0
            result = sum[0][c0] + sum[1][c1] + sum[2][c2]
            ans = result if ans > result
        end
    end
end
puts ans

Measured memory_bytes: 2428
#include "bits/stdc++.h"
 
using namespace std;
 
#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238
 
typedef pair<int, int> P;
 
 
signed main(){
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    bool flag = false;
    FOR(i,A,B+1){
        if(i%K==0) {cout<<"OK"<<endl; flag = true; break;}
    }
    if(!flag) cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3684