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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int k, x; cin >> k >> x;
  for(ll i = x-(k-1); i <= x+(k-1); ++i) cout << i << " ";
  cout << endl;
}

Measured memory_bytes: 3592
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int n,a[100],cnt,min=0;
  std::cin >> n;

  for(int i=0; i<n; i++) std::cin >> a[i];
  sort(a,a+n);
  for(int i=0; i<n; i++){
    if(a[i]>min){
      cnt++;
      min=a[i];
    }
  }

  std::cout << cnt << '\n';
  

  return 0;
  
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
// int power(int a,int n)
// {
//     a %= mod;
//     if(n == 1)return a;
//     if(n == 0)return 1;
//     if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
//     return power((a*a)%mod,n/2)%mod;
// }

// const int inf = (int) 1e18;
 
// int inverse(int x){
//     return power(x,mod-2)%mod;//little fermat....
// }

int n,lca[60][60],dp[(1<<20)+5][25];
vector<int>sub[60],mask(60),v1((1<<20)+5),v2((1<<20)+5);
vector<pii>adj[60],con(30),par(60);

void dfs(int x,int p){
    sub[x].pb(x);
    for(auto &y:adj[x]){
        if(y.f != p){
            par[y.f] = {x,y.se};
            dfs(y.f,x);
            for(auto &u:sub[y.f]){
                for(auto &v:sub[x]){
                    lca[u][v] = x;
                    lca[v][u] = x;
                }
            }
            for(auto &u:sub[y.f]){
                sub[x].pb(u);
            }
        }
    }
}

void solve(){
    int n;
    cin >> n;
    FOR(i,0,n-1){
        int u,v;
        cin >> u >> v;
        adj[u].pb({v,i});
        adj[v].pb({u,i});
    }
    par[1] = {1,-1};
    dfs(1,1);
    int m;
    cin >> m;
    FOR(i,0,m){
        cin >> con[i].f >> con[i].se;
        int l = lca[con[i].f][con[i].se];
        int u = con[i].f,v = con[i].se;
        while(u != l){
            mask[par[u].se] |= (1<<i);
            u = par[u].f;
        }
        while(v != l){
            mask[par[v].se] |= (1<<i);
            v = par[v].f;
        }
    }   
    n--;
    int half = n/2;
    FOR(i,0,(1<<half)){
        int tmp_mask = 0;
        FOR(j,0,half){
            if(i&(1<<j))tmp_mask |= mask[j];
        }
        v1[tmp_mask]++;
    }
    FOR(i,0,1<<(n-half)){
        int tmp_mask = 0;
        FOR(j,0,n-half){
            if(i&(1<<j))tmp_mask |= mask[half+j];
        }
        v2[tmp_mask]++;
    }
    FOR(i,0,(1<<20)){
        if(1&i)dp[i][0] = v2[i]+v2[i^1];
        else dp[i][0] = v2[i^1];
    }
    FOR(i,1,20){
        FOR(j,0,(1<<20)){
            dp[j][i] = dp[j^(1<<i)][i-1];   
            if(j&(1<<i))dp[j][i] += dp[j][i-1];
        }
    }
    long long ans = 0;
    FOR(i,0,(1<<20))ans += (long long )(v1[i]*dp[i][m-1]);
    cout << ans;
}

signed main()   
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
       solve();
       cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


Measured memory_bytes: 221568
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	ll a, v, b, w, t;
	scanf("%lld%lld%lld%lld%lld", &a, &v, &b, &w, &t);
	if(abs(a-b) <= abs(v-w) * t && v>w){
		printf("YES\n");
	} else {
		printf("NO\n");
	}
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
#define lli   long long int
typedef pair<int, int> ii; 
typedef vector<ii> vii;
typedef vector<int> vi; 
lli arr[100];
unordered_map<lli,bool>maps;

int main()
{	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif 
	   lli x,n;
	   cin>>x>>n;
	   for(int i=0;i<n;i++){
	   	cin>>arr[i];
	   	maps[arr[i]]=true;
	   }
	   sort(arr,arr+n);
	   if(binary_search(arr,arr+n,x)){
	   lli index=binary_search(arr, arr + n, x);
	   if(n==0)
	   	cout<<x<<endl;
	   else if(index==n-1){
	   		if(!maps[x-1])
	   			cout<<x-1<<endl;
	   		else
	   			cout<<x+1<<endl;
	   	}
	   
	   	else if(index==0)
	   		cout<<x-1<<endl;
	   	else{
	   		lli j=x-1; 
	   		lli last=x+1; lli ans1,ans2;
	   		while(true){
	   			if(!maps[j]){
	   				ans1=j;
	   				break;
	   			}
	   			j--;
	   		}
	   		while(true){
	   			if(!maps[last]){
	   				ans2=last;
	   				break;
	   			}
	   			last++;
	   		}
	   		if(abs(x-ans1)>(abs(x-ans2)))
	   			cout<<ans2<<endl;
	   		else
	   			cout<<ans1<<endl;
	   	}

	   }
	   else {
	   	cout<<x<<endl;
	   }
	   return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

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

struct warshall_floyd {
	static void solve(vector<vector<ll>>& d) {
		int n = d.size();
		rep(k, n) {
			rep(i, n) {
				rep(j, n) {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
	}
};

int main(void)
{
	ll n, m, l;
	cin >> n >> m >> l;
	vector<vector<ll>> graph(n, vector<ll>(n, (ll)1e15));
	rep(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		graph[a][b] = c;
		graph[b][a] = c;
	}
	int q;
	cin >> q;
	vector<P> qs;
	rep(i, q) {
		int s, t;
		cin >> s >> t;
		s--; t--;
		qs.emplace_back(s, t);
	}
	warshall_floyd::solve(graph);
	vector<vector<ll>> g2(n, vector<ll>(n, (ll)1e15));
	rep(i, n) rep(j, n) {
		if (graph[i][j] <= l) {
			g2[i][j] = 1;
			g2[j][i] = 1;
		}
	}
	warshall_floyd::solve(g2);
	rep(i, q) {
		int s = qs[i].first;
		int t = qs[i].second;
		if (g2[s][t] >= (ll)1e15) {
			cout << -1 << endl;
		}
		else {
			cout << g2[s][t] - 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3320
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
	int a, b;
	cin >> a >> b;
	int ans = 0;

	FOR(i, a, b + 1){
		int j1 = i / 10000;
		int j5 = i % 10;
		int j4 = i % 100;
		j4 /= 10; 
		int j2 = i % 10000;
		j2 /= 1000;

		if (j1 == j5 && j2 == j4) ans++;
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        pair<int, int> n; cin >> n.first >> n.second;
        if(n.first == 0 and n.second == 0) return 0;
        else{
            vector<int> Card(n.first);
            int tmp = n.first;
            for(int i = 0; i < n.first; i++){
                Card[i] = tmp;
                tmp--;
            }
            REP(i, n.second){
                pair<int, int> cut; cin >> cut.first >> cut.second;
                vector<int> New(0);
                for(int i = cut.first - 1; i < cut.first + cut.second - 1; i++) New.push_back(Card[i]);
                REP(i, cut.first - 1) New.push_back(Card[i]);
                FOR(i, cut.first + cut.second - 1, n.first) New.push_back(Card[i]);
                REP(i, n.first) Card[i] = New[i];
            }
            cout << Card[0] << endl;
        }
    }
}


Measured memory_bytes: 2992
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int i = 1;
		String str = "";
		while (sc.hasNextLine()) {
		    String s = sc.nextLine();
		    String[] sr = s.split("");
		    str = str + sr[i];
		    i++;
		}

		// 出力
		System.out.println(str);
	}
}

Measured memory_bytes: 19028
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int D;
int C[30];
int S[400][30];
int last[400][30];

unsigned int xor128()
{
  static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
  unsigned int t;
  t=(x^(x<<11)); x=y; y=z; z=w; 
  return( w=(w^(w>>19))^(t^(t>>8)) );
}

ll score(vector<int>& t)
{
  ll s = 0LL;
  REP(i,t.size()){
    s += S[i][t[i]];
    REP(j,26) last[i+1][j] = last[i][j];
    last[i+1][t[i]] = i+1;
    REP(j,26){
      s -= C[j] * (i+1-last[i+1][j]);
    } 
  }
  return s;
}

ll score_2(vector<int>& t, ll before, int d, int old, int q)
{
  ll s = before;
  s += S[d][q] - S[d][old];
  FOR(i,d,D){
    if(t[i]==old) break;
    s += C[old] * ((i+1) - last[i+1][old]);
    s -= C[old] * ((i+1) - last[d][old]);
  }
  FOR(i,d,D){
    if(i!=d && t[i]==q) break;
    s += C[q] * ((i+1) - last[i+1][q]);
    s -= C[q] * ((i+1) - (d+1));
  }

  return s;
}

vector<int> init(void)
{
  vector<int> t;
  REP(d, D){
    ll max_sc = LLONG_MIN;
    int ind = 0;
    REP(i,26){
      t.push_back(i);
      ll sc = score(t);
      if(max_sc<sc){
        max_sc = sc;
        ind = i;
      }
      t.pop_back();
    }
    t.push_back(ind);
  }
  return t;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  /*
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand365(0, 364);
  uniform_int_distribution<> rand26(0, 25);
  */
  cin >> D;
  REP(i,26) cin >> C[i];
  REP(i,D) REP(j,26) cin >> S[i][j];

  auto T = init();
  ll max_score = score(T);
  
  int ti = clock();
  while(clock() - ti < 190 * CLOCKS_PER_SEC / 100){ 
    REP(loop,100){
      //int d = rand365(mt);
      //int q = rand26(mt);
      int d = xor128() % 365;
      int q = xor128() % 26;
      int old = T[d];
      T[d] = q;
      ll tmp = score_2(T, max_score, d, old, q);
      if(max_score<tmp){
        max_score = tmp;
        FOR(i,d,D){
          if(T[i]==old) break;
          last[i+1][old] = last[d][old];
        }
        FOR(i,d,D){
          if(i!=d && T[i]==q) break;
          last[i+1][q] = (d+1);
        }
      }else{
        T[d] = old;
      }
    }
  }
  REP(i,D) cout << T[i]+1 << '\n';
  return 0;
}


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

int palindrome(char *S, int len) {
  int i;
  for (i = 0; i < len/2; i++) {
    if (S[i] != S[len-i-1]) return 1;
  }
  return 0;
}

int main(void) {
  char S[99], S2[99];
  int len;

  scanf("%s", S);
  len = strlen(S);
  for (int i = 0; i < len; i++) {
    S2[i] = S[len-i-1];
  }

  if (palindrome(S, len) == 0 && palindrome(S, len/2) == 0 && palindrome(S2, len/2) == 0) {
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n+2)
	for i := range as {
		switch i {
		case 0, n + 1:
			as[i] = 0
		default:
			fmt.Scan(&as[i])
		}
	}

	diffs := make([]int, n+1)
	sum := 0
	for i := range diffs {
		diffs[i] = abs(as[i] - as[i+1])
		sum += diffs[i]
	}

	for i := 0; i < n; i++ {
		ans := sum - diffs[i] - diffs[i+1] + abs(as[i]-as[i+2])
		fmt.Println(ans)
	}
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 6528
#include <stdio.h>
#define MAX 100
#define INFTY 100000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n;
int M[MAX][MAX];
int d[MAX];

//void dijkstra(int n,int d[],int M[MAX][MAX]){                                 
void dijkstra(void){
  int color[MAX];
  // int d[MAX];                                                                
  int i,v,min;
  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }


  d[0]=0;
  color[0]=GRAY;

  while(1){
    v=-1;
    min=INFTY;
    for(i=0;i<n;i++){
      if(color[i] == GRAY && d[i] < min){
        min = d[i];
        v = i;
      }
    }
    if(v == -1)break;
    color[v] = BLACK;
    for(i=0;i<n;i++){
      if(color[i] != BLACK && M[v][i] < INFTY){
        color[i] = GRAY;
        if(d[i] > (d[v] + M[v][i])){
          d[i] = (d[v]+M[v][i]);
        }

      }
    }
  }
  for(i=0;i<n;i++)printf("%d %d\n",i,d[i]);

}
int main(){
  int k,u,v,c,i,j;
  // int d[MAX],M[MAX][MAX];                                                    
  //int n;                                                                      
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INFTY;
    }
  }


  // scanf("%d",&n);                                                            
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }

  // dijkstra(n,d,M);                                                           
  dijkstra();
  /*  for(i=0;i<n;i++){                                                         
    printf("%d %d\n",i,d[i]);                                                   
    }*/
  return 0;
}


Measured memory_bytes: 2112
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

#define size_t int
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int N, M;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};


signed main(signed argc, char **argv) {
  cin >> N >> M;
  vector<vector<int>> e(M, vector<int>(2));
  for (size_t i = 0; i < M; i++) {
    int a,b;
    cin >> a >> b;
    e[i][0] = a - 1;
    e[i][1] = b - 1;
  }
  UnionFind uf(N);
  int ans = N * (N-1) / 2;
  VI anss(M);
  for (size_t i = M - 1; i >= 0; i--) {
    anss[i] = ans;
    bool con = uf.findSet(e[i][0], e[i][1]);
    if (!con) {
      ans = ans - uf.size(e[i][0]) * uf.size(e[i][1]);
    }
    uf.unionSet(e[i][0], e[i][1]);
  }
  for (size_t i = 0; i < M; i++) {
    cout << anss[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 8320
N, M = list(map(int, input().split()))
lr = []
for i in range(M):
    l, r = list(map(int, input().split()))
    lr.append([l, r])

mi = -1
ma = 10**5 + 1
for i in range(M):
    l = lr[i][0]
    r = lr[i][1]
    if mi <= l:
        mi = l
    if r <= ma:
        ma = r

ans = ma - mi + 1
print(ans)if ans >= 0 else print(0)

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

struct UF{
	int par[100010];
	int r[100010];
	void init(){
		rep(i,100010){
			par[i] = i;
			r[i] = 0;
		}
	}
	int find(int x){
		if(par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
	void unit(int x,int y){
		if(same(x,y))return;
		x = find(x);
		y = find(y);
		if(r[x] < r[y]){
			par[x] = y;
		}
		else {
			par[y] = x;
			if(r[x] == r[y]){
				r[x] ++;
			}
		}
	}
}uf;

vector<int> G[100010];
int color[100010];
bool dfs(int v,int c){
	if(color[v] == c)return true;
	if(color[v] == -c)return false;
	color[v] = c;
	bool ret = true;
	rep(i,G[v].size()){
		ret &= dfs(G[v][i],-c);
	}
	return ret;
}

int main(){
	static int n,m;
	static int u[200010],v[200010];
	scanf("%d%d",&n,&m);
	rep(i,m)scanf("%d%d",&u[i],&v[i]);
	
	rep(i,m){
		G[u[i]].pb(v[i]);
		G[v[i]].pb(u[i]);
	}
	rep1(i,n)color[i] = 0;
	
	ll a = 0 , b = 0 , c = 0;
	rep1(i,n){
		if(color[i] != 0)continue;
		if(G[i].size() == 0)c ++;
		else {
			if(dfs(i,1))a ++;
			else b ++;
		}
	}
	//cout << a << " " << b << " " << c << endl;
	cout << 2*n*c-c*c + b*b + 2*a*b + 2*a*a << endl;
}



Measured memory_bytes: 12288
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
using namespace std;

bool check(vs &ngo, string s){
	for (string t : ngo) if (t == s) return 0;
	return 1;
}

int main(){
	ll h, w; cin >> h >> w;
	vvc a(h, vc(w));
	vb retuisw(w), gyouisw(h);
	for (int i = 0; i < h; ++i){
		bool t = 1;
		for (int j = 0; j < w; ++j){
			//cout << i << " " << j << endl;
			cin >> a[i][j];
			if (a[i][j] == '#') t = 0;
		}gyouisw[i] = t;
	}
	//cout << "a" << endl;
	for (int i = 0; i < w; ++i){
		bool t = 1;
		for (int j = 0; j < h; ++j){
			if (a[j][i] == '#') t = 0;
		}retuisw[i] = t;
	}
	for (int i = 0; i < h; ++i){
		//cout << gyouisw[i] << endl;
		if (gyouisw[i]) continue;
		for (int j = 0; j < w; ++j){
			if (retuisw[j]) continue;
			cout << a[i][j];
		}cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, y int
	flg := false
	fmt.Scanf("%d %d", &n, &y)
	for i := 0; i <= n; i++ {
		for j := 0; j+i <= n; j++ {
			total := 10000*i + 5000*j + 1000*(n-j-i)
			if total == y {
				fmt.Println(i, j, n-i-j)
				flg = true
				break
			}
		}
		if flg {
			break
		}

	}

	if !flg {
		fmt.Println(-1, -1, -1)
	}

}


Measured memory_bytes: 1836
/// WA

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type,
less<T>, rb_tree_tag, 
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int mn = n+1;
    int ans = 0;
    for (int x; n--;) {
        cin >> x;
        if (x < mn)
            ans++;
        mn = min(mn, x);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()

using namespace std;


int main() {
	speed;
	int p[20];
	int n;
	int ans = 0;
	cin >> n;
	rep(i, n) {
		cin >> p[i];
	}
	rep(i, n - 2) {
		if (p[i + 1] > p[i] && p[i + 1] < p[i + 2]) {
			ans++;
		}
		else if (p[i + 1]<p[i] && p[i + 1]>p[i + 2]) {
			ans++;
		}
	}
	cout << ans;
	ed;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

L1 = 0
L4 = 0
for a in A:
    if a % 4 == 0:
        L4 += 1
    elif a % 2 == 1:
        L1 += 1

ans = 'No'
if L1 + L4 == N:
    if L4 + 1 >= L1:
        ans = 'Yes'
else:
    if L4 >= L1:
        ans = 'Yes'
print(ans)


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A.at(i);
    int Q;
    cin >> Q;
    vector<int> B(Q), C(Q);
    for(int i=0; i<Q; i++) cin >> B.at(i) >> C.at(i);

    vector<int> cnt(100005, 0);
    ll ans = 0;
    for(auto a : A)
    {
        cnt[a]++;
        ans += a;
    }

    for(int i=0; i<Q; i++)
    {
        // cout << B[i] << ' ' << C[i] << ' ' << cnt[B[i]] << ' ' << cnt[C[i]] << ' ' << ans << '\n';
        ans += (C[i] - B[i]) * cnt[B[i]];
        cnt[C[i]] += cnt[B[i]];
        cnt[B[i]] = 0;
        cout << ans << '\n';
    }


    return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N, x;
    cin >> N >> x;
    vector<int> A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }

    long long ans = 0;
    long long tmp = 0;
    while(A[0] + A[1] > x){
        if(A[1] >= 0){
            A[1]--; 
            ans++;
        }else{
            A[0]--;
            ans++;
        }
    }
    if(N == 2){
        cout << ans << endl;
        return 0;
    }
    for(int i = 2; i < N; ++i){
        if(A[i-1] + A[i] > x){
            tmp = A[i-1] + A[i] - x;
            ans += tmp;
            if(A[i] < tmp){
                tmp -= A[i];
                A[i] = 0;
                A[i-1] -= tmp;
            }else if(A[i] == tmp){
                A[i] = 0;
            }else{
                A[i] -= tmp;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
int main(void){
  int a,b;
  scanf("%d %d", &a, &b);
  int sum = a+b;
  int diff = a-b;
  int mul = a*b;
  int max = sum;
  if(max < diff){max = diff;}
  if(max < mul){max = mul;}
  printf("%d",max);
  return 0;
}


Measured memory_bytes: 128
D, G = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(D)]

ans=float("inf")

for bit in range(1 << D):
    count = 0
    sum = 0
    nokori = set(range(1,D+1))

    for i in range(D):
        if bit & (1 << i):
            sum=sum+pc[i][0]*(i+1)*100+pc[i][1]
            count=count+pc[i][0]
            nokori.discard(i+1)
    
    #G点に満たなければnokoriのうち一番大きいものをとく
    if sum<G:
        use=max(nokori)
        n=min(pc[use-1][0], -(-(G-sum)//(use*100)))
        count=count+n
        sum=sum+n*(use*100)
    
    if sum>=G:
        ans=min(ans, count)

print(ans)

Measured memory_bytes: 3064
n,m = map(int,input().split())
vals = []
inf = float("inf")
res = [inf]*2**n

for i in range(m):
	a,b = map(int,input().split())
	C = list(map(int,input().split()))
	cur = 0
	for c in C:
		cur |= 2**(c-1)
	res[cur] = min(res[cur],a)

ans = []
for i,r in enumerate(res):
	if res[i] == inf:
		continue
	ans.append([i,r])


for i,a in ans:
	for j in range(2**n):
		res[i|j] = min(res[i|j],res[i]+res[j])

if res[-1] == inf:
	print(-1)
else:
	print(res[-1])

Measured memory_bytes: 3188
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] array = new int[N];
    
    for(int i = 0 ; i < N ; i ++){
      array[i] = sc.nextInt();
    }
    
    Arrays.sort(array);
    
    int ans = array[N/2] -array[N/2 -1];
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 50604
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
        String[] input = br.readLine().split(" ");
        int var = Integer.parseInt(input[0]);
        int hor = Integer.parseInt(input[1]);

        int[][] matrix = new int[var][hor];
        int[] vector = new int[hor];
        
        //data input
        for(int i = 0; i < var; i++){
            String[] line = br.readLine().split(" ");
            for(int j = 0; j < hor; j++){
                matrix[i][j] = Integer.parseInt(line[j]);
            }
        }
        for(int i = 0; i < hor; i++){
            vector[i] = Integer.parseInt(br.readLine());
        }
        
        //data output
        for(int i = 0; i < var; i++){
            int result = 0;
            for(int j = 0; j < hor; j++){
                result += matrix[i][j] * vector[j];
            }
            System.out.println(result);
        }

    }
}

Measured memory_bytes: 27484
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n;

    for(int i=1;i<=n;i++)
    {
        cin>>A[i];
    }

    for(int i=2;i<n;i++){
        if(A[i-1]<A[i]&&A[i]<A[i+1])cnt++;
        else if(A[i+1]<A[i]&&A[i]<A[i-1])cnt++;
    }

    cout<<cnt;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

bool solve(bool** gems, vector<pair<char,int> >* v);

int main(void){
  while(1){
    int N,M;
    cin>>N;
    if(N==0){
      break;
    }
    bool* gems[21];
    for(int i=0;i<=20;i++){
      gems[i]=(bool*)malloc(21*sizeof(bool));
    }
    for(int i=0;i<=20;i++){
      for(int j=0;j<=20;j++){
        gems[i][j]=false;
      }
    }
    for(int i=0;i<N;i++){
      int x,y;
      cin>>x>>y;
      gems[20-y][x]=true;
    }
    cin>>M;
    vector<pair<char,int> > v;
    for(int i=0;i<M;i++){
      char d;
      int l;
      cin>>d>>l;
      pair<char,int> p=make_pair(d,l);
      v.push_back(p);
    }
    if(solve(gems,&v)) {
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

bool solve(bool** gems, vector<pair<char,int> >* _v){
  auto v=*_v;
  auto point=make_pair(10,10);
  gems[10][10]=false;
  for(auto iter=v.begin();iter!=v.end();iter++){
    if(iter->first=='S'){
      int X=point.first;
      int y_goal=point.second+iter->second;
      for(int y=min(point.second,y_goal);y<=max(point.second,y_goal);y++){
        gems[y][X]=false;
      }
      gems[y_goal][X]=false;
      point.second=y_goal;
    }
    else if(iter->first=='N'){
      int X=point.first;
      int y_goal=point.second-iter->second;
      for(int y=min(point.second,y_goal);y<=max(point.second,y_goal);y++){
        gems[y][X]=false;
      }
      gems[y_goal][X]=false;
      point.second=y_goal;
    }
    else if(iter->first=='E'){
      int Y=point.second;
      int x_goal=point.first+iter->second;
      for(int x=min(point.first,x_goal);x<=max(point.first,x_goal);x++){
        gems[Y][x]=false;
      }
      gems[Y][x_goal]=false;
      point.first=x_goal;
    }
    else if(iter->first=='W'){
      int Y=point.second;
      int x_goal=point.first-iter->second;
      for(int x=min(point.first,x_goal);x<=max(point.first,x_goal);x++){
        gems[Y][x]=false;
      }
      gems[Y][x_goal]=false;
      point.first=x_goal;
    }
  }
  for(int x=0;x<=20;x++){
    for(int y=0;y<=20;y++){
      if(gems[y][x]){
        return false;
      }
    }
  }
  return true;
}



Measured memory_bytes: 3276
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL << 60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  string S;
  S = "";
  while(N){
    int num;
    num = N % 2;
    if(num<0){
      num += 2;
    }
    S += toString(num);
    N = (N-num)/(-2);
  }
  reverse(S.begin(),S.end());
  if(S == "") cout << 0 << endl;
  else cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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(){
  int x;
  cin >> x;
  x-=400;
  x = x/200;
  cout << 8-x << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long ll;
using namespace std;

int main()
{


           ll n;
            cin>>n;
            if(n%1000==0)
                cout<<0<<endl;
            else{
           ll temp=n/1000;
           cout<<(temp+1)*1000-n<<endl;
           }







return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
int main(void){
    int x,y,i;
    while(1){
        scanf("%d %d",&x,&y);
        if ( x == 0&&y == 0) break;
        if (x > y){
            i = x;
            x = y;
            y = i;
            printf("%d %d\n",x,y);
        }
        else{
            printf("%d %d\n",x,y);
        }
    }
    return 0;
}

Measured memory_bytes: 600
package main

import (
  "fmt"
  "sort"
)

func main(){
  var n int
  
  fmt.Scan(&n)
  var a []int
  for i := 0; i<n; i++ {
    var tmp int
    fmt.Scan(&tmp)
    a = append(a,tmp)
  }
  
  sort.Ints(a)
  
  cnta,cntb := 0,0
  
  for i := 0; i < n; i++ {
    if i % 2 == 0 {
      cnta += a[len(a) - i - 1]
    } else {
      cntb += a[len(a) - i - 1]
    }
  }
  
  fmt.Println(cnta - cntb)
}

Measured memory_bytes: 512
const main = input => {
    const S = input.trim();
    if (S === 'Sunny') {
        console.log('Cloudy');
    } else if (S === 'Cloudy') {
        console.log('Rainy');
    } else {
        console.log('Sunny');
    }
};

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"));
// main(require("fs").readFileSync("input.txt", "utf8"));

Measured memory_bytes: 29552
n = int(input())
inp_h = [int(i) for i in input().split()]

h_max = max(inp_h)
h_len = len(inp_h)

ind = [0]*h_len

h_bool = [True if ind[i] == inp_h[i] else False for i in range(h_len)]

def make_index(h_bool):
    try:
        index = h_bool.index(False)
    except:
        index = -1
    return index

num = 0
while True:
    index = make_index(h_bool)
    index_list = []
    if index != -1:
        while True:
            if index < h_len:
                if h_bool[index] == False:
                    index_list.append(index)
                    index += 1
                elif h_bool[index] == True:
                    ind = [ind[i]+1 if i in index_list else ind[i] for i in range(h_len)]
                    h_bool = [True if ind[i] == inp_h[i] else False for i in range(h_len)]
                    num += 1
                    break
            elif index >= h_len:
                ind = [ind[i]+1 if i in index_list else ind[i] for i in range(h_len)]
                h_bool = [True if ind[i] == inp_h[i] else False for i in range(h_len)]
                num += 1
                break
    else:
        break
    
print(num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define len(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int n,k;cin>>n>>k;
  vector<int> an(200100);
  int a;
  rep(i,n) {
    cin>>a;
    an[a] ++;
  }
  sort(an.begin(), an.end());
  reverse(an.begin(), an.end());
  int sum=0, i=k;
  while (an[i] != 0) {
    sum+= an[i];
    i++;
  }
  cout << sum;
  
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
    typedef long long ll;
    ll n;
    cin >> n;
    if(n & 1) return cout << 0, 0;
    n >>= 1;
    // now n! me trailing 0 = sigma(n/ 5^i ) 
    ll R = 0;
    while(n) {
        R += (n / 5);
        n /= 5;
    } cout << R;
}

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

const int Maxn = 200005, p = 1e9 + 7;
int n, m, ct, tmp_ct, x[Maxn], y[Maxn], a[Maxn];
pair <int, int> P[Maxn];
long long sum[Maxn];
vector <int> Ve[Maxn];
int lowbit(int x)
{
	return x & -x;
}
void add(int x, int y)
{
	for (int i = x; i <= tmp_ct + 1; i += lowbit(i))
		(sum[i] += y) %= p;
}
long long ask(int x)
{
	long long tmp = 0;
	for (int i = x; i; i -= lowbit(i))
		(tmp += sum[i]) %= p;
	return tmp;
}
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%d", &x[i]);
	for (int i = 1; i <= m; i++)
		scanf("%d", &y[i]);
	for (int i = 1; i <= n; i++)
	{
		if (x[i] < y[1] || x[i] > y[m]) continue;
		int pos = upper_bound(y + 1, y + 1 + m, x[i]) - y;
		P[++ct] = make_pair(y[pos] - x[i], x[i] - y[pos - 1]);
	}
	sort(P + 1, P + 1 + ct);
	for (int i = 1; i <= ct; i++)
		a[2 * i - 1] = P[i].first, a[2 * i] = P[i].second;
	sort(a + 1, a + 1 + 2 * ct);
	tmp_ct = unique(a + 1, a + 1 + 2 * ct) - a - 1;
	for (int i = 1; i <= ct; i++)
	{
		P[i].first = lower_bound(a + 1, a + 1 + tmp_ct, P[i].first) - a;
		P[i].second = lower_bound(a + 1, a + 1 + tmp_ct, P[i].second) - a;
		Ve[P[i].first].push_back(P[i].second);
	}
	add(1, 1);
	for (int i = 1; i <= tmp_ct; i++)
	{
		int las = 0;
		for (vector <int> :: reverse_iterator it = Ve[i].rbegin(); it != Ve[i].rend(); it++)
			if (*it != las) add(*it + 1, ask(*it)), las = *it;
	}
	printf("%lld", ask(tmp_ct + 1));
	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    // find most common row, most common column, then 

    set<pair<int,int>> ps;
    int r, c, m;
    cin >> r >> c >> m;
    vector<int> rows(r + 1);
    vector<int> cols(c + 1);

    for(int i = 0; i < m; i++) {
        int y, x;
        cin >> y >> x;
        rows[y]++;
        cols[x]++;
        ps.insert(mp(y,x));
    }

    vector<int> indexRows;
    vector<int> indexCols;
    int bestRow = 0;
    int bestCol = 0;
    for(int i = 1; i <= r; i++) {
        if(rows[i] == bestRow) {
            indexRows.pb(i);
        } else if(rows[i] > bestRow) {
            indexRows.clear();
            indexRows.pb(i);
            bestRow = rows[i];
        }
    }
    for(int i = 1; i <= c; i++) {
        if(cols[i] == bestCol) {
            indexCols.pb(i);
        } else if(cols[i] > bestCol) {
            indexCols.clear();
            indexCols.pb(i);
            bestCol = cols[i];
        }
    }
    int ans = 0;
    trav(x, indexRows) {
        trav(y, indexCols) {
            if(ps.count(mp(x,y))) {
                ans = max(ans, bestRow + bestCol - 1);
            } else {
                ans = max(ans, bestRow + bestCol);
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 23740
//
// Created on 2020/03/01.
//

//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {

    int n;
    int m;
    cin>>n>>m;
    vector<int> ans(n,-1);
    for (int i = 0; i < m; ++i) {
        int s,c;
        cin>>s>>c;
        s --;
        if(c==0 && s==0 && n!= 1){
            cout<<-1<<endl;
            return 0;
        }
        if(ans[s] == -1 || ans[s]==c){
            ans[s] = c;
            continue;
        }

            cout<<-1<<endl;
            return 0;


    }

    for (int j = 0; j < n; ++j) {
        if(ans[j] == -1 && j != 0) ans[j]=0;
        if(ans[j] == -1 && j == 0 && n!=1) ans[j] = 1;
        if(ans[j]==-1 && j==0 && n ==1) ans[j]=0;

    }
    int out = 0;
    for (int k = 0; k < n; ++k) {
        out += ans[k] * pow(10,n-(k+1));
    }


    cout<<out<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PB push_back
#define pb push_back
#define X first
#define Y second

#define SZ(a) ((LL)(a).size())
#define all(a) (a).begin(),a.end()
#define forn(i, n) for(LL i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()
#define ll long long
#define MAXN 100
int step[100005];
vector<vector<int> > g(100005);
int n , m;
int block = 0;
int visited[100005];
void dfs(int u)
{
	visited[u] = 1;
	for(auto v : g[u])
	{
		if(v == block || visited[v])
			continue;
		dfs(v);
	}
}
int cnt(int u)
{
	memset(visited , 0 , sizeof visited);
	block = u;
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		if(u == i)
			continue;
		if(!visited[i])
		{
			ans++;
			dfs(i);
		}
	}
	return ans;
}
int main()
{
	
	cin >> n >> m;
	for(int i = 0; i < m; i++)
	{
		int u , v;
		cin >> u >> v;
		u--;v--;
		g[u].PB(v);
		g[v].PB(u);
		step[u]++;
		step[v]++;
	}
	int cnt4 = 0;
	int mx = 0;
	for(int i = 0; i < n; i++)
	{
		if(step[i] % 2)
		{
			cout << "No";
			return 0;
		}
		cnt4 += step[i] == 4;
		mx = max(mx , step[i]);
	}
	//cout << mx << " " << cnt4 << endl;
	if(mx >= 6)
	{
		cout << "Yes";
		return 0;
	}
	if(mx == 4 && cnt4 >= 3)
	{
		cout << "Yes";
		return 0;
	}
	if(mx == 4 && cnt4 == 1)
	{
		cout << "No";
		return 0;
	}
	if(mx == 2)
	{
		cout << "No";
		return 0;
	}
	bool good = false;
	for(int i = 0; i < n; i++)
	{
		
		if(step[i] == 4)
		{
			int f = cnt(i);
			
			good |= f != 1;
		}
	}
	if(good)
	{
		cout << "Yes";
		return 0;
	}
	cout << "No";
}


Measured memory_bytes: 7808
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class Eratosthenes:
    def __init__(self, n):
        self.n = n
        self.min_factor = [-1] * (n + 1)
        self.min_factor[0], self.min_factor[1] = 0, 1

    def get_primes(self):
        primes = []
        is_prime = [True] * (self.n + 1)
        is_prime[0] = is_prime[1] = False
        for i in range(2, self.n + 1):
            if not is_prime[i]:
                continue
            primes.append(i)
            self.min_factor[i] = i
            for j in range(i * 2, self.n + 1, i):
                is_prime[j] = False
                if self.min_factor[j] == -1:
                    self.min_factor[j] = i
        return primes

    def prime_factorization(self, n):
        res = []
        while n != 1:
            prime = self.min_factor[n]
            exp = 0
            while self.min_factor[n] == prime:
                exp += 1
                n //= prime
            res.append([prime, exp])
        return res


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    MAX_A = max(A) + 1

    er = Eratosthenes(MAX_A)
    er.get_primes()
    num = [0] * MAX_A
    for i in range(n):
        pf = er.prime_factorization(A[i])
        for p, ex in pf:
            num[p] = max(num[p], ex)

    LCM = 1
    for v in range(2, MAX_A):
        LCM *= pow(v, num[v], mod)
        LCM %= mod

    res = 0
    for a in A:
        res += LCM * pow(a, mod - 2, mod)
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 28152
#include <iostream>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int main() {
   // cout<<"Hello World!";
FAST
int a,b;
cin>>a>>b;
int n=max(a,b);
int range=min(a,b);
for(int i=0;i<n;++i)cout<<range;

   return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
int n, q;
string s;
char t[200000], d[200000];
set<char> st;
bool dropl(int mid){
    for(int i=0;i<q;i++){
        if(s[mid]==t[i]){
            if(d[i]=='L'){
                mid--;
            }
            else mid++;
            if(mid==n) return 0;
            if(mid==-1) return 1;
        }
    }
    return 0;
}
bool dropr(int mid){
    for(int i=0;i<q;i++){
        if(s[mid]==t[i]){
            if(d[i]=='L'){
                mid--;
            }
            else mid++;
            if(mid==-1) return 0;
            if(mid==n) return 1;
        }
    }
    return 0;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> q >> s;
    for (int i = 0; i < q; i++)
    {
        cin >> t[i] >> d[i];
    }
    s = s.c_str();
    int g = n;
        int min=-1, max=n;
        int mid=(max+min)/2;
    while(max-min>1){
        mid=(max+min)/2;
        if(!dropl(mid)) max=mid;
        else min=mid;
    }
    g-=min+1;
    min=-1;
    max=n;
    mid=(max+min)/2;
    while(max-min>1){
        mid=(max+min)/2;
        if(dropr(mid)==true) max=mid;
        else min=mid;
    }
    g=g-n+min+1;
    
    cout<<g<<"\n";
}

Measured memory_bytes: 976