akhauriyash/Code-Regression huggingface dataset:
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define 	vii 			vector<pair<int,int>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	ll n,res=0;cin>>n;
	if(n%2)return cout<<0,0;
	for(ll i=10;i<=n;i*=5){
		res+=(n/i);
	}
	cout<<res;
}


Measured memory_bytes: 256
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

// 階乗を計算 O(N) (N=10^7 で O(10^7))
int Factorial(ll n)
{
	for (ll i = n - 1; i > 1; i--)
		n *= i;
	return n;
}

// nCrを計算 O(N) (N=10^7 で O(10^7))
ll Combination(const ll n, const ll r)
{
	return Factorial(n) / (Factorial(r) * Factorial(n - r));
}

// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool IsPrime(const ll num)
{
    if (num < 2) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll DigitSum(ll n)
{
	ll sum = 0;
	while(n != 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll n;

	return OUT(n % DigitSum(n) == 0 ? "Yes" : "No");
}


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

int main(){
  int A;
  int B;
  cin >> A >> B;
  
  int Amin;
  if(A%2 == 0){Amin = A*12.5;}
  else{Amin = (A*12.5+1)/1;}
  
  int Amax;
  if((A+1) % 2 == 0){Amax = (A+1)*12.5-1;}
  else{Amax = (A+1)*12.5/1;}
  
  int Bmin = B*10;
  int Bmax = (B+1)*10-1;
  
  int ans = -1;
  
  for(int i=Amin; i <= Amax; i++){
    if(Bmin <= i && i <= Bmax){
      ans = i;
      break;
    }
  }
  
  //cout << Amin << Amax << Bmin << Bmax << endl;
  cout << ans << endl;
}

Measured memory_bytes: 256
include Math
def f(a, b, c)
  return (0.5 * a * b * sin(g(c))), (a ** 2 + b ** 2 - 2 * a * b * cos(g(c))) ** 0.5 + a + b, b * sin(g(c))
end
def g(c)
  return c * PI / 180
end
puts f(*gets.split(" ").map(&:to_i))
#f(*gets.split(" ").map(&:to_i)).each{|i|puts sprintf("%.4f", i)}

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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if(abs(x-a) > abs(b-x)){
    printf("B\n");
  }
  else printf("A\n");
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) {
  while (a && b) {
    if (a >= b) a %= b;
    else b %= a;
  }
  return a + b;
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
	ll s;
	if(k > 1){
		s = k*facctorialMethod(k-1);
	} else {
		s = 1;
	}
	return s;
}
vl primes(ll n){
	vl x(n);
	REP(i, n){
		x[i] = 0;
	}
	for(ll i = 2; i < sqrt(n) + 2; i++){
		while(n % i == 0){
			n /= i;
			x[i-1] += 1;
		}
	}
	if(n > 1){
		x[n-1] += 1;
	}
	return x;
}


void solve(){
	string S;
	cin >> S;
	ll count = 0;
	REP(i, S.size()){
		if(i % 2 == 1){
			if(S.substr(i, 1) == "L" || S.substr(i, 1) == "U" || S.substr(i, 1) == "D"){
				count++;
			} else {
				cout << "No" << endl;
				break;
			}
		} else {
			if(S.substr(i,1) == "R" || S.substr(i,1) == "U" || S.substr(i,1) == "D"){
				count++;
			} else {
				cout << "No" << endl;
				break;
			}
		}
	}
	if(count == S.size()){
		cout << "Yes" << endl;
	}
}


const ll mod = 1000000007;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(void){
    long long n,k,h[200001],ans=0;
    cin >> n >> k;
    rep (i,n){
        cin >> h[i];
    }
    sort(h,h+n);
    reverse(h,h+n);
    for (int i=k;i<n;i++){
        ans += h[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920
n=int(input())
nums=list(map(int,input().split()))
cnt=0
flag=0
while flag is 0:
    for i in range(n):
        num=nums[0]/2
        key=nums[0]%2
        if key==1:
            flag=1
            break
        else:
            del nums[0]
            nums.append(num)
    if flag==0:
        cnt+=1

print(cnt)

Measured memory_bytes: 9200
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN = 100000;
int x[MAXN + 5], y[MAXN + 5], c[MAXN + 5];
int y1[MAXN],N,K,Max,cnt;
int main() 
{

	scanf("%d%d",&N,&K);
	for(int i=1;i<=N;i++) 
	{
		char ch;
		scanf("%d %d %c",&x[i],&y[i],&ch);
		x[i]%=(2*K);
		y[i]%=(2*K);
		if(ch=='W' ) c[i] = 1;
	}
	for(int i=0;i<=K;i++) {
		cnt = 0;
		fill(y1,y1+2*K+1,0);
		for(int j=1;j<=N;j++) {
			bool p = ( i <= x[j] && x[j] < i+K );
			bool q = ( 0 <= y[j] && y[j] < K );
			if( p ^ q == c[j] )
			{
				cnt++;
				y1[y[j]] ++;
			}
			else 
			{
				y1[y[j]] --;
			}
		}
		for(int j=0;j<=K;j++) 
		{
			Max=std::max(Max,std::max(cnt,N-cnt));
			if( j != K )
				cnt = cnt - y1[j] - y1[K+j];
		}
	}
	printf("%d\n",Max);
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(){
    int y=0,i;
    char S[3];
    cin >> S[0] >> S[1] >> S[2];
    for(i=0; i<3; i++){
        if(S[i] == '1'){
            y++;;
        }
    }
    cout << y << endl;
    return 0;
    }

Measured memory_bytes: 256
def mfactorial(n: int, mod: int) -> int:
  cache = mfactorial.__cache if hasattr(mfactorial, '__cache') else [1, 1]
  n_len = len(cache)
  n_new = n - n_len + 1
  if n_new > 0:
    cache = cache + ([0] * n_new)
    for i in range(n_len, n + 1):
      cache[i] = cache[i - 1] * i % mod
    mfactorial.__cache = cache

  return mfactorial.__cache[n]


def cmb(n, r, mod):
  result = mfactorial(n, mod)
  result *= pow(mfactorial(r, mod), mod - 2, mod) % mod
  result %= mod
  result *= pow(mfactorial(n - r, mod), mod - 2, mod) % mod
  result %= mod

  return result


def main():
  MOD = 10 ** 9 + 7

  N, M, K = [int(i) for i in input().strip().split(' ')]
  c = cmb(N * M - 2, K - 2, MOD)

  X = 0
  Y = 0
  for i in range(M):
    X += (M - i) * i
  for i in range(N):
    Y += (N - i) * i

  total = (X * (N ** 2) + Y * (M ** 2)) % MOD * c % MOD
  print(total)


main()

Measured memory_bytes: 10856
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

ll N;
ll cnt[26];

void solve() {
	string str; cin >> str;
	N = sz(str);
	rep(i, 0, N) {
		cnt[str[i] - 'a']++;
	}
	ll res = N * (N - 1) / 2 + 1;
	rep(i, 0, 26) {
		res -= cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

using namespace std;

int n, x[100005][2], dp[100005][2], ta;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &ta);
		for (int j = 0; (1 << j) < ta; j++)
			x[i][1]++;
		if (ta == (1 << x[i][1]))
			x[i][0] = x[i][1];
		else
			x[i][0] = x[i][1] - 1;
		// printf("%d %d\n", x[i][0], x[i][1]);
		dp[i][0] = min(dp[i - 1][0] + max(0, x[i][0] - x[i - 1][1]), dp[i - 1][1] + max(0, x[i][0] - x[i - 1][0])) + x[i][1] - x[i][0];
		dp[i][1] = min(dp[i - 1][0] + max(0, x[i][1] - x[i - 1][1]), dp[i - 1][1] + max(0, x[i][1] - x[i - 1][0]));
	}
	printf("%d\n", min(dp[n][0], dp[n][1]));
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
  public static boolean check(String s){
    String[] ss = s.replaceAll("\\(|\\)","").split("&");
    boolean[] flg = new boolean[3];
    char[] ch = new char[3];

    for(int i=0;i<3;i++){
      if(ss[i].charAt(0) == '~'){
        ch[i] = ss[i].charAt(1);
      }
      else{
        flg[i] = true;
        ch[i] = ss[i].charAt(0);
      }
    }

    if(ch[0] != ch[1] && ch[0] != ch[2] && ch[1] != ch[2])
      return true;
    if(ch[0] == ch[1] && ch[1] == ch[2])
      return flg[0] == flg[1] && flg[1] == flg[2];
    if(ch[0] == ch[1])
      return flg[0] == flg[1];
    if(ch[0] == ch[2])
      return flg[0] == flg[2];

    return flg[1] == flg[2];
  }

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

    while(true){
      String[] s = sc.next().split("\\|");
      if(s[0].equals("#")) break;

      boolean flg = false;
      for(String ss : s){
        if(check(ss)){
          flg = true;
          break;
        }
      }

      System.out.println(flg ? "yes" : "no");
    }
  }
}

Measured memory_bytes: 13000
from collections import defaultdict

N = int(input())

if N == 1:
    print(0)
    exit()

p = defaultdict(int)

while N % 2 == 0:
    p[2] += 1
    N //= 2
f = 3
while f * f <= N:
    if N % f == 0:
        p[f] += 1
        N //= f
    else:
        f += 2
if N != 1:
    p[N] += 1

ans = 0

for v in p.values():
    n = 1
    i = 1
    while n <= v:
        ans += 1
        i += 1
        n += i

print(ans)

Measured memory_bytes: 9416
#include<bits/stdc++.h>
using namespace std;
char s[1000010];

inline int C(int n, int m) { return (n & m) == m; }

int main() {
    int n;
    scanf("%d%s", &n, s + 1);
    if(n == 1) putchar(s[1]), puts("");
    else {
        --n;
        int find1 = 0;
        for(int j = 1; j <= n; j++)
            s[j] = abs(s[j] - s[j + 1]), find1 |= s[j] == 1;
        if(!find1) for(int i = 1; i <= n; i++) s[i] >>= 1;
        find1 ^= 1;
        int t = 0;
        for(int j = 1; j <= n; j++) t ^= C(n - 1, j - 1) * (s[j] & 1);
        cout << (int(t) << find1) << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(void) {
	int num, i, ans, a, b;
	cin >> num >> a;
	ans = a;
	for (i = 0; i < num - 2; i++) {
		cin >> b;
		ans += min(a, b);
		a = b;
	}
	ans += a;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
import sys


def alg_combination_mod(n, r, mod):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i) % mod
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i) % mod
        return denominator * pow(molecule, mod - 2, mod) % mod


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x, y = list(map(int, readline().split()))
    if (x + y) % 3 != 0 or x <0 or y < 0:
        print(0)
    else:
        c = (x + y) // 3
        for i in range(c+1):
            xv = i * 1 + (c - i) * 2
            yv = i * 2 + (c - i) * 1
            if xv == x and yv == y:
                print(alg_combination_mod(c, i, mod))
                exit()
        print(0)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long x;
  cin >> x;
  for(int i = 0; i < 200; i++){
    for(int j = -100; j < 200; j++){
      if(i*i*i*i*i-j*j*j*j*j==x){
        cout << i << " " << j;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3632
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); ++i)
#define iter(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1 << 31);

#define sc second
#define fs first
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T>
T smod(T a, T b) {
  return (a % b + b) % b;
}
// vim: cc=60 ts=2 sts=2 sw=2:

int main() {
  // code

  string s;
  int q;
  cin >> s;
  cin >> q;

  string s1 = "", s2 = "";

  bool r = false;

  rep(i, 0, q) {
    int t;
    cin >> t;
    if (t == 1) r = !r;
    if (t == 2) {
      int f;
      char c;
      cin >> f >> c;
      if (!r) {
        if (f == 1)
          s1 += c;
        else
          s2 += c;
      } else {
        if (f == 2)
          s1 += c;
        else
          s2 += c;
      }
    }
  }

  reverse(s1.begin(), s1.end());

  string res = s1 + s + s2;

  if (r) reverse(res.begin(), res.end());

  cout << res << endl;

  // codend
}


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

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int n = 1;
    int m = -1;
    for (int a = 0; 100 * A * a <= F; a++) {
        int x = F - 100 * A * a;
        for (int b = 0; 100 * B * b <= x; b++) {
            int y = min(x - 100 * B * b, E * (A * a + B * b));
            for (int c = 0; c * C <= y; c++) {
                int d = (y - (c * C)) / D;
                if (m * (a * A + b * B) < (c * C + d * D) * n) {
                    n = a * A + b * B;
                    m = c * C + d * D;
                }
            }
        }
    }
    cout << n * 100 + m << " " << m << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin>>n;
  vector<int> v;
  for(int i=0; i<n; i++) {
    int a;
    cin>>a;
    v.push_back(a);
  }

  int sum = 0;
  long long count=0;
  int r =0;
  for(int l=0; l<n; l++) {
    while(r<n && (sum ^ v[r]) == (sum + v[r])) {
      sum+=v[r];
      r++;
    }

    count+=r-l;
    if(r == l) r++;
    else
      sum-=v[l];
  }
  cout<<count<<endl;
}



Measured memory_bytes: 1400
#include <stdio.h>

int main(void) {
	int hito[1000];
	int i;
	int imo;
	int ninnzuu;
	int kannkaku;
	int nowninnzuu;
	while(1) {
		scanf("%d %d",&ninnzuu,&kannkaku);
		if(ninnzuu==0 && kannkaku==0)break;
		for(i=0;i<ninnzuu;i++)hito[i]=1;
		imo=ninnzuu-1;
		for(nowninnzuu=ninnzuu;nowninnzuu>1;nowninnzuu--) {
			for(i=0;i<kannkaku;) {
				imo=(imo+1)%ninnzuu;
				if(hito[imo])i++;
			}
			hito[imo]=0;
		}
		for(i=0;i<ninnzuu;i++) {
			if(hito[i])break;
		}
		printf("%d\n",i+1);
	}
	return 0;
}

Measured memory_bytes: 0
"""
アンバランス
・長さが2以上
→そのまま
・過半数の文字が同じ
→abcaa　とか aabacda　aa とか 

ある2文字や3文字の区間を見た時に
・2文字：両方一致
・3文字：3つ中二つが一致
ならアンバランス
"""

S = input()
N = len(S)

for i in range(N-1):
  if len(set(S[i:i+2])) == 1:
    print(i+1, i+2)
    exit()

for i in range(N-2):
  if len(set(S[i:i+3])) <= 2:
    print(i+1, i+3)
    exit()

print(-1, -1)

Measured memory_bytes: 41068
#include<cstdio>
#include<cstring>
using namespace std;

const int N = 100010;
int n, a[N], s[N];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++){
		scanf("%d", &a[i]);
		s[i] = 0;
		while (a[i] % 2 == 0){
			a[i] /= 2;
			s[i] ++;
		}
	}
	int zero = 0, one = 0, other = 0;
	for (int i = 1; i <= n; i ++){
		if (s[i] == 0) zero ++;
		else{
			if (s[i] == 1) one ++;
			else other ++;
		}
	}
	if (one + zero <= other + 1) puts("Yes");
	else{
		if (one > 0) zero ++;
		if (zero <= other + 1) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    int h, w; cin >> h >> w;
    char a;
    int sum = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a;
            if(a == '#') sum++;
        }
    }
    if(sum == h+w-1) cout << "Possible";
    else cout << "Impossible";
    cout << endl;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, mn = 1e9, an = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (x < mn) {
            ++an;
            mn = x;
        }
    }
    cout << an << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>


using namespace std;

int main(void){


    int n;
    int s[128];
    while(scanf("%d", &n), n){
        int maxi = 0;
        int mini = 1000000000;
        int total=0, ns=0;

        for(int i = 0; i < n; i++){
            scanf("%d", &s[i]);
            if(s[i] > maxi){
                maxi = s[i];
            }
            if(s[i] < mini){
                mini = s[i];
            }
        }

        for(int i = 0; i < n; i++){
            if(maxi == s[i]){
                maxi = -1;
                continue;
            }
            if(mini == s[i]){
                mini = -1;
                continue;
            }
            total += s[i];
            ns++;
        }
        printf("%d\n", total/ns);
    }



    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int A;
  int nowDiv, minDiv;
  
  for(int i = 0; i < N; i++){
    cin >> A;
    nowDiv = 0;
    
    while ( (A % 2) == 0){
      A = A / 2;
      nowDiv++;
    }
    
    if (i == 0){
      minDiv = nowDiv;
    }
    else{
      minDiv = min(nowDiv, minDiv);
    }
  }
  
  cout << minDiv << endl;
}
  
 

Measured memory_bytes: 3512
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std; 


int
main(int argc, char const *argv[])
{
    int64_t n, m;
    cin >> n >> m;
    vector<tuple<int64_t, vector<int64_t>>> v(10);
    vector<bool> p(10);

    vector<uint64_t> ss(11);
    ss[0] =  0b0000000000;
    ss[1] =  0b0000000001;
    ss[2] =  0b0000000010;
    ss[3] =  0b0000000100;
    ss[4] =  0b0000001000;
    ss[5] =  0b0000010000;
    ss[6] =  0b0000100000;
    ss[7] =  0b0001000000;
    ss[8] =  0b0010000000;
    ss[9] =  0b0100000000;
    ss[10] =  0b1000000000;

    int64_t maxval = 1;

    for (int64_t i = 0; i < m; ++i) {
	int64_t k = 0;
	cin >> k;
	vector<int64_t> s(10);
	for (int64_t j = 0; j < k; ++j) {
	    cin >> s[j];
	}
	v[i] = make_tuple(k, s);
    }

    for (int64_t i = 0; i < m; ++i) {
	int64_t q;
	cin >> q;
	p[i] = q != 0;
    }

    for (int64_t i = 0; i < n; ++i) {
	maxval = maxval * 2;
    }


    int64_t ans = 0;
    for (uint64_t i = 0; i < maxval; ++i) {
	bool match = true;
	for (int64_t j = 0; j < m; ++j) {
	    auto k = get<0>(v[j]);
	    auto s = get<1>(v[j]);
	    bool t = false;
	    for (int64_t u = 0; u < k; ++u) {
		t ^= ((i & ss[s[u]]) != 0);
	    } 
	    if (t != p[j]) {
		match = false;
		break;
	    }
	}
	if (match) ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

if len(t) == 1:
    print(T)
    exit()

X = 0
for i in range(1,N):
    if i == N - 1:
        X += T
    if t[i] - t[i-1] >= T:
        X += T
    else:
        X += t[i] - t[i-1]

print(X)


Measured memory_bytes: 25196
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ll k,s,ans=0;cin>>k>>s;
    for(int i=0;i<=s;i++){
        for(int j=i;j<=s;j++){
            if(i<=k&&(j-i)<=k&&(s-j)<=k) ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
x=map(int, raw_input().split())

if x[0] > x[1]:
  x[0],x[1] = x[1],x[0]
if x[1] > x[2]:
  x[1],x[2] = x[2],x[1]
if x[0] > x[1]:
  x[0],x[1] = x[1],x[0]
print "%d %d %d" %(x[0],x[1],x[2])

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

int main()
{
  int i,c,h,m,s;;
  char number[100];

  i = 0;
  while((c = getchar()) != EOF) {
    number[i] = c;
    i++;
  }
  s = atoi(number);
  
  h = s / 3600;
  s -= h * 3600;
  m = s / 60;
  s -= m * 60;
  printf("%d:%d:%d\n", h, m, s);

  return 0;
}

Measured memory_bytes: 524
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>
#include <cassert>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
int comb(int n) {
    if (n <= 1) return 0;
    return n * (n - 1) / 2;
}
/* main */
int main(){
    int N, M;
    cin >> N >> M;
    cout << comb(N) + comb(M) << '\n';
}


Measured memory_bytes: 256
a=list(map(int,input().split()))
#initlalize 2D array
table = [[0 for i in range(a[1]+1)] for j in range(a[0]+1)]

#input
for i in range(a[0]):
    values = list(map(int,input().split()))
    for j in range(a[1]):
        table[i][j] = values[j]

#sum of a row
for i in range(a[0]):
    for j in range(a[1]):
        table[i][a[1]] += table[i][j]
#sum of a column
for i in range(a[1]+1):
    for j in range(a[0]):
        table[a[0]][i] += table[j][i]
#print
for i in range(a[0]+1):
    print(*table[i])


Measured memory_bytes: 6208
n,k = map(int,input().split())

ans = 0

for i in range(k+1,n+1):
    kosu = n // i
    ans += kosu*(i-(k+1)+1)
    if n % i == 0:
        continue
    if k == 0:
        ans += max(0,n%i-k)
    else:
        ans += max(0,n%i-(k-1))
   # print(i,ans)
    
print(ans)

Measured memory_bytes: 39408
def calc(listv):
    total=0
    total += (listv[0]+listv[1])/2
    list_l=len(listv)
    i = 2
    while(list_l >2):
        total += listv[i]
        total /= 2
        list_l -= 1
        i+=1
    return total

n=int(input())
ans=0
v=list(map(int,input().split()))
v.sort()
"""
if n>2:
    for i in range(2,n):
        ans=(v[0]+v[1])*(2**(-n+1))+v[i]*(2**(-n+i))
else:
    ans=(v[0]+v[1])*(2**(-n+1))
"""
ans = calc(v)
if ans-int(ans)==0:
    print(int(ans))
else:
    print(ans)




Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if b[i] >= a[i]:
        cnt += a[i]
        b[i] = b[i] - a[i]
        if b[i] >= a[i+1]:
            cnt += a[i+1]
            a[i+1] = 0
        else:
            a[i+1] = a[i+1]-b[i]
            cnt += b[i]
    else:
        cnt += b[i]
print(cnt)

Measured memory_bytes: 18476
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>

using namespace std;

int main() {
	int N, K;
	int h;
	int ans=0;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> h;
		if (h >= K)ans++;
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}

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

int main()
{
  int n; cin >> n;
  int d[105];
  rep(i, n) cin >> d[i];
  int ans = 0;
  for (int i=0; i<n; i++) {
    for (int j=i+1; j<n; j++) {
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

const int MAX = 1001;

int main(){

  vector<int> V;

  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++) V.push_back(i+j);
  
  sort(V.begin(),V.end());

  int n;
  while(cin >> n){
    int ans = 0;
    for(int i = 0; i <= n; i++){
      int a = upper_bound(V.begin(),V.end(),i)-lower_bound(V.begin(),V.end(),i);
      int b = upper_bound(V.begin(),V.end(),n-i)-lower_bound(V.begin(),V.end(),n-i);
      ans += a*b;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 7172
#include <stdio.h>

int main(void) {
    int A, B, C;
    scanf("%d%d%d", &A, &B, &C);

    if((A == B && B == C) || (A != B && B != C && C != A)) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }

    return 0;
}

Measured memory_bytes: 1620
import java.util.Scanner;

class Main{
    public  static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
	int x = stdIn.nextInt(); //長方形　X座標
	int y = stdIn.nextInt(); //長..    Y ..
	int s = stdIn.nextInt(); //円..   X.. 
	int t = stdIn.nextInt();// 円..　　Y..
	int r = stdIn.nextInt();// 円　半径

	//有効な範囲を考える
	if(s >= r&& s <= (x - r) && t >= r && t <= (y - r))
	    System.out.println("Yes");
	else
	    System.out.println("No");

	
    }
    
}

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



public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();

		String[] arr = br.readLine().split(" ");



		int n = Integer.parseInt(str);
		int value = 0;


		int max=-2147483648;
		int min=2147483647;
		
		long sum = 0 ;
		for(int i=0;i<n;i++){
			value = Integer.parseInt(arr[i]);
			if(max<value){
				max=value;
			}
			if(min>value){
				min=value;
			}
			sum+=(long)value;
			
		}
		System.out.println(min +" "+ max +" "+sum);
	}



}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n)cin>>a[i];
	vector<ll> sum((n*(n+1))/2);
	ll count = 0;
	rep(i,n){
		ll now = a[i];
		sum[count++] = now;
		For(j,i+1,n){
			now+=a[j];
			sum[count++]=now;
		}
	}
	sort(sum.rbegin(),sum.rend());
	ll ans = 0;
	for(ll i = 60; i >= 0; i--){
		ll tmp = 0;
		vector<ll> now(0);
		ll want = pow(2ll,i);
		rep(j,sum.size()){
			if(sum[j] >= want){
				sum[j] -= want;
				now.push_back(sum[j]);
			} 	
		}
		if(now.size() >= k){
			ans += want;
			sum = now;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5372
#include <iostream>
#define MAX 100010
using namespace std;

long long n, k;
long long w[MAX];

bool check(long long p)
{
	int i = 0;
	for(int j = 0;j < k;j++)
	{
		int sum = 0;
		while(sum + w[i] <= p)
		{
			sum += w[i];
			i++;
			
			if (i == n) return true;
		}
	}
	return false;
}

int main ()
{
	
	//輸入
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> w[i];
	}
	
	//處理
	long long left = 0, middle = 0;
	long long P = 1e+5*1e+4; // right
	
	while(P > left+1)
	{
		middle = (P + left) / 2;
		if (check(middle))
		{
			P = middle;
		}
		else
		{
			left = middle;
		}
	}
	
	//輸出
	cout << P << endl;
	
	return 0;
}


Measured memory_bytes: 3904
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

 long long modpow(long long n, long long k,long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
     int n;cin >>  n;
     vector<int>a(55,0);
     bool ok = 1;int cnt = 0;
     if(n<0) ok = 0;
     n = abs(n);
     while(n){
        if(n%2) a[cnt]++;
        cnt++;
        n /= 2;
     }
     if(ok){
        for(int i = 0;i<50;i++){
            if(i%2&&a[i]) a[i+1]++;
        }
        for(int i = 0;i<50;i++)
        while(a[i]>=2){
            a[i] -= 2;
            if(a[i+1]>0) a[i+1]--;
            else {a[i+1]++;a[i+2]++;}
     }}
     else{
        for(int i = 0;i<50;i++){
            if(i%2==0&&a[i]) a[i+1]++;
        }
        for(int i = 0;i<50;i++)
        while(a[i]>=2){
            a[i] -= 2;
            if(a[i+1]>0) a[i+1]--;
            else {a[i+1]++;a[i+2]++;}
    }
}
     int pos = 0;
     for(int i = 50;i>=0;i--){
        if(a[i]>0){
            pos = i;break;
        }
     }
     for(int i = pos;i>=0;i--){
        cout << a[i];
     }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    ll sum = 0;
    rep(i,m){
        int tmp;cin>>tmp;
        sum+=tmp;
    }
    if(sum>n){
        cout<<-1<<endl;
        return 0;
    }else{
        cout<<n-sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
import sys, re
import math
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

l = int(input())

side = l / 3
ans = side * side * side

print(ans)

Measured memory_bytes: 5456
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll,ll> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

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

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

int main(){
    int n,k;
    cin >> n >> k;
    string S;
    cin >> S;
    vector<int> C;
    int now = 1;
    int cnt = 0;
    rep(i,n){
        if(S[i] == '0'+now){
            ++cnt;
        }else{
            C.push_back(cnt);
            cnt=1;
            now = 1 - now;
        }
    }
    if(cnt!=0)C.push_back(cnt);
    if(C.size()%2==0)C.push_back(0);
    // 尺取法
    int right, left, tmp;
    right = left = tmp = 0;
    int ans = 0;
    int Add = 2*k +1;
    /*
    Left, rightにNext~,Next~が対応している。Nextをループ毎に前に出して、
    それを原方向が追いつくようにするとする.
    初回のsumの計算には、rightをADDぶん動かすことで計算することが可能.
    */
    for(int i=0; i<C.size();i+=2){
        int Nextleft = i;
        int Nextright = min(i+Add, (int)C.size());
        while(Nextleft>left){
            tmp -= C[left];
            left++;
        }

        while(Nextright > right){
            tmp+= C[right];
            right++;
        }
        ans = max(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a, b, n;
	cin >> a >> b >> n;
	ll cal = (ll)floor((double)a * (double)n / (double)b) - a * (ll)floor((double)n / (double)b);
	if(n / b >= 1){
		ll t = b - 1;
		t *= a;
		cout << (ll)floor((double)t / (double)b);
	}else{
		ll t = n;
		t *= a;
		cout << (ll)floor((double)t / (double)b);
	}
}

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

int main () {
  int a, b, t;
  cin >> a >> b >> t;
  int ans = b * (t / a);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// AOJ 2747 Curtain
// 2018.4.26 bal4u

#include <stdio.h>

// バッファを経ずstdinから数値を得る
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	if (c == '-') { c = getchar_unlocked();
		do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define INF 20002

int x[102], y[102];

int main()
{
	int N, a, b, c, i;
	int xmin, xmax, ymin, ymax;
	long long win, cur;

	while (N = in()) {
		for (i = 0; i < N; i++) x[i] = in(), y[i] = in();
		x[N] = x[0], y[N] = y[0];
 
		xmin = ymin = INF, xmax = ymax = -INF;
		for (i = 0; i < 4; i++) {
			a = in(), b = in();
			if (a < xmin) xmin = a;
			if (a > xmax) xmax = a;
			if (b < ymin) ymin = b;
			if (b > ymax) ymax = b;
		}

		win = cur = 0;
		for (i = 0; i < N; i++) if (x[i] == x[i+1]) {
			cur += (long long)x[i] * (y[i]-y[i+1]);
			a = x[i]; if (a > xmax) a = xmax;
			if (xmin > a) a = xmin;
			b = y[i]; if (b > ymax) b = ymax;
			if (ymin > b) b = ymin;
			c = y[i+1]; if (c > ymax) c = ymax;
			if (ymin > c) c = ymin;
			win += (long long)a * (b-c);
		}
		printf("%lld\n", win-cur);
	}
	return 0;
}


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

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int mi = min(x, y);
    int ans = min({a*x + b*y, mi*2*c + (x-mi)*a + (y-mi)*b, max(x,y)*2*c});
    cout << ans << 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;

int selectionSort(vector<int>& A, int N) {
    int t, sw = 0, minj;
    for (int i = 0; i < N - 1; i++) {
        minj = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minj]) minj = j;
        }
        swap(A[i], A[minj]);
        if (i != minj) sw++;
    }
    return sw;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int sw = selectionSort(A, N);
    for (int i = 0; i < N; i++) {
        if (i != 0) cout << " ";
        cout << A[i];
    }
    cout << endl << sw << endl;
    return 0;
}


Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        
        int count = 0;
        for(int i = 0; i < n-2; i++){
            if(s.charAt(i) == 'A' && s.charAt(i+1) == 'B' && s.charAt(i+2) == 'C'){
                count++;
            }
        }
        System.out.println(count);
    }
}

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

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

int main() {
    int h, w; cin >> h >> w;
    vector<string> field(h);
    for (string &s: field) cin >> s;
    UnionFind uf(h * w);
    auto idx = [&](int i, int j) { return i * w + j; };
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        for (int di: {-1, 0, 1}) for (int dj: {-1, 0, 1}) {
            if (di * di + dj * dj != 1) continue;
            int ni = i + di, nj = j + dj;
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (field[i][j] != field[ni][nj]) uf.unionSet(idx(i, j), idx(ni, nj));
        }
    }
    map<int, map<char, int>> cnt;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        cnt[uf.root(idx(i, j))][field[i][j]]++;
    }
    long long ans = 0;
    for (auto &p: cnt) {
        auto bw = p.second;
        ans += 1LL * bw['#'] * bw['.'];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 20608
n = gets.to_i
h = gets.split.map(&:to_i)
max_count = 0
count = 0
i = n - 2
while i >= 0 
  if h[i + 1] <= h[i]
    count += 1
  else
    max_count = [max_count, count].max 
    count = 0
  end
  i -= 1
end
puts [max_count, count].max


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

int main() {
  int n; cin>>n ;
  int k=n%10;
  if(k==3)cout<<"bon";
  else if(k==0||k==1||k==6||k==8)cout<<"pon";
  else{cout<<"hon";}
}
      

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

int main() {
  string s;
  cin >> s;

  // 'a'から'z'までのパターンを全てシミュレーションして、操作回数の最小値を求める
  int mini = 1e9;
  for (char c = 'a'; c <= 'z'; c++) {
    // 文字列tmpの文字が全てcになるまで繰り返す
    string tmp = s;
    int cnt = 0;
    while (1) {
      bool flag = true;
      for (int i = 0; i < tmp.size(); i++) {
        if (tmp[i] != c) flag = false;
      }
      if (flag) {
        mini = min(mini, cnt);
        break;
      }

      // tmpにcが見つかればその位置 + 1の文字をcに変えて、それ以外の任意の文字を削除する
      int del_num = -1; // 削除する文字の添え字を格納する
      vector<int> v; // cに変える添え字を格納する
      for (int i = 0; i < tmp.size(); i++) {
        if (tmp[i] == c) {
          v.push_back(i+1);
        } else {
          if (del_num != -1) continue;
          del_num = i;
        }
      }
      // 文字をcに変える
      for (int i = 0; i < v.size(); i++) {
        tmp[v[i]] = c;
      }
      // 文字の削除
      tmp.erase(tmp.begin() + del_num, tmp.begin() + (del_num + 1));
      cnt++;
    }
  }

  // 解答
  cout << mini << endl;
  return 0;
}


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

sum_satisfaction = 0

for i in range(n):
    sum_satisfaction += b[a[i]-1]
    if i == 0:
        continue
    elif a[i] == a[i-1] + 1:
        sum_satisfaction += c[a[i-1]-1]

print(sum_satisfaction)

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

int cov(char c){
    if(c == 'a')return 0;
    else return (c - 'a');
}

unsigned long dfs(vector<int> vec, int i){
        if(i == vec.size()-1)return vec.at(i)+1;
        else{
            unsigned long ans = (dfs(vec, i+1) * (vec.at(i) + 1)) %  1000000007;
            return ans;
        }
}

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

    vector<int> m(30);
    for(int i = 0; i < N; i++)
    {
         m.at(cov(S.at(i))) += 1;
    }
    
    unsigned long ans = dfs(m, 0);

    cout << (ans -1) %  1000000007<< endl;
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    string s;
    cin >> s;

    ll cnt[26] = {};
    rep(i, s.size())cnt[s[i]-'a']++;

    ll ans = s.size()*(s.size()-1)/2 + 1;
    rep(i, 26)ans -= cnt[i]*(cnt[i]-1)/2;

    cout << ans << endl;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  array<array<int, 3>, 3> c;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> c[i][j];
    }
  }

  bool ans = false;
  for (int a1 = 0; a1 <= 100 && !ans; ++a1) {
    array<int, 3> va, vb;
    va[0] = a1;
    vb[0] = c[0][0] - va[0];
    vb[1] = c[0][1] - va[0];
    vb[2] = c[0][2] - va[0];
    va[1] = c[1][0] - vb[0];
    va[2] = c[2][0] - vb[0];

    bool ok = true;
    for (int i = 0; i < 3 && ok; ++i) {
      for (int j = 0; j < 3 && ok; ++j) {
        if (c[i][j] == va[i] + vb[j]) {
          continue;
        }

        ok = false;
      }
    }

    if (ok) {
      ans = ok;
    }
  }

  cout << (ans ? "Yes" : "No") << '\n';
  return 0;
}

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

int main()
{
	int n;
	string str;
	set<string> dic;
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> str;
		if (str == "insert") {
			cin >> str;
			dic.insert(str);
		}
		else if (str == "find") {
			cin >> str;
			cout << (dic.find(str) != dic.end() ? "yes" : "no") << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 30092
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n;
    cin >> n;
    int a[100020];
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    double r = (double)a[n] / 2;
    int min = 1000000007;
    int ans;
    for(int i = 1;i <= n;i++){
        if(abs(r - a[i]) < min){min = abs(r - a[i]);ans = i;}
    }
    cout << a[n] << " " << a[ans];
}

Measured memory_bytes: 1024