akhauriyash/Code-Regression huggingface dataset:
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  if len(divisors) % 2 != 0:
    return divisors[-1]*2
  else:
    return divisors[-1] + divisors[-2]

n = int(input())

print(max(make_divisors(n)-2,0))


Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
long long cnt[1000];
int main()
{
	long long n,i,j,k,a,x,y,ans;
	ans=0;
	cin>>n;
	for (i=1;i<=n;i++)
	{
		a=i;
		x=a%10;
		while (a/10>0)
		{
			a=a/10;
		}
		x=10*a+x;
		//cout<<x<<endl;
		cnt[x]++;
	}
	for (i=1;i<=n;i++)
	{
		a=i;
		x=10*(a%10);
		while (a/10>0)
		{
			a=a/10;
		}
		x=a+x;
		//cout<<x<<endl;
		ans=ans+cnt[x];	
	}
	cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    int a[10];
    for(int i = 0;i<5;i++)  cin >> a[i];
    for(int i = 0;i<5;i++)  if(a[i] == 0)  return cout << i + 1 , 0;
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N,M;
    cin>>N>>M;
    int from,to;
    rep(i,M){
        int L,R;
        cin>>L>>R;
        if(i==0){from=L;to=R;}
        chmax(from,L);
        chmin(to,R);
    }
    int  ans=to-from+1;
    cout<<max(ans,0)<<endl;
}

Measured memory_bytes: 384
#include <string.h>
#include <stdio.h>

int main()
{   char s[100001];
    scanf("%s",s);
    for(int i=strlen(s)-1;i>=0;){
        if(s[i]=='r'&&s[i-1]=='e'&&s[i-2]=='s'&&s[i-3]=='a'&&s[i-4]=='r'&&s[i-5]=='e'){
            i=i-6;
        }else if(s[i]=='e'&&s[i-1]=='s'&&s[i-2]=='a'&&s[i-3]=='r'&&s[i-4]=='e'){
            i=i-5;
        }else if(s[i]=='r'&&s[i-1]=='e'&&s[i-2]=='m'&&s[i-3]=='a'&&s[i-4]=='e'&&s[i-5]=='r'&&s[i-6]=='d'){
            i=i-7;
        }else if(s[i]=='m'&&s[i-1]=='a'&&s[i-2]=='e'&&s[i-3]=='r'&&s[i-4]=='d'){
            i=i-5;
        }else{
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#define MAX 10000
#define NIL -1
using namespace std;

struct Node
{
	int parent, left, right;
};
Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d)
{
	if (u == NIL)
	{
		return;
	}
	D[u] = d;
	setDepth(T[u].left, d + 1);
	setDepth(T[u].right, d + 1);
}
int setHeight(int u)
{
	int h1 = 0, h2 = 0;
	if (T[u].left != NIL)
	{
		h1 = setHeight(T[u].left) + 1;
	}
	if (T[u].right != NIL)
	{
		h2 = setHeight(T[u].right) + 1;
	}
	return H[u] = ( h1 > h2 ? h1 : h2 );
}
int getSibling(int u)
{
	if (T[u].parent == NIL)
	{
		return NIL;
	}
	if (T[T[u].parent].left != u && T[T[u].parent].left != NIL)
	{
		return T[T[u].parent].left;
	}
	if (T[T[u].parent].right != u && T[T[u].parent].right != NIL)
	{
		return T[T[u].parent].right;
	}
	return NIL;
}
void print(int u)
{
	printf("node %d: ", u);
	printf("parent = %d, ", T[u].parent);
	printf("sibling = %d, ", getSibling(u));
	int deg = 0;
	if (T[u].left != NIL)
	{
		deg++;
	}
	if (T[u].right != NIL)
	{
		deg++;
	}
	printf("degree = %d, ", deg);
	printf("depth = %d, ", D[u]);
	printf("height = %d, ", H[u]);
	if (T[u].parent == NIL)
	{
		printf("root\n");
	}
	else if (T[u].left == NIL && T[u].right == NIL)
	{
		printf("leaf\n");
	}
	else
	{
		printf("internal node\n");
	}
}

int main()
{
	int v, l, r, root = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		T[i].parent = NIL;
	}
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d %d", &v, &l, &r);
		T[v].left = l;
		T[v].right = r;
		if (l != NIL)
		{
			T[l].parent = v;
		}
		if (r != NIL)
		{
			T[r].parent = v;
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (T[i].parent == NIL)
		{
			root = i;
		}
	}
	setDepth(root, 0);
	setHeight(root);
	for (int i = 0; i < n; i++)
	{
		print(i);
	}
	return 0;
}


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

using namespace std;

using u32 = uint32_t;
using u64 = uint64_t;
using ll = long long;

void PrintRunrun(int k) {

  constexpr int KetaMax = 99;
  int res[KetaMax];
  res[0] = 0;
  for (int i = 1; i < KetaMax; i++) {
    res[i] = -1;
  }

  for(int a = 0; k>0 ;k--) {
    while (true) {
      // a桁目++
      if (res[a] < 0) {
        res[a] = 1;
      }
      else {
        res[a]++;
      }

      // OK?
      if ((res[a + 1] < 0 || abs(res[a + 1] - res[a]) <= 1) && res[a] < 10) {
        // ++はOK!
        // これより桁を下りながら-1していく（下限0）
        for (; a > 0; a--) {
          res[a - 1] = (res[a] > 1) ? res[a] - 1 : 0;
          //cout << "FKDLJ";
          //throw runtime_error("");
        }
        a = 0;
        break;
      }

      // この桁は++できない。上の桁にうつるぜ
      //res[a] = 0;
      a++;
    }
#if 0
    // debug output
    for (int i = KetaMax - 1; i >= 0; i--) {
      if (res[i] >= 0) {
        cout << res[i];
      }
    }
    cout << '\n';
#endif
  }

  for (int i = KetaMax - 1; i >= 0; i--) {
    if (res[i] >= 0) {
      cout << res[i];
    }
  }
  cout << '\n';
}

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

  int k;
  cin >> k;

#if 0
  for (auto t : tens) {
    cout << t << '\n';
  }
#endif

  //debug
#if 0
  for (int i = 1; i <= 15; i++) {
    //cout << GetRunrun(i) << ',';
    PrintRunrun(i);
  }
#endif

  PrintRunrun(k);

  //cout << GetRunrun(k);
}


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

string to_alphabet(ll x)
{
    if (x <= 0) {
        return "";
    }

    ll n = x % 26;
    n = (n == 0) ? 26 : n;
    string s = { tolower(static_cast<char>(n + 64)) };
    if (x == n) {
        return s;
    } else {
        return to_alphabet((x - n) / 26) + s;
    }
}

int main() {
    ll N;
    cin >> N;

    const auto ret = to_alphabet(N);

    cout << ret << endl;
}


Measured memory_bytes: 3624
num=[0,2,5,5,4,5,6,3,7,6]
n,m=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(n+17)
for i in range(n+1):
  for j in a:
    if i==0 or dp[i]>0:dp[i+num[j]]=max(dp[i+num[j]],dp[i]*10+j)
print(dp[n])

Measured memory_bytes: 14692
s = input()

ans = 0
i = 0

while i < len(s)-1:
    if s[i] != s[i+1]:
        ans += 1
        i += 1
    else:
        if i+3 <= len(s)-1:    
            ans += 2
            i += 3
        elif i+2 == len(s)-1:
            ans += 1
            i += 2
        elif i+1 == len(s)-1:
            ans += 1
            i += 2
            
if i == len(s)-1:
    ans += 1
            
print(ans)

Measured memory_bytes: 3500
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int b1,b2,b3;
    cin>>b1>>b2>>b3;
    if(b3==1){
        cout<<"Open"<<endl;
    }
    else if(b1==1&&b2==1){
        cout<<"Open"<<endl;
    }
    else{
        cout<<"Close"<<endl;
    }
}



Measured memory_bytes: 3100
#include <iostream>
    #include <stdio.h>
    #include <string>
    #include <math.h>
    #include<algorithm>
    #include <numeric>
    using namespace std;
 
    int main(){
      int A,B,C,X,Y;
      cin >> A >> B >> C >> X >> Y;
      long long ans=A*X+B*Y;
      if(X>=Y){
       for(long long i=Y;i<=X;i++){
         ans=min(ans,2*i*C+(X-i)*A);
       }
      }
      else{
       for(long long i=X;i<=Y;i++){
        ans=min(ans,2*i*C+(Y-i)*B); 
       }
      }
      cout << ans << endl;
      return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[100000];
bool judge = false;
int main( ) {
	scanf( "%s", s );
	int len = strlen( s );
	for( register int i = 0; i < len - 1; i++ )
		if( s[i] == 'A' && s[ i + 1 ] == 'C' ) 
			{ judge = true; break; }
	if( judge ) puts( "Yes" );
	else        puts( "No"  );
} 

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	LL a, b, c;
	cin >> a >> b >> c;
	if (a >= c || b >= c) {
		cout << "No" << endl;
		return;
	}
	LL A = (a*2+b*2-c)*c;
	LL B = (a-b)*(a-b);

	
	if (A<B ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
struct edge{ll to,id;edge(ll to, ll id): to(to), id(id) {}};
vector<vector<edge> > v(50);
vector<ll> root;
bool dfs(int now,int p,int f){
	if(now==f)return true;
	for(edge i:v[now]){
		if(i.to==p)continue;
		if(dfs(i.to,now,f)){
			root.pb(i.id);
			return true;
		}
	}
	return false;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,a,b;
    cin>>n;
    for(ll i=1LL;i<n;i++){
    	cin>>a>>b;
    	a--;b--;
    	v[a].push_back({b,i-1});
    	v[b].push_back({a,i-1});
    }
    cin>>m;
    vector<ll> s(m,0LL);
    for(ll i=0LL;i<m;i++){
    	cin>>a>>b;
    	a--;b--;
    	root=vector<ll>();
    	bool niko=dfs(a,-1LL,b);
    	for(ll j:root){
    		s[i]|=1LL<<j;
    	}
    }
    ll ans=0,maki=(1LL<<m);
    for(ll bit=0;bit<maki;bit++){
    	ll mask=0;
    	for(ll i=0LL;i<m;i++){
    		if(bit>>i&1)mask|=s[i];
    	}
    	ll num=__builtin_popcountll(mask);
    	ll count=1LL<<(n-1-num);
    	if(__builtin_popcountll(bit)%2==0)ans += count;
    	else ans -= count;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const char *st = "ox";
const int dy[] = {-1, -1, 1, 1, -1, 0, 1, 0}, dx[] = {1, -1, 1, -1, 0, -1, 0, 1};
string s[8];
int gain(int y, int x, int t){
	int res = 0;
	rep(d, 8){
		int ny = y + dy[d], nx = x + dx[d], cnt = 0;
		while(0 <= ny && ny < 8 && 0 <= nx && nx < 8){
			if(s[ny][nx] == st[t] || s[ny][nx] == '.') break;
			ny += dy[d]; nx += dx[d];
			cnt++;
		}
		if(0 <= ny && ny < 8 && 0 <= nx && nx < 8 && s[ny][nx] == st[t]) res += cnt;
	}
	return res;
}
void flip(int y, int x, int t){
	s[y][x] = st[t];
	rep(d, 8){
		int ny = y + dy[d], nx = x + dx[d];
		while(0 <= ny && ny < 8 && 0 <= nx && nx < 8){
			if(s[ny][nx] == st[t] || s[ny][nx] == '.') break;
			ny += dy[d]; nx += dx[d];
		}
		if(!(0 <= ny && ny < 8 && 0 <= nx && nx < 8) || s[ny][nx] != st[t]) continue;
		ny = y + dy[d], nx = x + dx[d];
		while(0 <= ny && ny < 8 && 0 <= nx && nx < 8){
			if(s[ny][nx] == st[t] || s[ny][nx] == '.') break;
			s[ny][nx] = st[t];
			ny += dy[d]; nx += dx[d];
		}
	}
}


int main(){
	rep(i, 8) cin >> s[i];
	int turn = 0; int pass = 0;
	
	while(1){
		int mx = 0, mxi, mxj;
		rep(ii, 8) rep(jj, 8){
			int i = turn ? 7 - ii : ii, j = turn ? 7 - jj : jj;
			if(s[i][j] == '.'){
				int g = gain(i, j, turn);
				if(g > mx) mx = g, mxi = i, mxj = j;
			}
		}
		
		if(mx == 0 && pass) break;
		if(mx == 0){
			pass = 1;
		}
		else{
			pass = 0;
			flip(mxi, mxj, turn);
		}
		turn ^= 1;
	}
	rep(i, 8) cout << s[i] << endl;
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	std::string str; std::cin >> str;
	std::vector<int> count(str.size(), 0);
	auto prev_right = -1;
	for (auto i = 0; i < str.size(); ++i) {
		switch (str[i]) {
		case 'R': 
			if (prev_right == -1) prev_right = i;
			break;
		case 'L':
			if (prev_right != -1) {
				count[i] += (i - prev_right) / 2;
				count[i - 1] += (i - prev_right) - (i - prev_right) / 2;
				prev_right = -1;
			}
			break;
		default: break;
		}
	}
	auto prev_left = -1;
	for (int i = str.size() - 1; i >= 0; --i) {
		switch (str[i]) {
		case 'L':
			if (prev_left == -1) prev_left = i;
			break;
		case 'R':
			if (prev_left != -1) {
				count[i] += (prev_left - i) / 2;
				count[i + 1] += (prev_left - i) - (prev_left - i) / 2;
				prev_left = -1;
			}
			break;
		default:break;
		}
	}
	for (auto i = 0; i < count.size(); ++ i) {
		if (i != 0) std::cout << " ";
		std::cout << count[i];
	}
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

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

	length := 0
	for i := 0; i < len(s); i++ {
		tmp := 0
		for j := i; j < len(s); j++ {
			if s[j] != 'A' && s[j] != 'C' && s[j] != 'G' && s[j] != 'T' {
				break
			}
			tmp++
		}
		if length < tmp {
			length = tmp
		}
	}
	fmt.Printf("%d\n", length)
}


Measured memory_bytes: 512
import math
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
S = [0] * N
S[0] = 0
 
for i in range(1, N):
    value = math.inf
    maxStep = min(K, i)
    for step in range(1, maxStep + 1):
        value = min(value, S[i - step] + abs(h[i] - h[i - step]))
    S[i] = value
print(S[N - 1])

Measured memory_bytes: 84880
#include <stdio.h>
#include <stdlib.h>

int main(){
  int n,x,t,retval;
  if(scanf("%d %d %d",&n,&x,&t)<3){
    exit(1);
  }
  if(n%x==0){
    retval = n/x*t;
  }else{
    retval = (n/x+1)*t;
  }
  printf("%d\n",retval);
  return 0; 
}

Measured memory_bytes: 1720
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
    int x,a,b,c,sum;
    while(cin>>a>>b>>c>>x)
    {
        sum=0;
       for(int i=0;i<=a;i++)
        for(int j=0;j<=b;j++)
            for(int k=0;k<=c;k++)
        if(x==i*500+j*100+k*50)
       {
           sum++;
       }
       cout<<sum<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node
{
    int p, l, r;
};
struct Node T[MAX];
int n;

void preParse(int u)
{
    if (u == NIL)
        return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u)
{
    if (u == NIL)
        return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse(int u)
{
    if (u == NIL)
        return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main()
{
    int i, v, l, r, root;
    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++)
        if (T[i].p == NIL)
            root = i;

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define N 100100
using namespace std;
inline void read(long long &x)
{
	x=0;
	long long p=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
long long n;
long long a[N],b[N],c[N];
map<long long,long long>cmp1,cmp2,cmp3;
long long ans;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	for(long long i=1;i<=n;i++)
		read(a[i]);
	sort(a+1,a+n+1);
	for(long long i=1;i<=n;i++)
		read(b[i]);
	sort(b+1,b+n+1);
	for(long long i=1;i<=n;i++)
		read(c[i]);
	sort(c+1,c+n+1);
	for(long long i=1;i<=n;i++)
	{
		long long pos1=lower_bound(a+1,a+n+1,b[i])-a;
		if(!cmp1[b[i]])
		cmp1[b[i]]+=pos1-1;
	}
	for(long long i=1;i<=n;i++)
	{
		long long pos1=upper_bound(c+1,c+n+1,b[i])-c;
		if(!cmp2[b[i]])
		cmp2[b[i]]+=n-pos1+1;
	}
	for(long long i=1;i<=n;i++)
	{
		long long val1=cmp1[b[i]];
		long long val2=cmp2[b[i]];
		ans+=val1*val2;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(void) {
   int L[30][30] = {0};
   char *S1 =(char *)calloc(3*100000 , sizeof(char));
   char *S2 =(char *)calloc(3*100000 , sizeof(char));
   scanf("%s %s", S1,S2);  
   int n = strlen(S1);
   for (int i = 0; i < n; i++) {
      L[S1[i]-'a'][S2[i]-'a']=1;
     // L[S2[i]-'a'][S1[i]-'a']=1;
   }

   for (int i = 0; i < 30; i++) {
      int cnt = 0;
      for (int j = 0; j < 30; j++) {
         if (L[i][j]==1) {
            cnt++;
         }
         if (cnt > 1) {
            printf("No\n");
            return 0;
         }
      }
   }
   for (int i = 0; i < 30; i++) {
      int cnt = 0;
      for (int j = 0; j < 30; j++) {
         if (L[j][i]==1) {
            cnt++;
         }
         if (cnt > 1) {
            printf("No\n");
            return 0;
         }
      }
   }
   printf("Yes\n");
   return 0;

}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;

int main()
{
    vector<vector<char> >ph;
    vector<char>c;
    ph.push_back(c);
    c.push_back('.');
    c.push_back(',');
    c.push_back('!');
    c.push_back('?');
    c.push_back(' ');
    ph.push_back(c);
    c.clear();
    
    char cc='a';
    while(cc!='p'){
        for(int i=0;i<3;i++){
            c.push_back(cc++);
        }
        ph.push_back(c);
        c.clear();
    }
    for(int i=0;i<4;i++){
        c.push_back(cc++);
    }
    ph.push_back(c);
    c.clear();
    for(int i=0;i<3;i++){
        c.push_back(cc++);
    }
    ph.push_back(c);
    c.clear();
    for(int i=0;i<4;i++){
        c.push_back(cc++);
    }
    ph.push_back(c);
    
    int n;
    cin>>n;
    while(n--){
        string s;
        cin>>s;
        char cu='#';
        int co=0;
        for(int i=0;i<s.length();i++){
            if(s[i]=='0'){
                if(cu=='#'){
                    continue;
                } else {
                    co--;
                    cout<<ph[cu-'0'][co%(ph[cu-'0'].size())];
                    cu='#';
                    co=0;
                }
            } else {
                co++;
                cu=s[i];
            }
        }
        cout<<endl;
    }
    //freopen("/Users/shitian/Desktop/gcj/gcj/A-large.in", "r", stdin);
    //freopen("/Users/shitian/Desktop/gcj/gcj/out.txt", "w", stdout);
//    int tcase;
//    cin>>tcase;
//    for(int tca=1;tca<=tcase;tca++){
//        cout<<"Case #"<<tca<<": ";
//
//    }
    return 0;
}

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

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >

const int N = 1e5 + 7;
const int INF = 1e9 + 7;

int h[N];
int n, mx, cur;

main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> h[i];
        if (h[i] <= h[i - 1]){
            cur++;
        }
        else {
            mx = max(cur, mx);
            cur = 0;
        }
    }
    mx = max(cur, mx);
    cout << mx;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,x,n) for(int i=x;i<n;++i)
#define ar array
void func(int n){
    for(int i=0;i<=n;++i)
        cout<<i<<" ";
    for(int i=n-1;i>=0;--i)
        cout<<i<<" ";
    cout<<endl;
}
int32_t main()
{
  int n,p; cin>>n>>p;
  string s; cin>>s;
  if(p==2){
    int ans=0;
    for(int i=0;i<n;++i){
      if((s[i]-'0')%2==0)
        ans+=i+1;
    }
    cout<<ans;
  }else if(p==5){
    int ans=0;
    for(int i=0;i<n;++i){
      if((s[i]-'0')%5==0)
        ans+=i+1;
    }
    cout<<ans;
  }else{
    int ans=0;
    map<int,int> mp;
    ++mp[0];
    int p2=1; // power of ten
    int t=0; //current number
    for(int i=n-1;~i;--i){
      t+=(p2*(s[i]-'0'));
      t%=p;
      ans+=mp[t];
      ++mp[t];
      p2*=10;
      p2%=p;
    }
    cout<<ans;
  }
  return 0;
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int w,h;
    char c;
    cin >>w >>h >>c;

    vector<string> s(h,string(w,'.'));

    for(int i:{0,h-1})rep(j,w) s[i][j] = '-';
    for(int j:{0,w-1})rep(i,h) s[i][j] = '|';
    s[h/2][w/2] = c;
    for(int i:{0,h-1})for(int j:{0,w-1}) s[i][j] = '+';

    rep(i,h) cout << s[i] << "\n";
    return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;

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


int f(int x){
    int res = 0;
    while(x%2==0){
        x /= 2;
        res++;
    }
    return res;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i] /= 2;

    int t = f(a[0]);
    rep(i,n){
        if(f(a[i]) != t){
            cout << 0 << endl;
            return 0;
        }
        a[i] >>= t;
    }
    m >>= t;

    ll l = 1;
    rep(i,n){
        l = lcm(l,a[i]);
        if(l > m){
            cout << 0 << endl;
            return 0;
        }
    }

    m /= l;
    int ans = (m+1)/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2000, mod = 1e9 + 7;
int n, m, fa[maxn + 10];
ll X, ans[maxn + 10];

struct edge {
	int l, r, w;
	bool operator < (const edge &t) const {
		return w < t.w;
	}
}a[maxn + 10];

int getf(int p) {
	return fa[p] == p ? p : fa[p] = getf(fa[p]);
}

ll calc() {
	ll ans = 0;
	for (int i = 1; i <= m; ++i) {
		int x = getf(a[i].l), y = getf(a[i].r);
		if (x != y) {
			fa[x] = y; ans += a[i].w;
		}
	}
	return ans;
}

int pw(int x) {
	int ans = 1;
	while (x--) ans = ans * 2 % mod;
	return ans;
}

int main() {
	scanf("%d%d%lld", &n, &m, &X);
	for (int i = 1; i <= m; ++i)
		scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].w);
	if (n == 1 || n == 2) {
		printf("%d", 0); return 0;
	}
	sort(a + 1, a + m + 1);
	for (int i = 1; i <= n; ++i) fa[i] = i;
	ans[0] = calc();
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) fa[j] = j;
		fa[a[i].l] = a[i].r;
		ans[i] = calc() + a[i].w;
	}
	if (X < ans[0]) printf("0");
	else if (X == ans[0]) {
		int cnt = 0;
		for (int i = 1; i <= m; ++i) 
			if (ans[i] == ans[0]) ++cnt;
		int ans = 1ll * (pw(n - 1) + mod - 2) * pw(m - n + 1) % mod;
		(ans += 1ll * (pw(cnt - n + 1) + mod - 1) * pw(m - cnt + 1) % mod) %= mod;
		printf("%d", ans);
	} else {
		int cnt1 = 1, cnt2 = 2;
		for (int i = 1; i <= m; ++i)
			if (ans[i] == X) cnt1 = cnt1 * 2 % mod;
			else if (ans[i] > X) cnt2 = cnt2 * 2 % mod;
		printf("%lld", 1ll * (cnt1 + mod - 1) * cnt2 % mod);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=2e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll h,w;cin>>h>>w;
    char a[h][w];for(ll i=0;i<h;i++)cin>>a[i];
    ll cur=0;
    for(ll i=0;i<h;i++){
        ll s=-1;
        for(ll j=0;j<w;j++){
            if(a[i][j]=='#'){
                s=j;
                break;
            }
        }

        if(s==-1)return cout<<"Impossible" , 0;

        ll e=w;
        for(ll j=w-1;j>=0;j--){
            if(a[i][j]=='#'){
                e=j;
                break;
            }
        }

        for(ll j=s;j<=e;j++)if(a[i][j]!='#')return cout<<"Impossible" , 0;

        if(s!=cur)return cout<<"Impossible"  , 0;
        cur=e;
    }
    cout<<"Possible";
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        Sp[] sp = new Sp[n];
        for (int i = 0; i < n; i++) {
            sp[i] = new Sp(sc.next(), sc.nextInt(), i+1);
        }
        Arrays.sort(sp, (sp1, sp2) -> {
            if (sp1.s.equals(sp2.s)) {
                return Integer.compare(sp2.p, sp1.p);
            } else {
                return sp1.s.compareTo(sp2.s);
            }
        });
        for (Sp s : sp) {
            System.out.println(s.i);
        }
    }

    static class Sp {
        String s;
        int p;
        int i;

        public Sp(String s, int p, int i) {
            this.s = s;
            this.p = p;
            this.i = i;
        }
    }

}


Measured memory_bytes: 26964
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,ans=0,a,b,L,R,ce; cin>>n;
    vector<int> l(n,0);
    rep(i,n) cin>>l[i];
    sort(al(l));
    for(int i=0;i<=n-3;i++){
        for(int j=i+1;j<=n-2;j++){
            a=l[i]; b=l[j];
            L=j; R=n-1;
            while(L!=R){
                ce=(L+R+1)/2;
                if(l[ce]<a+b) L=ce;
                else R=ce-1;
            }
            ans+=L-j;
        }
    }
    cout<<ans<<endl;
}

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

public class Main {
	
	Scanner sc;
	
	LinkedList<Integer> list;
	
	void run() {
		sc = new Scanner(System.in);
		list = new LinkedList<Integer>();
		while (sc.hasNext()) {
			int a = sc.nextInt();
			if (a != 0)
				list.add(a);
			else System.out.println(list.removeLast());
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
	
	
}

Measured memory_bytes: 12000
N = int(input())
_t, _x, _y = 0, 0, 0
flg = True
for i in range(N):
    t, x, y = list(map(int, input().split()))
    dt = t - _t
    dd = abs(x - _x) + abs(y - _y)
    if not (dd <= dt and dt % 2 == dd % 2):
        flg = False
    _t, _x, _y = t, x, y
if flg:
    print('Yes')
else:
    print('No')


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  ll h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,0,h) cin >> s[i];
  
  ll res=0;
  rep(i,0,h){
   rep(j,0,w){ 
     if(s[i][j]=='#') continue;
     vvll d(h,vll(w,-1));
     d[i][j]=0;
     vector<pll> que;
     que.emplace_back(i,j);
     for(ll b=0;b<que.size();b++){
     for(ll dx=-1;dx<=1;dx++){
       for(ll dy=-1;dy<=1;dy++){
        if(dx*dx+dy*dy!=1) continue;
         ll x=que[b].first;
         ll y=que[b].second;
        if(x+dx<0||y+dy<0||x+dx>=h||y+dy>=w||s[x+dx][y+dy]=='#'||d[x+dx][y+dy]!=-1) continue;
         d[x+dx][y+dy]=d[x][y]+1;
         que.emplace_back(x+dx,y+dy);
       }
     }
     }
     
     res=max(res,d[que.back().first][que.back().second]);
     
   }
  }
  
  cout << res << endl;
  
}


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

using namespace std;

int main() {
    int dict[26] = {};
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        dict[s[i] - 'a']++;
    }
    for (int i = 0; i < 26; i++) {
        if (dict[i] == 0) {
            cout << char('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#define MAX 2000000
int A[MAX];
int H;//maxヒープに必要

void swap(int *a,int *b){
  int c=*a;*a=*b;*b=c;
}
void maxHeapify(int *A,int i){
  int l = 2*i;
  int r = 2*i+1;
  int largest;
  // 左の子、自分、右の子で値が最大のノードを選ぶ
  if(l <= H && A[l] > A[i])largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest])largest = r;

  // i の子の方が値が大きい場合
  if(largest != i){
    swap(&A[i],&A[largest]); 
    maxHeapify(A,largest); // 再帰的に呼び出し
  }
}


void Insert(int x){//一番最後に新要素追加して、その後に整列
  int i;
  
  i=H;
  A[i]=x;
  while(i>=2&&A[i/2]<A[i]){
    swap(&A[i],&A[i/2]);
    i=i/2;
  }
}

int Extract(void){//maxヒープのてっぺんとる
  int max;
 
  max=A[1];
  
  A[1]=A[H--];
  maxHeapify(A,1);

  return max;
}

int main(){
  char command[7];
  int xnum;
  int i;

  while(1){
    scanf("%s",command);
    if(command[0]=='i'){
      H++;//Hうごかしちゃ　だめ
      scanf("%d",&A[H]);
      Insert(A[H]);//insert
    }
    else if(command[1]=='x'){
      printf("%d\n",Extract());//extract
    }
    else break;
  }
  return 0;
}




Measured memory_bytes: 5648
from math import gcd


def prime_fac(x):
    pfs = set()
    for i in range(2, x):
        if i * i > x:
            break
        while x % i == 0:
            pfs.add(i)
            x //= i
    if x > 1:
        pfs.add(x)
    return pfs


n = int(input())
a = list(map(int, input().split()))

a.sort()
xs = [0] * (a[-1] + 1)
g = a[0]
for v in a:
    g = gcd(g, v)
    xs[v] += 1

if g != 1:
    print("not coprime")
    exit()

s = set()
for v in a:
    p = prime_fac(v)
    ls, lp = len(s), len(p)
    s.update(p)
    if len(s) < ls + lp:
        print("setwise coprime")
        exit()
print("pairwise coprime")


Measured memory_bytes: 195040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define int long long
#define fill(x, v) memset(x, v, sizeof(x))
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define ios std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
/*
std::cout << std::setprecision(9) << f << '\n';//3.141590000;
map<char,int>::reverse_iterator rit;
for(rit = mp.rbegin(); rit!=mp.rend(); rit++)
*/
int n;
int dp[3001][3001];
int arr[3001];
int x, y;
//dp[l][r]= max(a[l]-dp[l+1][r], a[r]-dp[l][r-]);
int winner()
{
    for (int l = n - 1; l >= 0; l--)
        for (int r = l; r < n; r++)
            if (l != r)
                dp[l][r] = max(arr[l] - dp[l + 1][r], arr[r] - dp[l][r - 1]);
            else
                dp[l][r] = arr[l];
    return dp[0][n - 1];
}
int32_t main()
{
    ios;
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    x = winner();
    cout << x << endl;
}


Measured memory_bytes: 70016
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Ford(i,a,b) for(int i=(a);i>=(b);--i)
#define fio(s) freopen(s".inp","r",stdin)
#define foo(s) freopen(s".out","w",stdout)
#define task "test"
using namespace std;
typedef long long LL;
const LL N=3009,OO=1e9+7;
LL n,k,dp[109][100009],s[109][100009],a[N];
int main(){
    //fio(task); foo(task);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>k;
    For(i,1,n) cin>>a[i];
    dp[0][k]=1;
    s[0][k]=1;
    For(i,1,n)
    For(j,0,k){
        if(j==0) dp[i][j]=s[i-1][j+a[i]]%OO;
        else dp[i][j]=(s[i-1][min(j+a[i],k)]-s[i-1][j-1]+OO)%OO;
        if(j>0)s[i][j]=(s[i][j-1]+dp[i][j])%OO; else s[i][j]=dp[i][j]%OO;
    }
    cout<<dp[n][0];
    return 0;
}


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

using namespace std;

const int mod = 1e9+7;

void add_self(int &a,int b)
{
    a+=b;
    if (a>=mod)
        a-=mod;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;
    int len=s.size();

    int d;
    cin >> d;
    vector <vector<int> > dp(d,vector <int>(2));
    dp[0][0]=1;

    for (int i=0;i<len;i++)
    {
        vector <vector <int> > new_dp (d,vector <int> (2));
        for (int sum=0;sum<d;sum++)
            for (bool sth:{false , true})
                for (int digit=0;digit < 10;digit++)
        {
            if (digit>s[i]-'0' && !sth)
                break;

            add_self(new_dp[(sum+digit)%d][sth || digit<s[i]-'0'],dp[sum][sth]);
        }

        dp=new_dp;
    }

    int answer=(dp[0][0]+dp[0][1])%mod;
    answer--;
    if (answer==-1)
        answer=mod-1;
    cout << answer;

}



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


// vector<long long> enum_divisors(long long N) {
//     vector<long long> res;
//     for (long long i = 1; i * i <= N; ++i) {
//         if (N % i == 0) {
//             res.push_back(i);
//             // 重複しないならば i の相方である N/i も push
//             if (N/i != i) res.push_back(N/i);
//         }
//     }
//     // 小さい順に並び替える
//     //sort(res.begin(), res.end());
//     return res;
// }


int main(){
    long long N; cin >> N;
    long long kake_count = 0;

    vector<long long> cnt(N+1, 1);
    for(int i=2; i<=N-1; ++i){
        for(int j=i; j<=N-1; j += i){
            cnt[j]++;
        }
    }
    long long ans = 0;
    for(int i=1; i<=N-1; ++i){
        ans += cnt[i];
    }

    cout << ans << endl;


    // for(int i=1; i<=N-1; ++i){
    //     long long kakeru = i;
    //     long long tasu = N-1;
    //     // if(kakeru == 1){
    //     //     kake_count +=1;
    //     // }else{
    //     //     auto res = enum_divisors(kakeru);
    //     //     kake_count += res.size();
    //     // }
    // }

    // cout << kake_count << endl;

}

Measured memory_bytes: 11164
n,m = map(int,input().split())
ls = list(map(int,input().split()))
lls = []
for i in range(n):
    lls.append(True)

for i in range(m):
    a,b = map(int,input().split())
    if ls[a-1] > ls[b-1] and lls[a-1] != False:
        lls[a-1] = True
    else:
        lls[a-1] = False

    if ls[b-1] > ls[a-1] and lls[b-1] != False:
            lls[b-1] = True
    else:
            lls[b-1] = False

print(lls.count(True))

Measured memory_bytes: 20092
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <float.h>
#include <iostream>
#include <map>
using namespace std;

int main()
{
	int nN;
	cin >> nN;
	int nA[100];
	int nSun = 0;
	for (int i = 0; i < nN; i++)
	{
		cin >> nA[i];
		nSun += nA[i];
	}

	double  dbAve = nSun / double(nN);

	int nMinIdx = 0;
	double dbMinAbs = 1000;
	for (int i = 0; i < nN; i++)
	{
		double dbTmpAbs = fabs(nA[i] - dbAve);
		if (dbTmpAbs < dbMinAbs)
		{
			dbMinAbs = dbTmpAbs;
			nMinIdx = i;
		}
	}

	cout << nMinIdx;

	return 0;
}


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


def solve(N: int, D: int):
    print(math.ceil(N/(2*D+1)))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(N, D)

if __name__ == '__main__':
    main()


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

pairs = [list(map(int, input().split())) for _ in range(N)]

x0 = 0
y0 = 0
t0 = 0
res = "Yes"
for t, x, y in pairs:
    dx = x - x0
    dy = y - y0
    dt = t - t0

    # if abs(dx) + abs(dy) != dt:
    tmp = dt - (abs(dx) + abs(dy))
    if tmp < 0 or tmp % 2 != 0:
        res = "No"
        break
    x0 = x
    y0 = y
    t0 = t

print(res)

Measured memory_bytes: 27324
#include <bits/stdc++.h>
#define ll         long long int 
#define pb         push_back
#define umap       unordered_map
#define mod        1000000007
#define all(x)     (x).begin(), (x).end()
#define rall(x)    (x).rbegin(), (x).rend()
#define MN(a,b,c)  min(a,min(b,c))
#define MX(a,b,c)  max(a,max(b,c))
#define pr1         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(int i=0;i<n;i++)
#define f1(i,x,y)  for(int i=x;i<=y;i++)
#define f2(i,x,y)  for(int i=x;i>=y;i--)
#define yes        cout<<"YES"<<"\n"
#define no         cout<<"NO"<<"\n"
#define modsum(a,b)  ((a%mod)+(b%mod))%mod
#define modpro(a,b)  ((a%mod)*(b%mod))%mod
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes 
//__builtin_ctz(x)      to count the number of trailing zeroes 
//__gcd(a,b)
using namespace std;
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 int  R,C,M;cin>>R>>C>>M;
 int  mx=0;
 int  x,y;
 map<pair<int, int>, int> vis; 
 umap <int,int> fr,fc;
 int fmxr=0,fmxc=0;
 int mxr=0,mxc=0;
 f1(i,1,M)
 {
     cin>>x>>y;fr[x]++;fc[y]++;
     vis[{x,y}]=1;
     mxr=max(mxr,fr[x]);mxc=max(mxc,fc[y]);
 }
 vector <int> MX,MY;
 for(auto it=fr.begin();it!=fr.end();++it)
 {if((it->S)==mxr){MX.pb(it->F);}}
 for(auto it=fc.begin();it!=fc.end();++it)
 {if((it->S)==mxc){MY.pb(it->F);}}
  y=0;
 for(int i=0;i<MX.size();i++)
 {
     for(int j=0;j<MY.size();j++)
     {
         if(vis[{MX[i],MY[j]}]==0)
         {y=1;break;}
     }
     if(y)break;
 }
 if(y)cout<<mxc+mxr;
 else cout<<mxc+mxr-1;
}
  

Measured memory_bytes: 53224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

void solve(string S)
{

    int ans = 0;
    int zero = 0;
    int one = 0;
    for(int i = 0; i < S.size(); i++)
    {
        if(S[i] == '0'){
            zero++;
        }else{
            one++;
        }

        if(zero > 0 && one > 0){
            zero--;
            one--;
            ans += 2;
        }
    }
    
    cout << ans << endl;
}

int main()
{
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL)
    x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key)
    {
      if(k < u->key )u = u->left;
      else u = u->right;
    }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL)
    return treeMinimum(x->right);
  y=x->parent;
  while(y != NIL || x == y->right)
    {
      x = y;
      y = y->parent;
    }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL)
    y = z;
  else y = treeSuccessor(z);
  if(y->left != NIL)
    {
      x = y->left;
    }
  else
    {
      x = y->right;
    }

  if(x != NIL)
    {
      x->parent = y->parent;
    }
  
  if(y->parent == NIL)
    root = x;
  else
    {
      if(y == y->parent->left)
	{
	  y->parent->left = x;
	}
      else
	{
	  y->parent->right = x;
	}
    }
  if(y != z)
    z->key = y->key;
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL)
    {
      y = x;
      if( z->key < x->key)
	{
	  x = x->left;
	}
      else
	{
	  x = x->right; 
	}
    }
  z->parent = y;
  if(y == NIL)
    root = z;
  else
    {
      if(z->key < y->key)
	{
	  y->left=z;
	}
      else
	{
	  y->right = z;
	}
    }
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Node find(Node u,int k)
{
  while(u != NIL && k != u->key)
    {
      if(u->key > k)
	u = u->left;
      else
	u = u->right;
    }
  return u;
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20448
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int a[100], b[100], c[100];
int main()
{
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  for (int i = 0; i < n; i++)
    scanf("%d", b + i);
  for (int i = 0; i < n - 1; i++)
    scanf("%d", c + i);
  for (int i = 0; i < n; i++)
  {
    if (i >= 1)
    {
      if (a[i] - a[i - 1] == 1)
        ans += c[a[i] - 2];
    }
    ans += b[a[i] - 1];
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 128
//edpc_j.cpp
//Sat Feb 16 11:41:32 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;
double dp[301][301][301];
int n,s,d,t;

double calcdp(int x, int y, int z){
	if (dp[x][y][z] != -1){
		return dp[x][y][z];
	}else {
		double temp = n;
		if (x>0){
			temp += x*calcdp(x-1,y,z);
		}
		if (y>0){
			temp += y*calcdp(x+1,y-1,z);
		}
		if (z>0){
			temp += z*calcdp(x,y+1,z-1);
		}
		temp = temp * 1.0/(x+y+z);
		dp[x][y][z] = temp;
//		cout << x << " " << y << " " << z << " " << temp << endl;
		return temp;
	}
}

int main(){
	cin >> n;

	s = 0;
	d = 0;
	t = 0;
	for (int i=0;i<n;i++){
		int temp;
		cin >> temp;
		if (temp==1){
			s++;
		}else if (temp==2){
			d++;
		}else if (temp==3){
			t++;
		}
	}

	for (int i=0;i<n+1;i++){
		for (int j=0;j<n+1;j++){
			for (int k=0;k<n+1;k++){
				dp[i][j][k] = -1;
			}
		}
	}

	dp[0][0][0] = 0;
	double ans = calcdp(s,d,t);

	printf("%.10f\n",ans);
}

Measured memory_bytes: 213376
#/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  const ll mod=1e9+7;
  const ll MAX=1e6+1;
  ll lcm(ll x,ll y){return (x*y)/__gcd(x,y);}
  //
  //	
    	ll solve(){
    		ll n;
    		cin>>n;
    		vpll vec;
    		rep(i,0,n){
    			ll x,y;
    			cin>>x>>y;
    			vec.pb(mp(y,x));
    		}
    		sort(all(vec));
    		ll cnt=0;
    		rep(i,0,n){
    			cnt+=vec[i].ss;
    			if(vec[i].ff<cnt)
    				return cout<<"No", 0;
    		}
    		cout<<"Yes";
  	}
	int main(){ 
		hs;
		ll t;
		// cin>>t;
		t=1;
		while(t--)
			solve();
    return 0; 
} 

Measured memory_bytes: 6512
a,b,c,d = map(int,input().split())
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
cd = lcm(c,d)
print(int((b-a+1)-(b//c+b//d-(a-1)//c-(a-1)//d)+(b//(cd)-(a-1)//(cd))))

Measured memory_bytes: 3060
H,W = map(int,input().split())
# H,W = 2000,2000

S = [[0 for w in range(W)] for h in range(H)]
for h in range(H):
    l = input()
    for w in range(W):
        if l[w]=="#":
            S[h][w] = 0
        else:
            S[h][w] = 1

Sh = [[0 for w in range(W)] for h in range(H)]

for h in range(H):
    se = []
    cnt = 0
    for w,val in enumerate(S[h]):
        if val == 1:
            cnt += 1
            se.append(w)
        else:
            for ww in se:
                Sh[h][ww] = cnt
            cnt = 0
            se = []
    for ww in se:
        Sh[h][ww] = cnt

Sw = [[0 for w in range(W)] for h in range(H)]

for w in range(W):
    se = []
    cnt = 0
    for h in range(H):
        val = S[h][w]
        if val == 1:
            cnt += 1
            se.append(h)
        else:
            for hh in se:
                Sw[hh][w] = cnt
            cnt = 0
            se = []
    for hh in se:
        Sw[hh][w] = cnt


mx = 0
for h in range(H):
    for w in range(W):
        mx = max(Sh[h][w] + Sw[h][w], mx)

print(max((mx-1,0)))


Measured memory_bytes: 139272