akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>

int main() {
	double cx[20], cy[20];
	int i;
	double a, b, c, z;
	double S;
	char dummy;
	
	i=0;
	while( std::cin >> cx[i] >> dummy >> cy[i] ) i++;

	S = 0.0;
	for( int j=1; j<i-1; j++) {
		a = sqrt( (cx[0]-cx[j])*(cx[0]-cx[j]) + (cy[0]-cy[j])*(cy[0]-cy[j]) );
		b = sqrt( (cx[0]-cx[j+1])*(cx[0]-cx[j+1]) + (cy[0]-cy[j+1])*(cy[0]-cy[j+1]) );
		c = sqrt( (cx[j]-cx[j+1])*(cx[j]-cx[j+1]) + (cy[j]-cy[j+1])*(cy[j]-cy[j+1]) );
		z = ( a + b + c ) / 2.0;

		S += sqrt( z*(z-a)*(z-b)*(z-c) );
	}
	
	if(S<0.000000) S*=-1.0;
	
	std::printf("%.6f", S);
	return 0;
}

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

using namespace std;

namespace {

#define VERA(i, a, b)for(auto i=(ll)(a);i<(ll)(b);++i)
#define ANDY(i, a, b)for(auto i=(ll)(a);i>(ll)(b);--i)

typedef long long ll;
typedef double dd;

struct UF {
  vector<ll> e;

  UF(int n) : e(n, -1) {}

  bool same_set(int a, int b) { return find(a) == find(b); }

  int size(int x) { return -e[find(x)]; }

  int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }

  void join(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return;
    if (e[a] > e[b]) swap(a, b);
    e[a] += e[b];
    e[b] = a;
  }
};


template <class T> inline ll Size(const T& x) { return x.size(); }

bool Solve(ll test_num) {
  (void) test_num;
  ll n, m;
  if (not(cin >> n >> m)) return false;
  UF dsu(n);
  vector<ll> wei(n);
  for (auto& w : wei) cin >> w;
  VERA(e, 0, m) {
    ll a, b;
    cin >> a >> b;
    dsu.join(a, b);
  }
  if (m == n - 1) {
    cout << "0\n";
    return true;
  }
  vector<vector<ll>> comps(n);
  vector<ll> all;
  ll res = 0, non_zero = 0;
  VERA(v, 0, n) comps[dsu.find(v)].push_back(v);
  for (auto& comp : comps) {
    if (comp.empty()) continue;
    static vector<ll> now;
    now.clear();
    for (auto v : comp)
      now.push_back(wei[v]);
    sort(now.begin(), now.end());
    res += now.front();
    ++non_zero;
    VERA(i, 1, Size(now)) all.push_back(now[i]);
  }
  if (n < 2 * (n - 1 - m)) {
    cout << "Impossible\n";
    return true;
  }
  sort(all.begin(), all.end());
  VERA(i, 0, 2 * (n - 1 - m) - non_zero) res += all[i];
  cout << res << endl;
  return true;
}

void Init() {
}

}

int main() {
#ifdef AZN
  const auto start_time = chrono::system_clock::now();
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  srand(1223);
  Init();
  ll test = 1;
  while (true)
    if (not Solve(test++))
      break;
#ifdef AZN
  cerr << "Took: " << ((chrono::system_clock::now() - start_time).count() /
                       static_cast<double>(chrono::system_clock::period::den)) << " s" << endl;
#endif
  return 0;
}


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


int main(){
    int N;
    string A,B,C;
    cin >> N >> A >> B >> C;
    int cnt = 0;
    rep(i,N){
        char a = A.at(i),b = B.at(i), c = C.at(i);
        set<int> S;
        S.insert(a);
        S.insert(b);
        S.insert(c);
        cnt += S.size() -1;
    }
    cout << cnt << endl;
}   

Measured memory_bytes: 256
package main

import "fmt"

func calc(n int) (result int) {
	for n != 0 {
		result += n % 10
		n /= 10
	}
	return
}

func main() {
	var N, A, B, ans int
	fmt.Scan(&N, &A, &B)

	for n := 0; n <= N; n++ {
		calcn := calc(n)
		if A <= calcn && calcn <= B {
			ans += n
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

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

ll n,m;
ll inf=1e15;
vector<edge> g;
vector<ll> d(1010,inf);
vector<bool> negative(1010,false);

void shortest_path(ll v){
  d[v]=0;
  rep(i,n+10){
    rep(j,m){
      edge now=g[j];
      if(d[now.from]!=inf && d[now.to]>d[now.from]+now.cost){
        d[now.to]=d[now.from]+now.cost;
      }
    }
  }
}

void find_negative(){
  rep(i,n+10){
    rep(j,m){
      edge now=g[j];
      if(d[now.from]!=inf && d[now.to]>d[now.from]+now.cost){
        d[now.to]=d[now.from]+now.cost;
        negative[now.to]=true;
      }
      //if(negative[now.from]) negative[now.to]=true;
    }
  }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m;
    rep(i,m){
      ll a,b,c;
      cin>>a>>b>>c;
      g.push_back({a,b,-c});
    }
    shortest_path(1);
    ll ans=-d[n];
    find_negative();
    if(negative[n]) cout<<"inf"<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string n;	
  int s=0; 
  cin>>n;
  if(n[0]!='C') 
    s++;
  if(n[1]!='O')
    s++;
  if(n[2]!='D') 
    s++;
  if(n[3]!='E') 
    s++;
  if(n[4]!='F') 
    s++;
  if(n[5]!='E') 
    s++;
  if(n[6]!='S') 
    s++; 
  if(n[7]!='T') 
    s++;
  if(n[8]!='I') 
    s++;
  if(n[9]!='V') 
    s++;
  if(n[10]!='A') 
    s++;
  if(n[11]!='L') 
    s++;
  if(n[12]!='2') 
    s++;
  if(n[13]!='0') 
    s++;
  if(n[14]!='1') 
    s++;
  if(n[15]!='6') 
    s++;
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
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(){
  ll A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  ll ans = INF;
  for(ll i=0; i<=1000000; i+=2){
    ll sum = i*C;
    sum += max(X-i/2,0LL)*A;
    sum += max(Y-i/2,0LL)*B;
    chmin(ans,sum);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  cout << N * (N - 1 ) / 2 + M * (M - 1) /2 <<endl;
  
  /*
  Nは偶数
  Mは奇数
  和が偶数
  */
  
}

Measured memory_bytes: 256
#include<iostream>
main(){int n,m,i,a,c[1<<20];for(std::string s;std::cin>>n>>m>>s,n;printf("%d\n",a))for(a=0,i=m;--i;a+=c[i]>=n)c[i]=s.substr(i,3)=="IOI"?c[i+2]+1:0;}

Measured memory_bytes: 5884
N, A, B = map(int, input().split())
if A % 2 == B % 2:
    print(abs(A - B) // 2)
else:
    A_top = A - 1
    B_top = B - 1
    top = (
        B_top + (A - B_top - 1) // 2 if A_top > B_top else A_top + (B - A_top - 1) // 2
    )

    A_btm = N - A
    B_btm = N - B
    btm = (
        B_btm + (N - A - B_btm) // 2 if A_btm > B_btm else A_btm + (N - B - A_btm) // 2
    )
    print(min(top, btm) + 1)


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

using namespace std;

typedef long long ll;

struct UF {
  int n_;
  vector<int> p_, rank_;
  UF(int n) : n_(n) {
    p_ = vector<int>(n);
    rank_ = vector<int>(n, 1);
    for (int i = 0; i < n; ++i) { p_[i] = i; }
  }

  int find_set(int x) {
    if (p_[x] != x) { p_[x] = find_set(p_[x]); }
    return p_[x];
  }

  void unite(int x, int y) {
    int s1 = find_set(x), s2 = find_set(y);
    if (s1 == s2) { return; }
    if (rank_[s1] > rank_[s2]) {
      p_[s2] = s1;
    }
    else {
      p_[s1] = s2;
      if (rank_[s1] == rank_[s2]) {
        ++rank_[s2];
      }
    }
  }

  bool is_connected(int x, int y) {
    return find_set(x) == find_set(y);
  }
};

int main()
{
  int n = 0, m = 0;
  scanf("%d %d", &n, &m);
  vector<int> pos(n + 1, -1);
  UF uf(n + 5);
  for (int i = 1; i <= n; ++i) {
    int a = -1;
    scanf("%d", &a);
    pos[i] = a;
  }

  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    uf.unite(x, y);
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (uf.is_connected(i, pos[i])) { ++ans; }
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define len(s) s.length()
#define all(v) v.begin(),v.end()
const ll INF = INT_MAX;
const int N = 2e5 + 5;
const ll mod = 1000000007 ;
using namespace std;


ll cnt[N];


int main() {



	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);


	ll tc = 1;
	// cin >> tc;
	while (tc--) {

		ll n, m, l, r;
		ll i, j;
		ll x, y;

		cin >> n;

		ll sum = 0;

		ll a[n];

		for (i = 0; i < n; i++) {
			cin >> a[i];
			sum += a[i];
			cnt[a[i]]++;
		}

		ll q;
		cin >> q;


		for (i = 0; i < q; i++) {

			ll b, c;
			cin >> b >> c;

			ll t = cnt[b];
			cnt[c] += t;
			cnt[b] = 0;

			sum = sum - t * b + t * c;

			cout << sum << endl;
		}





	}
}

Measured memory_bytes: 5176
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;


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

	int x, a, b;
	cin >> x >> a >> b;


	if(a >= b)
		cout << "delicious" << '\n';
	else if(x + a >= b)
		cout << "safe" << '\n';
	else
		cout << "dangerous" << '\n';

	return 0;
}


/*

*/

Measured memory_bytes: 256
n = int(input())
t , a = map(int, input().split())
h = list(map(int, input().split()))

tmp = max(h)
ans = 0
for i in range(len(h)):
  if abs(t - h[i] * 0.006 - a) <= tmp:
    ans = i + 1
    tmp = abs(t - h[i] * 0.006 - a)
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
void func(int,int);
char a[13][13];
int cnt;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(void)
{
	int i,j;
	while(scanf("%s",&a[0])!=EOF){
		for(i=1;i<12;i++) scanf("%s",a[i]);
		cnt=0;
		for(i=0;i<12;i++){
			for(j=0;j<12;j++){
				if(a[i][j]=='1'){
					cnt++;
					func(i,j);
				}
			}	
		}
		printf("%d\n",cnt);
	}
	return 0;
}
void func(int y,int x)
{
	int xx,yy,i;
	a[y][x]='0';
	for(i=0;i<4;i++){
		xx=x+dx[i]; yy=y+dy[i];
		if(xx<12&&xx>=0&&yy<12&&yy>=0&&a[yy][xx]=='1'){
			func(yy,xx);
		}
	}	
}

Measured memory_bytes: 2740
import java.util.Scanner;

/**
 * @Author: zhengtiantian
 * @Date: 19-3-28 下午3:58
 * @Description:
 */
public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        while (cin.hasNext()) {
            int n = cin.nextInt();
            int[] number = new int[n];
            for (int i = 0; i < n; i++) {
                number[i] = cin.nextInt();
                if (i == n -1) {
                    System.out.println(number[i]);
                    break;
                }
                System.out.print(number[i]+ " ");
            }
            // 枚举未排序
            for (int i = 1; i < n; i++) {
                int v = number[i];
                int j = i - 1;
                // 从已排序的集合中寻找空位插空
                while (j >= 0) {
                    if (number[j] > v) {
                        number[j + 1] = number[j];
                    } else {
                        break;
                    }
                    j--;
                }
                number[j + 1] = v;
                for (int z = 0; z < n; z++) {
                    if (z == n - 1) {
                        System.out.print(number[z]);
                        break;
                    }
                    System.out.print(number[z] + " ");
                }
                System.out.println();
            }

        }
    }

}



Measured memory_bytes: 32192
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	char x='a';
	char y;
	
	for(int i=0;i<300;i++){
		if(x=='a'){
			if(a.size()==0){y='a';break;}
			else{
				//for(int j=0;j<a.size()-1;j++)a[j]=a[j+1];
				x=a[0];
				a=a.substr(1);
			}
		}
		else if(x=='b'){
			if(b.size()==0){y='b';break;}
			else{
				//for(int j=0;j<b.size()-1;j++)b[j]=b[j+1];
				x=b[0];
				b=b.substr(1);
			}
		}
		else{
			if(c.size()==0){y='c';break;}
			else{
				//for(int j=0;j<c.size()-1;j++)c[j]=c[j+1];
				x=c[0];
				c=c.substr(1);
			}
		}
	}
	cout<<(char)(y-32)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); ++i)

using namespace std;

int main(){
  ll N, M, count, m;

  cin >> N >> M;

  vector<ll> A(M), B(M), X(N, -1), v;
  vector<vector<ll> > Y(N);

  rep(i, M){
    cin >> A[i] >> B[i];
  }

  rep(i, M){
    Y[A[i]-1].push_back(i);
    Y[B[i]-1].push_back(i);
  }


  v.push_back(1); //出口まで近い部屋から順に入れていく箱
  X[0] = 0;
  count = 1; //vがいくつ埋まったか
  rep(s, N){
    if(count == N) break;
    rep(i, Y[v[s]-1].size()){
      if(count == N) break;
      m = Y[v[s]-1][i];
      if (A[m] == v[s]) {
        if (X[B[m]-1] == -1) {
          v.push_back(B[m]);
          X[B[m]-1] = v[s];
          count++;
        }
      }else if (B[m] == v[s]) {
        if (X[A[m]-1] == -1) {
          v.push_back(A[m]);
          X[A[m]-1] = v[s];
          count++;
        }
      }
    }
  }

  cout << "Yes" << endl;
  for (ll i = 1; i < N; i++) {
    cout << X[i] << endl;
  }




  return 0;
}


Measured memory_bytes: 16712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H = sc.nextInt();
		int W = sc.nextInt();
		sc.close();
		int ans = (N - W + 1) * (N - H + 1);
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

struct Point{
	double x,y;
};


int main(){

	int n;
	scanf("%d",&n);
	double gaiseki,sum = 0;

	Point points[n];

	for(int i=0; i < n; i++){
		scanf("%lf %lf",&points[i].x,&points[i].y);
	}
	sum = points[n-1].x*points[0].y - points[n-1].y*points[0].x;
	for(int i=0; i < n-1; i++){
		gaiseki = points[i].x*points[i+1].y - points[i].y*points[i+1].x;
		sum += gaiseki;
	}

	printf("%.1lf\n",fabs(sum)/2);

    return 0;
}


Measured memory_bytes: 2728
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <array>

using namespace std;

class LISubsequence
{
public:
  int n;
  vector<int> a;
  vector<int> dp;
  LISubsequence(){}
  LISubsequence( int n ) : n(n), a(n) {}
  int solve();
};

int LISubsequence::solve()
{

  dp.push_back( a[0] );

  
  for ( auto i = 1; i < n; ++i )
    {
      if ( dp[dp.size() - 1] < a[i] )
        {
          dp.push_back( a[i] );
        }
      else
        {
          auto it = lower_bound( dp.begin(), dp.end(), a[i] );
          *it = a[i];
        }
    }

  cout << dp.size() << endl;
  
  return 0;
}

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

  LISubsequence lis(n);

  for ( auto i = 0; i < n; ++i )
    cin >> lis.a[i];

  lis.solve();

  return 0;
}

Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int ans=INF;
  int N=S.size();
  rep(i,0,26){
    char X=i+'a';
    string P=S;
    REP(_,0,N){
      string T;
      rep(j,0,P.size()-1){
        if(P[j]==X||P[j+1]==X) T+=X;
        else T+=P[j];
      }
      string Y=T+X;
      if(P==Y){
        ans=min(ans,_);
        break;
      }
      P=T;
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[200005];
int n, k;
bool check(ll x) {
  ll count = 0;
  for (int i = 0; i < n; i++) {
    count += a[i] / x - (a[i] % x == 0);
  }
  return count <= k;
}
int main() {
  cin >> n >> k;
  ll l, u;
  l = 1;
  u = 1000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  while (l <= u) {
    ll mid = (l + u) / 2;
    if (check(mid)) {
      u = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << l << endl;
}


Measured memory_bytes: 5172
#include <iostream>

using namespace std;

int main()
{
    string inp;

    while (cin >> inp, inp != "0") {
        int a, b;

        a = b = 0;
        for (int i = 1; i < inp.size(); i++) 
            inp[i] == 'A' ? a++ : b++;

        (a > b) ? a++ : b++;
        cout << a << " " << b << endl;
    }

    return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    string S;
    cin >> N >> S;
    string s2 = S.substr(N,N);
    reverse(s2.begin(), s2.end());
    string ss = S.substr(0,N) + s2;
    map< pair<string, string>, ll> mp1, mp2;
    rep(bit,0,pow(2,N)){
        string sr = "", sb = "";
        rep(i,0,N){
            if((bit>>i) & 1){
                sr += ss[i];
            }else{
                sb += ss[i];
            }
        }
        mp1[make_pair(sr, sb)]++;
        mp1[make_pair(sb, sr)]++;
    }
    rep(bit,0,pow(2,N)){
        string sr = "", sb = "";
        rep(i,0,N){
            if((bit>>i) & 1){
                sr += ss[N+i];
            }else{
                sb += ss[N+i];
            }
        }
        mp2[make_pair(sr, sb)]++;
        mp2[make_pair(sb, sr)]++;
    }
    ll ans = 0;
    for(auto &e: mp1){
        ans += e.second * mp2[e.first];
    }
    print(ans/4);
}


Measured memory_bytes: 78848
#include<iostream>
#include<string>

using namespace std;

int main() {
  string s; cin >> s;
  if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dbg(x) cerr << #x << " : " << x << endl;
int main(){
    string s;
    cin >> s;
    ll n=s.size();
    vector<vector<ll>> dp(n,vector<ll>(2));
    dp[n-1][0]=1;
    dp[n-1][1]=0;
    for(ll i=n-2;i>=0;i--){
        dp[i][0]=(s[i]==s[i+1]?dp[i+1][1]+1:dp[i+1][0]+1);
        if(i+2==n) dp[i][1]=1;
        else dp[i][1]=dp[i+2][0]+1;
    }
    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 11396
import sys
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

P = [i + a for i, a in enumerate(A, start=1)]
Q = [j - a for j, a in enumerate(A, start=1)]

res = 0
C = Counter(Q)
for p in P:
    res += C[p]

print(res)


Measured memory_bytes: 50436
package main

import (
	"fmt"
	"strconv"
)

func Amin(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func maxLen(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	var n int
	var min int = 10000000000
	fmt.Scan(&n)
	for i := 1; i <= Amin(n, 100000); i++ {
		is := strconv.Itoa(i)
		if n%i == 0 {
			j := n / i
			js := strconv.Itoa(j)
			f := maxLen(len(is), len(js))
			if f < min {
				min = f
			}
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    string s;
    cin>>s;
    if(s[0]==s[1]&&s[1]==s[2] || s[1]==s[2]&&s[2]==s[3]) puts("Yes");
    else puts("No");
    return 0;
}

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

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

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

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

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

ll dp[100010][3];
void solve(long long N, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c)
{
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    for (int i = 1; i <= N; i++)
    {
        dp[i][0] = max({dp[i][0], dp[i - 1][1] + a[i - 1], dp[i - 1][2] + a[i - 1]});
        dp[i][1] = max({dp[i][1], dp[i - 1][0] + b[i - 1], dp[i - 1][2] + b[i - 1]});
        dp[i][2] = max({dp[i][2], dp[i - 1][0] + c[i - 1], dp[i - 1][1] + c[i - 1]});
    }

    cout << max({dp[N][0],dp[N][1],dp[N][2]}) << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    std::vector<long long> c(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &a[i]);
        scanf("%lld", &b[i]);
        scanf("%lld", &c[i]);
    }
    solve(N, std::move(a), std::move(b), std::move(c));
    return 0;
}


Measured memory_bytes: 4992
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K,A[2001];
	scan(N>>K);
	rep(i,N) scan(A[i]);
	sort(A,A+N);
	int ans=0;
	rep(i,K) ans+=A[i];
	prin(ans);
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF = ll(1e18) +1;

int main() {
    ll N,K;
    cin >> N >>K ;
    vector<ll> x(N);
    for(int i=0;i<N;i++){
        cin >> x[i];
    }
    ll ans =INF;
    for(int i=K-1;i<N;i++){
        ll small = x[i+1-K];
        ll big = x[i];
        if(small <=0 && big<=0){
            ans = min(ans,abs(small));
        }
        if(small <=0 && big >0){
            ans = min(ans,min(abs(small)*2 +big,abs(small) + big*2));
        }
        if(small >0 && big >0){
            ans = min(ans,big);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef int64_t ll;
typedef long double ld; 

void solve() {
    ll n, m, x;
    cin >> n >> m >> x;
    ll c[n + 1], a[n + 1][m + 1];
    for(ll i = 1; i <= n; i++) {
        cin >> c[i];
        for(ll j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    ll cost = INT_MAX;
    for(ll i = 1; i < pow(2, n); i++) {
        ll u[m + 1] = {0}, tc = 0;
        for(ll j = 1; j <= 12; j++) {
            if(i & (1 << (j - 1))) {
                tc += c[j];
                for(ll k = 1; k <= m; k++) {
                    u[k] += a[j][k];
                }
            }
        }
        bool flag = true;
        for(ll k = 1; k <= m; k++) {
            if(u[k] < x) {flag = false; break;}
        }
        if(flag) cost = min(cost, tc);
    }
    if(cost != INT_MAX) cout << cost;
    else cout << "-1";
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4116
#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<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
using namespace std;


int main(){
    int N; cin >> N;
    string s,t; cin >> s >> t;
    vector<int> Num;

    for(int i = 0; i < N; i++){
        if(s[i] == t[i]){
            Num.push_back(1);
        }else{
            Num.push_back(0);
            i++;
        }
    }

    ll ans = 1;
    if(Num[0] == 1){
        ans *= 3;
    }else{
        ans *= 6;
    }

    if(Num.size() > 1){
        for(int i = 1; i < Num.size(); i++){
            if(Num[i-1] == 1){
                if(Num[i] == 1){
                    ans *=2;
                    ans %= MOD;
                }else{
                    ans *=2;
                    ans %= MOD;
                }
            }else{
                if(Num[i] == 1){
                    ans *=1;
                    ans %= MOD;
                }else{
                    ans *=3;
                    ans %= MOD;
                }
            }
        }
    }

    cout << ans << endl;
    sysp;
}

Measured memory_bytes: 504
#include <iostream>
using namespace std;

int main()
{
  int mount[11];
  for(int i=1; i<11; i++){
    cin >> mount[i];
  }

  for(int i=1; i<10; i++){
    for(int j=i+1; j<11; j++){
      if( mount[i] < mount[j] ){
	int temp;
	temp = mount[i];
	mount[i] = mount[j];
	mount[j] = temp;
      }
    }
  }

  cout << mount[1] << endl
       << mount[2] << endl
       << mount[3] << endl;
  return 0;
}

Measured memory_bytes: 1160
# coding: utf-8
# Your code here!

N=int(input())
C = list(map(int,input().split()))

a=sorted(C)

M=a[-1]


A=sorted([abs(2*i - M) for i in a])
#print(C)
#print(a)
#print(A)
N1= (-A[0]+M)//2
N2= (A[0]+M)//2
#print(N1,N2)
j = C.index(M)
if N1 in a:
    print(M,N1)
else:
    print(M,N2)





Measured memory_bytes: 14052
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others

//Hang in there!

using namespace std;


int main() {
	double H, N;
	cin >> H >> N;
	vector<int>data(N);
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> data[i];
		sum += data[i];
	}
	if (H <= sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector <int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (i + 1 != p[i]) {
            if (p[p[i] - 1] == i + 1) {
                count++;
            } else {
                cout << "NO" << endl;
                return 0;
            }
        }
    }

    if (count <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int main(){
    int n, k;
    cin >> n >> k;
    int si[n];
    rep(i, 0, n) cin >> si[i];

    int wa[n+1];
    rep(i, 0, n) wa[i+1] = wa[i] + si[i];

    int Max = 0;
    int Left = 0, Right = 0;
    rep(i, 0, n-k+1)
    {
        int Next = wa[i+k] - wa[i];
        if (Max < Next)
        {
            Max = Next;
            Left = i+k;
            Right = i;
        }
    }

    double kitai = 0;  
    rep(j, Right, Left)
    {
        double goukei = (si[j] * (si[j] + 1) / 2);
        kitai += (double)(goukei / si[j]);
    }
    printf("%.9f", kitai);
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

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

	int sum = 0, a;
	int as[n];
	for (int i = 0; i < n; i ++) {
		cin >> a;
		sum += a;
		as[i] = a;
	}

	int rt = sqrt(sum);
	vector<int> cds;
	for (int i = 1; i <= rt; i ++) {
		if (sum % i == 0) {
			cds.push_back(i);
		}
	}

	int total = cds.size();
	for (int i = total-1; i >= 0; i --) {
		int j = cds[i];
		cds.push_back(sum/j);
	}

	vector<int> mods;
	total = cds.size();
	for (int i = total-1; i >= 0; i -- ) {
		mods.clear();
		int cd = cds[i];
		int mod_sum = 0;
		for (int j = 0; j < n; j ++) {
			int tmp = as[j] %cd;
			mods.push_back(tmp);
			mod_sum += tmp;
		}

		int num = mod_sum / cd;
		sort(mods.begin(), mods.end(), greater<int>());


		int srcs = 0;
		for (int i = 0; i < num; i ++) {
			srcs += mods[i];
		}
		if (k >= mod_sum - srcs) {
			cout << cd << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll MOD=1e9+7 ;
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; }

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    priority_queue<double> que;
    int n,m;cin >> n >> m;
    rep(i,n){
        double tmpx;
        cin  >> tmpx;
        que.push(tmpx);
    }

    rep(i,m)
    {
        double tmpy = que.top();
        que.pop();
        tmpy /= 2;
        que.push(tmpy);
    }
    ll ans = 0;
    rep(i,n)
    {
        ll tmpz = que.top();
        que.pop();
        ans += tmpz;
    }
    cout<< ans << endl;

}


Measured memory_bytes: 1400
def main
  tables = []

  loop do
    table_number = gets.chomp.to_i
    break if table_number == 0

    tables << Table.new.create_table(table_number)
  end

  tables.each do |table|
     table.print_table
  end
end

class Table
  def initialize
    @table = []
    @total_table = []
  end

  def create_table table_number
    table_number.times do
      @table << gets.chomp.split(' ').map(&:to_i)
    end
   self
  end

  def print_table
    @total_table = @table

    total_row
    total_line
    print_right_justification(5)
  end

  private
  def total_row
    @total_table.each do |line|
      line.push(line.inject(0) {|sum, i| sum + i.to_i})
    end
  end

  def total_line
    total_line = []
    @total_table.transpose.each do |row|
      total_line << row.inject(:+)
    end

    @total_table.push(total_line)
  end

  def print_right_justification number
    @total_table.each do |line|
      print_line = []
      line.each{|item| print_line << item.to_s.rjust(number)}
      puts print_line.join()
    end
  end
end

main

Measured memory_bytes: 6124
#include<iostream>
using namespace std;
int main()
{
	int n,m,k,a,c=0,f[31]={0};
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>k;
		for(int j=0;j<k;j++)
		{
			cin>>a;
			f[a]++;
		}
	}
	for(int i=1;i<=m;i++)if(f[i]==n)c++;
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){

	int h, w;
	while( cin >> h >> w, h|w ){
		pii ans={1e3, 1e3};
		rep(i,155) rep(j,155) if(i>0 && j>0) if( i < j ){
			if( h*h + w*w < i*i + j*j || ( h*h + w*w == i*i + j*j && h < i)){
				if( ans.X*ans.X + ans.Y*ans.Y > i*i + j*j ){
					ans = pii(i, j);
				}else if( ans.X*ans.X + ans.Y*ans.Y == i*i + j*j &&
							ans.X > i ){
					ans = pii(i, j);
				}
			}
		}
		cout << ans.X << " " << ans.Y << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：Areas on the Cross-Section Diagram
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_3_D
// 所要時間：2時間
// 学んだこと：しんどかった．stackが便利なことはよくわかった．
//  stackを2つではなく1つでできないかと考えていたが，もう疲れたのでACしただけで満足することにした．
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
string terrain;
stack<ll> s;
stack<pair<ll, ll>> s2;
vll areas;

void solve() {
  ll area = 0;
  rep(i, terrain.size()) {
    if (terrain[i] == '\\') {
      s.push(i);  // 下りが来たらスタックに追加
    } else if (terrain[i] == '/') {
      if (!s.empty()) {
        ll j = s.top();
        area = i - j; // 対応する上りとの間でできる面積を計算
        // cout << "j:" << j << " i:" << i << " area:" << area << endl;
        s.pop();  // 対応する上りを取り除く
        if (!s2.empty()) {  // 水溜りの結合
          while (!s2.empty() && s2.top().first > j) {
            area += s2.top().second;
            s2.pop();
          }
        }
        s2.push(make_pair(j, area));  // 結合した水溜りを追加

        /*
        if (s.empty()) {
          areas.push_back(area);
          area = 0;
        }
        */
      }
    }
  }

  // 集計・出力
  // stackのままだと扱いにくいのでvectorにうつす
  while (!s2.empty()) {
    areas.push_back(s2.top().second);
    s2.pop();
  }
  reverse(areas.begin(), areas.end());
  ll k = areas.size();
  ll areaSum = 0;
  rep(i, k) { areaSum += areas[i]; }
  cout << areaSum << endl;
  if (k != 0) {
    cout << k << " ";
  } else {
    cout << k;
  }
  rep(i, k) {
    cout << areas[i];
    if (i != k - 1) { cout << " "; }
  }
  cout << endl;
}

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



Measured memory_bytes: 3272
main :: IO ()

main = do
    s <- getLine :: IO String
    let n = length s
    let ans = solve n s
    let result = if fst ans == snd ans then (-1,-1) else ans
    putStr $ show $ fst result
    putStr " "
    putStr $ show $ snd result

solve :: Int -> String -> (Int,Int)
solve n (x:xs) =
    if n == 1
        then
            (-1,-1)
        else
            if x == xs !! 0
                then
                    (1,2)
            else if n >= 3 && x == xs !! 1
                then
                    (1,3)
                else
                    (1 + fst t,1 + snd t)
                        where
                            t = solve (n - 1) xs
                    

Measured memory_bytes: 15740
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)


constexpr int MAX_V = 101010;
int V, E;
vector<int> G[MAX_V];  //グラフの隣接リスト表現
vector<int> rG[MAX_V]; //辺の向きを逆にしたグラフ
vector<int> vs;        //帰りがけ順の並び
bool used[MAX_V];      //すでに調べたか
int cmp[MAX_V];        //属する強連結成分のトポロジカル順序

void add_edge(int from, int to) {
	G[from].push_back(to);
	rG[to].push_back(from);
}

void dfs(int v) {
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		if (!used[G[v][i]])dfs(G[v][i]);
	}
	vs.push_back(v);
}

void rdfs(int v, int k) {
	used[v] = true;
	cmp[v] = k;
	for (int i = 0; i < rG[v].size(); i++) {
		if (!used[rG[v][i]])rdfs(rG[v][i], k);
	}
}

int scc() {
	memset(used, 0, sizeof(used));
	vs.clear();
	for (int v = 0; v < V; v++) {
		if (!used[v])dfs(v);
	}
	memset(used, 0, sizeof(used));
	int k = 0;
	for (int i = vs.size() - 1; i >= 0; i--) {
		if (!used[vs[i]])rdfs(vs[i], k++);
	}
	return k;
}

int main() {
	cin >> V >> E;
	REP(i, E) {
		int s, t;
		cin >> s >> t;
		add_edge(s, t);
	}
	scc();

	int q;
	cin >> q;
	REP(qqq, q) {
		int u, v;
		cin >> u >> v;
		cout << (cmp[u] == cmp[v] ? 1 : 0) << endl;
	}
}


Measured memory_bytes: 9064
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll H,W,N;
map<ll,map<ll,ll>> cnt;
set<pll> se;
void input(){
    fast_io();
    cin >> H >> W >> N;
    for (int i = 0; i < N; i++)
    {
        ll a,b; cin >> a >> b;
        a--,b--;
        cnt[a][b]++;
        se.insert(make_pair(a,b));
        for (int k = 0; k < 8; k++)
        {
            ll x = a+dx[k];
            ll y = b+dy[k];
            if(x<0 || x>=H) continue;
            if(y<0 || y>=W) continue;
            cnt[x][y]++;
            se.insert(make_pair(x,y));
        }
    }
}

int solve(){
    vector<ll> ans(10,0);
    // for(auto px:cnt) for(auto p:px.second) {ans[p.second]++;DBG(px.first)DBG(p.first)DBG(p.second)}
    for(auto itr=se.begin();itr!=se.end();itr++){
        if(itr->first==0 || itr->first==H-1) continue;
        if(itr->second==0 || itr->second==W-1) continue;
        ans[cnt[itr->first][itr->second]]++;
    }
    ll zero = (H-2)*(W-2);
    for (int i = 1; i < 10; i++)
    {
        zero -= ans[i];
    }
    ans[0] = zero;
    for (int i = 0; i < 10; i++)
    {
        cout << ans[i] << endl;
    }
    
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr LL mod = 998244353;
constexpr int maxn = 100000;
int N, sg[maxn + 1], s[maxn + 1];
LL p[maxn + 1];
vector<int> G[maxn + 1];
vector<LL> g(){
    vector<LL> res;
    int M;
    cin >> M;
    for(int i = 1; i <= N; i += 1) G[i].clear();
    for(int i = 0, u, v; i < M; i += 1){
        cin >> u >> v;
        if(u > v) swap(u, v);
        G[u].push_back(v);
    }
    for(int i = N; i; i -= 1){
        sg[i] = 0;
        for(int v : G[i]) s[sg[v]] = 1;
        while(s[sg[i]]) sg[i] += 1;
        for(int v : G[i]) s[sg[v]] = 0;
        if(res.size() <= sg[i]) res.resize(sg[i] + 1);
        res[sg[i]] = (res[sg[i]] + p[i]) % mod;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> N;
    p[1] = 1000000000000000000LL % mod;
    for(int i = 2; i <= N; i += 1) p[i] = p[i - 1] * p[1] % mod;
    auto g1 = g();
    auto g2 = g();
    auto g3 = g();
    LL ans = 0;
    for(int i = 0; i < (int)g1.size(); i += 1)
        for(int j = 0; j < (int)g2.size(); j += 1){
            int k = i ^ j;
            if(k < (int)g3.size()) ans += g1[i] * g2[j] % mod * g3[k] % mod;
        }
    cout << ans % mod;
    return 0;
}


Measured memory_bytes: 6400
import sys
import itertools
import queue
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, M = read_values()
    A = read_list()
    A.sort(reverse=True)
    S = sum(A)
    print("Yes" if A[M - 1] * M * 4 >= S else "No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 21688