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

signed main()
{
  int n; cin >> n;
  vector<int> vec(n);
  for(int i = 0; i<n; ++i){
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  int sumA = 0,sumB = 0;

  for(int i = 0; i<n; ++i){
    if(i%2==0){
      sumA += vec[i];
    }else{
      sumB += vec[i];
    }
  }

  cout << (sumA-sumB) << "\n";
}

Measured memory_bytes: 3616
fun main(args: Array<String>) {
    val (h, n) = readIntegerList()
    val abArray = Array(n) {
        val (a, b) = readIntegerList()
        Pair(a, b)
    }

    val dp = Array(h + 1) { Int.MAX_VALUE / 3 }
    dp[0] = 0
    for (ab in abArray) {
        for (i in dp.indices) {
            val tmp = Math.min(i + ab.first, h)
            dp[tmp] = Math.min(dp[tmp], dp[i] + ab.second)
        }
    }
    println(dp[h])
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 73364
n = int(input())
l = list(map(int, input().split()))
cnt = 0
for i in range(len(l)):
    for j in range(i, len(l)):
        for k in range(j, len(l)):
            if i != j and j != k and k != i:
                if i <= j <= k <= n:
                    if l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
                        if l[i]+l[j] > l[k] and l[j]+l[k] > l[i] and l[k]+l[i] > l[j]:
                            cnt +=1
print(cnt)

Measured memory_bytes: 9196
import java.util.Scanner;

// A - Remaining Balls
// https://atcoder.jp/contests/abc154/tasks/abc154_a
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        String T = scanner.next();
        int A = Integer.parseInt(scanner.next());
        int B = Integer.parseInt(scanner.next());
        String U = scanner.next();
        scanner.close();

        if (S.contains(U)) {
            A--;
        }
        if (T.contains(U)) {
            B--;
        }
        System.out.println(A + " " + B);
    }
}


Measured memory_bytes: 23764
#                         author:  kagemeka 
#                         created: 2019-11-07 00:57:57(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    a, b, c, d = (int(x) for x in sys.stdin.read().split())
    train_fare = a if a <= b else b
    bus_fare = c if c <= d else d
    print(train_fare + bus_fare)



if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include<stdio.h>
int main(){
    int i,d=0,k=0,a=0,b=0,c=0;
    scanf("%d",&k);
    scanf("%d%d",&a,&b);
    
    for(i=1;d<1000;i++)
    {
        d=k*i;
      if(a<=d&&d<=b)c++;
        
    }
    if(c>=1)printf("OK");
    else printf("NG");   

   return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	
	if (K >= N) {
		cout << X * N << endl;
	}
	else if (K < N) {
		cout << X * K + Y * (N - K);
	}
	return 0;
}

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

int main(){
  int N,count=0;
  string s;
  cin >> N >>s;
  for(int i=0;i<N-1;i++){
    if(s.at(i)!=s.at(i+1))count++;
  }
  cout << count +1 <<endl;
}

Measured memory_bytes: 512
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]

scount = Counter(s)
scsort = scount.most_common()
x = scsort[0][1]
anss = []
for i in scsort:
    if i[1] != x:
        break
    anss.append(i[0])

for i in sorted(anss):
    print(i)

Measured memory_bytes: 49404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
using PII = pair<int,int>;
using III = tuple<int,int,int>;
using EDGE = vector<III>;
using NODE = vector<PII>;
using TREE = vector<NODE>;

void v_print(vi &v){for(auto e:v){printf("%d,",e);}puts("");}//

void vln_print(vl &v, int n){
	rpz(i,n){
		printf("%lld,",v[i]);
	}puts("");
}//

void e_print(EDGE &v){for(auto e:v){
	printf("%d %d %d\n",get<0>(e),get<1>(e),get<2>(e));
	}puts("-");}//

#define V_MAX 100000
vi visited(V_MAX+1);
vl dist(V_MAX+1);

void dfs(TREE &T, int p, ll w){
	if(visited[p]) return;
	visited[p] = true;
	dist[p] = w;
	// printf("p %d\n", p);
	for(auto cw:T[p]){
		int np,nw; tie(np,nw) = cw;
		dfs(T, np, w+nw);
	}
}

vi solve(int N, EDGE &E){
	// printf("N %d\n",N);e_print(E);//

	TREE T(N+1, NODE());
	for(auto e:E){
		int u,v,w;
		tie(u,v,w) = e;
		T[u].emplace_back(v,w);
		T[v].emplace_back(u,w);
	}

	// rp(p,0,T.size()){printf("%d) ",p);//
	// for(auto c:T[p]){printf("(%d %d) ",c.first,c.second);}puts("");}puts("--");//

	dfs(T, 1, 0);
	// vln_print(dist, N+1);///

	vi ans(N, 0);
	rpz(i,N) ans[i] = dist[i+1]%2;
	return ans;
}

int main(){
	int N; cin>>N;
	EDGE E;
	rpz(i,N-1){
		int u,v,w;
		cin>>u>>v>>w;
		E.emplace_back(u,v,w);
	}
	for(auto a:solve(N, E)) cout << a <<endl;
}


Measured memory_bytes: 10228
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "
const int MXN = 104;
char in[MXN][MXN];
int dp[MXN][MXN];

bool moge[MXN][MXN];

int main()
{
  int n, m;
  scanf("%d%d", &n, &m);
  FOR(i, 1, n)
    FOR(j, 1, m)
      {
      scanf(" %c", &in[i][j]);
      }
  FOR(i, 0, n+1)
    FOR(j, 0, m+1)
      dp[i][j] = 1e9;

  dp[0][1] = 0;
  in[0][1] = '.';

  in[n+1][m] = '.';
  FOR(i, 0, n)
    FOR(j, 1, m)
      {
      if(i == 0 && j != 1)continue;

      if(in[i][j] == '.')
        {
        if(i && in[i-1][j] == '.')mini(dp[i][j], dp[i-1][j]);
        if(in[i][j-1] == '.')mini(dp[i][j], dp[i][j-1]);

        if(in[i+1][j] == '#')moge[i+1][j] = 1;
        if(in[i][j+1] == '#')moge[i][j+1] = 1;
        FOR(i2, i, n)
          FOR(j2, j, m)
            {
            if(in[i2][j2] == '#')moge[i2][j2] |= moge[i2-1][j2] | moge[i2][j2-1];
            }

        FOR(i2, i, n+1)
          FOR(j2, j, m)
            {
            if(in[i2][j2] == '.' && (moge[i2][j2-1] || (i2 && moge[i2-1][j2])))
              mini(dp[i2][j2], dp[i][j]+1);

            }

        FOR(i2, i, n)
          FOR(j2, j, m)moge[i2][j2] = 0;
        }
      }
  if(in[n][m] == '.')mini(dp[n+1][m], dp[n][m]);

/*
  FOR(i, 1, n)
    {
    FOR(j, 1, n)
      cerr << (dp[i][j] > 1e8 ? 9 : dp[i][j]) << " ";
    cerr << endl;
    }
*/
  printf("%d\n", dp[n+1][m]);
}


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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   string s;
   cin>>s;

   for(int i=0; i<s.size(); ++i){
      if(i % 2 == 0 && s[i] != 'h'){
         cout<<"No"<<'\n';
         return 0;
      }else if(i % 2 == 1 && s[i] != 'i'){
         cout<<"No"<<'\n';
         return 0;
      }
   }

   if(s.size() % 2 != 0){
      cout<<"No"<<'\n';
      return 0;
   }
   cout<<"Yes"<<'\n';
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <string>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

#define MAX_T 50
#define MAX_P 10

struct team{
	int fails[MAX_P+1];
	int ac, t, id;
};

bool sorter(const team &t1, const team &t2){
	if(t1.ac == t2.ac){
		if(t1.t == t2.t){
			return t1.id > t2.id;
		}else{
			return t1.t < t2.t;
		}
	} else {
		return t1.ac > t2.ac;
	}
}

int M, T, P, R;

team teams[MAX_T+1];

int main(){
	while(cin>>M>>T>>P>>R, M|T|P|R){
		vector<team> teams(T);

		rep(i,T){
			teams[i].ac = teams[i].t = 0;
			teams[i].id = i+1;
			rep(j,P) teams[i].fails[j] = 0;
		}

		rep(i,R){
			int m,t,p,j;
			cin>>m>>t>>p>>j;
			t--; p--;
			if(j == 0){
				teams[t].ac++;
				teams[t].t += m+teams[t].fails[p]*20;
			}else{
				teams[t].fails[p]++;
			}
		}
		sort(all(teams), sorter);

		printf("%d", teams[0].id);
		repl(i,1,T){
			if(teams[i-1].ac==teams[i].ac && teams[i-1].t==teams[i].t)
				printf("=");
			else
				printf(",");
			printf("%d", teams[i].id);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1204
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc	=	new Scanner(System.in);
		int m, f, r, total;

		while(true) {
			m	=	sc.nextInt();
			f	=	sc.nextInt();
			r	=	sc.nextInt();

			total = m + f;

			if			(m == -1 && f == -1 && r == -1) {
				break;
			} else if	(m == -1 || f == -1 || total < 30) {
				System.out.println("F");
			} else if	(total >= 80) {
				System.out.println("A");
			} else if	(total >= 65 && total < 80) {
				System.out.println("B");
			} else if	(total >= 50 && total < 65) {
				System.out.println("C");
			} else if	(total >= 30 && total < 50) {
				if 		(r >= 50) {
					System.out.println("C");
				} else {
					System.out.println("D");
				}
			}
		}

		sc.close();

	}
}



Measured memory_bytes: 26212
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    a, b, c, d = mi()
    print(max(a*c, a*d, b*c, b*d))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9564
//Created Time:2020年05月12日 星期二 20时00分16秒
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 2000006

using namespace std;

const int mod = 1e9 + 7;

int x1, x2, x3, x4, x5, x6;
int y1, y2, y3, y4, y5, y6;
int fac[N], ifac[N];

int C(int x, int y){
	if(x < y || x < 0 || y < 0) return 0;
	return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}

int way(int x1, int y1, int x2, int y2){
	int x = abs(x1 - x2), y = abs(y1 - y2);
	return C(x + y, x);
}

int main(){
	cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6;
	cin >> y1 >> y2 >> y3 >> y4 >> y5 >> y6;
	fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
	for(int i = 1; i <= 2000000; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
	for(int i = 2; i <= 2000000; ++i) ifac[i] = 1ll * (mod - mod / i) * ifac[mod % i] % mod;
	for(int i = 1; i <= 2000000; ++i) ifac[i] = 1ll * ifac[i] * ifac[i - 1] % mod;
	int res = 0;
	for(int x = x3, y = y4; x <= x4; y == y3 ? ++x : --y){
		int X, Y;
		if(x == x3 && y == y3) X = x, Y = y;
		else if(x == x3) X = x - 1, Y = y;
		else X = x, Y = y - 1;
		int tmp1 = (way(X, Y, x1 - 1, y1 - 1) + way(X, Y, x2, y2)) % mod;
		int tmp2 = (way(X, Y, x1 - 1, y2) + way(X, Y, x2, y1 - 1)) % mod;
		int tmp3 = (way(x, y, x6 + 1, y6 + 1) + way(x, y, x5, y5)) % mod;
		int tmp4 = (way(x, y, x5, y6 + 1) + way(x, y, x6 + 1, y5)) % mod;
		(res += mod - 1ll * (tmp1 - tmp2 + mod) * (tmp3 - tmp4 + mod) % mod * (x + y) % mod) %= mod;
	}
	for(int x = x3, y = y4; y >= y3; x == x4 ? --y : ++x){
		int X, Y;
		if(x == x4 && y == y4) X = x, Y = y;
		else if(y == y4) X = x, Y = y + 1;
		else X = x + 1, Y = y;
		int tmp1 = (way(x, y, x1 - 1, y1 - 1) + way(x, y, x2, y2)) % mod;
		int tmp2 = (way(x, y, x1 - 1, y2) + way(x, y, x2, y1 - 1)) % mod;
		int tmp3 = (way(X, Y, x6 + 1, y6 + 1) + way(X, Y, x5, y5)) % mod;
		int tmp4 = (way(X, Y, x5, y6 + 1) + way(X, Y, x6 + 1, y5)) % mod;
		(res += 1ll * (tmp1 - tmp2 + mod) * (tmp3 - tmp4 + mod) % mod * (x + y + 1) % mod) %= mod;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int a,b;
	cin >>a>>b;
	int sum=1;
	if(b==1) {
		printf("0");
	}
	else{
		int i;
		for(i=1;sum < b;i++){
			sum=sum+a-1;
		}
		cout<<i-1<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

long long euler_phi (long long n) {
	long long ret = n;
	for (long long i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			ret -= (ret / i);
			while (n % i == 0) {
				n /= i;
			}
		}
	}
	if (n > 1) ret -= (ret / n);
	return ret;
}

int main() {
	long long n;
	std::cin >> n;
	
	std::cout << euler_phi(n) << '\n';
	
	return 0;
}


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

#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)

void recursive_debug(string) { cerr << endl; }

template<class H,class... T>
void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}

template<class T,class U>
ostream& operator<<(ostream& ost, const pair<T,U> &p) {
    ost << "(" << p.first << ", " << p.second << ")";
    return ost;
}

template<class T>
ostream& operator<<(ostream &ost, const vector<T> &v) {
    ost << "[";
    for(T t : v) ost << t << ",";
    ost << "]";
    return ost;
}

struct State {
    ll score;
    vector<int> types;
    bool operator<(const State& rhs) const {
        return (score < rhs.score);
    }
    bool operator>(const State& rhs) const {
        return (score > rhs.score);
    }
};


int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int D, M = 26;
    cin >> D;
    vector<ll> c(M);
    rep(i,M) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(M));
    rep(d,D) rep(i,M) cin >> s[d][i];

    set<State> cur_states = {{0, {}}};
    size_t SIZE = 1000;

    rep(d,D) {
        set<State> nxt_states;
        for (auto &cur_itr : cur_states) {
            State state = cur_itr;
            vector<int> last(M, -1);
            rep(i,state.types.size()) {
                last[state.types[i]] = i;
            }
            ll minus_score = 0;
            rep(i,M) {
                minus_score -= c[i] * (d - last[i]);
            }
            rep(i,M) {
                State nxt_state;
                nxt_state.score = state.score + s[d][i] + minus_score + c[i] * (d - last[i]);
                nxt_state.types = state.types;
                nxt_state.types.push_back(i);
                
                nxt_states.insert(nxt_state);
                if (nxt_states.size() > SIZE) {
                    nxt_states.erase(nxt_states.begin());
                }
            }
        }

        cur_states = std::move(nxt_states);
    }

    for (int t : cur_states.begin()->types) {
        cout << t+1 << endl;
    }
    // debug(cur_states[0].score);

    return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  int n;
  cin>>n;
  int a,b;
  cin>>a>>b;
  int ans=0;
  for(int i=1;i<=n;i++){
  int count=0,q=i;
  while(q>0){
  count+=q%10;
  q/=10;
  }
    if(count<=b&&a<=count){
  ans+=i;
    //cout<<"i=="<<i<<endl;
    }
  }

cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int n,i,max=1;
  scanf("%d",&n);
  for(i=1;i<n;i++)
  {
    if(i*i>n)
    {
      max=(i-1)*(i-1);
      break;
    }
  }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
  

    int n, m;
    int ans = -1e9;
    int in[200000];

void maxSerch(int);


int main(void) {
  int i;
 
    scanf("%d", &n);
 
    for (i = 0; i < n; i++) {
        scanf("%d", &in[i]);
    }
 
    m = in[0];
 
    for (i = 1; i < n; i++) {
      maxSerch(i);
    }
    printf("%d\n", ans);
 
    return 0;
    }

void maxSerch(int i){


        if (ans < (in[i] - m)) {
            ans = in[i] - m;
        }
 
        if (in[i] < m) {
            m = in[i];
        }
 
    }

Measured memory_bytes: 1376
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

score = [k-q for _ in range(n)]

for i in range(q):
    score[a[i]-1] += 1

for i in range(n):
    if score[i] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 11796
import numpy as np

N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))

res = 0

for i in range(N):
    A = np.array(list(map(int, input().split())))
    if sum(A*B) + C > 0:
        res += 1

print(res)



Measured memory_bytes: 21540
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int N;
    cin >> N;
    vector<int> as(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }
    sort(as.begin(), as.end());

    cout << as.back() - as[0] << endl;

    return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF INT_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define int ll

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

  int N;
  cin>>N;
  vector<string>S(N);
  for(int i=0;i<N;i++)cin>>S[i];
  int sum=0;
  for(int k=0;k<N;k++){
    bool ok=true;
    for(int y=0;y<N;y++){
      for(int x=0;x<N;x++){
        if(S[(y+k)%N][x]!=S[(x+k)%N][y])ok=false;
      }
    }
    sum+=ok;
  }
  if(N==1)cout<<1<<endl;
  else cout<<sum*N<<endl;
  return 0;
}


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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

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

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


int main(){
  int a, b; cin>> a >> b;
  int cnt = 0;
  int now = 1;
  while(now < b){
    now = now + a -1;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

struct edge {
    ll from;
    ll to;
    ll cost;
};

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N, M;
    cin >> N >> M;
    mat d(N, vec(N, inf));
    vector<edge> e(M);
    Rep (i, N) d[i][i] = 0;
    Rep (i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        e[i] = edge{a, b, c};
        d[a][b] = c;
        d[b][a] = c;
    }

    Rep (k, N) Rep (i, N) Rep (j, N) chmin(d[i][j], d[i][k] + d[k][j]);

    ll ans = 0;
    Rep (i, M) {
        ll a = e[i].from, b = e[i].to, c = e[i].cost;
        if (d[a][b] != c) ans++;
    }

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

Measured memory_bytes: 384
a,b,x = gets.chomp.split(" ").map{|i|i = i.to_i}

#double radian = Math.atan2(y2 - y,x2 - x);
#return radian;
#double degree = arcLineMargineRadian * 180 / Math.PI;
# 台形になるとき
if ( x > ((a.to_f * a)*b)/2 )
  xx =((x.to_f)*2)/a
  z=(xx/a-b)
  puts (Math.atan2((b-z),a) * 180.to_f)/ Math::PI
# 三角形となるとき
else
  xx =( (x.to_f)*2)/a
  z=xx/b
  puts (Math.atan2(b,z) * 180.to_f)/ Math::PI
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vdebug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    int n;
    ll f[20][110], p[20][110];

    cin >> n;
    rep(i, n){
        rep(j, 10){
            cin >> f[j][i];
        }
    }
    rep(i, n){
        reps(j, 0, 10){
            cin >> p[j][i];
        }
    }

    ll res = -inf;
    for(int bit=1; bit < (1<<10); bit++){
        ll tmp = 0;
        rep(i, n){
            ll cnt = 0;
            for(int j=0; j<10; j++){
                if((bit & 1<<j) && f[j][i]) cnt++;
            }
            tmp += p[cnt][i];
        }
        chmax(res, tmp);
    }

    cout << res << endl;

    return 0;
}


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

int main() {
    int n,ans = 1;
    cin >> n;
    vector<int>a(n);
    for(int i = 0;i<n;i++)cin >> a[i];
    for(int i = 1;i<n;i++){
        bool flag = true;
        for(int j = 0;j<i;j++){
            if(a[j] > a[i])flag = false;
        }
      	if(flag)ans++;
    }
    cout << ans;
    return 0;
}

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

const int N = 200010;

typedef long long LL;

int fa[N], p[N], c0[N], c1[N];

struct node {

int u, c0, c1;

bool operator < (const node &b) const {
    LL t1 = (LL)c1 * b.c0, t2 = (LL)c0 * b.c1;
    if (t1 != t2) return t1 < t2;
    return u < b.u;
}

};

int find(int x) {
    return x == fa[x] ? x : fa[x] = find(fa[x]);
}

set<node> s;

int main() {
    int n; scanf("%d", &n);
    for (int i = 2; i <= n; i++) scanf("%d", &p[i]);
    for (int i = 1, a; i <= n; i++) {
        scanf("%d", &a), c0[i] = a == 0, c1[i] = a == 1, fa[i] = i;
        if (i != 1) s.insert((node){i, c0[i], c1[i]});
    }
    LL res = 0;
    while (!s.empty()) {
        int u = s.begin()->u; s.erase(s.begin());
        int t = find(p[u]); 
        if (t != 1) s.erase((node){t, c0[t], c1[t]});
        res += (LL)c1[t] * c0[u], c1[t] += c1[u], c0[t] += c0[u];
        fa[u] = t;
        if (t != 1) s.insert((node){t, c0[t], c1[t]});
    }
    printf("%lld\n", res);
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
const int N=405;
int a,b,c,d,sd[N],n,h,Map[N][N],vis[N],ans=1,Flag;
void dfs(int x){
	if (!vis[x]||!ans)return;
	vis[x]=0;
	if (x>h&&sd[x]<0)ans=0;
	if (x<=h&&sd[x]>0)ans=0;
	if (sd[x])Flag=1;
	for (int i=1;i<=h*2;i++)
		if (Map[x][i])dfs(i);
}
int main(){
	scanf("%d%d",&n,&h);
	for (int i=1;i<=n;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		a=c?-c+h+1:a+h;b=d?d+h:-b+h+1;
		sd[a]++;sd[b]--;
		Map[a][b]=Map[b][a]=vis[a]=vis[b]=1;
	}
	for (int i=1;i<=h*2&&ans;i++)
		if (vis[i]){
			Flag=0;dfs(i);
			if (!Flag)ans=0;
		}
	if (ans)puts("YES");
	else puts("NO");
}


Measured memory_bytes: 896
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		while(n != 0){
			int pm[] = new int[n];
			int pe[] = new int[n];
			int pj[] = new int[n];
			for(int i = 0 ; i<n ; i++){
				pm[i] = scan.nextInt();
				pe[i] = scan.nextInt();
				pj[i] = scan.nextInt();
			}
			for(int i = 0; i < n ; i++){
				if(pm[i] == 100 || pe[i] == 100 || pj[i] == 100 || (pm[i]+pe[i])/2 >= 90 || (pm[i]+pe[i]+pj[i])/3>= 80){
					System.out.println("A");
				}else if(((pm[i]+pe[i]+pj[i])/3>=70) || ((pm[i]+pe[i]+pj[i])/3 >= 50 && ((pm[i] >= 80) || (pe[i]) >= 80))){
					System.out.println("B");
				}else{
					System.out.println("C");
				}
			}
			n = scan.nextInt();
		}
	}
}

Measured memory_bytes: 28232
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

const int mod = 1e9 + 7;

using VL = vector<long long>;
using VVL = vector<VL>;

int n;
VVL connect;
VVL dp;  // ith nodeで j=0/1 -> 白/黒に対応

void dfs(int pos, int from) {
	// printf("dfs %2d -> %2d\n", from, pos);

	if (from != -1 && connect[pos].size() == 1) {
		return;
	}

	for (auto x: connect[pos]) {
		if (x == from) {
			continue;
		}

		dfs(x, pos);

		dp[pos][0] *= (dp[x][0] + dp[x][1]);
		dp[pos][0] %= mod;
		dp[pos][1] *= dp[x][0];
		dp[pos][1] %= mod;
	}
}

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

	connect.assign(n, {});
	dp.assign(n, VL(2, 1));  // 1で初期化

	int x, y;
	for (int i = 0; i < n-1; i++) {
		cin >> x >> y;
		x--;
		y--;
		connect[x].emplace_back(y);
		connect[y].emplace_back(x);
	}
	dfs(0, -1);

	long long ans = dp[0][0] + dp[0][1];
	ans %= mod;
	cout << ans << endl;

	// printf("-----\n");
	// for (int i = 0; i < n; i++) {
	// 	printf("i %d: %5lld %5lld\n", i, dp[i][0], dp[i][1]);
	// }
	return 0;
}


Measured memory_bytes: 16768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main() {
  int n, k;
  cin >> n >> k;
  vector<P> d(3);
  rep(i,3) cin >> d[i].first, d[i].second = i;
  string s;
  cin >> s;
  map<char, int> id;
  id['r'] = 2;
  id['s'] = 0;
  id['p'] = 1;

  sort(d.begin(), d.end(), greater<P>());
  vector<int> ok(n, 1);
  int res = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < n; j++) {
      if (ok[j]) {
        if (d[i].second == id[s[j]]) {
          if (j - k >= 0 && s[j - k] == s[j] && !ok[j - k]) continue;
          res += d[i].first;
          ok[j] = 0;
        }
      }
    }
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 3812
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#

# 数 値 読 み 込 み
a,b = [int(i) for i in input().split()]


if a <= 0 and b >=0:
  print("Zero")
elif a<0 and b<0 and (a-b)%2==0:
  print("Negative")
else:
  print("Positive")


Measured memory_bytes: 2940
#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<string>
#include<stack> 
#include<set>
#include<map>
#include<iostream>
#include<assert.h>
//#define Min(a,b,c) min((a),min((b),(c)))
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-11
#define pi 3.14159265359
#define pmm pair<map<int,int>*,map<int,LL>*>
typedef long long LL;
using namespace std;
const LL mod=1e9+7;
vector<int> v[100005]; 
int dfs(int n){
	vector<int> vv;
	for(vector<int>::iterator it=v[n].begin();it!=v[n].end();it++)
	{
		vv.pb(dfs(*it));
	}
	sort(vv.begin(),vv.end());
	int ma=0;
	for(int i=1;i<=vv.size();i++){
		ma=max(vv[vv.size()-i]+i,ma);
	}
	return ma;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		int a;
		scanf("%d",&a);
		v[a].pb(i);
	} 
	printf("%d\n",dfs(1));
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<set<pair<int,int64_t>>> G(N);
    rep(i,0,N-1){
        int u,v;
        int64_t w;
        cin>>u>>v>>w;

        G.at(u-1).emplace(v-1,w);
        G.at(v-1).emplace(u-1,w);
    }

    vector<int> Ans(N,-1);
    Ans.front()=0;
    queue<int> q;
    q.push(0);

    while(!q.empty()){
        int n=q.front();
        q.pop();

        for(auto g:G.at(n)){
            if(Ans.at(g.first)<0){
                if(g.second%2) Ans.at(g.first)=(!Ans.at(n));
                else Ans.at(g.first)=Ans.at(n);

                q.push(g.first);
            }
        }
    }

    for(auto ans:Ans) cout<<ans<<endl;
}

Measured memory_bytes: 18048
#include <bits/stdc++.h>
const int N = 4e1+5;
typedef long long i64;
int n; char A[N][N]; i64 f[N][N][N], g[N][N][N], h[N][N][N][N];
i64 F(int p, int l, int r); i64 G(int l, int m, int r); i64 H(int l1, int r1, int l2, int r2);
i64 F(int p, int l, int r)
{
    i64 &v = f[p][l][r]; if(~v) return v; v = 0;
    for(int i = l; i <= r; ++i) if(A[p][i] == '1') v += G(l, i, r);
    return v;
}
i64 G(int l, int m, int r)
{
    if(l == r) return 1; i64 &v = g[l][m][r]; if(~v) return v; v = 0;
    for(int i = l; i < m; i += 2) for(int j = r; j > m; j -= 2) v += H(l, i, j, r)*G(i+1, m, j-1);
    return v;
}
i64 H(int l1, int r1, int l2, int r2)
{
    i64 &v = h[l1][r1][l2][r2]; if(~v) return v; v = 0;
    for(int i = l1; i <= r1; ++i) v += G(l1, i, r1)*F(i, l2, r2);
    return v;
}
int main()
{
    scanf("%d", &n); for(int i = 0; i < n<<1; ++i) scanf("%s", A[i]);
    memset(f, -1, sizeof(f)), memset(g, -1, sizeof(g)), memset(h, -1, sizeof(h));
    printf("%lld\n", F(0, 1, n*2-1));
    return 0;
}

Measured memory_bytes: 37236
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt(), m=fsc.nextInt(), x=fsc.nextInt();
        int f=0, b=0;
        boolean read=false;
        int k=fsc.nextInt();
        int c=1;
        for(int i=0;i<=n;i++){
            if(k==i && i<x){
                f++;
                read=true;
            }
            else if(k==i && i>x){
                b++;
                read=true;
            }
            else{
                read=false;
            }
            if(read && c<m){
                k=fsc.nextInt();
                c++;
            }
        }
        fsc.close();
        System.out.println(Math.min(f, b));
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 21200
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws Exception {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		String s = in.readLine();
		
		System.out.println((s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) ? "Yes": "No");
	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  int N; cin >> N;
  vector <int> L(N);
  for (int i = 0; i < N; i++){
    cin >> L[i];
  }
  sort(L.begin(), L.end());

  int ans = 0;
  for (int i = 0; i < N - 2; i++){
    for (int j = i + 1; j < N - 1; j++){
      int A = L[i], B = L[j];
      for (int k = j + 1; k < N; k++){
        if (A + B <= L[k]){
          break;
        }else{
          ans++;
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (a > b || (n == 1 && a != b)) {
        cout << 0 << endl;
    } else {
        cout << b*(n-2) - a*(n-2) + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#define N 110000
inline char gc(){
	static char now[1<<16],*T,*S;
	if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
	return *S++;
}
inline int read(){
	int x=0;char ch=gc();
	while (ch<'0'||ch>'9') ch=gc();
	while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
	return x;
}
int n,a[N];
int main(){
//	freopen("addition.in","r",stdin);
	n=read();
	for (int i=1;i<=n;++i) a[i]=read();int ans1=0;
	for (int i=1;i<=n;++i) if (a[i]%2) ans1++;
	if (ans1%2) printf("NO");else printf("YES");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template<class T>
struct SegTree {
    int NN;
    T default_value;
    vector<T> data;

    T aggr(T a, T b) {
        return max(a, b);
    }

    SegTree(int N, T val) {
        default_value = val;
        NN = 1; while (NN < N) NN <<= 1;
        data = vector<T>(2 * NN, val);
    }

    SegTree(const vector<T> v, T val) {
        default_value = val;
        int N = v.size();
        NN = 1; while (NN < N) NN <<= 1;
        data = vector<T>(2 * NN, val);
        copy(v.begin(), v.end(), data.begin() + (NN - 1));
        build(0, 0, NN);
    }

    void build(int u, int l, int r) {
        if (r - l == 1) return;
        int m = (l + r) / 2;
        build(u * 2 + 1, l, m);
        build(u * 2 + 2, m, r);
        data[u] = aggr(data[2 * u + 1], data[2 * u + 2]);
    }

    T query(int a, int b, int u, int l, int r) {
        if (l >= b || r <= a)
            return default_value;
        if (l >= a && r <= b)
            return data[u];
        int m = (l + r) / 2;
        T res1 = query(a, b, u * 2 + 1, l, m);
        T res2 = query(a, b, u * 2 + 2, m, r);
        return aggr(res1, res2);
    }

    void update_value(int idx, T x, int u, int l, int r) {
        if (idx < l || idx >= r)
            return;
        if (idx == l && r - l == 1) {
            data[u] = x;
            return;
        }
        int m = (l + r) / 2;
        update_value(idx, x, u * 2 + 1, l, m);
        update_value(idx, x, u * 2 + 2, m, r);
        data[u] = aggr(data[2 * u + 1], data[2 * u + 2]);
    }

    void update_delta(int idx, T x, int u, int l, int r) {
        update_value(idx, data[NN - 1 + idx] + x, u, l, r);
    }
};

template <class T>
ostream & operator << (ostream &out, const SegTree<T> &seg) {
    out << "SegTree(NN=" << seg.NN << ", ";
    for (int u = 0; u < seg.NN; u += (u == 0) ? 1 : u) {
        out << "[ ";
        for (int i = 0; i < 2 * u + 1; i++) {
            out << seg.data[u + i] << " ";
        }
        out << "]";
    }
    out << ")";
    return out;
}


int solve() {
    int H, W, M;
    cin >> H >> W >> M;

    auto cntR = vector<int>(H, 0);
    auto cntC = vector<int>(W, 0);
    auto t = vector<vector<int>>(H, vector<int>());
    for (int i = 0; i < M; i++) {
        int r, c; 
        cin >> r >> c;
        r--; c--;
        cntR[r]++;
        cntC[c]++;
        t[r].push_back(c);
    }

    auto seg = SegTree<int>(cntC, 0);
    // cout << seg << endl;
    int ans = -1;
    for (int r = 0; r < H; r++) {
        for (auto c : t[r]) {
            seg.update_delta(c, -1, 0, 0, seg.NN);
        }
        // cout << seg << endl;
        int val = cntR[r] + seg.query(0, W, 0, 0, seg.NN);
        ans = max(ans, val);
        for (auto c : t[r]) {
            seg.update_delta(c, +1, 0, 0, seg.NN);
        }
    }
    return ans;
}

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

    cout << solve() << endl;

    return 0;
}

Measured memory_bytes: 27220
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int N,M,Q;
    cin >> N >> M >> Q;
    list<int> L;

    rep(i,N){
        L.pb(i);
    }

    list<int>::iterator baton = L.begin();

    rep(i,M){
        int a;
        cin >> a;
        if(a%2 == 0){
            rep(j,a){
                baton++;
                if(baton == L.end()){
                    baton = L.begin();
                }
            }
        }else{
            rep(j,a){
                if(baton == L.begin()){
                    baton = L.end();
                }
                baton--;
            }
        }
        list<int>::iterator it = baton;
        baton++;
        if(baton == L.end()){
            baton = L.begin();
        }
        L.erase(it);
    }

    vector<int> ans;

    rep(i,Q){
        int q;
        cin >> q;
        list<int>::iterator it = L.begin();
        for(it = L.begin(); it != L.end(); it++){
            if(*it == q){
                break;
            }
        }
        if(it != L.end()){
            //ans.pb(1);
            cout << 1 << endl;
        }else{
            //ans.pb(0);
            cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 9372
import collections

#くじ引き回数の抽出
draw_count = int(input())

#景品をリストに格納
item = [input() for i in range(draw_count)]

#景品の種類とその要素数を辞書型に格納
item_type = collections.Counter(item)

#景品の種類を表示
print(len(item_type))

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

int main( void )
{
  string s, t;
  cin >> s;

  int size;
  if( s.size() % 2 == 0 )
    size = s.size() / 2;
  else
    size = ( s.size() + 1 ) / 2;

  for( int i = 0; i < size; i++ )
  cout << s.at( 2 * i );
}

Measured memory_bytes: 3648
#include <stdio.h> 
int main()
{
  int n,flag=0;
  scanf("%d", &n);
  char s[n];  
  for(int i=0;i<n;i++){
    scanf("%s", &s[i]);
  }
  for(int i=0;i<n;i++){
    if(s[i]=='Y'){
      flag=1;
      break;
    }
  }
  if(flag==1) printf("Four\n");
  else printf("Three\n");
  return 0;
}


/*while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
*/


Measured memory_bytes: 128
num1 =input().rstrip().split()
num2 =input().rstrip().split()
num3 =input().rstrip().split()
numbers=[int(num1[0]),int(num1[1]),int(num1[2]),int(num2[0]),int(num2[1]),int(num2[2]),int(num3[0]),int(num3[1]),int(num3[2])]
#print(numbers)
N =int(input())
calls =[]
for i in range(N):
    calls.append(int(input()))
#print(calls)
for i in range(9):
    for call in calls:
        if call == numbers[i]:
            numbers[i]=0
#print(numbers)
a=numbers[0]+numbers[1]+numbers[2]
b=numbers[3]+numbers[4]+numbers[5]
c=numbers[6]+numbers[7]+numbers[8]
d=numbers[0]+numbers[3]+numbers[6]
e=numbers[1]+numbers[4]+numbers[7]
f=numbers[2]+numbers[5]+numbers[8]
g=numbers[0]+numbers[4]+numbers[8]
h=numbers[2]+numbers[4]+numbers[6]

if a*b*c*d*e*f*g*h==0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
T=[]
result=0
last=[0 for i in range(26)]

#初期解の算出
for i in range(D):
    change=[S[i][j]-(last[j]+1)*C[j] for j in range(26)]
    t=change.index(max(change))
    T.append(t+1)
    result+=S[i][t]
    last[t]=-1
    for j in range(26):
        last[j]+=1
        result-=C[j]*last[j]

for i in range(D):
    print(T[i])

Measured memory_bytes: 9396
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
ll num[200010]={0};
int main(){
	ll K,N;
	cin>>K>>N;
	memset(num,0,sizeof(num));
	for(int i=0;i<N;i++){
		cin>>num[i];
	}
	sort(num,num+N);
	if(N==1){//只有一个 
		cout<<0<<endl;
	}else if(N==2){//有两个
		ll len=num[N-1]-num[0];
		cout<<min(len,K-len)<<endl; 
	}else{//至少有三个及以上
		ll min_l=10000000;
		ll len[200010]={0},t=0;
		ll sum=0;
		for(int i=1;i<N;i++){
			len[t++]=num[i]-num[i-1];
			sum=sum+len[t-1];
		}
		len[t++]=K-num[N-1]+num[0];
		sum=sum+len[t-1];
		for(int i=0;i<t;i++){//丢掉第  i  个数 
			min_l=min(min_l,sum-len[i]);
		}
		cout<<min_l<<endl;
	}
	return 0;
}

Measured memory_bytes: 3328
import math
a,b,x = map(int, input().split())

ans1 = math.degrees(math.atan2((b-x/(a*a)),(a/2)))
ans2 = 90-math.degrees(math.atan2(2*x/(a*b),b))
if x/a > a*b/2:
    print(ans1)
else:
    print(ans2)

Measured memory_bytes: 3060
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int data[100]={};
int mini;
int n;
int SUM;


void dfs(int num,int sum){
    if(num>=n){
        mini=min(mini,abs(SUM-sum-sum));
        return ;
    }
    
    dfs(num+1,sum+data[num]);
    dfs(num+1,sum);
}


int main() {
    while(cin>>n){
        if(n==0)break;
        
        SUM=0;
        mini=99999999;
        rep(i,100) data[i]=0;
        
        rep(i,n){
            cin>>data[i];
            SUM+=data[i];
        }
        
        dfs(0,0);
        cout<<mini<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define pii pair<int,int>
typedef long long llong;
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	
	vector<pii > v;
	REP(i,n){
		int a;
		cin>>a;
		v.push_back(make_pair(a,1));
	}
	
	REP(i,m){
		int b,c;
		cin>>b>>c;
		v.push_back(make_pair(c,b));
	}
	
	sort(ALL(v));
	reverse(ALL(v));
	
	llong ans=0;
	int cnt=0;
	int j=0;
	while(1){
		if(v[j].second<n-cnt){
			ans+=(llong)v[j].first*v[j].second;
			cnt+=v[j].second;
			j++;
		}else break;
	}
	
	ans+=(llong)v[j].first*(n-cnt);
	
	cout<<ans<<endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cstdlib>
using namespace std;

const int N = 1005;
int n, m;
long long x[N][3];
long long dp[N];

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

	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> x[i][0] >> x[i][1] >> x[i][2];

	long long ans = 0;
	for (int mask = 0; mask < 8; mask++) {
		for (int i = 0; i < n; i++) {
			dp[i] = 0;
			for (int k = 0; k < 3; k++) {
				if (mask & (1<<k))
					dp[i] -= x[i][k];
				else
					dp[i] += x[i][k];
			}
		}

		sort(dp, dp+n);
		long long tmp = 0;
		for (int i = n-m; i < n; i++)
			tmp += dp[i];
		ans = max(ans, abs(tmp));
	}

	cout << ans << endl;
}


Measured memory_bytes: 256