akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main()
{
  int A, B, C, X;
  cin >> A; //500
  cin >> B; //100
  cin >> C; //50
  cin >> X;

  int count = 0;
  for(int a = 0; a < A+1; ++a){
    for(int b = 0; b < B+1; ++b){
      for(int c = 0; c < C+1; ++c){
        if(X == a*500+b*100+c*50){
          ++count;
        }
      }
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	int N;
	double A[11];
	double ans=0;
	string U[11];
	cin>>N;
	REP(i,N){
		cin>>A[i]>>U[i];
		if(U[i]=="JPY"){
			ans+=A[i];
		}
		else{
			ans+=A[i]*380000.0;
		}
	}
	printf("%12lf",ans);
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
As = list(map(int, input().split()))
As = list(map(lambda x: -x, As))
heapq.heapify(As)

count = 0
while count < M:
    tmp = heapq.heappop(As)
    tmp = int(tmp/2)
    heapq.heappush(As, tmp)
    count += 1

print(-sum(As))


Measured memory_bytes: 14180
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int e;
    while (true) {
        cin >> e;
        if (e == 0) {
            break;
        }
        int m = -1;
        for (int z=0, z_3=0; z_3<=e; z++, z_3=z*z*z) {
            for (int y=0, y_2=0; z_3+y_2<=e; y++, y_2=y*y) {
                int x;
                for (x=0; z_3+y_2+x<e; x++);
                if (z_3+y_2+x == e) {
                    if (m > 0) {
                        m = min(m, x+y+z);
                    }
                    else {
                        m = x+y+z;
                    }
                }
            }
        }
        cout << m << endl;
    }
    return 0;
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  int i = 0;
  for (int n = min(a, b);; n--) {
    if (a % n == 0 && b % n == 0) {
      if (++i == k) {
        cout << n << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, k; readV(n, k);
  string s; readV(s);

  auto a = s.chunkBy!"a == b".map!(c => cast(int)c.walkLength).array;
  if (s[0] == '0') a = 0 ~ a;

  auto ac = a.cumulativeSum, r = 0;

  for (auto i = 0; i < a.length; i += 2)
    r = max(r, ac[i..min(i+k*2+1, a.length)]);

  writeln(r);
}

class CumulativeSum(T)
{
  size_t n;
  T[] s;

  this(T[] a)
  {
    n = a.length;
    s = new T[](n+1);
    static if (T.init != 0) s[0] = T(0);
    foreach (i; 0..n) s[i+1] = s[i] + a[i];
  }

  pure auto opSlice(size_t l, size_t r) { return s[r]-s[l]; }
  pure auto opDollar() { return n; }
}
auto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }


Measured memory_bytes: 3452
n = int(input())
r = []

for i in range(n):
    r.append(int(input()))
minv = r[0]
maxv = -10**9
for i in range(1,n):
    maxv = max(maxv, r[i]-minv)
    minv = min(minv,r[i])

print(maxv)


Measured memory_bytes: 13588
N,M=map(int, input().split())
l=[list(map(int, input().split())) for _ in range(M)]
ans=[i for i in range(1,N+1)]
c=[1]


def dfs(cnt):
	if len(cnt)==N and sorted(cnt)==ans:
		return 1
	elif len(cnt)>=N:
		return 0
	temp=[]
	ret=0
	for i in range(M):
		if cnt[-1]==l[i][0]:
			temp.append(l[i][1])
		elif cnt[-1]==l[i][1]:
			temp.append(l[i][0])
	for h in temp:
		cnt.append(h)
		ret+=dfs(cnt)
		cnt.pop(-1)
	return ret

print(dfs(c))		

Measured memory_bytes: 9152
#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 rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) 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(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#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;

vint e[500];
bool dfs_bipartite(int v, vint &color, int c) {
    color[v] = c;
    for (auto u : e[v]) {
        if (color[u] != -1) {
            if (color[u] == c) return false;
            continue;
        }
        if (!dfs_bipartite(u, color, 1-c)) return false;
    }
    return true;
}
bool isBipartite(int n) {
    vint color(n, -1);
    rep(i, n) {
        if (color[i] != -1) continue;
        if (!dfs_bipartite(i, color, 0)) return false;
    }
    return true;
}


int main() {
    int n;
    cin >> n;
    vstr s(n);
    rep(i, n) cin >> s[i];

    vvint d(n, vint(n, INF));
    rep(i, n) rep(j, n) {
        if (i==j) d[i][j] = 0;
        if (s[i][j] == '0') continue;
        e[i].push_back(j);
        e[j].push_back(i);
        d[i][j] = 1;
    }

    if (!isBipartite(n)) {
        puts("-1");
        return 0;
    }

    rep(k, n) rep(i, n) rep(j, n) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    int ans = 0;
    rep(i, n) ans = max(ans, vmax(d[i]));
    ++ans;

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

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,m;
string s;
vll f;
// <------------- Implement Functions Here ----------> //

void fact() {
	f.pb(1);
	for(ll i=1;i<=max(n,m);i++) {
		f.pb((i * f[i-1])%MOD);
	}
}

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> m;
	fact();
	if(abs(n-m) > 1) {
		cout<<0;
		return;
	}
	ll ans = f[n] * f[m] %MOD;
	if(n - m == 0) ans = 2 * ans %MOD;
	cout<<ans;

}

int main() {
	fastio;randomINT;
	//cin>>t;
	while(T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 238680
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        char[] s = sc.next().toCharArray();

        if (s[0] >= 'A' && s[0] < 'a')
            System.out.println("A");
        else
            System.out.println("a");
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

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

using namespace std;
const int N = 200005;
typedef long long ll;
int a[N];
int b[N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i];
   }
   sort(a+1,a+1+n);
    int mid=n/2;
    for(int i=1;i<=n;i++){
        if(b[i]<=a[mid])
        printf("%d\n",a[mid+1]);
        else
        printf("%d\n",a[mid]);
    }
}


Measured memory_bytes: 3712
n=int(input())
a,b=[0]*n,[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())
a=list(reversed(a))
b=list(reversed(b))
cnt=0
for i in range(n):
    r=((a[i]+cnt)%b[i])
    if r==0:
        continue
    cnt += b[i]-r
print(cnt)

Measured memory_bytes: 11748
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main(void){
    int N, M, Abuf, Bbuf;
    cin >> N >> M;
    vector<vector<int>> Cave(N);
    vector<int> Exit(N, -1);
    for(int i=0; i<M; i++){
        cin >> Abuf >> Bbuf;
        Abuf--;
        Bbuf--;
        Cave[Abuf].push_back(Bbuf);
        Cave[Bbuf].push_back(Abuf);
    }

    queue<int> queRoom;
    Exit[0] = 0;
    queRoom.push(0);
    while(!queRoom.empty()){
        int curRoom = queRoom.front();
        queRoom.pop();
        for(int nxtRoom: Cave[curRoom]){
            if(Exit[nxtRoom] != -1)continue;
            Exit[nxtRoom] = curRoom;
            queRoom.push(nxtRoom);
        }
    }
    bool Dead = false;
    for(int i=0; i<N; i++){
        if(Exit[i] == -1){
            Dead = true;
            break;
        }
    }
    if(Dead){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        for(int i=1; i<N; i++){
            cout << Exit[i]+1 << endl;
        }
    }
    return 0;
}

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

int main() {
  int A , B , k ,  sum = 0 ;
  cin >> A >> B ;
  k = A ;
  for (int i=A-1 ; i<B ; i++){
    if (( k/10000 == k % 10) && ((k/1000)%10 == (k/10)%10))
      sum++;
    k++ ;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
// In the name the Allah the Most Merciful.

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

typedef long long ll;
const int INF = 1e9;

int main(void)
{
    int n , k;
    scanf("%d",&n);
    vector<int>dp(3);
    for(int i=0;i<n;i++){
        vector<int>temp(3 , 0);
        vector<int>c(3);
        for(int j=0;j<3;j++){
            scanf("%d",&c[j]);
        }
        for(int i1=0;i1<3;i1++){
            for(int j1=0;j1<3;j1++){
                if(i1!=j1){
                    temp[j1] = max(temp[j1] , dp[i1]+c[j1]);
                }
            }
        }
        dp = temp;
    }
    printf("%d\n",max(dp[0] , max(dp[1] , dp[2])));

    return 0;
}


Measured memory_bytes: 256
def max(a):
	max = -10000000
	for i in a:
		if max < i:
			max = i
	return max

def min(a):
	min = 10000000
	for i in a:
		if min > i:
			min = i
	return min

def sum(a):
	sum = 0
	for i in a:
		sum += i
	return sum


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

print(min(a), max(a), sum(a))

Measured memory_bytes: 8792
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        x: i32,
    }

    let ans = if x == 0 { 1 } else { 0 };
    println!("{}", ans);
}


Measured memory_bytes: 2104
import sys
n, a, b = map(int, input().split())

# 2で割って余り1ならすれ違わない
if (b - a) % 2 == 0:
    print((b - a) // 2)

else:
    # 左で折り返す場合
    left = ((a - 1) + (b - 1) + 1) // 2

    # 右で折り返す場合
    right = ((n - b) + (n - a) + 1) // 2

    print(min(left, right))

Measured memory_bytes: 9092
import sys
from collections import defaultdict

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n = int(input())
	al = list(IN())
	vv=defaultdict(lambda : 0)
	for v in al:
		vv[v]+=1
	
	dd=dict()
	total=0
	for key in vv:
		num=vv[key]
		use_all = num*(num-1)//2
		in_k = ((num-1)*(num-2))//2
		dd[key]=use_all - in_k
		total+=use_all
	
	for v in al:
		pp=total-dd[v]
		print(pp)
		
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  int memo[26]; memset(memo, 0, sizeof(memo));
  for (char c = 'a'; c <= 'z'; c++) {
    vector<int> at(1, -1);
    for (int i = 0; i < n; i++) {
      if (s[i] == c) at.push_back(i);
    }
    at.push_back(n);
    for (int i = 0; i < at.size() - 1; i++) {
      memo[c - 'a'] = max(memo[c - 'a'], at[i + 1] - at[i]);
    }
  }
  sort(memo, memo + 26);
  cout << memo[0] - 1 << "\n";
  return 0;
}

Measured memory_bytes: 384
from collections import defaultdict
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]
dict = defaultdict(int)
for a in A:
    dict[a] += 1

mod = 10 ** 9 + 7
dp = [0 for _ in range(N+1)]
dp[0] = 1
if dict[1] == 0:
    dp[1] = 1

for i in range(1, N):
    if dict[i] == 0 and dict[i-1] == 0:
        dp[i+1] += ((dp[i-1] + dp[i]) % mod)
    elif dict[i] == 0:
        dp[i+1] += (dp[i] % mod)
    elif dict[i-1] == 0:
        dp[i+1] += (dp[i-1] % mod)

print(dp[-1])



Measured memory_bytes: 18960
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int n,m;
vector<int>v[200001];
bool vis[200001];
int d[200001];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n>>m;
    int x,y;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    queue<int>q;
    q.push(1);
    d[1]=0;
    vis[1]=true;
    while(!q.empty()){
        int p=q.front();
        q.pop();
        for(int i=0;i<v[p].size();i++){
                if(p==1&&v[p][i]==n)continue;
            if(!vis[v[p][i]]){
                d[v[p][i]]=d[p]+1;
                q.push(v[p][i]);
                vis[v[p][i]]=true;
            }
        }
    }
    if(d[n]==2)cout<<"POSSIBLE";
    else cout<<"IMPOSSIBLE";
    return 0;
}


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

int main() {
  long double A = 0,B = 0, H = 0,M = 0,ans = 0,w = 0,m = 0;
  long double pi = 3.14159265358979;
  cin >> A >> B >> H >> M;
  w = cos(M * pi / 30 - (H * pi / 6 + M * pi / 360));
  ans = A * A + B * B - 2 * A * B * w;
  cout << fixed << setprecision(10);
  cout << sqrt(ans);
}

Measured memory_bytes: 4156
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;

using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n, m, K;
	ll memo[10004] = {};
	ll memo2[10004] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	for (int i = 0; i < 3; i++)
	{
		cin >> a;
		cin >> b;
		memo[a]++;
		memo[b]++;
	}
	for (int i = 1; i <= 4; i++)
	{
		if (memo[i]==1)
		{
			c++;
		}
		else
		{
			d++;
		}
	}
	if (c==2&&d==2)
	{
		cout << "YES" << endl;

	}
	else
	{
		cout << "NO" << endl;

	}
	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

int main(void){
  int a,b,c,x,cnt=0;

  cin>>a>>b>>c>>x;
  r(i,a+1){
    if(500*i>x)break;
    r(j,b+1){
      if(500*i+100*j>x)break;
      r(k,c+1){
        if(500*i+100*j+50*k==x)cnt++;
      }
    }
  }
  cout<<cnt<<endl;
return 0;}


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

int main() {
  int n;
  int a[2], b[2];
  while(cin >> n) {
    for(int i = 0; i < 2; ++i) {
      cin >> a[i] >> b[i];
      --a[i]; --b[i];
    }
    int ans = INT_MAX;
    for(int w = 1; w < n; ++w) {
      int sum = 0;
      for(int i = 0; i < 2; ++i) {
        int xa = a[i] % w;
        int ya = a[i] / w;
        int xb = b[i] % w;
        int yb = b[i] / w;
        sum += abs(xa-xb) + abs(ya-yb);
      }
      ans = min(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
solve :: (Int, Int) -> (Int, Int) -> String
solve (sx, sy) (tx, ty) = go1 ++ bk1 ++ go2 ++ bk2
    where
        go1 = (replicate v 'U') ++ replicate h 'R'
        bk1 = (replicate v 'D') ++ replicate h 'L'
        go2 = ['L'] ++ (replicate (v+1) 'U') ++ (replicate (h+1) 'R') ++ ['D']
        bk2 = ['R'] ++ (replicate (v+1) 'D') ++ (replicate (h+1) 'L') ++ ['U']
        v = abs $ sy - ty
        h = abs $ sx - tx

main = do
    [sx,sy,tx,ty] <- map read . words <$> getLine :: IO [Int]
    putStrLn $ solve (sx,sy) (tx,ty)

Measured memory_bytes: 1020
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
ll f(ll a, ll b) {
  ll x = min(a, b);
  ll y = max(a, b);
  if(y % x == 0) return y / x * x * 2 - x;
  return 2 * x * (y / x) + f(x, y % x);
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, X; cin >> N >> X;
  cout << N + f(X, N - X) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int A , B , C , D ;

    scanf("%d%d%d%d",&A,&B,&C,&D);
    if((A*B) < (C*D)){
        printf("%d",C*D);
    }else if((A*B) > (C*D)){
        printf("%d",A*B);
    }else{
        printf("%d",A*B);
    }


}


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

int main() {
  string S;
  cin >> S;
  int month,date = 0;
  int a = S.at(5) - '0';
  int b = S.at(6) - '0';
  int c = S.at(8) - '0';
  int d = S.at(9) - '0';
  month = 10*a + b;
  date = 10*c + d;
  if (month >= 5) cout << "TBD" << endl;
  else if (month <= 4) cout << "Heisei" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;
int main(){
	int n;
	bool han=false;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n)std::cin >> a[i];
	rep(i,n)rep(j,n){{
		std::vector<int> b(n);
		int counter=0;
		rep(k,n)b[k]=a[k];
		rep(k,n-1)if(b[k]>b[k+1])counter++;
		if(counter==0)han=true;
		
		if(i!=j){
			swap(b[i],b[j]);
			counter=0;
			//rep(k,n)std::cout << b[k];
			rep(k,n-1)if(b[k]>b[k+1])counter++;
			if(counter==0)han=true;
		}
	}}
	if(han)std::cout << "YES" << std::endl;
	else std::cout << "NO" << std::endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
using namespace std;

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)



int main()
{
	int n, h[100000] = {}, dp[10] = {};
	cin >> n;
	rep(i, n) cin >> h[i];
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
	}
	cout << dp[n - 1] << endl;
}



Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<string>
#include<queue>
using namespace std;

int n,m[101][101];
int d[101],t=0,vis[101];
queue<int> q;

void bfs(){
    q.push(1);
    d[1] = 1;
    int u,v;
    while( !q.empty() ){
        u = q.front();
        q.pop();
        for( v = 1; v <= n; v++ ){
            if( m[u][v]==0 || d[v]) continue;
            d[v] = d[u]+1;
            q.push(v);
        }
    }
    for( int i = 1; i <= n; i++ ){
        cout << i << " " << (d[i]-1) << endl;
    }
}

int main(){
    int i,j,k,u,v,du;
    scanf("%d",&n);
    k = n;
    while(k--){
        scanf("%d",&u);
        scanf("%d",&du);
        while(du--){
            scanf("%d",&v);
            m[u][v]  = 1;
        }
    }
    bfs();
}



Measured memory_bytes: 3256
// https://atcoder.jp/contests/abc138/tasks/abc138_c
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    double d;
    REP(i, n) { d += (double)1 / v[i]; }
    cout << setprecision(10) << (double)1 / d << endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
odd=0
m2=0
m4=0
for n in a:
    if n%2==1:
        odd+=1
    elif n%4!=0:
        m2+=1
    else:
        m4+=1
if m4>=odd or (m2==0 and m4>=odd-1):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int wday, jpage, mpage, limjpage, limmpage;
    cin >> wday >> jpage >> mpage >> limjpage >> limmpage;

    int const jday = jpage / limjpage + ( jpage % limjpage != 0 ? 1 : 0 );
    int const mday = mpage / limmpage + ( mpage % limmpage != 0 ? 1 : 0 );

    int const total = max( jday, mday );

    cout << wday - total << endl;
}

Measured memory_bytes: 1160
N, K = map(int, input().split())
ans = 0
mod = 10**9+7
for i in range(K, N+2):
    _min = (i+1)*i//2
    _max = ((N+1) + (N+1-i+1)) * i // 2
    ans += (_max - _min + 1) % mod
    ans %= mod
print(ans)

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


int main() {
    int w,a,b;
    cin >> w >> a >> b;
    if ( b>a+w||b+w<a ) {
        cout << min(abs(b-a-w),abs(a-b-w));
    } else {
        cout << 0 << '\n';
    }
    return 0;
}

 





Measured memory_bytes: 3616
#include <cstdio>

int main(){
    int n;
    scanf("%d",&n);
    bool card[4][13];
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 13; j++){
            card[i][j] = false;
        }
    }

    for(int i = 0; i < n; i++){
        char c;
        scanf("\n%c",&c);
        int x;
        scanf("%d",&x);
        if(c == 'S'){
            card[0][x - 1] = true;
        }
        else if(c == 'H'){
            card[1][x - 1] = true;
        }
        else if(c == 'C'){
            card[2][x - 1] = true;
        }
        else if(c == 'D'){
            card[3][x - 1] = true;
        }
    }

    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 13; j++){
            if(card[i][j] == false){
                if(i == 0){
                    printf("S %d",j+1);
                }
                else if(i == 1){
                    printf("H %d",j+1);
                }
                else if(i == 2){
                    printf("C %d",j+1);
                }
                else if(i == 3){
                    printf("D %d",j+1);
                }
                printf("\n");
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
int H[20], W[20];
string S[5];
int field[5][5];
int dist[1 << 17];
bool chmin(int &a, int b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int f(int nowbit, int stamp, int h, int w, int color) {
    int ans = nowbit;
    for(int dh = 0; dh < H[stamp]; dh++) {
        int newh = h + dh;
        if(newh < 0 || newh > 3) continue;
        for(int dw = 0; dw < W[stamp]; dw++) {
            int neww = w + dw;
            if(neww < 0 || neww > 3) continue;
            int grid = newh * 4 + neww;
            if(field[newh][neww] == color) ans |= (1 << grid);
            else ans &= ~(1 << grid);
        }
    }
    return ans;
}

int main() {
    //cout.precision(10);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> H[i] >> W[i];
    for(int h = 0; h <= 3; h++) cin >> S[h];
    for(int h = 0; h < 4; h++) {
        for(int w = 0; w < 4; w++) {
            if(S[h][w] == 'R') field[h][w] = 0;
            if(S[h][w] == 'G') field[h][w] = 1;
            if(S[h][w] == 'B') field[h][w] = 2;
        }
    }
    for(int i = 0; i < (1 << 16); i++) dist[i] = INF;
    dist[0] = 0;
    queue<int> que;
    que.push(0);
    while(!que.empty()) {
        int nowbit = que.front();
        //cerr << nowbit << " " << dist[nowbit] << endl;
        //if(dist[nowbit] > 3) break;
        if(dist[(1 << 16) - 1] != INF) break;
        que.pop();
        for(int stamp = 0; stamp < N; stamp++) {
            for(int h = 1 - H[stamp]; h <= 3; h++) {
                for(int w = 1 - W[stamp]; w <= 3; w++) {
                    for(int color = 0; color <= 2; color++) {
                        int newbit = f(nowbit, stamp, h, w, color);
                        if(chmin(dist[newbit], dist[nowbit] + 1)) que.push(newbit);
                    }
                }
            }
        }
    }
    cout << dist[(1 << 16) - 1] << endl;
    return 0;
}



Measured memory_bytes: 3564
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    cost = defaultdict(int)
    cost["r"] = p
    cost["s"] = r
    cost["p"] = s
    t = list(input())

    ans = 0
    for i in range(k):
        c = 0
        for j in range(i, n, k):
            if i == j:
                ans += cost[t[j]]
            else:
                if t[j] == t[j - k]:
                    t[j] = "ggg"
                else:
                    ans += cost[t[j]]
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 6200
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), C(M);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        A[i] = a;
        rep(j, b) {
            int c;
            cin >> c;
            C[i] |= (1 << (c - 1));
        }
    }

    vv<ll> dp = vvec(M + 1, 1 << N, LINF);
    dp[0][0] = 0;
    rep(i, M) {
        rep(bit, 0, 1 << N) {
            dp[i + 1][bit | C[i]] = min(dp[i + 1][bit | C[i]], dp[i][bit] + A[i]);
            dp[i + 1][bit] = min(dp[i + 1][bit], dp[i][bit]);
        }
    }

    if (dp[M][(1 << N) - 1] == LINF) {
        write(-1);
    }
    else {
        write(dp[M][(1 << N) - 1]);
    }
}

Measured memory_bytes: 32384
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void solve(){
	string s;
	cin>>s;
	int x=0,y=0,ans=0,bans=0;
	rep(i,sz(s)){
		if(s[i]=='A' && !x){
			ans=i;
			x=1;
		}
		if(s[i]=='Z'){
			bans=i;
		}
	}
	cout<<bans-ans+1;

}

int main(){
	Red;
	int t=1;
	// cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

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

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

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int K;
    cin >> K;
    int A = 0;
    for(int i = 0;i < 2000000;i++) {
        A += 7 * RS(10, i, K) % K;
        A %= K;
        if(A == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define MAX 2000000
#define INFTY (1<<30)
using namespace std;


int main()
{
    int key;
    char com[10];
    priority_queue<int> PQ;
    while(1)
    {
        scanf("%s",com);
        if(com[0]=='e'&&com[1]=='n')break;
        if(com[0]=='i')
        {
            scanf("%d",&key);
            PQ.push(key);
        }else
        {
            printf("%d\n",PQ.top());
            PQ.pop();
        }
    }
 	return 0;
}



Measured memory_bytes: 6976
#include <stdio.h>
#include <ctype.h>
#include <string.h>


int main(void){
	long long int i, l, flag[100][100][4], dx[4] = {0,1,0,-1},dy[4] = {-1,0,1,0}, h, w, d, j, k, x, y;
	char str[100][101], dir[5] = {"NESW"};
	while(1){
		scanf("%lld%lld%lld%*c",&h,&w,&l);
		if(h == 0 && w == 0 && l == 0)
			break;
		for(i = 0;i < h;i++){
			for(j = 0;j < w;j++){
				str[i][j] = getchar();
				if(isupper(str[i][j])){
					x = j;
					y = i;
					for(k = 0;k < 4;k++)
						if(str[i][j] == dir[k]) d = k;
					str[i][j] = '.';
				}
			}
			str[i][j] = '\0';
			getchar();
		}
		memset(flag,-1,sizeof(flag));
		for(i = 0;i < l;i++){
			if(flag[y][x][d] == -1)
				flag[y][x][d] = i;
			else{
				i += (i - flag[y][x][d]) * ((l - i) / (i - flag[y][x][d])) - 1;
				memset(flag,-1,sizeof(flag));
				continue;
			}
			while(1){
				if(x + dx[d] >= 0 && x + dx[d] < w && y + dy[d] >= 0 && y + dy[d] < h && str[y + dy[d]][x + dx[d]] == '.'){
					x = x + dx[d];
					y = y + dy[d];
					break;
				}
				d = (d + 1) % 4;
			}
		}
		printf("%lld %lld %c\n",y + 1,x + 1,dir[d]);
	}
	return 0;
}

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

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N+1);
  vector<ll> B(M+1);
  int x;
  for(int i=1; i<=N; ++i){
    cin >> x;
    A.at(i) = A.at(i-1) + x;
  }
  for(int i=1; i<=M; ++i){
    cin >> x;
    B.at(i) = B.at(i-1) + x;
  }
  int ans=0, j=M;
  for(int i=0; i<=N; i++){
    if(A.at(i) > K) break;
    while(B.at(j) > K-A.at(i)) --j;
    ans = max(ans, i+j);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6424
#include <iostream>
#include <set>

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

    std::multiset<int> s;
    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int t;
        std::cin >> t;
        if (t == 0) {
            int x;
            std::cin >> x;
            s.insert(x);
            std::cout << s.size() << "\n";
        } else if (t == 1) {
            int x;
            std::cin >> x;
            std::cout << s.count(x) << "\n";
        } else if (t == 2) {
            int x;
            std::cin >> x;
            s.erase(x);
        } else {
            int l, r;
            std::cin >> l >> r;
            auto e = s.upper_bound(r);
            for (auto itr = s.lower_bound(l); itr != e; ++itr) std::cout << *itr << "\n";
        }
    }
}


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

long long n,k;
long long T[100000];

int check(long long P){
  //Pを入れていくつの荷物が運べるかを返す
  long long i=0;
  for (int j=0;j<k;j++){
    long long s=0;    
    while(s+T[i]<P){
      s=s+T[i];
      i++;
      if(i==n) return n;
    }
  }
  return i; 
}


int solve(){
  long long left=0;
  long long right=100000*10000;
  while(right-left>1){//right>leftだと１差で永久に続く
    long long m=(left+right)/2;
    long long v=check(m);
    if(v>=n){
      right=m;
    }
    else left=m;
  }
  return left;
}

int main(){
  cin >> n >> k;
  for (int i=0;i<n;i++) cin>>T[i];
  long long ans=solve();
  cout<<ans<<endl;
  return 0;
}
  




Measured memory_bytes: 3876
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long li;

int n;

int main(void) {
  scanf("%d", &n);
  li ans = 0, diff = 0;
  int tmp = 2e9;
  for (int i = 1, x, y; i <= n; ++i) {
    scanf("%d%d", &x, &y);
    diff += abs(x - y);
    ans += x;
    if (y < x) tmp = min(tmp, y);
  }
  if (diff) printf("%lld\n", ans - tmp);
  else puts("0");

  return 0;
}


Measured memory_bytes: 128
//सत्यान्न प्रमदितव्यम्  ||
//Still, Taking my time to perfect the beats
//And I still got love for the streets, it's the A-D-D-U

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define nt _int128
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debugged cout<<"debugged\n";
#define inf 0x3f3f3f3f
#define LINF  0x3f3f3f3f3f3f3f3fll
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end() 

const ll mod = 999983;
#define mx 1000005
const ll mxi = 10005;

int main()
{
    fast_as_levi;
    ll n,m;
    cin>>n>>m;
    ll ht[n+1];
    for(int i=1;i<=n;i++)
    cin>>ht[i];
    ll mxa[n+1] = {0};
    while(m--)
    {
        ll x,y;
        cin>>x>>y;
        mxa[x] = max(ht[y],mxa[x]);
        mxa[y] = max(ht[x],mxa[y]);
    }
    ll ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(ht[i]>mxa[i])
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
template<typename T = int> using V = vector<T>;
template<typename T = int> using P = pair<T, T>;
using Vi = V<int>;
using Vl = V<ll>;
using Vd = V<ld>;
using VVi = V<Vi>;
using VVl = V<Vl>;
using VVd = V<Vd>;
using Pi = P<int>;
using Pl = P<ll>;
using Pd = P<ld>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); } // floor(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); } // ceil(log2(x))
inline int popcount(const ll x) { return __builtin_popcountll(x); }
inline void fail() { cout << -1 << '\n'; exit(0); }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
// const int INF  = 1<<30;
// const ll INFll = 1ll<<60;
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll h, w, m; cin >> h >> w >> m;
  
  Vi ci(h), cj(w);
  set<Pi> S;
  rep(i, m) {
    int x, y; cin >> x >> y;
    --x, --y;
    ++ci[x];
    ++cj[y];
    S.emplace(x, y);
  }

  int mi = 0, mj = 0;
  rep(i, h) chmax(mi, ci[i]);
  rep(i, w) chmax(mj, cj[i]);

  Vi vi, vj;
  rep(i, h) if (ci[i] == mi) vi.push_back(i);
  rep(i, w) if (cj[i] == mj) vj.push_back(i);
  
  for (auto i : vi) for (auto j : vj) {
    if (S.find(Pi(i, j)) == S.end()) {
      cout << (mi + mj) << '\n';
      return 0;
    }
  }
  cout << (mi + mj - 1) << '\n';
}


Measured memory_bytes: 23740
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x

int main() {

  string S, T;

  cin >> S;
  cin >> T;
  int ans = 0;

  if( S[0] == T[0] ){
    ans++;
  }
  if( S[1] == T[1] ){
    ans++;
  }
  if( S[2] == T[2] ){
    ans++;
  }

  cout << ans << endl;


}

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

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

#define K 10000

int main(){
  int n;
  int i,j;
  int *A;
  int *B;
  int C[K+1];

  scanf("%d",&n);
  A=(int *)malloc((n+1)*sizeof(int));
  B=(int *)malloc((n+1)*sizeof(int));
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
		  
  for(i=0;i<=K;i++)C[i]=0;
	  
  for(j=1;j<=n;j++)C[A[j]]++;
  
  for(i=1;i<=K;i++)C[i]=C[i]+C[i-1];

  for(j=n;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<n;i++)printf("%d ",B[i]);
  printf("%d\n",B[i]);
  free(A);
  free(B);
  return 0;
}



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

  let i, j, X, Y, xlen, ylen, maxlen;
  let c;
  while ((X = lines.shift()) && (Y = lines.shift())) {
    xlen = X.length;
    ylen = Y.length;
    c = Array.from(Array(xlen + 1), () => []);

    for (i = 1; i <= xlen; i++) {
      for (j = 1; j <= ylen; j++) {
        if (X[i-1] === Y[j-1]) c[i][j] = c[i - 1][j - 1] + 1||1;
        else c[i][j] = Math.max(c[i - 1][j]||0, c[i][j - 1]||0);
      }
    }
    console.log(c[xlen][ylen]);
  }
})();



Measured memory_bytes: 142608
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
h = list(map(int, input().split()))
h_cond = [True]*n
count = 0

for i in range(m):
    tmp_a, tmp_b = map(int, input().split())
    if h[tmp_a-1] < h[tmp_b-1]:
        h_cond[tmp_a-1] = False
    elif h[tmp_a-1] > h[tmp_b-1]:
        h_cond[tmp_b-1] = False
    else:
        h_cond[tmp_a - 1] = False
        h_cond[tmp_b - 1] = False

# print(h_cond)
# print(route)
for idx, hi in enumerate(h_cond):
    if h_cond[idx]:
        count += 1

print(count)


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

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

    int h,w;
    cin>>h>>w;
    string s[h];
    for (int i = 0; i < h; i++)
    {
        cin>>s[i];
    }
    int x[h][w]={};
    int y[h][w]={};
    for(int i=0;i<h;i++){
        int cnt=0;
        int l=0;
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                for(int k=l;k<j;k++){
                    x[i][k]=cnt;
                }
                cnt = 0;
                l=j+1;
            }
            else cnt++;
        }
        for(int k=l;k<w;k++){
            x[i][k]=cnt;
        }
    }
    for(int i=0;i<w;i++){
        int cnt=0;
        int l=0;
        for(int j=0;j<h;j++){
            if(s[j][i]=='#'){
                for(int k=l;k<j;k++){
                    y[k][i]=cnt;
                }
                cnt = 0;
                l=j+1;
            }
            else cnt++;
        }
        for(int k=l;k<h;k++){
            y[k][i]=cnt;
        }
    }
    int ans =0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans = max(ans,x[i][j]+y[i][j]-1);
            //cerr<<ans<<" "<<x[i][j]<<" "<<y[i][j]<<endl;
        }
    }
    cout << ans << endl;
    
    
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
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; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数,
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl a[n];
    rep(i,n)cin >> a[i];
    intl num = 0;
    rep(i,n)num ^= a[i];
    rep(i,n){
        cout << (num ^ a[i]) << " ";
    }
    return 0;
}


Measured memory_bytes: 5068