akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bitset>
#include <vector>
#include <algorithm>

using namespace std;

int flip_board(vector<bitset<10000>> board, int R, int C, int count) {
  for (int i = 0; i < R; ++i) {
    if (count & (1 << i)) {
      board[i].flip();
    }
  }
  int sum = 0;
  for (int i = 0; i < C; ++i) {
    int col = 0;
    for (int j = 0; j < R; ++j) {
      if (board[j][i]) col++;
    }
    sum += max(col, R - col);
  }
  return sum;
}

int main() {
  int R, C;
  while (cin >> R >> C) {
    if (R == 0 || C == 0) {
      break;
    }
    vector<bitset<10000>> board(10);
    for (int i = 0; i < R; ++i) {
      for (int j = 0; j < C; ++j) {
        int num;
        cin >> num;
        if (num) board[i][j] = true;
      }
    }
    int count = 0;
    int ret = 0;
    while (count < (1 << R)) {
      int ups = flip_board(board, R, C, count);
      ret = max(ret, ups);
      ++count;
    }
    cout << ret << endl;
  }
}

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

using namespace std;

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

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

    int n;
    cin >> n;
    vector<ll> a(n);
    ll x = 0;
    set<ll> st;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        x ^= a[i];
        st.insert(a[i] ^ (a[i] - 1));
    }
    int res = 0;
    for (ll k = 30; k >= 1; k--)
    {
        if ((x >> (k - 1)) & 1)
        {
            if (st.find((1 << k) - 1) != st.end())
            {
                x ^= (1 << k) - 1;
                res++;
            }
        }
    }
    if (x != 0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << res << endl;
    }
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		List<List<Integer>> graph = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			graph.add(new ArrayList<>());
		}
		
		for (int i = 1; i < n; i++) {
			int a = sc.nextInt();
			a--;
			graph.get(a).add(i);
		}
		
		for (int i = 0; i < n; i++) {
			System.out.println(graph.get(i).size());
		}
	}
}


Measured memory_bytes: 76740
a = list(map(int, input().split()))
c = 3
if a[0] == a[1] and a[0] == a[2] and a[1] == a[2]:
    c = 1
elif a[0] == a[1] or a[0] == a[2] or a[1] == a[2]:
    c = 2
print(c)

Measured memory_bytes: 38256
import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args) throws Exception {
		FastIO sc = new FastIO(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.nextInt();
		int[] h = new int[N];
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		
		int[] minCost = new int[N];
		Arrays.fill(minCost, (int)2e9);
		minCost[0] = 0;
		for(int i = 0; i < N; i++) {
			if(i+2 < N) minCost[i+2] = Math.min(minCost[i+2], minCost[i]+Math.abs(h[i+2]-h[i]));
			if(i+1 < N) minCost[i+1] = Math.min(minCost[i+1], minCost[i]+Math.abs(h[i+1]-h[i]));
		}
		
		pw.println(minCost[N-1]);
		pw.close();
		
	}

	static class FastIO {

		//Is your Fast I/O being bad?

		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;

		public FastIO(String fileName) throws Exception {
			dis = new FileInputStream(fileName);
		}

		public FastIO(InputStream is) throws Exception {
			dis = is;
		}

		int nextInt() throws Exception {
			int ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}

		long nextLong() throws Exception {
			long ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}

		byte nextByte() throws Exception {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}

		String next() throws Exception {
			StringBuffer ret = new StringBuffer();

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}

			return ret.toString();
		}

	}
}


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


int main(){
  long long int N, K;
  cin >> N >> K;
  set<long long int> checked;
  checked.insert(N);
  while(true){
    N = (N>K?N%K:abs(N-K));
    if(checked.find(N)==checked.end()){
      checked.insert(N);
    }else{
      break;
    }
  }
  cout << *checked.begin() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define sort(ss) sort(ss.begin(), ss.end())
#define rsort(ss) sort(ss.rbegin(), ss.rend())
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	char x1,x2,bb='A',a;
	while(cin>>x1>>a>>x2){
		if(x1==bb){
			bb=x2;
		}
		else if(x2==bb){
			bb=x1;
		}
	}
	cout<<bb<<endl;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

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

    int ans = n*n;

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

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

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


int main(){
  while(1){
    string s,sub;
    cin >> s;
    if(s == "-") break;
    int m;
    cin >> m;
    rep(i,m){
      int n;
      cin >> n;
      sub = s.substr(0, n);
      s.erase(0, n);
      s += sub;
    }
    cout << s << endl;
  }
}






Measured memory_bytes: 3216
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N;
    string S, T;
    

    cin >> N >> S >> T;
    string X = "";
    for (int i = 0; i < N; i++){
        X = X + S[i];        
        X = X + T[i];
    }
    cout << X << endl;
    return 0;
}


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

using namespace std;

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

int main() {
  
  int W, D;
  while(cin >> W >> D && (W|D)) {
    vector<int> h1(W), h2(D);
    map<int, int> mp1, mp2;
    int mx = 0;
    rep(i, W) { cin >> h1[i]; mp1[h1[i]] ++; mx = max(mx, h1[i]); }
    rep(i, D) { cin >> h2[i]; mp2[h2[i]] ++; mx = max(mx, h2[i]); }
    
    int ans = 0;
    /*
    for(map<int, int>::iterator it=mp1.begin(); it!=mp1.end(); it++) {
      ans += max(it->second, mp2[it->first])*it->first;
    }
    */
    for(int i=1; i<=mx; i++) {
      ans += max(mp1[i], mp2[i])*i;
    }
    
    cout << ans << endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 1196
#include<stdio.h>
#define MAX 10000
#define NIL -1
 
struct Node{
   
  int p, l, r;
 
};
 
struct Node T[MAX];
 
int n;
int D[MAX], H[MAX];
 
int getDepth(int);
int getSibling(int);
void print(int);
 
 
 
int main(){
   
  int i;
  int v;
  int l, r;
 
   
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ) {
     
    T[i].p = NIL;
     
  }
 
  for ( i = 0; i < n; i++ ){
     
    scanf("%d %d %d", &v, &l, &r);
 
    T[v].l = l;
    T[v].r = r;
 
    if ( l != NIL ) {
      T[l].p = v;
    }
     
    if ( r != NIL ) {
      T[r].p = v;
    }
  }
 
  for ( i = 0; i < n; i++ ){
     
    D[i] = getDepth(i);
    H[i] = 0;
 
  }
 
  for ( i = 0; i < n; i++ ){
    if ( T[i].l == NIL && T[i].r == NIL ) {
       
      H[i] = 0;
 
       
      int p = T[i].p;
      int c = 1;
       
      while(1){
     
    if ( p == NIL ) break;
    if ( H[p] < c ) {
      H[p] = c;
    }
     
    c++;
    p = T[p].p;
     
      }
    }
  }
 
  for ( i = 0; i < n; i++ ){
    print(i);
  }
   
  return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
int getDepth(int u){
   
  int d = 0;
 
  while(1){
 
    u = T[u].p;
    if ( u == NIL ) break;
    d++;
 
  }
  return d;
}
 
 
int getSibling(int u){
   
  if ( T[u].p == NIL ) return NIL;
  if ( T[T[u].p].l != u && T[T[u].p].l != NIL ) return T[T[u].p].l;
  if ( T[T[u].p].r != u && T[T[u].p].r != NIL ) return T[T[u].p].r;
   
  else  return NIL;
   
}
 
void print(int u){
   
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].p);
  printf("sibling = %d, ", getSibling(u));
 
   
  int deg = 0;
   
  if ( T[u].l != NIL ) deg++;
  if ( T[u].r != NIL ) deg++;
 
   
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);
 
   
  if ( T[u].p == NIL ){
     
    printf("root\n");
     
  }
  else if ( T[u].l == NIL && T[u].r == NIL ){
     
    printf("leaf\n");
     
  }
  else {
     
    printf("internal node\n");
     
  }
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

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

using namespace std;

int main()
{
  FAST/**/
   
   ll l,r,d;
   cin>>l>>r>>d;
   
   ll ans = 0;
   for(ll i=l;i<=r;i++)
   {
       if(i%d == 0)
            ans++;
   }
   
   cout<<ans;
   
   return 0;        
}  
  
          
   

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<climits>

#define pii pair<int,int>
#define ll long long
#define MOD 1000000007
#define in2d(i,j,H,W)(0<=i&&i<H&&0<=j&&j<W)

using namespace std;

int N;
vector<vector<int> >G;
vector<vector<int> >child;
vector<vector<ll> >dp;
ll dfs(int i,int c){
	if(dp[i][c]!=0)return dp[i][c];
	ll ans=1;
	if(c==1){
		for(int j=0;j<child[i].size();j++){
			int k=child[i][j];
			ans=(ans*dfs(k,0))%MOD;
		}
	}else{
		for(int j=0;j<child[i].size();j++){
			int k=child[i][j];
			ans=(ans*(dfs(k,0)+dfs(k,1)))%MOD;
		}
	}
	return dp[i][c]=ans;
}
vector<bool>done;
void dfs2(int i){
	done[i]=true;
	for(int j=0;j<G[i].size();j++){
		if(!done[G[i][j]]){
			child[i].push_back(G[i][j]);
			dfs2(G[i][j]);
		}
	}
			
}
int main(){
	cout<<fixed<<setprecision(11);

	cin>>N;
	G=vector<vector<int> >(N);
	for(int i=0;i<N-1;i++){
		int x,y;cin>>x>>y;
		G[x-1].push_back(y-1);
		G[y-1].push_back(x-1);
	}
	done=vector<bool>(N,false);
	child=vector<vector<int> >(N);
	dfs2(0);
	dp=vector<vector<ll> >(N,vector<ll>(2,0));
	cout<<(dfs(0,0)+dfs(0,1))%MOD<<endl;
	return 0;
}



Measured memory_bytes: 23552
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))


n,k=input_list()

ans=0

for i in range(1,n+1):
    cal=math.ceil(math.log(k/i,2))
    cal=max(0,cal)
    ans+=(1/2)**(cal)

print(ans/n)

Measured memory_bytes: 3316
n,x=map(int,input().split())
l=list(map(int,input().split()))
d=[0]
ans=1
for i in range(2,n+2):
    z=d[i-2]+l[i-2]
    d.append(z)
    if z<=x:
        ans+=1
    else:
        break
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  ll ans=0;
  for(int i=0;i<n-1;i++){
    if(a[i]>a[i+1]){
      ans+=a[i]-a[i+1];
      a[i+1]=a[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3932
#include <bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp> 

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

int main(void){
	char c;
	cin >> c;
	if(c >= 'A' && c <= 'Z'){
		cout << "A" << endl;
	}
	else{
		cout << "a" << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    
    int ans = 0;
    forn(i, a, b+1) {
        string s = to_string(i);
        string r = s;
        reverse(r.begin(), r.end());
        ans += s==r;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define MAX 400
#define WHITE 0
#define GRAY 1
#define BLACK 2

string s[MAX];
vector<pair<int, int>> m[MAX][MAX];
int c[MAX][MAX];
int dx[]={-1,0,0,1};
int dy[]={0,-1,1,0};

void bfs_init(){
	for(int i=0; i<MAX; i++){
		for(int j=0; j<MAX; j++){
			c[i][j]=WHITE;
		}
	}
	return;
}

ll bfs(int x, int y){
	ll b_cnt=0, w_cnt=0;
	queue<pair<int, int>> q;

	c[x][y]=GRAY;
	if(s[x][y]=='.') w_cnt++;
	else b_cnt++;

	q.push(make_pair(x,y));
	while(!q.empty()){
		pair<int,int> u=q.front();
		q.pop();
		int i=u.first, j=u.second;
		int l=m[i][j].size();
		for(int k=0; k<l; k++){
			int xx=m[i][j][k].first, yy=m[i][j][k].second;
			if(c[xx][yy]==WHITE){
				c[xx][yy]=GRAY;
				if(s[xx][yy]=='.') w_cnt++;
				else b_cnt++;
				q.push(make_pair(xx,yy));
			}
		}
		c[x][y]=BLACK;
	}
	return b_cnt*w_cnt;
}

int main(){
	int h, w;
	cin >> h >> w;
	for(int i=0; i<h; i++) cin >> s[i];

	vector<pair<int, int>> v;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			for(int k=0; k<4; k++){
				int x=i+dx[k], y=j+dy[k];
				if(x<0 || x>=h || y<0 || y>=w) continue;
				if(s[i][j]!=s[x][y]){
					m[i][j].push_back(make_pair(x,y));
				}
			}
		}
	}

	ll ans=0;
	bfs_init();
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(c[i][j]==WHITE){
				ans+=bfs(i, j);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N,M;
  cin >> N>>M;
  vec<vec<int>>a(M,vec<int>(2));
  REP(i,M){
    cin>>a[i][1]>>a[i][0];
  }
  sort(ALL(a));
  int ans=0,now=-1;
  REP(i,M){
    if (now<a[i][1]){
      now =a[i][0]-1;
      ans++;
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a[5];
  for(int i=0;i<5;i++)
  {
    cin>>a[i];
      
  }
  for(int i=0;i<5;i++)
  {
    if(a[i]==0)
      cout<<(i+1);
  }
  return 0;
}
  
  


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


int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
       long long int a,b,c,k;
       cin>>a>>b>>c>>k;
       long long int sum=0;
       if(a>=k){
        sum = sum +  k;
       }
       else if((a+b)>=k){
        sum = sum + a;
       }
       else if((a+b+c)>=k){
        sum = sum + a;
        sum = sum - (k - (a+b));
       }
       cout<<sum<<"\n";

     return 0;   
            
        
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

void solve(ll n,ll m){
	ll ans=0;
	vl v(n);
	rep(i,n){
		cin>>v[i];
	}
	v.push_back(0);
	vl cop;
	rep(i,n+1){
		range(j,i,n+1){
			cop.push_back(v[i]+v[j]);
		}
	}
	sort(all(cop));
	for(auto x:cop){
		ll y=m-x;
		if(y<0)continue;
		auto itr=upper_bound(all(cop),y);
		if(*itr!=0)itr--;
		ans=max(*itr+x,ans);
	}
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	while(cin>>n>>m,n){
		solve(n,m);
	}
}



Measured memory_bytes: 10724
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end();
int main() {
  int a;
  cin >> a;
  int b = a/100;
  b *= 111;
  if(a<=b) cout << b;
  else cout << b + 111;
}

Measured memory_bytes: 3576
#!/usr/bin/env python
# coding: utf-8


def main():
    a1, b1 = list(map(int, input().split()))
    a2, b2 = list(map(int, input().split()))
    a3, b3 = list(map(int, input().split()))
    l = [0 for _ in range(5)]
    l[a1] += 1
    l[b1] += 1
    l[a2] += 1
    l[b2] += 1
    l[a3] += 1
    l[b3] += 1
    for n in range(1, 5):
        if l[n] == 0 or l[n] == 3:
            print('NO')
            return
    print('YES')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    vector<pii> a(n);
    rep(i,n){
        int x;
        cin >> x;
        a[i] = pii(x, i + 1);
    }
    sort(a.begin(), a.end());
    rep(i,n){
        cout << a[i].second << " \n"[i==n-1];
    }
}

Measured memory_bytes: 1536
use std::cmp;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn find_min(x: &[u32]) -> u32 {
    let mut min: u32 = x[0];
    let mut x_iter = x.iter();
    while let Some(i) = x_iter.next() {
        min = cmp::min(*i, min);
    }
    return min;
}

#[allow(dead_code)]
fn find_max(x: &[u32]) -> u32 {
    let mut max: u32 = x[0];
    let mut x_iter = x.iter();
    while let Some(i) = x_iter.next() {
        max = cmp::max(*i, max);
    }
    return max;
}

fn main() {
    let _n: usize = read();
    let length: Vec<u32> = read_vec();

    let max = find_max(&length);

    let sum: u32 = length.iter().fold(0, |sum, &a| sum + a);

    if sum - max <= max {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
def resolve():
    A, B, C, D = list(map(int, input().split()))
    import math
    n_taka_attacks = math.ceil(C/B)
    n_ao_attacks = math.ceil(A/D)
    print("Yes" if n_taka_attacks <= n_ao_attacks else "No")


if '__main__' == __name__:
    resolve()

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

int main (){
  int total = 0;
  int N, M;
  cin >> N;
  int arrT[N];
  for (int i = 0; i < N; i ++){
    cin >> arrT[i];
  }
  cin >> M;
  int arrP[M], arrX[M];
  for (int i = 0; i < M; i ++){
    total = 0;
    cin >> arrP[i] >> arrX[i];
    for (int j = 0; j < N; j ++){
      if (j + 1 == arrP[i]){
        total += arrX[i];
      } else {
        total += arrT[j];
      }
    }
    cout << total << '\n';
  }
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long  sum,h,n;
    cin>>h>>n;
    for(int i=0;i<n;i++){
        cin>>sum;
        
        h-=sum;
    }
    if(h>0)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
def combination(n, k, p):
    numerator = 1
    for i in range(k):
        numerator = (numerator * (n-i)) % p

    denominator = 1
    for i in range(1, k+1):
        denominator = (denominator * i) % p

    return (numerator * pow(denominator, p-2, p)) % p


X, Y = map(int, input().split())

a = (2*Y-X) / 3
b = (2*X-Y) / 3

if a >= 0 and b >= 0 and a == int(a) and b == int(b):
    a = int(a)
    b = int(b)

    print(combination(a+b, a, 10**9+7))
else:
    print(0)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define MAX 114514
typedef long long int ll;
int main(){
   ll n,h,w;
   ll ans=0,a,b;
   cin>>n>>h>>w;
   for(int i=0;i<n;i++){
       cin>>a>>b;
       if(a>=h&&b>=w)ans++;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

struct UnionFind{
  int n;
  vector<int> ran,p,cnt;
  UnionFind(){}
  UnionFind(int sz):n(sz),ran(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(ran[x]<ran[y]) swap(x,y);
    ran[x]+=ran[y];
    p[y]=x;
  }
  int sum(int x){
    return ran[find(x)];
  }
};

string s[444];
int h,w;

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

int A[410*400];
int B[410*400];

signed main(){
  UnionFind U(410*410);
  cin>>h>>w;
  r(i,h)cin>>s[i];
  r(i,h)r(j,w){
    r(k,4){
      int y=i+dy[k];
      int x=j+dx[k];
      if(y<0||x<0||y>=h||x>=w)continue;
      if( s[i][j] != s[y][x] ){
        U.unite( i*410+j , y*410+x );
      }
    }
  }
  r(i,h)r(j,w){
    int p=i*410+j;
    if(s[i][j]=='.')A[U.find(p)] ++;
    else  B[U.find(p)] ++;
  }
  int ans=0;
  r(i,h)r(j,w){
    int p=i*410+j;
    ans+=A[p]*B[p];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const int MAX = 1010;
ll xyz[MAX][3];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i=0;i<n;i++) {
        cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
    }
    ll ans = 0;
    for (int i=0;i<8;i++) {
        vector<ll> v;
        for (int j=0;j<n;j++) {
            ll sum = 0;
            for (int k=0;k<3;k++) {
                if ((i >> k) & 1) {
                    sum += xyz[j][k];
                } else {
                    sum -= xyz[j][k];
                }
            }
            v.push_back(sum);
        }
        sort(v.begin(), v.end(), greater<ll>());
        ll tmp = 0;
        for (int j=0;j<m;j++) {
            tmp += v[j];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main()
{
  int a,b,c; cin >> a >> b >> c;
  
  cout << c << " " << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int n,l[26],r[26],m;
  m=0;
  string s,x,y;
  cin >> n;
  cin >> s;
  FOR(i,1,n){
    x = s.substr(0,i);
    y = s.substr(i,n-i);
    //cout << x << "|"<< y << endl;
    REP(j,26){
      l[j]=r[j]=0;
    }
    //cout << s.find("abcde",'a');
    REP(j,26){
      l[j]+=(find(x.begin(),x.end(),alp[j])!=x.end());
      r[j]+=(find(y.begin(),y.end(),alp[j])!=y.end());
    }
    //cout << l[0] << r[0];
    int t=0;
    REP(j,26){
      t+=(l[j]>0&&r[j]>0);
    }
    if (t>m)m=t;
  }
  cout << m;
  return 0;
}

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

int main()
{
    long long n,m;cin>>n>>m;
    if(n<m)swap(n,m);
    long long ans=0;
    if(m>=3)
    {
        ans=(n-2)*(m-2);
    }
    else if(m==2)
    {
        ans=0;
    }
    else
    {
        if(n==1)ans=1;
        else ans=n-2;
    }
    cout<<ans<<endl;
    
    
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, N: int, A: "List[int]"):
    print(YES if sum(A) >= H else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(H, N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 13996
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) return b; return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
#define debug2(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...);}
#define time__(d) for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second; debug2("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;

void getac(int T) {
    int n;
    cin>>n;
    ll sum=0;
    ll arr[n];
    map <int , int > m;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
        m[arr[i]]++;
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        ll x, y;
        cin>>x>>y;
        int count1=m[x];
        sum-=count1*x;
        m[x]=0;
        m[y]+=count1;
        sum+=y*count1;
        cout<<sum<<'\n';
    }
}
int  main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
//     freopen("error.txt", "w", stderr);
// #endif
    fastio;
    int t = 1;
    if (takeTestCases) cin >> t;
    int t_t = 1;
    while (t--) {
        if (printCaseNo)
        case (t_t);
        getac(t_t);
        t_t++;
    }
    cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 9020
from collections import defaultdict

s = input()
move = defaultdict(int)
ans = 'Yes'

for c in s:
    move[c] += 1

if move['N'] > 0 and move['S'] == 0:
    ans = 'No'
if move['S'] > 0 and move['N'] == 0:
    ans = 'No'
if move['W'] > 0 and move['E'] == 0:
    ans = 'No'
if move['E'] > 0 and move['W'] == 0:
    ans = 'No'

print(ans)

Measured memory_bytes: 3316
from collections import namedtuple

Edge = namedtuple('Edge', ('fr', 'to', 'cost'))
inf = 1e9


def bellman_ford(n, start, edges):
    dists = [inf for _ in range(n)]
    dists[start] = 0
    while True:
        updated = False
        for e in edges:
            if dists[e.fr] != inf and dists[e.fr] + e.cost < dists[e.to]:
                updated = True
                dists[e.to] = dists[e.fr] + e.cost

        if not updated:
            break

    return dists


def dijkstra(n, costs):
    dists = [inf for _ in range(n)]
    dists[0] = 0
    determined = [False for _ in range(n)]

    while True:
        v, min_d = -1, inf
        for i in range(n):
            if determined[i]:
                continue
            if dists[i] < min_d:
                v, min_d = i, dists[i]

        if v == -1:
            break

        determined[v] = True

        for i in range(n):
            if determined[i] or costs[v][i] == -1:
                continue

            dists[i] = min(dists[i], dists[v] + costs[v][i])

    return dists


n = int(input())

m = [[-1 for _ in range(n)] for _ in range(n)]
es = []
for i in range(n):
    fs = list(map(int, input().split()))
    ne = fs[1]
    for j in range(ne):
        v = fs[2+2*j]
        c = fs[2+2*j+1]
        m[i][v] = c
        es.append(Edge(i, v, c))


# d = bellman_ford(n, 0, es)
d = dijkstra(n, m)
for (i, di) in enumerate(d):
    print(i, di)



Measured memory_bytes: 6740
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
static inline void fast_io()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
using ll = long long;
using ld = long double;

int main()
{
    fast_io();

    ll sum = 0;
    map<long, long> data;
    long n;
    cin >> n;
    for (long i = 0; i < n; i++) {
        long tmp;
        cin >> tmp;
        data[tmp]++;
        sum += tmp;
    }

    long q;
    cin >> q;
    for (long i = 0; i < q; i++) {
        long tmp_b, tmp_c;
        cin >> tmp_b >> tmp_c;
        sum -= data[tmp_b] * tmp_b;
        sum += data[tmp_b] * tmp_c;
        data[tmp_c] += data[tmp_b];
        data[tmp_b] = 0;
        cout << sum << '\n';
    }
}


Measured memory_bytes: 9056
import sys
from collections import deque
input = sys.stdin.readline

n,m = map(int,input().split())
edge = [list(map(int,input().split())) for _ in range(n-1+m)]

graph = [[] for _ in range(n)]
indegree = [0 for _ in range(n)]
parent = [-1 for _ in range(n)]

for i in range(n-1+m):
    graph[edge[i][0]-1].append(edge[i][1]-1)
    indegree[edge[i][1]-1] += 1

root = indegree.index(0)
parent[root] = 0

queue = deque()
queue.append(root)

while queue:
    node = queue.popleft()
    for adj in graph[node]:
        indegree[adj] -= 1
        if indegree[adj] == 0:
            queue.append(adj)
            parent[adj] = node+1

for p in parent:
    print(p)

Measured memory_bytes: 76252
H, W = map(int, input().split())
S = []
for i in range(H):
    s = input()
    S.append(list(s))

def is_street(s, t):
    return S[s][t] == '.'

def count(maze):
    r = -1
    for i in range(H):
        for j in range(W):
            r = max(r, maze[i][j])
    return r

def bfs(h, w):
    m = []
    for i in range(H):
        s = [-1] * W
        m.append(s)
    m[h][w] = 0

    q = [[h, w]]
    while len(q) != 0:
        t, u = q.pop(0)
        cost = m[t][u]

        # 上
        ue = [t-1, u]
        if ue[0] >= 0 and m[ue[0]][ue[1]] == -1 and is_street(ue[0], ue[1]):
            m[ue[0]][ue[1]] = cost + 1
            q.append(ue)

        shita = [t+1, u]
        if shita[0] < H and m[shita[0]][shita[1]] == -1 and is_street(shita[0], shita[1]) :
            m[shita[0]][shita[1]] = cost + 1
            q.append(shita)

        hidari = [t, u-1]
        if hidari[1] >= 0 and m[hidari[0]][hidari[1]] == -1 and is_street(hidari[0], hidari[1]):
            m[hidari[0]][hidari[1]] = cost + 1
            q.append(hidari)

        migi = [t, u+1]
        if migi[1] < W and m[migi[0]][migi[1]] == -1 and is_street(migi[0], migi[1]):
            m[migi[0]][migi[1]] = cost + 1
            q.append(migi)
    # print(m)
    max_cost = count(m)
    return max_cost

ans = -1
for i in range(H):
    for j in range(W):
        if is_street(i, j):
            c = bfs(i, j)
            ans = max(ans, c)

print(ans)


Measured memory_bytes: 3192
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     

def main():
    N = I()
    A = LI()
    colors = [0] * 10
    free = 0
    for a in A:
        i = a // 400
        if i < 8:
            colors[i] += 1
        else:
            free += 1
    cnt = 0
    for c in colors:
        if c > 0:
            cnt += 1
    m = cnt
    if m == 0:
        m += 1
    M = cnt + free
    print(m, M)

def _main():
    N = I()
    A = LI()
    taken = set()
    free = 0
    for a in A:
        if a < 400:
            taken.add('gray')
        elif a < 800:
            taken.add('br')
        elif a < 1200:
            taken.add('green')
        elif a < 1600:
            taken.add('wat')
        elif a < 2000:
            taken.add('blue')
        elif a < 2400:
            taken.add('yellow')
        elif a < 2800:
            taken.add('orange')
        elif a < 3200:
            taken.add('red')
        else:
            free += 1
    minval = len(taken)
    maxval = minval + free
    print(minval, maxval)

main()



Measured memory_bytes: 6352
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;

int cal[13] = {0};
int val[26] = {0},vc;
int a[55] = {0};
int n,tmp,maxn = 0;

int main(){
	scanf("%d",&n);
	for(register int i = 0;i < n;i ++){
		scanf("%d",&a[i]);
		cal[a[i]] ++;
		if(cal[a[i]] >= 3 || cal[12] >= 2 || cal[0] >= 1){
			printf("0\n");
			return 0;
		}
	}
	for(register int i = 0;i < (1 << 22);i ++){
		memset(val,0,sizeof(val)); vc = 0;
		for(register int j = 1;j <= 11;j ++){
			if(cal[j] == 0) continue;
			if(cal[j] == 1){
				if((i >> (j - 1 + j - 1)) & 1) val[++ vc] = j;
				else val[++ vc] = 24 - j;
			}
			if(cal[j] == 2){
				if((i >> (j - 1 + j - 1)) & 1) val[++ vc] = j;
				else val[++ vc] = 24 - j;
				if((i >> (j - 1 + j)) & 1) val[++ vc] = j;
				else val[++ vc] = 24 - j;
			}
		}
		if(cal[12]) val[++ vc] = 12;
		val[++ vc] = 24;
		sort(val + 1,val + 1 + vc);
		tmp = 24;
		for(register int j = vc;j >= 1;j --) tmp = min(tmp,val[j] - val[j - 1]);
		maxn = max(maxn,tmp);
	}
	printf("%d\n",maxn);
	return 0;
}

Measured memory_bytes: 384
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, a, b, c = map(int, readline().split())
s = [readline().rstrip().decode() for _ in range(n)] + ['']
ans = [''] * n
for i, (bf, af) in enumerate(zip(s, s[1:])):
    if bf == 'AB':
        if a > b or (a == b and i != n - 1 and 'B' in af):
            b += 1
            a -= 1
            ans[i] = 'B'
        else:
            a += 1
            b -= 1
            ans[i] = 'A'
    elif bf == 'AC':
        if a > c or (a == c and i != n - 1 and 'C' in af):
            c += 1
            a -= 1
            ans[i] = 'C'
        else:
            c -= 1
            a += 1
            ans[i] = 'A'
    else:
        if b > c or (b == c and i != n - 1 and 'C' in af):
            c += 1
            b -= 1
            ans[i] = 'C'
        else:
            c -= 1
            b += 1
            ans[i] = 'B'
    if a < 0 or b < 0 or c < 0:
        print('No')
        exit()
print('Yes')
print('\n'.join(ans))


Measured memory_bytes: 17684
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    LL ans = 0;
    for(LL i = 0; i < n; ++i){
        for(LL j = i+1; j < n; ++j){
            LL left = a[j] - a[i] + 1;
            LL right = a[i] + a[j];
            LL left2 = max<LL>(j+1, lower_bound(a.begin(), a.end(), left) - a.begin());
            LL right2 = max<LL>(j+1, lower_bound(a.begin(), a.end(), right) - a.begin());
            ans += right2 - left2;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(x,y);
  if(x % y == 0) OUT(-1);
  else {
    OUT(x);
  }
}

Measured memory_bytes: 256