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

using namespace std;

int main(void)
{
    unsigned long long N, M;
    cin >> N >> M;

    if (N > M)
    {
        unsigned long long tmp = N;
        N = M;
        M = tmp;
    }

    if (N == 1 && M == 1)
    {
        cout << 1 << endl;
    }
    else if (N == 1 && M != 1)
    {
        cout << M - 2 << endl;
    }
    else if (N > 1 && M > 1)
    {
        cout << (N - 2) * (M - 2) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
 
  int i,j,n,mini,si,a1[37],a2[37],count=1,f=0;
  char sc,c1[37],c2[37];
 
  
  scanf("%d",&n);
 
  
  for(i=1;i<=n;i++){
    scanf(" %c%d",&c1[i],&a1[i]);
    a2[i]=a1[i];
    c2[i]=c1[i];
  }
 
 
 
  
  for(i=1;i<=n;i++){
    for(j=n;j>=i+1;j--){
      
      if(a1[j]<a1[j-1]){
        si=a1[j];
        a1[j]=a1[j-1];
        a1[j-1]=si;
    sc=c1[j];
    c1[j]=c1[j-1];
    c1[j-1]=sc;
 
    }
    }
  }
  
  for(i=1;i<=n;i++){
    printf("%c%d",c1[i],a1[i]);
    if(i!=n){
      printf(" ");
    }
  }
    printf("\n");
 
  
    printf("Stable\n");
 
  
  for(i=1;i<=n;i++){
    mini=i;
    for(j=i;j<=n;j++){
      if(a2[j]<a2[mini]){
        mini=j;
      }
    }
      
      si=a2[i];
      a2[i]=a2[mini];
      a2[mini]=si;
      sc=c2[i];
      c2[i]=c2[mini];
      c2[mini]=sc;
  }
 
 
 
  for(i=1;i<=n;i++){
    printf("%c%d",c2[i],a2[i]);
    if(i!=n){
      printf(" ");
    }
  }
  printf("\n");
 
  
  f=0;
  for(i=1;i<=n;i++){
    if(c2[i]!=c1[i]){
      printf("Not stable\n");
      f=1;
      break;
    }
  }  
  if(f==0)printf("Stable\n");
   
   
   
 
  return 0;
 
}


Measured memory_bytes: 2148
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("## ",*x,file=sys.stderr) if LOCAL else 0
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    X = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    def hurui(n=200000):#エラトステネスのふるい、nは最大値
        primes = set(range(2, n+1))
        for i in range(2, int(n**0.5+1)):
            primes.difference_update(range(i*2, n+1, i))
        #primes=list(primes)
        return primes
    l=list(hurui())
    i=bisect_left(l,X)
    print(l[i])


if __name__ == "__main__":
    main()

Measured memory_bytes: 124940
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let nm = read_vec::<u64>();
    let (n,m) = (nm[0],nm[1]);
    let mut an = Vec::new();
    let mut bn = Vec::new();
    for _ in 0..n{
        an.push(read::<String>());
    }
    for _ in 0..m{
        bn.push(read::<String>());
    }
    // let an = read_vec2::<String>(n as u32);
    // let bn = read_vec2::<String>(m as u32);
    let an = an.into_iter().map(|x| x.chars().collect::<Vec<char>>()).collect::<Vec<Vec<char>>>();
    let bn = bn.into_iter().map(|x| x.chars().collect::<Vec<char>>()).collect::<Vec<Vec<char>>>();
    for j in 0..(n-m+1){
        for k in 0..(n-m+1){
            let mut flag = true;
            for x in 0..m{
                for y in 0..m {
                   if an[(j+x) as usize][(k+y) as usize] != bn[x as usize][y as usize] { flag = false }
                }
            }
            if flag{
                println!("Yes");
                return;
            }
        }
    }
    println!("No");   
}

Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}

	// fmt.Println(slice)

	sort.Ints(slice)
	// fmt.Println(slice)

	res := slice[len(slice)-1] - slice[0]
	fmt.Println(res)
}


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

int main(void) {
  int64_t a, b, x;
  cin >> a >> b >> x;

  int64_t a_num = (a - 1) / x;
  int64_t b_num = b / x;
  if (a == 0)
    cout << b_num + 1 << endl;
  else
    cout << b_num - a_num << endl;
  return 0;
}

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

using ll = long long;
using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(false)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;

ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (a == 0 || b == 0) ? 0 : (a / __gcd(a, b) * b); }

int main(int argc, const char* argv[]) {
	ll n;
	cin >> n;
	vector<ll> a(n), b(n), c(n-1);
	ll ret = 0;

	rep(i, n) {
		cin >> a.at(i);
	}

	rep(i, n) {
		cin >> b.at(i);
		ret += b.at(i);
	}

	rep(i, n-1) {
		cin >> c.at(i);
	}

	rep(i, n-1) {
		if(a.at(i) + 1 == a.at(i+1)) {
			ret += c.at(a.at(i)-1);
		}
	}

	cout << ret << endl;

	return 0;
}


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

int n, a[10005];

signed main(){
  
  while( cin>>n, n ){
    
    int sum = 0;
  
    for(int i=0;i<n;i++){
      cin>>a[i];
      sum += a[i];
    }
  
    int ans = 0;
  
    for(int i=0;i<n;i++){
    
      if( n * a[i] <= sum ) ans++;
    
    }
  
    cout<<ans<<endl;

  }
  
  return 0;
}



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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
int go[100005];
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,mae;
    cin >> n >> m >> mae;
    rep(i,1,m){
        int x,y=mae,z;
        cin >> x;z=x;
        if(z<y)swap(z,y);
        go[y]++;go[z]--;
        mae = x;
    }
    go[0]=0;
    rep(i,1,n){
        go[i]+=go[i-1];
    }
    int cost = 0;
    rep(i,1,n){
        //cout << i << endl;
        int x,y,z;
        cin >> x >> y >> z;
        cost += min((x*go[i]),(z+y*go[i]));
    }
    cout << cost << endl;
    return 0;
}

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

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    int p = A + B;
    int m = A - B;
    int s = A * B;
    int ans = p;
    ans = max(ans, m);

    ans = max(ans, s);
    cout << ans << endl;
}

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i+j)
    
print(ans)

Measured memory_bytes: 47332
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int px = 0, py = 0, pt = 0;
    for(int i = 0; i < n; i++){
      int t = sc.nextInt();
      int x = sc.nextInt();
      int y = sc.nextInt();
      int sum = Math.abs(x-px) + Math.abs(y-py);
      if((t - pt) % 2 != sum % 2 || sum > t - pt){
        System.out.println("No");
        System.exit(0);
      }
      px = x;
      py = y;
      pt = t;
    }
    System.out.println("Yes");
  }
}

Measured memory_bytes: 88764
N,W=map(int,input().split())

v=[0]*N
w=[0]*N

for i in range(N):
  a,b=map(int,input().split())
  v[i]=a
  w[i]=b

dp=[0]*(W+1)

for i in range(W+1):
  for j in range(N):
    
    if (i+w[j])<=W:
      if dp[i+w[j]]==0:
        dp[i+w[j]]=dp[i]+v[j]
      else:
        dp[i+w[j]]=max(dp[i+w[j]],dp[i]+v[j])

print(dp[W])


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

int moder;
const int N = 5010;

void add(int &a, int b){a += b, a -= a >= moder ? moder : 0;}

int dp[N];

int main(){
    int n;
    scanf("%d%d", &n, &moder);
    dp[0] = 1;
    for (int i = 2; i <= n; ++ i){
        int coe = std::min(i - 1, n - i + 2);
        for (int j = 0; j + coe < N; ++ j){
            add(dp[j + coe], dp[j]);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++ i){
        ans = (ans + 1ll * (n - i) * dp[i]) % moder;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define C 100003
using namespace std;
 
int main()
{
   int x,n,i;
   cin >> x >> n;
   map<int,int>ck;
   for(i=0;i<n;i++)
   {
       int m;
       cin >> m;
       ck[m]++;
   }
   int fv=0,fp;
   for(i=x; ;i++)
   {
       if(ck.count(i))
       {
           fv++;
       }
       else
       {
           fp=i;
           break;
       }
   }
   int bv=0,bp;
   for(i=x; ;i--)
   {
       if(ck.count(i))
       {
           bv++;
       }
       else
       {
           bp=i;
           break;
       }
   }
   if(fv<bv)cout << fp;
   else if(fv>bv)cout << bp;
   else cout << min(fp,bp);
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, m, d;
    cin >> n >> m >> d;

    // d=0の場合
    if(d == 0){
        // 隣合う2項がd=0となるのは数値が同じ場合の時のみ。
        // (1,1),(2,2),...,(n,n)であり、かつ組み合わせはn^2通り存在する。
        // n/(n^2) = 1/n, これがm-1個のペア存在するため乗算する。
        cout << 1.0/n*(m-1) << endl;
    }
    // d>=1の場合
    else{
        cout << (long double)2.0*(n-d)/n*(m-1)/n << endl;
    }
}

Measured memory_bytes: 3768
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = [0]
for i in range(N+1):
  if i >= 1 and i <= N:
    D.append(D[i-1]+L[i-1])
print(len([int(y) for y in D if int(y) <= X]))


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

ll solve() {
    ll N;
    cin >> N;
    ll n = N+1;
    ll a = 1, b = 1;
    while ( (1LL << (a+1)) < n ) a++;

    auto log_2_lower = [](ll n) {
        ll r = 0;
        while ( 1LL << (r+1) <= n ) r++;
        return r;
    };

    int lc = log_2_lower(n);
    vector<int> rcs;
    for ( int i = 0; i < 50; i++ ) {
        if ( (n >> i) & 1 )  rcs.push_back(i);
    }
    vector<int> t1, t2;
    for ( int i = 0; i < lc; i++ ) {
        if ( (n >> i) & 1 ) {
            t1.push_back( 2*lc - i );
        }
        t1.push_back(i+1);
    }

    vector<int> ans;
    for ( int i = 0; i < t1.size(); i++ ) {
        if ( t1[i] <= lc ) ans.push_back(t1[i]);
    }
    for ( int i = t1.size()-1; i >= 0; i-- ) {
        if ( t1[i] > lc ) ans.push_back(t1[i]);
    }
    for ( int i = 0; i < t1.size(); i++ ) {
        ans.push_back(t1[i]);
    }

    cout << ans.size() << "\n";
    for ( int i = 0; i < ans.size(); i++ ) {
        cout << (i != 0 ? " " : "") << ans[i];
    }
    cout << "\n";

    return 0;
}

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

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
class takara {
public:
	int v, w;
	takara() {}
	takara(int x, int y) :v(x), w(y) {}
	bool operator<(const takara &other) {
		return this->w < other.w;
	}
};
signed main() {
	int W; int x(1);
	while (cin >> W, W) {
		int N; cin >> N;
		vector<takara>list;
		list.push_back(takara(0, 0));
		rep(i, 0, N) {
			int w, v; char c; cin >> v >> c >> w;
			list.push_back(takara(v, w));
		}
		vector<vector<int > >v(N + 1, vector<int>(W + 1, 0));
		rep(i, 1, N + 1) {
			rep(j, 1, W + 1) {
				v[i][j] = v[i - 1][j];
				if (j - list[i].w >= 0) {
					v[i][j] = max(v[i - 1][j], v[i - 1][j - list[i].w] + list[i].v);
				}
			}
		}
		int ret(0);
		rep(i, 0, W + 1) {
			if (v[N][ret] < v[N][i])ret = i;
		}
		cout << "Case " << x++ << ":" << endl;
		cout << v[N][W] << endl << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 6732
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  vint A(n);
  int ans = 0;
  rep(i,0,n) cin >> A[i];
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  int now = 0;
  int nowv = 0;
  rep(i,0,n-1){
    ans += A[now];
    nowv++;
    if(nowv == 2){
      now++;
      nowv = 0;
    }
    if(now == 0){
      now++;
      nowv = 0;
    }
  }
  cout << ans << endl; 
}

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

long long count = 0;
vector<int> v;
int a[1000010];

void insertionsort(int a[], int n, int g){
  int i, j, v;
  for(i = g; i < n; i++){
    v = a[i];
    j = i - g;
    while(j >= 0 && a[j] > v){
      a[j + g] = a[j];
      j -= g;
      count++;
    }
    a[j + g] = v;
  }
  /*for(int i = 0; i < n; i++){
    cout << a[i] << ((i == n-1) ? "\n" : " ");
  }
  */
}
/*
void shellsort(int a[], int n){
  int i, j, h, v;
  for(h = 1; h <= n/9; h = 3*h+1); //???????¨????
  for(; h > 0; h /= 3){            //???????????????
    insertionsort(a, n, h);
  }
}
*/
void shellsort(int a[], int n){
  int h = 1;
  while(1){
    if(h > n) break;
    v.push_back(h);
    h = 3 * h + 1;
  }
  for(int i = v.size() - 1; i >= 0; i--){
    insertionsort(a, n, v[i]);
  }
}

int main(){

  int n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  shellsort(a, n);
  cout << v.size() << endl;
  for(int i = v.size()-1; i >= 0; i--){
    cout << v[i] << ((i == 0) ? "\n" : " ");
  }
  cout << count << endl;
  for(int i = 0; i < n; i++){
    cout << a[i] << endl;
  }
  return 0;
}


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

// 💖 Hi, thanks for using ICIE! 💖
// 🔧 To use a custom code template, set it in Settings(Ctrl+,) in "Icie Template List" entry 🔧
// 📝 If you spot any bugs or miss any features, create an issue at https://github.com/pustaczek/icie 📝

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

    vector<int> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin>>v[i];
    }
    if(n % 2 == 1)
    {
        cout<<0<<endl;
    }
    else
    {
        std::sort(v.begin(), v.end());
        int middle = (v.size() - 1) / 2;
        cout<<(v[middle+1] - v[middle])<<endl;
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
using namespace std;

vector<vector<char> > matrix;

bool inside(int i, int j){
    return (i >= 0 && i<matrix.size() && j >= 0 && j < matrix[0].size());
}

bool isadj(int x, int y, int i, int j){
    if(x == i && abs(y-j) == 1) return true;
    if(y == j && abs(x-i) == 1) return true;
    if(x == i && y == j) return true;
    return false;
}

vector<pair<int,pair<int,int>> > getNeigh(int x, int y){
    vector<pair<int,pair<int,int>> > vec;
    for(int i=x-2;i<=x+2;++i){
        for(int j=y-2;j<=y+2;++j){
            if(x != i || y != j){
                if(inside(i,j) && matrix[i][j] == '.'){
                    if(!isadj(x,y,i,j)){
                        vec.push_back({1,{i,j}});
                    }
                    else{
                        vec.push_back({0,{i,j}});
                    }
                }
            }
        }
    }
    return vec;
}

vector<vector<long long int>> dist;

void daik(pair<int,int> start){
    priority_queue< pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>> > pq;
    pq.push({0,start});
    while(!pq.empty()){
        pair<int,pair<int,int>> u = pq.top(); pq.pop();
        int u_dist = u.first;   
        // cout << u.second.first  << ' ' << u.second.second << ' ' << u_dist << '\n';
        // cout << pq.size() << '\n';
        if(dist[u.second.first][u.second.second] != u_dist) continue;
        for(pair<int,pair<int,int>> v : getNeigh(u.second.first, u.second.second)){
            pair<int,int> to = v.second;
            int to_dist = v.first;
            // if(u.second.first == 0 && u.second.second == 0)
            //     cout << to.first << ',' << to.second << ':' << to_dist << '\n';
            if(dist[u.second.first][u.second.second] + to_dist < dist[to.first][to.second]){
                dist[to.first][to.second] = dist[u.second.first][u.second.second] + to_dist;
                pq.push({dist[to.first][to.second], to});
            } 
        }
        // cout << pq.size() << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int w, h; cin >> h >> w;
    int c1, c2 , d1, d2; cin >> c1 >> c2 >> d1 >> d2;
    matrix.assign(h, vector<char>(w, '.'));
    dist.assign(h, vector<long long int>(w,INT_MAX));
    dist[c1-1][c2-1] = 0;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cin >> matrix[i][j];
        }
    }
    // cout << "read\n";
    // for(auto p : getNeigh(0,0)){
    //     cout << p.second.first << ' ' << p.second.second << ':' << p.first << '\n';
    // }
    daik({c1-1,c2-1});
    // for(int i=0;i<matrix.size();++i){
    //     for(int j=0;j<matrix[i].size();++j){
    //         cout << dist[i][j] << ' ';
    //     }cout << '\n';
    // }
    if(dist[d1-1][d2-1] == INT_MAX) cout << -1 << '\n';
    else
        cout << dist[d1-1][d2-1] << '\n';
    return 0;
}

Measured memory_bytes: 12448
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n, k;
string s;
long long dp[ 105 ][ 105 ][ 2 ];

long long solve( int pos, int sum, bool allowed )
{
	if( pos == n )
	{
		return sum == k;
	}
	if( dp[ pos ][ sum ][ allowed ] != -1 )
	{
		return dp[ pos ][ sum ][ allowed ];
	}
	dp[ pos ][ sum ][ allowed ] = 0;
	for( int i = 0; i <= ( allowed ? 9 : s[ pos ] - '0' ); ++i )
	{
		dp[ pos ][ sum ][ allowed ] += solve( pos + 1, ( i != 0 ? sum + 1 : sum ), ( allowed || i < ( s[ pos ] - '0' ) ) );
	}
	return dp[ pos ][ sum ][ allowed ];
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> s >> k;
	n = s.length();
	memset( dp, -1, sizeof( dp ) );
	cout << solve( 0, 0, 0 ) << "\n";
	return 0;
}

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

public class Main{
    public static void main(String[] args)throws IOException{
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int t=sc.nextInt();

        System.out.println(t/a*b+"\n");
        sc.close();
    }
}

Measured memory_bytes: 23764
s[51],a[51],t;short*p;Q(){for(p=a;*p=='=Q';p++);}main(i,b){for(;~scanf("%[^\n]\n",s);i=0)i||puts(sscanf(s,">'%[=]#%[=]%c%c",a,b,&t,a)-3||t-'~'|strcmp(a,b)?sscanf(s,">^%[Q=]~%c%c",a,&t,a)-2||t-'~'|(Q(),*p&7|p==a)?"NA":"B":"A");}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
#define inf 1000000007
//#define for(i, a, b) for(int i=a; i<b; i++)
int dp[1000001] = {0};

void solve(){
	int n, cnt=0;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++) cin>>arr[i];	
	for(int i=0;i<n;i++){
		if(arr[i]!=i+1){
			cnt++;
		}
	}
	//cout<<cnt<<endl;
	if(cnt<=2){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}

signed main(){	
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int  a,b,ans;
    char op;

     cin>>a>>op>>b;
        while(op!='?')
        {
        if(op=='+')
            ans=a+b;
        else if(op=='-')
            ans=a-b;
        else if(op=='*')
           ans=a*b;
        else if(op='/')
           ans=a/b;
        cout<<ans<<endl;
       cin>>a>>op>>b;


    }
return 0;
}



Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for(int i = 0 ; i < n ; i++) s[i] = sc.next();
		long[] cnt = new long[5];
		for(int i = 0 ; i < n ; i++) {
			if(s[i].charAt(0) == 'M') cnt[0]++;
			if(s[i].charAt(0) == 'A') cnt[1]++;
			if(s[i].charAt(0) == 'R') cnt[2]++;
			if(s[i].charAt(0) == 'C') cnt[3]++;
			if(s[i].charAt(0) == 'H') cnt[4]++;
		}
		long ans = 0;
		for(int i = 0 ; i < 5 ; i++) {
			for(int j = i + 1 ; j < 5 ; j++) {
				for(int k = j + 1 ; k < 5 ; k++) {
					ans += cnt[i] * cnt[j] * cnt[k];
				}
			}
		}
		System.out.println(ans);
	}
}


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

signed main(){
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(b - a == c - b){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

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

//
// Created by karayuu on 2018-12-23.
//

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int ans = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3124
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n;
  ll tw=0,fo=0,oth=0;
  cin >> n;
  bool can=true;
  ll a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]%4==0){
      fo++;
    }else if(a[i]%2==0){
      tw++;
    }else{
      oth++;
    }
  }
  if(tw==0){
    oth--;
  }
  if(fo>=oth){
    can = true;
  }else{
    can = false;
  }
  if(can) cout <<"Yes\n";
  else cout <<"No\n";
}


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

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
ans = len(str(Base_10_to_n(int(n),k)))
print(ans)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  float c = (float)(a + b) / 2;
  if(c - int(c) == 0){
    cout << int(c) << endl;
  }else{
    cout << int(c) + 1 << endl;
  }
}

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  char c;cin>>c;
  if('A'<=c&&c<='Z'){
    puts("A");
  }else{
    puts("a");
  }
  
  return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n,k,res=0,cou=0,y,m,d,a[20005],ooki[2005]={};
queue<pair<long long int,long long int> >que;
string str[1100],strtmp;
int main() {
	cout << fixed << setprecision(10);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(a[i]>a[j]){
				ooki[i]++;
			}
		}
	}
	for(int i=0;i<n;i++){
		long long int tmp=k*(k-1)/2;
		tmp%=mod;
		res+=tmp*ooki[i];
		res%=mod;
		ooki[i]=0;
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j]){
				ooki[i]++;
			}
		}
	}
	for(int i=0;i<n;i++){
		
		res+=k*ooki[i];
		res%=mod;
		ooki[i]=0;
	}
	cout<<res;
} 


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

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> d(n);
	for (auto &e : d) std::cin >> e;
	
	std::sort(d.begin(), d.end());
	
	std::cout << d[n / 2] - d[n / 2 - 1] << std::endl;
	
	return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;



#define CODE 4
#define CODE_LENGTH 12
#define TABLE_SIZE 1046527

int encode(const char* code) {
    int key = 0;
    int len = strlen(code);
    key = len;
    for (int i = 0; i < len; i++) {
        switch(code[i]) {
        case 'A':
            key = key << 2;
            break;
        case 'C':
            key = (key << 2) | 1;
            break;
        case 'G':
            key = (key << 2) | 2;
            break;
        case 'T':
            key = (key << 2) | 3;
            break;
        default:
            printf("Invalid char %c\n", code[i]);
            return 1;
        }
    }
    return key;
}

typedef struct table {
    char value[CODE_LENGTH];
} HTable;

int h1(const int key, const int m) {
    return key % m;
}

int h2(const int key, const int m) {
    return 1 + key % (m - 1);
}

int get_hash(const int key, const int j, const int m) {
    return (h1(key, m) + j * h2(key, m)) % m;
}

int main (void) {

    int n;
    int size = 0;
    char code[CODE_LENGTH];
    char cmd[7];
    int key;
    int m = TABLE_SIZE;
    int h;

    HTable *tbl = new HTable[m];
    for (int i = 0; i < m; i++) {
        tbl[i].value[0] = '\0';
    }

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", cmd);
        if (strcmp(cmd, "insert") == 0) {
            scanf("%s", code);
            key = encode(code);
            for (int j = 0; ; j++) {
                h = get_hash(key, j, m);
                if (tbl[h].value[0] == '\0') break;
            }
            strcpy(tbl[h].value, code);
        }
        else if (strcmp(cmd, "find") == 0) {
            scanf("%s", code);
            key = encode(code);
            for (int j = 0; ; j++) {
                h = get_hash(key, j, m);
                if (strcmp(tbl[h].value, code) == 0) {
                    printf("yes\n");
                    break;
                }
                else if (tbl[h].value[0] == '\0') {
                    printf("no\n");
                    break;
                }
            }
        }
    }

    return 0;
}





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

using namespace std;

int main(){
	int N, K,  num_H = 0;
  	long long attack = 0;
  	cin >> N >> K;
  	vector<int> H(N);
  	if(K >= N){
      cout << "0" << endl;
      return 0;
    }
  	for(int i = 0; i < N; i++)
      cin >> H[i];
  	sort(H.begin(), H.end());
  	reverse(H.begin(), H.end());
  	while(num_H < N){
    	if(K > 0){
        	K--;
          	num_H++;
          	continue;
        }
      	attack += H.at(num_H);
      	num_H++;
    }
  	cout << attack << endl;
  	return 0;
}

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

int main(){
    double a,b,c;   cin>>a>>b>>c;
    double PI=acos(-1);

    double rad=c*PI/180;

    double S,L,h;

    S=a*b*sin(rad)/2;

    L=a+b+sqrt(a*a + b*b - 2*a*b*cos(rad));

    h=b*sin(rad);

    printf("%8lf\n",S);    
    printf("%8lf\n",L);   
    printf("%8lf\n",h);   


    return 0;
}



Measured memory_bytes: 3532
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();

        String s = sc.next();

        if (3200 <= a) {
            System.out.println(s);
        } else {
            System.out.println("red");
        }


    }
}


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

def main():
    N = int(input())
    ret = 0
    pv = 0
    for _ in range(N):
        nw = int(input())
        pa = min(pv, nw)
        ret += pa
        pv = nw - pa
        ret += pv//2
        pv = pv%2
    print(ret)

if __name__ == '__main__':
    main()

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

int main(){
  ll n, k;
  cin >> n >> k;
  
  if(n < k){
    n = min(n, k-n);
  }else{
    n = n % k;
    n = min(n, k-n);
  }
  
  cout << n << endl;
  return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    ll x, k, d; cin >> x >> k >> d;
    if(abs(x) / d >= k){
        cout << abs(x)-d*k << endl;
    }else{
        // cout << min(abs(x)%d, (d-abs(x)%d)) << endl;
        int ama = (abs(x) / d) % 2;
        if(k%2 == ama) cout << abs(x)%d << endl;
        else cout << (d-abs(x)%d) << endl;
    }
}

Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int n,m;
int fa[100001],dis[100001];
int find(int x)
{
	if(x!=fa[x])
	{
		int t=fa[x];
		fa[x]=find(fa[x]);
		dis[x]+=dis[t];
	}
	return fa[x];
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		fa[i]=i;
	}
	for(int i=1,t1,t2,t3,fa1,fa2;i<=m;i++)
	{
		cin>>t1>>t2>>t3;
		fa1=find(t1);
		fa2=find(t2);
		if(fa1==fa2)
		{
			if(dis[t1]-dis[t2]!=t3)
			{
				cout<<"No";
				return 0;
			}
		}
		else
		{
			fa[fa1]=fa2;
			dis[fa1]=t3+dis[t2]-dis[t1];
		}
	}
	cout<<"Yes";
}

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

#define int long long
#define rep(i, a) for (int i = 0; i < (a); i++)
#define repd(i, a) for (int i = (a)-1; i >= 0; i--)
#define reps(i, a, j) for (int i = (j); i < (a); i++)
#define deb(x) cout << #x << " " << x << endl;
#define debs(x) cout << #x << " " << x << " ";
#define deba(x) for (auto _i:x) cout << _i << " "; cout << endl;
#define ms(a) memset(a,0,sizeof(a));
#define mp make_pair
#define eb emplace_back
#define pii pair < int , int >
#define all(a) a.begin(),a.end()

vector < int > g[200000+1],vis(200000+1,0);

int dfs(int i) {
    if (vis[i] == true) return 0;
    vis[i] = true;
    int res = 1;
    for (auto x:g[i]) {
        if (vis[x] == false) {
            res += dfs(x);
        }
    }
    return res;
}

void solve() {
    int n,m; cin >> n >> m;
    rep(i,m) {
        int x,y; cin >> x >> y;
        x--; y--;
        g[x].eb(y);
        g[y].eb(x);
    }
    int res = 0;
    rep(i,n) {
        if (vis[i] == false) {
            res = max(res,dfs(i));
        }
    }
    cout << res << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t; t=1;
    while (t--) solve();
}

Measured memory_bytes: 21856
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	M := nextInt()
	Q := nextInt()

	a := make([]int, Q)
	b := make([]int, Q)
	c := make([]int, Q)
	d := make([]int, Q)

	for i := 0; i < Q; i++ {
		a[i] = nextInt() - 1
		b[i] = nextInt() - 1
		c[i] = nextInt()
		d[i] = nextInt()
	}
	candidates := make([][]int, 0)
	queue := make([]q, 0)
	queue = append(queue, q{M, N, []int{}})

	for len(queue) > 0 {
		item := queue[0]
		queue = queue[1:]

		if item.balls == 0 && item.lines == 0 {
			item.arr = append(item.arr, 0)
			A := make([]int, 0)
			s := 0
			for i := 0; i < len(item.arr); i++ {
				if item.arr[i] == 1 {
					s++
				} else {
					A = append(A, s)
				}
			}

			candidates = append(candidates, A)
			continue
		}

		if item.balls > 0 {
			q1 := q{item.balls - 1, item.lines, copy(item.arr)}
			q1.arr = append(q1.arr, 1)
			queue = append(queue, q1)
		}
		if item.balls != M && item.lines > 0 {
			q2 := q{item.balls, item.lines - 1, copy(item.arr)}
			q2.arr = append(q2.arr, 0)
			queue = append(queue, q2)
		}
	}

	ans := 0

	for j := 0; j < len(candidates); j++ {
		A := candidates[j]
		// printarr(A)
		s := 0
		for i := 0; i < Q; i++ {
			if A[b[i]]-A[a[i]] == c[i] {
				s += d[i]
			}
		}
		ans = max(ans, s)
	}

	fmt.Println(ans)
}

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

type q struct {
	balls int
	lines int
	arr   []int
}

func copy(f []int) []int {
	t := make([]int, len(f))

	for i := 0; i < len(f); i++ {
		t[i] = f[i]
	}

	return t
}

func printarr(arr []int) {
	for i := 0; i < len(arr); i++ {
		print(arr[i], ",")
	}
	println()
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 96096
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int L = 0, R = 1, A = 0, B = 1, C = 2, D = 3;

int e[2][4];

int main()
{
    double r,l;
    while(cin >> l >> r)
    {
        if(l < 0.2) e[L][D]++;
        else if(l < 0.6) e[L][C]++;
        else if(l < 1.1) e[L][B]++;
        else e[L][A]++;

        if(r < 0.2) e[R][D]++;
        else if(r < 0.6) e[R][C]++;
        else if(r < 1.1) e[R][B]++;
        else e[R][A]++;

    }
    REP(4)cout << e[L][i] << " " << e[R][i] << endl;

    return 0;
}

Measured memory_bytes: 0
X,N = map(int,input().split())

if N!=0:

    P = list(map(int,input().split()))

    B = X
    S = X

    while True:
        #print(B,S)
        if P.count(S) == 0:
            print(S)
            break
        elif P.count(B) == 0:
            print(B)
            break
        S -= 1
        B += 1

else:
    print(X)

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

int main()
{
  int d[3];
  while( cin >> d[0] >> d[1] >> d[2], d[0]+d[1]+d[2] ) {
    int n;
    cin >> n;
    sort(d, d+3);

    while( n-- ) {
      int r;
      cin >> r;
      if( sqrt(d[0]*d[0] + d[1]*d[1]) < 2*r ) cout << "OK" << endl;
      else cout << "NA" << endl;
    }

  }

}

Measured memory_bytes: 1172
using System;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = double.Parse(Console.ReadLine());
            Console.WriteLine(Calc(num));
        }

        static string Calc(double num)
        {
            double area = (num * num) * Math.PI;
            double length = (num * 2) * Math.PI;
            return area + " " + length; 
        }
    }
}


Measured memory_bytes: 9320
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    int ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

string s;
const int N = 1e5 + 5;
int pre[N];
void solve(){
	string s;
	cin >> s;
	int n = sz(s);
	s = '0' + s;
	for(int j = 0; j < 26; j++){
		char ch = 'a' + j;
		int mini = 1e9;
		fr(i, 1, n){
			pre[i] = pre[i - 1];
			if(s[i] == ch){
				pre[i]++;
			}
			else{
				pre[i]--;
			}
			if(pre[i] - mini > 0){
				fr(j, 0, i - 1){
					if(pre[j] == mini){
						cout << j + 1 << " " << i << endl;
						return;
					}
				}
			}
			mini = min(mini, pre[i - 1]);
		}
	}
	cout << -1 << " " << -1;
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

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

int main() {
	string a, b;
	cin >> a >> b;

	string res = a + b;
	//cout << res;

	int p = 1, result = 0;

	for(int i = res.size() - 1; i >= 0; --i) {
		result = p * (res[i] - '0') + result;
		p *= 10;
	}

	double root = sqrt(result);
	if(root == (int)root)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}


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

int main()
{
	int a, b;

	cin >> a;
	cin >> b;

	if (a + b == 15)
		cout << "+";
	if (a*b == 15)
		cout << "*";
	else if((a+b!=15)&&(a*b!=15))
	{
		cout << "x";
	}
}

Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2020-03-23.
//
# include <bits/stdc++.h>

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

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;
}

# define EPS (1e-7)
# define INF (1LL << 60)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll N, K;
vector<ll> A, F;

bool is_ok(ll x) {
    ll sum = 0;
    for (int i = 0; i < N; ++i) sum += max(0ll, A[i] - x / F[i]);
    return (sum <= K);
}

int main() {
    cin >> N >> K;
    A.resize(N);
    F.resize(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = 0; i < N; ++i) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<ll>());

    ll l = -1, r = INF;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        if (is_ok(m)) r = m;
        else l = m;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

    vector<pair<int64_t, int64_t>> p(n);
    for (auto&& pp : p) {
        // b, a
        cin >> pp.second >> pp.first;
    }

    sort(p.begin(), p.end());

    int64_t t = 0;
    for (const auto& pp : p) {
        t += pp.second;
        if (t > pp.first) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int t=(C+B-1)/B;
  int a=(A+D-1)/D;
  if(t<=a){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}

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

int is[52][52];
int w, h, c;

void search(int x, int y){
	int i, j;
	if(!is[x][y]) return;
	is[x][y] = 0;
	for(i = -1; i <= 1; i++){
		for(j = -1; j <= 1; j++){
			search(x + i , y + j);
		}
	}
	return;
}

int main(void){
	int i, j;
	while(cin >> h >> w, w){
		memset(is, 0, sizeof(is));
		c = 0;
		for(i = 1; i <= w; i++)
			for(j = 1; j <= h; j++)
				cin >> is[i][j]; 

		while(1){
			for(i = 1; i <= w; i++){
				for(j = 1; j <= h; j++){
					if(is[i][j]) break;
				}
				if(is[i][j]) break;
			}
			if(i == w+1) break;
			search(i, j);
			c++;
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 1320
#include<iostream>
#include<algorithm>
#include<stack>
#define MAX 1400

using namespace std;

struct Rectangle
{
	int height; int pos;
};

int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];


int getLangestRectangle(int size, int buffer[]) {
	stack<Rectangle>S;
	int maxv = 0;
	buffer[size] = 0;
	for (int i = 0; i <= size; i++) {
		Rectangle rect;
		rect.height = buffer[i];
		rect.pos = i;
		if (S.empty()) {
			S.push(rect);
		}
		else {
			if (S.top().height < rect.height) {
				S.push(rect);
			}
			else if(S.top().height>rect.height){
				int target = i;
				while (!S.empty() && S.top().height >= rect.height) {
					Rectangle pre = S.top();
					S.pop();
					int area = pre.height*(i - pre.pos);
					maxv = max(maxv, area);
					target = pre.pos;
				}
				rect.pos = target;
				S.push(rect);
			}
		}
	}
	return maxv;
}

int getLargestRectangel() {
	for (int j = 0; j < W; j++) {
		for (int i = 0; i < H; i++) {
			if (buffer[i][j]) {
				T[i][j] = 0;
			}
			else{
				T[i][j] = (i > 0) ? T[i - 1][j] + 1 : 1;
			}
		}
	}
	int maxv = 0;
	for (int i = 0; i < H; i++) {
		maxv = max(maxv, getLangestRectangle(W, T[i]));
	}
	return maxv;
}
int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> buffer[i][j];
		}
	}
	cout << getLargestRectangel() << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    vector<ll> H(N);

    REP(i, N){
        cin >> H[i];
    }

    // グラフ
    Graph G(N);

    REP(i, M){
        ll a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    ll ans = 0;
    REP(i, N){
        ll h = H[i];
        bool flag = true;
        for(auto v:G[i]){
            if(h > H[v]){
                flag = true;
            }
            else{
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9068