akhauriyash/Code-Regression huggingface dataset:
A,B=map(int,input().split())
ma,mi=0,0
ma=max(A,B)
mi=min(A,B)

if A%B==0 or B%A==0:
    print(ma)

else :
    for i in range(2,ma+1):
        if (ma*i)%mi==0:
            print(ma*i)
            break
        i+=(mi-1)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int N, K;
int x[60], y[60];
ll ans;

int main() {
	cin >> N >>K;
	for (int i = 0;i < N;i++) {
		cin >> x[i] >> y[i];
	}

	ans = 9223372036854775807;
	for (int a = 0;a < N;a++) {
		for (int b = 0;b < N;b++) {
			for (int c = 0;c < N;c++) {
				for (int d = 0;d < N;d++) {
					int xu = x[a];
					int xd = x[b];
					int yu = y[c];
					int yd = y[d];
					if (xu > xd || yu > yd) continue;

					int cnt = 0;
					for (int i = 0;i < N;i++) {
						if (x[i] >= xu && x[i] <= xd && y[i] >= yu && y[i] <= yd) cnt++;
					}

					if (cnt < K) continue;

					ll tmp = 1LL * (xd - xu)*(yd - yu);

					ans = min(ans, tmp);
				}
			}
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    //input
    int N;
    cin >> N;
    int x[N];
    int y[N];
    int stat [N];
    int statx[N][N];
    int staty[N][N];
    REP(i,N){
        int a;
        cin >> a;
        stat[i] = a;
        REP(j,a){
            int c,d;
            cin >> c >> d;
            c--;
            statx[i][j] = c;
            staty[i][j] = d;
        }
    }

    //logic
    int key = 0;
    REP(i,(1<<N)){
        bool right = true;
        bool ans[N];
        bool T[N];
        int num = 0;
        REP(j,N){
            if(i & (1<<j)) T[j] = false;
            else{
                T[j]= true;
                num++;
            }
        }
        REP(j,N){
            ans[j] = true;
            if(T[j]){
                REP(k,stat[j]){
                    if(T[statx[j][k]]){
                        if(staty[j][k] == 0) ans[j] = false;
                    }
                    else{
                        if(staty[j][k] == 1) ans[j] = false;
                    }
                }
            }
            if(!ans[j]) right = false;
        }
        if(right){
            key = max(key,num);
        }
    }

    //answers
    cout << key << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

int gcd(int ,int);

int main(){
  int n1,n2;
  
  scanf("%d %d",&n1,&n2);
  
  if(n1 > n2){
    printf("%d\n",gcd(n1,n2));
  }else{
    printf("%d\n",gcd(n2,n1));
  }
  return 0;
}

int gcd(int x,int y){
  int r;
  
  r = x % y;
  while(r!=0){
    x= y;
    y = r;
    r = x % y;
  }
  
  return y;
}



Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int n=sc.nextInt();
	static int m=sc.nextInt();
	
	int[] count(int[] ass,int[] cost){
		int[] cnt = new int[n];
		for(int i=0;i<m;i++){
			for(int j=0;j<n;j++){
				if(ass[i]>=cost[j]){
					cnt[j]++;
					break;
				}
			}
		}
		return cnt;
	}
	int count(int[] cnt){
		int best=cnt[0];
		int index=0;
		for(int i=1;i<n;i++){
			if(best<cnt[i]){
				best=cnt[i];
				index=i;
			}
		}
		return index+1;
	}
	void doIt(){
		int cost[]=new int[n];//競技にかかる費用
		int ass[]=new int[m];//審査員の評価基準
		int cnt[]=new int[n];//票数
		int index;
		for(int i=0;i<n;i++){
			cost[i]=sc.nextInt();
		}
		for(int i=0;i<m;i++){
			ass[i]=sc.nextInt();
		}
		cnt=count(ass,cost);
		index=count(cnt);
		System.out.println(index);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		new Main().doIt();
		
	}

}

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

public class Main {
	public static void main (String[] args) {
	Scanner s=new Scanner(System.in);	
	long a[][]=new long[3][3];
	for(int i=0;i<3;i++)
	{for(int j=0;j<3;j++)
	a[i][j]=s.nextLong();
	}
	int n=s.nextInt();
	for(int kk=0;kk<n;kk++)
	{long p=s.nextLong();
	for(int i=0;i<3;i++)
	{for(int j=0;j<3;j++)
	{if(a[i][j]==p)
	a[i][j]=-1;}}}
	boolean flag=false;
	if(a[0][0]==-1 && a[0][1]==-1 &&a[0][2]==-1)
	flag=true;
	if(a[1][0]==-1 &&a[1][1]==-1 &&a[1][2]==-1)
	flag=true;
	if(a[2][0]==-1 &&a[2][1]==-1 &&a[2][2]==-1)
	flag=true;
	if(a[0][0]==-1 && a[1][0]==-1 &&a[2][0]==-1)
	flag=true;
	if(a[0][1]==-1 &&a[1][1]==-1 &&a[2][1]==-1)
	flag=true;
	if(a[0][2]==-1 &&a[1][2]==-1 &&a[2][2]==-1)
	flag=true;
	if(a[0][0]==-1 &&a[1][1]==-1 &&a[2][2]==-1)
	flag=true;
	if(a[0][2]==-1 &&a[1][1]==-1 &&a[2][0]==-1)
	flag=true;
	if(flag)
	System.out.println("Yes");
	else
	System.out.println("No");
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    char a;
    cin >> a;
    if ('A' <= a && a <= 'Z')
        cout << 'A';
    else
        cout << 'a';
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

struct mi {
  int val; static const int MOD = 1e9+7; static_assert(MOD > 0, "Modulus not set!");
  mi(int v=0) : val(v) { if ((val %= MOD) < 0) val += MOD; }
  mi& operator += (const mi& b) { (val += b.val) %= MOD; return *this; }
  mi& operator -= (const mi& b) { return (*this) += MOD-b.val; }
  mi& operator *= (const mi& b) { val = ((ll)val*(ll)b.val) % MOD; return *this; }
  mi& operator /= (const mi& b) { return (*this) *= b.pow(MOD-2); }
#define _op(op, op2) mi operator op (const mi& b) const { mi ans = *this; return ans op2 b; }
  _op(+, +=); _op(-, -=); _op(*, *=); _op(/, /=);
#undef _op
  mi pow(ll e) const { mi res(1), b(*this); for (; e>0; e/=2, b*=b) { if (e&1) res*=b; } return res; }
  int toInt() const { return val; }
};

const int N = 1005;
mi dp[N][N];

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  int h, w; cin >> h >> w;
  char c;
  dp[0][1] = 1;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      cin >> c;
      if (c == '.') {
        dp[i][j] = dp[i-1][j] + dp[i][j-1];
      }
    }
  }
  cout << dp[h][w].toInt() << nl;

  return 0;
}



Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int a, b; cin >> a >> b;
  int k; cin >> k;
  rep(i, k) {
    if (i%2 != 0) {
      swap(a, b);
    }
    if (a%2 != 0) {
      a--;
    }
    b += a/2;
    a /= 2;
    if (i%2 != 0) {
      swap(a, b);
    }
  }
  cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}


bool isPrime(ll n) {
    if(n%2==0 && n!=2) {
        return false;
    }
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

ll binary_exp(ll x, ll n, ll mod)
{
    if (n == 0) {
        return 1;
    } else if (n == 1) {
        return x % mod;
    } else {
        ll temp = binary_exp(x, n / 2, mod);
        temp = (temp * temp) % mod;

        if (n % 2 == 0) {
            return temp;
        } else {
            return ((x % mod) * temp) % mod;
        }
    }
}

map<ll, ll> m;
// map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    //cin >> t;
    while(t--) {
        ll n;
        cin >> n;
        string s="ACL";
        for(ll i=0; i<n; i++) {
            cout << s;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3100
#include <iostream>

using namespace std;

const int N=40, INF=1000000000;
int a[N], b[N], c[N], d[N*10+1][N*10+1][N+1];

int main() {
  int n, ma, mb;
  cin >> n >> ma >> mb;
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
  for (int i = 0; i <= N*10; i++)
    for (int j = 0; j <= N*10; j++)
      for (int k = 0; k <= n; k++)
        d[i][j][k] = INF;
  for (int k = 0; k <= n; k++)
    d[0][0][k] = 0;
  for (int i = 1; i <= N*10; i++)
    for (int j = 1; j <= N*10; j++)
      for (int k = 1; k <= n; k++) {
        d[i][j][k] = d[i][j][k-1];
        if (a[k-1] <= i && b[k-1] <= j)
          d[i][j][k] = min(d[i][j][k], d[i-a[k-1]][j-b[k-1]][k-1]+c[k-1]);
      }
  int M = INF;
  for (int i = 1; i*ma<=N*10&&i*mb<=N*10; i++) M = min(M, d[ma*i][mb*i][n]);
  cout << (M == INF ? -1 : M) << endl;
}


Measured memory_bytes: 25984
x=int(input())

if x<=6:
  print(1)
elif x<=11:
  print(2)
else:
  if x%11==0:
    print(2*(x//11))
  else:
    if (x-(x//11)*11)<=6:
      print(2*(x//11)+1)
    elif (x-(x//11)*11)<=11:
      print(2*(x//11)+2)
    

Measured memory_bytes: 8968
local par={}
local size={}

local function init(n)
    for i=1,n do
        par[i]=i
        size[i]=1
    end
end

local function root(x)
    return par[x]==x and x or root(par[x])
end

local function same(x,y)
    return root(x)==root(y)
end

local function unite(x,y)
    x=root(x)
    y=root(y)
    if x==y then
        return
    end
    if size[x]>size[y] then
        x,y=y,x
    end
    par[x]=y
    size[y]=size[y]+size[x]
end

local function getsize(x)
    return size[root(x)]
end

----------

local n,m=io.read("n","n")
init(n)

local p={}
for i=1,n do
    p[i]=io.read("n")
end

for i=1,m do
    local x,y=io.read("n","n")
    unite(x,y)
end

local counter=0
for i=1,n do
    if same(p[i],i) then
        counter=counter+1
    end
end
print(counter)

Measured memory_bytes: 5884
import sys
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
m2=0
p1=0
m1=0
for i in range(n):
  c.append(b[i]-a[i])
s=sum(c)
cou=0
for i in range(n):
  if(c[i]<0):
    cou+=0
  elif(c[i]>0):
    cou+=(c[i])//2+(c[i])%2
if(cou<=s):print("Yes")
else:print("No")


Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int h,j;
    h=j=0;
    bool b = false;
    for(int i=0;i<s.size();i++)
    {
        if(i%2==0){
            if(s[i]!='h') {
                b=true;
                break;
            }
        }else{
            if(s[i]!='i'){
                b=true;
                break;
            }
        }
    }
    if(b || s.size()%2) cout <<"No";
    else cout <<"Yes";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
h = [int(input()) for _ in range(n)]

h.sort()
#小さい順に並べられたk本の木の、一番低い奴と高い奴の高さの差
dh = [int(1e9)]*n
for i in range(k-1,n):
    dh[i]=h[i]-h[i-k+1]
    
print(min(dh))

Measured memory_bytes: 16888
N = int(input())
F = [[int(_) for _ in input().split()] for _ in range(N)]
P = [[int(_) for _ in input().split()] for _ in range(N)]
store = [0] * N
ans = -float('inf')

for i in range(N):
    tmp = 0
    for j in range(10):
        tmp += F[i][j] << j
    store[i] = tmp

for i in range(1, 2**10):
    bene = 0
    for j in range(N):
        bene += P[j][bin(i & store[j]).count('1')]
    
    if bene > ans:
        ans = bene

print(ans)

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

a,b,c = inputIL()

if b-a == c-b:
  print("YES")
else:
  print("NO")

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

long long a, b, n;

int main() {

    cin >> a >> b >> n;

    // for (int i = 1; i <= n; i++) {
    //     cout << i << " " << (a * i) / b - a * (i / b) << endl;
    // }

    if (b == 1) {
        cout << 0 << endl;
        return 0;
    }

    long long x = min(n, b - 1);

    cout << (a * x) / b - a * (x / b) << endl;

    return 0;
}


Measured memory_bytes: 3644
using System;

namespace AtCoder{
    public static class AtCoder{
        public static void Main(){
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var c = int.Parse(input[2]);
            var k = int.Parse(input[3]);

            if(k <= a){ Console.WriteLine(k);}
            else if(k <= a + b){ Console.WriteLine(a);}
            else {Console.WriteLine(a - (k - a - b));}
        }
    }
}

Measured memory_bytes: 27376
n = str(input())

ans = 0
if n[0] == "1":
    ans += 900
else:
    ans += 100

if n[1] == "1":
    ans += 90
else:
    ans += 10

if n[2] == "1":
    ans += 9
else:
    ans += 1

print(ans)

Measured memory_bytes: 2940
#[allow(dead_code)]
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()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();
    if n < 10 {
        println!("{}", n);
    } else if n < 100 {
        println!("{}", 9);
    } else if n < 1000 {
        println!("{}", n - 99 + 9);
    } else if n < 10000 {
        println!("{}", 909);
    } else if n < 100000 {
        println!("{}", n - 9999 + 909);
    } else {
        println!("{}", 90909);
    }
}


Measured memory_bytes: 4352
from itertools import product
N, M = map(int, input().split())
X = []
Y = []
Z = []
for _ in range(N):
    x, y, z = list(map(int, input().split()))
    X.append(x)
    Y.append(y)
    Z.append(z)


def compute(xyz, opr):
    """
    >>> compute((1,2,3),("+","-","+"))
    2
    """
    x, y, z = xyz
    return eval(opr[0] + str(x) + opr[1] + str(y) + opr[2] + str(z))


oprs = list(product(("+", "-"), ("+", "-"), ("+", "-")))

Max = -float("inf")

for opr in oprs:
    L = [compute(xyz, opr) for xyz in zip(X, Y, Z)]
    L.sort()
    L.reverse()
    Max = max(Max, sum(L[:M]))

print(Max)


Measured memory_bytes: 3316
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
void solve(int n,std::vector<int> &v){
	int size =v.size();
	for(int i=(size==0)?n:min(n,v[size-1]);i >0;i--){
		v.push_back(i);
		if(i==n){
			for(int j=0;j <=size;j++){
				cout <<v[j];
				cout <<(j!=size?" ":"\n");
			}
		}else{
			solve(n-i,v);
		}
		v.pop_back();
	}
}

int main(){
	while(cin>>n,n){
	std::vector<int> v;
	solve(n,v);
	}
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
	int n;cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	int res=0;
	for(int i=0;i<n;i++) res^=a[i];
	vector<int>ans(n);
	for(int i=0;i<n;i++){
		ans[i] = res^a[i];
		cout<<ans[i]<<" ";
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 4748
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i=1; i*i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

void solve(){
    ll N;
    cin >> N;
    auto res = divisor(N);
    ll ans = LINF;
    for(auto x : res){
        auto y = N / x;
        chmin(ans, (x - 1) + (y - 1));
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  if(K == 1) cout << 0 << endl;
  else cout << N - K << endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define itn int

long long int GCD(long long int a,long long int b){long long int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
using namespace std;

int main() {
  char b;
  cin >> b;
  if(b=='A'){
    cout << "T" << endl;
    return 0;
  }
  else if (b == 'T')
  {
    cout << "A" << endl;
    return 0;
  }
  else if (b == 'C')
  {
    cout << "G" << endl;
    return 0;
  }
  else if (b == 'G')
  {
    cout << "C" << endl;
    return 0;
  }
}


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

int main(){
    string str;
    ll N;
    cin >> str >> N;
    for(int i = 0; i < str.size(); i++){
        if(str[i] != 'a' && ('a' + 26) - str[i] <= N){
            N -= ('a' + 26) - str[i];
            str[i] = 'a';
        }
    }
    N = N % 26;
    if(N > 0){
        str.back() = ((str.back() + N) - 'a') % 26 + 'a';
    }
    cout << str << endl;
}





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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define eps 1e-9

const int MOD = 1e9+7;

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

ll POWER[65];
ll power(ll a, ll b) {ll ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=MOD) ret%=MOD;if(a>=MOD) a%=MOD;b>>=1;}return ret;}
ll inv(ll x) {return power(x,MOD-2);}

void precompute() {
	POWER[0]=1;
	for(int i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL;
}
const int MAXN = 1e5+5;
int ar[MAXN];
int main() {
//	freopen("TASK.in","r",stdin);	
//	freopen("TASK.out","w",stdout);
//	precompute();
	int n,l;
	cin>>n>>l;
	int f=-1,t=-1;
	for(int i=1;i<=n;i++) {
		scanf("%d",&ar[i]);
		if(i==1 and ar[i]>=l) f=i,t=i;
		else if(i>1 and ar[i]+ar[i-1]>=l) f=i-1,t=i;
	}
	if(f==-1) cout<<"Impossible\n";
	else {
		cout<<"Possible\n";
		for(int i=1;i<f;i++) cout<<i<<"\n";
		for(int i=n-1;i>=f;i--) cout<<i<<"\n";
	}
	return 0;
}


Measured memory_bytes: 1152
using System;
class ITP1_9_A
{
    static void Main()
    {
        int counter = 0;
        string target = Console.ReadLine();
        while (true)
        {
            string[] rl = Console.ReadLine().Split(' ');
            if (rl[0] == "END_OF_TEXT") break;
            for (int i = 0; i < rl.Length; i++)
                if (string.Equals(target, rl[i], StringComparison.OrdinalIgnoreCase)) counter++;
        }
        Console.WriteLine(counter);
    }
}

Measured memory_bytes: 5596
unittest
{
	assert( [ "5", "3 2 2 4 1", "1 2 2 2 1" ].parse.expand.solve == 14 );
	assert( [ "4", "1 1 1 1", "1 1 1 1" ].parse.expand.solve == 5 );
	assert( [ "7", "3 3 4 5 4 5 3", "5 3 4 4 2 3 2" ].parse.expand.solve == 29 );
	assert( [ "1", "2", "3" ].parse.expand.solve == 5 );
}



import std.algorithm;
import std.conv;
import std.functional;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	long[][ 2 ] ass;
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.split.to!( long[] );
	}
	return tuple( ass );
}

long solve( long[][ 2 ] ass, long x = 0L, long y = 0L )
{
	auto l = ( ass.length      <= x + 1 ) ? 0L : memoize!solve( ass, x + 1, y );
	auto d = ( ass[ x ].length <= y + 1 ) ? 0L : memoize!solve( ass, x, y + 1 );
	
	return ass[ x ][ y ] + max( l, d );
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int solve(vector<vint>bm){
    if(bm.size()==0||bm[0].size()==0)return 1;

    int h=bm.size();
    int w=bm[0].size();

    UnionFindTree uf(h+w);
    rep(i,h)rep(j,w)if(bm[i][j])uf.unite(i,h+j);

    int cnt=h+w;
    rep(i,h+w)if(uf.find(i)==i)cnt--;
    int ret=1;
    rep(i,cnt)ret=ret*2%mod;
    return ret;
}

signed main(){
    int H,W;
    cin>>H>>W;
    vector<string>fld(H);
    rep(i,H)cin>>fld[i];
    int ans=1;
    if(H&1){
        bool flag=false;
        rep(j,W)if(fld[H/2][j]!=fld[H/2][W-1-j])flag=true;
        if(flag)ans=ans*2;
        fld.erase(fld.begin()+H/2);
        H--;
    }

    if(W&1){
        bool flag=false;
        rep(i,H)if(fld[i][W/2]!=fld[H-1-i][W/2])flag=true;
        if(flag)ans=ans*2;
        rep(i,H)fld[i]=fld[i].substr(0,W/2)+fld[i].substr(W/2+1,W/2);
        W--;
    }

    vector<vint>bm(H/2,vint(W/2));
    rep(i,H/2)rep(j,W/2){
        int cnt[26]={};
        cnt[fld[i][j]-'a']++;
        cnt[fld[i][W-1-j]-'a']++;
        cnt[fld[H-1-i][W-1-j]-'a']++;
        cnt[fld[H-1-i][j]-'a']++;
        int w=24;
        rep(k,26){
            for(int l=1;l<=cnt[k];l++)w/=l;
        }
        if(w==24){
            ans=ans*12%mod;
            bm[i][j]=1;
        }
        else{
            ans=ans*w%mod;
        }
    }

    ans=ans*solve(bm)%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  ll sum = 0;
  rep(i, n + 1) sum += i;
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )

typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int N=1e5+10, M=(ll)1e9+1 ;
const int mod = 1e9+7  ;

void work(){
   string s;
   cin >> s;
   for(ll i=0;i<s.length()-1;i++)
    if(s[i]==s[i+1]){
        cout << "Bad";
        return;
    }
   cout << "Good";
}
int main(){
 ios_base::sync_with_stdio(0);

    ll t,z;
    // cin >> t;
    // z=t;
    t=1;
    while(t--){
            // cout << "Case #" << z-t << ": ";
            work();
    }
   return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){
    ios::sync_with_stdio(false);
    int N, M;
    map<int, int> m;
    cin >> N >> M;
    for(int i=0;i<N;i++){
        int A, B;
        cin >> A >> B;
        m[A] += B;
    }
    ll ans=0;
    for(auto shop : m){
        int c = min(M, shop.second);
        ans += (ll)c*shop.first;
        M -= c;
        if(M == 0) break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int n;
vector<int> nums;
vector<ll> acc;
int k;

bool check(int d) { // d組できますか
    auto it = upper_bound(all(nums), d) - nums.begin();
    it--;
    ll sum;
    if (it < 0) {
        sum = (ll)sz(nums) * d;
    } else {
        sum = acc[it];
        sum += (ll)(sz(nums) - it - 1) * d;
    }
    if (sum >= (ll)k * d) return 1;
    
    return 0;
}

template<typename T>
void binary_search(T ok, T ng) {
    while (abs(ng - ok) > 1) {
        T mid = (ng + ok) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    
    for (auto e : mp) nums.eb(e.S);
    sort(all(nums));
    rep(i, sz(nums)) acc.eb(nums[i]);
    rep3(i, 1, sz(nums)) acc[i] += acc[i - 1];
    
    rep3(i, 1, n + 1) {
        k = i;
        binary_search(0, n + 1);
    }
    
    
}


Measured memory_bytes: 19440
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    for(int i=k;i<n;i++){
        if(a[i-k]<a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(10) <<
#include "atcoder/all"

#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)

using namespace std;
using namespace atcoder;


int main(){
    int n, q;
    cin >> n >> q;
   
    fenwick_tree<ll> ft(n);
    rep(i,n){
        int a; cin >> a;
        ft.add(i,a);
    }

    while(q--){
        int t; cin >> t;
        if(t){
            int l, r; cin >> l >> r;
            cout << ft.sum(l, r) << endl;
        }else {
            int p; ll x;
            cin >> p >> x;
            ft.add(p, x);
        }
    }
}


Measured memory_bytes: 8220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
int count(vector<int>& P) {
  int n = P.size();
  BinaryIndexedTree<int> bit(n);
  int res = 0;
  rep(i, n) {
    bit.add(P[i], 1);
    res += i+1-bit.sum(P[i]);
  }
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> A(n), B(n);
  rep(i, n) cin >> A[i];
  rep(i, n) cin >> B[i];
  int ans = inf;
  rep(i, 1<<n) {
    vector<int> v;
    map<int, vector<int>> odd, even;
    rep(j, n) {
      if((i>>j)&1) { // うら
        v.push_back(B[j]);
        if(j%2) { // 奇数 -> 偶数
          even[B[j]].push_back(j);
        } else { // 偶数 -> 奇数
          odd[B[j]].push_back(j);
        }
      } else { // おもて
        v.push_back(A[j]);
        if(j%2) { // 奇数 -> 奇数
          odd[A[j]].push_back(j);
        } else { // 偶数 -> 偶数
          even[A[j]].push_back(j);
        }
      }
    }
    sort(all(v));
    map<int, vector<int>> odd2, even2;
    rep(j, n) {
      if(j%2) {
        odd2[v[j]].push_back(j);
      } else {
        even2[v[j]].push_back(j);
      }
    }
    bool ok = true;
    int tmp = 0;
    vector<int> P(n);
    for(auto ele: odd) {
      if(ele.second.size() != odd2[ele.first].size()) ok = false;
      else {
        rep(k, ele.second.size()) {
          tmp += abs(ele.second[k]-odd2[ele.first][k]);
          P[odd2[ele.first][k]] = ele.second[k];
        }
      }
    }
    for(auto ele: even) {
      if(ele.second.size() != even2[ele.first].size()) ok = false;
      else {
        rep(k, ele.second.size()) {
          tmp += abs(ele.second[k]-even2[ele.first][k]);
          P[even2[ele.first][k]] = ele.second[k];
        }
      }
    }
    if(!ok) continue;
    int cnt = count(P);
    ans = min(cnt, ans);
  }
  cout << (ans == inf ? -1 : ans) << "\n";
  return 0;
}


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

const ll mod = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i=k; i<=n+1; i++) {
    ans += (n + n+1-i)*i / 2 - (i-1)*i / 2 + 1;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){

    int n, i;
    double x=0;
    cin >> n;
    int array[n];

    for(i=0; i<n; i++){
        scanf("%d", &array[i]);
    }

    for(i=0; i<n; i++){
        x += array[i];
    } 

    x /= n;
    x = round(x);

    int soma=0;
    for(i=0; i<n; i++){
        soma += (array[i] - x) * (array[i] - x);
    }

    cout << soma << endl;

    return 0;
}

Measured memory_bytes: 384
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

friend = UnionFind(n)

for i, j in ab:
    friend.union(i-1, j-1)

ans = 0
for i in range(n):
    ans = max(friend.size(i), ans)


print(ans)

Measured memory_bytes: 111636
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (b?gcd(a%b,b):a);
}
int main(){
	ll x;
	cin>>x;
	cout<<360/gcd(x,360)<<endl;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    int tmp=0;
    int ans=0;
    while(tmp<n){
        if(a[tmp]%2==0){
            a[tmp]/=2;
            ans++;
        }
        else tmp++;
    }
    cout << ans << endl;
}

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

int A, B, C, D, K, l, r, mid;

bool check(int Na) {
	int Nb = (Na - 1) / K;
	return (B - Nb) <= 1ll * K * (A - Na + 1);
}

int main() {
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		scanf("%d%d%d%d", &A, &B, &C, &D);
		K = (A + B) / (min(A, B) + 1);
		l = 0; r = A;
		while (l < r) {
			mid = (l + r + 1) >> 1;
			if (check(mid)) l = mid;
			else r = mid - 1;
		}
		int Na = l, Nb = (Na - 1) / K;
		rep (i, C, D)
			if (i <= Na + Nb) {
				if (i % (K + 1)) putchar('A');
				else putchar('B');
			}
			else {
				if ((A + B - i) % (K + 1) != K) putchar('B');
				else putchar('A');
			}
		puts("");
	}
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, INF = 0x3f3f3f3f;
int n, f[3][N];
char s[N];

int main() {
	scanf("%s", s + 1), n = strlen(s + 1);
	memset(f, -INF, sizeof(f));
	f[1][1] = 1, f[2][2] = 1, f[1][2] = (s[1] == s[2]) ? -INF : 2;
	for(int i = 3; i <= n; i++) {
		f[1][i] = f[2][i - 1] + 1;
		if(s[i] != s[i - 1]) f[1][i] = max(f[1][i], f[1][i - 1] + 1);
		f[2][i] = f[1][i - 2] + 1;
		if(i > 3 && s[i] != s[i - 2] && s[i - 1] != s[i - 3])
			f[2][i] = max(f[2][i], f[2][i - 2] + 1);
	}
	printf("%d\n", max(f[1][n], f[2][n]));
	return 0;
}

Measured memory_bytes: 2816
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		while (sc.hasNext())
		{
			double xa1 = sc.nextDouble(),
					ya1 = sc.nextDouble(),
					xa2 = sc.nextDouble(),
					ya2 = sc.nextDouble(),
					xb1 = sc.nextDouble(),
					yb1 = sc.nextDouble(),
					xb2 = sc.nextDouble(),
					yb2 = sc.nextDouble();
			double xaMin = Math.min(xa1, xa2),
					xaMax = Math.max(xa1, xa2),
					xbMin = Math.min(xb1, xb2),
					xbMax = Math.max(xb1, xb2),
					yaMin = Math.min(ya1, ya2),
					yaMax = Math.max(ya1, ya2),
					ybMin = Math.min(yb1, yb2),
					ybMax = Math.max(yb1, yb2);
			if (xaMax < xbMin || xbMax < xaMin || yaMax < ybMin || ybMax < yaMin)
			{
				System.out.println("NO");
			}
			else
			{
				System.out.println("YES");
			}
		}
	}
}

Measured memory_bytes: 12000
N=int(input())
l=[]

for i in range(N):
    l.append(int(input()))

l=sorted(l)
i=0
sum=0
nr=0
nl=0
right=l.pop(0)
left=right

while len(l)>1:
    if i%4==0:
        nr=l.pop(-1)
        sum+=nr-right
        right=nr        
    elif i%4==1:
        nl=l.pop(-1)
        sum+=nl-left
        left=nl
    elif i%4==2:
        nr=l.pop(0)
        sum-=nr-right
        right=nr       
    elif i%4==3:
        nl=l.pop(0)
        sum-=nl-left
        left=nl
        
    i+=1

#終わりのはじっこの処理がヤバイ? ちゃんと差がおおきくなるように配置できてるか
#11678で25出せればおけ
        
print(sum+max(abs(right-l[0]),abs(left-l[0])))

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,A;
  cin>>N>>A;
  vector<int>x(N);
  for(int i=0;i<N;i++)cin>>x[i];
  vector<vector<vector<ll>>>dp(N+1,vector<vector<ll>>(N+1,vector<ll>(50*50+1,0)));
  //[何番目まで][足す個数][合計]
  for(int i=0;i<=N;i++){
    for(int j=0;j<=N;j++){
      for(int k=0;k<=50*50;k++){
        if(i==0&&j==0&&k==0)dp[0][0][0]++;
        if(i-1>=0&&k-x[i-1]<0)dp[i][j][k]=dp[i-1][j][k];
        if(i-1>=0&&j-1>=0&&k-x[i-1]>=0)dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]];
      }
    }
  }

  ll ans=0;
  for(int j=1;j<=N;j++){
    ans+=dp[N][j][A*j];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 52224
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, ans;
bool used[26];
string s;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> s;
    set<char> sa, sb;
    rep(i, 0, n) {
        int sum = 0;
        fill(used, used+26, false);
        string x = s.substr(0, i+1), y = s.substr(i+1, n-i-1);
        rep(j, 0, x.size()) sa.insert(x[j]);
        rep(j, 0, y.size()) {
            if (!used[y[j]-'a'] && find(sa.begin(), sa.end(), y[j]) != sa.end()) {
                sum++;
                used[y[j]-'a'] = true;
            }
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
const long long INF = 1LL <<60;  
int main(void){
  long long res=0;
  long long n,k;
  long long i,j;
  
  cin>>n>>k;
  long long p[n];
  for(i=0;i<n;i++){
    cin>>p[i];
  }
  sort(p,p+n);
  for(i=0;i<k;i++){
    res+=p[i];
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <math.h>

int prime[10005];

void solve(void) {
  int N;
  int cnt = 0;
  int i, j;

  scanf("%d", &N);

  for (i = 0; i < N; i++) {
    int x;
    int f = 0;
    scanf("%d", &x);
    int root = sqrt((double)x);

    for (j = 2; j <= root && j != x; j++) {
      if (x % j == 0) {
        f = 1;
      }
    }
    cnt += !f;
  }

  printf("%d\n", cnt);
}

int main(void) {
  solve();

  return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
 
int main(){
  int a,b,c,i,j,k,m,n,cnt=0;
  int g[100][100]={},gg[100][100]={};
  scanf("%d %d\n",&n,&m);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(i!=j)
        g[i][j]=gg[i][j]=1001;
    }
  }
  for(i=0;i<m;i++){
    scanf("%d %d %d",&a,&b,&c);
    g[a-1][b-1]=g[b-1][a-1]=gg[a-1][b-1]=gg[b-1][a-1]=c;
  }
  for(k=0;k<n;k++){
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        if(g[i][j]>g[i][k]+g[k][j])
          g[i][j]=g[i][k]+g[k][j];
      }
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(gg[i][j]!=1001&&gg[i][j]!=g[i][j])
        cnt++;
    }
  }
  printf("%d\n",cnt/2);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;} 
int main(void)
{
  char s[3];
  scanf("%s",s);
  if(strcmp(s,"AAA")==0||strcmp(s,"BBB")==0)
    printf("No");
  else
    printf("Yes");
    
}

Measured memory_bytes: 128
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

void solve()
{
    IN(h, a);
    cout << ceil(1.0 * h / a) << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

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

    int N, M, T;
    cin >> N >> M >> T;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    int ans = T - M - min(M, T - A[A.size() - 1]);
    for (int i = 1; i < N; i++) {
        ans -= min(A[i] - A[i - 1], 2 * M);
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

const ll INF=1000000007;

int main(){
        ll dog, monkey;
        cin>>dog>>monkey;
        ll res=1;
        if(abs(dog-monkey)>=2){
                cout<<0<<endl;
                return 0;
        }

        bool flag=false;
        if(monkey==dog){
              flag=true;
        }
        while(dog>1){
        //      cout<<res<<endl;
                res=(res*dog)%INF;
                dog--;
        }
        while(monkey>1){
        //      cout<<res<<endl;
                res=(res*monkey)%INF;
                monkey--;
        }
        if(flag)
                res=(res*2)%INF;
        cout<<res%INF<<endl;
        return 0;
}


Measured memory_bytes: 256