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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

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

// const int mxN = 1e9 + 7;
const int M = 1e9 + 7;

ll pw(ll b, ll e)
{
	ll res = 1;
	while (e)
	{
		if (e % 2)
			res = (res * b) % M;
		b = (b * b) % M;
		e >>= 1; // e/=2;
	}
	return res;
}

// ll fact[mxN + 1], inv[mxN + 1];
// ll C(ll n, ll k)
// {
// 	return (((fact[n] * inv[k]) % M) * inv[n - k]) % M;
// }
// ll f1[M + 1], f2[M + 1];
// ll C(int n, int k)
// {
// 	return (((f1[n] * f2[k]) % M) * f2[n - k]) % M;
// }

int main()
{
	fast;
	string s;
	cin >> s;
	sort(all(s));
	if (s[2] == s[0])
		cout << "No";
	else
		cout << "Yes";
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>

int main()
{
    std::string s;
    std::cin >> s;
    std::vector<int> count(26);
    for (char c : s) {
        count[c - 'a']++;
    }

    int sum = 0;
    for (int i = 0; i < 26; i++) {
        sum += count[i] % 2;
    }
    std::cout << sum / 2 << std::endl;
    return 0;
}

Measured memory_bytes: 3164
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().split(" ");
        long n = Long.parseLong(str[0]);
        long m = Long.parseLong(str[1]);
        long ans = 0;
        if(n == 1 & m == 1){
            ans = 1;
        }else if(n == 1 & m != 1){
            ans = m - 2;
        }else if(n != 1 & m == 1){
            ans = n - 2;
        }else{
            ans = (n-2) * (m-2);
        }
        System.out.println(ans);
    }
    
}


Measured memory_bytes: 21844
#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 <unordered_map>
#include <unordered_set>
#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>
#define _GLIBCXX_DEBUG
#define INF 100000010
using namespace std;
const int mod = 1000000007;


int main(){
 int64_t N,K;
  cin>>N>>K;
  vector<int> A(N+1,0);
  for(int i=0; i<K; i++){
    int k;
    cin>>k;
    for(int j=0; j<k; j++){
      int a;cin>>a;
      A[a]++;
    }
    }
  int ans=0;
for(int i=1; i<N+1; i++){
if(A[i]==0)ans++;
}
  cout << ans << endl;
}

Measured memory_bytes: 3636
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import *
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    m, d = LI()
    ans = 0
    for i in range(1, m + 1):
        for j in range(10, d + 1):
            if int(str(j)[0]) < 2 or int(str(j)[1]) < 2:
                continue
            if i == int(str(j)[0]) * int(str(j)[1]):
                ans += 1
    print(ans)
    return

#B
def B():
    n, l = LI()
    a = LI()
    d0 = defaultdict(int)
    d1 = defaultdict(int)
    for i in a:
        d0[i] += 1
    for i in range(n):
        b = 0
        for k in range(i+1, n):
            if a[i] > a[k]:
                b += 1
        d1[i] = b
    ans = 0
    d2 = list(d0.items())
    d2.sort()
    d3 = defaultdict(int)
    d = 0
    for key, value in d2:
        d3[key] = d
        d += value
    for i in range(n):
        ans += d3[a[i]] * l * (l-1) // 2 + d1[i] * l
        ans %= mod
    print(ans % mod)
    return

#C
def C():
    n = II()
    s = S()
    lis = [0] * (2 * n)
    for i in range(1, 2 * n):
        lis[i] = (lis[i-1] ^ (s[i] == s[i-1]))
    l = [0] * (2 * n)
    for i in range(2 * n):
        l[i] += l[i - 1] + (lis[i] == 0)
    ans = 1
    if l[-1] != n or s[0] == "W":
        print(0)
        return
    k = 1
    for i in range(2 * n):
        if lis[i]:
            ans *= l[i] - (k - 1)
            ans %= mod
            k += 1
    print(ans * math.factorial(n) % mod)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 65008
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(1,n-1):
  if (p[i-1]>p[i] and p[i]>p[i+1]) or (p[i-1]<p[i] and p[i]<p[i+1]):
    count+=1
print(count)


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector <int> a(n + 1, 0);  //1 origin
	for (int i = 1; i <= n; i++)  cin >> a[i];

	vector <int> b(n + 1, 0);  //1 origin

	bool flag = true;
	for (int i = n; i >= 1; i--) {
		if (n / i < 2) {
			if (a[i] == 1) {
				b[i] = 1;
			} 
			else {
				b[i] = 0;
			}
		}
		else {
			int sum = 0;
			for (int j = n - (n % i); j >= i + 1; j -= i) {
				sum += b[j];
			}
			if ((sum + 1) % 2 == a[i])  b[i] = 1;
			else if ((sum + 0) % 2 == a[i])  b[i] = 0;
			else {
				flag = false;
				break;
			}
		}
	}

	if (flag) {
		int m = 0;
		for (int i = 1; i <= n; i++)  m += b[i];
		cout << m << endl;
		for (int i = 1; i <= n; i++) {
			if (b[i] == 1)  cout << i << ' ';
		}
		cout << endl;
	}
	else {
		cout << -1 << endl;
	}
}



Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,f[109],pas,jm;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    for(b=1; b<=a; b++) cin>>f[b];
    pas=999999999999999999LL;
    for(b=-1005; b<=1005; b++){
        jm=0;
        for(c=1; c<=a; c++){
            jm+=(f[c]-b)*(f[c]-b);
        }
        if(pas>jm) pas=jm;
    }
    cout<<pas;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<string> b(N);
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }
    int M;
    cin >> M;
    vector<string> r(M);
    for (int i = 0; i < M; i++) {
        cin >> r[i];
    }
    int ans = 0;
    for (string s : b) {
        int score = 0;
        for (string sb : b) {
            if (s == sb) score++;
        }
        for (string sr : r) {
            if (s == sr) score--;
        }
        ans = max(score, ans);
    }
    cout << ans << endl;
}

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

#define ii pair<int, int>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define INF int(1e9)

using namespace std;

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

    int k, n;

    cin >> k >> n;

    vi arr(n);

    for(int i=0; i<n; i++) cin >> arr[i];

    int init = arr[0];
    int end = arr[n-1];
    
    int ans = INF;

    for(int i=0; i<n; i++){
        int a = 2*abs(arr[i]-arr[0]) + abs(arr[i]-arr[n-1]);
        int b = abs(arr[i]-0) + abs(k-arr[i+1]);
        int c = abs(arr[i]-arr[0]) + 2*abs(arr[i]-arr[n-1]);
        ans = min(ans, min(min(a, b),c));
        //cout << a << " " << b << " " << c << endl;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
//int choose2(ll x){
	//	return x*(x-1)/2;}
const int INF = 1001001001;

int main() {
	ll N,K,tmp;
	cin >> N >> K;
	
	tmp = N % K;
	tmp = min(K -tmp,tmp);

	cout << tmp;
	


	
}

Measured memory_bytes: 256
answer = []

while True:
    m, f, r = list(map(int, input().split()))
    if m == f == r == -1:
        break

    # 中間試験、期末試験のいずれかを欠席した
    if (m == -1) or (f == -1):
        answer.append("F")
    # 中間試験と期末試験の合計点数が80以上
    elif 80 <= m + f:
        answer.append("A")
    # 中間試験と期末試験の合計点数が65以上80未満
    elif 65 <= m + f < 80:
        answer.append("B")
    # 中間試験と期末試験の合計点数が 50 以上 65 未満
    # 再試験の点数が 50 以上
    elif (50 <= m + f < 65) or (50 <= r):
        answer.append("C")
    # 中間試験と期末試験の合計点数が 30 以上 50 未満
    elif 30 <= m + f < 50:
        answer.append("D")
    # 中間試験と期末試験の合計点数が 30 未満
    elif m + f < 30:
        answer.append("F")

[print(*answer[i]) for i in range(len(answer))]


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

typedef long long ll;
#define Inf 1 << 20
#define MInf -(1 << 20)
 
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
#define Rep(i,n,m) for(int i = (int)(n); i < (int)(m);i++)
#define rrep(i,n) for(int i = (int)(n - 1); i > -1;i--)
#define RRep(i,n,m) for(int i = (int)(n - 1); i > (int)(m);i--)
#define trav(a, x) for(auto& a : x)
 
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))
#define REVERSE(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REVERSE(V)
 
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define yes(n) cout << ((n) ? "yes" : "no") << endl;

int main()
{
    string s;
    cin >> s;
    char s1 = s[0];
    char s2 = s[s.size() - 1];
    cout << s1 << s.size() - 2 << s2 << endl;
}


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

for i in range(n):
  if i == 0:
    pass
  elif i == 1:
    dp[i] = dp[0]+abs(h[0]-h[i])
  else:
    dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1]) 


Measured memory_bytes: 13928
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

//Sale Result
public class Main{

	static class P implements Comparable<P>{
		public int x;
		public int o;
		public long s;
		public int compareTo(P o) {
			return this.o-o.o;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			List<P> l = new ArrayList<P>();
			P[] s = new P[4001];
			int id = 1;
			while(n--!=0){
				int d = sc.nextInt();
				if(s[d]==null){
					s[d] = new P();
					s[d].x = d;
					s[d].o = id++;
				}
				long p = sc.nextLong();
				long k = sc.nextLong();
				s[d].s+=p*k;
//				if(1000000<=s[d].s&&s[d].o==0)s[d].o=id++;
			}
			for(int i=1;i<4001;i++)if(s[i]!=null&&1000000<=s[i].s)l.add(s[i]);
			Collections.sort(l);
			if(l.isEmpty())System.out.println("NA");
			else for(P i:l)System.out.println(i.x);
		}
	}
}

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

inline int gcd(int a, int b) {
  while (b) {
    int t = a % b;
    a = b;
    b = t;
  }

  return a;
}

inline int gcd(int a, int b, int c) {
  int g = gcd(a, b);
  return gcd(g, c);
}

int main(void) {
  int k;
  cin >> k;

  int sum = 0;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= k; j++)
      for (int u = 1; u <= k; u++)
        sum += gcd(i, j, u);

  cout << sum << endl;

}


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

int main() {
  int N;
  cin>>N;
  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
  cin >> vec.at(i);
}
   sort(vec.begin(), vec.end()); 
  int k=0;
  int a=N;
  cin>>k>>a;
   bool finished = false;
  
  while(k<N-1){
    
       for(int j=k+1; j<N; j++){
      if(vec.at(k)==vec.at(j)){
        a--;
        if(j==N-1){
          finished = true;
         break;
         
       }
      }
      
       
         else{
        k=j;
        if(j==N-1){
          finished = true;
         break;
         
       }
      }
    }
    if (finished) {
      break;
    }
  }
    

  
  cout<<a<<endl;
}

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

int main() {
  string c;
  cin >> c;
  if (c == "a") cout << "vowel" << endl;
  else if (c == "i") cout << "vowel" << endl;
  else if (c == "u") cout << "vowel" << endl;
  else if (c == "e") cout << "vowel" << endl;
  else if (c == "o") cout << "vowel" << endl;
  else cout << "consonant" << endl;

}


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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  long long a, b, c;
  cin >> a >> b >> c;
  long long k;
  cin >> k;
  if (k <= a) {
    cout << k << '\n';
  } else {
    k = max(k - a - b, 0ll);
    cout << a - k << '\n';
  }
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  int a[4], b[4];
  while (cin >> a[0] >> a[1] >> a[2] >> a[3]) {
    int ansb = 0, ansh = 0;
    rep(i, 4) cin >> b[i];
    rep(i, 4) rep(j, 4) {
      if (a[i] == b[j]) {
        if (i == j)
          ansh++;
        else
          ansb++;
      }
    }
    cout << ansh << ' ' << ansb << endl;
  }
  return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>
using namespace std;
int n, m;
string s;
int cnt;
vector<int> v;
void insertionSort(int n, int h) {
	for (int i = h; i < n; ++i) {
		int w = v[i];
		int j = i - h;
		while (j >= 0 && v[j] > w) {
			v[j + h] = v[j];
			j = j - h;
			cnt++;
		}
		v[j + h] = w;
	}
}
int main() {
	cin >> n;
	
	for (int i = 0; i < n; ++i) {
		int a; cin >> a;
		v.push_back(a);
	}
	int m = 0;
	vector<int> h;
    int i=0;
	while(i<n){
        i=3*i+1;
        if(i>n) break;
        h.push_back(i);
        m++;
    }
	reverse(h.begin(), h.end());
	cout << m << endl;
	for (int i = 0; i < m; ++i) {
		if (i == m - 1) {
			cout << h[i] << endl;
			break;
		}
		cout << h[i] << " ";
	}
	
	for (int i = 0; i < m; ++i) {
		insertionSort(n, h[i]);
	}
	cout << cnt << endl;
	for (int i = 0; i < n; ++i) {
		cout << v[i] << endl;
	}
}


Measured memory_bytes: 6876
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Diagnostics;

namespace test
{

    class Program
    {
        static void Main(string[] args)
        {
            string inString = Console.ReadLine();
            StringBuilder sb = new StringBuilder();
            foreach (char c in inString)
            {
                sb.Insert(0,c);
            }

            Console.WriteLine(sb);

        }


    }
        
}

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

set<string> ms;
set<string>::iterator it;

int main(){
	string s,sub;
	int k;
	cin>>s>>k;
	for (int i=0;i<s.size();i++)
		for (int j=1;j<=5;j++){
			sub=s.substr(i,j);
			ms.insert(sub);
		}
			
	int cnt=0;
	for (it=ms.begin();it!=ms.end();it++){
		cnt++;
		if (cnt==k){
			cout<<*it<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            a = L[i]
            b = L[j]
            c = L[k]
            if a == b or b == c or c == a:
                continue
            if a+b>c and b+c>a and c+a>b:
                ans += 1
                # print("i:j:k:{},{},{}".format(i+1,j+1,k+1))
print(ans)


Measured memory_bytes: 9092
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>

using namespace std;

typedef vector<int> VI;
typedef pair<int, int> P;
typedef long long ll;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define ALL(a)  (a).begin(),(a).end()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_buck
#define EACH(i,c) REP(i,(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int n, m, k, s, t;
VI es;
string str;

int main() {
	cin >> n;

	FOR(i, 1, 3501){
		FOR(j, 1, 3501){
			ll l = n*i*j, r = (ll)4 * i * j - n*(i + j);
			if(r<1)continue;
			if(l%r==0){
				cout<<l / r<<" "<<i<<" "<<j <<  endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
#include <stdio.h>
  
int main() {
  char ch[250]={0};
  char a[250] ={0};
  int h;
  int i,j,k,l,n,m;
  
  
  while(1){
    i=0;
    while(1){
        
      scanf("%c",&ch[i]);
      if(ch[i] == '\n') {    
    break;
      }
        
      i++;
    }
     
    if ( i == 1 && ch[0] == '-' ) break;
  
    //  printf("%d",i);
      
    scanf("%d",&m);
      
    for(j=0;j<m;j++){
      scanf("%d", &h );
        
      for(k=0;k<i-h;k++) {
    a[k] = ch[h+k];
    //    printf("a[%d] = ch[%d]の%c\n",k ,h+k,ch[h+k]);
      }
      for(k=0;k<h;k++){
    a[i-h+k] = ch[k];
    //   printf("a[%d] = ch[%d]の%c\n",i-h+k,k,ch[k]);
      }
      for(k=0; k<i; k++){
    ch[k] = a[k];
    // printf("ch[%d] = a[%d]の%c\n",k,k,a[k]);
      }
    }
    for(k=0;k<i;k++) {
      printf("%c",ch[k]);
    }
    printf("\n");
      scanf("%c",&ch[0]);
  }
    
    
  return 0;
    
}


Measured memory_bytes: 2072
s = gets.chomp.split('')
t = gets.chomp.split('')
motosize = t.size
max = 0

def hoge(a, b)
  count = 0
  for i in 0...(a.size) do
    count += 1 if (a[i] == b[i])
  end
  count
end

for i in 0..(s.size - t.size) do
  tmp = hoge(s[i...(i+t.size)], t)
  if (tmp > max)
    max = tmp
  end
end

puts motosize - max

Measured memory_bytes: 14284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

int N;
double dp[305][305][305];

int d1[] = {-1, 1, 0};
int d2[] = {0, -1, 1};
int d3[] = {0, 0, -1};
void rec(int cnt1, int cnt2, int cnt3) {
    if ((cnt1 | cnt2 | cnt3) == 0) {
        dp[cnt1][cnt2][cnt3] = 0;
        return;
    }

    dp[cnt1][cnt2][cnt3] = N;
    int c[3] = {cnt1, cnt2, cnt3};
    for (int i = 0; i < 3; ++i) {
        int nxt1 = cnt1 + d1[i];
        int nxt2 = cnt2 + d2[i];
        int nxt3 = cnt3 + d3[i];
        if (nxt1 < 0 || nxt2 < 0 || nxt3 < 0)
            continue;
        if (dp[nxt1][nxt2][nxt3] == -1)
            rec(nxt1, nxt2, nxt3);
        dp[cnt1][cnt2][cnt3] += c[i] * dp[nxt1][nxt2][nxt3];
    }
    dp[cnt1][cnt2][cnt3] /= (cnt1 + cnt2 + cnt3);
}

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

    cin >> N;
    static int cnt[3];
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        cnt[a - 1]++;
    }

    for (int i = 0; i < N + 3; ++i)
        for (int j = 0; j < N + 3; ++j)
            fill(dp[i][j], dp[i][j] + N + 3, -1);

    rec(cnt[0], cnt[1], cnt[2]);
    printf("%.14lf\n", dp[cnt[0]][cnt[1]][cnt[2]]);
    return 0;
}


Measured memory_bytes: 221568
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
char num_str[1002];
int num;
long sum = 0;
int i;
char tmp;
while (1){
fgets(num_str,sizeof(num_str),stdin);
if (num_str[0] =='0') break;
for (i = 0; i < strlen(num_str)-1; i++){
tmp = num_str[i];
num = atoi(&tmp);
sum = sum + num;
}
printf("%ld\n",sum);
sum = 0;
memset(num_str,1002, 0);
}
return 0;
}

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



def get_gcd(a,b):
  if a>b: a,b=[b,a]
  return b if a==0 else get_gcd(b%a,a)


def main():
  A,B,C,D = map(int, input().split())
  CD = C*D//get_gcd(C,D)

  num_C = B//C - (A-1)//C
  num_D = B//D - (A-1)//D
  num_CD = B//CD - (A-1)//CD

  print(B-A+1 - (num_C+num_D-num_CD)) 


if __name__ == "__main__":
  main()

Measured memory_bytes: 38256
function Main(N) {
var O =  Math.floor(N/1.08);
  if(Math.floor(O*1.08) == N){
    console.log(O);
  }else if(Math.floor((O+1)*1.08) == N){
    console.log(O+1);
  }else{
    console.log(":(")
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5, INF = 0x3f3f3f3f, M = N << 1;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define repe(i, u) for (int i = head[u]; i; i = nxt[i])



int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int a, b;
  cin >> a >> b;
  int ans = 0, now = 1;
  while (now < b) {
    now += a - 1;
    ans++;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())
ans = 0

if a+b <= c*2:
    ans += min(x, y)*(a+b)
else:
    ans += min(x, y)*c*2

if x > y:
    if a <= c*2:
        ans += (x-y)*a
    else:
        ans += (x-y)*c*2
else:
    if b <= c*2:
        ans += (y-x)*b
    else:
        ans += (y-x)*c*2

print(ans)


Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string s;
	cin >> s;
	cout << count(all(s), '1') << endl;
}


Measured memory_bytes: 256
f(int*a,int*b){return*a-*b;}
n,a[2<<17],b[2<<17],i;
main(){
	scanf("%d",&n);
	for(;~scanf("%d",a+i);i++)b[i]=a[i];
	qsort(a,n,4,f);
	for(i=0;i<n;i++)printf("%d\n",a[a[n/2]>b[i]?n/2:n/2-1]);
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_ ; ++i)
#define drep(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_ ; --i)
#define clear(a, b) memset((a), (b), sizeof(a))
#define Make_Fault() assert(0)
#define Sys_Fault() exit(998244353)
typedef long long LL;
int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = (x << 3) + (x << 1) + (ch - 0x30);
		ch = getchar();
	}
	return flag * x;
}

int a1, a2, a3, a4, a5, a6, a7;
LL ans;
int main() {
#ifdef Qrsikno
	freopen("m.in","r",stdin);
	freopen("m.out","w",stdout);
#endif
	a1 = read(), a2 = read(), a3 = read(), a4 = read(), a5 = read(), a6 = read(), a7 = read(); 
	//I O T J L S Z
	ans += a2;
	LL tmp1 = a1 / 2ll * 2 + a4 / 2ll * 2 + a5 / 2ll * 2,
	   tmp2 = (a1 - 1) / 2ll * 2 + (a4 - 1) / 2ll * 2 + (a5 - 1) / 2ll * 2 + 3ll;
	if(!(a1 > 0 && a4 > 0 && a5 > 0)) tmp2 = 0;
	ans += max(tmp1, tmp2);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int 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++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
ll n;
const int N=1000000;
vector<bool> isp(N+1, true);
//エラトステネスの篩
void sieve() {
  isp[0] = false;
  isp[1] = false;
  for (int i=2; pow(i,2)<=N; i++) {
    if (isp[i]) for(int j=2; i*j<=N; j++) isp[i*j] = false;
  }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    sieve();
    while(true){
        if(isp[n]){
            cout<<n<<"\n";
            break;
        }
        n++;
    }
}



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

int main(){
    ll d; cin >> d;
    map<ll,ll> mp;
    rep(i,26){
        ll c; cin >> c;
        mp[i] = c;
    }
    vector<vector<ll>> g(365, vector<ll> (26));

    rep(i,365){
        rep(j,26){
            cin >> g[i][j];
        }
    }

    ll cnt = 0;
    rep(i,365){
        cnt++;
        cnt%=26;
        cout << cnt + 1 << endl;
    }
}

Measured memory_bytes: 3720
<?php
$number = explode(' ', fgets(STDIN));
$n = $number[0];
$a = $number[1];
$b = $number[2];

$max = min($a, $b);
$value = $a + $b - $n;
$min = $value > 0 ? $value : 0;

printf('%d %d', $max, $min);

Measured memory_bytes: 4728
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();
        if(a < b){
            if(b < c){
                System.out.printf("%d %d %d\n", a, b, c);
            }else if(a < c){
                System.out.printf("%d %d %d\n", a, c, b);
            }else{
                System.out.printf("%d %d %d\n", c, a, b);
            }
        }else{
            if(a < c){
                System.out.printf("%d %d %d\n", b, a, c);
            }else if(b < c){
                System.out.printf("%d %d %d\n", b, c, a);
            }else{
                System.out.printf("%d %d %d\n", c, b, a);
            }
        }
    }
}


Measured memory_bytes: 26244
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main(void)
{
	int N;
	int A[100010],B[100010];
	int p = 1;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		B[A[i]] = p;
		p++;
	}
	for (int j = 1; j <= N; j++) {
		printf("%d ", B[j]);
	}
 
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> result = new ArrayList<Integer>();
		String[] n;

		while (true) {

			String line = sc.nextLine();
			n = line.split(" ");

			if (n[0].equals("0") && n[1].equals("0")) {
				break;
			}
			int a = Integer.parseInt(n[0]);
			int b = Integer.parseInt(n[1]);
			for (int i = 0; i < a; i++) {
				for (int j = 0; j < b; j++) {
					System.out.print("#");
				}
				System.out.println("");

			}
			System.out.println("");

		}
	}

}



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

int main(){ 
    Int A, B, C, K, ans;

    cin >> A >> B >> C >> K;

    if (A >= K) ans = K;
    else if ((K - A) <= B) ans = A;
    else ans = A - (K - A - B);

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

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

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

signed main(){
  int n;cin>>n;
  repd(i,1,50001){
    if(floor((double)i*((double)1.08)) == n){
      cout << i<< endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1LL << 60;

class UnionFind {
 protected:
  vi data;

 public:
  UnionFind(int size) : data(size, -1) {}
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) {
        swap(x, y);
      }
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int main() {
  ll n, k, l;
  cin >> n >> k >> l;
  UnionFind uf1(n), uf2(n), uf3(n);
  rep(i, k) {
    ll p, q;
    cin >> p >> q;
    p--, q--;
    uf1.unite(p, q);
  }
  rep(i, l) {
    ll r, s;
    cin >> r >> s;
    r--, s--;
    uf2.unite(r, s);
  }
  map<pll, ll> m;
  rep(i, n) {
    pll p = {uf1.root(i), uf2.root(i)};
    if (m.find(p) == m.end()) {
      m[p] = 1;
    } else {
      m[p]++;
    }
  }
  rep(i, n) {
    pll p = {uf1.root(i), uf2.root(i)};
    cout << m[p];
    if (i < n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 14336
parseint(x)=parse(Int,x)
l=Array{Int}(3,3)
for i in 1:3
    l[i,:]=parseint.(split(readline()))
end
n=parseint(readline())
for i in 1:n
    l[l.==parseint(readline())]=0
end
for i=1:3
    if l[i,:]==[0,0,0] || l[:,i] == [0,0,0]
        print("Yes")
        exit()
    end
end
if l[1,1]==l[2,2]==l[3,3]==0 || l[1,3]==l[2,2]==l[3,1]==0
    print("Yes")
    exit()
end
print("No")

Measured memory_bytes: 183500
put = '#'
put2 = '.'
output = []
while True:
	data = list(map(int, input().split()))
	if data[0] == 0 and data[1] == 0:
		break
	output += [data]

for tmp in output:
	for h in range(tmp[0]):
		for w in range(tmp[1]):
			if h == 0 or h == tmp[0]-1 or w == 0 or w == tmp[1]-1:
				print(put, end="")
			else:
				print(put2, end="")
		print()
	print()


Measured memory_bytes: 7004
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

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

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

/***************************************************************************/

int st[N<<2];

void update(int in, int la, int ra, int p, int val) {
	if(la == ra) {
		st[in] += val;
		if(st[in] >= MOD) st[in] -= MOD;
		return;
	}
	int mid = (la + ra) >> 1;
	int lt = (in << 1) + 1; int rt = lt + 1;
	if(p <= mid) update(lt, la, mid, p, val);
	else update(rt, mid+1, ra, p, val);
	st[in] = st[lt] + st[rt];
	if(st[in] >= MOD) st[in] -= MOD;
}

int sumRange(int in, int la, int ra, int l, int r) {
	if(ra < l or r < la) return 0;
	if(l <= la and ra <= r) return st[in];
	int mid = (la + ra) >> 1;
	int lt = (in << 1) + 1; int rt = lt + 1;
	int ans = sumRange(lt, la, mid, l, r) + sumRange(rt, mid+1, ra, l, r);
	if(ans >= MOD) ans -= MOD;
	return ans;
}

bool comp(pii X, pii Y) {
	if(X.fi == Y.fi) return X.se > Y.se;
	else return X.fi < Y.fi;
}

vector<pii> Q;
vector<int> YS;
int X[N], Y[N];

int main() {

	boost;
	int n, m; cin>>n>>m;
	for(int i=1; i<=n; i++) {
		cin>>X[i];
	}
	for(int i=1; i<=m; i++) {
		cin>>Y[i];
	}
	for(int i=1; i<=n; i++) {
		if(X[i] < Y[1] or X[i] > Y[m]) continue;
		int p = upper_bound(Y+1, Y+m+1, X[i]) - Y;
		Q.push_back(pii(X[i] - Y[p-1], Y[p] - X[i]));
		YS.push_back(Q.back().se);
	}
	sort(Q.begin(), Q.end());
	Q.resize(unique(Q.begin(), Q.end()) - Q.begin());
	sort(Q.begin(), Q.end(), comp);

	sort(YS.begin(), YS.end());
	YS.resize(unique(YS.begin(), YS.end()) - YS.begin());

	update(0, 0, YS.size(), 0, 1);

	for(auto it : Q) {
		int p = lower_bound(YS.begin(), YS.end(), it.se) - YS.begin();
		int sum = sumRange(0, 0, YS.size(), 0, p);
		update(0, 0, YS.size(), p+1, sum);
	}

	cout<<st[0]<<"\n";
	
	return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLD;
LL mod = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(k);
	VLL negs, pos;
	rep(i, 0, n) {
		sll(num);
		if(num < 0)	negs.push_back(abs(num));
		else if(num > 0)	pos.push_back(abs(num));
		else	k--;
	}
	sort(negs.begin(), negs.end());
	if(k == 0) {
		puts("0");
		return 0;
	}
	LL ans = LONG_MAX;
	rep(i, 0, k+1) {
		if(i == 0) {
			if(k <= negs.size())	ans = min(ans, negs[k-1]);
		}
		else if(i == k) {
			if(k <= pos.size())		ans = min(ans, pos[k-1]);
		}
		else {
			if(i <= pos.size() && k-i <= negs.size())
				ans = min(ans, pos[i-1] + negs[k-i-1] + min(pos[i-1], negs[k-i-1]));
		}
	}
	pll(ans); nl;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll lcm(ll a, ll b) {
	return a*b/gcd(a,b);
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == r) { return 1; }

	if (r > n / 2) { r = n / 2; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

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

	// 素数である
	return true;
}

ll GreaterBinarySearch(llvec array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return -1LL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	int n; cin>>n;
	ll a[n];
	for(int i=0; i<n; i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0; i<n-1; i++) {
		if(a[i]==a[i+1]) {
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    ll N,A,B; cin >> N >> A >> B;

    if(A > B) {cout << 0 << endl; return 0;}
    if(B-A > N) {cout << 0 << endl; return 0;}
    cout << A + (N-1) * B - (N-1) * A - B + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int d,t,s;
    cin>>d>>t>>s;
    double x = double (d)/s;
 
    if(x <= t){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3572
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;
    
    

    void calc()
    {
        cin = new Scanner();
        long N = cin.nextLong();
        long M = cin.nextLong();
        long ans = M / 2;
        ans = Math.Min(ans, (N * 2 + M) / 4);
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13140
/**
 *	author:		Yoseph Weissman
 *	created:	08.07.2020 10:43:46
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s(1,'\0');
	cin >> s;
	if (s == "SUN") cout << 7 << "\n";
	else if (s == "SAT") cout << 1 << "\n";
	else if (s == "MON") cout << 6 << "\n";
	else if (s == "TUE") cout << 5 << "\n";
	else if (s == "WED") cout << 4 << "\n";
	else if (s == "THU") cout << 3 << "\n";
	else if (s == "FRI") cout << 2 << "\n";
	return 0;
}


Measured memory_bytes: 3592
n = int(input())

if 400 <= n <= 599:
    print(8)
elif 600 <= n <= 799:
    print(7)
elif 800 <= n <= 999:
    print(6)
elif 1000 <= n <= 1199:
    print(5)
elif 1200 <= n <= 1399:
    print(4)
elif 1400 <= n <= 1599:
    print(3)
elif 1600 <= n <= 1799:
    print(2)
elif 1800 <= n <= 1999:
    print(1)

Measured memory_bytes: 9188
n = int(input())
a = []
b = []
for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)
a = a[::-1]
b = b[::-1]
cnt = 0
for i in range(n):
    if (a[i]+cnt)%b[i]:
        cnt+=b[i]-(a[i]+cnt)%b[i]
print(cnt)

Measured memory_bytes: 11816
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll h, w; cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (w % 2 == 0 || h % 2 == 0) {
        cout << w * h / 2 << endl;
    } else {
        cout << w * h / 2 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a)  (a).begin(),(a).end()
#define P pair<int, int>
#define ll long long
const int MOD = 1000000007;
//bitset<64>(x).count()
//fixed << setprecision(15) << 
ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
int main (){
  int n;
  cin >> n;
  if(n==1){
    cout << 0 << endl;
  } else {ll ans = (myPow(10, n, MOD) + myPow(8, n, MOD))%MOD;
    ans-= (2*myPow(9, n, MOD))%MOD;
    if(ans<0) ans+= MOD;
    ans %= MOD;
    cout << ans << endl;
  }
}


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

int main(){
    int n;
    cin >> n;
    double sum=0;
    double x;
    for(int i=0;i<n;i++){
        cin >> x;
        x= 1/x;
        sum+=x;
    }
    cout << 1/sum << endl;
}

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

using namespace std;

int main() {
    int N;
    long long int x;
    cin >> N >> x;
    vector<long long int> A(N);
    for(int n=0; n<N; n++) {
        cin >> A[n];
    }
    
    long long int ans=0;
    for(int n=1; n<N; n++) {
        if(A[n-1]>x) {
            ans += A[n-1]-x;
            A[n-1] = x;
            ans += A[n];
            A[n] = 0;
        } else {
            if(A[n-1]+A[n]>x) {
                ans += A[n-1]+A[n]-x;
                A[n] = x-A[n-1];
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
    
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <bits/stdc++.h> 
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll l[200020],r[200020],a[200020];

int main(){
  int n;
  cin >> n;
  ll k;
  cin >> k;
  rep(i,n){
    cin >> a[i+1];
    a[i+1]--;
    a[i+1]%=k;
  }
  REP(i,1,n+10)l[i]=(l[i-1]+a[i])%k;
  if(k>=n+1)k=n+1;
  map<ll,ll> mp;
  rep(i,k){
    mp[l[i]]++;
  }
  ll ans=mp[l[0]]-1;
  int cnt=0;
  for(int i=1;i<=n-1;i++){
    cnt++;
    mp[l[i-1]]--;
    if(i+k-1<=n)mp[l[i+k-1]]++;
    ans+=mp[l[i]]-1;
  }
  cout << ans << endl;
return 0;}

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

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int idx = 0; 
    int left_pound = 0;
    int right_dot = 0;
    while (idx < N && s[idx] == '.') {
        idx++;
    }
    int n = N - 1;
    while(n >= 0 && s[n] == '#') {
        n--;
    }
    if (n <= idx) {
        cout << 0 << endl;
        return 0;
    }
    // cout << idx << n << endl;
    for(int i = idx; i < n + 1; ++i) {
        if (s[i] == '.') right_dot++;
        else left_pound++;
    }
    int changed_pound = 0;
    // cout << right_dot << left_pound << endl;
    int count = min(right_dot, left_pound);
    for(int i = idx + 1; i < n + 1; ++i) {
        changed_pound++;
        while(s[i] == '.') {
            right_dot--;
            i++;
        }
        count = min(count, right_dot + changed_pound);
    }
    // cout << count << endl;
    int changed_dot = 0;
    // cout << right_dot << left_pound << endl;
    for(int i = n - 1; i >= idx; --i) {
        changed_dot++;
        while(s[i] == '#') {
            left_pound--;
            i--;
        }
        count = min(count, changed_dot + left_pound);
    }

    cout << count << endl;
}

Measured memory_bytes: 640