akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for(int i  = (int)(s); i < (int)(e); ++i)
#define rep(i, n) REP(i, 0, n)

struct UF {
  int n;
  vector<int> d;
  UF(int v) : n(v+1), d(v+1, -1){
    REP(i, 1, n) d[i] = -i;
  }
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return false;
    d[y] = x;
    return true;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

int main() {
  int n, q;
  while(cin >> n >> q) {
    if(n == 0 && q  == 0) break;
    vector<int> par(n+1);
    REP(i, 2, n+1) cin >> par[i];
    using P = pair<int, int>;
    vector<P> query(q);
    vector<int> marked(n+1);
    marked[1] = 1;
    rep(i, q) {
      char c;
      int t;
      cin >> c >> t;
      query[i].first = (c == 'M');
      query[i].second = t;
      if(query[i].first) marked[t]++;
    }
    UF uf(n);
    REP(i, 1, n+1) {
      if(!marked[i]) {
	uf.unite(par[i], i);
      }
    }
    // REP(i, 1, n+1) {
    //   cout << i << " " << uf.root(i) << endl;
    // }
    long long int ans = 0LL;
    for(int i = q-1; i >= 0; --i) {
      int v = query[i].second;
      if(query[i].first) {
	marked[v]--;
	if(marked[v] == 0) uf.unite(par[v], v);
      }
      else {
	ans += uf.root(v);
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 4780
#include <bits/stdc++.h>
int num[2000][2000];
int num2[2000][2000];
int num3[2000][2000];
int main()
{
    int N, D;
    std::cin >> N >> D;
    for (int i = 0, x, y; i < N; i++) {
        std::cin >> x >> y;
        num[y % D][x % D]++;
        num[D + y % D][x % D]++;
        num[y % D][D + x % D]++;
        num[D + y % D][D + x % D]++;
    }
    int max = 0;
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < D; j++) { max = std::max(max, num[i][j]); }
    }
    int a = 0;
    for (; (a + 1) * (a + 1) < max; a++) {}
    for (int i = 0; i < 2 * D; i++) {
        for (int j = 0; j < 2 * D; j++) { num2[i][j] = num[i][j] > a * a ? 1 : 0, num3[i][j] = num[i][j] > a * (a + 1) ? 1 : 0; }
    }
    for (int i = 0; i < 2 * D; i++) {
        for (int j = 1; j < 2 * D; j++) { num2[i][j] += num2[i][j - 1], num3[i][j] += num3[i][j - 1]; }
    }
    for (int i = 1; i < 2 * D; i++) {
        for (int j = 0; j < 2 * D; j++) { num2[i][j] += num2[i - 1][j], num3[i][j] += num3[i - 1][j]; }
    }
    auto get2 = [&](const int xl, const int xr, const int yl, const int yr) { return num2[yr - 1][xr - 1] - (yl == 0 ? 0 : num2[yl - 1][xr - 1]) - (xl == 0 ? 0 : num2[yr - 1][xl - 1]) + (yl == 0 or xl == 0 ? 0 : num2[yl - 1][xl - 1]); };
    auto get3 = [&](const int xl, const int xr, const int yl, const int yr) { return num3[yr - 1][xr - 1] - (yl == 0 ? 0 : num3[yl - 1][xr - 1]) - (xl == 0 ? 0 : num3[yr - 1][xl - 1]) + (yl == 0 or xl == 0 ? 0 : num3[yl - 1][xl - 1]); };

    auto ok = [&](const int b) {
        for (int i = 0; i < D; i++) {
            for (int j = 0; j < D; j++) {
                const int n2 = get2(i + b, i + D, j + b, j + D);
                const int n3 = get3(i + b, i + D, j, j + b) + get3(i, i + b, j + b, j + D);
                if (n3 == 0 and n2 == 0) { return true; }
            }
        }
        return false;
    };
    int inf = 0, sup = D + 1;
    while (sup - inf > 1) {
        const int mid = (inf + sup) / 2;
        (ok(mid) ? sup : inf) = mid;
    }
    std::cout << a * D + inf << std::endl;
    return 0;
}


Measured memory_bytes: 47104
def GCD( a,  b ):
    if b == 0:
        # print("--" * 10)
        return a
    else:
        # print(b)
        return GCD(b, a % b)

N = int(input())
As = list(map(int,input().split(" ")))

left = [0]

for i,A in enumerate(As[:]):
    left.append(GCD(A,left[i]))
Bs = As[::-1]
right = [0]

for i,B in enumerate(Bs[:]):
    right.append(GCD(B,right[i]))
# print(left)
# print(right)

left = left[::-1]

ans = []
for i in range(0,N):
    ans.append(GCD(left[i+1],right[i]))
print(max(ans))


Measured memory_bytes: 14584
# https://atcoder.jp/contests/abc128/abc128_c
import itertools as it

N, M = map(int, input().split())
xss = [[int(s) for s in input().split()][1:] for _ in range(M)]
ps = [int(s) for s in input().split()]

iterable = it.product([0, 1], repeat=N)
cnt = 0
for switches in iterable:
    res = True
    for xs, p in zip(xss, ps):
        selected = [switches[x - 1] for x in xs]
        is_on = (sum(selected) % 2) == p
        res = res and is_on

    if res:
        cnt += 1

print(cnt)


Measured memory_bytes: 3064
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e7+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
void solve()
{
    ll m;
    cin>>m;
    ll k=m/4;
    while(k>=0)
    {
        if((m-k*4)%7==0)
            {cout<<"Yes";return;}
        k--;
    }
    cout<<"No";return;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;for(int te=1;te<=t;te++)
    {
        solve();
    }
    return 0;
}

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

void change(string&t){
	for(auto i=t.begin()+1;i!=t.end();++i){
		if(*(i-1)==*i)*i='@';
	}
}

int cnt(string&t){
	return count(t.begin()+1,t.end(),'@');
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s; int k; cin>>s>>k;
	string t=s;
	change(t);
	string t1=t.back()+s;
	change(t1);
	string t2=t1.back()+s;
	change(t2);
	int f=cnt(t),e=cnt(t1),o=cnt(t2);
	cout<<1l*f+1l*k/2*e+1l*(k-1)/2*o<<"\n"s;
}

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

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

    if(x == 0) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}



Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Optional;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り　0:ON　1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if(system==0) param.add(sc.next());
				if(system==1) param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		num.remove(0);
		
		Optional<Integer> max = num.stream().max(Comparator.naturalOrder());
		Optional<Integer> min = num.stream().min(Comparator.naturalOrder());
		
		System.out.println(max.get() - min.get());
	}
}

Measured memory_bytes: 27092
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int state[214514];
int nxt[214514];
vector<int> cycle;
vector<int> es[214514];
vector<multiset<int>> mex;

int DecomposeNamori(int v) {
  if (state[v] == 2) {
    return 0;
  }

  if (state[v] == 1) {
    state[v] = 2;
    return 1;
  }

  assert(state[v] == 0);
  state[v] = 1;
  int res = DecomposeNamori(nxt[v]);
  if (res == 1) {
    cycle.eb(v);
    if (state[v] == 2) return 0;
    state[v] = 2;
    return 1;
  }
  assert(res == 0);
  es[nxt[v]].eb(v);
  state[v] = 2;
  return 0;
}

int CalcGrundy(int v) {
  vector<char> num(es[v].size());
  int ret = es[v].size();
  for (int u : es[v]) {
    int t = CalcGrundy(u);
    if (t >= num.size()) continue;
    num[t] = 1;
  }

  rep(t, ret) {
    if (!num[t]) return t;
  }
  return ret;
}

multiset<int> CalcMex(int v) {
  multiset<int> ret;
  for (int u : es[v]) {
    ret.insert(CalcGrundy(u));
  }
  return ret;
}

int Mex(multiset<int> &ms) {
  int ret = ms.size();
  rep(t, ret) {
    if (!ms.count(t)) return t;
  }
  return ret;
}

int main() {
  cin >> N;
  rep(v, N) {
    cin >> nxt[v];
    nxt[v]--;
  }

  rep(v, N) {
    if (state[v] == 2) continue;
    assert(state[v] == 0);
    DecomposeNamori(v);
  }

  reverse(all(cycle));
  for (int v : cycle) {
    mex.eb(CalcMex(v));
  }

  assert(mex.size() >= 2);
  vector<int> grundy(mex.size());
  int M = mex.size();
  int st = Mex(mex[0]);
  rep(i, 2) {
    if (i == 0) {
      grundy[0] = st;
    } else {
      mex[0].insert(st);
      grundy[0] = Mex(mex[0]);
      mex[0].erase(mex[0].find(st));
    }

    reps(idx, 1, mex.size()) {
      int p = (idx-1)%M;
      mex[idx].insert(grundy[p]);
      grundy[idx] = Mex(mex[idx]);
      mex[idx].erase(mex[idx].find(grundy[p]));
    }

    mex[0].insert(grundy[M-1]);
    if (grundy[0] == Mex(mex[0])) {
      puts("POSSIBLE");
      return 0;
    }
    mex[0].erase(mex[0].find(grundy[M-1]));
  }
  puts("IMPOSSIBLE");
}


Measured memory_bytes: 27240
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define MIN(a,b,c,d) min(min(a,b),min(c,d))

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int w, h;
vpl pq;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  cin >> w >> h;
  pq = vpl(w+h);
  int k;
  for(k = 0;k < w;k++){
    cin >> pq[k].first;
    pq[k].second = 0;
  }
  for(;k < w+h;k++){
    cin >> pq[k].first;
    pq[k].second = 1;
  }
  sort(all(pq));
  int a = w+1, b = h+1;
  ll cost = 0;
  rep(i,h+w){
    if(pq[i].second == 0){
      cost += pq[i].first * b;
      a--;
    }else{
      cost += pq[i].first * a;
      b--;
    }
  }
  cout << cost << endl;
	return 0;
}


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

using namespace std;

mt19937 rng(time(NULL));

int D;
int c[27];
int s[410][27];
const int MAX = 26;

int ans[410];

int last[27];
long long dc = 0, score = 0, sum = 0;

long long curScore;
vector<int> candidate, optimal;

set<int> position[27];

double prob = 0;

long long f(long long x){
	if(x < 0) return 0;
	return x * (x + 1) / 2;
}

const int PMAX = 1000000000;

double dice(){
	return (double) (rng() % PMAX) / (PMAX - 1);
}

long long calc(vector<int> &a){
	long long score = 0;

	memset(last, 0, sizeof(last));
	for(int i = 1; i < (int) a.size(); i++){
		score += s[i][a[i]];

		last[a[i]] = i;
		for(int j = 1; j <= MAX; j++){
			score -= 1LL * c[j] * (i - last[j]);
		}
	}

	return score;
}

void Randomize(){
	for(int i = 1; i <= MAX; i++) position[i].insert(-1);
	for(int i = 1; i <= MAX; i++) position[i].insert(D + 1);

	int id = 1;
	for(auto &k : candidate) position[k].insert(id++);

	// for(int i = 1; i <= MAX; i++){
	// 	int pre = -1;
	// 	for(auto &k : position[i]){
	// 		score -= 1LL * f(k - pre - 1) * c[i];
	// 		pre = k;
	// 	}
	// }

	for(int asd = 0; asd <= 1000; asd++){
		int pos, contestNxt;
		pos = rng() % D + 1; contestNxt = rng() % 26 + 1;
		
		// int contestNow = candidate[pos];

		// int lfNow = *position[contestNow].lower_bound(pos - 1);
		// int rgNow = *position[contestNow].upper_bound(pos);

		// int rgNxt = *position[contestNxt].lower_bound(pos);
		// int lfNxt = *prev(position[contestNxt].lower_bound(pos));

		// long long paramNow = s[pos][contestNow] - f(rgNxt - lfNxt - 1) * c[contestNxt] - f(rgNow - pos - 1) * c[contestNow] - f(pos - lfNow - 1) * c[contestNow];
		// long long paramNxt = s[pos][contestNxt] - f(rgNxt - pos - 1) * c[contestNxt] - f(pos - lfNxt - 1) * c[contestNxt] - f(rgNow - lfNow - 1) * c[contestNow];

		vector<int> nxt = candidate;

		nxt[pos] = contestNxt;

		long long paramNow = calc(candidate);
		long long paramNxt = calc(nxt);

		double p = 0;
		if(paramNow < paramNxt) p = 0.9999;

		if(curScore < paramNxt) optimal = nxt, curScore = paramNxt;
		
		if(dice() <= p) swap(candidate, nxt);
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> D;

	for(int i = 1; i <= MAX; i++) cin >> c[i], sum += c[i];

	for(int i = 1; i <= D; i++){
		for(int j = 1; j <= MAX; j++){
			cin >> s[i][j];
		}
	}

	candidate.emplace_back(0);

	for(int i = 1; i <= D; i++){
		int opt = -1; long long inc = -1e18;

		for(int j = 1; j <= MAX; j++){
			if(inc < s[i][j] - (dc + sum) + c[j] * (i - last[j])){
				opt = j;
				inc = s[i][j] - (dc + sum) + c[j] * (i - last[j]);
			}
		}

		candidate.emplace_back(opt);
		// cout << opt << "\n";

		dc += sum;
		dc -= c[opt] * (i - last[opt]);
		last[opt] = i;

		// score += inc;
		score += s[i][opt];
		// cout << (i % MAX) + 1 << "\n";
	}

	optimal = candidate;
	curScore = calc(optimal);
	Randomize();

	for(int i = 1; i < (int) optimal.size(); i++){
		cout << optimal[i] << "\n";
	}

	// cerr << score << "\n";

	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
int a[100005];
int Min = 0x3f3f3f3f;

int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(int i=k-1;i<n;i++){
        int temp = a[i] - a[i-k+1];
        Min = min(Min,temp);
    }
    printf("%d\n",Min);

    return 0;
}


Measured memory_bytes: 640
n=gets.to_i
a,b =[], []
n.times do |i|
    a[i], b[i] = gets.chomp.split.map(&:to_i)
end

ans = 0
(n-1).downto(0) do |i|
    if (a[i] + ans) % b[i] != 0
        ans += b[i] - (a[i] + ans) % b[i]
    end
end
puts ans

Measured memory_bytes: 5480
m, n = map(int, input().split())

mod = 10 ** 9 + 7


def modpow(m, n, mod):
    if n == 0:
        return 1

    if n % 2 == 0:
        return modpow(m, n // 2, mod) ** 2 % mod
    else:
        return modpow(m, n - 1, mod) * m % mod


print(modpow(m, n, mod) % mod)



Measured memory_bytes: 5600
x1,y1,x2,y2 = map(int,input().split())

x3 = x2 + (y1-y2)
y3 = y2 - (x1-x2)

x4 = x3 + (y2-y3)
y4 = y3 - (x2-x3)

print("{} {} {} {}".format(x3,y3,x4,y4))

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

const ll MOD = (int)1e9 + 7;
ll power(ll b, ll e) {
	ll r = 1;
	while(e) {
		if(e % 2 == 1) {
			r *= b;
			r %= MOD;
		}
		e >>= 1;
		b *= b;
		b %= MOD;
	}
	return r;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector<ll> dp(k + 1, 0);
	ll ans = 0;
	for(int i = k; i >= 1; --i) {
		dp[i] = power(k / i, n);
		for(int j = 2 * i; j <= k; j += i) {
			dp[i] -= dp[j];
			if(dp[i] < 0) dp[i] += MOD;
		}
		// cout << dp[i] << " ";
		ans += i * dp[i];
		ans %= MOD;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3956
#include <stdio.h>
 
typedef struct shain{
    int bangou;
    double uriage;
}shain;
 
int main(void){
    int data_n,i,j,flag,kaburi,hyouji;
    int bangou,tanka,suuryou;
    shain men[4001];
     
    while(1){
        scanf("%d",&data_n);
        if(data_n == 0) break;
        kaburi = 0;
        hyouji = 0;
        for(i=0;i < 4001;i++){
            men[i].bangou = 0;
            men[i].uriage = 0.0;
        }
        for(i=0;i < data_n;i++){
            scanf("%d %d %d",&bangou,&tanka,&suuryou);
            for(j=0;j <= i;j++){
                if(men[j].bangou == bangou){
                    flag = 1;
                    kaburi++;
                    men[j].uriage += 1.0*tanka*suuryou;
                }
            }
            if(flag != 1){
                men[i].bangou = bangou;
                men[i].uriage = 1.0*tanka*suuryou;
            }
            flag = 0;
        }
        j = i;
        for(i=0;i < j;i++){
            if(men[i].uriage >= 1000000.0){
                printf("%d\n",men[i].bangou);
                hyouji++;
            }
        }
        if(hyouji == 0) printf("NA\n");
    }
    return 0;
}

Measured memory_bytes: 672
#include<bits/stdc++.h>
using namespace std;
#define INF 100000

int main()
{
  int n,ma,mb;cin>>n>>ma>>mb;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  int i,j,k;
  for(i=0;i<n;i++)cin>>a.at(i)>>b.at(i)>>c.at(i);
  vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(n*10+1,vector<int>(n*10+1,INF)));
  for(i=0;i<=n;i++)dp.at(i).at(0).at(0)=0;
  for(i=1;i<=n;i++)
  {
    for(j=1;j<=n*10;j++)
    {
      for(k=1;k<=n*10;k++)
      {
        if(j-a.at(i-1)>=0&&k-b.at(i-1)>=0)
        {
          dp.at(i).at(j).at(k)=min(dp.at(i-1).at(j).at(k),dp.at(i-1).at(j-a.at(i-1)).at(k-b.at(i-1))+c.at(i-1));
        }
        else dp.at(i).at(j).at(k)=dp.at(i-1).at(j).at(k);
      }
    }
  }
  int ans=INF;
  for(i=1;max(ma,mb)*i<=10*n;i++)
  {
    if(dp.at(n).at(i*ma).at(i*mb)<ans)ans=dp.at(n).at(i*ma).at(i*mb);
  }
  if(ans==INF)cout<<-1<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 27264
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=500000;

main(){
    string s;
    cin>>s;
    if(s=="SUN")cout<<7;
    if(s=="MON")cout<<6;
    if(s=="TUE")cout<<5;
    if(s=="WED")cout<<4;
    if(s=="THU")cout<<3;
    if(s=="FRI")cout<<2;
    if(s=="SAT")cout<<1;
}

Measured memory_bytes: 256
#include <iostream>                                             
#include <vector>                                               
using namespace std;                                            
                                                                
int main(void) {                                                
  int r, c;                                                     
  cin >> r >> c;                                                
  vector< vector<int> > rc(r+1,vector<int>(c+1,0));             
  for (int i=0; i<r; i++) {                                     
    for (int j=0; j<c; j++) {                                   
      cin >> rc[i][j];                                          
      rc[i][c] += rc[i][j];                                     
    }                                                           
  }                                                             
  for (int j=0; j<c+1; j++) {                                   
    for (int i=0; i<r; i++) {                                   
      rc[r][j] += rc[i][j];                                     
    }                                                           
  }                                                             
  for (int i=0; i<r+1; i++) {                                   
    for (int j=0; j<c+1; j++) {                                 
      cout << rc[i][j] << flush;                                
      cout << (j-c?" ":"\n") << flush;                          
    }                                                           
  }                                                             
  return 0;                                                     
}                                                               
                                                                
                                                                
                                                                
                                                                
                         

Measured memory_bytes: 3156
#include <algorithm>
#include <iostream>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

#define MAX_N 100000

int main(void) {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  priority_queue<int, vector<int>> que;
  rep(i, N) {
    int a;
    cin >> a;
    que.push(a);
  }

  for (int i = 0; i < M; i++) {
    int X = que.top();
    que.pop();
    X /= 2;
    que.push(X);
  }

  ll Ans = 0;
  for (int i = 0; i < N; i++) {
    int X = que.top();
    que.pop();
    Ans += X;
  }
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <cstdlib>
#include <bitset>
using namespace std;

int main()
{ 
    int n, x, i, j, k, ans;
    while(true){
    cin >> n >> x;
    if((n==0)&(x==0))break;
    ans = 0;
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            for(k=j+1; k<n; k++){
                if((i!=j)&(i!=k)&(j!=k)){
                    if(i+j+k==x-3)ans++;
                }
            }
        }
    }
    cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//ifstream cin("input.txt");
 
    int k,a,b;
    cin>>k>>a>>b;
    
    for(int i=a; i<=b; i++)
    {
        if(i%k==0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    
    cout << "NG" << endl;
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
typedef long long li;
#define yn(i) print((i)?"first":"second")
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int n; cin >>n;
  int f=0;
  rep(i,n){
    int a; cin >>a;
    if(a&1) f|=1;
  }
  yn(f);
}


Measured memory_bytes: 3624
def main():
    N, K = map(int, input().split())
    S = input()
    nums = []
    now = 1
    cnt = 0
    for s in S:
        if int(s) == now:
            cnt += 1
        else:
            nums.append(cnt)
            now ^= 1
            cnt = 1
    if cnt > 0:
        nums.append(cnt)
    if len(nums) % 2 == 0:
        nums.append(0)
    add = 2 * K + 1
    ans = 0
    left = 0
    right = 0
    tmp = 0
    for cnt in range(0, len(nums), 2):
        nleft = cnt
        nright = min(cnt + add, len(nums))
        while nleft > left:
            tmp -= nums[left]
            left += 1
        while nright > right:
            tmp += nums[right]
            right += 1
        ans = max(tmp, ans)
    print(ans)


main()


Measured memory_bytes: 4092
n,m = map(int,input().split())
a = list(map(int, input().split()))
a.sort()
e =0
bc = []
for i in range(m):
    d = list(map(int,input().split()))
    bc.append([d[1],d[0]])
    e += d[0] 
#print(a)  
 
 
bc.sort()
bc.reverse()
#print(bc)
 
#print(e)
#print(a[n-1])
j = 0
for i in range(n):
    if j == bc[0][1] :
        bc.remove(bc[0])
        j = 0
    if bc[0][0] > a[i]:
        a[i] = bc[0][0]
        j += 1
    else:
        break
    if i == e-1:
        break
 
 
#print(a)
print(sum(a))

Measured memory_bytes: 24428
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const ll N =2e5+5;
ll ans[N];
ll sum[N];
int main(){
       cin.tie(0), ios::sync_with_stdio(0);
     int s,w;
     cin>>s>>w;
    if(w>=s)
    cout<<"unsafe"<<endl;
    else
    cout<<"safe"<<endl;
 
     }

Measured memory_bytes: 3664
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  std::vector<int> a(n);
  int min=INT32_MAX,max=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    min=std::min(min,a[i]);
    max=std::max(max,a[i]);
  }
  if(max-min==0){

    bool     is_alone = true, is_notalone = true;
    for(auto x:a){
      if(x != n - 1) is_alone       = false;
      if(!(x <= n / 2)) is_notalone = false;
    }
    if(is_alone || is_notalone){
      cout << "Yes" << endl;
      return 0;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }else if(max-min==1){
    int num_min = 0, num_max = 0;
    for(auto   x:a){
      if(x == min){
        num_min++;
      }else{
        num_max++;
      }
    }
    if(num_min+1<=max&&max<=num_min+num_max/2){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
    
  }else{
    cout<<"No"<<endl;
      

  }

  return 0;
}


Measured memory_bytes: 640
#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;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    cout << (n-1)/2<<endl;
    return 0;
}


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

double abs(double x,double y){
  if(x>=y){
    return x-y;
  }
  else{
    return y-x;
  }
}
int main() {
  int N,T,A;
  cin>> N>>T>>A;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin >> H.at(i);
  }
  int ans=1;
  double tem =abs(A,T-0.006*H.at(0));
  for(int i=1 ;i<N;i++){
    if(tem>abs(A,T-0.006*H.at(i))){
      tem=abs(A,T-0.006*H.at(i));
      ans=i+1;
    }
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException{
		int num;
		String[] str;
		List<Integer> list;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();

		num = Integer.parseInt(br.readLine());
		str = br.readLine().split(" ");

		list =  new ArrayList<Integer>(){
			{
				for(int i = 0; i < num; i++){
					add(Integer.parseInt(str[i]));
				}
			}
		};

		Collections.reverse(list);
		for(int i: list){
			builder.append(String.valueOf(i + " "));
		}
		builder.delete(builder.length() - 1, builder.length());

		System.out.println(builder);
		br.close();
	}
}

Measured memory_bytes: 24492
<?php
$num = 0;
// 標準入力を一行ずつ配列に代入します
while ($line = fgets(STDIN)) {
   $num += ceil((int)trim($line)/10) * 10;
   if(substr(trim($line), -1) != '0'){
     $rest[] = substr(trim($line), -1);
   }
}

$d = min($rest);

$t = 10;
if($d == 0)
{
  $t = 0;
}
echo $num-$t+$d;

Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, C;
  std::cin >> N >> C;
  vvl D = vv(C+1, C+1, 0, ll);
  vvl Cs = vv(N+1, N+1, 0, ll);
  for(int i=1;i<=C;i++) for(int j=1;j<=C;j++) std::cin >> D[i][j];
  for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) std::cin >> Cs[i][j];
  //%== 1 or 2 or 3 group
  std::vector<ll> one(C+1, 0), two(C+1, 0), three(C+1, 0);
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      if((i+j)%3==1) one[Cs[i][j]]++;
      else if((i+j)%3==2) two[Cs[i][j]]++;
      else three[Cs[i][j]]++;
    }
  }
  ll ans = 10000000000000, now;
  for(int i=1;i<=C;i++){
    for(int j=1;j<=C;j++){
      for(int k=1;k<=C;k++){
        now = 0;
        if(i==j || i==k || j == k) continue;
        for(int l=1;l<=C;l++) {
          now += one[l] * D[l][i];
          now += two[l] * D[l][j];
          now += three[l] * D[l][k];
        }
        ans = (ans>now?now:ans);
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 2304
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=2009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

 struct MinQ
{ int window;deque<pair<int,int> >dq;
  MinQ(int x){window=x;}
  void push(int idx,int x)
  {while(!dq.empty() && dq.back().first>=x)dq.pop_back();dq.push_back(make_pair(x,idx));}
  int qry(int idx){while(idx-dq.front().second>=window)dq.pop_front();return dq.front().first;}
};

int n,x;
int a[2*M+7];
int yo(int d)
{   int ret=d*x;
    d++;
    MinQ Magic(d);
    f(i,1,d-1)
    {
        Magic.push(i,a[i]);
    }
    f(i,d,n+d-1)
    {
        Magic.push(i,a[i]);
        int mn=Magic.qry(i);
        ret+=mn;
    }
    return ret;
}
 main()

{
    fast
    cin>>n>>x;
    f(i,1,n)cin>>a[i],a[n+i]=a[i];
    int ses=inf;
    f(i,0,n-1)
    {
        ses=min(ses,yo(i));
    }
    cout<<ses<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	long long a,b,c;
	cin>>a>>b>>c;
	long long n=b*c;
	if(n>=a)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3576
N = int(input())
S = []
for i in range(N):
    S.append(int(input()))
S.sort()
ans = sum(S)

if ans%10!=0:
    print(ans)
else:
    d = ans
    for val in S:
        if val%10!=0:
            d = val
            break
    if d!=ans:
        print(ans - d)
    else:
        print(0)

Measured memory_bytes: 3060
n = int(input())
a = [int(input()) for i in range(n)]
ma = max(a)
b = [x for x in a]
b.remove(ma)
ma2 = max(b)
if a.count(ma) > 1:
    for i in range(n):
        print(ma)
else:
    for i in range(n):
        if a[i] == ma:
            print(ma2)
        else:
            print(ma)

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

int n,m;
char a[55][55],b[55][55];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			cin>>a[i][j];
	for(int i=0;i<m;++i)
		for(int j=0;j<m;++j)
			cin>>b[i][j];
	for(int i=0;i<=n-m;++i)
		for(int j=0;j<=n-m;++j){
			bool ok=true;
			for(int x=0;x<m;++x)
				for(int y=0;y<m;++y)
					ok&=a[i+x][j+y]==b[x][y];
			if(ok)
				return puts("Yes\n"),0;
		}
	cout<<"No\n";
}




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


def solve(X: int):
    n500 = X // 500
    n5 = (X - 500 * n500) // 5
    print(n500*1000 + n5 * 5)
    return


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

if __name__ == '__main__':
    main()


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 998244353;

int main(){
  int n;
  cin >> n;
  vi d(n,0);
  int mx=0;
  REP(i,n){
    int x;
    cin >> x;
    if(i==0 && x != 0){
      cout << 0 << endl;
      return 0;
    }
    d[x]++;
    chmax(mx,x);

  }
  ll ans=1;

  if(d[0] != 1){
    cout << 0 << endl;
    return 0;
  }
  REP(i,mx+1){
    ll tmp=1;
    REP(j,d[i+1]){
      tmp *= d[i];
      tmp %= MOD;
    }
    ans *= tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 4000000000000000037
#define INF 1000000007
//#define MOD 1000000007
#define PI (acos(-1))
#define EPS 1e(-9);
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,M; cin>>N>>M;

    ll A[N],B[N+1];

    B[0]=0;

    rep(i,N){
        cin>>A[i];
        B[i+1]=B[i]+A[i];
        B[i+1]%=M;
    }

    unordered_map<ll,ll> ct;
    rep(i,N+1){
       ++ct[B[i]]; 
    }

    ll ans=0;

    for(auto x:ct){
        ll now=x.second;
        ans+=(now*(now-1))/2;
    }

    cout<< ans<<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

int main() {
  string A,B;
  cin >> A >> B;
  int S = 0;
  if (A.size() > B.size()) {
    S = A.size();
  }
  else {
    S = B.size();
  }
  for (int i = 0;i < S; i++) {
    if (A.size() < S) {
      if (i == S-1) {
      cout << B.at(i);
      break;
      }
    }
    else if (B.size() < S) {
      if (i == S-1) {
        cout << A.at(i);
        break;
      }
    }
    cout << A.at(i) <<B.at(i);
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double PI=acos(-1);
int n,L,t[3010];
double x[3010],y[3010];
int main()
{
	scanf("%d%d",&n,&L);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&t[i]);
//		x[i]=cos(PI*2*t/L);
//		y[i]=sin(PI*2*t/L);
	}
	double ansx=0,ansy=0;
	double ang=PI/L;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int mid=(t[i]+t[j]);
//			if(abs(t[i]-t[j])>L/2)mid=(mid+L)%(2*L);
			double midx=cos(ang*mid+PI),midy=sin(ang*mid+PI);
			ansx+=midx*(j-i-1);ansy+=midy*(j-i-1);
			midx=cos(ang*mid),midy=sin(ang*mid);
			ansx+=midx*(n-2-(j-i-1));ansy+=midy*(n-2-(j-i-1));
//			double midx=(x[i]+x[j])/2,midy=(y[i]+y[j])/2;
//			ansx+=midx*3;ansy+=midy*3;
		}
	}
	printf("%.15lf %.15lf\n",ansx*6.0/(1ll*n*(n-1)*(n-2)),ansy*6.0/(1ll*n*(n-1)*(n-2)));
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

/***********************************************************************
重さ1の辺によって構成されるグラフの最短経路問題に帰着されるので、幅優先探索でいける。
幅優先探索はキューを用いて実現する。キューの備える性質はFirstInFirstOut。お尻から
入れて、頭から出す。キューの実装の概要は以下の通り。

queue<T> q;
q.push(初期状態);
while(!q.empty()) {
	T now = q.front();
	q.pop();
	状態nowに対する操作
	for(int i = 0; i < 次の状態の個数; i++) {
		T next = i番目の次の状態;
		if(nextが訪問済みかを確認) {
			q.push(next);
		}
	}
}

************************************************************************/

// Queue
type pos struct {
	x int
	y int
	movecounter int // マス目(0, 0)から何回移動したかを記録
}

type queue struct {
	container []*pos
}

func NewQueue() *queue  {
	return &queue{make([]*pos, 0)}
}

func (q *queue) push(s *pos) *pos {
	// posへのポインタを引数にqueueのcontainerの末尾に加えて、その加えられたposのポインタを返す
	q.container = append(q.container, s)
	return s
}

func (q *queue) pop() *pos {
	// queueの先頭要素を弾く
	s := q.container[0]
	q.container = q.container[1:]
	return s
}

func (q *queue) isEmpty() bool {
	return len(q.container) == 0
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	maze := make([]string, h)
	for i := range maze {
		fmt.Scan(&maze[i])
	}

	// 訪問記録
	visited := make([][]bool, h)
	for i := range visited {
		visited[i] = make([]bool, w)
	}
	visited[0][0] = true

	// 移動方向
	dx := []int{-1, 0, 1, 0}
	dy := []int{0, -1, 0, 1}

	//fmt.Println(maze)
	//fmt.Println(visited)

	// '#'のマス目の数を数える
	s := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if []rune(maze[i])[j] == '#' {
				s++
			}
		}
	}

	// 幅優先探索
	queue := NewQueue()
	queue.push(&pos{x:0, y:0, movecounter:0})
	var p *pos

	for !queue.isEmpty() {

		// 現在のマス目
		p = queue.pop()

		// 現在のマス目がゴールならループを抜ける
		if p.x == w-1 && p.y == h-1 {
			break
		}

		// 現在のマス目からできる全ての動きについて調べて、到達可能なマス目をqueueにpushする
		for i := 0; i < 4; i++ {
			x := p.x + dx[i]
			y := p.y + dy[i]
			if 0 <= x && x < w && 0 <= y && y < h {
				if visited[y][x] == false && []rune(maze[y])[x] == '.' {
					visited[y][x] = true
					queue.push(&pos{x: x, y: y, movecounter: p.movecounter + 1})
				}
			}
		}
	}
	// 上記のfor文を回りきった暁には各posのmovecounterには何回移動すればそのマスにたどり着くかが記載されているはず
	// pは一番最後に探索されたposに対するポインタかゴールのどちらか

	if !(p.x == w-1 && p.y == h-1) {
		fmt.Println(-1)
	} else {
		fmt.Println(h*w - s - (p.movecounter + 1))
	}
}


Measured memory_bytes: 2048
import math

mod = 10**9 + 7

n = int(input())
x = list(map(int,input().split()))
dis = [x[i]-x[i-1] for i in range(1,n)]
f = (math.factorial(n-1))%mod
def modinv(a, mod=mod):
    return pow(a, mod-2, mod)

count = 0
suminv = 0
for i in range(1,n):
    suminv += modinv(i)
    suminv %= mod
    count += dis[i-1]*suminv
    count %= mod
count = (count*f)%mod

print(int(count))

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int h,w,n;
    cin >> h >> w >> n;
    map <int,int> x,y;
    pair <int,int> ar[n];
    int mx=0,my=0;
    for(int i=0;i<n;i++){
    	int u,v;
    	cin >> u >> v;
    	ar[i]={u,v};
    	x[u]++,y[v]++;
    	mx=max(mx,x[u]),my=max(my,y[v]);
    }
    set <int> a,b;
    for(auto [key,val]:x){
    	if(val==mx)a.insert(key);
    }
    for(auto [key,val]:y){
    	if(val==my)b.insert(key);
    }
    int cnt=0;
    for(int i=0;i<n;i++){
    	auto [u,v]=ar[i];
    	if(a.count(u) and b.count(v))
    		cnt++;
    }
    int ans=mx+my;
    if(cnt==(int)a.size()*(int)b.size())
    	ans--;
    cout << ans;
}

Measured memory_bytes: 73936
#include <iostream>
#include <stack>

using namespace std;

int main() {
	int n;
	stack<int> s;
	while (cin >> n) {
		if (n == 0) {
			cout << s.top() << endl;
			s.pop();
		}
		else {
			s.push(n);
		}
	}
	return 0;
}

Measured memory_bytes: 2984
/**
 *    author: gxfireball       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;

void solve(){
    int n,cnt=0,r=0,w=0;
    cin>>n;
    string str;
    cin>>str;
    for(int i=0; i<n;++i){
        if(str[i] == 'R') r++;
        if(str[i] == 'W') w++;
    }
    for(int i=0;i<r;++i) if(str[i] == 'W') cnt++;
    cout<<min(min(r,w),cnt);
}

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



Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

ll dp[11000];//残り体力：最小コスト

int main(){cout<<fixed<<setprecision(20);
		   //dp
           ll h,n;
           cin>>h>>n;
           vll a(n),b(n);
           rep(i,0,n){
             cin>>a[i]>>b[i];
           }
           rep(i,1,h+1)dp[i]=INF;
           
           /////////
           rep(i,1,h+1){
             rep(j,0,n){
              if(i-a[j]>=0)chmin(dp[i],dp[i-a[j]]+b[j]);
               else chmin(dp[i],b[j]);
             }
           }
           cout<<dp[h]<<endl;
}

Measured memory_bytes: 3668
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
	char S[11];
	char* s;
	int t;

	scanf("%s",&S);

	s = strtok(S, "/");
	t = atoi(s);
	if((int)t<2019){
		printf("Heisei\n");
	}else if((int)t>2019){
		printf("TBD\n");
	}else{
		s = strtok(NULL, "/");
		t = atoi(s);
		if((int)t>04){
			printf("TBD\n");
		}else{
			printf("Heisei\n");
		}
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int y[101],a,b,c,x,aa,z;
int main(){
	scanf("%d %d %d",&a,&b,&c);
	while (1){
		aa+=a;
		z=aa%b;
		if (z==c){
			printf("YES\n");
			return 0;
		}
		if (y[z]==1) break;
		y[z]=1;
	}
	printf("NO\n");
	return 0;
} 

Measured memory_bytes: 256
using System;
using System.Linq;

class Plogram
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        int min = int.MaxValue;

        for (int i = 0; i < N - 1; i++)
        {
            if(min > Gcd(A[i],A[i+1]))
            {
                min = Gcd(A[i], A[i + 1]);
            }
        }

        Console.WriteLine(min);
    }

    static public int Gcd(int a, int b)
    {
        while( b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
}

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

using ll = long long;

constexpr ll INF = 1e18;

map<string, set<pair<ll, ll>>> arr;
map<string, ll> arr_size;

bool program(string const& s, int& p);
bool declaration(string const& s, int& p);
bool assignment(string const& s, int& p);
ll expression(string const& s, int& p);
string array_name(string const& s, int& p);
ll number(string const& s, int& p);

bool program(string const& s, int& p) {
    if(s.find('=') == string::npos) {
        return declaration(s, p);
    } else {
        return assignment(s, p);
    }
}

bool declaration(string const& s, int& p) {
    string name = array_name(s, p);
    arr_size[name] = number(s, ++p);
    return false;
}

bool assignment(string const& s, int& p) {
    string name = array_name(s, p);
    ll idx = expression(s, ++p);
    if(arr_size[name] <= idx) {
        return true;
    }
    p += 2; // equal
    ll val = expression(s, p);
    if(val == INF) {
        return true;
    }
    auto it = arr[name].lower_bound(make_pair(idx, -1));
    if(it != arr[name].end() && it->first == idx) {
        arr[name].erase(it);
    }
    arr[name].insert(make_pair(idx, val));
    return false;
}

ll expression(string const& s, int& p) {
    if(isdigit(s[p])) {
        return number(s, p);
    }
    string name = array_name(s, p);
    ll idx = expression(s, ++p);
    if(arr_size[name] <= idx) {
        return INF;
    }
    auto it = arr[name].lower_bound(make_pair(idx, -1));
    if(it == arr[name].end() || it->first != idx) {
        return INF;
    }
    ++p;
    return it->second;
}

string array_name(string const& s, int& p) {
    string res;
    while(isalpha(s[p])) {
        res += s[p++];
    }
    return res;
}

ll number(string const& s, int& p) {
    ll res = 0;
    while(isdigit(s[p])) {
        res *= 10;
        res += s[p++] - '0';
    }
    return res;
}

int main() {
    string s;
    vector<string> v;
    while(getline(cin, s)) {
        if(s[0] == '.') {
            if(v.size() == 0) {
                break;
            }
            int res = 0;
            for(int i=0; i<v.size(); ++i) {
                int p = 0;
                if(program(v[i], p)) {
                    res = i+1;
                    break;
                }
            }
            cout << res << endl;
            v.clear();
            arr.clear();
            arr_size.clear();
            continue;
        }
        v.push_back(move(s));
    }
}

Measured memory_bytes: 3324
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    long A[] =new long[N];
    long ans =0;
    long t =0;
    for(int i=0;i<N;i++){
      A[i]=sc.nextLong();
      t=Math.max(t,A[i]);
      ans =ans +t-A[i];}
    System.out.println(ans);    
  }
}

Measured memory_bytes: 62220
from collections import Counter
H, W, M = map(int, input().split())
YX = [tuple(map(int, input().split())) for i in range(M)]
yx_set = set(YX)

xc = Counter()
yc = Counter()

for y, x in YX:
    yc[y] += 1
    xc[x] += 1

ans = 0
for y, x in YX:
    ans = max(ans, yc[y] + xc[x] - 1)

xmc = xc.most_common()
ymc = yc.most_common()
xmx = xmc[0][1]
ymx = ymc[0][1]
for xk, xv in xmc:
    if xv < xmx:
        break
    for yk, yv in ymc:
        if yv < ymx:
            break
        if (yk, xk) in yx_set:
            continue
        ans = max(ans, yv + xv)
        break
print(ans)


Measured memory_bytes: 225748