akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;





int main() 
{
  ll N,M; cin>>N>>M;
  if(N>=M) {cout<<0<<endl; return 0;}
  vector<ll> X(M);
  rep(i,M)
  {
    cin>>X.at(i);
  }
  sort(X.begin(),X.end());
  ll all=0;
  vector<ll> sa(M-1);
  rep(i,M-1)
  {
    sa.at(i)=X.at(i+1)-X.at(i);
    all+=sa.at(i);
  }
  sort(sa.rbegin(),sa.rend());
  rep(i,N-1)
  {
    all-=sa.at(i);
  }
  cout<<all<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
int a,b,c,d,s,t;
s=0;t=0;
scanf("%d %d %d %d",&a,&b,&c,&d);
s=a+b+c+d;
scanf("%d %d %d %d",&a,&b,&c,&d);
t=a+b+c+d;
if(t<=s){printf("%d\n",s);}else{printf("%d\n",t);}
return 0;

}

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

typedef long long ll;
typedef pair <int , int> pii;
typedef long double ld;

const int N = 1e6+10 , mod = 1e9+7 , M = 26;

int nxt[N][M] , cnt[N][M] , id = 1;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   string s[n];
   for(int i = 0 ; i < n ; i++){
      cin >> s[i];
      int m = s[i].length();
      int cur = 0;
      for(int j = m - 1 ; j > 0 ; j--){
         if(!nxt[cur][s[i][j] - 'a']){
            nxt[cur][s[i][j] - 'a'] = id++;
         }
         cur = nxt[cur][s[i][j] - 'a'];
      }
      cnt[cur][s[i][0] - 'a']++;
   }
   ll ans = 0;
   for(int i = 0 ; i < n ; i++){
      int m = s[i].length();
      int cur = 0;
      int num[26];
      memset(num , 0 , sizeof(num));
      for(int j = 0 ; j < m ; j++)
         num[s[i][j] - 'a']++;
      for(int j = m - 1 ; j >= 0 ; j--){
         for(int k = 0 ; k < 26 ; k++){
            if(num[k])
               ans += cnt[cur][k];
         }
         cur = nxt[cur][s[i][j] - 'a'];
         num[s[i][j] - 'a']--;
      }
   }
   ans -= n;
   cout << ans;
   return 0;
}


Measured memory_bytes: 154420
from collections import deque
from itertools import combinations
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]

def dfs(d, a, b, c):
    if d == N:
        # A,B,Cの竹それぞれで最初の１回は合成していないため30引く
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c)> 0 else 10**9
    
    p1 = dfs(d+1, a, b, c)
    p2 = dfs(d+1, a+L[d], b, c) + 10
    p3 = dfs(d+1, a, b+L[d], c) + 10
    p4 = dfs(d+1, a, b, c+L[d]) + 10
    
    return min(p1, p2, p3, p4)
    
print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
 
using namespace std;  
 
typedef long long ll;
typedef long double ld;
 
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rs resize
#define all(x) x.begin(), x.end()   
 
void pre(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void pudge(){
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 == 12 && m2 == 1){
        cout << 1;
        return;
    }
    if (m2 == m1 + 1)
        cout << 1;
    else
        cout << 0;
}
 
int main(){ 
    pre();
    pudge();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char a,b,c;
    cin>>a>>b>>c;
    if(a==c||a==b||b==c)
    cout << "No" <<' ';
    else if(a!=c&&a!=b&&b!=c)
    cout << "Yes" <<' ';
    else
    cout << "No" <<' ';
    return 0;
}


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

public class Main
{
	public static void main(String[] Arguments) throws IOException 
	{
		BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
		char C = BR.readLine().charAt(0);
		switch (C)
		{
		case 'A':
			System.out.println("T");
			break;
		case 'T':
			System.out.println("A");
			break;
		case 'C':
			System.out.println("G");
			break;
		case 'G':
			System.out.println("C");
			break;
		}
	}
}


Measured memory_bytes: 32496
l, r = gets.chomp.split().map(&:to_i)
ans = 2020

if l.div(2019) < r.div(2019)
  ans = 0
else
  l.upto(r) do |n|
    (n + 1).upto(r) do |m|
      a = (n * m) % 2019
      ans = a if a < ans
    end
  end
end

puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int count = 0;
	for (int i = 1; i < n - 1; i++) {
		if (p[i + 1] > p[i] && p[i - 1] < p[i]) {
			count++;
		}
		else if (p[i + 1] < p[i] && p[i - 1] > p[i]) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

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

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

  // 素因数分解する
  vector<pair<ll, int>> f;
  for (ll i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt != 0) f.emplace_back(i, cnt);
  }
  if (n != 1) f.emplace_back(n, 1);

  // 答えを求める
  int ans = 0;
  for (auto p : f) {
    int x = p.second;
    int a = 1;
    while (x >= a) {
      x -= a;
      a++;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
# -*- coding: utf-8 -*-

#約数列挙（ググってでてきたやつ）
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#入力
N_given = int(input())

#見つけたKのリスト
list_found_K = []


#パターン1 
divisors_N_minus_1 = make_divisors(N_given-1)
#みつけたKを追加
for divs in divisors_N_minus_1:
	if divs != 1:
		list_found_K.append(divs)

#パターン2
#K候補（Nの約数）
divisors_N = make_divisors(N_given)
divisors_N.remove(1)

#全てのN候補で試行
for candidate_K in divisors_N:
	N_wk = N_given
	#Kで割り尽くす
	while N_wk % candidate_K == 0:
		N_wk //=candidate_K

	#パターン1風　1引いてK候補で割れたらKに正式採用
	if (N_wk-1) % candidate_K == 0:
		list_found_K.append(candidate_K)

print(len(list_found_K))


Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

typedef pair<int,int> par;

const int N=200010;

int n,x,y,cnt,a[N],b[N],G[N];
int fa[N][20];
struct edge{
  int t,nx;
}E[N<<2];

inline void addedge(int x,int y){
  E[++cnt].t=y; E[cnt].nx=G[x]; G[x]=cnt;
  E[++cnt].t=x; E[cnt].nx=G[y]; G[y]=cnt;
}

int dpt[N];

void dfs(int x,int f){
  if(f) dpt[x]=dpt[f]+1;
  fa[x][0]=f; for(int i=1;i<=18;i++) fa[x][i]=fa[fa[x][i-1]][i-1];
  for(int i=G[x];i;i=E[i].nx)
    if(E[i].t!=f) dfs(E[i].t,x);
}

namespace Grp{
  int cnt,G[N];
  struct edge{
    int t,nx;
  }E[N<<1];

  inline void addedge(int x,int y){
    E[++cnt].t=y; E[cnt].nx=G[x]; G[x]=cnt;
    E[++cnt].t=x; E[cnt].nx=G[y]; G[y]=cnt;
  }
}

queue<int> Q;
int dis[N],mark[N];

const int inf=1<<29;

inline void bfs(){
  for(int i=1;i<=n;i++) dis[i]=inf;
  Q.push(x); dis[x]=0;
  while(!Q.empty()){
    int x=Q.front(); Q.pop();
    for(int i=Grp::G[x];i;i=Grp::E[i].nx){
      int v=Grp::E[i].t;
      if(dis[x]+1>=dis[v]) continue;
      if(dis[x]+1>=dpt[v]) continue;
      dis[v]=dis[x]+1; Q.push(v);
    }
  }
}

inline int lca(int x,int y){
  if(dpt[x]<dpt[y]) swap(x,y);
  for(int i=18;~i;i--)
    if(dpt[fa[x][i]]>=dpt[y]) x=fa[x][i];
  if(x==y) return x;
  for(int i=18;~i;i--)
    if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
  return fa[x][0];
}

inline int dist(int x,int y){
  return dpt[x]+dpt[y]-2*dpt[lca(x,y)];
}

int main(){
  scanf("%d%d%d",&n,&x,&y);
  for(int i=1;i<n;i++)
    scanf("%d%d",&a[i],&b[i]);
  for(int i=1,u,v;i<n;i++)
    scanf("%d%d",&u,&v),addedge(u,v);
  dfs(y,0); dpt[0]=-1;
  for(int i=1;i<n;i++)
    if(dist(a[i],b[i])>2) mark[a[i]]=mark[b[i]]=1;
    else Grp::addedge(a[i],b[i]);
  bfs(); int ans=0;
  if(mark[x]) return puts("-1"),0;
  for(int i=1;i<=n;i++){
    if(mark[i] && dis[i]<dpt[i]) return puts("-1"),0;
    if(dis[i]<dpt[i]) ans=max(ans,dpt[i]*2);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 34304
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {
	if (a > b) a = b;
}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {
	if (a < b) a = b;
}
typedef pair<int, int> pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 200020;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;


void solve() {
	int S, W; cin >> S >> W;
	if (W >= S)print("unsafe");
	else print("safe");
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// int q; cin >> q;
	// while (q--)
	solve();
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    string S;
    cin >> S;
    REP(i,S.size()){
        if(S[i]=='1'){
            cout << 9;
        }else if(S[i]=='9'){
            cout << 1;
        }else{
            cout << S[i];
        }
    }cout << endl;
    
    return 0;
}   


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

using namespace std;

typedef long long ll;

int main(){
	string s;
	cin >> s;
	vector<int> a;
	for(int i = 0; i < s.size(); i++){
		a.push_back(s[i]-'0');
		while(a.size() > 1 && abs(a[a.size()-1]-a[a.size()-2]) > 0)a.erase(a.begin()+a.size()-1), a.erase(a.begin()+a.size()-1);
	}
	cout << (int)s.size()-(int)a.size() << endl;
	return 0;
}

Measured memory_bytes: 1020
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   int ans = 0;
   f(i,0,n){
      int x;
      cin >> x;
      if(i % 2 == 0){
         if(x & 1) ans++;
      }
   }
   cout << ans;
   return 0;
} 

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int a[200100],n;
bool check(int x){
    for(int i=0;i<=n-1;i++){
        if((a[n-i]<x&&a[n-i-1]<x)||(a[n+i]<x&&a[n+i+1]<x))
            return false;
        if((a[n-i]>=x&&a[n-i-1]>=x)||(a[n+i]>=x&&a[n+i+1]>=x))
            return true;
    }
    return a[2*n-1]>=x;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=2*n-1;i++){
        scanf("%d",&a[i]);
    }
    int l=1,r=2*n-1,ans=0;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid))
            l=mid+1,ans=mid;
        else
            r=mid-1;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 4556
import bisect
import sys
input=sys.stdin.readline
N,Q=map(int,input().split())
STX=[list(map(int,input().split())) for i in range(N)]
STX.sort(key=lambda x:x[2])
ans=[-1]*Q
jump=[-1]*Q
D=[int(input()) for i in range(Q)]
for s,t,x in STX:
    l=bisect.bisect_left(D,s-x)
    r=bisect.bisect_left(D,t-x)
    while(l<r):
        k=jump[l]
        if k==-1:
            ans[l]=x
            jump[l]=r
            l+=1
        else:
            l=k
for i in range(Q):
    print(ans[i])


Measured memory_bytes: 108636
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define V vector
#define P pair
#define M map
#define F first()
#define S second()
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

int main(){
    sts(a);sts(b);
    cout << ((a==b)? "H" : "D") << endl;
    return 0;
}


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

ll solve() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = N/(A+B) * A;
    ll r = N % (A+B);
    if ( r <= A ) {
        ans += r;
    } else {
        ans += A;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int MOD = 1e9+7;
const long long INF = 1LL << 60;
const int INF_INT = 1e9;
typedef long long ll;

int N, A, B, C;
vector<int> len(20); //Nの制約を見る

int dfs(int cur, int a, int b, int c){
    if(cur==N){
        if(!a || !b || !c){
            return INF_INT;
        }
        return abs(A-a)+abs(B-b)+abs(C-c);
    }
    int ans = INF_INT;
    ans = dfs(cur+1, a, b, c);
    ans = min(ans, dfs(cur+1, a+len[cur], b, c) + (a?10:0));
    ans = min(ans, dfs(cur+1, a, b+len[cur], c) + (b?10:0));
    ans = min(ans, dfs(cur+1, a, b, c+len[cur]) + (c?10:0));
    return ans;
}
int main(){
    cin >> N >> A >> B >> C;
    rep(i,N) {
        cin >> len[i];
    }
    cout << dfs(0,0,0,0) << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main{
    public static void main(String[] args)throws IOException{
	final BufferedReader br=new BufferedReader(new InputStreamReader(System.in));	
	while(true){
	    String[] str=br.readLine().split(" ");
	    int a = Integer.parseInt(str[0]);
	    String op=str[1];
	    int b=Integer.parseInt(str[2]);
	    if(op.equals("?")) break;
	    if(op.equals("+")) System.out.println((a+b));
	    else if(op.equals("-")) System.out.println((a-b));
	    else if(op.equals("*")) System.out.println((a*b));
	    else if(op.equals("/")) System.out.println((a/b));    
	}
    }
}

Measured memory_bytes: 16920
str = gets.chomp
q = gets.to_i
q.times do
  cmd = gets.split
  if cmd[0] == 'print'
    puts str[cmd[1].to_i..cmd[2].to_i]
  elsif cmd[0] == 'reverse'
    str[cmd[1].to_i..cmd[2].to_i] = str[cmd[1].to_i..cmd[2].to_i].reverse
  else
    str[cmd[1].to_i..cmd[2].to_i] = cmd[3]
  end
end



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

int compar(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;
}

int main () {
	int N;
	scanf("%d", &N);
	int *A = malloc(N * sizeof(int));
	int *exists = calloc(1, 1000000 * sizeof(int));
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		exists[A[i]] += 1;
	}

	// ソートする
	qsort(A, N, sizeof(int), compar);

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int warikireta = 0;
		// 同じ数字が存在する場合は、割り切れる
		if (exists[A[i]] > 1)
			continue;
		for (int j = 0; j < i; j++) {
			if ((A[i] / 100) < A[j]) {
				int k = 2;
				while (k < 100) {
					if (A[i] % k == 0 && exists[A[i] / k]) {
						warikireta = 1;
						break;
					}
					k++;
				}
				break;
			}
			// 2のチェック
			//if ((A[i] / 2) < A[j])
			//	break;
			//// 3の倍数チェック
			//if ((A[i] / 3) < A[j]) {
			//	// A[j]がA[i]を3で割った値より大きい場合割り切れる可能性があるのは
			//	// A[i] / 2のみ
			//	if (A[i] % 2 == 0 && exists[A[i] / 2]) {
			//		warikireta = 1;
			//		break;
			//	} else {
			//		break;
			//	}
			//}
			//// 5の倍数チェック
			//if ((A[i] /5) < A[j]) {
			//	if (A[i] % 2 == 0 && exists[A[i] / 2]) {
			//		warikireta = 1;
			//		break;
			//	} else if (A[i] % 3 == 0 && exists[A[i] / 3]) {
			//		warikireta = 1;
			//		break;
			//	} else if (A[i] % 4 == 0 && exists[A[i] / 4]) {
			//		warikireta = 1;
			//		break;
			//	} else {
			//		break;
			//	}
			//}

			if (A[i] % A[j] == 0) {
				warikireta = 1;
				break;
			}
		}
		if (warikireta == 0)
			ans++;
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 7036
#include<bits/stdc++.h>
#include<atcoder/dsu>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n, q;
  cin >> n >> q;
  atcoder::dsu uf(n);

  rep(i, q) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0) {
      uf.merge(u, v);
    } else {
      int ans = 0;
      if (uf.same(u, v)) ans = 1;
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N;
    cin >> N;

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

    map<int, int> mp;
    int num;
    for (int i = 0; i < N; i++)
    {
        num = a[i];
        mp[num + 1]++;
        mp[num]++;
        mp[num - 1]++;
    }

    int ans = -1;
    for (auto iter = mp.begin(); iter != mp.end(); iter++)
    {
        ans = max(ans, iter->second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5120
import sys
input = sys.stdin.readline
import bisect
def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            idx = bisect.bisect_left(L, L[i]+L[j], j+1, N)
            ans += idx-j-1
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 42844
#include<iostream>
using namespace std;
int main(void){
  int a,b,c,m,x,y,z;
  cin>>a>>b>>c;
  x=10*a+b+c;
  y=10*b+a+c;
  z=10*c+a+b;
  if(x>y){
    m=x;
  }else{
    m=y;
  }
  if(m>z){
    cout<<m<<endl;
  }else{
    m=z;
    cout<<m<<endl;
  }
  return 0;
}

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

#define pii pair<int, int>
#define vii vector<pii>
#define ll long long
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)

int main() {
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	int counter = 0;
	for(int i = 0; i < n; i++) {
		int temp;
		scanf("%d", &temp);
		if(temp < a || temp >= b) {
			counter++;
		}
	}
	printf("%d\n", counter);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
void collect(ll number, ll limit, vector<ll>& nums) {
  if(number > limit) {
    return;
  } else {
    if(number != 0) {
      auto n_str = to_string(number);
      if(n_str.find('3') != string::npos && n_str.find('5') != string::npos &&
         n_str.find('7') != string::npos) {
        nums.push_back(number);
      }
    }
    auto nn = number * 10;
    for(auto n : {3, 5, 7}) {
      collect(nn + n, limit, nums);
    }
  }
}

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

  vector<ll> nums;
  collect(0LL, N, nums);
  cout << nums.size() << endl;
  return 0;
}

Measured memory_bytes: 640
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

	public void Proc()
	{
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

        int mamonoCount = (int)inpt[0];
        this.BigDamage = inpt[1];
        this.SmallDamage = inpt[2];

        SortedDictionary<long, int> mons = new SortedDictionary<long, int>();

        for (int i = 0; i < mamonoCount; i++) {
            long mon = long.Parse(Reader.ReadLine());
            if(mons.ContainsKey(mon)) {
                mons[mon]++;
            } else {
                mons.Add(mon, 1);
            }
        }
        long minKaisu = mons.First().Key / BigDamage;
        long maxKaisu = mons.Last().Key / SmallDamage + 1;

        long ans = GetAns(minKaisu, maxKaisu, mons);
        Console.WriteLine(ans);
    }

    private long GetAns(long min, long max, SortedDictionary<long, int> dic) {
        if(max-min <= 1) {
            if(CanBuild(min, dic)) {
                return min;
            }
            return max;
        }
        long mid = (max + min) / 2;
        if(CanBuild(mid, dic)) {
            return GetAns(min, mid, dic);
        } else {
            return GetAns(mid, max, dic);
        }
    }

    private bool CanBuild(long target , SortedDictionary<long, int> dic) {
        long diff = BigDamage - SmallDamage;
        long tmp = (long)dic.Where(a => a.Key > SmallDamage * target).Select(a => Math.Ceiling(((decimal)a.Key - (SmallDamage*target)) / (BigDamage - SmallDamage)) * a.Value).Sum();
        return tmp <= target;
    }


    private long SmallDamage;
    private long BigDamage;


	public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


2 10 4
20
20


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 24788
#include <cctype>
#include <iostream>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    char s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    s[k-1]=tolower(s[k-1]);
    for(int i=0;i<n;i++){
        std::cout << s[i];
    }
}


Measured memory_bytes: 3608
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<Element> set = new TreeSet<>();
        for (int i = 1; i <= n; i++) {
            int seq = sc.nextInt();
            set.add(new Element(i, seq));
        }
//        System.out.println(set);
        String ans = set.stream().map(e -> String.valueOf(e.no)).collect(Collectors.joining(" "));
        System.out.println(ans);

        sc.close();
    }

    static class Element implements Comparable<Element> {
        int no; // 出席番号
        int seq; // 到着順序

        public Element(int no, int seq) {
            this.no = no;
            this.seq = seq;
        }

        @Override
        public int compareTo(Element o) {
            return seq - o.seq;
        }

        @Override
        public String toString() {
            return "no=" + no + ", seq=" + seq;
        }
    }
}


Measured memory_bytes: 69616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main() {
  int A, B, M;
  std::cin >> A >> B >> M;
  std::vector<int> a(A);
  std::vector<int> b(B);
  for (int i = 0; i < A; i++) {
    std::cin >> a.at(i);
  }
  for (int i = 0; i < B; i++) {
    std::cin >> b.at(i);
  }
  int a_min = *std::min_element(a.begin(), a.end());
  int b_min = *std::min_element(b.begin(), b.end());
  int min_cost = a_min + b_min;
  for (int i = 0; i < M; i++) {
    int x, y, c;
    std::cin >> x >> y >> c;
    x--;
    y--;
    min_cost = std::min(min_cost, a[x] + b[y] - c);
  }
  std::cout << min_cost << std::endl;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  u64 size = s.size();
  u64 ret = 0;
  for (u64 i = 1; i < size; ++i) {
    if (s[i] != s[i-1]) ret++;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 512
import Data.Char

solver::Int->Int->String->String
solver a b s = let (as,h:bs)  = splitAt a s in
               let bo = (and (map isDigit as))&&(and (map isDigit bs))&&(h=='-')&&(length bs == b) in
               if bo then "Yes\n" else "No\n"

main::IO()
main=do
  abc<-getLine
  let a:b:[]=map read (words abc)
  s<-getLine
  putStr (solver a b s)

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((abs(b - a) <= d && abs(c - b) <= d) || abs(c - a) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

bool is_square(int n){
  for (int i=0; i<sqrt(n)+1; i++){
    if (i*i == n) return true;
  }
  return false;
}

int main(){
  int N, D;
  vector<vi> X(11, vi(11));

  cin >> N >> D;
  for(int i=0;i<N; i++){
    for(int j=0; j<D; j++){
      cin >> X[i][j];
    }
  }

  int cnt = 0;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      int dist = 0;
      for(int k=0; k<D; k++){
        dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }
      if(is_square(dist)) cnt++;
    }
  }

  cout << cnt << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	string s; cin>>s;
	int g = 0, p = 0;
	int ans = 0;
	for(auto ch : s){
		if(ch == 'g'){
			if(p + 1 <= g){
				ans++; p++;
			}else{
				g++;
			}
		}else{
			if(p + 1 <= g){
				p++;
			}else{
				ans--; g++;
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}

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

int main(){
    int c[3][3], a[3], b[3];

    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            scanf("%d",&c[i][j]);
        }
    }

    b[0] = c[0][0];
    b[1] = c[0][1];
    b[2] = c[0][2];

    a[0] = 0;
    a[1] = c[1][1] - b[1];
    a[2] = c[2][2] - b[2];

    bool isCorrect = true;

    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            if(a[i] + b[j] != c[i][j])
                isCorrect = false;
        }
    }

    if(isCorrect)
        puts("Yes");
    else
        puts("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll, ll> pii;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
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 A, B, K;
int main()
{
    cin >> A >> B >> K;
    int temp = min(A, B);
    vi ans;
    int cnt = 0;
    REP(i, temp + 1)
    {
        if ((A % (i + 1) == 0) && (B % (i + 1) == 0))
        {
            cnt++;
            ans.push_back(i + 1);
        }
    }
    cout << ans[ans.size() - K] << endl;
    // system("pause");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IO std::ios::sync_with_stdio(false);std::cin.tie(0)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mset(s,_) memset(s,_,sizeof s)
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define mk make_pair
using namespace std;
int a[200010];
int main(){
  int n;
	cin>>n;
	ll ans=1;
	int w1=0,w2=0;
	for(int i=1;i<=n;i++){
		ll tp;
		cin>>tp;
		if(tp==0) w2=1;
		if(!w1){
		ans=ans*tp;
		if(ans<=0||ans>(long long)(1e18))
		  w1=1;
	  }
	}
	if(w2) cout<<0<<'\n';
	else if(w1) cout<<-1<<'\n';
	else cout<<ans<<'\n';
}



Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl '\n'
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int is_square(int n){
   double x=sqrt(n);
   return (x-floor(x)==0);
}
void solve(){
    int a,b,c,x;
    int cnt=0;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++){
	  for(int j=0;j<=b;j++){
		 for(int k=0;k<=c;k++){
			  cnt+=(i*500+j*100+k*50==x); 
			} 
		 }	
	}
	cout<<cnt<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int n;
    scanf("%d",&n);
    int m;
    scanf("%d",&m);


    int ans = 0;
    srep(i,1,m-n+1){
        ans+=i;
    }
    ans -= m;
    
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
import java.io.IOException; 
import java.io.InputStream; 
import java.io.PrintWriter; 

class Main{ 

	static void solve(){ 
	 int n = ni();
	 int[] a = nia(n);
	 int ans = 0;
	 for(int i=1;i<n;++i){
		 if(a[i]==a[i-1]){
			 ++ans;
			if(i<n-1)a[i]=a[i+1]-1;
		 }
	 }
	 out.println(ans);
 
	} 
 
 
 
 
	public static void main(String[] args){ 
		 solve(); 
		 out.flush(); 
	 } 
	 private static InputStream in = System.in; 
	 private static PrintWriter out = new PrintWriter(System.out); 
 
	 private static final byte[] buffer = new byte[1<<15]; 
	 private static int ptr = 0; 
	 private static int buflen = 0; 
	 private static boolean hasNextByte(){ 
		 if(ptr<buflen)return true; 
		 ptr = 0; 
		 try{ 
			 buflen = in.read(buffer); 
		 } catch (IOException e){ 
			 e.printStackTrace(); 
		 } 
		 return buflen>0; 
	 } 
	 private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} 
	 private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} 
	 private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} 
 
	 private static double nd(){ return Double.parseDouble(ns()); } 
	 private static char nc(){ return (char)skip(); } 
	 private static String ns(){ 
		 StringBuilder sb = new StringBuilder(); 
		 for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); 
		 return sb.toString(); 
	 } 
	 private static int[] nia(int n){ 
		 int[] res = new int[n]; 
		 for(int i=0;i<n;++i)res[i]=ni(); 
		 return res; 
	 } 
	 private static long[] nla(int n){ 
		 long[] res = new long[n]; 
		 for(int i=0;i<n;++i)res[i]=nl(); 
		 return res; 
	 } 
	 private static int ni(){ 
		 int res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	 } 
	 private static long nl(){ 
		 long res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	} 
} 



Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] P = new int[N];

        for (int i = 0; i < N; i++)
            P[i] = sc.nextInt();

        int min = 999999999;
        int cnt = 0;

        for (int i = 0; i < N; i++) {
            if (min >= P[i]) {
                cnt++;
                min = P[i];
            }
        }

        System.out.println(cnt);

    }
}


Measured memory_bytes: 86400
h, w = gets.split.map(&:to_i)
a = h.times.map { gets.chomp.chars.map { |s| s == '#' } }
list = []
h.times do |i|
  w.times do |j|
    list << i * w + j if a[i][j]
  end
end

cnt = 0
loop do
  n = list.size
  n.times do
    x = list.shift
    i = x / w
    j = x % w
    if i - 1 >= 0 && !a[i - 1][j]
      a[i - 1][j] = true
      list << (i - 1) * w + j
    end
    if i + 1 < h && !a[i + 1][j]
      a[i + 1][j] = true
      list << (i + 1) * w + j
    end
    if j - 1 >= 0 && !a[i][j - 1]
      a[i][j - 1] = true
      list << i * w + j - 1
    end
    if j + 1 < w && !a[i][j + 1]
      a[i][j + 1] = true
      list << i * w + j + 1
    end
  end
  break if list.empty?

  cnt += 1
end
puts cnt


Measured memory_bytes: 21500
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int a,b,c,d,ans=0;
	cin>>a>>b>>c>>d;
	ans=a*c;
	ans=max(ans,b*d);
	ans=max(ans,a*d);
	ans=max(ans,b*c);
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
int a[100008];int d[100008];int op=1e9+8;
int gcd(int x,int y)
{
	if(x==0 or y==0) return op+150;
	if(x<y) swap(x,y);if(x%y==0) return x;
	return (x%y,y);
}
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int n,k;cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
	{
		d[i]=a[i+1]-a[i];if(d[i]==0) continue;if(i==0) op=d[i];else op=min(op,gcd(op,d[i]));
	}
	for(int i=0;i<n;i++)
	if(abs(k-a[i])%op==0 and a[i]>=k)
	{
		cout<<"POSSIBLE"<<endl;
		return 0;
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 1024
<?php
  list($s) = explode(" ", trim(fgets(STDIN)));

  $max = 0;
  $cnt=0;
  for ($i=0; $i<3; $i++) {
    if($s[$i]=='R'){
      $cnt++;
      $max = max($max, $cnt);
    }else{
      $cnt=0;
    }
  }

  echo $max;

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

typedef long double ld;

const ld EPS = 1e-9;
const ld INF = 1e10;
const ld PI = M_PI;

struct Point{
  ld x, y;
  Point(ld x, ld y):x(x), y(y){}
  Point(){}
};

Point operator+(const Point &a, const Point &b){
  return Point(a.x + b.x, a.y + b.y);
}
Point operator-(const Point &a, const Point &b){
  return Point(a.x - b.x, a.y - b.y);
}
Point operator*(const Point &a, const ld b){
  return Point(a.x * b, a.y * b);
}
Point operator*(const Point &a, const Point &b){
  return Point(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x);
}
Point operator/(const Point &a, const ld b){
  return Point(a.x / b, a.y / b);
}

ld cross(const Point &a, const Point &b){
  return a.x*b.y - a.y*b.x;
}

ld dot(const Point &a, const Point &b){
  return a.x*b.x + a.y*b.y;
}

ld norm(const Point &a){
  return dot(a, a);
}

struct Line:vector<Point>{
  Line(Point a = Point(0, 0), Point b = Point(0, 0)){
    this->push_back(a);
    this->push_back(b);
  }
};

int ccw(Point a, Point b, Point c){
  b = b - a;
  c = c - a;
  if(cross(b, c) > EPS) return +1; // 反時計周り
  if(cross(b, c) < -EPS) return -1; // 時計周り
  if(dot(b, c) < 0) return +2; // c -- a -- b がこの順番に一直線上
  if(norm(b) < norm(c)) return -2; // a -- b -- c がこの順番に一直線上
  return 0; // a -- c -- b が一直線上
}

bool is_intersect_SS(const Line &s, const Line &t){
  return ccw(s[0], s[1], t[0]) * ccw(s[0], s[1], t[1]) <= 0 &&
    ccw(t[0], t[1], s[0]) * ccw(t[0], t[1], s[1]) <= 0;
}

int main(){  
  int q;
  cin >> q;
  while(q--){
    Point p0, p1;
    Line l1, l2;
    cin >> p0.x >> p0.y >> p1.x >> p1.y;
    l1 = Line(p0, p1);
    
    cin >> p0.x >> p0.y >> p1.x >> p1.y;
    l2 = Line(p0, p1);
    
    if(is_intersect_SS(l1, l2)) cout << 1 << endl;
    else cout << 0 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  rep(i, q) {
    ll a, b;
    cin >> a >> b;
    if (a == b) {
      cout << a*2-2 << endl;
      continue;
    }
    ll c = sqrt(a*b);
    if (c*c == a*b) c--;
    if (c*(c+1) >= a*b)
      cout << (c-1)*2 << endl;
    else
      cout << c*2-1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC090
{
    class B
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            int count = 0;
            string s;

            for (int i = A; i <= B; i++)
            {
                s = i.ToString();

                if (s[0] == s[s.Length - 1] && s[1] == s[s.Length - 2]) { count++; }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int p,l,r;
};

struct Node T[MAX];
int n;

void preParse(int u){
  if ( u == NIL ) return;
  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);
}
void inParse(int u){
  if ( u == NIL ) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}
void postParse(int u){
  if ( u == NIL ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i, k, l, r, root;
  scanf("%d",&n);
  for ( i = 0 ; i < n ; i++ ) {
    T[i].p = NIL;
  }

  for ( i = 0 ; i < n ; i++ ){
    scanf("%d %d %d",&k,&l,&r);
    T[k].l = l;
    T[k].r = r;
    if ( l != NIL ) T[l].p = k;
    if ( r != NIL ) T[r].p = k;
  }

  for ( i = 0 ; i < n ; i++ )
    if ( T[i].p == NIL )
      root = i;

  printf("Preorder\n");

  preParse(root);
  printf("\n");

  printf("Inorder\n");

  inParse(root);
  printf("\n");

  printf("Postorder\n");

  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2028
n=int(input())
s=[input() for _ in range(n)]
a=[[0 for _ in range(26)] for _ in range(n)]
for i in range(n):
    for t in list(s[i]):
        a[i][ord(t)-ord('a')]+=1
b=[]
for i in range(26):
    t=2147483647
    for j in range(n):
        t=min(t,a[j][i])
    b.append(t)
c=[]
for i in range(26):
    c+=chr(ord('a')+i)*b[i]
print("".join(c))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  ll total = 0;
  for (auto &x: a) total += x;

  ll alpha = a[0];
  ll beta = total - a[0];
  ll minimum = abs(alpha - beta);
  for (int i = 1; i < n-1; i++) {
    alpha += a[i];
    beta -= a[i];
    if (abs(alpha - beta) < minimum) minimum = abs(alpha - beta);
  }

  cout << minimum << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
	int x, y, W, H, r;
	scanf("%d %d %d %d %d", &W, &H, &x,&y,&r);
	if ((x-r)>=0&(y-r)>=0&(x+r)<=W&(y+r)<=H)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2112
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll f[20005];
ll h,n;
ll v[10005],c[10005];
ll rh,mxv;
inline void read(ll &x)
{
	ll f;char c;
	for (f=1,c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for (x=0;c<='9'&&c>='0';c=getchar()) x=x*10+(c&15);x*=f;
}
inline ll mn(ll _x,ll _y)
{
	return _x<_y?_x:_y;
}
inline ll mx(ll _x,ll _y)
{
	return _x>_y?_x:_y;
}
int main()
{
	read(h);read(n);
	for(ll i=1;i<=n;i++)
	{
		read(v[i]);
		read(c[i]);
		mxv=mx(mxv,v[i]);
	}
	rh=h+mxv;
	for(ll j=1;j<=rh;j++)
		f[j]=1050000000;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=v[i];j<=rh;j++)
			f[j]=mn(f[j],f[j-v[i]]+c[i]);
	}
	ll ans=1050000000;
	for(ll i=h;i<=rh;i++)
		ans=mn(ans,f[i]);
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
 int n, a, b, c, d, count = 0;
 
 while(cin >> n){
  for(a = 0;a < 10;a++){
    for(b = 0;b < 10;b++){
      for(c = 0;c < 10;c++){
        for(d = 0;d < 10;d++){
          if(a + b + c + d == n) count++;
        }
      }
    }
  }
  cout << count << endl;
  count = 0;
 }

 return 0; 
}

Measured memory_bytes: 1160
// 2011/06/22 Tazoe

#include <iostream>
using namespace std;

void sieve(bool is_prime[], int n)
{
	for(int i=0; i<n; i++)
		is_prime[i] = true;

	if(n>=1)
		is_prime[0] = false;
	if(n>=2)
		is_prime[1] = false;

	for(int i=2; i<n; i++)
		if(is_prime[i])
			for(int j=i+i; j<n; j+=i)
				is_prime[j] = false;
}

int main()
{
	bool is_prime[1000001];
	sieve(is_prime, 1000001);

	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int cnt = 0;
		for(int p=2; p<=n-p; p++)
			if(is_prime[p]&&is_prime[n-p])
				cnt++;

		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
string ss;
int l,s,ans;
int main()
{
    cin>>ss;
    ans=l=ss.length();
    for(int i=0;i<l;i++)
    {
        if(ss[i]=='S')
		{
			s++;
		}
        else if(ss[i]=='T'&&s)
        {
            s--;
            ans-=2;
        }
    }
	printf("%d\n",ans);
}

Measured memory_bytes: 640
from decimal import Decimal

a,b,c = (x for x in input().split())

roota = Decimal(a)**Decimal("0.5")
rootb = Decimal(b)**Decimal("0.5")
rootc = Decimal(c)**Decimal("0.5")

if roota + rootb < rootc:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9832
#include<stdio.h>
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int ans = 0;
	long long int i;
	for (i = 1; i < n; i++)
		ans += (n - 1) / i;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

using namespace std;

int main() {
  int n, m, k;
  bool b = false;
  cin >> n >> m >> k;
  for(int i = 0; i <= n; i++) {
    for(int j = 0; j <= m; j++) {
      int a = i * m;
      a = a - j * i + (n - i) * j;
      if(a == k) b = true;
    }
  }
  if(b) cout << "Yes" << endl;
  else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int A,B,C;
string S;
bool flag = true;

void solve(){
   rep(i, S.length()){
       if(i%2==0){
           if(S[i]!='h'){
            flag = false;
            break;
           }
       } else {
           if(S[i]!='i'){
            flag = false;
            break;
           }
       }
   }
    if(S[S.length()-1]=='h')
        flag = false;

   if(flag)
       cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main(){
    cin >> S;

    solve();
}


Measured memory_bytes: 256