akhauriyash/Code-Regression huggingface dataset:
# C - Walking Takahashi
X,K,D = map(int,input().split())
n = abs(X)//D
if K<n:
    print(min(abs(X+K*D),abs(X-K*D)))
else:
    K -= n
    ans = min(abs(X+n*D),abs(X-n*D))
    if K%2==0:
        print(ans)
    else:
        print(D-ans)

Measured memory_bytes: 61864
#include<stdio.h>
#include<math.h>
#define dis(a,b) (a)*(a)+(b)*(b)
int main(){
  double x[3],y[3],a,b,c,sum=0.0;
  scanf("%lf,%lf%lf,%lf%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2]);
  a=dis(x[0]-x[1],y[0]-y[1]);
  do{
    b=dis(x[1]-x[2],y[1]-y[2]);
    c=dis(x[2]-x[0],y[2]-y[0]);
    sum+=sqrt((a*b+b*c+c*a)*2-a*a-b*b-c*c)/4;
    x[1]=x[2];
    y[1]=y[2];
    a=c;
  }while(scanf("%lf,%lf",&x[2],&y[2])!=-1);
  printf("%lf\n",sum);
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
const int MAXN=110000;
char s[MAXN];
int main()
{
//	freopen("C.in", "r", stdin);
//	freopen("C.out", "w", stdout);
	int ans=0;
	scanf("%s", s);
	for (int i=1; s[i]; i++)
		if (s[i]!=s[i-1]) ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
m = int(input())

a = list(map(int, input().split()))
p = [0]*n

for i in range(m):
    b = list(map(int, input().split()))
    for j in range(n):
        if a[i] == b[j]:
            p[j] += 1
        else:
            p[a[i]-1] += 1

for i in range(n):
    print(p[i])


Measured memory_bytes: 5624
#include <iostream>



int main()
{
	int H, N;
	int A = 0;
	int num;
	std::cin >> H >> N;
	for (int i = 0; i < N; i++) {
		std::cin >> num;
		A += num;
	}
	if (A >= H) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
}

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

const int INF = 1001001001;
int dx[4] = {-1, 0 ,1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    int h, w; cin >> h >> w;
    vector<vector<char>> mp(h, vector<char>(w));
    vector<vector<int>> dist(h, vector<int>(w));
    int cnt = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mp[i][j];
            dist[i][j] = -INF;
            if(mp[i][j] == '.') cnt++;
        }
    }
    queue<pair<int, int>> que;
    dist[0][0] = 0;
    que.push(make_pair(0, 0));
    while(!que.empty()){
        auto p = que.front(); que.pop();
        for(int i = 0; i < 4; i++){
            if(p.first + dx[i] < 0 || p.first + dx[i] >= h || p.second + dy[i] < 0 || p.second + dy[i] >= w || mp[p.first + dx[i]][p.second + dy[i]] == '#') continue;
            if(dist[p.first + dx[i]][p.second + dy[i]] == -INF){
                dist[p.first + dx[i]][p.second + dy[i]] = dist[p.first][p.second] + 1;
                que.push(make_pair(p.first + dx[i], p.second + dy[i]));
            }
            if(dist[p.first + dx[i]][p.second + dy[i]] > dist[p.first][p.second] + 1){
                dist[p.first + dx[i]][p.second + dy[i]] = dist[p.first][p.second] + 1;
                que.push(make_pair(p.first + dx[i], p.second + dy[i]));
            }
        }
    }
    if(dist[h-1][w-1] == -INF) cout << -1 << endl;
    else cout << cnt - dist[h-1][w-1] - 1 << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <cstdlib>

int main() {
    double x1{}, y1{}, x2{}, y2{};
    std::cin >> x1 >> y1 >> x2 >> y2;
    printf("%.8lf\n", pow(pow(x1-x2, 2.0) + pow(y1-y2, 2.0), 0.5));
}



Measured memory_bytes: 3392
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

typedef long long ll;
int const inf = 1<<29;

const bool M[3][5][5] = {
{
  {0,0,0,0,0},
  {0,0,1,0,0},
  {0,1,1,1,0},
  {0,0,1,0,0},
  {0,0,0,0,0},
},
{
  {0,0,0,0,0},
  {0,1,1,1,0},
  {0,1,1,1,0},
  {0,1,1,1,0},
  {0,0,0,0,0},
},
{
  {0,0,1,0,0},
  {0,1,1,1,0},
  {1,1,1,1,1},
  {0,1,1,1,0},
  {0,0,1,0,0},
},
};

int G[10][10];

bool check(int k, int y, int x) {
  REP(i, -2, 3) REP(j, -2, 3) {
    if(M[k][2+i][2+j]) {
      if(!in_range(y+i, x+j, 10, 10)) return false;
      if(!G[y+i][x+j]) return false;
    }
  }
  return true;
}

void use(int k, int y, int x) {
  REP(i, -2, 3) REP(j, -2, 3) if(M[k][2+i][2+j])
    G[y+i][x+j] --;
}

void revive(int k, int y, int x) {
  REP(i, -2, 3) REP(j, -2, 3) if(M[k][2+i][2+j])
    G[y+i][x+j] ++;
}

bool cleared() {
  bool ok = 1;
  rep(i, 10) rep(j, 10) {
    ok &= G[i][j] == 0;
  }
  return ok;
}

bool invalid(int y, int x) {
  if(y-2 >= 0 && x-2 >= 0 && G[y-2][x-2]) return 1;
  return 0;
}

bool solve(int r, int y, int x) {
  if(y == 10) return r == 0 && cleared();
  if(invalid(y, x)) return 0;
  if(r && G[y][x]) {
    rep(k, 3) {
      if(check(k, y, x)) {
        use(k, y, x);
        if(solve(r - 1, y, x)) {
          cout << x << ' ' << y << ' ' << k + 1 << endl;
          return 1;
        }
        revive(k, y, x);
      }
    }
  }
  return solve(r, y + (x == 9), (x + 1) % 10);
}

int main() {

  int N; cin >> N;
  rep(i, 10) rep(j, 10) {
    cin >> G[i][j];
  }

  solve(N, 0, 0);
  
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<pair<string, int>, int>> v;
  int n; cin >> n;
  for (int i = 1; i <= n; i++) {
    pair<pair<string, int>, int> entry;
    cin >> entry.first.first >> entry.first.second;
    entry.first.second *= -1;
    entry.second = i;
    v.push_back(entry);
  }
  sort(v.begin(), v.end());
  for (auto p : v) cout << p.second << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;
    string t = "CODEFESTIVAL2016";
    int ans = 0;

    for(int i=0; i<s.size(); i++) if(s[i] != t[i]) ans++;

    cout << ans << endl;
} 

Measured memory_bytes: 256
## B - Two Colors Card Game
N = int(input())
S = []
for n in range(N):
    S.append(input())
M = int(input())
T = []
for m in range(M):
    T.append(input())
val = [0]
for s in set(S):
    val.append(S.count(s) - T.count(s))
print(max(val))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#define llint long long

using namespace std;

llint n;
bool prime[60005];
vector<llint> pvec;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	for(int i = 2; i < 60005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 60005; j+=i){
			prime[j] = true;
		}
	}
	for(int i = 2; i < 55555; i++){
		if(!prime[i] && i % 5 == 1) pvec.push_back(i);
	}
	
	cin >> n;
	for(int i = 0; i < n; i++) cout << pvec[i] << " "; cout << endl;
	
	return 0;
}

Measured memory_bytes: 384
package main
 
import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
const initBufSize, maxBufSize = 10000, 1000000
 
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
 
func nextInts(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = nextInt()
	}
	return res
}
 
func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}
 
func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}
 
func abs(n int) int {
	return int(math.Abs(float64(n)))
}
 
func pow(r, n int) int {
	return int(math.Pow(float64(r), float64(n)))
}
 
func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initBufSize), maxBufSize)
	n := nextInt()
	k := nextInt()
 
	//すぬけ君1～Nがお菓子を持っていたら"1"、持っていなかったら"-1"とする
	sunuke := make(map[int]int)
	for i := 1; i <= n; i++ {
		sunuke[i] = -1
	}
 
	var d, snack, count int
	count = n
	for i := 0; i < k; i++ {
		//K番目のお菓子を持っているすぬけ君の人数
		d = nextInt()
		for j := 0; j < d; j++ {
			//お菓子を持っているすぬけ君の番号
			snack = nextInt()
			for k := 0; k < n; k++ {
				if sunuke[snack] == -1 {
					sunuke[snack] *= -1
					count--
				}
			}
		}
	}
	fmt.Println(count)
}

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

using namespace std;

const int maxl = 210;

int n, k;
char S[maxl];
char SS[maxl];

int cal(char *S, int n) {
	int c = 0;
	int res = 0;
	for (int i = 1; i <= n; i++) {
		c ++;
		if (i == n || S[i] != S[i+1]) {
			res += c / 2;
			c = 0;
		}
	}
	return res;
}

int main() {
	scanf("%s", S+1);
	scanf("%d", &k);
	n = int(strlen(S+1));
	for (int i = 1; i <= n; i++) SS[i] = SS[n+i] = S[i];
	int flag = 1;
	for (int i = 1; i < n; i++) if (S[i] != S[n]) flag = 0;
	if (flag) printf("%lld\n", 1LL*n*k/2);
	else {
		int v1 = cal(S, n);
		int v2 = cal(SS, 2*n);
		printf("%lld\n", v1 + 1LL * (v2 - v1) * (k-1));
	}
	return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    string s;
    cin>>s;
    sort(s.begin(),s.end());

    if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2])
        {
    cout<<"Yes"<<endl;
        return 0;
        }
        cout<<"No"<<endl;
}


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

void solve(int m){
    int ans = 0;
    for (int x=1; x<101; x++){
        for (int y=x; y<101; y++){
            for (int z=y; z<101; z++){
                if ((x*x + y*y + z*z + x*y + y*z + z*x) == m){
                    if (x==y && y==z) ans++;
                    else if (x != y && x != z && y != z) ans += 6;
                    else ans += 3;
                }
            }
        }
    }
    cout << ans << endl;
}

int main(){
    int n; cin>>n;
    for (int i=1; i<=n; i++) solve(i);
}

Measured memory_bytes: 3480
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main()
{
	int32_t A, B, C;
	cin >> A >> B >> C;

	int32_t res = C - (A - B);
	if (res < 0)
		res = 0;
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
package main

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

var (
	rdr   = bufio.NewReaderSize(os.Stdin, 1000000)
	reply string
)

func main() {
	in := nextSlice()
	solve(in)
}

func solve(buf []string) {
	a, _ := strconv.Atoi(buf[0])
	b, _ := strconv.Atoi(buf[1])
	c, _ := strconv.Atoi(buf[2])
	if b-a == c-b {
		yesorNO(true)
	} else {
		yesorNO(false)
	}
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func nextSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func scanSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func scanFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

// ---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

// ---------------------------------------------------

func yesOrNo(b bool) {
	if b {
		reply = "Yes"
		fmt.Println(reply)
		return
	}
	reply = "No"
	fmt.Println(reply)
}

func yesorNO(b bool) {
	if b {
		reply = "YES"
		fmt.Println(reply)
		return
	}
	reply = "NO"
	fmt.Println(reply)
}

Measured memory_bytes: 640
//package atcoder;

import java.io.*;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long n = s.nextLong();
        HashSet<Long> set = new HashSet<>();
        set.add(n);
        long k = n % 2 == 0 ? n/2 : 3L*n + 1L;
        int count = 2;
        while(!set.contains(k)) {
            set.add(k);
            count++;
            if(k %2 == 0) {
                k /= 2;
            } else {
                k = 3L*k + 1L;
            }
        }
        System.out.println(count);

    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1000000007
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(), v.end(), greater<ll>()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
using namespace std;
int main() {
    ll n;
    cin >> n;
    ll ans = INT_MAX;
    vl a(n);
    for(auto &it: a) {
        cin >> it;
    }
    sort(all(a));
    for(int i = 1; i <= 100; ++i) {
        ll st = 0;
        for(int j = 0; j < n; ++j) {
            st += ((i - a[j])*(i - a[j]));
        }
        ans = min(ans, st);
    }
    cout << ans;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())
alps = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
ans = []
for i in S:
  index = alps.index(i) + N
  ans.append(alps[index])
print(''.join(ans))

Measured memory_bytes: 3188
#include <iostream>
int main(){int c[9],i;for(i=0;i<9;i++)std::cin>>c[i];std::cout<<(c[0]+c[4]+c[8]==c[1]+c[5]+c[6]&&c[0]+c[4]+c[8]==c[2]+c[3]+c[7]?"Yes":"No");}

Measured memory_bytes: 256
line = input()
a, b, c, d = line.split(" ")
a, b, c, d = int(a), int(b), int(c), int(d)

max = max(a,c)

for i in range(max):
    c = c - b
    if c <= 0:
        print("Yes")
        break
    a  = a - d
    if a <= 0:
        print("No")
        break

Measured memory_bytes: 9200
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define ad(x,y) (x=(x+(y))%M)
#define mu(x,y) (x=x*(y)%M)
#define fi first
#define se second
#define pq priority_queue
#define br putchar('\n')
#define pb push_back
#define isinf(x) (x>=INF?-1:x)

using namespace std;

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

template<class T> void ckmin(T &a, T b) { return a>b?a=b:0; }
template<class T> void ckmax(T &a, T b) { return a<b?a=b:0; }

inline ll read()
{
    char c;ll out=0,f=1;
    for (c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());if (c=='-'){f=-1;c=getchar();}
    for (;c>='0'&&c<='9';c=getchar()){out=(out<<3)+(out<<1)+c-'0';}return out*f;
}
void write(ll x)
{
	if (x<0){putchar('-');write(-x);return;}
    if (x>9){write(x/10);}putchar(x%10+'0');
}

char s[200010];
ll ans,cnt;

int main()
{
	int i;
	
	scanf("%s",s);
	
	for (i=0;s[i];++i)
	{
		if (s[i]=='B')
		{
			++cnt;
		}
		else
		{
			ans+=cnt;
		}
	}
	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  char s1[1001];
  char juge[27]="XYZABCDEFGHIJKLMNOPQRSTUVW";
  cin >> s1;
  int len=strlen(s1);
  for(int i=0;i<len;i++){
    int temp;
    temp=s1[i]-'A';
    s1[i]=juge[temp];
  }
  cout << s1 << endl;
  return(0);
}

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

void draw_rect(int w,int h){
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << (((i+j)%2)?".":"#");
        }
        cout << endl;
    }
}

int main(){
    int w,h;
    while(1){
        cin >> h >> w;
        if (w==0 && h==0) break;
        draw_rect(w,h);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007

using namespace std;

int main(void){
  string s, t, u;
  int a, b, c;

  cin >> s >> t;
  cin >> a >> b >> u;

  if (s == u)
    cout << (a - 1) << " " << b << endl;
  else
    cout << a << " "  << (b - 1) << endl;



  

  return 0;
}


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

using ll = long long;
using Graph = vector<vector<int>>;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  ll k; cin >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  vector<int> dist(n+1,-1);
  vector<int> vp;
  
  int v = 1;
  while(dist[v]==-1){
    dist[v] = vp.size();
    vp.push_back(v);    
    v = a[v-1];
  }
  
  int p = vp.size()-dist[v];
  int length = dist[v];

  if(k<length) cout << vp[k] << endl;
  else{
    k -= (ll)length;
    k %= (ll)p;

    cout << vp[length+k] << endl;
  }  
  
  return 0;
}


Measured memory_bytes: 5752
#include<cstdio>
#include<cstring>

#define MAXN 200000
char str[MAXN+5];

int main(){
    scanf("%s",str+1);
    int len=strlen(str+1);
    for(int i=1;i<=len;i++){
        if(str[i]==str[i+1]){
            printf("%d %d",i,i+1);
            return 0;
        }
        if(str[i]==str[i+2]){
            printf("%d %d",i,i+2);
            return 0;
        }
    }
    printf("-1 -1");
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

int main() {
	long long n,rest;
	double root;
	int count=0;
	vector<pair<int, int>> P;
	
	cin >> n;
	root = sqrt(n);

	rest = n;
	for (int i = 2; i <= root; i++) {
		count = 0;
		while (rest % i == 0) {
			rest /= i;
			count++;
		}
		P.push_back(make_pair(i, count));
	}

	if (n % rest == 0 && rest > root) {
		P.push_back(make_pair(rest, 1));
	}

	int ans = 0;
	for (int i = 0; i < P.size() ; i++) {
		for (int j = 1; j < 1000000000000; j++) {
			P[i].second -= j;
			if (P[i].second < 0) { break; }
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000000 + 7
#define PI 3.14159265359

const long long INF = 100000;
typedef pair<int,int> P;
typedef long long ll;

using Graph = vector<vector<int>>;

vector<string> v;

//753数か判定
bool hantei(string S) {
	int N = S.size();
	bool flag3 = false;
	bool flag5 = false;
	bool flag7 = false;

	rep (i, N) {
		if (S[i] == '3') flag3 = true;
		if (S[i] == '5') flag5 = true;
		if (S[i] == '7') flag7 = true;
	}
	
	if (flag3 && flag5 && flag7) return true;
	else return false;
}

ll N;
void dfs(string S) {
	ll k = stoll(S);
	if (k > N) return;
	
	v.push_back(S);

	dfs(S + '3');
	dfs(S + '5');
	dfs(S + '7');

}

int main() {
	cin >> N;
	dfs("3");
	dfs("5");
	dfs("7");

	int ans = 0;
	for (int i = 0; i < v.size(); i++) {
		if (hantei(v[i])) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 2172
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}




signed main(void)
{
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> v;
    fact();
    int tmp = M;
    for(int i = 2; tmp > 1; i++) {
        if (i * i > M) {
            v.push_back(tmp);
            break;
        }
        while (tmp % i == 0) {
            v.push_back(i);
            tmp /= i;
        }
    }
    int cnt[10010] = {};
    int k = 0;
    rep(i, v.size()) {
        cnt[k]++;
        if (i + 1 == v.size()) break;
        if (v[i] != v[i + 1]) k++;
    }
    //rep(i, 3) cout<< cnt[i] << " ";
    //cout << endl;
    int ans = 1;
    rep(i, 10000) {
        ans = Mul(ans, F[N - 1 + cnt[i]]);
        ans = Div(ans, Mul(F[N - 1], F[cnt[i]]));
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 16768
N = int(input())
a = list(map(int, input().split()))

x = y = z = 0
for val in a:
    if val % 4 == 0:
        x += 1
    elif val % 2 == 0:
        y += 1
    else:
        z += 1

if z == 0:
    print('Yes')
elif x == 0:
    print('No')
elif y == 0 and x + 1 >= z:
    print('Yes')
elif x >= z:
    print('Yes')
else:
    print('No')

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

int main() {
  int H, W;
  cin >> H >> W;
  bool black = false;
  vector<vector<char>> a(H, vector<char>(W));
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> a.at(i).at(j);
      if(a.at(i).at(j) == '#')
        black = true;
    }
    if(!black)
      for(int j = 0; j < W; j++)
        a.at(i).at(j) = '-';
    black = false;
  }
  for(int j = 0; j < W; j++) {
    for(int i = 0; i < H; i++) {
      if(a.at(i).at(j) == '#')
        black = true;
    }
    if(!black)
      for(int i = 0; i < H; i++)
        a.at(i).at(j) = '-';
    black = false;
  }
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(a.at(i).at(j) != '-') {
        cout << a.at(i).at(j);
        black = true;
      }
    }
    if(black) {
      cout << endl;
      black = false;
    }
  }
}

Measured memory_bytes: 256
"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split(" ");

const R = parseInt(input[0], 10);
const G = parseInt(input[1], 10);
const B = parseInt(input[2], 10);
const N = parseInt(input[3], 10);

let ans = 0;

for (let r = 0; r <= N / R; r++) {
  for (let g = 0; g <= (N - (r * R)) / G; g++) {
    const rest = N - (r * R + g * G);
    if (rest % B === 0) {
      ans++;
    }
  }
}

console.log(ans);


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

string A,B,s;
int DP[3005][3005];

int LCS (int a, int b){
	if(a<0 || b<0) return 0;
	if(DP[a][b]!=-1) return DP[a][b];
	if(A[a]==B[b]) return DP[a][b] = 1+LCS(a-1,b-1);
	return DP[a][b] = max(LCS(a-1,b), LCS(a,b-1));
}

void ss (int a, int b){
	if(a<0 || b<0) return;
	if(A[a] == B[b]){
		s+=A[a];
		ss(a-1,b-1);
	} else{
		if(LCS(a-1,b)>LCS(a,b-1)){
			ss(a-1,b);
		} else {
			ss(a,b-1);
		}
	}
}

int main(){
	memset(DP,-1,sizeof DP);
	cin>>A>>B;
	int pana = A.length();
	int panb = B.length();
	
	int ans = LCS(pana-1,panb-1);

	s = "";
	ss(pana-1,panb-1);
	reverse(s.begin(),s.end());
	
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 35840
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main()
{
	string str = "NG";
	unsigned int k, a, b;

	// input
	cin >> k >> a >> b;

	// calc
	for (unsigned int i = a; i<=b; i++)
	{
		if ((i % k) == 0) {
			str = "OK";
			break;
		}
	}

	// output
	cout << str;
	cout << endl;

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

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

    cin >> n;
    string s;
    cin >> s;
    
    int minimum = 0;
    int count = 0;
    
    //iteration iはリーダーの位置とみなす。
    FOR(i, 1, n){
        if(s[i] == 'E') minimum++;
    }
    count = minimum;
    FOR(i, 0, n-1){
        if(s[i] == 'W') count++;
        if(s[i + 1] == 'E') count--;
        minimum = min(minimum, count);
    }
    
    /*
    rep(i, n){
        count = 0;
        rep(j, n){
            if(j < i){
                if(s[j] == 'W') count++;
            }
            if(i < j){
                if(s[j] == 'E') count++;
            }
        }
        minimum = min(minimum, count);
    }
    */
    
    cout << minimum << endl;
    return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	int num = 0;
	int numMax = 0;

	rep(i, n){
		int a, b;
		cin >> a >> b;

		if(a == b){
			num++;
			numMax = max(numMax, num);
		}
		else{
			numMax = max(numMax, num);
			num = 0;
		}
	}

	if(3 <= numMax) cout << "Yes";
	else cout << "No";
	
	return 0;
}

Measured memory_bytes: 3640
import itertools
H, W, K = map(int,input().split())

masu = []
for h in range(H):
    tmp = [1 if i == "#" else 0 for i in input()]
    masu.append(tmp)

ans = 0

h_product = list(itertools.product([0, 1], repeat=H))
w_product = list(itertools.product([0, 1], repeat=W))

for h_pro in h_product:
    for w_pro in w_product:
        tmp = 0
        for h in range(len(h_pro)):
            for w in range(len(w_pro)):
                tmp += h_pro[h] * w_pro[w] * masu[h][w]
        if tmp == K:
            ans += 1
                
       
print(ans)


Measured memory_bytes: 9040
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector <pair<int,int>> l;
int main()
{
    ll a,b,c,g,h,i,sum=0;
    cin>>a;
    ll d[a];
    for(i=0;i<a;i++)
    {
        cin>>d[i];
        sum=sum+d[i];
    }
    cin>>b;
    ll e;
    for(i=0;i<b;i++)
    {
        cin>>c;
        cin>>e;
        l.push_back(make_pair(c,e));
    }
    for(i=0;i<b;i++)
    {
        e=l[i].first;
        c=sum-d[e-1]+l[i].second;
        cout<<c<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
X,K,D = map(int,input().split())

X = abs(X)

if K*D < X:
    print(X-K*D)
else:
    count = X//D
    if (K-count)%2==0:
        print(X%D)
    else:
        print(min(X%D+D, abs(X%D-D)))

Measured memory_bytes: 61704
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

// edit

ll pow(ll x, ll p){
    ll ret = 1ll;
    REP(i, p){
        ret *= x;
    }
    return ret;
}

void solve(ll X) {
    ll RAN = 300;
    
    for(ll a = -RAN; a <= RAN; ++a){
        for(ll b = -RAN; b <= RAN; ++b){
            if(pow(a, 5)  == X + pow(b, 5)){
                cout << a << " " << b << endl;
                return;
            }
        }
    }

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    ll X;
    cin >> X;
    solve(X);


    return 0;
}


Measured memory_bytes: 3600
#B - 0 or 1 Swap(ABC135)
N=int(input())
P=list(map(int, input().split()))
P1=sorted(P)
P2=[P[i]-P1[i] for i in range(N)]
if P2.count(0)<N-2:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

vector<string> s;

int main(){
    int N, tmp;
    ll sum, count;
    string ss;

    cin >> N;
    for(int i=0; i<N; i++){
        cin >> ss;
        sort(ss.begin(), ss.end());
        s.push_back(ss);
    }

    sort(s.begin(), s.end());
    //cout << s[0] << endl;
    ss=s[0];
    count=1;
    sum=0;
    for(int i=1; i<N; i++){
        if(ss==s[i]){
            count++;
        }else{
            if(count<=1){
                ss = s[i];
                count = 1;
            }else{
                sum += count*(count-1)/2;
                ss = s[i];
                count = 1;
            }
        }
    }
    if(count > 1){
        sum += count*(count-1)/2;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 5748
#include<iostream>
using namespace std;
int main()
{
	int a[51];
	int b[51];
	int c[51]={};
	int n,m,x,y,i;
	cin>>n>>m;
	for(i=0;i<m;i++)
	cin>>a[i]>>b[i];
		
		
		for(i=0;i<m;i++)	
	{
     		x=a[i];
     		c[x-1]++;
     		y=b[i];
     		c[y-1]++;
     		}
     		for(i=0;i<n;i++)
     		cout<<c[i]<<'\n';
     		
     		return 0;
     		}

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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define int ll

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int INF = 1e9;
const ll MOD = 1e9+7;

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a = b; return true;} return false; }

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string T; cin >> T;
    REP(i, T.length())
    {
        if(T[i] == '?') T[i] = 'D';
    }
    cout << T << endl;
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N), sum(N+1, 0);
  REP(i, N){
    cin >> A[i];
    sum[i+1] = sum[i] + A[i];
  }
  map<ll, ll> mp;
  FOR(i, 0, N+1){
    mp[sum[i] % M]++;
  }
  ll ans = 0;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    if(itr->second < 2) continue;
    ans += itr->second*(itr->second - 1) /2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5760
N, Y = map(int, input().split())
check=False
for x in range(N + 1):
    for y in range(N + 1):
        z = N - x - y
        if 0 <= z and z <= N and 10000 * x + 5000 * y + 1000 * z == Y:
           print(x, y, z)
           check=True
           break
    if check == True:
        break
if check == False:
    print('-1 -1 -1')

Measured memory_bytes: 3060
n = int(input())
A = list(map(int, input().split()))

odds = 0
fours = 0
evens = 0

for a in A:
    if a % 4 == 0:
        fours += 1
    elif a % 2 == 0:
        evens += 1
    else:
        odds += 1

if evens == 0:
    if odds <= fours + 1:
        print("Yes")
    else:
        print("No")
else:
    if odds <= fours:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 15020
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] cin = Console.ReadLine().Split();
        int h = int.Parse(cin[0]);
        int w = int.Parse(cin[1]);
        string[] s = new string[h];
        for (int i = 0; i < h; i++)
        {
            s[i] = Console.ReadLine();
        }
        bool flag = false;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (s[i][j] == '#')
                {
                    if (Check(s, i, j)) flag = true;
                }
                if (flag) break;
            }
            if (flag) break;
        }
        if (flag) Console.WriteLine("No");
        else Console.WriteLine("Yes");
    }

    static bool Check(string[] s, int i, int j)
    {
        if (i != 0)
            if (s[i - 1][j] == '#') return false;
        if (i != s.Length - 1)
            if (s[i + 1][j] == '#') return false;
        if (j != 0)
            if (s[i][j - 1] == '#') return false;
        if (j != s[i].Length - 1)
            if (s[i][j + 1] == '#') return false;
        return true;
    }
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  map<string, int> mp;
  ll ans = 0;
  rep(i, n) {
    string s; cin >> s;
    sort(s.begin(), s.end());
    ans += mp[s]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11264
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int tmp;
        if(a > b){
            tmp = a;
            a = b;
            b = tmp;
        }
        if(a > c){
            tmp = a;
            a = c;
            c = tmp;
        }
        if(b > c){
            tmp = b;
            b = c;
            c = tmp;
        }
        System.out.println(a + " " + b + " " + c);
    }
}


Measured memory_bytes: 26236
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n, m;
  cin >> n >> m;

  cout << (n - 1) * (m - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
int p[110000];
int q[2][110000];
pair<int,int>t[2][110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
		q[i%2][p[i]]++;
	}
	for(int i=0;i<2;i++)for(int j=0;j<110000;j++){
		t[i][j]=make_pair(-q[i][j],j);
	}
	std::sort(t[0],t[0]+110000);
	std::sort(t[1],t[1]+110000);
	int ret=mod;
	if(t[0][0].second!=t[1][0].second){
		ret=a+t[0][0].first+t[1][0].first;
	}else{
		ret=a+t[0][1].first+t[1][0].first;
		ret=min(ret,a+t[0][0].first+t[1][1].first);
		
	}
	printf("%d\n",ret);
}


Measured memory_bytes: 4224
fun main(args: Array<String>) {
    var (N, K) = readInputLine().split(" ").map { it.toInt() }
    val Ds = readInputLine().split(" ").map { it.toInt() }.toSet()

    for (i in N until 100000) {
        if (i.toString().toCharArray().all { !Ds.contains(it - '0') }) {
            println(i)
            return
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 38768
#include <bits/stdc++.h>
using namespace std;
int n, l, c0, c1, c2;
long long z;
int x[300020];
int t[300020];
int f[300020];
int main() {
	scanf("%d%d", &n, &l);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x[i]);
	}
	z = 1;
	for (int i = 0; i < n; i++) {
		scanf("%d", &t[i]);
		z += t[i] / (2 * l);
		t[i] %= 2 * l;
		if (t[i] > 0) {
			z++;
			int f = (t[i] <= (l - x[i]) * 2);
			int g = (t[i] <= (x[i]) * 2);
			if (i == n - 1) {
				if (f) {
					z--;
				}
				break;
			}
			if (g) {
				c0++;
				if (f) {
					c2++;
				}
			} else if (f) {
				c1++;
			}
			while (c0 - c2 < c1 + c2) {
				if (c2 > 0) {
					c2--;
				} else {
					c1--;
				}
			}
		}
	}
	z -= c1 + c2;
	printf("%lld\n", z * l * 2);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll MOD = 1000000007;

template<typename T>
T mod_pow(T a, int p)
{
	if (p == 0)return 1;
	else if (p == 1)return a;
	else if (p % 2 == 0)
	{
		ll h = mod_pow(a, p / 2);
		return h * h % MOD;
	}
	else return (mod_pow(a, p - 1) * a) % MOD;
}



void solve()
{	
	ll n,k; cin >> n>>k;
	ll e_max=min(n-1,k);
	ll ans=0;
	vector<ll> fact(n+1,1);
	vector<ll> fact_inv(n+1,1);
	rep(i, n)
	{
		fact[i+1]=(fact[i]*(ll)(i+1))%MOD;
		fact_inv[i+1]=fact_inv[i]*mod_pow((ll)(i+1),MOD-2)%MOD;
	}

	rep(i,e_max+1)
	{
		ll tmp=(((fact[n]*fact_inv[i])%MOD)*fact_inv[n-i])%MOD;
		tmp%=MOD;
		tmp*=(((fact[n-1]*fact_inv[i])%MOD)*fact_inv[n-i-1])%MOD;
		ans+=tmp;
		ans%=MOD;
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll h, w;
    cin >> h >> w;

    vl a(h);
    set<ll> st1;
    vl v1(h*w+1);  // v1[i] : aの中でi以上の数の個数
    rep(i, h) {
        cin >> a[i];
        st1.insert(a[i]);
        v1[a[i]]++;
    }

    vl b(w);
    set<ll> st2;
    vl v2(h*w+1);  // v2[i] : bの中でi以上の数の個数
    rep(i, w) {
        cin >> b[i];
        st2.insert(b[i]);
        v2[b[i]]++;
    }

    if(st1.size() != h || st2.size() != w) {
        out(0);
        re0;
    }

    for(ll i = h*w; i >= 2; i--) {
        v1[i-1] += v1[i];
        v2[i-1] += v2[i];
    }   

    ll ans = 1;
    ll cnt = 0;
    for(ll x = h*w; x >= 1; x--) {
        if(st1.find(x) != st1.end() && st2.find(x) != st2.end()) {
            ans *= 1;
        }
        else if(st1.find(x) != st1.end() && st2.find(x) == st2.end()) {
            ans *= v2[x];
        }
        else if(st1.find(x) == st1.end() && st2.find(x) != st2.end()) {
            ans *= v1[x];
        }
        else {
            ans *= max(0LL, v1[x]*v2[x] - cnt);
        }
        ans %= mod;
        cnt++;
    }

    out(ans);
    re0;
}

Measured memory_bytes: 16000
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>

#define M 1000000000

using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    
    int ans(1);
    int i(0);
    while(ans < b){
        i++;
        ans -= 1;
        ans += a;
    }
    
    cout << i << endl;
    
    return 0;
}


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

using namespace std;
int main(){
    int n; cin>>n;
     int a[n+1];
     int b[n+1];
     int c[n];
     int ans=0;

     for(int i=1;i<=n;i++)cin>>a[i];
     for(int i=1;i<=n;i++)cin>>b[i];
     for(int i=1;i<=n-1;i++)cin>>c[i];

   for(int i=1;i<=n;i++){
      ans+=b[a[i]];
       if(i<=n-1&&a[i+1]==a[i]+1)ans+=c[a[i]];

   }
     
	cout<<ans<<endl;
}



Measured memory_bytes: 256
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] data = br.readLine().split(" ");
    
    int a = Integer.parseInt(data[0]);
    int b = Integer.parseInt(data[1]);
    int c = Integer.parseInt(data[2]);
    
    int i = 1;
    int init = a%b;
    while (true){
      if((a*i)%b == c){
        System.out.println("YES");
        return;
      }
      if(i>1 && (a*i)%b==init){
        System.out.println("NO");
        return;
      }
      i++;
    }
  }
}


Measured memory_bytes: 21204
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()
b=n1()
c=n1()

a.sort()
b.sort()
c.sort()

from bisect import bisect_left,bisect_right
b2=[]
for i in b:
    b2.append(bisect_left(a,i))

import itertools
b3=list(itertools.accumulate(b2))
    
ans=0
for i in c:
    t=bisect_left(b,i)
    if t>0:
        ans+=b3[t-1]
    
print(ans)

Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;cin>>n>>m;
    ll ans = 0;
    for(ll i=1; i*i<=m&&i*n<=m; i++){
        if(m%i)continue;
        ans=max(ans,i);
        if(i>=n)ans=max(ans,m/i);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256