akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	
	if(A.size()<B.size()) {
		cout<<"LESS"<<endl;
	}
	else if(B.size()<A.size()) {
		cout<<"GREATER"<<endl;
	}
	else if(A<B) {
		cout<<"LESS"<<endl;
	}
	else if(A>B) {
		cout<<"GREATER"<<endl;
	}
	else {
		cout<<"EQUAL"<<endl;
	}

}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
rc=list(map(int,input().split()))
a=[[0 for x in range(rc[1]+1)]for x in range(rc[0]+1)]
for x in range(rc[0]):
    code=list(map(int,input().split()))
    result=0
    for y in range(rc[1]):
        a[x][y]=code[y]
        result+=code[y]
    a[x][rc[1]]=result

for y in range(rc[1]+1):
    result=0
    for x in range(rc[0]):
        result+=a[x][y]
    a[rc[0]][y]=result

for x in range(rc[0]+1):
    string=""
    for y in range(rc[1]+1):
        string+=str(a[x][y])
        if (y!=rc[1]):
            string+=" "
    print(string)

Measured memory_bytes: 7772
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
int main(){

  //input
  int N;
  cin >> N;
  int A[N],B[N],C[N];
  for(int i=0;i<N;i++) cin >> A[i] >> B[i] >> C[i];
  
  //dp_setup
  //define:dp[i][j]=i日目迄で得られる最大幸福量/最後にjを選択
  int dp[N+1][3];
  for(int i=0;i<N+1;i++) for(int j=0;j<3;j++) dp[i][j]=0;
  
  //dp_onwork
  for(int i=0;i<N;i++){
    dp[i+1][0]=max(dp[i][1],dp[i][2])+A[i];
    dp[i+1][1]=max(dp[i][2],dp[i][0])+B[i];
    dp[i+1][2]=max(dp[i][0],dp[i][1])+C[i];
  }
  
  //output
  
  cout << max({dp[N][0],dp[N][1],dp[N][2]}) << endl;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define N	 100
string ans;
void solve(){
	string s;
	cin>>s;
	rep(i,0,sz(s)){
		ans+=s[i];
		i++;
	}
	cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 592
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;

  vP ps(m);
  rep(i, m){
    ll a, b;
    cin >> a >> b;
    a--, b--;
    ps[i] = P(b, a);
  }
  Sort(ps);

  ll ans = 0;
  ll pre = -1;
  rep(i, m){
    if(ps[i].second > pre) {
        ans += 1;
        pre = ps[i].first - 1;
      }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, a[112345];

    cin >> n;
    REP(i, n)
    cin >> a[i];

    bool used[112345];
    fill(used, used + n + 1, false);

    int res = 0;
    int cur = 1;
    while (true)
    {
        used[cur] = true;
        cur = a[cur - 1];

        res++;

        if (used[cur])
        {
            cout << -1 << endl;
            return 0;
        }
        if (cur == 2)
        {
            cout << res << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 768
using System.Collections.Generic;
    using System.Collections;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System;

    namespace cysharp_test
    {
        class Program
        {
            static void Main (string[] args)
            {
                new Program ().solve ();
            }

            void solve ()
            {
                int[] nm = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();
                int N = nm[0];
                int M = nm[1];

                long[] heights = Console.ReadLine ().Split (' ').Select (long.Parse).ToArray ();
                bool[] possibility = new bool[N];
                for (int i = 0; i < N; i++)
                {
                    possibility[i] = true;
                }
                for (int i = 0; i < M; i++)
                {
                    var input = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();
                    if (heights[input[0] - 1] > heights[input[1] - 1]) possibility[input[1] - 1] = false;
                    else if (heights[input[0] - 1] < heights[input[1] - 1]) possibility[input[0] - 1] = false;
                else { possibility[input[0] - 1] = false; possibility[input[1] - 1] = false; }
            }
                Console.WriteLine (possibility.Count (b => b));
                Console.ReadKey ();
            }

        }
        struct Vector2
        {
            public Vector2 (long x, long y)
            {
                this.x = x;
                this.y = y;
            }

            public long x, y;

            public static Vector2 operator + (Vector2 a, Vector2 b)
            {
                return new Vector2 (a.x + b.x, a.y + b.y);
            }

            public static Vector2 operator - (Vector2 a, Vector2 b)
            {
                return new Vector2 (a.x - b.x, a.y - b.y);
            }

            public static Vector2 operator * (Vector2 a, long scala)
            {
                return new Vector2 (a.x * scala, a.y + scala);
            }

            public static bool operator == (Vector2 a, Vector2 b)
            {
                return (a.x == b.x) && (a.y == b.y);
            }

            public static bool operator != (Vector2 a, Vector2 b)
            {
                return !(a.x == b.x) && (a.y == b.y);
            }

            public override int GetHashCode ()
            {
                return (int) (x + y);
            }

            public override bool Equals (object obj)
            {
                if (!(obj == null) && obj is Vector2)
                {
                    return (this == (Vector2) obj);
                }
                else return false;
            }

            public override string ToString ()
            {
                return ("(" + x + "," + y + ")");
            }
        }
    }

Measured memory_bytes: 33716
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ir = new Resolver(new ConsoleReader());
            Console.WriteLine(ir.Resolve());
        }
    }

    public class Resolver
    {
        IInputReader InputReader { get; }
        public List<string> Messages { get; set; } = new List<string>();

        int n;
        string a;
        string b;
        string c; 

        public void ParseLines(){
            n = int.Parse(InputReader.ReadLine());
            a = InputReader.ReadLine();
            b = InputReader.ReadLine();
            c = InputReader.ReadLine();
        }

        public string Resolve()
        {
            var res = 0;
            for(int i = 0; i < n; i++)
            {
                var ax = a.Substring(i, 1);
                var bx = b.Substring(i, 1);
                var cx = c.Substring(i, 1);

                if(ax == bx && bx == cx)
                {
                    continue;
                }
                        
                if (ax == bx || bx == cx || cx==ax)
                {
                    res += 1;
                    continue;
                }

                res += 2;

            }

            return res.ToString();
        }


        public Resolver(IInputReader inputReader)
        {
            InputReader = inputReader;
            ParseLines();
        }

    }

    public interface IInputReader
    {
        string ReadLine();
    }

    class ConsoleReader : IInputReader
    {
        string IInputReader.ReadLine()
        {
            return Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11220
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);

        int taro = 0;
        int hanako = 0;
        for(int i = 0; i < n; i++) {
          line = sc.nextLine();
          String[] l = line.split(" ");
          char[] t = l[0].toCharArray();
          char[] h = l[1].toCharArray();

          for(int j = 0; j < t.length; j++) {
            if(t[j] < h[j]) {
              hanako += 3;
              break;
            } else if( t[j] > h[j]) {
              taro += 3;
              break;
            } else if(j == t.length - 1 || j == h.length - 1) {
              if(t.length < h.length) {
                hanako += 3;
              } else if(t.length > h.length) {
                taro += 3;
              } else {
                hanako++;
                taro++;
              }
              break;
            }
          }
        }

        System.out.println(taro + " " + hanako);
    }
}

Measured memory_bytes: 30340
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i,t,n) for(int i=t;i<n;i++)
#define nd "\n"
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>




/*ll power(ll x,ll t){
if(t<=0){
    return 1;
}
ll y=(power(x,t/2));
y=(y*y)%ma;
if(t%2)
    y=(y*x)%ma;
return y;

}*/
/*ll ph[100001];
void E_phi(int n){

ph[0]=0;
ph[1]=1;
for(int i=2;i<=n;i++){
    ph[i]=i;
}
for(int i=2;i<=n;i++){
    if(ph[i]==i){
        for(int j=i;j<=n;j+=){
            ph[j]-=ph[j]/i;
        }
    }
}


}*/
/*string s,t;
vector<int>  z_fun(string s){

int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}*/

/*struct st{
ll sum,pre,suf,ans;
st(){}
st(ll k){
ans=k,pre=k,suf=k,sum=0;
}

};
ll t[4*200001+4];
ll a[200001];
ll lazy[4*200001+4];
ll mx=1e14;



void push(int ind){
int l=2*ind+1,r=2*ind+2;
t[l]+=lazy[ind];
t[r]+=lazy[ind];
lazy[l]+=lazy[ind];
lazy[r]+=lazy[ind];
lazy[ind]=0;

}

void build(int ind,int l,int r){
if(l==r){
    t[ind]=a[l];
return;
}
int mid=(l+r)/2;
build(2*ind+1,l,mid);
build(2*ind+2,mid+1,r);

  t[ind] =min(t[ind*2+1] , t[ind*2+2]);



}
ll query(int ind,int l,int r,int p,int q){

if(l>q || r<p )
    return mx;
    int mid=(l+r)/2;

if(l>=p && r<=q )
    {
      return t[ind];
    }
    push(ind);
ll x=query(2*ind+1,l,mid,p,q);
ll y=query(2*ind+2,mid+1,r,p,q);


return min(x,y);
}

void update(int ind,int l,int r,int p,int q,int val){
if(l>q || r<p )
    return;

if(l>=p && r<=q )
    {
      t[ind]+=val;
      lazy[ind]+=val;
      return;
    }
push(ind);
int mid=(l+r)/2;
    update(2*ind+1,l,mid,p,q,val);
     update(2*ind+2,mid+1,r,p,q,val);
    t[ind]=min(t[2*ind+1],t[2*ind+2]);



}


ll mod(ll a){
if(a>=0)
    return a;
else return -a;
}
*/

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   int n;
   cin>>n;
   set<int> s;
   vector<int>a;
   map<int,ll> f;
   rep(i,0,n){
   int p;

   cin>>p;
   f[p]++;
   s.insert(p);
   }
   for(auto i:s)
    a.pb(i);
  n=a.size();
  ll ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
        for(int k=j+1;k<n;k++){
            if(a[i]+a[j]>a[k])
                ans+=f[a[i]]*f[a[j]]*f[a[k]];
        }
    }

  }
  cout<<ans<<endl;

   }





Measured memory_bytes: 3628
n,m,l = map(int,input().split())
a = []
b = []

for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(m):
    b.append(list(map(int,input().split())))

c = [[0 for i in range(l)] for j in range(n)]

for i in range(n):
    for j in range(l):
        tmp = 0
        for h in range(m):
            tmp += a[i][h]*b[h][j]
        c[i][j] = tmp

for i in range(n):
    print(*c[i])


Measured memory_bytes: 7060
function memoization(f) {
  const cache = {};
  return (...param) => {
    const c = cache[param];
    return typeof c === 'undefined' ? cache[param] = f(...param) : c;
  };
}

class _Node {
  constructor(id, parentId, leftId, rightId) {
    this.id = id;
    this.parentId = parentId;
    this.leftId = leftId;
    this.rightId = rightId;
  }
  get type() {
    return this.parentId === -1
        ? 'root'
        : this.leftId === -1 && this.rightId === -1
            ? 'leaf'
            : 'internal node'}
}

class BinaryTree {
  constructor() {
    this.nodes = [];
    this._nodeInfo = [];
    this.getDepth = memoization(this.getDepth.bind(this));
    this.getHeight = memoization(this.getHeight.bind(this));
  }
  static get Node() {return _Node;}

  add(id, leftId, rightId) {this.nodes[id] = new BinaryTree.Node(id, -1, leftId, rightId);}

  connect() {
    for (let i = 0; i < this.nodes.length; i++ ) this._nodeInfo[i] = {node:null, sibling:-1, degree:0};
    this.nodes.forEach(n => {
      if (n.leftId !== -1) {
        this.nodes[n.leftId].parentId = n.id;
        this._nodeInfo[n.leftId].sibling = n.rightId;
      }
      if (n.rightId !== -1) {
        this.nodes[n.rightId].parentId = n.id;
        this._nodeInfo[n.rightId].sibling = n.leftId;
      }
    });
    this.nodes.forEach(n => {
      this._nodeInfo[n.id] = {sibling: this._nodeInfo[n.id].sibling, node: n, degree: (n.leftId !== -1) + (n.rightId !== -1)}
    });
  }

  getDepth(id, i = 0) {
    let pid = this.find(id).parentId;
    return pid === -1 ? i : this.getDepth(pid, i + 1);
  }

  getHeight(id, i = 0) {
    if (id === -1) return i - 1;
    let n = this.find(id);
    let [lid, rid] = [n.leftId, n.rightId];
    return Math.max(this.getHeight(lid, i + 1), this.getHeight(rid, i + 1))
  }

  find(id) {return this.nodes[id]}

  print() {
    console.log(this._nodeInfo.map(o =>
      `node ${o.node.id}: parent = ${o.node.parentId}, sibling = ${o.sibling}, degree = ${o.degree}, depth = ${this.getDepth(o.node.id)}, height = ${this.getHeight(o.node.id)}, ${o.node.type}`
    ).join('\n'));
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  let tree = new BinaryTree();

  let id, l, r;
  lines.map(l => l.split(' ').map(Number)).forEach(function(line) {
    tree.add(...line);
  });
  tree.connect();
  tree.print();
})();



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int a, b;
    cin >> a >> b;
    if(b % a == 0) cout << a + b << endl;
    else cout << b- a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(void){
    int a,b,ans=0;
    std::cin>>a>>b;
    if(a>b){
        for(int i=0;i<a;i++){
            std::cout<<b;
            ans+=b*std::pow(10,i);
        }
    }
    else{
        for(int i=0;i<b;i++){
            std::cout<<a;
            ans+=a*std::pow(10,i);
        }
    }
    //std::cout<<"\n"<<ans<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> interval(100005);
    rep(i,n){
        if(a[i] != 0) interval[a[i]-1]++;
        interval[a[i]]++;
        interval[a[i]+1]++;
    }
    ll maxcnt = 0;
    rep(i,100002){
        maxcnt = max(maxcnt, interval[i]);
    }
    cout << maxcnt << endl;
    return 0;
}

Measured memory_bytes: 4824
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fir first
#define sec second
#define ll long long
using namespace std;
const int MAXN = 2e5 + 7;
int n, p[MAXN], val[MAXN], cnt[MAXN];
pii e;
bool vis[MAXN];
vector<int>G[MAXN];
int getmex(int u)
{
    int res = 0;
    for (int v : G[u]) if (val[v] != -1) cnt[val[v]]++;
    for (int x = 0; x <= n; x++) if (cnt[x] == 0)
    {
        res = x;
        break;
    }
    for (int v : G[u]) if (val[v] != -1) cnt[val[v]]--;
    return res;
}
void dfs(int u)
{
    vis[u] = 1;
    for (int v : G[u])
    {
        if (vis[v]) 
        {
            if (val[v] == -1) e = {u, v};
            continue; 
        }
        dfs(v);
    }
    val[u] = getmex(u);
}
int main() 
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) 
    {
        scanf("%d", &p[i]);
        G[p[i]].push_back(i);
    }
    memset(val, -1, sizeof(val));
    for (int i = 1; i <= n; i++) if (val[i] == -1) dfs(i);
    if (val[e.fir] != val[e.sec]) puts("POSSIBLE");
    else 
    {
        val[e.fir] = getmex(e.fir);
        int u = p[e.fir];
        while (u != e.fir)
        {
            val[u] = getmex(u);
            u = p[u];
        } 
        if (getmex(e.fir) == val[e.fir]) puts("POSSIBLE");
        else puts("IMPOSSIBLE");
    }
    return 0;
}

Measured memory_bytes: 20480
import std.stdio;

immutable mod = 4294967311L;
long[] inv;

void main(){
	long x;
	int n, y, op;
	scanf("%d", &n);
	inv = new long[1_000_001];
	inv[1] = 1;
	foreach(_; 0..n){
		scanf("%d%d", &op, &y);
		if(op >= 3 && y < 0) x = -x, y = -y;
		if(op == 1) x += y;
		else if(op == 2) x -= y;
		else if(op == 3) x *= y;
		else if(op == 4) x = mul(x, inv_(y));
		x %= mod;
	}

	if(x < 0) x += mod;
	if(x > int.max) x -= mod;

	writeln(x);
}

long inv_(int x){
	return inv[x] ? inv[x] : (inv[x]=mul(inv_(mod%x), mod-mod/x));
}

long mul(long x, long y){
	return ( ((x*(y>>16)%mod)<<16) + (x*(y&0xffff)) ) % mod;
}

Measured memory_bytes: 10748
from collections import deque

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

A = deque()
dp = [0] * N
for i in range(M):
  A.append(int(input()))
A.append(N+1)

if N == 1:
  print(1)

elif N == 2:
  if 1 in A:
    print(1)
  else:
    print(2)
    
else:
  a = A.popleft()
  if a != 1:
    dp[0] = 1
  else:
    a = A.popleft()
    
  if a != 2:
    dp[1] = dp[0] + 1
  else:
    a = A.popleft()
    
  for i in range(2,N):
    if a != i+1:
      dp[i] = dp[i-1] + dp[i-2]
    else:
      a = A.popleft()
  print(dp[-1]%1000000007)

Measured memory_bytes: 470264
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

const int N=6010;
int a[N][N];
int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);

    int n, k, k2; cin>>n>>k;
    k2=k+k;
    for(int x, y; n--; ) {
        char c;
        cin>>x>>y>>c;
        if (c%2) x+=k;
        x%=k2, y%=k2;
        for(int i=0; i<4; ++i) {
            for(int j=0; j<4; ++j) {
                if (i%2!=j%2) continue;
                ++a[y+i*k][x+j*k];
                --a[y+i*k][x+j*k+k];
                --a[y+i*k+k][x+j*k];
                ++a[y+i*k+k][x+j*k+k];
            }
        }
    }
#define rep(i, a) for(int i=a; i<N; ++i)
    rep(i, 0) rep(j, 1) a[i][j]+=a[i][j-1];
    rep(i, 1) rep(j, 0) a[i][j]+=a[i-1][j];

    int res=0;
    rep(i, 0) rep(j, 0) res=max(res, a[i][j]);
    cout<<res<<endl;
}


Measured memory_bytes: 141440
#include<stdio.h>
#define MAX 100000

int parent(int i){ return i / 2; }
int left(int i){ return i * 2; }
int right(int i){ return i * 2 + 1; }

int main(){
  int n, i, A[MAX+1];

  scanf("%d",&n);
  for(i = 1; i <= n; i++) scanf("%d",&A[i]);

  for(i = 1; i <= n; i++){
    printf("node %d: key = %d, ",i, A[i]);
    if(parent(i) >= 1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= n) printf("left key = %d, ",A[left(i)]);
    if(right(i) <= n) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 608
import java.util.Scanner;
//static long X=
public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long X=sc.nextLong();
		long top=0;
		for(long i=1;;i++) {
			if(Math.pow(i,5)-Math.pow(i-1,5)==X) {
				System.out.println(i+" "+(i-1));
				System.exit(0);
			}else if(Math.pow(i,5)-Math.pow(i-1,5)>X) {
				top=i-1;
				break;
			}
		}
		for(long i=top;;i--) {
			if(Math.pow(i,5)>X) {
			for(long j=0;j<=i;j++) {
			if(Math.pow(i,5)-Math.pow(i-j,5)==X) {
				System.out.println(i+" "+(i-j));
				System.exit(0);
			}else if(Math.pow(i,5)-Math.pow(i-j,5)>X) {
				break;
			}
			}
				}else {
					for(long j=0;j<=i;j++) {
						if(Math.pow(i,5)+Math.pow(i-j,5)==X) {
							System.out.println(i+" "+(-i+j));
							System.exit(0);
							}else if(Math.pow(i,5)+Math.pow(i-j,5)<X) {
								break;
							}

				}
		}}
	}
}


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


typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;
typedef vector<vll> vvll;


#define F first
#define S second
#define pb push_back
#define mp make_pair

// don't edit before this line 



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



ll n;
vvll arr;
ll memo[21][1<<21];

ll func(ll m,ll w){

	if(m==n-1)
	{
		ll cnt=0;
		for(int i=0;i<n;i++)
		{
			if(arr[m][i]==1 && !(w & 1<<i))
				cnt++;
		}
		return cnt;
	}
	if(memo[m][w]!=-1)
		return memo[m][w];
	ll cc = 0;
	for(int i=0;i<n;i++)
	{
		if(arr[m][i]==1 && !(w & 1<<i))
			{
				cc+=func(m+1,w|1<<i);
				cc=cc%mod;
			}
	}
	return memo[m][w]=cc;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cout.setf(ios::fixed), cout.precision(20);

	cin >> n;
	arr.resize(n);

	for(int i=0;i<n;i++)
	{
		arr[i].resize(n);
		for(int j=0;j<n;j++)
			cin >> arr[i][j];
	}

	for(int i=0;i<21;i++)
		for(int j=0;j<1<<21;j++){
			memo[i][j]=-1;
		}
	ll xx = func(0,0);
	cout<<xx<<"\n";
	
	return 0;
}


Measured memory_bytes: 344320
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans;
    ll n,q;
    cin>>n>>q;
    ll s[n+1];
    s[0]=0;
    char now,prev;
    now='Z';

    for(int i=0;i<n;i++){
        s[i+1]=0;
        prev=now;
        cin>>now;
        if(prev=='A'&&now=='C'){
            s[i+1]=s[i]+1;
        }else{
            s[i+1]=s[i];
        }
    }
    for(int i=0;i<q;i++){
        ll l,r;
        cin >>l>>r;
        cout <<(s[r]-s[l])<<endl;
    }

    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    dbg cout <<ans<<endl;

    return 0;

}

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

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  vector<int> a(3),b(3),c(3);
  int n,d;
  cin >> a[0] >> a[1] >> a[2] >> b[0] >> b[1] >> b[2] >> c[0] >> c[1] >> c[2] >> n;
  for (int i = 0; i < n; i++){
    cin >> d;
    for (int j = 0; j < 3; j++){
      if (a[j] == d){
        a[j] = 0;
      }
    }
    for (int j = 0; j < 3; j++){
      if (b[j] == d){
        b[j] = 0;
      }
    }
    for (int j = 0; j < 3; j++){
      if (c[j] == d){
        c[j] = 0;
      }
    }
  }
  if (a[0] == 0 && a[1] == 0 && a[2] == 0){
    cout << "Yes\n";
    return 0;
  }
  if (b[0] == 0 && b[1] == 0 && b[2] == 0){
    cout << "Yes\n";
    return 0;
  }
  if (c[0] == 0 && c[1] == 0 && c[2] == 0){
    cout << "Yes\n";
    return 0;
  }
  if (a[0] == 0 && b[0] == 0 && c[0] == 0){
    cout << "Yes\n";
    return 0;
  }
  if (a[1] == 0 && b[1] == 0 && c[1] == 0){
    cout << "Yes\n";
    return 0;
  }
  if (a[2] == 0 && b[2] == 0 && c[2] == 0){
    cout << "Yes\n";
    return 0;
  }
  if (a[0] == 0 && b[1] == 0 && c[2] == 0){
    cout << "Yes\n";
    return 0;
  }
  if (c[0] == 0 && b[1] == 0 && a[2] == 0){
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
  return 0;
}

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

using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);
#define Infi                0x3f3f3f3f

const int dx[] = {+1,-1,+0,+0};                         // 4 X directions
const int dy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int dx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int dy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

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( 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...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif

typedef long long int           ll;
typedef unsigned long long int  llu;


int main(void){

   // READ_IN;
   string s;
   cin >> s;

   if(s[3-1]==s[4-1] && s[5-1]==s[6-1]){
    cout << "Yes" << endl;
   }
   else{
    cout << "No" << endl;
   }


    return 0;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long ruijou(long long m,long long n){
    long long i,a=1;
    for(i=0;i<n;i++){
        a=a*m;
    }
    return a;
}
int main(void){
    long long N,n,i,sum;
    cin >> N;
    n=N;
    if(N<100){
        cout << 0 << endl;
        return 0;
    }
    for(i=0;n>9;i++){
        n=n/10;
    }
    long long N1=n;
    n=i+1;
    sum=0;
    for(i=3;i<n;i++){
        sum+=ruijou(3,i)-ruijou(2,i)*3+3;
    }
    long long sumn;
    sumn=ruijou(3,n-1)-(ruijou(2,n-1)-2)*2-3;
    for(i=1;i<N1;i++){
        if(i==3||i==5||i==7){
            sum+=sumn;
        }
    }
    if(N1==3||N1==5||N1==7){
        long long N2=(N/ruijou(10,n-2))%10;
        for(i=0;i<N2;i++){
            if(i==3||i==5||i==7){
                if(N1==i){
                    sum+=ruijou(3,n-2)-ruijou(2,n-1)+1;
                }else{
                    sum+=ruijou(3,n-2)-ruijou(2,n-2);
                }
            }
        }
        if(N2==3||N2==5||N2==7){
            for(i=0;i<N%ruijou(10,n-2)+1;i++){
                long long j,a=0,b=0,c=0,d=1,M=N-i;
                for(;M>0;){
                    if(M%10==3){
                        a=1;
                    }
                    else if(M%10==5){
                        b=1;
                    }
                    else if(M%10==7){
                        c=1;
                    }else{
                        d=0;
                    }
                    M=M/10;
                }
                if(a*b*c*d==1){
                    sum++;
                }
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int digsum(n){
  int array[10],i,ans=0;
  for(i=9;i>=0;i--){
    array[i] = n / (int)pow(10,i);
    n = n % (int)pow(10,i);
    ans += array[i];
  }
  return ans;
}

int main(){
  int N,S;
  scanf("%d",&N);
  S = digsum(N);
  if(N%S==0) printf("Yes");
  else printf("No");
  return 0;
}

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

using namespace std;

#define ge getchar()
#define Re read()

inline int read() {
	int x = 0, ch;
	while(!isdigit(ch = ge)) ;
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = ge;
	return x;
}
template<typename T>
inline void chkmin(T&x, T y) { x = x < y ? x : y; }

const int MAXN = 500000;

int a[MAXN + 1];
int d[MAXN + 1];
int to[MAXN + 1][2];
int T[MAXN << 2];
int id[MAXN + 1];

priority_queue<int, vector<int>, greater<int> >q;

#define ls (nd << 1)
#define rs (nd << 1 | 1)

inline void Modify(int nd, int l, int r, int p, int v) {
	T[nd] = v; if(l == r) return ; int mid = (l + r) >> 1;
	if(p <= mid) Modify(ls, l, mid, p, v);
	else Modify(rs, mid + 1, r, p, v);
}

inline int Query(int nd, int l, int r, int L, int R) {
	if(L <= l && r <= R) return T[nd];
	int mid = (l + r) >> 1, res = 2147483647;
	if(L <= mid) chkmin(res, Query(ls, l, mid, L, R));
	if(mid < R) chkmin(res, Query(rs, mid + 1, r, L, R));
	return res;
}

#undef ls
#undef rs

int main() {
	int n = Re, k = Re;
	for(int i = 1; i <= n; i++) a[Re] = i;
	memset(T, 63, sizeof(T));
	for(int i = n; i >= 1; i--) {
		int L = Query(1, 1, n, max(1, a[i] - k + 1), a[i]);
		int R = Query(1, 1, n, a[i], min(n, a[i] + k - 1));
		if(L <= n && a[i] - a[L] < k) d[a[L]]++, to[a[i]][0] = a[L];
		if(R <= n && a[R] - a[i] < k) d[a[R]]++, to[a[i]][1] = a[R];
		Modify(1, 1, n, a[i], i);
	} int x, u, ct = 0;
	for(int i = 1; i <= n; i++) if(!d[i]) q.push(i);
	while(!q.empty()) {
		id[x = q.top()] = ++ct; q.pop();
		u = to[x][0]; if(u) { d[u]--; if(!d[u]) q.push(u); }
		u = to[x][1]; if(u) { d[u]--; if(!d[u]) q.push(u); }
	} for(int i = 1; i <= n; i++) printf("%d\n", id[i]);
	return 0;
}

Measured memory_bytes: 21876
#include <stdio.h>

#define INF (1000000000)

int v[100];
int dist[100];
int cost[100][100];
int n, m;

int prim(void)
{
    int i, j;
    int temp;
    int res;
    
    for (i = 0; i < n; i++){
        v[i] = 0;
    }
    
    res = 0;
    dist[0] = 0;
    while (1){
        temp = -1;
        for (i = 0; i < n; i++){
            if (v[i] == 0 && (temp == -1 || dist[i] < dist[temp])){
                temp = i;
            }
        }
        
        if (temp == -1){
            break;
        }
        
        v[temp] = 1;
        
        res += dist[temp];
        
        for (i = 0; i < n; i++){
            dist[i] = dist[i] > cost[temp][i] ? cost[temp][i] : dist[i];
        }
    }
    
    return (res);
}

int main(void)
{
    int i, j;
    int a, b, tcost;
    
    while (1){
        scanf("%d%d", &n, &m);
        
        if (n + m == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            dist[i] = INF;
            for (j = 0; j < n; j++){
                cost[i][j] = INF;
            }
            cost[i][i] = 0;
        }
        
        for (i = 0; i < m; i++){
            scanf("%d%d%d", &a, &b, &tcost);
            cost[a][b] = cost[b][a] = tcost;
        }
        
        printf("%d\n", prim());
    }
    
    return (0);
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>

using namespace std;

const long double EPS = 1e-10;

class Point{
    public: 
    long double x,y;
    Point(long double x = 0.0, long double y = 0.0): x(x), y(y) {}
    Point operator + (Point p) const { return Point(x+p.x, y+p.y); }
    Point operator - (Point p) const { return Point(x-p.x, y-p.y); }
    Point operator * (long double a) const { return Point(x*a, y*a); }
    Point operator / (long double a) const { return Point(x/a, y/a); }
    bool operator < (const Point &p) const { return (x != p.x ? x < p.x : y < p.y); }
    bool operator == (const Point &p) const { return fabsl(x - p.x) < EPS && fabsl(y - p.y) < EPS; }
    long double abs() const { return sqrt(norm()); }
    long double norm() const { return x*x + y*y; }
    long double dot(Point p) const { return x*p.x + y*p.y; }
    long double cross(Point p) const { return x*p.y - y*p.x; }   
};

class Segment{
    public: 
    Point p,q;
    Segment(Point p, Point q): p(p), q(q) {}
};

typedef Point Vector;

Point getCrossPoint(Segment s1, Segment s2){
    Vector base = s2.q - s2.p;
    long double d1 = abs(base.cross(s1.p - s2.p));
    long double d2 = abs(base.cross(s1.q - s2.p));
    long double t = d1 / (d1+d2);
    return s1.p + (s1.q - s1.p) * t;
}

int main(){
    int n;
    cin >> n;
    vector<Point> ps(4, Point());
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++){
            cin >> ps[j].x >> ps[j].y;
        }
        Segment s1 = Segment(ps[0], ps[1]);
        Segment s2 = Segment(ps[2], ps[3]);
        Point cross_point = getCrossPoint(s1, s2);
        printf("%.10Lf %.10Lf\n", cross_point.x, cross_point.y);
    }
}


Measured memory_bytes: 3280
# List = [list(map(int, input().split()))]
# List = [int(input(i)) for i in range(6)]
List = list(int(input()) for i in range(5))
K = int(input())
# print(List)
times = int(0)

for j in range(len(List) - 1):
    for k in range(len(List) - 1):
        if(List[-j] - List[k] > K):
            # print(":(")
            times += 1
            # continue
if(times == 0):
    print("Yay!")
else:
    print(":(")
    
    

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))
#define max(p,q)((p)>(q)?(p):(q))

char s[100010];
int main(){
	scanf("%s",s);
	int n=strlen(s);
	
	ll ans=n;
	rep(i,0,n-1)if(s[i]!=s[i+1])ans=min(ans,max(n-1-i,i+1));
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;
using namespace std::chrono;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
int mod=1000000007;
const int MX=0x3f3f3f3f;

vector<vi> v;
int ans,n,m,q;
vi p;
void func(int i,int num){
	if(i==n){
		int j,temp=0;
		REP(j,0,q-1) {
			if(p[v[j][1]-1]-p[v[j][0]-1]==v[j][2]) temp+=v[j][3];
		}
		ans=max(ans,temp);
		return;
 	}
	for(int j=num;j<=m;j++){
		p.EB(j);
		func(i+1,j);
		p.pop_back();
	}
}	

int main() {
	IOS;
	int i,j,temp;
	cin>>n>>m>>q;
	v=vector<vi>(q);
	REP(i,0,q-1)
		REP(j,0,3) cin>>temp,v[i].EB(temp);
	func(0,1);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3660
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            WillReturn.Add("2 1 4");
            WillReturn.Add("2");
            WillReturn.Add("1 1");
            WillReturn.Add("2 3");
            //6
            //9
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("7 2 3 8 5");
            WillReturn.Add("3");
            WillReturn.Add("4 2");
            WillReturn.Add("1 7");
            WillReturn.Add("4 13");
            //19
            //25
            //30
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct PXDef
    {
        internal int P;
        internal int X;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] TArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
        var PXList = new List<PXDef>();

        for (int I = 3; I <= InputList.Count - 1; I++) {
            int[] wkArr = { };
            Action<string> SplitAct = pStr =>
                wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

            SplitAct(InputList[I]);
            PXList.Add(new PXDef { P = wkArr[0], X = wkArr[1] });
        }

        int SumVal = TArr.Sum();
        foreach (PXDef EachPX in PXList) {
            int wkSum = SumVal;
            wkSum -= TArr[EachPX.P - 1];
            wkSum += EachPX.X;
            Console.WriteLine(wkSum);
        }
    }
}


Measured memory_bytes: 3032
def main():
    import collections
    N, P = map(int, input().split())
    S = input()[::-1]
    ans = 0
    if P == 2 or P == 5:
        for i, s in enumerate(S):
            if int(s) % P == 0:
                ans += N - i
    else:
        mod = [0] * P
        mod[0] = 1
        current = 0
        X = 1
        for s in S:
            current = (current + int(s) * X) % P
            ans += mod[current]
            mod[current] += 1
            X = X * 10 % P
    
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=2e5;
const int inf=1e9;
int main(){
	int N,M; cin>>N>>M;
	cout<<pow(2, M) * (100 * (N-M) + 1900 * M)<<endl;
}

Measured memory_bytes: 4280
import sys
input = sys.stdin.readline

"""
・とりあえず部分点解法：各クエリに対してO(N)
・いくつかを残していくつかを自由に埋める
・残すもの：被覆区間がoverlapしないように残す
・つまり、区間で覆えている点が処理できて、区間で覆えていない点が他所から持ってこないといけない。
"""

N,M = map(int,input().split())
A = [int(x) for x in input().split()]
XY = [tuple(int(x) for x in input().split()) for _ in range(M)]

def subscore_solution():
    from collections import Counter
    for x,y in XY:
        A[x-1] = y
        covered = [False] * (N+N+10)
        for key,cnt in Counter(A).items():
            for i in range(cnt):
                covered[max(0,key-i)] = True
        print(sum(not bl for bl in covered[1:N+1]))

counter = [0] * (N+1)
covered = [0] * (N+N+10)
for a in A:
    counter[a] += 1
    covered[a-counter[a]+1] += 1
magic = sum(x==0 for x in covered[1:N+1])

for i,y in XY:
    x = A[i-1]
    A[i-1] = y
    rem = x - counter[x] + 1
    counter[x] -= 1
    counter[y] += 1
    add = y - counter[y] + 1
    covered[rem] -= 1
    if 1<=rem<=N and covered[rem] == 0:
        magic += 1
    if 1<=add<=N and covered[add] == 0:
        magic -= 1
    covered[add] += 1
    print(magic)



Measured memory_bytes: 47496
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=1010, inf=1e9, mod=1e9+7;
int n, N;
int h[maxn], b[maxn], f[maxn][maxn];

template<typename T>
inline void read(T &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;	
}

inline int power(int a, int b)
{
	if(b<0) return 1;
	int ans=1;
	for(;b;b>>=1, a=1ll*a*a%mod)
	if(b&1) ans=1ll*a*ans%mod;
	return ans;
}
 
int main()
{
	read(n);
	for(int i=1;i<=n;i++) read(h[i]), b[++N]=h[i];
	sort(b+1, b+1+N); N=unique(b+1, b+1+N)-b-1;
	for(int i=1;i<=n;i++) h[i]=lower_bound(b+1, b+1+N, h[i])-b;
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		f[i][0]=2ll*f[i-1][0]%mod;
		for(int j=h[i]+1;j<=h[i-1];j++) f[i][0]=(f[i][0]+2ll*f[i-1][j])%mod;
		int sj=min(h[i], h[i-1]);
		for(int j=1;j<=sj;j++)
		f[i][j]=1ll*f[i-1][j]*power(2, b[h[i]]-b[h[i-1]])%mod;
		for(int j=h[i-1]+1;j<=h[i];j++)
		if(j>1) f[i][j]=(f[i][j]+1ll*f[i-1][0]*(power(2, b[j]-b[j-1])-1+mod)*2%mod*power(2, b[h[i]]-b[j]))%mod;
		else f[i][j]=(f[i][j]+1ll*f[i-1][0]*(power(2, b[j]-1)-1)*2%mod*power(2, b[h[i]]-b[j]))%mod;
	}
	int ans=0;
	for(int i=0;i<=N;i++) ans=(ans+f[n][i])%mod;
	printf("%d\n", ans);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
int main(void)
{
    long long mod = 1000000007;
    long long N, K;
    cin >> N >> K;
    vector<vector<long long>> A(N, vector<long long>(2));
    for (long long i = 0; i < N; i++)
    {
        long long a;
        cin >> a;
        if (a >= 0)
        {
            A[i][0] = a;
            A[i][1] = 0;
        }
        else
        {
            A[i][0] = a * (-1);
            A[i][1] = 1;
        }
    }
 
    sort(A.begin(),A.end(),[](const vector<long long> &alpha,const vector<long long> &beta){return alpha[0] > beta[0];});
 
    long long ans = 1;
    long long check = 0;
    for (long long i = 0; i < K; i++)
    {
        check += A[i][1];
    }

    if (check % 2 == 1)
    {
        long long num1 = 0;
        bool num1check = false;
        long long num2 = 0;
        bool num2check = false;
        long long num3 = N-1;
        for (long long i = K; i < N; i++)
        {
            if (A[i][1] != A[K-1][1])
            {
                num1 = i;
                num1check = true;
                break;
            }
        }
        for (long long i = K-2; i > -1; i--)
        {
            if (A[i][1] != A[K-1][1])
            {
                for (long long j = K; j < N; j++)
                {
                    if (A[j][1] != A[i][1])
                    {
                        num2 = i;
                        num3 = j;
                        num2check = true;
                        break;
                    }
                }
                break;
            }
        }
        if (num1check == false && num2check == false)
        {
            for (long long j = N-1; j > N - K-1; j--)
            {
                ans = ans * A[j][0] % mod;
            }
            ans = (mod - ans) % mod;
            cout << ans << endl;
            exit(0);
        }

        if(((A[num1][0] * A[num2][0] >= A[num3][0] * A[K-1][0]) && num1check == true) || num2check == false)
        {
            for (long long i = 0; i < K-1; i++)
            {
                ans = ans * A[i][0] % mod;
            }
            ans = ans * A[num1][0] % mod;
        }
        else
        {
            for (long long i = 0; i < K; i++)
            {
                if (i != num2)
                {
                    ans = ans * A[i][0] % mod;
                }
            }
            ans = ans * A[num3][0] % mod;
        }
        cout << ans << endl;
        exit(0);
    }
    for (long long i = 0; i < K; i++)
    {
        ans = ans * A[i][0] % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 14556
// created_by  Rishi_Mohan

#include<bits/stdc++.h>

#define    ll           long long
#define    db1(x)       cout<<#x<<"="<<x<<'\n'
#define    db2(x,y)     cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define    db3(x,y,z)   cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

using namespace std;

void solve()
{
    ll n,k;
    cin >> n >> k;
    vector<int>v(n+1,0);
    while(k--)
    {
        ll d;
        cin >> d;
        for(int i=1;i<=d;i++)
        {
            ll x;
           cin >> x;
           v[x] += i;
        }

    }
    //for(int i=0;i<n;i++) cout
    int ans = count(v.begin(),v.end(),0);
    cout << ans-1 ;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,temp,dp[100004],k,j;
	cin>>n;
	cin>>k;
	vector<int>v;
	for(i=0;i<n;i++)
		{
			cin>>temp;
			v.push_back(temp);
		}
	
	dp[0]=0;
//	dp[1]=abs(v[0] - v[1]);
	for(i=1;i<=k;i++)
		{
			dp[i]=abs(v[0] - v[i]);
		}
	for(i=k + 1;i<n;i++)
		{
			//dp[i] = min(  (dp[i-1] + abs(v[i] - v[i-1]) )  , ( dp[i-2] + abs(v[i] - v[i-2])  )       );
			int minn=INT_MAX,sum=0;
			for(j=i-k;j<i;j++)
				{
					sum=dp[j] + abs(v[j] - v[i]);
					if(minn>sum)
						minn=sum;
					
					sum=0;	
				}
			
			dp[i]=minn;	
		}
	
	cout<<dp[n-1]<<endl;	
	
}

Measured memory_bytes: 1144
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int[][] AB = new int[N][2];
        for (int i = 0; i < N; i++) {
            AB[i][0] = sc.nextInt();
            AB[i][1] = sc.nextInt();
        }

        Arrays.sort(AB, (a, b) -> a[0] - b[0]);

        int max = 0;
        int[] dp = new int[T];

        for (int i = 0; i < N; i++) {
            int a = AB[i][0];
            int b = AB[i][1];
            max = Math.max(max, dp[T-1] + b);
            for (int j = T - 1; j >= 0; j--) {
                dp[j] = dp[j];
                if (j >= a) {
                    dp[j] = Math.max(dp[j], dp[j-a] + b);
                }
            }
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 33152