akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int n;
int x[8], y[8];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }
  
  double sum = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      int dx = x[j] - x[i];
      int dy = y[j] - y[i];
      sum += hypot(dx, dy);
    }
  }
  cout << setprecision(16) << fixed << sum * 2 / n << endl;
}

Measured memory_bytes: 256
def solve(diff_list):
    max_gcd = diff_list[0]
    for key in range(1, len(diff_list)):
        max_gcd = gcd(max_gcd, diff_list[key])
    return max_gcd

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def main():
    n, x = map(int, input().split())
    x_list = list(map(int, input().split()))

    diff_list = []
    for i in x_list:
        diff_list.append(abs(i - x))

    ans = solve(diff_list)
    print(ans)

main()

Measured memory_bytes: 14252
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(input())

res = 0
for k in range(1, N+1):
    y = N // k
    res += k * y * (y+1) // 2

print(res)

Measured memory_bytes: 62900
#include "bits/stdc++.h"

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)


#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;

const int MOD = 1000*1000*1000 + 7;
const int NMAX = 1000*1000 + 11;

int arr[NMAX];
int n,m,p,q,k,a,b,c,ans;
string s,str;
char ch;
vector<int> v;

void solve()
{
    cin>>a;
    cin>>s;

    int b = (s[0]-'0')*100 + (s[2] - '0')*10 + (s[3] - '0');

    cout<<a*b/100;
}

int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

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

int main(){
    int x; cin >> x;
    int _x = x % 100;
    rep(a, 100)rep(b, 50)rep(c, 33)rep(d, 25)rep(e, 20){
        int sum = a + 2 * b + 3 * c + 4 * d + 5 * e;
        if(_x != sum % 100) continue;
        if(x - _x < (a + b + c + d + e) * 100) continue;
        cout << 1 << endl;
        return 0;
    }

    cout << 0 << endl;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h" 
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rerep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
const ll INF = 10e9;
int main(){
    ll n;
    cin>>n;
    ll one=n%10;
    if(one==3)cout<<"bon"<<endl;
    elif(one==0||one==1||one==6||one==8)cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    string s,t,u;
    cin>>s>>t;
    ll a,b;
    cin>>a>>b;
    cin>>u;
    if (s==u)
        cout<<a-1<<" "<<b;
    else
        cout<<a<<" "<<b-1;




}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    cout << ((c - (a - b) >= 0)?c - (a - b):0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
using namespace std;

int lcm(int max, int min) {
    int multiplier = 1;
    while ((max * multiplier) % min != 0) {
        multiplier++;
    }
    return max * multiplier;
}

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

int main(void) {
    int a, b;
    while (scanf("%d %d", &a, &b)+1)  {
        int min = (a < b)? a : b;
        int max = (a < b)? b : a;
        printf("%d %d\n", gcd(max, min), lcm(max, min));
    }
    return 0;
}

Measured memory_bytes: 1024
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 998244353;
const long double EPS = 0.00000001;


long long int N, M, K, L, R, H, W;

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

	cin >> N;
	
	int num[200000];
	for (int i = 0; i < N; i++) {
		cin >> num[i];
	}
	int box = 0;

	for (int i = 0; i < N; i++) {
		if (num[i] > box + 1) {
			M += (num[i]-1) / (box + 1);
			box = max(box, 1);
		}
		else {
			box = max(box,num[i]);
		}
		//cout << " " << M << endl;
	}
	cout << M << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, s = 0, d = 0, v[100000];
    cin >> n;
    int a[n];
    for (int i = 0; i < 100000; i++) v[i] = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        v[a[i] - 1]++;
    }
    for (int i = 0; i < 100000; i++)
    {
        if (v[i] != 0)
        {
            d++;
            s += (v[i] - 1);
        }
    }
    cout << d - s % 2;
}

Measured memory_bytes: 4352
from itertools import permutations

n, m = map(int, input().split())
g = {i: [] for i in range(1, n+1)}

for _ in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

p = permutations([x for x in range(2, n+1)])

res = 0
for l in p:
    tmp = g[1]
    for x in l:
        if x in tmp:
            tmp = g[x]
        else:
            break
    else:
        res += 1

print(res)

Measured memory_bytes: 3064
#挿入ソート

N = int(input())

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

print(*A)

for i in range(1, N):
    v = A[i]
    j =i-1

    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1

        A[j+1] = v
    print(*A)



Measured memory_bytes: 5976
num_str = input().strip()
number = int(num_str)

if len(num_str) == 1:
    print(number)
elif len(num_str) == 2:
    print(9)
elif len(num_str) == 3:
    print(number - 100 + 1 + 9)
elif len(num_str) == 4:
    print(909)
elif len(num_str) == 5:
    print(number - 10000 + 1 + 900 + 9)
elif len(num_str) == 6:
    print(90909)
exit(0)


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void print(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void print(H head, T ...tail) { cout << head << " "; print(tail...); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, m; read(n, m);
	int cnt = 0;
	rep(i, 0, n) {
		string s; read(s);
		for (char c : s) if (c == '#') cnt++;
	}
	print(cnt == n + m - 1 ? "Possible" : "Impossible");
}


Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V
 
getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]
 
type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)
 
mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
fi = fromInteger
fig = fromIntegral
rf = realToFrac
 
(.<.) f g -- combination
    | f < g = 0 
    | g < 1 || f < 1 = 1
    | True = foldr1 (*) (take g [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)
 
unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)
 
mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a
 
countIf f = length . filter f
 
-- 
--
--

_enumAll keta now = do
  if keta < 1 then now
  else do
    let new = (concat $ map (\x -> map (\y -> y:x) "375") now)
    _enumAll (keta - 1) new ++ now
enumAll keta
  | keta < 3 = []
  | True = filter (\x -> length (unique x) > 2) $ _enumAll (keta - 1) ["3", "5", "7"]
  
countAllPoss keta
  | keta < 3 = 0
  | keta == 3 = fact 3
  | True = 3 ^ keta - 2 ^ keta * 3
countThis n
  | n < 357 = 0
  | n < 1000 = length $ filter (n >=) [357, 375, 537, 573, 735, 753]
  | True = length . filter (n >=) . map (read :: String -> Int) $ enumAll (length $ show n)
countAll n = countAllPoss (pred . length $ show n) + countThis n
main = do
  i <- getLine
  let int = read i :: Int
  let allp = enumAll (length i)
  let counts = length . filter (<= int) $ map read allp
  putStrLn $ show counts



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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> A(n);
  ll sum = 0;
  rep(i,n) {
    cin >> A[i];
    sum += A[i];
  }
  ll ati = (sum + 4*m - 1) / (4*m);
  sort(all(A), greater<int>());
  bool ok = true;
  rep(i,n) {
    if (A[i] < ati && i < m) {
      ok = false; break;
    }
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
def rot(c, dist)
  new_cord = c.ord + dist
  if new_cord > 'Z'.ord
    new_cord = 'A'.ord + (new_cord - 'Z'.ord - 1)
  end
  return new_cord.chr
end

def solve()

  n = gets.to_i
  strs = gets.chomp.chars
  res = []
  strs.each do |c|
    res << rot(c, n)
  end
  puts res.join
end

solve

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll h[n];for(ll i=0;i<n;i++)cin>>h[i];
  ll ans=0;
  for(ll i=100;i>0;i--){
    ll s=0;
    for(ll j=0;j<n;j++){
      if(h[j]>=i)s=1;
      else{
        if(s==1)ans++;
        s=0;
      }
    }
    if(s==1)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
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; }
void say(bool yes){cout<<(yes?"YES":"NO")<<endl;};

int main(){

    string a, b;
    cin >> a >> b;
    reverse(a.begin(), a.end());
    say(a == b);

    return 0;
}

Measured memory_bytes: 256
case = 0
while True:
  case += 1
  W = int(input())
  if (W == 0):
    break
  N = int(input())
  vl = [0]
  wl = [0]
  for i in range(N):
    (v,w) = tuple(map(int,input().split(",")))
    vl.append(v)
    wl.append(w)
  dp = [[0 for i in range(W+1)] for j in range(N+1)]
  for i in range(1,N+1):
    for j in range(1,W+1):
      if j >= wl[i]:
        dp[i][j] = max(dp[i-1][j], dp[i][j-1], dp[i-1][j-wl[i]] + vl[i])
      else:
        dp[i][j] = max(dp[i-1][j], dp[i][j-1])
  print("Case " + str(case) + ":")
  print(dp[N][W])
  for i in range(W+1):
    if dp[N][i] == dp[N][W]:
      print(i)
      break


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

int main() {
  int N;
  cin >> N;
  vector<int> house(N);
  int sum = 0;
  for(int i = 0; i < N; i++) {
    cin >> house.at(i);
    sum += house.at(i);
  }
  int a = sum / N;
  int b = a + 1;
  int Sa = 0;
  int Sb = 0;
  for(int i = 0; i < N; i++) {
    Sa += (house.at(i) - a) * (house.at(i) - a);
    Sb += (house.at(i) - b) * (house.at(i) - b);
  }
  if(Sa < Sb) {
    cout << Sa << endl;
  }
  else {
    cout << Sb << endl;
  }    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Mashu cout << "UUZ ate it." << endl
#define RE register int
#define ll long long
using namespace std;

inline int read(){
	char ch=getchar();
	int x=0,cf=1;
	while(ch<'0'||ch>'9') {
		if(ch=='-') cf=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	if (cf < 0) return -x;
	else return x;
}

int G[55];
template<class T> inline void write(T x){
	int g=0;
	do{G[++g]=x%10;x/=10;}while(x);
	for(int i=g;i>=1;--i)putchar('0'+G[i]);putchar('\n');
}

int fa[100010], vis[100010];

int get(int x){
	if (fa[x] != x) return fa[x] = get(fa[x]);
	else return x;
}

int main(){
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) fa[i] = i;
	for (int i = 1; i <= m; i++){
		int a, b;
		cin >> a >> b;
		fa[get(a)] = get(b);
	}
	int qwq = 0;
	for (int i = 1; i <= n; i++){
		if (!vis[get(i)]){
			qwq++;
			vis[get(i)] = 1;
		}
	}
	cout << qwq - 1;
	return 0;
	Mashu;
}

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

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

using namespace std;

int main() {
	int n, a = 1;
	cin >> n;
	vector<int> v(n);
	REP(i, n) {
		cin >> v[i];
	}
	int b = v[0];
	while (a <= n + 1) {
		if (b == 2) {
			cout << a << endl;
			return 0;
		}
		a++;
		b = v[b-1];
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main
{
public static void main(String[] args)
{
	Scanner scan = new Scanner(System.in);
	
	int[] x = new int[10000];
	int[] y = new int[10000];
	int i;
	int kari;
	
	for (i=0; i<=10000; i++){
		x[i] = scan.nextInt();
		y[i] = scan.nextInt();
		if (x[i]==0 && y[i]==0){
			break;}
		else if (x[i]>y[i]){
			kari = x[i];
			x[i] = y[i];
			y[i] = kari;}}
			
	for (int q=0; q<i; q++){
		System.out.println(x[q]+" "+y[q]);}
	}
}


Measured memory_bytes: 36584
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    int N, K;
    bool answer = true;
    cin >> N >> K;
    vector<char> D(K);
    for(int i = 0; i < K; i++){
        cin >> D[i];
    }
    for(int i = N;; i++){
        answer = true;
        for(int j = 0; j < to_string(i).size(); j++){
            for(int l = 0; l < K;l++){
                if(to_string(i).at(j) == D[l]){answer = false;}
            }
        }
        if(answer == true){
                cout << i << endl;
                break;
        }
    }
}

Measured memory_bytes: 256
(* Vicfred
 * https://atcoder.jp/contests/abc080/tasks/abc080_b
 * implementation
 * *)
let n = read_int ()
let rec f n = if n = 0 then 0 else n mod 10 + f (n / 10)
let main = print_endline @@ if n mod f n = 0 then "Yes" else "No"



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

const int MAX = 1010000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long nCk(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(void) {

  COMinit();
  
  ll n, k;
  cin >> n >> k;

  for (ll i = 1; i <= k; i++) {
    cout << nCk(n - k + 1, i) * nCk(k - 1, i - 1) % MOD << endl;
  }

  return 0;
}

Measured memory_bytes: 23936
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    string s;
    cin >> s;
    long long ans = 0;
    rep(i, 1, s.length())
    {
        if (s[i] != s[i - 1])
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <sstream>

using namespace std;
int main() {
	int n = 0;
	cin >> n;
	vector<string> s(n);
	bool ret = true;
	for (int i = 0; i < n; i++) {
		string now = "";
		cin >> now;
		for (int j = i - 1; j >= 0; j--)if (s[j] == now)ret = false;
		if (i > 0) {
			char x = s[i - 1][s[i - 1].size() - 1];
			if (x != now[0])ret = false;
		}
		s[i] = now;
	}
	if (ret)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	    String S=gs();
	    int k=1;
	    String bs=S.substring(0,1);
	    for (int i=1; i<S.length();i++) {
	    	String s=S.substring(i, i+1);
	    	if(s.equals(bs)) {
	    		if(i!=S.length()-1) {
	    			k++;
	    			bs=S.substring(i, i+2);
                  	i++;
	    		}
	    	} else {
	    		k++;
	    		bs=s;
	    	}
	    	
	    }
	    System.out.println(k);
//        if(k%2==0) {
//        	
//		    System.out.println(a-b);
//        } else {
//        	System.out.println(b-a);
//
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 49796
#include <bits/stdc++.h>
#define fast_io ios::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main(){
	fast_io;
	int t;
	cin>>t;	
	int r=0;
	int *num=new int[t];
	for(int i=0;i<t;i++){
		cin>>num[i];
		if(i>=2 && ((num[i-1]>num[i-2] && num[i-1]<num[i])||(num[i-1]<num[i-2] && num[i-1]>num[i]))){
			r++;
		}
	}
	cout<<r;
	system("pause>0");
	return 0;
}

Measured memory_bytes: 3724
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
A, B = LI()

print(A * B)

Measured memory_bytes: 10840
#include <iostream>

using namespace std;

int gcd(int x, int y)
{
	return y > 0 ? gcd(y, x % y) : x;
}

int main()
{
	int a, b;
	while(cin>>a>>b)
	{
		int g = gcd(a, b);
		cout << g << " " << a / g * b << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int N=1e5+5;
ll dp[N][4],A[N][3],n;

ll f(int i, int l){
	if(i==n)return 0;
	ll &r=dp[i][l];
	if(r!=-1)return r;
	r=0;
	fore(j,0,3)if(l!=j)r=max(r,f(i+1,j)+A[i][j]);
	return r;
}

int main(){FIN;mset(dp,-1);
	cin >> n;
	fore(x,0,n)fore(i,0,3)cin>>A[x][i];
	cout << f(0,3) << "\n";
}

Measured memory_bytes: 13568
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;
 
int n, k;
vi a;
 
int main()
{
    cin >> n >> k;
    a.resize(n);
    rep(i, n) cin >> a[i];
 
    int ans = 1;
    n -= k;
    ans += (int)(n / (k - 1));
    if(n % (k-1) != 0) ans++;
    cout << ans << endl;
 
    return 0;
}

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

const int MAX_N = 1e5 + 5, inf = 1e9 + 7;
int n, k, ans;
bool mark[MAX_N];
int nxt[MAX_N];
int dis[MAX_N];
vector <int> topo;
vector <int> child[MAX_N];

void dfs (int v) {
	mark[v] = true;
	if (!mark[nxt[v]])
		dfs(nxt[v]);

	topo.push_back(v);
}

int dfs2 (int v = 0) {
	int tmp = dis[v];
	for (int u: child[v])
		tmp = max(tmp, dfs2(u));


	if (!v)
		return 0;

	if (tmp - dis[v] == k - 1 && nxt[v]) {
		ans++;
		nxt[v] = 0;
		dis[v] = 1;
		return -inf;
	}

	return tmp;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> k;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> nxt[i];
		nxt[i]--;

		if (i) {
			child[nxt[i]].push_back(i);
			cnt += nxt[i] != 0;
		}
	}
	if (nxt[0] != 0) {
		ans++;
		nxt[0] = 0;
	}

	if (k == 1) {
		ans += cnt;
		cout << ans << "\n";
		return 0;
	}

	for (int i = 0; i < n; i++)
		if (!mark[i])
			dfs(i);

	for (int v: topo)
		dis[v] = 1 + dis[nxt[v]];


	dfs2();
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 11896
s = gets.chomp.split('')

h = Hash.new(0)
s.each do |i|
  h[i] += 1
end
ha = h.to_a
if ha.size == 2 && ha[0][1] == 2 && ha[1][1] == 2
  print('Yes')
else
  print('No')
end


Measured memory_bytes: 1788
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		int K = in.nextInt();
		
		for (int i = 0; i < K; i++) {
			if(i%2==0){
                B+=A/2;
                A/=2;
            } else {
                A += B / 2;
                B /= 2;
            }
		}
		
		System.out.println(A + " " + B);
	}
	
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
 
  int main(){
     string s;
     cin>>s;
     rep(i,s.size()){
         cout<<'x';
     }
      
  }
  

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n, k, a;
    cin >> n >> k;
    map<int, int> mp;
    for (int i=0; i<n; i++) {
        cin >> a;
        mp[a]++;
    }
    vector<int> v;
    for (auto iter=mp.begin(); iter!=mp.end(); iter++) {
        v.push_back(iter->second);
    }
    sort(v.begin(), v.end(), greater<>());
    int limit = min(k, (int)v.size());
    int result = n;
    for (int i=0; i<limit; i++) {
        result -= v[i];
    }
    cout << result << endl;
}

Measured memory_bytes: 13584
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll inf = 1e18;


int main() {
	int n;
	cin >> n;
	vector<double> a(n);
	double sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	double ite = 0;
	rep(i, n) {
		if (abs(a[ite] - sum / n) > abs(a[i] - sum / n)) {
			ite = i;
		}
	}
	cout << ite << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int A[2][100];
int dp[2][100];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(j, 2) rep(i, N) cin >> A[j][i];
  rep(j, 2) rep(i, N) dp[j][i] = -INF;
  dp[0][0] = 0;
  rep(x, N) {
    dp[0][x+1] = max(dp[0][x+1], dp[0][x] + A[0][x]);
    dp[1][x+1] = max(dp[1][x+1], dp[1][x] + A[1][x]);
    dp[1][x+1] = max(dp[1][x+1], dp[0][x+1] + A[1][x]);
  }
  cout << dp[1][N] << "\n";
  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
p = gets.chomp.split(' ').map(&:to_i)
diff = 0
(1..n).each.with_index do |num, i|
  diff += 1 if (num != p[i])
end

if (diff == 0 || diff == 2)
  puts 'YES'
else
  puts 'NO'
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    array<bool, 26> exists;
    exists.fill(false);

    string S;
    cin >> S;
    for (const char c : S)
    {
        if (exists[c - 'a'])
        {
            cout << "no" << endl;
            return;
        }
        exists[c - 'a'] = true;
    }
    cout << "yes" << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int n = scn.nextInt();
        for(int i = 0; i < n; i++) {
            System.out.println(inning());
        }
    }
    
    private static int inning() {
        int score = 0, out = 0;
        int[] base = new int[3];
        while(out < 3) {
            switch(scn.next()) {
              case "OUT":
                out++;
                break;
              case "HIT":
                score += hit(base);
                break;
              case "HOMERUN":
                score += homerun(base);
                break;
            }
        }
        return score;
    }
    
    private static int hit(int[] base) {
        int point = base[2];
        base[2] = base[1];
        base[1] = base[0];
        base[0] = 1;
        return point;
    }
    
    private static int homerun(int[] base) {
        int point = 1;
        for(int i = 0; i < 3; i++) {
            point += base[i];
        }
        Arrays.fill(base, 0);
        return point;
    }
}

Measured memory_bytes: 26068
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli a,b,c,d;

int main(){
cin >> a >> b >> c >> d;
cout << max(a*b,c*d) << endl;
return 0;
}

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

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

  vector<int> a(n), b(n), v(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < n; ++i)
    cin >> b[i];
  for (int i = 0; i < n; ++i)
    v[i] = a[i] - b[i];

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

  int last = n - 1, ans = 0;
  for (int i = 0; i < n; ++i) {
    if (v[i] >= 0)
      continue;

    int j = last;
    while (v[j] > 0) {
      int x = min(-v[i], v[j]);
      v[i] += x;
      v[j] -= x;
      if (v[j] > 0)
        break;
      if (v[i] < 0)
        --j;
    }

    if (v[i] < 0) {
      cout << -1 << endl;
      return 0;
    }

    ans += 1 + (last - j);
    last = j;
  }

  if (ans > 0)
    ++ans;
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
fast_io
string s; cin>>s;
int ans=0;
rep(i,3){
if(s[i]=='1') ans++;
}
cout<<ans;
return 0;
}

Measured memory_bytes: 256
import sys
def input() : return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    left_sum = [0] * N # [0, i]
    right_sum = [0] * N # [i, N-1]

    left_sum[0] = A[0]
    right_sum[-1] = A[-1]

    for i in range(1, N):
        left_sum[i] = left_sum[i-1] + A[i]
        right_sum[(N-1)-i] = right_sum[(N-1)-(i-1)] + A[(N-1)-i]
    
    ans = 10 ** 18
    for i in range(N-1):
        diff = abs(left_sum[i] - right_sum[i+1])
        ans = min(ans, diff)
    
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 30828
# PyPy 推奨
n = int(input())

dp = [float("INF")] * 1000010
dp[0] = 0


for i in range(1, 100001):
    power = 1
    while power <= n:
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 6


for i in range(1, 100001):
    power = 1
    while power <= n:
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 9


ans = dp[n]
print(ans)

Measured memory_bytes: 13972
M, D = map(int, input().split(" "))

count = 0
for m in range(1, M+1):
    for d in range(1, D+1):
        d1 = d // 10
        d2 = d % 10
        if d1 >= 2 and d2 >= 2 and d1 * d2 == m:
            count += 1
print(count)

Measured memory_bytes: 3060
Module M
    sub Main()
        dim l = Console.ReadLine().Split()'.Select(Function(x) Integer.Parse(x)).ToList()
        dim a = Integer.Parse(l(0)), b = Integer.Parse(l(1)), c = Integer.Parse(l(2)), d = Integer.Parse(l(3))
        dim x = System.Math.Abs(b-a) <= d and System.Math.Abs(c-b) <= l(3)
        dim y = System.Math.Abs(c-a) <= d
        if x or y = True then
            Console.WriteLine("Yes")
        else
            Console.WriteLine("No")
        end if
    end sub
end Module

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

class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());

        Deque<Integer> list = new ArrayDeque<>();

        for (int i=0; i<n; i++) {
            String str = br.readLine();

            if (str.startsWith("insert")) {
                list.addFirst(Integer.parseInt(str.substring(str.indexOf(" ")+1)));
            }else if (str.equals("deleteFirst")) {
                list.pollFirst();
            }else if (str.equals("deleteLast")){
                list.pollLast();
            }else {
                list.remove((Integer)Integer.parseInt(str.substring(str.indexOf(" ")+1)));
            }
        }
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder sb = new StringBuilder();
        sb.append(list.poll());
        for (Integer s : list) {
            sb.append(" ");
            sb.append(s);
        }
        bw.write(sb.toString());
        bw.newLine();
        bw.close();

        br.close();
    }
}



Measured memory_bytes: 125468
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  // val a = new Array[Int](N)

  val N, A, B, C, D = in.next().toInt
  val s = "#" + in.next()
  val can = '.'


  var ans = true

  if (C == D)
    ans = false
  else if (C < D) {
    for (i <- A to C-1) {
      if (s(i) == '#' && s(i+1) == '#') {
        ans = false
      }
    }
    for (i <- B to D-1) {
      if (s(i) == '#' && s(i+1) == '#') {
        ans = false
      }
    }
  }
  else if (C > D) {
    ans = false

    breakable {
      for(i <- B-1 to D-1) {
        if (i+2 <= N) {
          if (List(s(i), s(i+1), s(i+2)).forall(_ == can))
            ans = true
        }
      }
    }


    for (i <- A to C-1) {
      if (s(i) == '#' && s(i+1) == '#') {
        ans = false
      }
    }
  }


  if (ans)
    println("Yes")
  else
    println("No")
}



class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 38292
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        
        // ans: nをkで割れるなら割り、そうでないならkを引く...をした数が1になるkの数
        // (2 <= k <= n)
        long ans = 0;
        
        // ex. n=12
        // 12: 12/12 = 1 OK
        // 11: 12-11 = 1 OK
        // 10: 12-10 = 2
        // 9: 12-9 = 3
        // 8: 12-8 = 4
        // 7: 12-7 = 5
        // 6: 12/6 = 2
        // 5: 12-5-5 = 2
        // 4: 12/4 = 3
        // 3: 12/3 -3 = 1 OK
        // 2: 12/2/2 -2 = 1 OK
        
        // -> 割り切って、その後は引くだけ
        // (「割れる」->「mod kが0」であり、割るとmod kの値は変わる)
        // (mod kが0でなくなったら割れない、引くしかない)
        // (引いてもmod kの値は変わらないので「引く後に割る」は起きない)
        
        // 全てなめるとO(10^12) -> 分けて考える。
        
        // 1.「/」もして「=1」になる
        // -> 「/」し切った値 (mod k) = 1ならOK
        
        // 2.「-」のみで「=1」になる
        // -> n (mod k) = 1
        // -> n-1 ≡ 0 (mod k) 
        // -> n-1の約数はOK(1はNG) (ex. n = 11 -> 11 (mod 2,5,10)は1)
        
        // list1: nの約数リスト
        // list2: n-1の約数リスト
        List<Long> list1 = divisorList(n);
        List<Long> list2 = divisorList(n - 1);
        
        // 上のように条件を満たすものをansに加算
        for (Long num : list1) {
            if (num == 1) continue;
            long tmp = n;
            while (tmp % num == 0) {
                tmp /= num;
            }
            if (tmp % num == 1) ans++;
        }
        ans += (list2.size()-1);
        System.out.println(ans);
        
    }
    
    public static List<Long> divisorList(long n) {
        List<Long> res = new ArrayList<Long>();
        for (long i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                res.add(i);
                
                long j = n / i;
                if (j != i) {
                    res.add(j);
                }
            }
        }
        res.sort(Comparator.naturalOrder());
        
        return res;
    }
}

Measured memory_bytes: 22612
import itertools
import math
import fractions
import functools
n, m, q= map(int, input().split())
abcd = []
for i in range(q):
    a, b, c, d = map(int, input().split())
    abcd.append([a-1, b-1, c, d])

l = []
for i in range(m):
    l.append(i)
maximum = 0
for a in itertools.combinations_with_replacement(l, n):
    sum = 0
    for i in range(q):
        if a[abcd[i][1]] - a[abcd[i][0]] == abcd[i][2]:
            sum += abcd[i][3]
    maximum = max(maximum,sum)
print(maximum)

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

#define fi first
#define se second
#define inf 0x3f3f3f3f
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define MOD 1000000007
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main(){
	
	int a,b,m;
	cin >> a >> b >> m;
	vector<int> A(a);
	vector<int> B(b);
	for(auto &x:A)
		cin >> x;
	for(auto &x:B)
		cin >> x;
	int ans = 100000000,v1,v2,d;
	
	while(m--){
		cin >> v1 >> v2 >> d;
		v1--,v2--;
		ans = min(ans,A[v1]+B[v2]-d);
	}
	sort(all(A));
	sort(all(B));
	ans = min(ans,A[0]+B[0]);
	cout << ans << '\n';
	
	
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}







Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i, c) for (int i = 0; i < (c);i++)
using namespace std;
int main(){
  int K, N;
  cin >> K >> N;
  vector<int> data(N);
  rep(i, N) cin >> data.at(i);
  data.push_back(K + data.at(0));
  int len = 0;
  rep(i, N ) len = max(len, data.at(i + 1) - data.at(i));
  cout << K - len << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[101],sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	for(int i=0;i<n-2;i++)
	for(int j=i+1;j<n-1;j++)
	for(int k=j+1;k<n;k++)
	{
		if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i]&&a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]){
			//cout<<i<<j<<k<<endl;
			sum++;	
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
long double n,k,ans;
int main() {
	scanf("%Lf%Lf",&n,&k);
	for(register long double i=1; i<=n; i+=1) {
		if(i>=k) {
			ans+=1.0/n;
			continue;
		}
		long double x=i,cnt=1;
		while(x<k) {
			x*=2.0;
			cnt*=2.0;
		}
		ans+=(1.0/n)*(1.0/cnt);
	}
	printf("%.9Lf",ans);
	return 0;
}

Measured memory_bytes: 3772
#include <stdio.h>

int main(void)
{
  int N;
  int M;
  int S[5];
  int C[5];
  int arr[3] = {-1, -1, -1};
  int result;

  // input
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d %d", &S[i], &C[i]);
  }

  // check 1
  for (int i = 0; i < M; i++) {
    for (int j = i; j < M; j++) {
      if (S[i] == S[j]) {
        if (C[i] != C[j]) {
          printf("%d\n", -1);
          return 0;
        }
      }
    }
  }
  
  // put
  for (int i = 0; i < M; i++) {
    arr[S[i] - 1] = C[i];
  }

  // check 2
  if (N >= 2 && arr[0] == 0) {
    printf("%d\n", -1);
    return 0;
  }
  // 
  if (arr[0] == -1) {
    if (N == 1) {
      arr[0] = 0;
    } else {
      arr[0] = 1;
    }
  }
  for (int i = 0; i < N; i++) {
    if (arr[i] == -1) {
      arr[i] = 0;
    }
  }

  // output
  for (int i = 0; i < N; i++) {
    printf("%d", arr[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 128
import sys
from operator import itemgetter
from itertools import accumulate
def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    C = list(accumulate(A))
    dp = [0] * N
    for i in range(N-1):
        if C[i] * 2 >= A[i+1]:
            dp[i+1] = dp[i] + 1
    print(dp[N-1]+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 60184
# second sum
# segment tree verify


class SegTree():
    # 1-indexed
    def __init__(self, N, function, basement):
        self.n = N
        self.K = (self.n-1).bit_length()
        self.f = function
        self.b = basement
        self.seg = [basement]*(2**(self.K+1)+1)
        X = 2**self.K

    def update(self, k, value):
        X = 2**self.K
        k += X
        self.seg[k] = value
        while k:
            k = k >> 1
            self.seg[k] = self.f(self.seg[k << 1], self.seg[(k << 1) | 1])

    def query(self, L, R):
        num = 2**self.K
        L += num
        R += num
        vL = self.b
        vR = self.b
        while L < R:
            if L & 1:
                vL = self.f(vL, self.seg[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.f(self.seg[R], vR)
            L >>= 1
            R >>= 1
        return self.f(vL, vR)

    def find_max_index(self, L, R, X):
        # [L,R)でX以下の物で最大indexを取得
        return self.fMi(L, R, X, 1, 0, 2**self.K)

    def find_min_index(self, L, R, X):
        # [L,R) でX以下の物で最小のindexを取得する
        return self.fmi(L, R, X, 1, 0, 2**self.K)

    def fMi(self, a, b, x, k, l, r):
        if self.seg[k] < x or r <= a or b <= l:
            return -1
        else:
            if k >= 2**self.K:
                return k-2**self.K
            else:
                vr = self.fMi(a, b, x, (k << 1) | 1, (l + r) // 2, r)
                if vr != -1:
                    return vr
                return self.fMi(a, b, x, k << 1, l, (l + r) // 2)

    def fmi(self, a, b, x, k, l, r):
        if self.seg[k] < x or r <= a or b <= l:
            return -1
        else:
            if k >= 2**self.K:
                return k-2**self.K
            else:
                vl = self.fmi(a, b, x, k << 1, l, (l+r)//2)
                if vl != -1:
                    return vl
                return self.fmi(a, b, x, k << 1 | 1, (l+r)//2, r)


xx = int(input())
P = list(map(int, input().split()))
P = [10**18, 10**18]+P+[10**18, 10**18]  # sentinel
Q = []
for i, v in enumerate(P):
    Q.append((v, i))
Q.sort(reverse=True)
N = len(Q)
A = SegTree(N, max, 0)
ans = 0
for value, index in Q:
    A.update(index, value)
    if value < 10**18:
        l2 = A.find_max_index(0, index, value)
        l1 = A.find_max_index(0, l2, value)
        r1 = A.find_min_index(index+1, N, value)
        r2 = A.find_min_index(r1+1, N, value)

        if 1<l2:
            ans += value*((l2-l1)*(r1-index))

        if r1<N-2:
            ans += value*((r2-r1)*(index-l2))

print(ans)

Measured memory_bytes: 94340
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		List<Integer> w = new ArrayList<Integer>();
		List<Integer> h = new ArrayList<Integer>();


		 for(int i=0;;i++){
			 h.add(i, scan.nextInt());
			 w.add(i, scan.nextInt());
			 if(w.get(i)==0 && h.get(i)==0) break;
		 }

		 for(int i=0;;i++){
			if(w.get(i)==0 && h.get(i)==0) break;
			 printSquare(w.get(i),h.get(i));

		 }
	}

	static void printSquare(int w,int h){
		for(int i=0 ;i< h;i++){
			for(int j=0; j < w;j++){
				System.out.print("#");
			}
				System.out.println();
		}
			System.out.println();
	}

}

Measured memory_bytes: 35728